Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonitorSide = "left"
- BundledWire1 = "front"
- BundledWire2 = "back"
- NamenNummer = 0
- mon = peripheral.wrap(MonitorSide)
- redstone.setBundledOutput(BundledWire1, 0)
- mon.setBackgroundColor(colors.black)
- mon.setTextScale(1)
- mon.clear()
- SystemStart = "JA"
- function getMonitorSize()
- monitor = peripheral.wrap(MonitorSide)
- MonitorWidth, MonitorHeight = monitor.getSize()
- MonitorMid = math.floor(MonitorWidth / 2)
- print("Monitor Mitte: " .. MonitorMid)
- print("Monitor Breite: " .. MonitorWidth)
- print("Monitor Höhe: " .. MonitorHeight)
- end
- function calc_color(color)
- return math.pow(2, color - 1)
- end
- function msg(gap, line, color, groundb, text)
- mon.setBackgroundColor(calc_color(groundb))
- mon.setCursorPos(gap,line)
- mon.setTextColor(calc_color(color))
- text = mon.write(text)
- end
- function clearMonitor()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.black)
- mon.clear()
- end
- function NameChangeMonitor()
- local dateiname = "NameSave"
- local function ladeNamen()
- local namenListe = {}
- if fs.exists(dateiname) then
- local datei = fs.open(dateiname, "r")
- local i = 1
- while true do
- local zeile = datei.readLine()
- if zeile == nil then break end
- namenListe[i] = zeile
- i = i + 1
- end
- datei.close()
- else
- print("Datei nicht gefunden.")
- end
- return namenListe
- end
- local function speichereNamen(namenListe)
- local datei = fs.open(dateiname, "w")
- for _, zeile in ipairs(namenListe) do
- datei.writeLine(zeile)
- end
- datei.close()
- end
- local function aendereNamen()
- file = fs.open("local" , "r")
- NamenNummer = file.readLine()
- file.close()
- local namenListe = ladeNamen()
- if NamenNummer == "ON" then
- neuerName = "ON"
- elseif NamenNummer == "OFF" then
- neuerName = "OFF"
- else
- NamenNummer = tonumber(NamenNummer)
- neuerName = read()
- end
- -- Ersetze den Namen in der Liste
- namenListe[NamenNummer] = "Wert_" .. NamenNummer .. ": " .. neuerName
- -- Speichere die geåA4nderte Liste zuråBCck in die Datei
- speichereNamen(namenListe)
- end
- aendereNamen(NamenNummer)
- end
- dateiname = "NameSave"
- function ladeNamen()
- local namenListe = {}
- if fs.exists(dateiname) then
- local datei = fs.open(dateiname, "r")
- local i = 1
- while true do
- local zeile = datei.readLine()
- if zeile == nil then break end
- namenListe[i] = zeile
- i = i + 1
- end
- datei.close()
- end
- return namenListe
- end
- function extrahiereName(zeile)
- local _, _, name = string.find(zeile, ": (.+)")
- return name
- end
- function setzeDynamischeVariablen(namenListe)
- local variablenTabelle = {}
- for i = 1, #namenListe do
- local nameKey = "Wert_" .. i
- local extrahierterName = extrahiereName(namenListe[i])
- variablenTabelle[nameKey] = extrahierterName
- end
- return variablenTabelle
- end
- namenListe = ladeNamen()
- local variablenTabelle = setzeDynamischeVariablen(namenListe)
- print("alle Namen eingelesen")
- function mainStatus()
- -- VariablenTabelle neu laden bei jedem Schleifendurchlauf
- local namenListe = ladeNamen()
- local variablenTabelle = setzeDynamischeVariablen(namenListe)
- local currentLine = 6 -- Startzeile bleibt konstant
- for i = 50, 74 do
- local xpos = 3 + ((i - 50) % 5)
- if variablenTabelle["Wert_" .. i] == "ON" then
- msg(xpos, currentLine, 16, 6, " ")
- else
- msg(xpos, currentLine, 16, 15, " ")
- end
- -- Wenn 5 in einer Reihe -> Nächste Zeile
- if (i - 50 + 1) % 5 == 0 then
- currentLine = currentLine + 3 -- Zeilenwechsel
- end
- end
- end
- function Editor1()
- --Editor öffnen
- while true do
- -- VariablenTabelle neu laden bei jedem Schleifendurchlauf
- local namenListe = ladeNamen()
- local variablenTabelle = setzeDynamischeVariablen(namenListe)
- mon.setCursorPos(1,1)
- clearMonitor()
- msg(MonitorWidth,01,08,16,"x")
- msg(03,02,05,16,"Willkommen im Editor")
- for i = 1,MonitorWidth do
- msg(i,04,05,16,"~")
- end
- msg(03,07,09,16,"Ab hier geht alles im PC weiter")
- term.setCursorPos(1,1)
- term.clear()
- print("Editor:")
- print("")
- print("0 = Editor beenden")
- print("1 = Überschrift: Name ändern")
- print("2 = Kategorien: Name ändern")
- print("3 = Namen in den Kategorien ändern")
- print(" ")
- Eingabe = read()
- if Eingabe == "0" then
- os.reboot()
- elseif Eingabe == "1" then
- print("Alter Name: " .. variablenTabelle["Wert_100"])
- print("Neuer Name:")
- NamenNummer = 100
- elseif Eingabe == "2" then
- print("Alte Namen:")
- for i = 1,5 do
- print(i .. "= " .. variablenTabelle["Wert_" .. i])
- end
- NamenNummer = read()
- print("Neuer Name:")
- elseif Eingabe == "3" then
- print("Kategorie Nummer wählen:")
- for i = 1,5 do
- print(i .. "= " .. variablenTabelle["Wert_" .. i])
- end
- EingabeKategorie = read()
- if EingabeKategorie >= "1" and EingabeKategorie <= "5" then
- print("Functions Nummer wählen:")
- local startIndex = (tonumber(EingabeKategorie) - 1) * 5 + 6
- for i = 0, 4 do
- print((i + 1) .. " = " .. variablenTabelle["Wert_" .. (startIndex + i)])
- end
- EingabeFunktion = tonumber(read())
- if EingabeFunktion >= 1 and EingabeFunktion <= 5 then
- NamenNummer = startIndex + (EingabeFunktion - 1)
- print("Neuer Name:")
- end
- end
- end
- file = fs.open("local" , "w")
- file.write(NamenNummer)
- file.close()
- NameChangeMonitor()
- sleep(0.5)
- end
- end
- function main()
- --Überschrift
- mon.setCursorPos(1,1)
- clearMonitor()
- msg(MonitorWidth,01,08,16,"x")
- msg(02,02,05,16," " .. variablenTabelle["Wert_100"] .. " ")
- for i = 1,MonitorWidth do
- msg(i,04,05,16,"~")
- end
- --Statusanzeige
- mainStatus()
- --Kategorien
- msg(10,06,01,12," " .. variablenTabelle["Wert_1"] .. " ")
- msg(10,09,01,12," " .. variablenTabelle["Wert_2"] .. " ")
- msg(10,12,01,12," " .. variablenTabelle["Wert_3"] .. " ")
- msg(10,15,01,12," " .. variablenTabelle["Wert_4"] .. " ")
- msg(10,18,01,12," " .. variablenTabelle["Wert_5"] .. " ")
- local event, button, X, Y = os.pullEvent("monitor_touch")
- if (X == MonitorWidth or X == MonitorWidth - 1) and (Y == 1 or Y == 2) then
- Editor1()
- else
- --Katergorie öffnen
- local values = { [6] = "Wert_1", [9] = "Wert_2", [12] = "Wert_3", [15] = "Wert_4", [18] = "Wert_5" }
- if X >= 10 and values[Y] then
- file = fs.open("local", "w")
- file.write(values[Y])
- file.close()
- mon.setCursorPos(1,1)
- clearMonitor()
- Katergory()
- end
- end
- main()
- end
- function WireUpdate()
- local namenListe = ladeNamen()
- local variablenTabelle = setzeDynamischeVariablen(namenListe)
- -- Liste der Farben
- local colors = {
- colors.white,
- colors.orange,
- colors.magenta,
- colors.lightBlue,
- colors.yellow,
- colors.lime,
- colors.pink,
- colors.gray,
- colors.lightGray,
- colors.cyan,
- colors.purple,
- colors.blue,
- colors.brown,
- colors.green,
- colors.red,
- colors.black
- }
- local farbenAnzahl = 16 -- Anzahl der Farben (16)
- if SystemStart == "JA" then
- print("Systemstart : JA")
- for i = 50, 74, 1 do
- if variablenTabelle["Wert_" .. i] == "ON" then
- local farbeIndex = ((i - 50) % farbenAnzahl) + 1
- local farbe = colors[farbeIndex]
- if farbeIndex <= 16 then
- -- Die ersten 16 Farben gehen an BundledWire1
- sleep(0.5)
- redstone.setBundledOutput(BundledWire1, redstone.getBundledOutput(BundledWire1) + farbe)
- else
- -- Restliche Farben gehen an BundledWire2
- sleep(0.5)
- redstone.setBundledOutput(BundledWire2, redstone.getBundledOutput(BundledWire2) + farbe)
- end
- end
- end
- SystemStart = "NEIN"
- print("Systemstart : JA -> NEIN")
- elseif SystemStart == "NEIN" then
- print(" ")
- print("Systemstart : NEIN")
- file = fs.open("local2" , "r")
- localWert = file.readLine()
- file.close()
- for i = 50, 74, 1 do
- local farbeIndex = ((i - 50) % farbenAnzahl) + 1
- local farbe = colors[farbeIndex]
- if "Wert_" .. i == localWert then
- print("Test: Wert_" .. i .. " = " .. localWert)
- if farbeIndex <= 16 then
- sleep(0.5)
- redstone.setBundledOutput(BundledWire1, farbe)
- else
- sleep(0.5)
- redstone.setBundledOutput(BundledWire2, farbe)
- end
- print("Wire Nr. " .. BundledWire1 .. "Farbe: " .. farbe)
- end
- end
- end
- end
- function Katergory()
- local namenListe = ladeNamen()
- local variablenTabelle = setzeDynamischeVariablen(namenListe)
- -- Überschrift
- mon.setCursorPos(1,3)
- clearMonitor()
- file = fs.open("local" , "r")
- header = file.readLine()
- file.close()
- msg(MonitorWidth,01,08,16,"x")
- msg(02,02,05,16," " .. variablenTabelle[header] .. " ")
- for i = 1, MonitorWidth do
- msg(i,04,01,08,"-")
- msg(i,05,01,08," ")
- msg(i,06,01,08,"-")
- end
- msg(01,05,01,08, "| Function")
- msg(MonitorWidth - 09,05,01,08, "| Status |")
- -- Definiere eine Tabelle mit den Header-Werten und den entsprechenden Wertbereichen.
- local headerToValues = {
- ["Wert_1"] = {6, 10},
- ["Wert_2"] = {11, 15},
- ["Wert_3"] = {16, 20},
- ["Wert_4"] = {21, 25},
- ["Wert_5"] = {26, 30}
- }
- -- Status Start-Werte für jede Kategorie (50, 55, 60 usw.)
- local statusStartValues = {
- ["Wert_1"] = 50,
- ["Wert_2"] = 55,
- ["Wert_3"] = 60,
- ["Wert_4"] = 65,
- ["Wert_5"] = 70
- }
- -- Hole den Wertebereich basierend auf dem Header-Wert.
- local wertebereich = headerToValues[header]
- local statusStartIndex = statusStartValues[header] -- Hole den Status-Startwert je nach Kategorie
- -- Überprüfen, ob der Header einen gültigen Wert hat.
- if wertebereich then
- local startWert, endWert = wertebereich[1], wertebereich[2]
- -- Zeilenstart immer 7 bis 11
- local zeile = 7
- local wertIndex = startWert
- for i = 7, 11 do
- -- Hier gibst du den entsprechenden Wert aus, je nach Index.
- local variablenKey = "Wert_" .. wertIndex
- local statusKey = "Wert_" .. statusStartIndex
- -- Hole den Status (ON/OFF) für den aktuellen Wert.
- local status = variablenTabelle[statusKey] -- Auslesen aus der Datei
- if status == "ON" then
- statusAnzeige = "ON"
- else
- statusAnzeige = "OFF"
- end
- -- Gib die Werte auf dem Monitor aus.
- if statusAnzeige == "ON" then
- for i = 1, MonitorWidth do
- msg(i, zeile, 01, 06, " ")
- end
- msg(1, zeile, 01, 06, "| " .. variablenTabelle[variablenKey] .. " ")
- msg(MonitorWidth - 9, zeile, 01, 06, "| " .. statusAnzeige .. " |")
- elseif statusAnzeige == "OFF" then
- for i = 1, MonitorWidth do
- msg(i, zeile, 01, 15, " ")
- end
- msg(1, zeile, 01, 15, "| " .. variablenTabelle[variablenKey] .. " ")
- msg(MonitorWidth - 9, zeile, 01, 15, "| " .. statusAnzeige .. " |")
- end
- -- Zeilen- und Wert-Index hochzählen
- zeile = zeile + 1
- wertIndex = wertIndex + 1
- statusStartIndex = statusStartIndex + 1 -- Status-Index hochzählen
- end
- else
- print("Ungültiger header-Wert.")
- end
- -- Abfrage für Klicks auf Zeile 6 bis 10
- local event, button, X, Y = os.pullEvent("monitor_touch")
- -- Zeilen für die Status-Werte (7 bis 11 -> Status 50 bis 54,abhängig von der Kategorie)
- if Y >= 7 and Y <= 11 then
- local statusStartIndex = statusStartValues[header] + (Y - 7) -- Berechne den Status-Wert
- local statusKey = "Wert_" .. statusStartIndex
- print("Test statusStartIndex: " .. statusStartIndex)
- -- Wechsle den Status (ON/OFF)
- if variablenTabelle[statusKey] == "ON" then
- variablenTabelle[statusKey] = "OFF"
- elseif variablenTabelle[statusKey] == "OFF" then
- variablenTabelle[statusKey] = "ON"
- end
- print("Wert_" .. statusStartIndex .. "->" .. variablenTabelle[statusKey])
- -- Datei einlesen
- local fileName = "NameSave"
- local file = fs.open(fileName, "r")
- local content = file.readAll()
- file.close()
- -- Den gewünschten Status ändern (nur die Zeile mit dem statusKey ersetzen)
- local newLine = statusKey .. ": " .. variablenTabelle[statusKey]
- file = fs.open("local2" , "w")
- file.write("Wert_" .. statusStartIndex)
- file.close()
- -- Ersetze nur die Zeile mit statusKey
- content = content:gsub(statusKey .. ": [^\n]*", newLine) -- Diese Zeile nur ersetzen
- -- Die Datei mit dem neuen Inhalt überschreiben
- file = fs.open(fileName, "w")
- file.write(content)
- file.close()
- -- Bildschirm neu laden
- WireUpdate()
- Katergory()
- else
- os.reboot()
- end
- end
- getMonitorSize()
- WireUpdate()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement