Add storage capacity bar to monitor dashboard for better inventory management

This commit is contained in:
MayaTheShy
2026-03-15 16:35:53 -04:00
parent 13aba05745
commit fe2efaaf36

View File

@@ -161,6 +161,57 @@ local function drawDashboard()
monFill(3, colors.lightBlue)
monCenter(3, string.rep("\140", math.min(w - 4, 60)), colors.cyan, colors.lightBlue)
-- ===== Storage capacity bar =====
-- Count total slots and used slots across all chests (in parallel)
local totalSlots = 0
local usedSlots = 0
local capTasks = {}
local capResults = {}
for i, chestName in ipairs(chests) do
capResults[i] = { total = 0, used = 0 }
capTasks[i] = function()
local inv = peripheral.wrap(chestName)
if inv then
local size = inv.size()
capResults[i].total = size
local contents = inv.list()
for _ in pairs(contents) do
capResults[i].used = capResults[i].used + 1
end
end
end
end
if #capTasks > 0 then
parallel.waitForAll(table.unpack(capTasks))
end
for _, r in ipairs(capResults) do
totalSlots = totalSlots + r.total
usedSlots = usedSlots + r.used
end
local freeSlots = totalSlots - usedSlots
local usedRatio = totalSlots > 0 and (usedSlots / totalSlots) or 0
local capY = 4
monFill(capY, colors.black)
local capLabel = string.format(" Storage: %d/%d slots (%d free)", usedSlots, totalSlots, freeSlots)
monWrite(2, capY, capLabel, colors.lightGray, colors.black)
-- Draw capacity bar
local barStart = #capLabel + 4
local barWidth = w - barStart - 2
if barWidth > 4 then
local barColor = colors.lime
if usedRatio > 0.9 then barColor = colors.red
elseif usedRatio > 0.7 then barColor = colors.orange
elseif usedRatio > 0.5 then barColor = colors.yellow
end
monBar(barStart, capY, barWidth, usedRatio, barColor, colors.gray)
-- Show percentage on the bar
local pctStr = string.format(" %d%% ", math.floor(usedRatio * 100))
local pctX = barStart + math.floor(barWidth / 2) - math.floor(#pctStr / 2)
monWrite(pctX, capY, pctStr, colors.white, barColor)
end
-- ===== Item catalogue =====
local catalogue = buildCatalogue()
@@ -176,7 +227,7 @@ local function drawDashboard()
table.sort(itemList, function(a, b) return a.total > b.total end)
-- Header row
local row = 5
local row = 6
monFill(row, colors.gray)
monWrite(2, row, "#", colors.lightGray, colors.gray)
monWrite(5, row, "Item", colors.lightGray, colors.gray)