From fe2efaaf36970e4e620b3a441478b5013638bb17 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 15 Mar 2026 16:35:53 -0400 Subject: [PATCH] Add storage capacity bar to monitor dashboard for better inventory management --- inventoryManager.lua | 53 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index 8d8a245..9ee7625 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -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)