-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontrol.lua
75 lines (61 loc) · 1.72 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
handler = require("script/event_handler")
names = require("shared")
util = require("script/script_util")
--error(serpent.block(defines.events))
local libs = {
--debug = require "script/debug",
unit_deployment = require("script/unit_deployment"),
hive_mind = require("script/hive_mind"),
creep = require("script/creep"),
pollution_lab = require("script/pollution_lab")
}
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
else
--error(lib_name.." needs to have a get events function cmon lets be reasonable now ok I know its some boiler plate etc. but its alright its more efficient")
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)