Stop spinner when loading coal
authorOlav Bakke Svendsen <mail@olavbs.no>
Thu, 12 Oct 2023 04:56:11 +0000 (06:56 +0200)
committerOlav Bakke Svendsen <mail@olavbs.no>
Thu, 12 Oct 2023 04:56:11 +0000 (06:56 +0200)
steam/temporary-coal-feeder.lua

index 611661f6bda01cfa0be51be69c1504c4be30d04d..d18f3d6289bb6726ec629303df7f0a4d4c0c66ed 100644 (file)
@@ -79,31 +79,35 @@ local print_stats = function(monitor, stock)
 end
 
 local spinner_chars = {"\\","-","/","|"}
-local spinner = function()
+local spin = function()
   local c = table.remove(spinner_chars)
   table.insert(spinner_chars, 1, c)
   return c
 end
+local print_spinner(monitor, x, y, spinning) = function()
+  local s = spin()
+  main_monitor.setTextColor(1)
+  main_monitor.setCursorPos(29,12)
+  main_monitor.write(spinning and s or "*")
+end
 
 local main_timer = os.startTimer(0)
 local spinner_timer = os.startTimer(0)
 
 while true do
   local e = table.pack(os.pullEvent())
-  if e[1] == "monitor_touch" and e[2] == treefarm_monitor then
-    treefarm_monitor.write(spinner())
-  elseif e[1] == "timer" and e[2] == main_timer then
+--   if e[1] == "monitor_touch" and e[2] == treefarm_monitor then
+--     treefarm_monitor.write(spin())
+  if e[1] == "timer" and e[2] == main_timer then
     main_timer = os.startTimer(60)
     os.cancelTimer(spinner_timer)
+    print_spinner(main_monitor, 29,12, false)
     local stock = balance_coal()
     print_stats(main_monitor, stock)
     feed(stock)
     spinner_timer = os.startTimer(0)
   elseif e[1] == "timer" and e[2] == spinner_timer then
     spinner_timer = os.startTimer(0.5)
-    local s = spinner()
-    main_monitor.setTextColor(1)
-    main_monitor.setCursorPos(29,12)
-    main_monitor.write(s)
+    print_spinner(main_monitor, 29, 12, true)
   end
 end