Advertisement
Guest User

reactor.lua

a guest
Aug 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local buttonAPI = require("buttonAPI")
  2. local component = require("component")
  3. local term = require("term")
  4. local event = require("event")
  5. local math = require("math")
  6. local br = component.br_reactor
  7. local mon = component.gpu
  8. local w, h = mon.getResolution()
  9. local isCooldown = false
  10. local timerID = nil
  11.  
  12. function regulate()
  13.   local bufferCutoff = 500000
  14.   if br.getEnergyStored() > bufferCutoff and br.getActive() == true then
  15.     powerOff()
  16.     isCooldown = false
  17.   elseif br.getEnergyStored() <= bufferCutoff and isCooldown == false then
  18.     isCooldown = true
  19.     powerOn()
  20.   end
  21. end
  22.  
  23. function resetCooldown()
  24.   isCooldown = false
  25. end
  26.  
  27. function fillTable()
  28.   buttonAPI.setTable("Enable", powerOn, 1, 3, (w / 2 - 1.5), (h / 2))
  29.   buttonAPI.setTable("Disable", powerOff, (w / 2 + 1.5), 3, w, (h / 2))
  30.   buttonAPI.setTable("Auto Control", autoControl, 1, (h / 2 + 2), w, (h / 2 + 15))
  31.   buttonAPI.screen()
  32. end
  33.  
  34. function getClick()
  35.   local _,_, x, y = event.pull("touch")
  36.   buttonAPI.checkxy(x, y)
  37. end
  38.  
  39. function powerOn()
  40.   buttonAPI.toggleButton("Enable")
  41.   buttonAPI.toggleButton("Disable")
  42.   br.setActive(true)
  43. end
  44.  
  45. function powerOff()
  46.   buttonAPI.toggleButton("Disable")
  47.   buttonAPI.toggleButton("Enable")
  48.   br.setActive(false)
  49. end
  50.  
  51. function autoControl()
  52.   buttonAPI.toggleButton("Auto Control", 0x00AA00, 0x0000DD)
  53.   if timerID == nil then
  54.     timerID = event.timer(3, regulate, math.huge)
  55.   else
  56.     event.cancel(timerID)
  57.     timerID = nil
  58.   end
  59. end
  60.  
  61. term.clear()
  62. fillTable()
  63. buttonAPI.heading("Reactor Control")
  64. if br.getActive() == true then
  65.   buttonAPI.toggleButton("Enable")
  66. else
  67.   buttonAPI.toggleButton("Disable")
  68. end
  69. while true do
  70.   getClick()
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement