Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CONFIG_FILE = "slave.cfg"
- local MODEM_SIDE = "bottom"
- local config = {
- routes = {
- green = { activeSides = {}, inactiveSides = {} },
- blue = { activeSides = {}, inactiveSides = {} },
- red = { activeSides = {}, inactiveSides = {} },
- purple = { activeSides = {}, inactiveSides = {} },
- }
- }
- local routeKeys = { "green", "blue", "red", "purple" }
- local routeNames = {
- green = "Zold",
- blue = "Kek",
- red = "Piros",
- purple = "Lila",
- }
- local function loadConfig()
- if not fs.exists(CONFIG_FILE) then return end
- local h = fs.open(CONFIG_FILE, "r")
- local raw = h.readAll()
- h.close()
- local t = textutils.unserialize(raw)
- if type(t) == "table" then config = t end
- end
- local function saveConfig()
- local h = fs.open(CONFIG_FILE, "w")
- h.write(textutils.serialize(config))
- h.close()
- end
- local function splitSides(text)
- local out = {}
- for part in string.gmatch((text or ""), "[^,%s]+") do
- if part ~= MODEM_SIDE then table.insert(out, part) end
- end
- return out
- end
- local function listSides(t)
- if not t or #t == 0 then return "(nincs)" end
- return table.concat(t, ",")
- end
- local function clearAll()
- for _, side in ipairs({ "top", "left", "right", "front", "back" }) do
- redstone.setOutput(side, false)
- end
- end
- local function pulse(list)
- clearAll()
- for _, side in ipairs(list or {}) do
- redstone.setOutput(side, true)
- end
- sleep(1)
- clearAll()
- end
- loadConfig()
- while true do
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- print("ROUTE SLAVE SETUP")
- print("=================")
- print("Computer ID: " .. os.getComputerID())
- print("Modem oldal: " .. MODEM_SIDE)
- print("Alaphelyzet: egyenes / nincs redstone")
- print("")
- for _, key in ipairs(routeKeys) do
- local r = config.routes[key]
- print(routeNames[key] .. " aktiv: " .. listSides(r.activeSides))
- print(routeNames[key] .. " egyenes: " .. listSides(r.inactiveSides))
- end
- print("")
- print("1 - Route szerkesztese")
- print("2 - Aktiv route teszt")
- print("3 - Egyenes teszt")
- print("4 - Mentes")
- print("5 - Kilepes")
- print("")
- write("> ")
- local cmd = read()
- if cmd == "1" then
- write("Route key (green/blue/red/purple): ")
- local key = read()
- if config.routes[key] then
- write("Aktiv oldalak (pl top,left): ")
- config.routes[key].activeSides = splitSides(read())
- write("Egyenes oldalak (uresen hagyhatod): ")
- config.routes[key].inactiveSides = splitSides(read())
- end
- elseif cmd == "2" then
- write("Route key (green/blue/red/purple): ")
- local key = read()
- if config.routes[key] then
- print("1 mp aktiv teszt")
- pulse(config.routes[key].activeSides)
- end
- elseif cmd == "3" then
- print("1 mp egyenes teszt")
- clearAll()
- sleep(1)
- elseif cmd == "4" then
- saveConfig()
- print("Mentve")
- sleep(1)
- elseif cmd == "5" then
- clearAll()
- term.clear()
- term.setCursorPos(1,1)
- print("Kilepes")
- break
- end
- end
Advertisement