Advertisement
PlatinKinggg

gui.lua

May 29th, 2025 (edited)
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | Gaming | 0 0
  1. -- Datei: gui.lua
  2. -- Ausgabe auf Monitor, Debug-Ausgabe optional im Terminal (CC: Tweaked), modularisiert
  3.  
  4. local gui = {}
  5. local config = require("config")
  6.  
  7. local monitor = peripheral.find and peripheral.find("monitor") or nil
  8.  
  9. -- Hilfsfunktionen fĂźr Terminal
  10. local function termClear()
  11.   term.clear()
  12. end
  13.  
  14. local function termWriteAt(x, y, text)
  15.   term.setCursorPos(x, y)
  16.   print(text)
  17. end
  18.  
  19. -- Hilfsfunktionen fĂźr Monitor
  20. local function monitorClear()
  21.   if monitor then monitor.clear() end
  22. end
  23.  
  24. local function monitorWriteAt(x, y, text)
  25.   if monitor then
  26.     monitor.setCursorPos(x, y)
  27.     monitor.write(text)
  28.   end
  29. end
  30.  
  31. function gui.clear()
  32.   if config.debug == 1 then termClear() end
  33.   monitorClear()
  34. end
  35.  
  36. function gui.drawCenteredText(y, text)
  37.   if config.debug == 1 then
  38.     local w, _ = term.getSize()
  39.     local x = math.floor((w - #text) / 2)
  40.     termWriteAt(x, y, text)
  41.   end
  42.  
  43.   if monitor then
  44.     local w, _ = monitor.getSize()
  45.     local x = math.floor((w - #text) / 2)
  46.     monitorWriteAt(x, y, text)
  47.   end
  48. end
  49.  
  50. function gui.updateMonitor(turbines)
  51.   local turbine = require("turbine")
  52.  
  53.   gui.clear()
  54.   gui.drawCenteredText(1, "Turbinenstatus")
  55.  
  56.   local y = 3
  57.   for i, t in ipairs(turbines) do
  58.     local info = turbine.getTurbineInfo(t)
  59.  
  60.     local lines = {
  61.       string.format("Turbine %d:", i),
  62.       string.format("  Aktiv: %s", tostring(info.active)),
  63.       string.format("  Energie: %d / %d RF", info.energyStored, info.energyCapacity),
  64.       string.format("  Flowrate: %d / %d mB/t", info.fluidFlowRate, info.fluidFlowRateMax),
  65.       string.format("  Rotor: %d RPM", info.rotorSpeed),
  66.       string.format("  RF/t: %.1f", info.energyProducedLastTick)
  67.     }
  68.  
  69.     for j, line in ipairs(lines) do
  70.       if config.debug == 1 then termWriteAt(1, y + j - 1, line) end
  71.       monitorWriteAt(1, y + j - 1, line)
  72.     end
  73.  
  74.     y = y + #lines + 1
  75.   end
  76. end
  77.  
  78. return gui
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement