From 258ea85277a8b46e04f74457c0faf1d277e6fbd6 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 9 Jan 2024 22:55:26 +0100 Subject: [PATCH] Hopefully no more save deletion --- main.lua | 13 +++++++++++-- metadata.xml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main.lua b/main.lua index 1ab05a3..df7b3ef 100644 --- a/main.lua +++ b/main.lua @@ -6,6 +6,7 @@ mod.print = Isaac.ConsoleOutput mod.game = Game() local savegen = include("save") local save = savegen:new() +local saveloaded = false local json = include("json") local DEBUG = false local getgamedata = Isaac.GetPersistentGameData -- Repentogon exclusive @@ -141,6 +142,7 @@ function mod:newrun() if DEBUG then mod.print(data .. "\n") end save = savegen:new() save:load(json, data) + saveloaded = true else save = savegen:new() end @@ -163,19 +165,26 @@ function mod:newrun() mod.print(".\n") end +function mod:endrun() + saveloaded = false +end + function mod:save() mod:SaveData(save:dump(json)) end mod:AddCallback(ModCallbacks.MC_POST_GAME_END, mod.save) mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, mod.newrun) +mod:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, mod.endrun) if not isrepentogon then -- Used to check for new items mod:AddCallback(ModCallbacks.MC_POST_UPDATE, mod.update) else function mod.addCollectibleCallaback(_, id, _, _, _, _) - mod.registerTouched(id) + if saveloaded then + mod.registerTouched(id) + end end - -- This is not a vanilla callback, it is from repentogon + -- This is not a vanilla callback mod:AddCallback(ModCallbacks.MC_POST_ADD_COLLECTIBLE, mod.addCollectibleCallaback) end diff --git a/metadata.xml b/metadata.xml index 7524289..315e6fb 100644 --- a/metadata.xml +++ b/metadata.xml @@ -23,7 +23,7 @@ This mod is still relevant in itself if you do not want to use external tools, o Anyway, I hope that this mod will be useful to someone :) Source code is available at https://forge.chapril.org/ayte/DeadGodHelper - 1.13 + 1.14 Public