Advertisement
Scarjit

Untitled

Oct 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. local reactor = peripheral.wrap("back")
  2. local monitor = peripheral.wrap("monitor_0")
  3.  
  4. if reactor == nil then
  5. error("No reactor found")
  6. end
  7. if monitor == nil then
  8. error("No monitor found")
  9. end
  10.  
  11. local energyStored = 0
  12. local energyProduced = 0
  13. local energyCapacity = 0
  14. local fillPercentage = 0
  15. local batteryWindowBG = window.create(monitor, 2, 2, 5, 10, true)
  16. local batteryWindowFG = window.create(monitor, 2, 2, 5, 5, true)
  17.  
  18. batteryWindowBG.setBackgroundColor(colours.red)
  19. batteryWindowBG.clear()
  20. batteryWindowBG.redraw()
  21.  
  22. batteryWindowFG.setBackgroundColor(colours.green)
  23. batteryWindowFG.clear()
  24. batteryWindowFG.redraw()
  25.  
  26. local function round(num, numDecimalPlaces)
  27. local mult = 10^(numDecimalPlaces or 2)
  28. return math.floor(num * mult + 0.5) / mult
  29. end
  30.  
  31. local function UpdateReactorStats()
  32. local stats = reactor.getEnergyStats()
  33. energyStored = stats["energyStored"]
  34. energyProduced = stats["energyProducedLastTick"]
  35. energyCapacity = stats["energyCapacity"]
  36. if energyStored == 0 then
  37. fillPercentage = 0
  38. else
  39. fillPercentage = energyStored / energyCapacity * 100
  40. end
  41. end
  42.  
  43. local function ClearScreen()
  44. term.setBackgroundColor(colours.black)
  45. term.clear()
  46. term.setCursorPos(1,1)
  47. end
  48.  
  49. local function ClearMonitor()
  50. monitor.setBackgroundColor(colours.black)
  51. monitor.clear()
  52. monitor.setCursorPos(1,1)
  53. end
  54.  
  55. local function UpdateMonitorStats()
  56. batteryWindowFG.reposition(2, 2, 5, round(fillPercentage/10, 0))
  57.  
  58. batteryWindowBG.redraw()
  59. batteryWindowFG.redraw()
  60. --monitor.write(fillPercentage)
  61. end
  62.  
  63. ClearScreen()
  64. ClearMonitor()
  65. UpdateReactorStats()
  66.  
  67. while true do
  68. os.sleep(0.2)
  69. UpdateReactorStats()
  70. ClearScreen()
  71. ClearMonitor()
  72. UpdateMonitorStats()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement