Advertisement
MagmaLP

Test Mon 2

May 19th, 2025 (edited)
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.44 KB | None | 0 0
  1. -- Hilfsfunktionen
  2. local function clear()
  3.   term.setBackgroundColor(colors.black)
  4.   term.setTextColor(colors.lightBlue)
  5.   term.clear()
  6.   term.setCursorPos(1, 1)
  7. end
  8.  
  9.  
  10. -- Auto-Start Bildschirmanzeige (einmalig beim Programmstart)
  11. local function autoStartScreen()
  12.   if not fs.exists("auto_start") then return end
  13.  
  14.   local file = fs.open("auto_start", "r")
  15.   local screenFile = file.readLine()
  16.   file.close()
  17.  
  18.   if not screenFile or screenFile == "" then return end
  19.  
  20.   local path = "screens/" .. screenFile
  21.   if not fs.exists(path) then
  22.     term.setTextColor(colors.red)
  23.     print("Auto-Start Datei existiert nicht mehr: " .. screenFile)
  24.     term.setTextColor(colors.lightBlue)
  25.     sleep(2)
  26.     return
  27.   end
  28.  
  29.   local monitor = peripheral.wrap("left")
  30.   if not monitor then
  31.     term.setTextColor(colors.red)
  32.     print("Kein Monitor für Auto-Start gefunden.")
  33.     term.setTextColor(colors.lightBlue)
  34.     sleep(2)
  35.     return
  36.   end
  37.  
  38.   monitor.setBackgroundColor(colors.black)
  39.   monitor.setTextColor(colors.white)
  40.   monitor.clear()
  41.   monitor.setCursorPos(1, 1)
  42.  
  43.   local file = fs.open(path, "r")
  44.   while true do
  45.     local line = file.readLine()
  46.     if not line then break end
  47.     local gap, lineNum, textColor, bgColor, text = line:match("([^,]+),([^,]+),([^,]+),([^,]+),(.+)")
  48.     gap = tonumber(gap)
  49.     lineNum = tonumber(lineNum)
  50.     textColor = tonumber(textColor)
  51.     bgColor = tonumber(bgColor)
  52.     if gap and lineNum and textColor and bgColor and text then
  53.       monitor.setCursorPos(gap, lineNum)
  54.       monitor.setTextColor(textColor)
  55.       monitor.setBackgroundColor(bgColor)
  56.       monitor.write(text)
  57.     end
  58.   end
  59.   file.close()
  60. end
  61.  
  62.  
  63.  
  64. local function listScreens()
  65.   if not fs.exists("screens") then fs.makeDir("screens") end
  66.   local files = fs.list("screens")
  67.   local screens = {}
  68.   for _, f in ipairs(files) do
  69.     if not fs.isDir("screens/" .. f) then
  70.       table.insert(screens, f)
  71.     end
  72.   end
  73.   return screens
  74. end
  75.  
  76. local function waitEnter()
  77.   term.setTextColor(colors.gray)
  78.   print("\nDrücke [Enter], um fortzufahren...")
  79.   term.setTextColor(colors.lightBlue)
  80.   read()
  81. end
  82.  
  83. -- [2] Neuen Bildschirm Konfigurieren
  84. local function screenConfig()
  85.   shell.run("1")
  86. end
  87.  
  88. -- [1] Gespeicherten Bildschirm anschauen
  89. local function promptScreenStart()
  90.   clear()
  91.   print("Gespeicherte Screens:\n")
  92.   local screens = listScreens()
  93.   for i, s in ipairs(screens) do
  94.     print(i .. ") " .. s)
  95.   end
  96.   io.write("\nNummer eingeben zum Starten: ")
  97.   local n = tonumber(read())
  98.  
  99.   if not (n and screens[n]) then
  100.     term.setTextColor(colors.red)
  101.     print("Ungültige Eingabe.")
  102.     term.setTextColor(colors.lightBlue)
  103.     waitEnter()
  104.     return
  105.   end
  106.  
  107.   -- Monitor suchen
  108.   local monitor = peripheral.wrap("left")
  109.   if not monitor then
  110.     term.setTextColor(colors.red)
  111.     print("Kein Monitor gefunden.")
  112.     term.setTextColor(colors.lightBlue)
  113.     waitEnter()
  114.     return
  115.   end
  116.  
  117.   monitor.setBackgroundColor(colors.black)
  118.   monitor.setTextColor(colors.white)
  119.   monitor.clear()
  120.   monitor.setCursorPos(1, 1)
  121.  
  122.   -- Datei öffnen und lesen
  123.   local path = "screens/" .. screens[n]
  124.   local file = fs.open(path, "r")
  125.   if not file then
  126.     term.setTextColor(colors.red)
  127.     print("Datei konnte nicht geöffnet werden.")
  128.     term.setTextColor(colors.lightBlue)
  129.     waitEnter()
  130.     return
  131.   end
  132.  
  133.   while true do
  134.     local line = file.readLine()
  135.     if not line then break end
  136.     local gap, lineNum, textColor, bgColor, text = line:match("([^,]+),([^,]+),([^,]+),([^,]+),(.+)")
  137.     gap = tonumber(gap)
  138.     lineNum = tonumber(lineNum)
  139.     textColor = tonumber(textColor)
  140.     bgColor = tonumber(bgColor)
  141.  
  142.     if gap and lineNum and textColor and bgColor and text then
  143.       monitor.setCursorPos(gap, lineNum)
  144.       monitor.setTextColor(textColor)
  145.       monitor.setBackgroundColor(bgColor)
  146.       monitor.write(text)
  147.     end
  148.   end
  149.  
  150.   file.close()
  151.   term.setTextColor(colors.green)
  152.   print("\nBildschirm auf Monitor angezeigt.")
  153.   term.setTextColor(colors.lightBlue)
  154.   waitEnter()
  155. end
  156.  
  157.  
  158. -- [3] Auto-Start Bildschirm festlegen
  159. local function promptAutoStart()
  160.   clear()
  161.   print("Auto-Start Bildschirm festlegen:\n")
  162.   local screens = listScreens()
  163.   for i, s in ipairs(screens) do
  164.     print(i .. ") " .. s)
  165.   end
  166.   io.write("\nNummer eingeben: ")
  167.   local n = tonumber(read())
  168.   if n and screens[n] then
  169.     local file = fs.open("auto_start", "w")
  170.     file.write(screens[n])
  171.     file.close()
  172.     term.setTextColor(colors.green)
  173.     print("\nGespeichert! Beim nächsten Start wird dieser Bildschirm automatisch angezeigt.")
  174.     term.setTextColor(colors.lightBlue)
  175.   else
  176.     term.setTextColor(colors.red)
  177.     print("Ungültige Eingabe.")
  178.     term.setTextColor(colors.lightBlue)
  179.   end
  180.   waitEnter()
  181. end
  182.  
  183. -- [4] Gespeicherten Bildschirm löschen
  184. local function deleteScreen()
  185.   clear()
  186.   print("Screen löschen:\n")
  187.   local screens = listScreens()
  188.   for i, s in ipairs(screens) do
  189.     print(i .. ") " .. s)
  190.   end
  191.   io.write("\nNummer eingeben: ")
  192.   local n = tonumber(read())
  193.   if n and screens[n] then
  194.     fs.delete("screens/" .. screens[n])
  195.     term.setTextColor(colors.green)
  196.     print("\nBildschirm gelöscht.")
  197.     term.setTextColor(colors.lightBlue)
  198.   else
  199.     term.setTextColor(colors.red)
  200.     print("Ungültige Eingabe.")
  201.     term.setTextColor(colors.lightBlue)
  202.   end
  203.   waitEnter()
  204. end
  205.  
  206. -- Hauptmenü
  207. local function main()
  208.   autoStartScreen() -- Bildschirm einmalig anzeigen (wenn vorhanden)
  209.  
  210.   while true do
  211.     clear()
  212.     print([[
  213.  
  214. Willkommen im Bildschirm - Konfigurator
  215.  
  216. Du kannst ohne Programmierkenntnisse folgendes tun:
  217.  
  218. 1) Gespeicherten Bildschirm anschauen      
  219. 2) Neuen Bildschirm konfigurieren          
  220. 3) Auto-Start für Bildschirm festlegen    
  221. 4) Gespeicherten Bildschirm löschen        
  222. 5) Beenden                                
  223.  
  224. ]])
  225.     io.write("Bitte Zahl eingeben und [Enter] drücken: ")
  226.     local input = read()
  227.  
  228.     if input == "1" then promptScreenStart()         -- [1]
  229.     elseif input == "2" then screenConfig()          -- [2]
  230.     elseif input == "3" then promptAutoStart()       -- [3]
  231.     elseif input == "4" then deleteScreen()          -- [4]
  232.     elseif input == "5" then                         -- [5]
  233.       print("Beende Menü...")
  234.       sleep(1)
  235.       break
  236.     else
  237.       term.setTextColor(colors.red)
  238.       print("Ungültige Eingabe.")
  239.       term.setTextColor(colors.lightBlue)
  240.       waitEnter()
  241.     end
  242.   end
  243. end
  244.  
  245. main()
  246.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
OSZAR »