-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathutils.lua
71 lines (61 loc) · 1.64 KB
/
utils.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
require "defines"
debug_level = -1 -- eventually change this in on_load() of the mod
local debug_player = nil
white = {r = 1, g = 1, b = 1}
red = {r = 1, g = 0.3, b = 0.3}
green = {r = 0, g = 1, b = 0}
blue = {r = 0, g = 0, b = 1}
yellow = {r = 1, g = 1, b = 0}
orange = {r = 1, g = 0.5, b = 0}
--------------------------------------------------------------------------------------
function debug( s, lvl )
if debug_player == nil then
if game.player then debug_player = game.player end
end
if debug_mem == nil then debug_mem = {} end
if lvl == nil then lvl = debug_level end
if (debug_level >= 0) and ((lvl >= debug_level) or (lvl == 0)) then
if debug_player then
if #debug_mem > 0 then
for _, m in pairs( debug_mem ) do
debug_player.print(m)
end
debug_mem = {}
end
if s ~= nil then debug_player.print(s) end
else
table.insert( debug_mem, s )
end
end
end
--------------------------------------------------------------------------------------
function square_area( origin, radius )
return {
{x=origin.x - radius, y=origin.y - radius},
{x=origin.x + radius, y=origin.y + radius}
}
end
--------------------------------------------------------------------------------------
function min( val1, val2 )
if val1 < val2 then
return val1
else
return val2
end
end
--------------------------------------------------------------------------------------
function max( val1, val2 )
if val1 > val2 then
return val1
else
return val2
end
end
--------------------------------------------------------------------------------------
function iif( cond, val1, val2 )
if cond then
return val1
else
return val2
end
end