forked from Klonan/Construction_Drones
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
76 lines (63 loc) · 1.61 KB
/
control.lua
File metadata and controls
76 lines (63 loc) · 1.61 KB
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
handler = require("script/event_handler")
names = require("shared")
util = require("script/script_util")
local libs = {
--auto_request = require("script/auto_request"),
construction_drone = require("script/construction_drone"),
freeplay_interface = require("script/freeplay_interface"),
}
local on_event = function(event)
for name, lib in pairs (libs) do
if lib.on_event then
lib.on_event(event)
end
end
end
local register_events = function(libraries)
local all_events = {}
for lib_name, lib in pairs (libraries) do
if lib.get_events then
local lib_events = lib.get_events()
for k, handler in pairs (lib_events) do
all_events[k] = all_events[k] or {}
all_events[k][lib_name] = handler
end
end
end
for event, handlers in pairs (all_events) do
local action
action = function(event)
for k, handler in pairs (handlers) do
handler(event)
end
end
script.on_event(event, action)
end
end
local on_init = function()
--game.speed = settings.startup["game-speed"].value
for name, lib in pairs (libs) do
if lib.on_init then
lib.on_init()
end
end
register_events(libs)
end
local on_load = function()
for name, lib in pairs (libs) do
if lib.on_load then
lib.on_load()
end
end
register_events(libs)
end
local on_configuration_changed = function(data)
for name, lib in pairs (libs) do
if lib.on_configuration_changed then
lib.on_configuration_changed(data)
end
end
end
script.on_init(on_init)
script.on_load(on_load)
script.on_configuration_changed(on_configuration_changed)