feat: optimize broadcastState function to conditionally include recipe tables based on config changes
This commit is contained in:
@@ -39,7 +39,6 @@ local ok, err = xpcall(function()
|
|||||||
|
|
||||||
-- Override dofile to load modules into our _ENV so they inherit
|
-- Override dofile to load modules into our _ENV so they inherit
|
||||||
-- Opus's require/package (CC:Tweaked dofile uses _G instead).
|
-- Opus's require/package (CC:Tweaked dofile uses _G instead).
|
||||||
local _ccDofile = dofile
|
|
||||||
local function dofile(path) -- luacheck: ignore
|
local function dofile(path) -- luacheck: ignore
|
||||||
local fn, err = loadfile(path, nil, _ENV)
|
local fn, err = loadfile(path, nil, _ENV)
|
||||||
if fn then return fn()
|
if fn then return fn()
|
||||||
@@ -148,9 +147,12 @@ local function broadcastState()
|
|||||||
-- Keep ctx in sync so display.lua can check ctx.craftTurtleOk directly
|
-- Keep ctx in sync so display.lua can check ctx.craftTurtleOk directly
|
||||||
ctx.craftTurtleOk = payload.craftTurtleOk
|
ctx.craftTurtleOk = payload.craftTurtleOk
|
||||||
|
|
||||||
payload.smeltable = cfg.SMELTABLE
|
-- Only include recipe tables when config has changed (they're large).
|
||||||
payload.craftable = cfg.CRAFTABLE
|
if state.configDirty then
|
||||||
state.configDirty = false
|
payload.smeltable = cfg.SMELTABLE
|
||||||
|
payload.craftable = cfg.CRAFTABLE
|
||||||
|
state.configDirty = false
|
||||||
|
end
|
||||||
|
|
||||||
ctx.networkModem.transmit(cfg.BROADCAST_CHANNEL, cfg.ORDER_CHANNEL, payload)
|
ctx.networkModem.transmit(cfg.BROADCAST_CHANNEL, cfg.ORDER_CHANNEL, payload)
|
||||||
state.lastBroadcastVersion = state.stateVersion
|
state.lastBroadcastVersion = state.stateVersion
|
||||||
|
|||||||
Reference in New Issue
Block a user