Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scripts/stageapi/core/saveSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down