Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings Writer for Storage System (mit Taskliste)
- -- Platziert über dem Disk Drive mit der "Settings"-Disk
- local SETTINGS_LABEL = "Settings"
- local COORD_FILE = "initial_coords.txt"
- local TASK_FILE = "task_list.txt" -- zentrale Taskliste auf der Settings-Disk
- -- Funktion: Hole Disk-Laufwerk mit Label "Settings"
- function getSettingsDisk()
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == SETTINGS_LABEL then
- return disk, disk.getMountPath()
- end
- end
- end
- return nil, nil
- end
- -- Funktion: Überprüft, ob initial_coords.txt bereits existiert
- function coordsFileExists()
- local _, path = getSettingsDisk()
- if not path then return false end
- return fs.exists(fs.combine(path, COORD_FILE))
- end
- -- Funktion: Fragt den Nutzer nach einer Koordinate (in Form "x y z")
- function askForCoords(promptText)
- while true do
- print(promptText)
- local input = read()
- local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
- if x and y and z then
- return tonumber(x), tonumber(y), tonumber(z)
- else
- print("Ungültiges Format. Bitte erneut eingeben als: x y z")
- end
- end
- end
- -- Funktion: Speichert die beiden Koordinaten in initial_coords.txt
- function saveInitialCoords(x1, y1, z1, x2, y2, z2)
- local _, path = getSettingsDisk()
- if not path then error("Settings-Disk nicht gefunden!") end
- local fullPath = fs.combine(path, COORD_FILE)
- local file = fs.open(fullPath, "w")
- file.writeLine(string.format("%d,%d,%d", x1, y1, z1))
- file.writeLine(string.format("%d,%d,%d", x2, y2, z2))
- file.close()
- print("Koordinaten erfolgreich gespeichert.")
- end
- -- Funktion: Lädt Taskliste von Disk
- function loadTaskList(filePath)
- if not fs.exists(filePath) then return {} end
- local file = fs.open(filePath, "r")
- local content = file.readAll()
- file.close()
- local data = textutils.unserialize(content)
- return data or {}
- end
- -- Funktion: Fügt Task zur Liste hinzu und speichert sie wieder
- function appendTaskToList(filePath, taskData)
- local tasks = loadTaskList(filePath)
- table.insert(tasks, taskData)
- local file = fs.open(filePath, "w")
- file.write(textutils.serialize(tasks))
- file.close()
- print("Neuer Task wurde erfolgreich gespeichert.")
- end
- -- Funktion: Wiederholt Menü für Task-Erstellung
- function showTaskMenu(filePath)
- while true do
- print()
- print("Was möchtest du tun?")
- print("[1] Kisten per Task erstellen lassen")
- print("[2] Bereits vorhandene Kisten initialisieren")
- print("[3] Bestandsaufnahme durchführen")
- print("[4] Beenden")
- write("Auswahl: ")
- local choice = read()
- if choice == "1" or choice == "2" then
- local x, y, z = askForCoords("Position der ersten Kiste eingeben (x y z):")
- local taskType = (choice == "1") and "create_chests" or "initialize_chests"
- local task = {
- taskType = taskType,
- x = x,
- y = y,
- z = z
- }
- appendTaskToList(filePath, task)
- elseif choice == "3" then
- local task = {
- taskType = "check_inventory"
- }
- appendTaskToList(filePath, task)
- elseif choice == "4" then
- print("Beende das Programm.")
- break
- else
- print("Ungültige Eingabe. Bitte wähle 1-4.")
- end
- end
- end
- -- === Hauptprogramm ===
- print("Starte Settings-Setup...")
- local _, path = getSettingsDisk()
- while not path do
- print("Warte auf eingelegte Settings-Disk...")
- sleep(1)
- _, path = getSettingsDisk()
- end
- local taskFilePath = fs.combine(path, TASK_FILE)
- if coordsFileExists() then
- print("initial_coords.txt existiert bereits.")
- else
- print("Keine initial_coords.txt gefunden. Bitte Koordinaten eingeben.")
- local x1, y1, z1 = askForCoords("Start-Koordinate eingeben (x y z):")
- local x2, y2, z2 = askForCoords("End-Koordinate eingeben (x y z):")
- print()
- print("Sollen die Kisten jetzt manuell erstellt werden oder per Task?")
- print("[1] Kisten existieren bereits")
- print("[2] Kisten sollen per Task erstellt werden")
- write("Auswahl (1 oder 2): ")
- local choice = read()
- if choice == "2" then
- local task = {
- taskType = "create_chests",
- x = x1,
- y = y1,
- z = z1
- }
- appendTaskToList(taskFilePath, task)
- else
- print("Kein Task erstellt. Es wird davon ausgegangen, dass die Kisten vorhanden sind.")
- end
- saveInitialCoords(x1, y1, z1, x2, y2, z2)
- end
- -- Starte interaktives Menü zur Erstellung weiterer Tasks
- showTaskMenu(taskFilePath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement