Rework shop to support multiple item types and add unified PlayerModel
Generalize the shop from selling only ModifierDefinition to any IShopItem (modifiers + dice). Add purchase condition checks, hover tooltips, and fixed prices. Introduce PlayerModel as a facade over CurrencyBank, InventoryModel, and DiceCollection for centralized state and save/load. New files: - IShopItem interface for purchasable items - ShopCatalog SO (unified catalog for all item types) - ShopTooltipView (description on hover) - PlayerModel (aggregates player state) - DiceCollection (owned dice tracking) - DiceCatalog SO (dice definition registry) - DiceCollectionTests Modified: - ModifierDefinition/DieDefinitionSO implement IShopItem - ShopModel/ShopView/ShopItemView/ShopController use IShopItem - SaveData v3 with OwnedDiceIds - GameController uses PlayerModel for save/load - GameLifetimeScope registers new services Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using YachtDice.Modifiers.Definition;
|
||||
|
||||
namespace YachtDice.Shop
|
||||
{
|
||||
@@ -13,10 +12,11 @@ namespace YachtDice.Shop
|
||||
[SerializeField] private ShopItemView itemPrefab;
|
||||
[SerializeField] private TMP_Text currencyText;
|
||||
[SerializeField] private Button closeButton;
|
||||
[SerializeField] private ShopTooltipView tooltipView;
|
||||
|
||||
private readonly List<ShopItemView> spawnedItems = new();
|
||||
|
||||
public event Action<ModifierDefinition> OnBuyClicked;
|
||||
public event Action<IShopItem> OnBuyClicked;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -34,7 +34,7 @@ namespace YachtDice.Shop
|
||||
public void Hide() => gameObject.SetActive(false);
|
||||
public bool IsVisible => gameObject.activeSelf;
|
||||
|
||||
public void Populate(IReadOnlyList<ModifierDefinition> catalog, ShopModel model)
|
||||
public void Populate(IReadOnlyList<IShopItem> catalog, ShopModel model)
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
@@ -47,11 +47,13 @@ namespace YachtDice.Shop
|
||||
var state = model.GetItemState(def);
|
||||
item.Setup(def, state);
|
||||
item.OnBuyClicked += HandleBuy;
|
||||
item.OnHoverEnter += HandleHoverEnter;
|
||||
item.OnHoverExit += HandleHoverExit;
|
||||
spawnedItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshStates(IReadOnlyList<ModifierDefinition> catalog, ShopModel model)
|
||||
public void RefreshStates(IReadOnlyList<IShopItem> catalog, ShopModel model)
|
||||
{
|
||||
for (int i = 0; i < spawnedItems.Count && i < catalog.Count; i++)
|
||||
{
|
||||
@@ -71,11 +73,25 @@ namespace YachtDice.Shop
|
||||
for (int i = 0; i < spawnedItems.Count; i++)
|
||||
{
|
||||
spawnedItems[i].OnBuyClicked -= HandleBuy;
|
||||
spawnedItems[i].OnHoverEnter -= HandleHoverEnter;
|
||||
spawnedItems[i].OnHoverExit -= HandleHoverExit;
|
||||
Destroy(spawnedItems[i].gameObject);
|
||||
}
|
||||
spawnedItems.Clear();
|
||||
}
|
||||
|
||||
private void HandleBuy(ModifierDefinition def) => OnBuyClicked?.Invoke(def);
|
||||
private void HandleBuy(IShopItem item) => OnBuyClicked?.Invoke(item);
|
||||
|
||||
private void HandleHoverEnter(IShopItem item, RectTransform anchor)
|
||||
{
|
||||
if (tooltipView != null)
|
||||
tooltipView.Show(item, anchor);
|
||||
}
|
||||
|
||||
private void HandleHoverExit()
|
||||
{
|
||||
if (tooltipView != null)
|
||||
tooltipView.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user