Working card system
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Data.CardSystem
|
||||
{
|
||||
@@ -20,6 +24,10 @@ namespace Data.CardSystem
|
||||
[Header("Card Collection")]
|
||||
[SerializeField] private List<CardDefinition> availableCards = new List<CardDefinition>();
|
||||
|
||||
[Header("Auto-Loading Configuration")]
|
||||
[SerializeField] private bool autoLoadCardDefinitions = true;
|
||||
[SerializeField] private string cardDataPath = "Data/Cards";
|
||||
|
||||
// Runtime data - will be serialized for save/load
|
||||
[SerializeField] private CardInventory playerInventory = new CardInventory();
|
||||
|
||||
@@ -36,6 +44,12 @@ namespace Data.CardSystem
|
||||
{
|
||||
_instance = this;
|
||||
|
||||
// Auto-load card definitions if enabled
|
||||
if (autoLoadCardDefinitions)
|
||||
{
|
||||
LoadCardDefinitionsFromFolder();
|
||||
}
|
||||
|
||||
// Build lookup dictionary
|
||||
BuildDefinitionLookup();
|
||||
|
||||
@@ -54,6 +68,47 @@ namespace Data.CardSystem
|
||||
_isQuitting = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads all card definitions from the specified folder
|
||||
/// </summary>
|
||||
private void LoadCardDefinitionsFromFolder()
|
||||
{
|
||||
// Initialize list if needed
|
||||
if (availableCards == null)
|
||||
{
|
||||
availableCards = new List<CardDefinition>();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// In editor we can load assets directly from the project folder
|
||||
string folderPath = "Assets/" + cardDataPath;
|
||||
string[] guids = AssetDatabase.FindAssets("t:CardDefinition", new[] { folderPath });
|
||||
|
||||
List<CardDefinition> loadedDefinitions = new List<CardDefinition>();
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
CardDefinition cardDef = AssetDatabase.LoadAssetAtPath<CardDefinition>(assetPath);
|
||||
if (cardDef != null && !string.IsNullOrEmpty(cardDef.Id))
|
||||
{
|
||||
loadedDefinitions.Add(cardDef);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the existing list with loaded definitions
|
||||
availableCards = loadedDefinitions;
|
||||
#else
|
||||
// In build, load from Resources folder
|
||||
CardDefinition[] resourceCards = Resources.LoadAll<CardDefinition>(cardDataPath);
|
||||
if (resourceCards != null && resourceCards.Length > 0)
|
||||
{
|
||||
availableCards = resourceCards.Where(card => card != null && !string.IsNullOrEmpty(card.Id)).ToList();
|
||||
}
|
||||
#endif
|
||||
|
||||
Logging.Debug($"[CardSystemManager] Loaded {availableCards.Count} card definitions from {cardDataPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a lookup dictionary for quick access to card definitions by ID
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user