-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomhandler.lua
346 lines (336 loc) · 10.7 KB
/
customhandler.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
local sound = require "music"
local coins = require "coins"
path = (love.filesystem.isFused() and "Source/Custom/") or "Custom/"
local readOnlyValues = {
VERSION = "constant",
TILE_EMPTY = "TILE_* constant",
TILE_WALL1 = "TILE_* constant",
TILE_WALL2 = "TILE_* constant",
TILE_WALL3 = "TILE_* constant",
TILE_WALL4 = "TILE_* constant",
TILE_WALL5 = "TILE_* constant",
TILE_WALL6 = "TILE_* constant",
TILE_WALL7 = "TILE_* constant",
TILE_WALL8 = "TILE_* constant",
TILE_WALL9 = "TILE_* constant",
TILE_FLOOR1 = "TILE_* constant",
TILE_FLOOR2 = "TILE_* constant",
TILE_FLOOR3 = "TILE_* constant",
TILE_LOCK = "TILE_* constant",
TILE_KEY = "TILE_* constant",
TILE_REDSWITCH = "TILE_* constant",
TILE_BLUESWITCH = "TILE_* constant",
TILE_START = "TILE_* constant",
TILE_GOAL = "TILE_* constant",
TILE_REDWALLON = "TILE_* constant",
TILE_BLUEWALLON = "TILE_* constant",
TILE_REDWALLOFF = "TILE_* constant",
TILE_BLUEWALLOFF = "TILE_* constant",
TILE_AFLOOR1 = "TILE_* constant",
TILE_AFLOOR2 = "TILE_* constant",
TILE_RIGHTPUSHER1 = "TILE_* constant",
TILE_RIGHTPUSHER2 = "TILE_* constant",
TILE_RIGHTPUSHER3 = "TILE_* constant",
TILE_LEFTPUSHER1 = "TILE_* constant",
TILE_LEFTPUSHER2 = "TILE_* constant",
TILE_LEFTPUSHER3 = "TILE_* constant",
TILE_UPPUSHER1 = "TILE_* constant",
TILE_UPPUSHER2 = "TILE_* constant",
TILE_UPPUSHER3 = "TILE_* constant",
TILE_DOWNPUSHER1 = "TILE_* constant",
TILE_DOWNPUSHER2 = "TILE_* constant",
TILE_DOWNPUSHER3 = "TILE_* constant",
TILE_SPIKEON = "TILE_* constant",
TILE_SPIKEOFF = "TILE_* constant",
TILE_SPIKE = "TILE_* constant",
TILE_BRIDGE = "TILE_* constant",
TILE_CRACKEDBRIDGE = "TILE_* constant",
TILE_SLIME = "TILE_* constant",
TILE_CHASM1 = "TILE_* constant",
TILE_CHASM2 = "TILE_* constant",
TILE_ENEMY = "TILE_* constant",
TILE_CUSTOM1 = "TILE_* constant",
TILE_CUSTOM2 = "TILE_* constant",
TILE_CUSTOM3 = "TILE_* constant",
TILE_BRIDGE_ROTATED = "TILE_* constant",
TILE_CRACKEDBRIDGE_ROTATED = "TILE_* constant",
DIR_LEFT = "DIR_* constant",
DIR_RIGHT = "DIR_* constant",
DIR_UP = "DIR_* constant",
DIR_DOWN = "DIR_* constant",
player = "reference",
tilemap = "reference",
leveltime = "checker",
timer = "checker",
}
local tilesetFlagsTypes = {
snow = "boolean",
dark = "boolean",
rain = "table",
thunder = "boolean",
glitch = "boolean",
enemyquadtype = "string",
bridgeshardcolor = "table",
rotatebridges = "boolean",
playersprite = "string",
keysprite = "string",
}
function CheckArgument(n, funcname, arg, ctype, bad)
local atype = type(arg)
if atype ~= ctype then
error("bad "..(bad or "argument").." #"..n.." to '"..funcname.."' ("..ctype.." expected, got "..atype..")")
end
end
function SearchCustom(modname)
local modtype = love.filesystem.getInfo(path..modname, "directory")
if not modtype then
messagebox.setMessage("Mod not found", "could not find folder named \""..modname.."\" in the Custom folder")
return false
end
path = path..modname
coins.reset()
sound.soundtest = {{name = "Love's path", subtitle = "Main menu", creator = "MAKYUNI", filename = "menu.ogg"}}
sound.getSounds(path.."/Sounds", true)
lastmap = 1
mapspath = path.."/Maps/"
GetAllMaps()
savefile = modname..".dat"
LoadData()
local ok, CustomInfo = pcall(love.filesystem.load, path.."/custom.lua")
if not CustomInfo then
customEnv = {}
return true
end
if not ok then love.window.showMessageBox("Failed to load custom.lua!", CustomInfo --[[@as string]], "error") return true end
local musics = love.filesystem.getDirectoryItems(path.."/Music")
if musics then
for _, musicname in ipairs(musics) do
if musicname:sub(#musicname - 3) == ".ogg" then
table.insert(possibleMusic, musicname)
end
end
end
customEnv = {
--MISCELLANEOUS LIBRARY--
VERSION = VERSION,
print = print,
log = debugmode and lovebug.log or print,
error = error,
type = type,
tostring = tostring,
tonumber = tonumber,
ipairs = ipairs,
pairs = pairs,
table = table,
math = math,
KeyPressed = nil,
SetMessageBox = function(title, text)
messagebox.setMessage(tostring(title), tostring(text))
end,
SetNotifcation = function(text)
notification.setMessage(tostring(text))
end,
--SOUND LIBRARY--
PlaySound = sound.playSound,
AddSoundTestEntry = function(name, subtitle, creator, filename, required)
CheckArgument(1, "AddSoundTestEntry", name, "string")
CheckArgument(4, "AddSoundTestEntry", filename, "string")
table.insert(sound.soundtest,
{name = name, subtitle = subtitle or "", creator = creator or "", filename = filename, require = tonumber(required)})
end,
--MAP LIBRARY--
TILE_EMPTY = 0,
TILE_WALL1 = 1,
TILE_WALL2 = 2,
TILE_WALL3 = 3,
TILE_WALL4 = 4,
TILE_WALL5 = 5,
TILE_WALL6 = 6,
TILE_WALL7 = 7,
TILE_WALL8 = 8,
TILE_WALL9 = 9,
TILE_FLOOR1 = 10,
TILE_FLOOR2 = 11,
TILE_FLOOR3 = 12,
TILE_LOCK = 13,
TILE_KEY = 14,
TILE_REDSWITCH = 15,
TILE_BLUESWITCH = 16,
TILE_START = 17,
TILE_GOAL = 18,
TILE_REDWALLON = 19,
TILE_BLUEWALLON = 20,
TILE_REDWALLOFF = 21,
TILE_BLUEWALLOFF = 22,
TILE_AFLOOR1 = 23,
TILE_AFLOOR2 = 24,
TILE_RIGHTPUSHER1 = 25,
TILE_RIGHTPUSHER2 = 26,
TILE_RIGHTPUSHER3 = 27,
TILE_LEFTPUSHER1 = 28,
TILE_LEFTPUSHER2 = 29,
TILE_LEFTPUSHER3 = 30,
TILE_UPPUSHER1 = 31,
TILE_UPPUSHER2 = 32,
TILE_UPPUSHER3 = 33,
TILE_DOWNPUSHER1 = 34,
TILE_DOWNPUSHER2 = 35,
TILE_DOWNPUSHER3 = 36,
TILE_SPIKEON = 37,
TILE_SPIKEOFF = 38,
TILE_SPIKE = 39,
TILE_BRIDGE = 40,
TILE_CRACKEDBRIDGE = 41,
TILE_SLIME = 42,
TILE_CHASM1 = 43,
TILE_CHASM2 = 44,
TILE_ENEMY = 45,
TILE_CUSTOM1 = 46,
TILE_CUSTOM2 = 47,
TILE_CUSTOM3 = 48,
TILE_BRIDGE_ROTATED = 50,
TILE_CRACKEDBRIDGE_ROTATED = 51,
tilemap = tilemap,
leveltime = nil,
timer = nil,
SetTimer = function(time)
timer = time
end,
CheckMap = CheckMap,
IterateMap = IterateMap,
SetTile = SetTile,
AddCustomCoin = function(map, x, y)
CheckArgument(1, "AddCustomCoin", map, "number")
CheckArgument(2, "AddCustomCoin", x, "number")
CheckArgument(3, "AddCustomCoin", y, "number")
coins[map] = {x = x, y = y, got = false}
LoadData()
end,
UpdateFrame = nil,
MapLoad = nil,
--QUADS LIBRARY--
GetDirectionalQuads = function(image)
return GetDirectionalQuads(path.."/"..image)
end,
GetQuads = function(n, image)
return GetQuads(n, path.."/"..image)
end,
GetExtraQuad = function(image)
return GetExtraQuad(path.."/"..image)
end,
--OBJECTS LIBRARY--
DIR_LEFT = 1,
DIR_RIGHT = 3,
DIR_UP = 5,
DIR_DOWN = 7,
player = player,
SpawnObject = function(sprite, ...)
return SpawnObject(path.."/"..sprite, ...)
end,
RemoveObject = RemoveObject,
RemoveMovingObject = RemoveMovingObject,
RemoveStandingObject = RemoveStandingObject,
RemoveCollidedObject = RemoveCollidedObject,
EraseObject = EraseObject,
DamageObject = DamageObject,
StopObject = StopObject,
PusherCheck = PusherCheck,
PushObject = PushObject,
SlowPushObject = SlowPushObject,
SearchObject = SearchObject,
TryMove = TryMove,
PredictMove = PredictMove,
DirectionMomentum = DirectionMomentum,
MomentumDirection = MomentumDirection,
GetDistance = GetDistance,
DashObject = DashObject,
FireShot = FireShot,
FacePlayer = FacePlayer,
EndLevel = EndLevel,
AddObjectType = AddObjectType,
AddObjectCollision = function(motype, collidedmotype, collision)
CheckArgument(1, "AddObjectCollision", motype, "string")
CheckArgument(2, "AddObjectCollision", collidedmotype, "string")
if not collisions[motype] then error('object type "'..motype..'" does not exist!') end
if not collisions[collidedmotype] then error('object type "'..collidedmotype..'" does not exist!') end
if collisions[motype][collidedmotype] then
error('object type "'..motype..'" arleady has collisions defined for "'..collidedmotype..'"!')
end
collisions[motype][collidedmotype] = collision
end,
GetString = require("ffi").string,
--TILESET LIBRARY--
wallDesc = "\nMost objects can't walk in this tile",
floorDesc = "\nObjects can walk in this tile",
spikeDesc = "\nObjects in this tile will be destroyed",
AddCustomTileset = function(tilesetname, description, collision, tile, flags)
CheckArgument(1, "AddCustomTileset", tilesetname, "string")
if tilesets[tilesetname] then error('tileset "'..tilesetname..'" arleady exists!') end
tilesets[tilesetname] = {
custom = true,
description = setmetatable(description or {}, {__index = function() return "MISSING INFO!" end}),
collision = setmetatable(collision or {}, {__index = function() return true end}),
tile = setmetatable(tile or {}, {__index = function() return nil end})
}
if flags then
local num = 0
for k, v in pairs(flags) do
num = num + 1
if tilesetFlagsTypes[k] then
CheckArgument(num, k, v, tilesetFlagsTypes[k], "tileset flag value")
tilesets[tilesetname][k] = v
else
error("Unknown tileset flag \""..k.."\"")
end
end
end
table.insert(possibleTilesets, tilesetname)
end,
}
setfenv(CustomInfo, setmetatable({}, {
__index = function(t, k) if customEnv[k] then return customEnv[k] end end,
__newindex = function(t, k, v)
if readOnlyValues[k] then
error('attempt to modify read-only value "'..k..'" ('..readOnlyValues[k]..')')
return
end
customEnv[k] = v
end
}))
local ok, errormsg2 = pcall(CustomInfo)
if not ok then love.window.showMessageBox("Error while loading custom.lua!", errormsg2, "error") end
return true
end
function GetTilesetPath()
if tilesetname == "" then tilesetname = "forest.png" end
local testpath = path
if tilesets[tilesetname] and type(tilesets[tilesetname]) == "table" then
testpath = (tilesets[tilesetname].custom and path) or "Sprites"
else
if tilesetname == "forest.png" then
error("the default tileset is missing.\n"..
"If you did not alter the source code in any way, contact me!")
end
local errorname = "Error while loading tileset!"
local errormsg = 'the tileset "'..tilesetname..'" was not found\n'.."the default tileset will be used instead."
messagebox.setMessage(errorname, errormsg, true)
tilesetname = "forest.png"
return GetTilesetPath()
end
if love.filesystem.getInfo(testpath, "directory")
and love.filesystem.getInfo(testpath.."/Tiles/"..tilesetname)
and love.filesystem.getInfo(testpath.."/Enemies/"..tilesetname) then
return testpath.."/"
else
if tilesetname == "forest.png" then
error("The default tileset is broken.\n"..
"Undo any modifications done to it or reinstall the .exe")
end
local errorname = "Error while loading tileset!"
local errormsg = 'The tileset "'..tilesetname..'" has missing sprites\n'..
"the default tileset will be used instead."
messagebox.setMessage(errorname, errormsg, true)
tilesetname = "forest.png"
return GetTilesetPath()
end
end