Enhance event handling in craftItem function and improve broadcastState function to include stateVersion
This commit is contained in:
@@ -1176,7 +1176,7 @@ local function craftItem(recipeIdx)
|
|||||||
|
|
||||||
while os.clock() < deadline do
|
while os.clock() < deadline do
|
||||||
local timerId = os.startTimer(math.max(0.1, deadline - os.clock()))
|
local timerId = os.startTimer(math.max(0.1, deadline - os.clock()))
|
||||||
local event, p1, p2, p3, p4 = os.pullEvent()
|
local event, p1, p2, p3, p4, p5 = os.pullEvent()
|
||||||
|
|
||||||
if event == "modem_message" then
|
if event == "modem_message" then
|
||||||
local channel = p2
|
local channel = p2
|
||||||
@@ -1184,6 +1184,9 @@ local function craftItem(recipeIdx)
|
|||||||
if channel == CRAFT_REPLY_CHANNEL and type(message) == "table" and message.type == "craft_result" then
|
if channel == CRAFT_REPLY_CHANNEL and type(message) == "table" and message.type == "craft_result" then
|
||||||
result = message
|
result = message
|
||||||
break
|
break
|
||||||
|
elseif channel == ORDER_CHANNEL then
|
||||||
|
-- Re-queue so Task 12 picks it up after craftItem returns
|
||||||
|
os.queueEvent(event, p1, p2, p3, p4, p5)
|
||||||
end
|
end
|
||||||
elseif event == "timer" and p1 == timerId then
|
elseif event == "timer" and p1 == timerId then
|
||||||
-- Timeout tick, loop will check deadline
|
-- Timeout tick, loop will check deadline
|
||||||
@@ -2481,13 +2484,14 @@ end
|
|||||||
-- Network broadcast (sends state to client displays)
|
-- Network broadcast (sends state to client displays)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local function broadcastState(force)
|
local function broadcastState()
|
||||||
if not networkModem then return end
|
if not networkModem then return end
|
||||||
ensureItemList()
|
ensureItemList()
|
||||||
|
|
||||||
-- Build dynamic state (always included)
|
-- Build dynamic state (always included)
|
||||||
local state = {
|
local state = {
|
||||||
type = "state",
|
type = "state",
|
||||||
|
stateVersion = stateVersion,
|
||||||
cache = {
|
cache = {
|
||||||
itemList = cache.itemList,
|
itemList = cache.itemList,
|
||||||
grandTotal = cache.grandTotal,
|
grandTotal = cache.grandTotal,
|
||||||
@@ -2721,10 +2725,12 @@ local function main()
|
|||||||
-- Task 3: Auto-smelt
|
-- Task 3: Auto-smelt
|
||||||
function()
|
function()
|
||||||
while true do
|
while true do
|
||||||
activity.smelting = true
|
|
||||||
needsRedraw = true
|
|
||||||
smelterNeedsRedraw = true
|
|
||||||
local ok, didWork = pcall(autoSmelt)
|
local ok, didWork = pcall(autoSmelt)
|
||||||
|
if ok and didWork then
|
||||||
|
activity.smelting = true
|
||||||
|
needsRedraw = true
|
||||||
|
smelterNeedsRedraw = true
|
||||||
|
end
|
||||||
activity.smelting = false
|
activity.smelting = false
|
||||||
-- Update furnace status quickly after smelt cycle
|
-- Update furnace status quickly after smelt cycle
|
||||||
pcall(refreshFurnaceStatus)
|
pcall(refreshFurnaceStatus)
|
||||||
|
|||||||
Reference in New Issue
Block a user