forked from masondevelops1/forecasted-restoration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.lua
More file actions
458 lines (406 loc) · 13.8 KB
/
mod.lua
File metadata and controls
458 lines (406 loc) · 13.8 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
function Mod:afmGetMusic()
if Mod.ghast_tear_real then return end
if Mod:intermissionReached() then return "AUDIO_DRONE" end
--if Mod:ch7Reached() then return "spireselect" end
return "sinkingfeeling"
end
function Mod:afmGetChapterName()
--if Mod:ch7Reached() then return "Chapter 7" end
return "Chapter 6"
end
function Mod:afmGetStyle()
--if Mod:ch7Reached() then
--return "ch7"
--end
return "DEVICE"
end
function Mod:getPaletteColor(key)
if Mod.ghast_tear_real then return end
if Mod:intermissionReached() then return end
if key == "filemenu_deselected" then
return {0.5, 0.5, 0.5}
elseif key == "filemenu_selected" then
return {1,1,1}
elseif key == "filemenu_header" then
return {.5,.5,.5}
elseif key == "filemenu_copy" then
return {0.5,1,0.5}
elseif key == "filemenu_settings" then
return {0.4,1.0,0.2}
end
end
function Mod:afmCreateBackground(bg)
if Mod.ghast_tear_real then return end
if Mod:intermissionReached() then return end
--if Mod:ch7Reached() then return end
local gbg = AdvancedGonerBackground()
bg.sprite = Assets.getTexture("backgrounds/IMAGE_DEPTH_2")
bg:addChild(gbg)
end
function Mod:postInit()
love.window.setTitle("DELTARUNE")
love.window.setIcon(Assets.getTextureData("icons/deltarune"))
Kristal.setPresence({
details = "DELTARUNE Chapter 6",
state = "- CONNECTION FAILURE -",
largeImageKey = "https://i.imgur.com/IKdy5Nz.jpeg",
smallImageKey = "logo",
largeImageText = "DELTARUNE: Chapter 6 - In Too Deep",
smallImageText = "Kristal v" .. tostring(Kristal.Version),
startTimestamp = math.floor(os.time() - Game.playtime),
instance = 0
})
if Mod:intermissionReached() then
Mod:stashPreIntermissionSaves()
return
end
print("Loaded "..self.info.name.."!")
end
function Mod:afmPostInit(new_file)
if Mod.ghast_tear_real then Mod.ghast_tear_real = nil end
if new_file then
local equipments = Mod.info.equipment
if equipments then
for id, equipped in pairs(equipments) do
local member = Game.party_data[id]
if member then
if equipped.weapon then
member:setWeapon(equipped.weapon ~= "" and equipped.weapon or nil)
end
local armors = equipped.armor or {}
for i = 1, #armors do
if armors[i] then
member:setArmor(i, armors[i] ~= "" and armors[i] or nil)
end
end
else
Kristal.Console:error("Attempted to set equipment for non-existent member " .. id)
end
end
end
local inventory = Mod.info.inventory
if inventory then
Game.inventory:clear()
Game.light_inventory:clear()
Game.dark_inventory:clear()
if inventory.items then
for i, item in ipairs(inventory.items) do
Game.inventory:setItem("items", i, item)
end
end
if inventory.key_items then
for i, item in ipairs(inventory.key_items) do
Game.inventory:setItem("key_items", i, item)
end
end
if inventory.storage then
for i, item in ipairs(inventory.storage) do
Game.inventory:setItem("storage", i, item)
end
end
end
if Mod:intermissionReached() then
Game.world:loadMap("basket")
--Plot:set("nf_school_init")
Game.world.menu = nil
else
Game.world:startCutscene("nightCutscenes.susie")
end
end
end
function Mod:unlockQuest(quest, silent)
if not silent and Game.stage then
--local popup = Game.stage:addChild(QuestCreatedPopup(quest))
--popup.layer = 1500
end
end
function Mod:completeQuest(quest, silent)
if not silent and Game.stage then
--local popup = Game.stage:addChild(QuestCompletedPopup(quest))
--popup.layer = 1500
end
end
function Mod:init()
Utils.hook(Encounter, "createSoul", function(orig, self, x, y, color)
if Game.battle.is_parry then
return ParrySoul(x, y)
end
return orig(self, x, y, color)
end)
Utils.hook(Encounter, "createSoul", function(orig, self, x, y, color)
if Game.battle.is_fast then
return FastSoul(x, y)
end
return orig(self, x, y, color)
end)
Utils.hook(Battle, "postInit", function(orig, self, ...)
---@cast self Battle
orig(self,...)
if self.encounter.background then
self.background = GonerBackground2();
self:addChild(self.background)
self.background:setLayer(BATTLE_LAYERS["bottom"] - 1)
end
end)
Utils.hook(Battle, "update", function (orig, self, ...)
---@cast self Battle
orig(self, ...)
if self.background then
self.background.alpha = self.transition_timer / 10
end
end)
Utils.hook(Battle, "onStateChange", function (orig, self, old, new)
---@cast self Battle
if new == "VICTORY" and self.background then
self.background.timer.active = false
end
return orig(self, old, new)
end)
-- Utils.hook(Battle, "drawBackground", function() end)
---@diagnostic disable-next-line: redefined-local
local self = Registry
-- TODO: PR this to kristal, it's cool
Utils.hook(Registry, "createMap", function(_,id, world, ...)
if self.maps[id] then
local map = self.maps[id](world, self.map_data[id], ...)
map.id = id
return map
elseif self.map_data[id] then
local map_class = self.maps[self.map_data[id].class] or Map
local map = map_class(world, self.map_data[id], ...)
map.id = id
return map
else
error("Attempt to create non existent map \"" .. tostring(id) .. "\"")
end
end)
end
function Mod:stashPreIntermissionSaves()
local base = "saves/" .. Mod.info.id
local stash = base .. "/pre-intermission"
local marker = base .. "/stash_completed"
if love.filesystem.getInfo(marker) then
return
end
if not love.filesystem.getInfo(stash) then
love.filesystem.createDirectory(stash)
end
local targets = { "file_1.json", "file_2.json", "file_3.json" }
local stashed_any = false
for _, filename in ipairs(targets) do
local src = base .. "/" .. filename
local dst = stash .. "/" .. filename
local info = love.filesystem.getInfo(src)
if info and info.type == "file" then
local data = love.filesystem.read(src)
if data then
love.filesystem.write(dst, data)
local check = love.filesystem.getInfo(dst)
if check and check.type == "file" then
love.filesystem.remove(src)
stashed_any = true
end
end
end
end
if stashed_any then
love.filesystem.write(marker, "ok")
end
end
function Mod:intermissionReached()
if Mod:ch7Reached() then return false end
local save_path = "saves/" .. Mod.info.id
local reset_file = love.filesystem.getInfo(save_path .. "/reset.json") ~= nil
return reset_file;
end
function Mod:ch7Reached()
local save_path = "saves/" .. Mod.info.id
local ch7_file = love.filesystem.getInfo(save_path .. "/chapter7.json") ~= nil
return ch7_file;
end
---@return Video
function Mod:video(id, callback)
local video = Video(id)
local callback_obj = Callback({
update = function (cbk)
if not video:isPlaying() then
if callback and callback(video, cbk) == false then return end
video:remove()
end
end
})
video:addChild(callback_obj)
video.x = SCREEN_WIDTH/2
video.origin_x = 0.5
return video
end
function Mod:load(data)
self.silly_mode = Game:getFlag("silly_mode", false)
self.silly_mode_last = self.silly_mode
Game:setFlag("silly_mode", self.silly_mode)
end
function Mod:registerDebugOptions(debug)
debug:registerOption("main", "Silly Mode", function() return debug:appendBool("Toggle Silly Mode", self.silly_mode) end, function()
self.silly_mode = not self.silly_mode
Game:setFlag("silly_mode", self.silly_mode)
end)
end
function Mod:postUpdate()
if Kristal.DebugSystem:isMenuOpen() then return end
if self.silly_mode ~= self.silly_mode_last then
if self.silly_mode_message then
self.silly_mode_message:remove()
end
if self.silly_mode then
Assets.playSound("won")
self.silly_mode_message = SillyModeMessage()
Game.stage:addChild(self.silly_mode_message)
end
Game:setFlag("silly_mode", self.silly_mode)
self.silly_mode_last = self.silly_mode
end
end
function Mod:loadObject(world,name,data)
if name == "gonerbg" then
if not self.shared_gonerbg then
---@type AdvancedGonerBackground
self.shared_gonerbg = AdvancedGonerBackground()
if data and data.properties and data.properties.collapse then
self.shared_gonerbg.saturation = 1
self.shared_gonerbg.container.timescale = 10
self.shared_gonerbg.afterimage_timer = 0
self.shared_gonerbg.sprite = Assets.getTexture("world/cutscenes/intro/DEPTH_MONO")
end
end
self.shared_gonerbg:applyProperties(data and data.properties or {})
self.shared_gonerbg:remove()
return self.shared_gonerbg
end
end
function Mod:getUISkin()
-- cool lore
if Game:getFlag("special_textbox") then
return "knight"
end
end
--- Convenience function for development
function Mod:runWave(wave)
assert(isClass(wave) or Registry.getWave(wave), "Invalid wave: "..Utils.dump(wave))
if not Game.battle then
Game:encounter("wavetester")
Game.battle.encounter.waves = {wave}
else
end
Game.battle:setState("DEFENDINGBEGIN", { wave })
Kristal.Console:close()
end
function Mod:playJingle(sound, ...)
local music = Game:getActiveMusic()
music:pause()
local src = Assets.playSound(sound, ...)
Game.stage.timer:afterCond(function ()
return not src:isPlaying()
end, function ()
music:resume()
end)
end
function Mod:getKeyringFlag(name)
local keyring = Game.inventory:getItemByID("keyring")
if not keyring then
return nil, false
end
return keyring:getFlag(name)
end
---@return boolean success Whether the flag was successfully set.
function Mod:setKeyringFlag(name, value)
local keyring = Game.inventory:getItemByID("keyring")
if not keyring then
return false
end
keyring:setFlag(name, value)
return true
end
function Mod:onRegistered()
-- TODO: Proper iterScripts? AHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHAH
Mod.pong_cutscenes = {
pirates = modRequire("scripts.pong.cutscenes.pirates")
}
end
function Mod.getPongCutscene(group, id)
local cutscene = Mod.pong_cutscenes[group]
if type(cutscene) == "table" then
return cutscene[id], true
elseif type(cutscene) == "function" then
return cutscene, false
end
end
function Mod:onMapMusic(map, orig_music)
-- Workaround for mapTransition passing the wrong map
if orig_music == "evergrove-outskirts" then
return "evergrove-outskirts"
end
if Utils.startsWith(map.id, "boat/") then
if orig_music == "waves" then
if false then
elseif not Plot:isBefore("boat_end") then
return "evergrove-outskirts"
elseif not Plot:isBefore("boat_act3_mapswitch") then
return "rain_outdoors"
end
-- TODO: Incorporate room101_confrontation into plot
elseif Plot:between("boat_act3_room101_confrontation", "boat_end", true, false) then
return "creepychase"
end
end
-- Cool nonstandard thing that should really be in Kristal tbh
if map.onMusic then
local mus = map:onMusic(orig_music)
if mus then return mus end
end
end
---@deprecated
---@param plot PLOT.key|PLOT
function Mod:plotAfter(plot)
return Plot:isAfter(plot)
end
---@deprecated
---@return PLOT
---@return PLOT.key
function Mod:getPlot()
local plot = Game:getFlag("plot", 0)
return plot, Utils.getKey(PLOT, plot)
end
---@deprecated
---@param plot PLOT.key|PLOT
function Mod:setPlot(plot)
return Plot:set(plot)
end
function Mod:quickerReload()
Kristal.callEvent(KRISTAL_EVENT.unload)
Kristal.setState("Empty")
Mod.info.loaded_scripts = false
Kristal.Mods.getAndLoadMod(Mod.info.id)
Kristal.callEvent(KRISTAL_EVENT.preInit)
Registry.initialize()
Kristal.setState("Game")
end
function Mod:getUISkin()
if self.ui_skin_override then return self.ui_skin_override end
if not (Game.world and Game.world.map and Game.world.map.id) then return end
if Utils.startsWith(Game.world.map.id, "gateway") then
return "twilight"
end
end
function Mod:setUISkin(skin)
self.ui_skin_override = skin
UISkinLib:swapUISkin(Kristal.callEvent(KRISTAL_EVENT.getUISkin) or (Game:isLight() and "light" or "dark"))
end
function Mod:onFootstep(char, num)
if char.world.map.data.properties.step_sound then
local player_only, step_sound = Utils.startsWith(char.world.map.data.properties.step_sound, "player:")
if player_only and not char.is_player then return end
local sound_path = "steps/"..step_sound .. Utils.clampWrap(num, 2)
print(sound_path)
Assets.playSound(sound_path)
end
end