WOrking card save loads
This commit is contained in:
@@ -35,7 +35,8 @@ namespace Data.CardSystem
|
|||||||
private HashSet<string> _placedInAlbumCardIds = new HashSet<string>();
|
private HashSet<string> _placedInAlbumCardIds = new HashSet<string>();
|
||||||
|
|
||||||
// Dictionary to quickly look up card definitions by ID
|
// 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
|
// Event callbacks using System.Action
|
||||||
public event Action<List<CardData>> OnBoosterOpened;
|
public event Action<List<CardData>> OnBoosterOpened;
|
||||||
@@ -53,13 +54,13 @@ namespace Data.CardSystem
|
|||||||
|
|
||||||
// Set instance immediately so it's available before OnManagedAwake() is called
|
// Set instance immediately so it's available before OnManagedAwake() is called
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
|
// Load card definitions from Addressables, then register with save system
|
||||||
|
LoadCardDefinitionsFromAddressables();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnManagedAwake()
|
protected override void OnManagedAwake()
|
||||||
{
|
{
|
||||||
// Load card definitions from Addressables, then register with save system
|
|
||||||
LoadCardDefinitionsFromAddressables();
|
|
||||||
|
|
||||||
Logging.Debug("[CardSystemManager] Initialized");
|
Logging.Debug("[CardSystemManager] Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +109,11 @@ namespace Data.CardSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void BuildDefinitionLookup()
|
private void BuildDefinitionLookup()
|
||||||
{
|
{
|
||||||
|
if (_definitionLookup == null)
|
||||||
|
{
|
||||||
|
_definitionLookup = new Dictionary<string, CardDefinition>();
|
||||||
|
}
|
||||||
|
|
||||||
_definitionLookup.Clear();
|
_definitionLookup.Clear();
|
||||||
|
|
||||||
foreach (var cardDef in availableCards)
|
foreach (var cardDef in availableCards)
|
||||||
@@ -127,6 +133,8 @@ namespace Data.CardSystem
|
|||||||
cardData.SetDefinition(def);
|
cardData.SetDefinition(def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lookupInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -635,10 +643,16 @@ namespace Data.CardSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply a previously saved snapshot to the runtime inventory
|
/// Apply a previously saved snapshot to the runtime inventory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ApplyCardCollectionState(CardCollectionState state)
|
public async void ApplyCardCollectionState(CardCollectionState state)
|
||||||
{
|
{
|
||||||
if (state == null) return;
|
if (state == null) return;
|
||||||
|
|
||||||
|
// Wait for lookup to be initialized before loading
|
||||||
|
while (!_lookupInitialized)
|
||||||
|
{
|
||||||
|
await System.Threading.Tasks.Task.Yield();
|
||||||
|
}
|
||||||
|
|
||||||
playerInventory.ClearAllCards();
|
playerInventory.ClearAllCards();
|
||||||
_pendingRevealCards.Clear();
|
_pendingRevealCards.Clear();
|
||||||
_placedInAlbumCardIds.Clear();
|
_placedInAlbumCardIds.Clear();
|
||||||
|
|||||||
@@ -192,6 +192,20 @@ namespace UI.CardSystem
|
|||||||
_placedCard = albumCard;
|
_placedCard = albumCard;
|
||||||
_isOccupiedPermanently = true;
|
_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
|
// Register with AlbumViewPage for enlarge/shrink handling
|
||||||
AlbumViewPage albumPage = FindObjectOfType<AlbumViewPage>();
|
AlbumViewPage albumPage = FindObjectOfType<AlbumViewPage>();
|
||||||
if (albumPage != null)
|
if (albumPage != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user