tommy2805

Config editor reactor client

Oct 25th, 2025 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. local configPath = "config"
  2.  
  3. -- =========================
  4. -- FUNZIONI DI SUPPORTO
  5. -- =========================
  6. local function loadConfig()
  7. if not fs.exists(configPath) then return nil end
  8. local f = fs.open(configPath, "r")
  9. local data = f.readAll()
  10. f.close()
  11. local func = loadstring(data)
  12. if func then return func() else error("Errore nel config") end
  13. end
  14.  
  15. local function saveConfig(cfg)
  16. local f = fs.open(configPath, "w")
  17. f.write("return " .. textutils.serialize(cfg))
  18. f.close()
  19. end
  20.  
  21. -- =========================
  22. -- MAIN
  23. -- =========================
  24. term.setTextColor(colors.cyan)
  25. print("=== Editor Configurazione Modulo Reattore ===")
  26. term.setTextColor(colors.white)
  27.  
  28. local config = loadConfig()
  29. if not config then
  30. print("Nessun file di configurazione trovato!")
  31. return
  32. end
  33.  
  34.  
  35. while true do
  36. print("\nCosa vuoi modificare?")
  37. print("[1] ID di questo reattore (attuale: " .. tostring(config.id) .. ")")
  38. print("[2] ID del server (attuale: " .. tostring(config.server_id) .. ")")
  39. print("[3] Lato output (attuale: " .. tostring(config.output_side) .. ")")
  40. print("[4] Intervallo aggiornamento (attuale: " .. tostring(config.update_interval) .. "s)")
  41. print("[5] Esci")
  42. write("> ")
  43. local choice = read()
  44.  
  45. if choice == "1" then
  46. local id
  47. repeat
  48. write("Nuovo ID reattore (numero): ")
  49. id = tonumber(read())
  50. if not id then print("Inserisci un numero valido!") end
  51. until id
  52. config.id = id
  53. print("ID reattore aggiornato.")
  54.  
  55. elseif choice == "2" then
  56. local server_id
  57. repeat
  58. write("Nuovo ID server (numero): ")
  59. server_id = tonumber(read())
  60. if not server_id then print("Inserisci un numero valido!") end
  61. until server_id
  62. config.server_id = server_id
  63. print("ID server aggiornato.")
  64.  
  65. elseif choice == "3" then
  66. local validSides = {left = true, right = true, top = true, bottom = true, front = true, back = true}
  67. repeat
  68. write("Nuovo lato per l'uscita (left/right/top/bottom/front/back): ")
  69. newSide = read()
  70. if not validSides[newSide] then print("Lato non valido!") end
  71. until validSides[newSide]
  72. config.output_side = newSide
  73. print("Lato output aggiornato.")
  74.  
  75. elseif choice == "4" then
  76. local n
  77. repeat
  78. write("Nuovo intervallo di aggiornamento (secondi): ")
  79. n = tonumber(read())
  80. if not n or n <= 0 then print("Inserisci un numero valido!") end
  81. until n and n > 0
  82. config.update_interval = n
  83. print("Intervallo aggiornamento impostato a " .. n .. "s.")
  84.  
  85. elseif choice == "5" then
  86. break
  87.  
  88. else
  89. print("Scelta non valida.")
  90. end
  91.  
  92. -- Salvataggio automatico
  93. saveConfig(config)
  94. print("\nConfig salvata.")
  95. end
  96.  
  97. term.setTextColor(colors.green)
  98. print("Uscita dall’editor.")
  99.  
Advertisement
Add Comment
Please, Sign In to add comment