-
Notifications
You must be signed in to change notification settings - Fork 4
/
control.lua
82 lines (68 loc) · 2.91 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
if script.level.campaign_name then return end -- Don't init if it's a campaign
if script.level.level_name == "sandbox" then return end -- Don't init if it's "sandbox" scenario
MAKE_DEFINE_GLOBAL = true
require("defines")
---@type table<string, module>
local modules = {}
modules.example_module = require("models/example-module")
modules.data_consistency_example = require("models/data-consistency-example")
-- modules.empty_module = require("models.empty-module")
--- Adds https://github.com/ZwerOxotnik/factorio-BetterCommands if exists
if script.active_mods["BetterCommands"] then
local is_ok, better_commands = pcall(require, "__BetterCommands__/BetterCommands/control")
if is_ok then
better_commands.COMMAND_PREFIX = MOD_SHORT_NAME
modules.better_commands = better_commands
end
end
-- Safe disabling of this mod remotely on init stage
-- Useful for other map developers and in some rare cases for mod devs
if remote.interfaces["disable-" .. script.mod_name] then
for _, module in pairs(modules) do
local update_global_data_on_disabling = module.update_global_data_on_disabling
module.events = nil
module.on_nth_tick = nil
module.commands = nil
module.on_load = nil
module.add_remote_interface = nil
module.add_commands = nil
module.on_configuration_changed = update_global_data_on_disabling
module.on_init = update_global_data_on_disabling
end
else
if modules.better_commands then
if modules.better_commands.handle_custom_commands then
-- Adds commands
for _, module in pairs(modules) do
modules.better_commands.handle_custom_commands(module)
end
end
if modules.better_commands.expose_global_data then
modules.better_commands.expose_global_data()
end
end
end
local event_handler
if script.active_mods["zk-lib"] then
-- Same as Factorio "event_handler", but slightly better performance
local is_ok, zk_event_handler = pcall(require, "__zk-lib__/static-libs/lualibs/event_handler_vZO.lua")
if is_ok then
event_handler = zk_event_handler
end
end
event_handler = event_handler or require("event_handler")
event_handler.add_libraries(modules)
-- Auto adds remote access for rcon and for other mods/scenarios via zk-lib
if script.active_mods["zk-lib"] then
local is_ok, remote_interface_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/remote-interface-util")
if is_ok and remote_interface_util.expose_global_data then
remote_interface_util.expose_global_data()
end
local is_ok, rcon_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/rcon-util")
if is_ok and rcon_util.expose_global_data then
rcon_util.expose_global_data()
end
end
-- This is a part of "gvv", "Lua API global Variable Viewer" mod. https://mods.factorio.com/mod/gvv
-- It makes possible gvv mod to read sandboxed variables in the map or other mod if following code is inserted at the end of empty line of "control.lua" of each.
if script.active_mods["gvv"] then require("__gvv__.gvv")() end