diff --git a/scripts/stageapi/core/saveSystem.lua b/scripts/stageapi/core/saveSystem.lua index ace966b..1be5dd4 100644 --- a/scripts/stageapi/core/saveSystem.lua +++ b/scripts/stageapi/core/saveSystem.lua @@ -8,6 +8,7 @@ StageAPI.LogMinor("Loading Save System") StageAPI.SaveDataLoaded = false StageAPI.RoomsToLoad = {} +StageAPI.LevelMapsToLoad = {} function StageAPI.TryLoadModData(continued) if Isaac.HasModData(mod) and continued then @@ -230,9 +231,9 @@ function StageAPI.LoadSaveString(str) end end - StageAPI.LevelMaps = {} + StageAPI.LevelMapsToLoad = {} for _, levelMapSaveData in ipairs(decoded.LevelMaps) do - StageAPI.LevelMap({SaveData = levelMapSaveData}) + StageAPI.LevelMapsToLoad[#StageAPI.LevelMapsToLoad+1] = levelMapSaveData end StageAPI.CurrentLevelMapID = decoded.CurrentLevelMapID @@ -468,10 +469,15 @@ local function NewLevelLoad() StageAPI.RoomsToLoad[i] = nil end + for i = #StageAPI.LevelMapsToLoad, 1, -1 do + StageAPI.LevelMap({SaveData = StageAPI.LevelMapsToLoad[i]}) + StageAPI.LevelMapsToLoad[i] = nil + end + StageAPI.SaveModData() end -mod:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, NewLevelLoad) +mod:AddPriorityCallback(ModCallbacks.MC_POST_NEW_ROOM, CallbackPriority.IMPORTANT, NewLevelLoad) mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, function (_, isContinued) -- Needs to trigger also when loading a level if isContinued then