From 909e8e6f1d7ccd631def52a1daed2b3e36c2ea91 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 15 Mar 2026 22:30:36 -0400 Subject: [PATCH] Add progress display during inventory scanning in refreshCache function --- inventoryManager.lua | 73 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index adba00b..53685fd 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -168,7 +168,8 @@ local function scanInventory(deviceName) end -- Full scan: updates the global cache -local function refreshCache() +-- onProgress(current, total, chestName) is called per chest if provided +local function refreshCache(onProgress) activity.scanning = true local chests = getChests() @@ -176,7 +177,8 @@ local function refreshCache() local totalSlots = 0 local usedSlots = 0 - for _, chest in ipairs(chests) do + for ci, chest in ipairs(chests) do + if onProgress then onProgress(ci, #chests, chest) end local inv = peripheral.wrap(chest) if inv then totalSlots = totalSlots + inv.size() @@ -1015,9 +1017,72 @@ local function main() print("Console shows log. Use the monitor to interact.") print("") - -- Initial scan before starting + -- Initial scan with progress bar on monitor print("[INIT] Scanning inventories...") - refreshCache() + if mon then + local w, h = mon.getSize() + local buf = window.create(mon, 1, 1, w, h, false) + + local function drawBoot(current, total, chestName) + buf.setBackgroundColor(colors.black) + buf.clear() + + -- Title + buf.setBackgroundColor(colors.blue) + buf.setCursorPos(1, 1) + buf.write(string.rep(" ", w)) + local title = " INVENTORY MANAGER " + buf.setCursorPos(math.floor((w - #title) / 2) + 1, 1) + buf.setTextColor(colors.white) + buf.write(title) + + -- Scanning label + local midY = math.floor(h / 2) + buf.setBackgroundColor(colors.black) + buf.setTextColor(colors.lightGray) + local label = "Scanning inventories..." + buf.setCursorPos(math.floor((w - #label) / 2) + 1, midY - 2) + buf.write(label) + + -- Chest name + local short = chestName or "" + if #short > w - 4 then short = ".." .. short:sub(-(w - 6)) end + buf.setTextColor(colors.gray) + buf.setCursorPos(math.floor((w - #short) / 2) + 1, midY - 1) + buf.write(short) + + -- Progress bar + local barW = math.min(w - 8, 40) + local barX = math.floor((w - barW) / 2) + 1 + local ratio = total > 0 and (current / total) or 0 + local filled = math.floor(ratio * barW) + + buf.setCursorPos(barX, midY + 1) + buf.setBackgroundColor(colors.lime) + buf.write(string.rep(" ", filled)) + buf.setBackgroundColor(colors.gray) + buf.write(string.rep(" ", barW - filled)) + + -- Percentage + count + buf.setBackgroundColor(colors.black) + buf.setTextColor(colors.white) + local pct = string.format("%d/%d (%d%%)", current, total, math.floor(ratio * 100)) + buf.setCursorPos(math.floor((w - #pct) / 2) + 1, midY + 3) + buf.write(pct) + + -- Bottom accent + buf.setCursorPos(1, h) + buf.setBackgroundColor(colors.blue) + buf.write(string.rep(" ", w)) + + buf.setVisible(true) + buf.setVisible(false) + end + + refreshCache(drawBoot) + else + refreshCache() + end print("[INIT] Done. Found " .. #cache.itemList .. " item types.") print("")