Update assets, working save kerfuffle
This commit is contained in:
@@ -8,8 +8,7 @@ namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Specialized slot for album pages that only accepts a specific card.
|
||||
/// Validates cards based on their CardDefinition.
|
||||
/// Self-populates with owned cards when enabled.
|
||||
/// Empty by default, auto-spawns owned cards on enable.
|
||||
/// </summary>
|
||||
public class AlbumCardSlot : DraggableSlot
|
||||
{
|
||||
@@ -17,17 +16,57 @@ namespace UI.CardSystem
|
||||
[SerializeField] private CardDefinition targetCardDefinition; // Which card this slot accepts
|
||||
[SerializeField] private GameObject cardPrefab; // Card prefab to spawn when card is owned
|
||||
|
||||
private StateMachine.Card _placedCard;
|
||||
private StateMachine.Card _assignedCard; // The card currently in this slot (if any)
|
||||
|
||||
/// <summary>
|
||||
/// Get the target card definition for this slot
|
||||
/// </summary>
|
||||
public CardDefinition TargetCardDefinition => targetCardDefinition;
|
||||
|
||||
/// <summary>
|
||||
/// Check if this slot has a card assigned to it
|
||||
/// </summary>
|
||||
public bool HasCardAssigned => _assignedCard != null;
|
||||
|
||||
/// <summary>
|
||||
/// Get the card currently assigned to this slot
|
||||
/// </summary>
|
||||
public StateMachine.Card AssignedCard => _assignedCard;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// Check if we should spawn a card for this slot
|
||||
CheckAndSpawnOwnedCard();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Assign a card to this slot (called by AlbumViewPage after placement animation)
|
||||
/// </summary>
|
||||
public void AssignCard(StateMachine.Card card)
|
||||
{
|
||||
if (card == null)
|
||||
{
|
||||
Logging.Warning("[AlbumCardSlot] Attempted to assign null card to slot");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_assignedCard != null && _assignedCard != card)
|
||||
{
|
||||
Logging.Warning($"[AlbumCardSlot] Slot already has a card assigned, replacing with new card");
|
||||
// Clean up old card
|
||||
if (_assignedCard.gameObject != null)
|
||||
{
|
||||
Destroy(_assignedCard.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
_assignedCard = card;
|
||||
Logging.Debug($"[AlbumCardSlot] Card '{card.CardData?.Name}' assigned to slot for {targetCardDefinition?.name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if player owns the card for this slot and spawn it if so
|
||||
/// (Called on OnEnable to handle game reload scenarios)
|
||||
/// </summary>
|
||||
private void CheckAndSpawnOwnedCard()
|
||||
{
|
||||
@@ -35,9 +74,12 @@ namespace UI.CardSystem
|
||||
if (CardSystemManager.Instance == null || targetCardDefinition == null)
|
||||
return;
|
||||
|
||||
// Guard: don't spawn if already occupied
|
||||
if (_placedCard != null)
|
||||
// Guard: don't spawn if already has a card assigned
|
||||
if (_assignedCard != null)
|
||||
{
|
||||
Logging.Debug($"[AlbumCardSlot] Slot for {targetCardDefinition.name} already has card assigned, skipping spawn");
|
||||
return;
|
||||
}
|
||||
|
||||
// Guard: need prefab to spawn
|
||||
if (cardPrefab == null)
|
||||
@@ -46,31 +88,41 @@ namespace UI.CardSystem
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if player owns this card at ANY rarity (prioritize highest rarity)
|
||||
CardData ownedCard = null;
|
||||
// Check if player owns this card in COLLECTION (not pending)
|
||||
CardData ownedCard = FindOwnedCardForSlot();
|
||||
|
||||
// Check in order: Legendary > Rare > Normal
|
||||
foreach (CardRarity rarity in new[] { CardRarity.Legendary, CardRarity.Rare, CardRarity.Normal })
|
||||
{
|
||||
CardData card = CardSystemManager.Instance.GetCardInventory().GetCard(targetCardDefinition.Id, rarity);
|
||||
if (card != null)
|
||||
{
|
||||
ownedCard = card;
|
||||
break; // Found highest rarity owned
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn card if owned
|
||||
// Only spawn if owned (not pending)
|
||||
if (ownedCard != null)
|
||||
{
|
||||
SpawnCard(ownedCard);
|
||||
Logging.Debug($"[AlbumCardSlot] Found owned card for {targetCardDefinition.name}, spawning");
|
||||
SpawnOwnedCard(ownedCard);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn a Card in this slot using the PlacedInSlotState
|
||||
/// Find owned card for this slot (checks collection only, not pending)
|
||||
/// </summary>
|
||||
private void SpawnCard(CardData cardData)
|
||||
private CardData FindOwnedCardForSlot()
|
||||
{
|
||||
var inventory = CardSystemManager.Instance.GetCardInventory();
|
||||
|
||||
// Check in order: Legendary > Rare > Normal (prioritize highest rarity)
|
||||
foreach (CardRarity rarity in new[] { CardRarity.Legendary, CardRarity.Rare, CardRarity.Normal })
|
||||
{
|
||||
CardData card = inventory.GetCard(targetCardDefinition.Id, rarity);
|
||||
if (card != null)
|
||||
{
|
||||
return card; // Found highest rarity owned
|
||||
}
|
||||
}
|
||||
|
||||
return null; // Not owned
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn a card that the player already owns (for reload scenarios)
|
||||
/// </summary>
|
||||
private void SpawnOwnedCard(CardData cardData)
|
||||
{
|
||||
GameObject cardObj = Instantiate(cardPrefab, transform);
|
||||
var card = cardObj.GetComponent<StateMachine.Card>();
|
||||
@@ -79,22 +131,21 @@ namespace UI.CardSystem
|
||||
{
|
||||
// Setup card for album slot (starts in PlacedInSlotState)
|
||||
card.SetupForAlbumSlot(cardData, this);
|
||||
_placedCard = card;
|
||||
|
||||
// Resize the card to match the slot size
|
||||
RectTransform cardRect = card.transform as RectTransform;
|
||||
RectTransform slotRect = transform as RectTransform;
|
||||
if (cardRect != null && slotRect != null)
|
||||
{
|
||||
// Set height to match slot height (AspectRatioFitter will handle width)
|
||||
float targetHeight = slotRect.rect.height;
|
||||
cardRect.sizeDelta = new Vector2(cardRect.sizeDelta.x, targetHeight);
|
||||
|
||||
// Ensure position and rotation are centered
|
||||
cardRect.localPosition = Vector3.zero;
|
||||
cardRect.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
// Assign card to this slot
|
||||
_assignedCard = card;
|
||||
|
||||
// Register with AlbumViewPage for enlarge/shrink handling
|
||||
AlbumViewPage albumPage = FindFirstObjectByType<AlbumViewPage>();
|
||||
if (albumPage != null)
|
||||
@@ -110,16 +161,5 @@ namespace UI.CardSystem
|
||||
Destroy(cardObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the target card definition for this slot
|
||||
/// </summary>
|
||||
public CardDefinition TargetCardDefinition => targetCardDefinition;
|
||||
|
||||
/// <summary>
|
||||
/// Get the target card definition for this slot (method version for compatibility)
|
||||
/// </summary>
|
||||
public CardDefinition GetTargetCardDefinition() => targetCardDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user