From 8c940f4444c5755bb41193c6221f8b11a3758284 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Fri, 7 Nov 2025 15:06:22 +0100 Subject: [PATCH] WOrking card save loads --- .../Data/CardSystem/CardSystemManager.cs | 24 +++++++++++++++---- .../UI/CardSystem/DragDrop/AlbumCardSlot.cs | 14 +++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Data/CardSystem/CardSystemManager.cs b/Assets/Scripts/Data/CardSystem/CardSystemManager.cs index 708ab56e..621d4f30 100644 --- a/Assets/Scripts/Data/CardSystem/CardSystemManager.cs +++ b/Assets/Scripts/Data/CardSystem/CardSystemManager.cs @@ -35,7 +35,8 @@ namespace Data.CardSystem private HashSet _placedInAlbumCardIds = new HashSet(); // Dictionary to quickly look up card definitions by ID - private Dictionary _definitionLookup = new Dictionary(); + private Dictionary _definitionLookup; + private bool _lookupInitialized = false; // Event callbacks using System.Action public event Action> OnBoosterOpened; @@ -53,13 +54,13 @@ namespace Data.CardSystem // Set instance immediately so it's available before OnManagedAwake() is called _instance = this; + + // Load card definitions from Addressables, then register with save system + LoadCardDefinitionsFromAddressables(); } protected override void OnManagedAwake() { - // Load card definitions from Addressables, then register with save system - LoadCardDefinitionsFromAddressables(); - Logging.Debug("[CardSystemManager] Initialized"); } @@ -108,6 +109,11 @@ namespace Data.CardSystem /// private void BuildDefinitionLookup() { + if (_definitionLookup == null) + { + _definitionLookup = new Dictionary(); + } + _definitionLookup.Clear(); foreach (var cardDef in availableCards) @@ -127,6 +133,8 @@ namespace Data.CardSystem cardData.SetDefinition(def); } } + + _lookupInitialized = true; } /// @@ -635,10 +643,16 @@ namespace Data.CardSystem /// /// Apply a previously saved snapshot to the runtime inventory /// - public void ApplyCardCollectionState(CardCollectionState state) + public async void ApplyCardCollectionState(CardCollectionState state) { if (state == null) return; + // Wait for lookup to be initialized before loading + while (!_lookupInitialized) + { + await System.Threading.Tasks.Task.Yield(); + } + playerInventory.ClearAllCards(); _pendingRevealCards.Clear(); _placedInAlbumCardIds.Clear(); diff --git a/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardSlot.cs b/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardSlot.cs index 51fb4d98..6c436591 100644 --- a/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardSlot.cs +++ b/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardSlot.cs @@ -192,6 +192,20 @@ namespace UI.CardSystem _placedCard = albumCard; _isOccupiedPermanently = true; + // Resize the card to match the slot size (same as placed cards) + RectTransform cardRect = albumCard.transform as RectTransform; + RectTransform slotRect = transform as RectTransform; + if (cardRect != null && slotRect != null) + { + // Set height to match slot height (AspectRatioFitter will handle width) + float targetHeight = slotRect.rect.height; + cardRect.sizeDelta = new Vector2(cardRect.sizeDelta.x, targetHeight); + + // Ensure position and rotation are centered + cardRect.localPosition = Vector3.zero; + cardRect.localRotation = Quaternion.identity; + } + // Register with AlbumViewPage for enlarge/shrink handling AlbumViewPage albumPage = FindObjectOfType(); if (albumPage != null)