Enhance smelter monitor setup and dashboard functionality, including recipe loading and touch event handling
This commit is contained in:
@@ -1599,13 +1599,32 @@ local function main()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if setupMonitor() then
|
if setupMonitor() then
|
||||||
print("[OK] Monitor: " .. MONITOR_SIDE)
|
print("[OK] Monitor: " .. (monName or MONITOR_SIDE))
|
||||||
else
|
else
|
||||||
print("[WARN] No monitor on " .. MONITOR_SIDE)
|
print("[WARN] No monitor on " .. MONITOR_SIDE)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if setupSmelterMonitor() then
|
||||||
|
print("[OK] Smelter monitor: " .. (smelterMonName or SMELTER_MONITOR_SIDE))
|
||||||
|
else
|
||||||
|
print("[WARN] No smelter monitor on " .. SMELTER_MONITOR_SIDE)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load recipe toggles from disk
|
||||||
|
loadDisabledRecipes()
|
||||||
|
if smeltingPaused then
|
||||||
|
print("[INIT] Smelting is PAUSED (toggle on smelter monitor)")
|
||||||
|
end
|
||||||
|
local enabledCount = 0
|
||||||
|
local totalRecipeCount = 0
|
||||||
|
for _ in pairs(SMELTABLE) do totalRecipeCount = totalRecipeCount + 1 end
|
||||||
|
for k in pairs(SMELTABLE) do
|
||||||
|
if not disabledRecipes[k] then enabledCount = enabledCount + 1 end
|
||||||
|
end
|
||||||
|
print(string.format("[INIT] %d/%d recipes enabled", enabledCount, totalRecipeCount))
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
print("Console shows log. Use the monitor to interact.")
|
print("Console shows log. Use the monitors to interact.")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
-- Try loading cached inventory from disk for instant startup
|
-- Try loading cached inventory from disk for instant startup
|
||||||
@@ -1691,12 +1710,14 @@ local function main()
|
|||||||
if cacheLoaded then
|
if cacheLoaded then
|
||||||
pcall(refreshCache)
|
pcall(refreshCache)
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
print("[INIT] Background refresh complete. " .. #cache.itemList .. " types.")
|
print("[INIT] Background refresh complete. " .. #cache.itemList .. " types.")
|
||||||
end
|
end
|
||||||
while true do
|
while true do
|
||||||
sleep(SCAN_INTERVAL)
|
sleep(SCAN_INTERVAL)
|
||||||
pcall(refreshCache)
|
pcall(refreshCache)
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -1713,19 +1734,24 @@ local function main()
|
|||||||
while true do
|
while true do
|
||||||
activity.smelting = true
|
activity.smelting = true
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
local ok, didWork = pcall(autoSmelt)
|
local ok, didWork = pcall(autoSmelt)
|
||||||
activity.smelting = false
|
activity.smelting = false
|
||||||
|
-- Update furnace status quickly after smelt cycle
|
||||||
|
pcall(refreshFurnaceStatus)
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
-- If work was done, scan sooner to update cache
|
-- If work was done, scan sooner to update cache
|
||||||
if ok and didWork then
|
if ok and didWork then
|
||||||
pcall(refreshCache)
|
pcall(refreshCache)
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
end
|
end
|
||||||
sleep(SMELT_INTERVAL)
|
sleep(SMELT_INTERVAL)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Task 4: Dashboard redraw (event-driven, checks every 0.1s)
|
-- Task 4: Inventory dashboard redraw (event-driven, checks every 0.1s)
|
||||||
function()
|
function()
|
||||||
needsRedraw = true
|
needsRedraw = true
|
||||||
while true do
|
while true do
|
||||||
@@ -1745,12 +1771,29 @@ local function main()
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Task 5: Touch event listener
|
-- Task 5: Smelter dashboard redraw
|
||||||
|
function()
|
||||||
|
smelterNeedsRedraw = true
|
||||||
|
while true do
|
||||||
|
if smelterNeedsRedraw then
|
||||||
|
smelterNeedsRedraw = false
|
||||||
|
pcall(drawSmelterDashboard)
|
||||||
|
end
|
||||||
|
sleep(0.1)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- Task 6: Touch event listener (both monitors)
|
||||||
function()
|
function()
|
||||||
while true do
|
while true do
|
||||||
local event, side, x, y = os.pullEvent("monitor_touch")
|
local event, side, x, y = os.pullEvent("monitor_touch")
|
||||||
print(string.format("[TOUCH] x=%d y=%d", x, y))
|
if smelterMonName and side == smelterMonName then
|
||||||
handleTouch(x, y)
|
print(string.format("[SMELT-TOUCH] x=%d y=%d", x, y))
|
||||||
|
handleSmelterTouch(x, y)
|
||||||
|
else
|
||||||
|
print(string.format("[TOUCH] x=%d y=%d", x, y))
|
||||||
|
handleTouch(x, y)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user