WOrking card save loads
This commit is contained in:
@@ -35,7 +35,8 @@ namespace Data.CardSystem
|
||||
private HashSet<string> _placedInAlbumCardIds = new HashSet<string>();
|
||||
|
||||
// Dictionary to quickly look up card definitions by ID
|
||||
private Dictionary<string, CardDefinition> _definitionLookup = new Dictionary<string, CardDefinition>();
|
||||
private Dictionary<string, CardDefinition> _definitionLookup;
|
||||
private bool _lookupInitialized = false;
|
||||
|
||||
// Event callbacks using System.Action
|
||||
public event Action<List<CardData>> 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
|
||||
/// </summary>
|
||||
private void BuildDefinitionLookup()
|
||||
{
|
||||
if (_definitionLookup == null)
|
||||
{
|
||||
_definitionLookup = new Dictionary<string, CardDefinition>();
|
||||
}
|
||||
|
||||
_definitionLookup.Clear();
|
||||
|
||||
foreach (var cardDef in availableCards)
|
||||
@@ -127,6 +133,8 @@ namespace Data.CardSystem
|
||||
cardData.SetDefinition(def);
|
||||
}
|
||||
}
|
||||
|
||||
_lookupInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -635,10 +643,16 @@ namespace Data.CardSystem
|
||||
/// <summary>
|
||||
/// Apply a previously saved snapshot to the runtime inventory
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
@@ -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<AlbumViewPage>();
|
||||
if (albumPage != null)
|
||||
|
||||
Reference in New Issue
Block a user