Almost working card state machine
This commit is contained in:
@@ -27,21 +27,29 @@ namespace UI.CardSystem.StateMachine
|
||||
public CardData CardData => cardData;
|
||||
|
||||
// Runtime state
|
||||
public bool IsNewCard { get; set; }
|
||||
public int RepeatCardCount { get; set; }
|
||||
public bool IsClickable { get; set; } = true;
|
||||
public bool SuppressRevealBadges { get; set; } = false; // Set by states to suppress NEW/REPEAT badges in revealed state
|
||||
|
||||
// Events for external coordination (BoosterOpeningPage, etc.)
|
||||
public event Action<CardContext> OnFlipComplete;
|
||||
public event Action<CardContext> OnCardDismissed;
|
||||
public event Action<CardContext> OnCardInteractionComplete;
|
||||
public event Action<CardContext> OnUpgradeTriggered;
|
||||
// Original transform data (captured on spawn for shrink animations)
|
||||
public Vector3 OriginalScale { get; private set; }
|
||||
public Vector3 OriginalPosition { get; private set; }
|
||||
public Quaternion OriginalRotation { get; private set; }
|
||||
|
||||
// Helper methods for states
|
||||
public void FireFlipComplete() => OnFlipComplete?.Invoke(this);
|
||||
public void FireCardDismissed() => OnCardDismissed?.Invoke(this);
|
||||
public void FireCardInteractionComplete() => OnCardInteractionComplete?.Invoke(this);
|
||||
public void FireUpgradeTriggered() => OnUpgradeTriggered?.Invoke(this);
|
||||
// Single event for reveal flow completion
|
||||
public event Action<CardContext> OnRevealFlowComplete;
|
||||
|
||||
private bool _hasCompletedReveal = false;
|
||||
public bool HasCompletedReveal => _hasCompletedReveal;
|
||||
|
||||
// Helper method for states to signal completion
|
||||
public void NotifyRevealComplete()
|
||||
{
|
||||
if (!_hasCompletedReveal)
|
||||
{
|
||||
_hasCompletedReveal = true;
|
||||
OnRevealFlowComplete?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -55,15 +63,58 @@ namespace UI.CardSystem.StateMachine
|
||||
if (stateMachine == null)
|
||||
stateMachine = GetComponentInChildren<AppleMachine>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// Subscribe to CardDisplay click and route to active state
|
||||
if (cardDisplay != null)
|
||||
{
|
||||
cardDisplay.OnCardClicked += HandleCardDisplayClicked;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (cardDisplay != null)
|
||||
{
|
||||
cardDisplay.OnCardClicked -= HandleCardDisplayClicked;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCardDisplayClicked(CardDisplay _)
|
||||
{
|
||||
// Gate by clickability
|
||||
if (!IsClickable) return;
|
||||
if (stateMachine == null || stateMachine.currentState == null) return;
|
||||
|
||||
var handler = stateMachine.currentState.GetComponent<ICardClickHandler>();
|
||||
if (handler != null)
|
||||
{
|
||||
handler.OnCardClicked(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup the card with data
|
||||
/// </summary>
|
||||
public void SetupCard(CardData data, bool isNew = false, int repeatCount = 0)
|
||||
public void SetupCard(CardData data)
|
||||
{
|
||||
cardData = data;
|
||||
IsNewCard = isNew;
|
||||
RepeatCardCount = repeatCount;
|
||||
_hasCompletedReveal = false; // Reset completion flag
|
||||
|
||||
// Capture original transform for shrink animations.
|
||||
// If current scale is ~0 (pop-in staging), default to Vector3.one.
|
||||
var currentScale = transform.localScale;
|
||||
if (currentScale.x < 0.01f && currentScale.y < 0.01f && currentScale.z < 0.01f)
|
||||
{
|
||||
OriginalScale = Vector3.one;
|
||||
}
|
||||
else
|
||||
{
|
||||
OriginalScale = currentScale;
|
||||
}
|
||||
OriginalPosition = transform.localPosition;
|
||||
OriginalRotation = transform.localRotation;
|
||||
|
||||
if (cardDisplay != null)
|
||||
{
|
||||
@@ -77,4 +128,3 @@ namespace UI.CardSystem.StateMachine
|
||||
public CardDisplay GetCardDisplay() => cardDisplay;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user