-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
120 lines (102 loc) · 3.57 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Train = require("__flib__.train")
Misc = require("__flib__.misc")
Area = require("__flib__.area")
Event = require("__flib__.event")
Gui = require("__flib__.gui")
message_level = tonumber(settings.global["ltn-interface-console-level"].value)
debug_log = settings.global["ltn-interface-debug-logfile"].value
Elevator = require("elevator-connection")
ElevatorUI = require("elevator-ui")
Delivery = require("ltn-delivery")
local function initialize()
global.elevators = global.elevators or {}
global.players = global.players or {}
global.ltn_stops = global.ltn_stops or {}
end
local function register_event_handlers()
Event.register(remote.call("space-exploration", "get_on_train_teleport_started_event"), Delivery.on_train_teleport_started)
Event.register(remote.call("logistic-train-network", "on_stops_updated"), Delivery.on_stops_updated)
Event.register(remote.call("logistic-train-network", "on_dispatcher_updated"), Delivery.on_dispatcher_updated)
end
local function check_delivery_reset_setting(report_to)
if settings.global["ltn-dispatcher-requester-delivery-reset"].value then
report_to.print({ "se-ltn-glue-message.requester-delivery-reset-should-be-disabled", { "mod-setting-name.ltn-dispatcher-requester-delivery-reset" } })
end
end
Event.on_init(function()
initialize()
register_event_handlers()
end)
Event.on_load(function()
register_event_handlers()
end)
Event.on_configuration_changed(function()
initialize()
check_delivery_reset_setting(game)
end)
Event.register(defines.events.on_entity_destroyed, Elevator.on_entity_destroyed)
Event.register({ defines.events.on_player_created, defines.events.on_player_joined_game }, function(e)
local player = game.get_player(e.player_index)
if player and player.connected then
check_delivery_reset_setting(player)
end
end)
Event.register(defines.events.on_player_removed, function(e)
local player_data = global.players[e.player_index]
if player_data and player_data.elevator_gui then
player_data.elevator_gui.destroy()
end
global.players[e.player_index] = nil
end)
Event.register(defines.events.on_runtime_mod_setting_changed, function(e)
if not e then return end
if e.setting == "ltn-interface-console-level" then
message_level = tonumber(settings.global["ltn-interface-console-level"].value)
elseif e.setting == "ltn-interface-debug-logfile" then
debug_log = settings.global["ltn-interface-debug-logfile"].value
elseif e.setting == "ltn-dispatcher-requester-delivery-reset" then
check_delivery_reset_setting(game)
end
Delivery.on_runtime_mod_setting_changed(e)
end)
local function safe_destroy(maybe_entity)
if maybe_entity and maybe_entity.valid then
maybe_entity.destroy()
end
end
remote.add_interface("se-ltn-glue", {
reset = function()
for _, data in pairs(global.elevators) do
safe_destroy(data.connector)
if data.ground then
safe_destroy(data.ground.connector)
end
if data.orbit then
safe_destroy(data.orbit.connector)
end
end
for _, data in pairs(global.players) do
if data.elevator_gui then
data.elevator_gui.destroy()
end
end
global.elevators = {}
global.players = {}
end,
connect_elevator = function(elevator_entity, network_id)
local data = Elevator.from_entity(elevator_entity)
if data then
data.network_id = network_id
data.ltn_enabled = true
Elevator.update_connection(data)
end
end,
disconnect_elevator = function(elevator_entity)
local data = Elevator.from_unit_number(elevator_entity.unit_number)
if data then
data.ltn_enabled = false
Elevator.update_connection(data)
end
end,
})
-- if script.active_mods["gvv"] then require("__gvv__.gvv")() end