-
Notifications
You must be signed in to change notification settings - Fork 78
/
init.lua
249 lines (183 loc) · 6.02 KB
/
init.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- central library table
loveframes = {}
-- library info
loveframes.info = {}
loveframes.info.author = "Nikolai Resokav"
loveframes.info.version = "0.9.2.5"
loveframes.info.stage = "Alpha"
-- library configurations
loveframes.config = {}
loveframes.config["DIRECTORY"] = "libraries/loveframes"
loveframes.config["DEFAULTSKIN"] = "Blue"
loveframes.config["ACTIVESKIN"] = "Blue"
loveframes.config["INDEXSKINIMAGES"] = true
loveframes.config["DEBUG"] = true
loveframes.drawcount = 0
loveframes.hoverobject = false
loveframes.modalobject = false
--[[---------------------------------------------------------
- func: load()
- desc: loads the library
--]]---------------------------------------------------------
function loveframes.load()
-- install directory of the library
local dir = loveframes.config["DIRECTORY"]
-- require the internal base libraries
require(dir .. "/third-party/middleclass/middleclass")
require(dir .. "/util")
require(dir .. "/skins")
require(dir .. "/templates")
require(dir .. "/debug")
-- create a list of gui objects and skins
local objects = loveframes.util.GetDirContents(dir .. "/objects")
local skins = loveframes.util.GetDirContents(dir .. "/skins")
-- loop through a list of all gui objects and require them
for k, v in ipairs(objects) do
if v.extension == "lua" then
require(v.path .. "/" ..v.name)
end
end
-- loop through a list of all gui skins and require them
for k, v in ipairs(skins) do
if v.extension == "lua" then
require(v.path .. "/" ..v.name)
end
end
-- create the base gui object
loveframes.base = base:new()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates all library objects
--]]---------------------------------------------------------
function loveframes.update(dt)
local object = loveframes.base
object:update(dt)
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws all library objects
--]]---------------------------------------------------------
function loveframes.draw()
local object = loveframes.base
-- set the drawcount to zero
loveframes.drawcount = 0
-- draw the base object
object:draw()
-- draw the debug library
loveframes.debug.draw()
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function loveframes.mousepressed(x, y, button)
local object = loveframes.base
object:mousepressed(x, y, button)
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function loveframes.mousereleased(x, y, button)
local object = loveframes.base
object:mousereleased(x, y, button)
if button == "l" then
loveframes.hoverobject = false
end
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function loveframes.keypressed(key, unicode)
local object = loveframes.base
object:keypressed(key, unicode)
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function loveframes.keyreleased(key)
local object = loveframes.base
object:keyreleased(key)
end
--[[---------------------------------------------------------
- func: New(type, parent)
- desc: creates a new object or multiple new objects
(based on the method used) and returns said
object or objects for further manipulation
--]]---------------------------------------------------------
function loveframes.Create(data, parent)
if type(data) == "string" then
-- create the new object
local object = _G[data]:new()
if object.internal == true then
if object.type == "tooltip" then
object = tooltip:new()
else
return
end
end
-- parent the new object by default to the base gui object
object.parent = loveframes.base
table.insert(loveframes.base.children, object)
-- if the parent argument is not nil, make that argument the object's new parent
if parent ~= nil then
object:SetParent(parent)
end
-- return the object for further manipulation
return object
elseif type(data) == "table" then
-- table for creation of multiple objects
local objects = {}
-- this function reads a table that contains a layout of object properties and then
-- creates objects based on those properties
local function CreateObjects(t, o, c)
local child = c or false
for k, v in pairs(t) do
-- current default object
local object = _G[v.type]:new()
-- indert the object into the table of objects being created
table.insert(objects, object)
-- parent the new object by default to the base gui object
object.parent = loveframes.base
table.insert(loveframes.base.children, object)
if o then
object:SetParent(o)
end
-- loop through the current layout table and assign the properties found
-- to the current object
for i, j in pairs(v) do
if i ~= "children" and i ~= "func" then
if child == true then
if i == "x" then
object["staticx"] = j
elseif i == "y" then
object["staticy"] = j
else
object[i] = j
end
else
object[i] = j
end
elseif i == "children" then
CreateObjects(j, object, true)
end
end
if v.func then
v.func(object)
end
end
end
-- create the objects
CreateObjects(data)
return objects
end
end
-- load the library
loveframes.load()