-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdbg.lua
More file actions
136 lines (113 loc) · 2.95 KB
/
dbg.lua
File metadata and controls
136 lines (113 loc) · 2.95 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- Debug utilities
local _dbg = {}
-- Draw coordinates, and visualise the current cursor position both scaled and unscaled.
_dbg.coords = {
enabled = false,
keybind = 'c',
draw = function()
love.graphics.setFont(fonts.sans.small)
local mx, my = love.mouse.getPosition()
local umx, umy = unscaled(love.mouse.getPosition())
love.graphics.setLineWidth(4)
love.graphics.setColor(0,1,0)
love.graphics.line(mx, 0, mx, resolution.y)
love.graphics.line(umx, 0, umx, resolution.y)
love.graphics.setColor(1,0.1,0.1)
love.graphics.line(0, my, resolution.x, my)
love.graphics.line(0, umy, resolution.x, umy)
love.graphics.setColor(1,1,0)
love.graphics.rectangle("line", 0, 0, scaled_res.x, scaled_res.y)
love.graphics.rectangle("line", 0, 0, resolution.x, resolution.y)
love.graphics.setColor(1,1,1)
love.graphics.setLineWidth(1)
local coord = {"scaled = {",mx,",",my,"}\nunscaled = {",umx,",",umy,"}\nozxa units = {",math.floor(umx/40),",",math.floor(umy/40),"}"}
love.graphics.print(table.concat(coord), 5, 460)
end
}
_dbg.grid = {
enabled = false,
keybind = 'g',
draw = function()
love.graphics.setColor(1,1,1, 0.25)
love.graphics.setLineWidth(1)
local cellSize = 40
for x = cellSize, resolution.x, cellSize do
love.graphics.line(x, 0, x, resolution.y)
end
for y = cellSize, resolution.y, cellSize do
love.graphics.line(0, y, resolution.x, y)
end
end
}
_dbg.info = {
enabled = false,
keybind = 'f',
draw = function()
love.graphics.setFont(fonts.sans.small)
love.graphics.print("FPS: "..love.timer.getFPS()..", Running at "..scaled_res.x.."x"..scaled_res.y, 5, 10)
end
}
_dbg.box_pos = {
enabled = false,
keybind = 'p',
draw = function()
-- nothing
end
}
_dbg.phys_pause = {
enabled = false,
keybind = 'i',
draw = function()
love.graphics.print("Physics iteration paused", 500, 0)
end
}
_dbg.restart = {
enabled = false,
keybind = 'r',
draw = function()
scene.restart()
_dbg.restart.enabled = false
end
}
_dbg.autorestart = {
enabled = false,
keybind = 't',
}
dbg = {}
local debugEnabled = nil
function dbg.debugEnabled()
if debugEnabled == nil then
if love.filesystem.getInfo(".git")
or love.filesystem.getInfo("debug.txt") then
debugEnabled = true
else
debugEnabled = false
end
end
return debugEnabled
end
function dbg.runUpdate()
if not love.keyboard.isDown('f3') or not dbg.debugEnabled() then return end
for id, def in pairs(_dbg) do
if love.keyboard.isDown(def.keybind) and not sparsifier[def.keybind] then
_dbg[id].enabled = not _dbg[id].enabled
end
sparsifier[def.keybind] = love.keyboard.isDown(def.keybind)
end
end
-- Call draw functions for enabled debug options
function dbg.runDraw()
if not dbg.debugEnabled() then return end
for _, def in pairs(_dbg) do
if def.enabled then
love.graphics.setColor(1,1,1)
love.graphics.setFont(fonts.sans.medium)
if def.draw then
def.draw()
end
end
end
end
function dbg.isEnabled(option)
return _dbg[option].enabled
end