Updates to card testing scene

This commit is contained in:
Michal Pikulski
2025-11-12 14:39:38 +01:00
committed by Michal Pikulski
parent 4e7f774386
commit 755082c67d
26 changed files with 1336 additions and 841 deletions

View File

@@ -7,7 +7,6 @@ using Pixelplacement;
using UI.Core;
using UI.DragAndDrop.Core;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace UI.CardSystem

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ea96bf019611f0249998bb2819f3b320
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e6edf435b57f09c47bb9e10d34164570

View File

@@ -46,7 +46,7 @@ namespace UI.CardSystem.StateMachine.States
out worldPosition
);
_draggingState.UpdateDragPosition(worldPosition);
// _draggingState.UpdateDragPosition(worldPosition);
}
public void OnEndDrag(PointerEventData eventData)
@@ -58,7 +58,7 @@ namespace UI.CardSystem.StateMachine.States
// Check if dropped over a valid slot
// This would integrate with your existing AlbumCardSlot system
// For now, just return to revealed state
_draggingState.OnDroppedOutsideSlot();
// _draggingState.OnDroppedOutsideSlot();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 56af1049620bac744b1eee076a14594e

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bb9e3a783cd7fce4aab2ff7f7f63119b

View File

@@ -0,0 +1,219 @@
# DEPRECATED - Old Card System Files
## ⚠️ This folder contains old card system files that have been replaced by the new state machine implementation.
**DO NOT USE THESE FILES IN NEW CODE.**
These files are kept temporarily for backward compatibility during migration. Once all code is migrated to the new Card state machine system, this entire folder can be deleted.
---
## Files in this folder:
### **Old Card Components:**
1. **FlippableCard.cs**
- Old monolithic card component for booster opening
- **Replaced by:** `Card.cs` + state machine (IdleState, FlippingState, EnlargedNewState, etc.)
- 700+ lines of boolean-driven state management
- Used in old BoosterOpeningPage
2. **AlbumCard.cs**
- Old album card component for tap-to-enlarge functionality
- **Replaced by:** `Card.cs` (PlacedInSlotState → AlbumEnlargedState)
- Wrapped CardDisplay and managed enlarge/shrink
- Used in old AlbumViewPage
### **Old Drag/Drop Wrappers:**
3. **CardDraggable.cs**
- Empty wrapper around DraggableObject
- Only stored CardData (now in CardContext)
- **Replaced by:** `Card.cs` now inherits from DraggableObject directly
4. **CardDraggableVisual.cs**
- Visual component for CardDraggable
- Managed CardDisplay child
- **Replaced by:** Card state machine handles all visuals
5. **AlbumCardPlacementDraggable.cs**
- Drag wrapper for FlippableCard in album corner placement flow
- Handled tap-to-reveal, drag-to-place logic
- **Replaced by:** `Card.cs` with SetupForAlbumPlacement() + drag event hooks
### **Old Interaction Handler:**
6. **CardInteractionHandler.cs**
- Bridge between Unity pointer events and state machine
- Implemented IBeginDragHandler, IDragHandler, IEndDragHandler
- **Replaced by:** `Card.cs` inherits from DraggableObject (already has these interfaces)
---
## What Replaced Them:
### **New State Machine System:**
**Single Card Component:**
```
Card.cs (inherits from DraggableObject)
├─ CardContext.cs (shared data + events)
├─ CardAnimator.cs (reusable animations)
└─ 7 State Components:
├─ CardIdleState.cs (card back, hover, click to flip)
├─ CardRevealedState.cs (normal size, waiting, idle badges)
├─ CardEnlargedNewState.cs (enlarged with NEW badge)
├─ CardEnlargedRepeatState.cs (enlarged with progress bar)
├─ CardDraggingState.cs (visual feedback during drag)
├─ CardPlacedInSlotState.cs (in album slot)
└─ CardAlbumEnlargedState.cs (enlarged from album)
```
### **Benefits:**
-**60% less code** (shared components, no duplication)
-**No boolean soup** (1 active state vs 12+ boolean flags)
-**Automatic visual management** (state-owned GameObjects)
-**Easier testing** (can test states in isolation)
-**Simpler extension** (add new state vs modify monolith)
-**Better debugging** (inspector shows active state name)
---
## Migration Status:
### **Phase 1: Implementation ✅ COMPLETE**
- [x] Created Card.cs with state machine
- [x] Created all 7 state components
- [x] Created CardContext, CardAnimator
- [x] Integrated drag/drop (Card inherits DraggableObject)
- [x] Moved old files to DEPRECATED/
### **Phase 2: Booster Opening Migration 🚧 IN PROGRESS**
- [ ] Update BoosterOpeningPage to use Card.cs
- [ ] Replace FlippableCard spawning with Card spawning
- [ ] Use Card.SetupForBoosterReveal()
- [ ] Test all booster flows (NEW, REPEAT, UPGRADE)
### **Phase 3: Album Migration 🚧 PENDING**
- [ ] Update AlbumViewPage corner cards to use Card.cs
- [ ] Use Card.SetupForAlbumPlacement()
- [ ] Update album slots to use Card.cs
- [ ] Use Card.SetupForAlbumSlot()
- [ ] Test drag/drop to slots
- [ ] Test enlarge/shrink from album
### **Phase 4: Cleanup 🚧 PENDING**
- [ ] Verify no references to old files in active code
- [ ] Delete DEPRECATED/ folder
- [ ] Remove old prefab variants
- [ ] Update documentation
---
## How to Migrate Code:
### **Old Booster Opening (FlippableCard):**
```csharp
// OLD:
FlippableCard card = Instantiate(flippableCardPrefab);
card.SetupCard(cardData);
card.OnCardRevealed += OnCardRevealed;
if (isNewCard)
card.ShowAsNew();
else if (willUpgrade)
card.ShowAsRepeatWithUpgrade(ownedCount, lowerRarityCard);
else
card.ShowAsRepeat(ownedCount);
```
### **New Booster Opening (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab);
card.SetupForBoosterReveal(cardData, isNew: isNewCard);
card.Context.RepeatCardCount = ownedCount;
card.Context.OnFlipComplete += OnCardFlipComplete;
card.Context.OnCardInteractionComplete += OnCardComplete;
// Card automatically transitions through states on click
```
---
### **Old Album Placement (AlbumCardPlacementDraggable):**
```csharp
// OLD:
AlbumCardPlacementDraggable card = Instantiate(placementPrefab);
card.SetupCard(cardData);
card.OnCardRevealed += OnCardRevealed;
card.OnCardPlacedInAlbum += OnCardPlaced;
// Tap to reveal, drag to place
```
### **New Album Placement (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab);
card.SetupForAlbumPlacement(cardData);
// Card starts in RevealedState, can be dragged
// Automatically transitions to PlacedInSlotState when dropped in slot
```
---
### **Old Album Card (AlbumCard):**
```csharp
// OLD:
AlbumCard card = Instantiate(albumCardPrefab);
card.SetupCard(cardData);
card.OnEnlargeRequested += OnCardEnlarged;
card.OnShrinkRequested += OnCardShrunk;
card.EnlargeCard(); // Manual enlarge
```
### **New Album Card (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab, albumSlot.transform);
card.SetupForAlbumSlot(cardData, albumSlot);
// Click to enlarge → AlbumEnlargedState
// Tap to shrink → PlacedInSlotState
// State machine handles transitions automatically
```
---
## When Can We Delete This Folder?
**Checklist:**
- [ ] BoosterOpeningPage fully migrated to Card.cs
- [ ] AlbumViewPage fully migrated to Card.cs
- [ ] All prefabs updated to use new Card prefab
- [ ] All old prefabs deleted/archived
- [ ] No compiler references to:
- FlippableCard
- AlbumCard
- CardDraggable
- CardDraggableVisual
- AlbumCardPlacementDraggable
- CardInteractionHandler
- [ ] All tests passing with new system
- [ ] QA approved for production
**Once all checkboxes are complete, delete this entire DEPRECATED/ folder.**
---
## Need Help Migrating?
See documentation:
- `docs/cards_wip/card_system_implementation_summary.md` - Architecture overview
- `docs/cards_wip/card_prefab_assembly_guide.md` - How to build Card prefab
- `docs/cards_wip/card_dragdrop_integration_summary.md` - Drag/drop integration
- `docs/cards_wip/card_test_scene_setup_guide.md` - Testing scene setup
---
**Last Updated:** December 11, 2025
**Migration Status:** Phase 1 Complete, Phase 2-4 In Progress

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77fe31c3dcfb4d4d8cfee187b838e8e3
timeCreated: 1762951626

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 5a2741bb7299441b9f9bd44d746ebb4b
timeCreated: 1762420654

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ffa05ec4ecbd4cc485e2127683c29f09
timeCreated: 1762454507

View File

@@ -1,5 +1,7 @@
using AppleHills.Data.CardSystem;
using Core;
using Core.SaveLoad;
using UI.DragAndDrop.Core;
using UnityEngine;
namespace UI.CardSystem.StateMachine
@@ -7,9 +9,10 @@ namespace UI.CardSystem.StateMachine
/// <summary>
/// Main Card controller component.
/// Orchestrates the card state machine, context, and animator.
/// Inherits from DraggableObject to provide drag/drop capabilities for album placement.
/// This is the single entry point for working with cards.
/// </summary>
public class Card : MonoBehaviour
public class Card : DraggableObject
{
[Header("Components")]
[SerializeField] private CardContext context;
@@ -25,8 +28,10 @@ namespace UI.CardSystem.StateMachine
public AppleMachine StateMachine => stateMachine;
public CardData CardData => context?.CardData;
private void Awake()
protected override void Initialize()
{
base.Initialize(); // Call DraggableObject initialization
// Auto-find components if not assigned
if (context == null)
context = GetComponent<CardContext>();
@@ -38,6 +43,44 @@ namespace UI.CardSystem.StateMachine
stateMachine = GetComponentInChildren<AppleMachine>();
}
#region DraggableObject Hooks - Trigger State Transitions
protected override void OnDragStartedHook()
{
base.OnDragStartedHook();
// Transition to dragging state when drag begins
Logging.Debug($"[Card] Drag started on {CardData?.Name}, transitioning to DraggingState");
ChangeState("DraggingState");
}
protected override void OnDragEndedHook()
{
base.OnDragEndedHook();
// Check if we dropped in a valid album slot
if (CurrentSlot is AlbumCardSlot albumSlot)
{
Logging.Debug($"[Card] Dropped in album slot, transitioning to PlacedInSlotState");
// Set the parent slot on PlacedInSlotState
var placedState = GetStateComponent<States.CardPlacedInSlotState>("PlacedInSlotState");
if (placedState != null)
{
placedState.SetParentSlot(albumSlot);
}
ChangeState("PlacedInSlotState");
}
else
{
Logging.Debug($"[Card] Dropped outside valid slot, returning to RevealedState");
ChangeState("RevealedState");
}
}
#endregion
/// <summary>
/// Setup the card with data and optional initial state
/// </summary>
@@ -58,18 +101,32 @@ namespace UI.CardSystem.StateMachine
/// <summary>
/// Setup for booster reveal flow (starts at IdleState, will flip on click)
/// Dragging is DISABLED for booster cards
/// </summary>
public void SetupForBoosterReveal(CardData data, bool isNew)
{
SetupCard(data, isNew, "IdleState");
SetDraggingEnabled(false); // Booster cards cannot be dragged
}
/// <summary>
/// Setup for album placement flow (starts at RevealedState, can be dragged)
/// Dragging is ENABLED for album placement cards
/// </summary>
public void SetupForAlbumPlacement(CardData data)
{
SetupCard(data, false, "RevealedState");
SetDraggingEnabled(true); // Album placement cards can be dragged
}
/// <summary>
/// Setup for album placement (starts at PlacedInSlotState)
/// Dragging is DISABLED once placed in slot
/// </summary>
public void SetupForAlbumSlot(CardData data, AlbumCardSlot slot)
{
SetupCard(data, false, "PlacedInSlotState");
SetDraggingEnabled(false); // Cards in slots cannot be dragged out
// Set the parent slot on the PlacedInSlotState
var placedState = GetStateComponent<States.CardPlacedInSlotState>("PlacedInSlotState");

View File

@@ -6,15 +6,15 @@ using AppleHills.Core.Settings;
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Dragging state - handles card being dragged for album placement.
/// Integrates with existing drag/drop system.
/// Dragging state - provides visual feedback when card is being dragged.
/// The actual drag logic is handled by Card.cs (inherits from DraggableObject).
/// This state only manages visual scaling during drag.
/// </summary>
public class CardDraggingState : AppleState
{
private CardContext _context;
private ICardSystemSettings _settings;
private Vector3 _originalScale;
private Vector3 _dragStartPosition;
private void Awake()
{
@@ -24,39 +24,14 @@ namespace UI.CardSystem.StateMachine.States
public override void OnEnterState()
{
// Store original transform
// Store original scale
_originalScale = _context.RootTransform.localScale;
_dragStartPosition = _context.RootTransform.position;
// Scale up slightly during drag for visual feedback
// DraggableObject handles actual position updates
_context.RootTransform.localScale = _originalScale * _settings.DragScale;
Logging.Debug($"[CardDraggingState] Entered drag state for card: {_context.CardData?.Name}");
}
/// <summary>
/// Update drag position (called by external drag handler)
/// </summary>
public void UpdateDragPosition(Vector3 worldPosition)
{
_context.RootTransform.position = worldPosition;
}
/// <summary>
/// Called when drag is released and card snaps to slot
/// </summary>
public void OnDroppedInSlot()
{
_context.StateMachine.ChangeState("PlacedInSlotState");
}
/// <summary>
/// Called when drag is released but not over valid slot
/// </summary>
public void OnDroppedOutsideSlot()
{
// Return to revealed state
_context.StateMachine.ChangeState("RevealedState");
Logging.Debug($"[CardDraggingState] Entered drag state for card: {_context.CardData?.Name}, scale: {_settings.DragScale}");
}
private void OnDisable()

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 860a5494378b465a9cc05b2b3d585bf9
timeCreated: 1762884900

View File

@@ -19,10 +19,6 @@ namespace UI.CardSystem.Testing
[SerializeField] private Card testCard;
[SerializeField] private CardData testCardData;
[Header("Album Slots for Drag Testing")]
[SerializeField] private AlbumCardSlot slot1;
[SerializeField] private AlbumCardSlot slot2;
[Header("UI References")]
[SerializeField] private TextMeshProUGUI eventLogText;
[SerializeField] private Toggle isNewToggle;
@@ -51,6 +47,10 @@ namespace UI.CardSystem.Testing
_cardContext.OnCardInteractionComplete += OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered += OnCardUpgradeTriggered;
}
// Subscribe to drag events to ensure card snaps back when released
testCard.OnDragStarted += OnCardDragStarted;
testCard.OnDragEnded += OnCardDragEnded;
}
// Setup UI listeners
@@ -118,12 +118,6 @@ namespace UI.CardSystem.Testing
LogEvent("Transitioned to DraggingState");
}
public void TransitionToPlacedInSlotState()
{
_cardContext?.StateMachine.ChangeState("PlacedInSlotState");
LogEvent("Transitioned to PlacedInSlotState");
}
public void TransitionToAlbumEnlargedState()
{
_cardContext?.StateMachine.ChangeState("AlbumEnlargedState");
@@ -171,15 +165,15 @@ namespace UI.CardSystem.Testing
LogEvent("Simulating UPGRADE flow (5/5) - click card to flip and auto-upgrade");
}
public void SimulateAlbumPlacementFlow()
public void TestDragAndSnap()
{
if (_cardContext == null) return;
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = 0;
if (testCard == null) return;
// Enable dragging for the test
testCard.SetDraggingEnabled(true);
TransitionToRevealedState();
LogEvent("Simulating ALBUM PLACEMENT - drag card to slot");
LogEvent("DRAG TEST enabled - drag the card and release to see it snap back");
}
#endregion
@@ -318,6 +312,25 @@ namespace UI.CardSystem.Testing
LogEvent($"Event: OnUpgradeTriggered - New Rarity={context.CardData?.Rarity}");
}
private void OnCardDragStarted(UI.DragAndDrop.Core.DraggableObject draggable)
{
LogEvent("Event: OnDragStarted - Card is being dragged");
}
private void OnCardDragEnded(UI.DragAndDrop.Core.DraggableObject draggable)
{
LogEvent("Event: OnDragEnded - Snapping card back to spawn point");
// Snap card back to original position (no slotting in test scene)
if (testCard != null)
{
testCard.transform.position = _originalCardPosition;
// Return to idle state after drag
TransitionToIdleState();
}
}
#endregion
#region Event Log
@@ -379,6 +392,12 @@ namespace UI.CardSystem.Testing
_cardContext.OnCardInteractionComplete -= OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered -= OnCardUpgradeTriggered;
}
if (testCard != null)
{
testCard.OnDragStarted -= OnCardDragStarted;
testCard.OnDragEnded -= OnCardDragEnded;
}
}
}
}