The forgotten push

This commit is contained in:
Michal Pikulski
2025-11-05 20:55:09 +01:00
committed by Michal Pikulski
parent 0204c11560
commit cd12c344a9
2 changed files with 35 additions and 4 deletions

View File

@@ -325,6 +325,13 @@ namespace Core
LogDebugMessage($"Skipping save for: {oldSceneName} (skipSave=true)");
}
// PHASE 4: Clear PuzzleManager state before scene transition
if (PuzzleS.PuzzleManager.Instance != null)
{
LogDebugMessage($"Clearing puzzle state before scene transition");
PuzzleS.PuzzleManager.Instance.ClearPuzzleState();
}
// PHASE 5: Remove all AstarPath (A* Pathfinder) singletons before loading the new scene
var astarPaths = FindObjectsByType<AstarPath>(FindObjectsSortMode.None);
foreach (var astar in astarPaths)

View File

@@ -184,6 +184,8 @@ namespace PuzzleS
return;
}
// Reset restoration flag when loading new scene data
_isDataRestored = false;
_isDataLoaded = false;
string addressablePath = $"Puzzles/{currentScene}";
@@ -213,11 +215,10 @@ namespace PuzzleS
_currentLevelData = handle.Result;
Logging.Debug($"[Puzzles] Loaded level data: {_currentLevelData.levelId} with {_currentLevelData.allSteps.Count} steps");
// Reset state
_completedSteps.Clear();
_unlockedSteps.Clear();
// Don't clear steps here - SceneManagerService calls ClearPuzzleState() before scene transitions
// This allows save restoration to work properly without race conditions
// Unlock initial steps
// Unlock initial steps (adds to existing unlocked steps from save restoration)
UnlockInitialSteps();
// Update all registered behaviors now that data is loaded
@@ -567,6 +568,27 @@ namespace PuzzleS
return _isDataLoaded;
}
/// <summary>
/// Clears all puzzle state (completed steps, unlocked steps, registrations).
/// Called by SceneManagerService before scene transitions to ensure clean state.
/// </summary>
public void ClearPuzzleState()
{
Logging.Debug("[PuzzleManager] Clearing puzzle state");
_completedSteps.Clear();
_unlockedSteps.Clear();
_isDataRestored = false;
// Clear any pending registrations from the old scene
_pendingRegistrations.Clear();
_pendingUnlocks.Clear();
// Unregister all step behaviours from the old scene
_stepBehaviours.Clear();
_registeredBehaviours.Clear();
}
#region Save/Load Lifecycle Hooks
protected override string OnSceneSaveRequested()
@@ -591,6 +613,8 @@ namespace PuzzleS
protected override void OnSceneRestoreRequested(string data)
{
Debug.Log("[XAXA] PuzzleManager loading with data: " + data);
if (string.IsNullOrEmpty(data) || data == "{}")
{
Logging.Debug("[PuzzleManager] No puzzle save data to restore");