Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("viewportAPI")
- os.loadAPI("buttonAPI")
- os.loadAPI("pbar")
- p = peripheral.wrap("top")
- pbar.SetPeripheral("top")
- rSide = "bottom"
- tresh = 0.9
- modem = peripheral.wrap("back")
- modem.open(137)
- redstone.setBundledOutput(rSide, 0)
- viewport = viewportAPI.new({term = p})
- flagStorage = true
- flagDoor = false
- flagReactor = false
- flagProgressBar = false
- buttonReactor = buttonAPI.new({
- x = 5, y = 2, width = 19, height = 5, text = "Reacteur", textColor = colors.white, backgroundColor = colors.red
- })
- viewport:addElement(buttonReactor)
- buttonDoor = buttonAPI.new({
- x = 5, y = 9, width = 19, height = 5, text = "Porte", textColor = colors.white, backgroundColor = colors.red
- })
- viewport:addElement(buttonDoor)
- viewport:redraw()
- function clickHandlerDoor(element, posX, posY)
- flagDoor = not flagDoor
- element.backgroundColor = flagDoor and colors.green or colors.red
- bundleHandle()
- return true
- end
- function clickHandlerReactor(element, posX, posY)
- if not flagStorage then
- flagReactor = not flagReactor
- element.backgroundColor = flagReactor and colors.green or colors.red
- bundleHandle()
- end
- return true
- end
- function boolToNum(bool)
- return bool and 1 or 0
- end
- function bundleHandle()
- redstone.setBundledOutput(rSide,boolToNum(flagReactor)*boolToNum(not flagStorage)*colors.white+boolToNum(flagDoor)*colors.red)
- end
- buttonDoor.callback = clickHandlerDoor
- buttonReactor.callback = clickHandlerReactor
- while true do
- event, side, param1, param2, param3 = os.pullEvent()
- if event == "monitor_touch" then
- viewport:handleClick(param1, param2)
- if flagProgressBar then
- pbar.DrawToPeripheral("Energie")
- end
- elseif event == "modem_message" then
- stored = param3[1]
- capacity = param3[2]
- ratio = stored/capacity
- if ratio > tresh then
- flagStorage = true
- buttonReactor.backgroundColor = colors.purple
- viewport:redraw()
- bundleHandle()
- elseif flagStorage then
- flagStorage = false
- buttonReactor.backgroundColor = flagReactor and colors.green or colors.red
- viewport:redraw()
- bundleHandle()
- end
- if not flagProgressBar then
- flagProgressBar = true
- pbar.SetTable("Energie",capacity,stored,5,24,20)
- pbar.DrawToPeripheral("Energie")
- else
- pbar.SetCurValue("Energie",stored)
- pbar.DrawToPeripheral("Energie")
- end
- end
- end
Add Comment
Please, Sign In to add comment