Merge a card refresh (#59)
- **Refactored Card Placement Flow** - Separated card presentation from orchestration logic - Extracted `CornerCardManager` for pending card lifecycle (spawn, shuffle, rebuild) - Extracted `AlbumNavigationService` for book page navigation and zone mapping - Extracted `CardEnlargeController` for backdrop management and card reparenting - Implemented controller pattern (non-MonoBehaviour) for complex logic - Cards now unparent from slots before rebuild to prevent premature destruction - **Improved Corner Card Display** - Fixed cards spawning on top of each other during rebuild - Implemented shuffle-to-front logic (remaining cards occupy slots 0→1→2) - Added smart card selection (prioritizes cards matching current album page) - Pending cards now removed from queue immediately on drag start - Corner cards rebuild after each placement with proper slot reassignment - **Enhanced Album Card Viewing** - Added dramatic scale increase when viewing cards from album slots - Implemented shrink animation when dismissing enlarged cards - Cards transition: `PlacedInSlotState` → `AlbumEnlargedState` → `PlacedInSlotState` - Backdrop shows/hides with card enlarge/shrink cycle - Cards reparent to enlarged container while viewing, return to slot after - **State Machine Improvements** - Added `CardStateNames` constants for type-safe state transitions - Implemented `ICardClickHandler` and `ICardStateDragHandler` interfaces - State transitions now use cached property indices - `BoosterCardContext` separated from `CardContext` for single responsibility - **Code Cleanup** - Identified unused `SlotContainerHelper.cs` (superseded by `CornerCardManager`) - Identified unused `BoosterPackDraggable.canOpenOnDrop` field - Identified unused `AlbumViewPage._previousInputMode` (hardcoded value) - Identified unused `Card.OnPlacedInAlbumSlot` event (no subscribers) Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Reviewed-on: #59
This commit is contained in:
106
Assets/Scripts/CardSystem/Data/CardData.cs
Normal file
106
Assets/Scripts/CardSystem/Data/CardData.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
[Serializable]
|
||||
public class CardData
|
||||
{
|
||||
// Core data (serialized)
|
||||
public string Id; // Auto-generated unique ID (GUID)
|
||||
public string DefinitionId; // ID of the card definition this instance was created from
|
||||
public CardRarity Rarity; // Current rarity (may be upgraded from original)
|
||||
public int CopiesOwned; // Number of copies the player has (for stacking)
|
||||
|
||||
// Reference back to the definition (not serialized)
|
||||
[NonSerialized]
|
||||
private CardDefinition _definition;
|
||||
|
||||
// Properties that reference definition data
|
||||
public string Name => _definition?.Name;
|
||||
public string Description => _definition?.Description;
|
||||
public CardZone Zone => _definition?.Zone ?? CardZone.AppleHills;
|
||||
public int CollectionIndex => _definition?.CollectionIndex ?? 0;
|
||||
public Sprite CardImage => _definition?.CardImage;
|
||||
|
||||
// Default constructor
|
||||
public CardData()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString();
|
||||
CopiesOwned = 0;
|
||||
}
|
||||
|
||||
// Constructor from definition
|
||||
public CardData(CardDefinition definition)
|
||||
{
|
||||
Id = Guid.NewGuid().ToString();
|
||||
DefinitionId = definition.Id;
|
||||
Rarity = definition.Rarity;
|
||||
CopiesOwned = 1;
|
||||
_definition = definition;
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
public CardData(CardData other)
|
||||
{
|
||||
Id = other.Id;
|
||||
DefinitionId = other.DefinitionId;
|
||||
Rarity = other.Rarity;
|
||||
CopiesOwned = other.CopiesOwned;
|
||||
_definition = other._definition;
|
||||
}
|
||||
|
||||
// Method to link this card data to its definition
|
||||
public void SetDefinition(CardDefinition definition)
|
||||
{
|
||||
if (definition != null)
|
||||
{
|
||||
_definition = definition;
|
||||
DefinitionId = definition.Id;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to upgrade rarity when enough copies are collected
|
||||
public bool TryUpgradeRarity()
|
||||
{
|
||||
// Simple implementation - each rarity needs twice as many copies to upgrade
|
||||
int requiredCopies = (int)Rarity * 2 + 1;
|
||||
|
||||
if (CopiesOwned >= requiredCopies && Rarity < CardRarity.Legendary)
|
||||
{
|
||||
Rarity += 1;
|
||||
CopiesOwned -= requiredCopies;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ToString method for debugging
|
||||
public override string ToString()
|
||||
{
|
||||
return $"CardData [ID: {Id}, Name: {Name}, Rarity: {Rarity}, Zone: {Zone}, " +
|
||||
$"DefinitionID: {DefinitionId}, Copies: {CopiesOwned}, " +
|
||||
$"Has Definition: {_definition != null}, Has Image: {CardImage != null}]";
|
||||
}
|
||||
}
|
||||
|
||||
// Enums for card attributes
|
||||
public enum CardRarity
|
||||
{
|
||||
Normal = 0,
|
||||
Rare = 1,
|
||||
Legendary = 2
|
||||
}
|
||||
|
||||
public enum CardZone
|
||||
{
|
||||
NotApplicable,
|
||||
AppleHills,
|
||||
Quarry,
|
||||
CementFactory,
|
||||
CentralStreet,
|
||||
Valentine,
|
||||
Dump
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user