tman1123

ReceiverSetup.lua

Apr 1st, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- receiver_setup.lua
  2. local configFileName = "displays.txt"
  3.  
  4. function saveConfig(config)
  5.     local file = fs.open(configFileName, "w")
  6.     file.write(textutils.serialize(config))
  7.     file.close()
  8.     print("Configuration saved.")
  9. end
  10.  
  11. function loadConfig()
  12.     if fs.exists(configFileName) then
  13.         local file = fs.open(configFileName, "r")
  14.         local config = textutils.unserialize(file.readAll())
  15.         file.close()
  16.         return config
  17.     else
  18.         return {displays = {}}
  19.     end
  20. end
  21.  
  22. local config = loadConfig()
  23.  
  24. function drawMenu()
  25.     term.clear()
  26.     term.setCursorPos(1, 1)
  27.     print("Displays Setup")
  28.     print("Configured Displays:")
  29.     for i, display in ipairs(config.displays) do
  30.         print(i .. ". Side: " .. display.side .. ", Type: " .. display.type)
  31.     end
  32.     print("\n1. Add Display")
  33.     print("2. Edit Display")
  34.     print("3. Delete Display")
  35.     print("4. Exit")
  36.     print("5. Exit & Run")
  37. end
  38.  
  39. function addDisplay()
  40.     local display = {}
  41.     print("Enter the side the display is connected to (left, right, top, bottom, front, back):")
  42.     display.side = read()
  43.     print("Do you want to display the floor number or name? (Enter 'number' or 'name'):")
  44.     display.type = read()
  45.     table.insert(config.displays, display)
  46.     saveConfig(config)
  47. end
  48.  
  49. function editDisplay()
  50.     print("Enter the index of the display to edit:")
  51.     local index = tonumber(read())
  52.     if config.displays[index] then
  53.         print("Enter new side (currently " .. config.displays[index].side .. "):")
  54.         config.displays[index].side = read()
  55.         print("Enter new type ('number' or 'name', currently " .. config.displays[index].type .. "):")
  56.         config.displays[index].type = read()
  57.         saveConfig(config)
  58.     else
  59.         print("Invalid index.")
  60.     end
  61. end
  62.  
  63. function deleteDisplay()
  64.     print("Enter the index of the display to delete:")
  65.     local index = tonumber(read())
  66.     if index and index >= 1 and index <= #config.displays then
  67.         table.remove(config.displays, index)
  68.         saveConfig(config)
  69.     else
  70.         print("Invalid index.")
  71.     end
  72. end
  73.  
  74. function mainMenu()
  75.     drawMenu()
  76.     local choice = read()
  77.     if choice == "1" then
  78.         addDisplay()
  79.     elseif choice == "2" then
  80.         editDisplay()
  81.     elseif choice == "3" then
  82.         deleteDisplay()
  83.     elseif choice == "4" then
  84.         return false -- Exit the program
  85.     elseif choice == "5" then
  86.         shell.run('receiver')
  87.     end
  88.     return true
  89. end
  90.  
  91. while mainMenu() do
  92.     -- Loop back to the main menu after each action
  93. end
  94.  
Add Comment
Please, Sign In to add comment