Skip to content

Commit 9a680ea

Browse files
committed
Switch to sp/mp init events
1 parent 7ab721b commit 9a680ea

File tree

7 files changed

+15
-23
lines changed

7 files changed

+15
-23
lines changed

exp_commands/module/commands/ipc.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ local Clustorio = require("modules/clusterio/api")
1010

1111
local json_to_table = helpers.json_to_table
1212

13+
Commands.add_rcon_static("Clustorio", Clustorio)
14+
Commands.add_rcon_static("ipc", Clustorio.send_json)
15+
1316
Commands.new("_ipc", { "exp-commands_ipc.description" })
1417
:argument("channel", { "exp-commands_ipc.arg-channel" }, Commands.types.string)
1518
:argument("message", { "exp-commands_ipc.arg-message" }, Commands.types.string)

exp_commands/module/commands/rcon.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ System command which runs arbitrary code within a custom (not sandboxed) environ
1111
local ExpUtil = require("modules/exp_util")
1212
local Async = require("modules/exp_util/async")
1313
local Storage = require("modules/exp_util/storage")
14-
local Clustorio = require("modules/clusterio/api")
1514

1615
local Commands = require("modules/exp_commands") --- @class Commands
1716

@@ -26,9 +25,7 @@ setmetatable(rcon_env, { __index = rcon_static })
2625
rcon_static.Async = Async
2726
rcon_static.ExpUtil = ExpUtil
2827
rcon_static.Commands = Commands
29-
rcon_static.Clustorio = Clustorio
3028
rcon_static.print = Commands.print
31-
rcon_static.ipc = Clustorio.send_json
3229
--- @diagnostic enable: name-style-check
3330

3431
--- Some common callback values which are useful when a player uses the command

exp_legacy/module/control.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ for _, error in ipairs(errors) do log(error) end
4141

4242
log("[END] -----| Explosive Gaming Scenario Loader |-----")
4343

44-
--- Register all event handlers via clusterio
44+
--- Register all event handlers via event handler
4545
local Event = require("modules/exp_legacy/utils/event")
4646
return Event.real_handlers

exp_legacy/module/utils/event.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local Clustorio = require("modules/clusterio/api")
21
local ExpUtil = require("modules/exp_util")
32

43
local Event = {
@@ -66,7 +65,8 @@ function Event.on_init(handler)
6665
end
6766

6867
handlers[#handlers + 1] = handler
69-
Event.add(Clustorio.events.on_server_startup, handler)
68+
Event.add(defines.events.on_singleplayer_init, handler)
69+
Event.add(defines.events.on_multiplayer_init, handler)
7070
end
7171

7272
function Event.on_load(handler)

exp_util/module/async.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,10 @@ end
408408
local e = defines.events
409409
local events = {
410410
[e.on_tick] = on_tick,
411+
[e.on_singleplayer_init] = Async.on_init,
412+
[e.on_multiplayer_init] = Async.on_init,
411413
}
412414

413-
local Clustorio = ExpUtil.optional_require("modules/clusterio/api")
414-
if Clustorio then
415-
events[Clustorio.events.on_server_startup] = Async.on_init
416-
end
417-
418415
Async._function_metatable.__call = Async._function_prototype.start_soon
419416
Async.events = events --- @package
420417
return Async

exp_util/module/include/package.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-- luacheck:ignore global package
22

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

exp_util/module/storage.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,10 @@ function Storage.on_init()
119119
end
120120
end
121121

122-
local events = {}
123-
124-
local Clustorio = ExpUtil.optional_require("modules/clusterio/api")
125-
if Clustorio then
126-
events[Clustorio.events.on_server_startup] = Storage.on_init
127-
end
122+
--- @package
123+
Storage.events = {
124+
[defines.events.on_multiplayer_init] = Storage.on_init,
125+
[defines.events.on_singleplayer_init] = Storage.on_init,
126+
}
128127

129-
Storage.events = events --- @package
130128
return Storage

0 commit comments

Comments
 (0)