miezto

dr_fuel

Oct 1st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. local monitor = peripheral.wrap("monitor_181")
  2. local reactor = peripheral.wrap("right")
  3.  
  4. local mon, monX, monY
  5. monX, monY = monitor.getSize()
  6. mon = {}
  7. mon.monitor,mon.X, mon.Y = monitor, monX, monY
  8.  
  9. function clear(mon)
  10.     term.clear()
  11.     term.setCursorPos(1,1)
  12.     mon.monitor.setBackgroundColor(colors.black)
  13.     mon.monitor.clear()
  14.     mon.monitor.setCursorPos(1,1)
  15. end
  16.  
  17. function draw_text(mon, x, y, text, text_color, bg_color)
  18.     mon.monitor.setBackgroundColor(bg_color)
  19.     mon.monitor.setTextColor(text_color)
  20.     mon.monitor.setCursorPos(x,y)
  21.     mon.monitor.write(text)
  22. end
  23.  
  24. function draw_text_right(mon, offset, y, text, text_color, bg_color)
  25.     mon.monitor.setBackgroundColor(bg_color)
  26.     mon.monitor.setTextColor(text_color)
  27.     mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
  28.     mon.monitor.write(text)
  29. end
  30.  
  31. function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color)
  32.     draw_text(mon, x, y, text1, text1_color, bg_color)
  33.     draw_text_right(mon, offset, y, text2, text2_color, bg_color)
  34. end
  35.  
  36. local reactor_info
  37.  
  38. function update()
  39.     while true do
  40.         clear(mon)
  41.        
  42.         --terminal
  43.         reactor_info = reactor.getReactorInfo()
  44.         for k, v in pairs (reactor_info) do
  45.             print(k.. ": ".. v)
  46.         end
  47.  
  48.         --monitor
  49.         draw_text(mon, 2, 2, "DR H", colors.white, colors.black)
  50.         if reactor_info.status == "online" then
  51.             draw_text(mon, 2, 3, "  ON", colors.lime, colors.gray)
  52.         elseif reactor_info.status == "offline" then
  53.             draw_text(mon, 2, 3, " OFF", colors.red, colors.gray)
  54.         elseif reactor_info.status == "stopping" then
  55.             draw_text(mon, 2, 3, "STOP", colors.orange, colors.gray)
  56.         elseif reactor_info.status == "charging" or reactor_info.status == "charged"then
  57.             draw_text(mon, 2, 3, "  CH", colors.blue, colors.gray)
  58.         end
  59.  
  60.         local fuelPercent, fuelColor
  61.         fuelPercent = 100 - math.ceil(reactor_info.fuelConversion / reactor_info.maxFuelConversion * 10000)*.01
  62.         fuelColor = colors.gray
  63.         if fuelPercent > 40 then fuelColor = colors.green end
  64.         if fuelPercent <= 40 and fuelPercent > 20 then fuelColor = colors.yellow end
  65.         if fuelPercent <= 20 and fuelPercent > 11 then fuelColor = colors.orange end
  66.         if fuelPercent <= 11 then fuelColor = colors.red end
  67.    
  68.         if fuelPercent < 90 then draw_text(mon, 3, 5, "  ", fuelColor, colors.gray)
  69.                             else draw_text(mon, 3, 5, "  ", fuelColor, fuelColor) end
  70.         if fuelPercent < 70 then draw_text(mon, 3, 6, "  ", fuelColor, colors.gray)
  71.                             else draw_text(mon, 3, 6, "  ", fuelColor, fuelColor) end
  72.         if fuelPercent < 50 then draw_text(mon, 3, 7, "  ", fuelColor, colors.gray)
  73.                             else draw_text(mon, 3, 7, "  ", fuelColor, fuelColor) end
  74.         if fuelPercent < 30 then draw_text(mon, 3, 8, "  ", fuelColor, colors.gray)
  75.                             else draw_text(mon, 3, 8, "  ", fuelColor, fuelColor) end
  76.         if fuelPercent < 11 then draw_text(mon, 3, 9, "__", fuelColor, colors.gray)
  77.                             else draw_text(mon, 3, 9, "__", fuelColor, fuelColor) end
  78.  
  79.         draw_text_right(mon, 0, 11, math.floor(fuelPercent) .. " %", fuelColor, colors.black)
  80.  
  81.         sleep(0.1)
  82.     end
  83. end
  84.  
  85. parallel.waitForAny(update)
Add Comment
Please, Sign In to add comment