Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local configPath = "config"
- -- =========================
- -- FUNZIONI DI SUPPORTO
- -- =========================
- local function loadConfig()
- if not fs.exists(configPath) then return nil end
- local f = fs.open(configPath, "r")
- local data = f.readAll()
- f.close()
- local func = loadstring(data)
- if func then return func() else error("Errore nel config") end
- end
- local function saveConfig(cfg)
- local f = fs.open(configPath, "w")
- f.write("return " .. textutils.serialize(cfg))
- f.close()
- end
- -- =========================
- -- MAIN
- -- =========================
- term.setTextColor(colors.cyan)
- print("=== Editor Configurazione Modulo Reattore ===")
- term.setTextColor(colors.white)
- local config = loadConfig()
- if not config then
- print("Nessun file di configurazione trovato!")
- return
- end
- while true do
- print("\nCosa vuoi modificare?")
- print("[1] ID di questo reattore (attuale: " .. tostring(config.id) .. ")")
- print("[2] ID del server (attuale: " .. tostring(config.server_id) .. ")")
- print("[3] Lato output (attuale: " .. tostring(config.output_side) .. ")")
- print("[4] Intervallo aggiornamento (attuale: " .. tostring(config.update_interval) .. "s)")
- print("[5] Esci")
- write("> ")
- local choice = read()
- if choice == "1" then
- local id
- repeat
- write("Nuovo ID reattore (numero): ")
- id = tonumber(read())
- if not id then print("Inserisci un numero valido!") end
- until id
- config.id = id
- print("ID reattore aggiornato.")
- elseif choice == "2" then
- local server_id
- repeat
- write("Nuovo ID server (numero): ")
- server_id = tonumber(read())
- if not server_id then print("Inserisci un numero valido!") end
- until server_id
- config.server_id = server_id
- print("ID server aggiornato.")
- elseif choice == "3" then
- local validSides = {left = true, right = true, top = true, bottom = true, front = true, back = true}
- repeat
- write("Nuovo lato per l'uscita (left/right/top/bottom/front/back): ")
- newSide = read()
- if not validSides[newSide] then print("Lato non valido!") end
- until validSides[newSide]
- config.output_side = newSide
- print("Lato output aggiornato.")
- elseif choice == "4" then
- local n
- repeat
- write("Nuovo intervallo di aggiornamento (secondi): ")
- n = tonumber(read())
- if not n or n <= 0 then print("Inserisci un numero valido!") end
- until n and n > 0
- config.update_interval = n
- print("Intervallo aggiornamento impostato a " .. n .. "s.")
- elseif choice == "5" then
- break
- else
- print("Scelta non valida.")
- end
- -- Salvataggio automatico
- saveConfig(config)
- print("\nConfig salvata.")
- end
- term.setTextColor(colors.green)
- print("Uscita dall’editor.")
Advertisement
Add Comment
Please, Sign In to add comment