Fix puzzle lockout

This commit is contained in:
Michal Pikulski
2025-11-03 10:57:14 +01:00
parent 3e343d074c
commit c933f657a7
2 changed files with 30 additions and 942 deletions

File diff suppressed because one or more lines are too long

View File

@@ -72,6 +72,9 @@ namespace PuzzleS
// Registration for ObjectiveStepBehaviour // Registration for ObjectiveStepBehaviour
private Dictionary<PuzzleStepSO, ObjectiveStepBehaviour> _stepBehaviours = new Dictionary<PuzzleStepSO, ObjectiveStepBehaviour>(); private Dictionary<PuzzleStepSO, ObjectiveStepBehaviour> _stepBehaviours = new Dictionary<PuzzleStepSO, ObjectiveStepBehaviour>();
// Track pending unlocks for steps that were unlocked before their behavior registered
private HashSet<string> _pendingUnlocks = new HashSet<string>();
/// <summary> /// <summary>
/// Returns true if this participant has already had its state restored. /// Returns true if this participant has already had its state restored.
/// Used by SaveLoadManager to prevent double-restoration. /// Used by SaveLoadManager to prevent double-restoration.
@@ -333,8 +336,15 @@ namespace PuzzleS
_stepBehaviours.Add(behaviour.stepData, behaviour); _stepBehaviours.Add(behaviour.stepData, behaviour);
Logging.Debug($"[Puzzles] Registered step: {behaviour.stepData.stepId} on {behaviour.gameObject.name}"); Logging.Debug($"[Puzzles] Registered step: {behaviour.stepData.stepId} on {behaviour.gameObject.name}");
// Use pending registration pattern for save/load timing independence // Check if this step has a pending unlock
if (_isDataRestored) if (_pendingUnlocks.Contains(behaviour.stepData.stepId))
{
// Step was unlocked before behavior registered - unlock it now!
behaviour.UnlockStep();
_pendingUnlocks.Remove(behaviour.stepData.stepId);
Logging.Debug($"[Puzzles] Fulfilled pending unlock for step: {behaviour.stepData.stepId}");
}
else if (_isDataRestored)
{ {
// Data already restored - update immediately // Data already restored - update immediately
UpdateStepState(behaviour); UpdateStepState(behaviour);
@@ -482,9 +492,16 @@ namespace PuzzleS
if (_stepBehaviours.TryGetValue(step, out var behaviour)) if (_stepBehaviours.TryGetValue(step, out var behaviour))
{ {
// Behavior exists - unlock it immediately
behaviour.UnlockStep(); behaviour.UnlockStep();
Logging.Debug($"[Puzzles] Step unlocked: {step.stepId}");
}
else
{
// Behavior hasn't registered yet - add to pending unlocks
_pendingUnlocks.Add(step.stepId);
Logging.Debug($"[Puzzles] Step unlocked but behavior not registered yet, added to pending: {step.stepId}");
} }
Logging.Debug($"[Puzzles] Step unlocked: {step.stepId}");
// Broadcast unlock // Broadcast unlock
OnStepUnlocked?.Invoke(step); OnStepUnlocked?.Invoke(step);