Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exp_commands/module/commands/ipc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ local Clustorio = require("modules/clusterio/api")

local json_to_table = helpers.json_to_table

Commands.add_rcon_static("Clustorio", Clustorio)
Commands.add_rcon_static("ipc", Clustorio.send_json)

Commands.new("_ipc", { "exp-commands_ipc.description" })
:argument("channel", { "exp-commands_ipc.arg-channel" }, Commands.types.string)
:argument("message", { "exp-commands_ipc.arg-message" }, Commands.types.string)
Expand Down
3 changes: 0 additions & 3 deletions exp_commands/module/commands/rcon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ System command which runs arbitrary code within a custom (not sandboxed) environ
local ExpUtil = require("modules/exp_util")
local Async = require("modules/exp_util/async")
local Storage = require("modules/exp_util/storage")
local Clustorio = require("modules/clusterio/api")

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

Expand All @@ -26,9 +25,7 @@ setmetatable(rcon_env, { __index = rcon_static })
rcon_static.Async = Async
rcon_static.ExpUtil = ExpUtil
rcon_static.Commands = Commands
rcon_static.Clustorio = Clustorio
rcon_static.print = Commands.print
rcon_static.ipc = Clustorio.send_json
--- @diagnostic enable: name-style-check

--- Some common callback values which are useful when a player uses the command
Expand Down
2 changes: 1 addition & 1 deletion exp_legacy/module/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ for _, error in ipairs(errors) do log(error) end

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

--- Register all event handlers via clusterio
--- Register all event handlers via event handler
local Event = require("modules/exp_legacy/utils/event")
return Event.real_handlers
4 changes: 2 additions & 2 deletions exp_legacy/module/utils/event.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local Clustorio = require("modules/clusterio/api")
local ExpUtil = require("modules/exp_util")

local Event = {
Expand Down Expand Up @@ -66,7 +65,8 @@ function Event.on_init(handler)
end

handlers[#handlers + 1] = handler
Event.add(Clustorio.events.on_server_startup, handler)
Event.add(defines.events.on_singleplayer_init, handler)
Event.add(defines.events.on_multiplayer_init, handler)
end

function Event.on_load(handler)
Expand Down
7 changes: 2 additions & 5 deletions exp_util/module/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions exp_util/module/include/package.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions exp_util/module/storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ function Storage.on_init()
end
end

local events = {}

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

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