forked from narc0tiq/evoGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
73 lines (58 loc) · 2.05 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
require "defines"
require "evoGUI"
if not evogui then evogui = {} end
function evogui.log(message)
if game then
for i, p in ipairs(game.players) do
p.print(message)
end
else
error(serpent.dump(message, {compact = false, nocode = true, indent = ' '}))
end
end
function evogui.format_number(n) -- credit http://richard.warburton.it
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
function string.starts_with(haystack, needle)
return string.sub(haystack, 1, string.len(needle)) == needle
end
local octant_names = {
[0] = {"direction.east"},
[1] = {"direction.southeast"},
[2] = {"direction.south"},
[3] = {"direction.southwest"},
[4] = {"direction.west"},
[5] = {"direction.northwest"},
[6] = {"direction.north"},
[7] = {"direction.northeast"},
}
function evogui.get_octant_name(vector)
local radians = math.atan2(vector.y, vector.x)
local octant = math.floor( 8 * radians / (2*math.pi) + 8.5 ) % 8
return octant_names[octant]
end
script.on_init(evogui.mod_init)
script.on_configuration_changed(evogui.mod_update)
script.on_load(function()
local status, err = pcall(RemoteSensor.initialize)
if err then evogui.log({"err_generic", "on_load", err}) end
end)
script.on_event(defines.events.on_player_created, function(event)
local status, err = pcall(evogui.new_player, event)
if err then evogui.log({"err_generic", "on_player_created", err}) end
end)
script.on_event(defines.events.on_tick, function(event)
local status, err = pcall(evogui.update_gui, event)
if err then evogui.log({"err_generic", "on_tick", err}) end
end)
script.on_event(defines.events.on_gui_click, function(event)
local status, err = pcall(evogui.on_gui_click, event)
if err then
if event.element.valid then
evogui.log({"err_specific", "on_gui_click", event.element.name, err})
else
evogui.log({"err_generic", "on_gui_click", err})
end
end
end)