mirror of
https://github.com/Earth-Genesis-Games/Ajedrez_Purgatorio.git
synced 2026-09-11 09:47:35 +00:00
fix: 6 critical bugs blocking campaign flow
C1: CampaignManager._pendingChapterIndex consumed in OnSceneLoaded (Start only runs once for DontDestroyOnLoad) C2: PieceIdentityManager.AssignIdentities() called after BoardManager.SetupBoard C3: CampaignState.Reset() populates _alivePieces from _allIdentities C4: GameManager no longer calls GameStateManager.TransitionTo — CampaignManager handles state exclusively C5: PromotionUI uses only callback, removes duplicate PromotePawnTo call C6: DialogueSystem.StartDialogue fires OnDialogueComplete on failure (returns bool now) W1: OnChapterDefeat calls AutoSaveProgress to persist defeat state W2: PauseMenuController uses SceneTransitionManager for fade effect
This commit is contained in:
@@ -156,13 +156,20 @@ public class CampaignState : ScriptableObject
|
||||
public void Reset()
|
||||
{
|
||||
_completedChapters.Clear();
|
||||
_alivePieces.Clear();
|
||||
_totalPiecesLost = 0;
|
||||
_currentChapterPiecesLost = 0;
|
||||
_lastChapterWasVictory = false;
|
||||
_lastCompletedChapterId = null;
|
||||
|
||||
Debug.Log("[CampaignState] Estado reseteado.");
|
||||
// Initialize all pieces as alive for new campaign
|
||||
_alivePieces.Clear();
|
||||
foreach (var identity in _allIdentities)
|
||||
{
|
||||
if (identity != null && !string.IsNullOrEmpty(identity.characterName))
|
||||
_alivePieces.Add(identity.characterName.ToLower());
|
||||
}
|
||||
|
||||
Debug.Log($"[CampaignState] Estado reseteado. {_alivePieces.Count} piezas inicializadas como vivas.");
|
||||
}
|
||||
|
||||
// ==================== COMPATIBILIDAD CON SISTEMAS EXISTENTES ====================
|
||||
|
||||
@@ -72,16 +72,7 @@ public class CampaignManager : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Retry subscription (handles race condition with GameManager.Awake)
|
||||
SubscribeToGameManager();
|
||||
|
||||
// If we have a pending chapter, load it now (scene just loaded)
|
||||
if (_pendingChapterIndex >= 0)
|
||||
{
|
||||
int idx = _pendingChapterIndex;
|
||||
_pendingChapterIndex = -1;
|
||||
InitializeChapter(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════
|
||||
@@ -112,9 +103,15 @@ public class CampaignManager : MonoBehaviour
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
// Re-subscribe when a new scene loads (new GameManager created)
|
||||
_subscribedToGameManager = false;
|
||||
SubscribeToGameManager();
|
||||
|
||||
if (_pendingChapterIndex >= 0)
|
||||
{
|
||||
int idx = _pendingChapterIndex;
|
||||
_pendingChapterIndex = -1;
|
||||
InitializeChapter(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════
|
||||
@@ -240,6 +237,11 @@ public class CampaignManager : MonoBehaviour
|
||||
if (BoardManager.Instance != null && _campaignState != null)
|
||||
{
|
||||
BoardManager.Instance.SetupBoard(_campaignState);
|
||||
|
||||
// Assign narrative identities to pieces
|
||||
var pim = FindObjectOfType<PieceIdentityManager>();
|
||||
if (pim != null)
|
||||
pim.AssignIdentities();
|
||||
}
|
||||
|
||||
// AI config
|
||||
@@ -345,6 +347,7 @@ public class CampaignManager : MonoBehaviour
|
||||
if (_campaignState != null && CurrentChapter != null)
|
||||
_campaignState.CompleteChapter(CurrentChapter.id, wasVictory: false);
|
||||
|
||||
AutoSaveProgress();
|
||||
TransitionToDeadKings();
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class DialogueSystem : MonoBehaviour
|
||||
/// Inicia un diálogo por ID.
|
||||
/// </summary>
|
||||
/// <param name="dialogueId">ID del diálogo a iniciar</param>
|
||||
public void StartDialogue(string dialogueId)
|
||||
public bool StartDialogue(string dialogueId)
|
||||
{
|
||||
if (_isActive)
|
||||
{
|
||||
@@ -108,7 +108,8 @@ public class DialogueSystem : MonoBehaviour
|
||||
if (!_dialogues.ContainsKey(dialogueId))
|
||||
{
|
||||
Debug.LogError($"[DialogueSystem] Diálogo no encontrado: {dialogueId}");
|
||||
return;
|
||||
OnDialogueComplete?.Invoke();
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentDialogue = _dialogues[dialogueId];
|
||||
@@ -116,7 +117,8 @@ public class DialogueSystem : MonoBehaviour
|
||||
if (_currentDialogue.nodes == null || _currentDialogue.nodes.Count == 0)
|
||||
{
|
||||
Debug.LogError($"[DialogueSystem] Diálogo {dialogueId} no tiene nodos.");
|
||||
return;
|
||||
OnDialogueComplete?.Invoke();
|
||||
return false;
|
||||
}
|
||||
|
||||
_isActive = true;
|
||||
@@ -124,6 +126,7 @@ public class DialogueSystem : MonoBehaviour
|
||||
|
||||
// Mostrar primer nodo
|
||||
DisplayNode(_currentDialogue.nodes[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -537,9 +537,7 @@ private void OnPromotionSelected(PieceType pieceType)
|
||||
if (AudioManager.Instance != null)
|
||||
AudioManager.Instance.PlayCheckmate();
|
||||
|
||||
// GameStateManager: transition to GameOver
|
||||
if (GameStateManager.Instance != null)
|
||||
GameStateManager.Instance.TransitionTo(GameState.GameOver);
|
||||
// GameState transition handled by CampaignManager via OnCheckmate event
|
||||
}
|
||||
|
||||
private void OnGameDraw(string reason)
|
||||
@@ -547,8 +545,6 @@ private void OnPromotionSelected(PieceType pieceType)
|
||||
Debug.LogWarning($"¡Tablas! Razón: {reason}");
|
||||
OnDraw?.Invoke(reason);
|
||||
|
||||
// GameStateManager: transition to GameOver (draw = defeat in campaign)
|
||||
if (GameStateManager.Instance != null)
|
||||
GameStateManager.Instance.TransitionTo(GameState.GameOver);
|
||||
// GameState transition handled by CampaignManager via OnDraw event
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,8 +184,11 @@ namespace AjedrezPurgatorio.UI
|
||||
if (GameStateManager.Instance != null)
|
||||
GameStateManager.Instance.TransitionTo(GameState.Menu);
|
||||
|
||||
// Load main menu scene
|
||||
SceneManager.LoadScene(_mainMenuSceneName);
|
||||
// Load main menu scene with fade transition
|
||||
if (SceneTransitionManager.Instance != null)
|
||||
SceneTransitionManager.Instance.LoadScene(_mainMenuSceneName);
|
||||
else
|
||||
SceneManager.LoadScene(_mainMenuSceneName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -69,10 +69,7 @@ public class PromotionUI : MonoBehaviour
|
||||
// Reanudar el juego
|
||||
Time.timeScale = 1f;
|
||||
|
||||
// Ejecutar promoción
|
||||
GameManager.Instance.PromotePawnTo(_pawnToPromote, pieceType);
|
||||
|
||||
// Callback opcional
|
||||
// Callback — CampaignManager/GameManager handles promotion via callback
|
||||
_onPromotionSelected?.Invoke(pieceType);
|
||||
|
||||
_pawnToPromote = null;
|
||||
|
||||
Reference in New Issue
Block a user