Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor_pos = nil
- sides = {"top" , "bottom" , "front" , "left" , "right" , "back"}
- reactor_file = "reactor.txt"
- state_file = "state.txt"
- command = nil
- id = nil
- function clear()
- term.setBackgroundColor(colors.green)
- term.clear()
- end
- function nextLine()
- local hx, hy = term.getCursorPos()
- term.setCursorPos(hx, hy + 1)
- end
- function setReactorPos()
- clear()
- term.setCursorPos(15, 7)
- term.write("Select reactor possition")
- term.setCursorPos(15, 8)
- term.write("1: Top, 2: Bot, 3: Front")
- term.setCursorPos(15, 9)
- term.write("4: Left, 5: Right, 6: Back")
- term.setCursorPos(15, 10)
- reactor_pos = tonumber(read())
- local file = fs.open(reactor_file, "w")
- file.write(reactor_pos)
- file.close()
- end
- function saveStateOnDisk()
- local file = fs.open(state_file, "w")
- file.write(command)
- file.close()
- end
- function loadStateFromDisk()
- if fs.exists(state_file) then
- local file = fs.open(state_file, "r")
- result = tostring(file.readLine())
- file.close()
- return result
- end
- return nil
- end
- function DetectPeripheral(name)
- for i = 1, 6 do
- if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == name then
- return sides[i]
- end
- end
- return nil
- end
- function rednetControll()
- while true do
- wifi = DetectPeripheral("modem")
- rednet.open(wifi)
- a, b, c = rednet.receive()
- id = a
- command = b
- return b;
- end
- end
- function keyControll()
- while true do
- local sEvent, param = os.pullEvent("monitor_touch")
- if redstone.getOutput(sides[reactor_pos]) == true then
- command = "stop"
- return 0
- else
- command = "start"
- return 0
- end
- end
- end
- function Menu()
- clear()
- term.setCursorPos(screen_width/4 , screen_height * 0.3)
- local temp = tostring(sides[reactor_pos])
- if redstone.getOutput(temp) then
- term.write("ALL WORKS!")
- else
- term.write("NOTHING WORKS!")
- end
- term.setCursorPos(screen_width/4 ,1 + (screen_height * 0.3) )
- term.write("REACTOR IS ON "..sides[reactor_pos])
- term.setCursorPos(screen_width/4 ,2 + (screen_height * 0.3) )
- term.write("PRESS X TO CHANGE")
- return 0
- end
- screen = peripheral.wrap(DetectPeripheral("monitor"))
- --logout protection, reactor position
- if not fs.exists(reactor_file) then
- setReactorPos()
- else
- local file = fs.open(reactor_file, "r")
- reactor_pos = tonumber(file.readLine())
- file.close()
- end
- --logout protection, reactor output
- command = loadStateFromDisk()
- if command == "start" then
- redstone.setOutput(sides[reactor_pos], true)
- end
- --mainloop
- term.redirect(screen)
- screen_width, screen_height = screen.getSize()
- while true do
- Menu()
- parallel.waitForAny(rednetControll, keyControll)
- if command == "start" then
- redstone.setOutput(sides[reactor_pos], true)
- saveStateOnDisk()
- if not id == nil then
- rednet.send(id, true)
- id = nil
- end
- elseif command == "stop" then
- redstone.setOutput(sides[reactor_pos], false)
- saveStateOnDisk()
- if not id == nil then
- rednet.send(id, false)
- id = nil
- end
- elseif command == "state" then
- rednet.send(id, redstone.getOutput(sides[reactor_pos]))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement