This commit is contained in:
DamianCorazza
2025-10-21 12:42:40 +02:00
42 changed files with 1738 additions and 1351 deletions

View File

@@ -57,5 +57,19 @@ namespace AppleHills.Data.CardSystem
return Color.white;
}
}
public override bool Equals(object obj)
{
if (obj is CardDefinition other)
{
return string.Equals(Id, other.Id, StringComparison.Ordinal);
}
return false;
}
public override int GetHashCode()
{
return Id != null ? Id.GetHashCode() : 0;
}
}
}

View File

@@ -23,17 +23,13 @@ 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();
// Dictionary to quickly look up card definitions by ID
private Dictionary<string, CardDefinition> _definitionLookup = new Dictionary<string, CardDefinition>();
// Event callbacks using System.Action
public event Action<List<CardData>> OnBoosterOpened;
public event Action<CardData> OnCardCollected;
@@ -43,23 +39,19 @@ namespace Data.CardSystem
private void Awake()
{
_instance = this;
// Auto-load card definitions if enabled
if (autoLoadCardDefinitions)
{
LoadCardDefinitionsFromFolder();
}
// Register for post-boot initialization
BootCompletionService.RegisterInitAction(InitializePostBoot);
}
private void InitializePostBoot()
{
// Load card definitions from Addressables
LoadCardDefinitionsFromAddressables();
// Build lookup dictionary
BuildDefinitionLookup();
// Register for post-boot initialization
BootCompletionService.RegisterInitAction(InitializePostBoot);
}
private void InitializePostBoot()
{
// Initialize any dependencies that require other services to be ready
Logging.Debug("[CardSystemManager] Post-boot initialization complete");
}
@@ -67,46 +59,35 @@ namespace Data.CardSystem
{
_isQuitting = true;
}
/// <summary>
/// Loads all card definitions from the specified folder
/// Loads all card definitions from Addressables using the "BlokkemonCard" label
/// </summary>
private void LoadCardDefinitionsFromFolder()
private async void LoadCardDefinitionsFromAddressables()
{
// Initialize list if needed
if (availableCards == null)
availableCards = new List<CardDefinition>();
// Load by label instead of group name for better flexibility
var handle = UnityEngine.AddressableAssets.Addressables.LoadResourceLocationsAsync(new string[] { "BlokkemonCard" }, UnityEngine.AddressableAssets.Addressables.MergeMode.Union);
await handle.Task;
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
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))
var locations = handle.Result;
var loadedIds = new HashSet<string>();
foreach (var loc in locations)
{
loadedDefinitions.Add(cardDef);
var cardHandle = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<CardDefinition>(loc);
await cardHandle.Task;
if (cardHandle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
var cardDef = cardHandle.Result;
if (cardDef != null && !string.IsNullOrEmpty(cardDef.Id) && !loadedIds.Contains(cardDef.Id))
{
availableCards.Add(cardDef);
loadedIds.Add(cardDef.Id);
}
}
}
}
// 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>

View File

@@ -2,7 +2,6 @@
using Core;
using System;
using System.Collections;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Audio;

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using UnityEditor;
using Data.CardSystem;
using Core;
using AppleHills.UI.CardSystem;
using UI.CardSystem;
using UnityEngine.UI;
namespace AppleHills.Tests

View File

@@ -4,10 +4,11 @@ using Core;
using Data.CardSystem;
using Pixelplacement;
using TMPro;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// UI page for viewing the player's card collection in an album.

View File

@@ -1,9 +1,9 @@
using UnityEngine;
using TMPro;
using Pixelplacement;
using Pixelplacement;
using Pixelplacement.TweenSystem;
using TMPro;
using UnityEngine;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// Manages a notification dot that displays a count (e.g., booster packs)

View File

@@ -4,11 +4,11 @@ using AppleHills.Data.CardSystem;
using Core;
using Data.CardSystem;
using Pixelplacement;
using TMPro;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// UI page for opening booster packs and displaying the cards obtained.

View File

@@ -1,13 +1,12 @@
using System;
using System.Collections;
using AppleHills.Data.CardSystem;
using AppleHills.Data.CardSystem;
using Core;
using Data.CardSystem;
using Pixelplacement;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// Main UI controller for the card album system.

View File

@@ -1,13 +1,11 @@
using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
using Core;
using Data.CardSystem;
using Pixelplacement;
using TMPro;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// UI page for the main menu of the card system.

View File

@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
namespace UI.CardSystem
{
/// <summary>
/// Handles displaying and interacting with a single card in the UI.

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea8964f9870d45479f09a4b05c2b0d0c
timeCreated: 1761040697

View File

@@ -1,7 +1,7 @@
using System;
using UnityEngine;
namespace AppleHills.UI.CardSystem
namespace UI.Core
{
/// <summary>
/// Base class for UI pages that can transition in and out.

View File

@@ -5,7 +5,7 @@ using Core;
using UnityEngine;
using UnityEngine.InputSystem;
namespace AppleHills.UI.CardSystem
namespace UI.Core
{
/// <summary>
/// Manages UI page transitions and maintains a stack of active pages.

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using AppleHills.Core.Settings;
using Core;
@@ -72,10 +73,37 @@ namespace Utils
return frameAdjustedSpeed * screenNormalizationFactor;
}
public static bool AddressableKeyExists(object key)
public static bool AddressableKeyExists(object key, Addressables.MergeMode mergeMode = Addressables.MergeMode.Union)
{
IList<IResourceLocation> locations;
return Addressables.LoadResourceLocationsAsync(key).WaitForCompletion()?.Count > 0;
try
{
// Handle different key types
if (key is string[] keyArray)
{
// For string arrays, use the array as is with merge mode
return Addressables.LoadResourceLocationsAsync(keyArray, mergeMode).WaitForCompletion()?.Count > 0;
}
else if (key is IEnumerable<object> keyList)
{
// For collections of keys, convert to object[]
return Addressables.LoadResourceLocationsAsync(keyList.ToArray(), mergeMode).WaitForCompletion()?.Count > 0;
}
else if (key is string stringKey)
{
// For single string keys, wrap in array
return Addressables.LoadResourceLocationsAsync(new string[] { stringKey }, mergeMode).WaitForCompletion()?.Count > 0;
}
else
{
// For other single keys (AssetReference, etc.), wrap in object[]
return Addressables.LoadResourceLocationsAsync(new object[] { key }, mergeMode).WaitForCompletion()?.Count > 0;
}
}
catch (System.Exception ex)
{
Debug.LogWarning($"[AppleHillsUtils] Error checking addressable key existence: {ex.Message}");
return false;
}
}
}
}