-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhudebug.lua
162 lines (127 loc) · 3.25 KB
/
hudebug.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
local hudebug = {}
hudebug.active = false
hudebug.color = {}
hudebug.page = 1
hudebug.pageCount = 0
hudebug.color.r = 255
hudebug.color.g = 0
hudebug.color.b = 0
hudebug.color.a = 255
hudebug.posx = 5
hudebug.posy = 0
hudebug.scale = 1.2
hudebug.slots = {}
--[[
function hudebug.setHudColor
@param (number) r, (number) g, (number) b, (number) a
-Values for red, green, blue, and alpha (opacity) respectively.
Changes the color of the text displayed by HuDebug.
]]--
function hudebug.setHudColor(r,g,b,a)
hudebug.color.r = r
hudebug.color.g = g
hudebug.color.b = b
hudebug.color.a = a
end
--[[
function hudebug.setScale
@param (number) scale
-Value for scaling of text
Scales the HuDebug text.
]]--
function hudebug.setScale(scale)
hudebug.scale = scale
end
--[[
function hudebug.setPosition
@param (number) x, (number) y
-Values for position of debugging.
Moves the position of the top-left corner of the text.
]]--
function hudebug.setPosition(x,y)
hudebug.posx = x
hudebug.posy = y
end
--[[
function hudebug.pageName
@param (number) page, (string) name
-Which page index and what name for the page
Either creates or renames the page depending on whether or not hudebug.slots[page] existed.
]]--
function hudebug.pageName(page, name)
if not hudebug.slots[page] then
hudebug.slots[page] = {}
hudebug.slots[page].name = name
hudebug.pageCount = hudebug.pageCount + 1
else
hudebug.slots[page].name = name
end
end
--[[
function hudebug.updateMsg
@param (number) page, (integer/string) slot, (string/integer) msg
Stores the message msg to page page in the unique key slot
]]--
function hudebug.updateMsg(page,slot,msg)
if msg == "" then
msg = nil end
if not hudebug.slots[page] then
hudebug.slots[page] = {}
end
hudebug.slots[page][slot] = msg
end
--[[
function hudebug.reset
Resets all pages and values.
If you call this you need to create pages again. Maybe add a clear Page function
]]--
function hudebug.reset()
hudebug.slots = nil
hudebug.slots = {}
if hudebug.active then
hudebug.active = false
end
end
--[[
function hudebug.toggle
Sets active state of HuDebug to on/off
]]--
function hudebug.toggle()
hudebug.active = not hudebug.active
end
--[[
function hudebug.nextPage
Iterates through the pages. Pages, like lua tables, start at index 1.
]]--
function hudebug.nextPage()
local p = hudebug.page
if p == hudebug.pageCount then
hudebug.page = 1
else
hudebug.page = p + 1
end
end
--[[
function hudebug.draw
Draws the text to the screen.
]]--
function hudebug.draw()
if (not hudebug.active) then return end
local c = 1
local y = hudebug.posy
local page = hudebug.page
love.graphics.push()
love.graphics.scale(hudebug.scale)
love.graphics.reset()
love.graphics.setColor(hudebug.color.r,hudebug.color.g,hudebug.color.b,hudebug.color.a)
love.graphics.print("--Debug: " .. hudebug.slots[page].name .. "--",hudebug.posx,hudebug.posy)
for i,v in pairs(hudebug.slots[page]) do
if i ~= "name" then
y = hudebug.posy+ c*20
love.graphics.print(v,hudebug.posx,y)
c = c+1
end
end
love.graphics.pop()
end
return hudebug