Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --========================================================--
- -- colony_dashboard.lua • CC-Tweaked + Colony Peripheral
- --========================================================--
- ------------------------------------ optional monitor redirection
- local mon = peripheral.find("monitor")
- if mon then
- mon.setTextScale(0.5)
- term.redirect(mon)
- end
- term.clear()
- ------------------------------------ tiny helpers
- local function centre(txt, y)
- local w = term.getSize()
- term.setCursorPos(math.floor((w - #txt) / 2) + 1, y)
- term.write(txt)
- end
- local PALETTE = { hdr = colours.yellow, ok = colours.lime, bg = colours.black }
- ---draw a horizontal bar (0–1 range)
- local function bar(label, pct, y)
- pct = math.max(0, math.min(1, pct or 0))
- local w = term.getSize()
- local width = w - #label - 6 -- " [", bar, "]"
- local filled = math.floor(width * pct + 0.5)
- term.setCursorPos(1, y)
- term.write(label .. " [")
- term.setBackgroundColor(PALETTE.ok)
- term.write((" "):rep(filled))
- term.setBackgroundColor(PALETTE.bg)
- term.write((" "):rep(width - filled) .. "]")
- end
- ------------------------------------ main paint routine
- local function draw()
- term.clear()
- -- ── colony summary ─────────────────────────────────────────
- local okInfo, info = pcall(colony.getInfo, colony)
- if not okInfo or type(info) ~= "table" then
- centre("§cUnable to read colony data!", 1)
- return
- end
- term.setTextColour(PALETTE.hdr)
- centre(info.name or "Colony", 1)
- term.setTextColour(colours.white)
- centre(
- ("Citizens %d / %d Happiness %.2f%%")
- :format(info.citizens or 0,
- info.maxCitizens or 0,
- (info.happiness or 0) * 100),
- 3
- )
- if info.raid then
- term.setTextColour(colours.red)
- centre("⚠ RAID IN PROGRESS ⚠", 4)
- term.setTextColour(colours.white)
- end
- bar("Happiness ", info.happiness, 6)
- -- ── outstanding requests ───────────────────────────────────
- local okReq, req = pcall(colony.getRequests, colony)
- req = okReq and req or {}
- term.setCursorPos(1, 8)
- print("Requests (first 5):")
- if #req == 0 then
- print(" – none –")
- else
- for i = 1, math.min(5, #req) do
- local r = req[i]
- print((" • %s ×%d (%s)")
- :format(r.items and r.items[1] and (r.items[1].displayName or r.items[1].name) or r.name,
- r.count or r.minCount or 1,
- r.target or "unknown"))
- end
- end
- end
- ------------------------------------ loop forever
- while true do
- draw()
- sleep(5) -- refresh every 5 s; tweak as you like
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement