Second draft of the consolidated card system
This commit is contained in:
249
Assets/Scripts/Tests/CardSystemTester.cs
Normal file
249
Assets/Scripts/Tests/CardSystemTester.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
using UnityEngine;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using Data.CardSystem;
|
||||
using Core;
|
||||
using AppleHills.UI.CardSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing component for the Card System. Provides editor buttons to test core functionalities.
|
||||
/// Place this in a test scene to easily test card system features without needing full game implementation.
|
||||
/// </summary>
|
||||
public class CardSystemTester : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private CardSystemManager cardSystemManager;
|
||||
[SerializeField] private CardAlbumUI cardAlbumUI;
|
||||
|
||||
[Header("Test Settings")]
|
||||
[SerializeField] [Range(1, 10)] private int boosterPacksToAdd = 3;
|
||||
[SerializeField] [Range(1, 100)] private int cardsToGenerate = 10;
|
||||
[SerializeField] private bool autoOpenPacksWhenAdded = false;
|
||||
|
||||
[Header("Debug Info")]
|
||||
[SerializeField] [ReadOnly] private int currentBoosterCount;
|
||||
[SerializeField] [ReadOnly] private int totalCardsInCollection;
|
||||
[SerializeField] [ReadOnly] private string lastActionMessage;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Auto-find references if needed
|
||||
if (cardSystemManager == null)
|
||||
cardSystemManager = FindAnyObjectByType<CardSystemManager>();
|
||||
|
||||
if (cardAlbumUI == null)
|
||||
cardAlbumUI = FindAnyObjectByType<CardAlbumUI>();
|
||||
|
||||
// Log missing references
|
||||
if (cardSystemManager == null)
|
||||
Debug.LogError("CardSystemTester: No CardSystemManager found in the scene!");
|
||||
|
||||
if (cardAlbumUI == null)
|
||||
Debug.LogError("CardSystemTester: No CardAlbumUI found in the scene!");
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
|
||||
// Refresh the debug information displayed in the inspector
|
||||
private void RefreshDebugInfo()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
currentBoosterCount = cardSystemManager.GetBoosterPackCount();
|
||||
totalCardsInCollection = cardSystemManager.GetCardInventory().GetAllCards().Count;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Custom editor buttons for testing
|
||||
public void AddBoosterPacks()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
cardSystemManager.AddBoosterPack(boosterPacksToAdd);
|
||||
lastActionMessage = $"Added {boosterPacksToAdd} booster pack(s)";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
|
||||
if (autoOpenPacksWhenAdded && cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick();
|
||||
cardAlbumUI.OpenBoosterPack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SimulateBackpackClick()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
// This will show the main card menu
|
||||
// Manually trigger a click on the backpack icon
|
||||
// Note: This relies on the backpack icon being correctly set up in the CardAlbumUI
|
||||
if (cardAlbumUI.BackpackIcon != null)
|
||||
{
|
||||
Button backpackButton = cardAlbumUI.BackpackIcon.GetComponent<Button>();
|
||||
if (backpackButton != null)
|
||||
{
|
||||
backpackButton.onClick.Invoke();
|
||||
lastActionMessage = "Opened card menu via backpack click";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "Failed to find Button component on backpack icon";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "BackpackIcon reference is null";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenBoosterPack()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick(); // First make sure we've opened the menu
|
||||
cardAlbumUI.OpenBoosterPack();
|
||||
lastActionMessage = "Opening booster pack";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenAlbumView()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick(); // First make sure we've opened the menu
|
||||
cardAlbumUI.OpenAlbumView();
|
||||
lastActionMessage = "Opening album view";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateRandomCards()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
int cardsAdded = 0;
|
||||
List<CardDefinition> allDefinitions = cardSystemManager.GetAllCardDefinitions();
|
||||
|
||||
if (allDefinitions.Count == 0)
|
||||
{
|
||||
lastActionMessage = "Error: No card definitions available";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cardsToGenerate; i++)
|
||||
{
|
||||
// Get a random card definition
|
||||
CardDefinition randomDef = allDefinitions[Random.Range(0, allDefinitions.Count)];
|
||||
|
||||
// Create a card data instance and add it to inventory
|
||||
CardData newCard = randomDef.CreateCardData();
|
||||
cardSystemManager.GetCardInventory().AddCard(newCard);
|
||||
cardsAdded++;
|
||||
}
|
||||
|
||||
lastActionMessage = $"Generated {cardsAdded} random cards";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAllCards()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
int count = cardSystemManager.GetCardInventory().GetAllCards().Count;
|
||||
cardSystemManager.GetCardInventory().ClearAllCards();
|
||||
lastActionMessage = $"Cleared {count} cards from inventory";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(CardSystemTester))]
|
||||
public class CardSystemTesterEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
CardSystemTester tester = (CardSystemTester)target;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Test Actions", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Add Booster Packs"))
|
||||
{
|
||||
tester.AddBoosterPacks();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Card Menu"))
|
||||
{
|
||||
tester.SimulateBackpackClick();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Booster Pack"))
|
||||
{
|
||||
tester.OpenBoosterPack();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Album View"))
|
||||
{
|
||||
tester.OpenAlbumView();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("Generate Random Cards"))
|
||||
{
|
||||
tester.GenerateRandomCards();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear All Cards"))
|
||||
{
|
||||
tester.ClearAllCards();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Simple attribute to make fields read-only in the inspector
|
||||
public class ReadOnlyAttribute : PropertyAttribute { }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
3
Assets/Scripts/Tests/CardSystemTester.cs.meta
Normal file
3
Assets/Scripts/Tests/CardSystemTester.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c59c766505c4342983594dbe19f3db0
|
||||
timeCreated: 1760951960
|
||||
Reference in New Issue
Block a user