Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- clear the terminal
- term.clear()
- term.setCursorPos(1, 1)
- rednet.open("back")
- function printTable(table, offset)
- offset = offset or 0
- if (type(table) ~= "table") then
- print("Not a table")
- return
- end
- print(string.rep(" ", offset) .. "{")
- for key, value in pairs(table) do
- if(type(value) == "table") then
- write(string.rep(" ", offset + 1) .. key .. " => ")
- printTable(value, offset + 1)
- else
- print(string.rep(" ", offset + 1) .. key .. " => " .. value .. ",")
- end
- end
- print(string.rep(" ", offset) .. "}")
- end
- dofile("reactor.lua")
- -- load the config file
- config_file = io.open("config", "r")
- local config = textutils.unserialize(config_file:read("*a"))
- config_file:close()
- monitor = peripheral.wrap(config["monitor_side"])
- monitor.clear()
- monitor.setTextScale(1.5)
- local monitor_width, monitor_height = monitor.getSize()
- local offsets = {
- { ["xoffset"] = 0, ["yoffset"] = 0 },
- { ["xoffset"] = 25, ["yoffset"] = 0 },
- { ["xoffset"] = 0, ["yoffset"] = 9 },
- { ["xoffset"] = 25, ["yoffset"] = 9 },
- }
- -- create reactors
- local reactors = {}
- for i=1,4 do
- reactors[i] = Reactor(config["reactors"][i]["name"], config["reactors"][i]["id"], offsets[i]["xoffset"], offsets[i]["yoffset"])
- end
- -- draw the dividers
- function drawDividers()
- -- set colors
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- -- draw vertical dividers
- for i = 1, monitor_height do
- monitor.setCursorPos(24, i)
- monitor.write("||")
- end
- -- draw horizontal divider
- for i = 1, monitor_width do
- monitor.setCursorPos(i, 9)
- monitor.write("-")
- end
- -- make the intersection look pretty
- monitor.setCursorPos(24, 9)
- monitor.write("++")
- end
- -- Draws the display
- function drawDisplay()
- parallel.waitForAll(reactors[1].update, reactors[2].update, reactors[3].update, reactors[4].update)
- for num, reactor in pairs(reactors) do
- reactor.display(monitor)
- end
- end
- -- sleep
- function doSleep()
- os.sleep(config["sleep_time"])
- end
- -- wait for a touch on the monitor
- function doTouchEvent()
- local event, side, xCoord, yCoord = os.pullEvent("monitor_touch")
- for num, reactor in pairs(reactors) do
- reactor.handleTouch(xCoord, yCoord)
- end
- end
- -- main run loop
- drawDividers()
- while true do
- drawDisplay()
- parallel.waitForAny(doTouchEvent, doSleep)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement