Advertisement
Seepekaboo

ColonyMon

Jul 6th, 2025 (edited)
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | Gaming | 0 0
  1. --========================================================--
  2. --  colony_dashboard.lua  •  CC-Tweaked + Colony Peripheral
  3. --========================================================--
  4.  
  5. ------------------------------------ optional monitor redirection
  6. local mon = peripheral.find("monitor")
  7. if mon then
  8.   mon.setTextScale(0.5)
  9.   term.redirect(mon)
  10. end
  11. term.clear()
  12.  
  13. ------------------------------------ tiny helpers
  14. local function centre(txt, y)
  15.   local w = term.getSize()
  16.   term.setCursorPos(math.floor((w - #txt) / 2) + 1, y)
  17.   term.write(txt)
  18. end
  19.  
  20. local PALETTE = { hdr = colours.yellow, ok = colours.lime, bg = colours.black }
  21.  
  22. ---draw a horizontal bar  (0–1 range)
  23. local function bar(label, pct, y)
  24.   pct = math.max(0, math.min(1, pct or 0))
  25.   local w = term.getSize()
  26.   local width = w - #label - 6               -- " [", bar, "]"
  27.   local filled = math.floor(width * pct + 0.5)
  28.  
  29.   term.setCursorPos(1, y)
  30.   term.write(label .. " [")
  31.   term.setBackgroundColor(PALETTE.ok)
  32.   term.write((" "):rep(filled))
  33.   term.setBackgroundColor(PALETTE.bg)
  34.   term.write((" "):rep(width - filled) .. "]")
  35. end
  36.  
  37. ------------------------------------ main paint routine
  38. local function draw()
  39.   term.clear()
  40.  
  41.   -- ── colony summary ─────────────────────────────────────────
  42.   local okInfo, info = pcall(colony.getInfo, colony)
  43.   if not okInfo or type(info) ~= "table" then
  44.     centre("§cUnable to read colony data!", 1)
  45.     return
  46.   end
  47.  
  48.   term.setTextColour(PALETTE.hdr)
  49.   centre(info.name or "Colony", 1)
  50.   term.setTextColour(colours.white)
  51.  
  52.   centre(
  53.     ("Citizens %d / %d   Happiness %.2f%%")
  54.       :format(info.citizens or 0,
  55.                info.maxCitizens or 0,
  56.                (info.happiness or 0) * 100),
  57.     3
  58.   )
  59.  
  60.   if info.raid then
  61.     term.setTextColour(colours.red)
  62.     centre("⚠ RAID IN PROGRESS ⚠", 4)
  63.     term.setTextColour(colours.white)
  64.   end
  65.  
  66.   bar("Happiness ", info.happiness, 6)
  67.  
  68.   -- ── outstanding requests ───────────────────────────────────
  69.   local okReq, req = pcall(colony.getRequests, colony)
  70.   req = okReq and req or {}
  71.   term.setCursorPos(1, 8)
  72.   print("Requests (first 5):")
  73.   if #req == 0 then
  74.     print("  – none –")
  75.   else
  76.     for i = 1, math.min(5, #req) do
  77.       local r = req[i]
  78.       print(("  • %s ×%d  (%s)")
  79.         :format(r.items and r.items[1] and (r.items[1].displayName or r.items[1].name) or r.name,
  80.                  r.count or r.minCount or 1,
  81.                  r.target or "unknown"))
  82.     end
  83.   end
  84. end
  85.  
  86. ------------------------------------ loop forever
  87. while true do
  88.   draw()
  89.   sleep(5)              -- refresh every 5 s; tweak as you like
  90. end
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement