This commit is contained in:
2025-08-31 01:41:02 +09:00
parent 3891e48acd
commit 0d519700b6
7 changed files with 15 additions and 23 deletions

View File

@@ -408,13 +408,10 @@ end
local e = defines.events
local events = {
[e.on_tick] = on_tick,
[e.on_singleplayer_init] = Async.on_init,
[e.on_multiplayer_init] = Async.on_init,
}
local Clustorio = ExpUtil.optional_require("modules/clusterio/api")
if Clustorio then
events[Clustorio.events.on_server_startup] = Async.on_init
end
Async._function_metatable.__call = Async._function_prototype.start_soon
Async.events = events --- @package
return Async

View File

@@ -1,7 +1,5 @@
-- luacheck:ignore global package
local Clustorio = require("modules/clusterio/api")
--- Enum values for the different lifecycle stages within a factorio module
-- Info on the data lifecycle and how we use it: https://lua-api.factorio.com/latest/auxiliary/data-lifecycle.html
-- We start in control stage and so values 1 thorough 3 are only present for completeness
@@ -25,10 +23,9 @@ return setmetatable({
on_load = function() package.lifecycle = package.lifecycle_stage.load end,
on_configuration_changed = function() package.lifecycle = package.lifecycle_stage.config_change end,
events = {
-- TODO find a reliable way to set to runtime because currently it will desync if accessed before player joined
-- TODO make clusterio optional dependency
[defines.events.on_player_joined_game] = function() package.lifecycle = package.lifecycle_stage.runtime end,
[Clustorio.events.on_server_startup] = function() package.lifecycle = package.lifecycle_stage.runtime end,
[defines.events.on_singleplayer_init] = function() package.lifecycle = package.lifecycle_stage.runtime end,
[defines.events.on_multiplayer_init] = function() package.lifecycle = package.lifecycle_stage.runtime end,
},
}, {
__index = package,

View File

@@ -119,12 +119,10 @@ function Storage.on_init()
end
end
local events = {}
--- @package
Storage.events = {
[defines.events.on_multiplayer_init] = Storage.on_init,
[defines.events.on_singleplayer_init] = Storage.on_init,
}
local Clustorio = ExpUtil.optional_require("modules/clusterio/api")
if Clustorio then
events[Clustorio.events.on_server_startup] = Storage.on_init
end
Storage.events = events --- @package
return Storage