-
Notifications
You must be signed in to change notification settings - Fork 5
/
toolset.lua
110 lines (96 loc) · 2.45 KB
/
toolset.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
local controls = require('controls')
local l = require('lume')
local sw, sh = love.graphics.getDimensions()
local log_entries = {}
local log_lines = 20
local tracking = {}
local moduleInitialized = false -- log module is initialized lazily
local actualLoveDraw
local font
local fontSize = 16
local draw_functions = {}
local function imposterLoveDraw()
actualLoveDraw()
local fader = 1
love.graphics.setFont(font)
for i = #log_entries, #log_entries - log_lines, -1 do
love.graphics.setColor(1, 1, 1, fader)
love.graphics.print(log_entries[i] or '', 5, 5 + (#log_entries - i) * fontSize)
fader = fader - 1 / log_lines
end
local line = 0
love.graphics.setColor(1, 1, 1)
for k,v in pairs(tracking) do
if type(v) == 'table' then
love.graphics.print(string.format(k,unpack(v)), sw*3/5, 5 + line * fontSize)
else
love.graphics.print(string.format(k,v), sw*3/5, 5 + line * fontSize)
end
line = line + 1
end
for _,v in ipairs(draw_functions) do
v()
end
end
local function init()
moduleInitialized = true
actualLoveDraw = love.draw
love.draw = imposterLoveDraw
font = love.graphics.newFont("Ubuntu-B.ttf", fontSize)
end
-- usage: log(speed)
-- usage: log('data: ', speed, x, y)
function log(...)
local arg={...}
local line
if #arg > 1 then
line = table.concat(arg, ", ")
else
line = tostring(arg[1])
end
print(line)
log_entries[#log_entries + 1] = line
end
-- usage: logf('speed: %1.2f m/s', speed)
function logf(s, ...)
line = string.format(s, ...)
print(line)
log_entries[#log_entries + 1] = line
end
-- usage: track('speed: %1.2f m/s', self.speed)
function track(format, value)
tracking[format] = value
return value
end
function drawTable(t, x, y)
local tabSize = 20 -- px
local x = x or sw * 3 / 5
local y = y or 5 + 4 * fontSize
love.graphics.setFont(font)
love.graphics.setColor(1, 1, 1)
for k,v in pairs(t) do
if type(v) == 'table' then
love.graphics.print(tostring(k), x, y)
y = y + fontSize *.2
x, y = drawTable(v, x + tabSize, y)
x = x - tabSize
else
local line
if type(v) == 'number' then
line = string.format('%s: %1.3f', k, v)
else
line = string.format('%s: %1s', k, v)
end
love.graphics.print(line, x, y)
end
y = y + fontSize *.6
end
return x, y
end
function addDraw(f)
table.insert(draw_functions, f)
end
if love.system.getOS() ~= 'Android' then
log_lines = 50
end
init()