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:
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YachtDice.Shop
|
||||
{
|
||||
[CreateAssetMenu(fileName = "ShopCatalog", menuName = "YachtDice/Shop/Catalog")]
|
||||
public class ShopCatalog : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<ScriptableObject> items = new();
|
||||
|
||||
private List<IShopItem> cachedItems;
|
||||
|
||||
public IReadOnlyList<IShopItem> All
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cachedItems == null) RebuildCache();
|
||||
return cachedItems;
|
||||
}
|
||||
}
|
||||
|
||||
public IShopItem FindById(string id)
|
||||
{
|
||||
var all = All;
|
||||
for (int i = 0; i < all.Count; i++)
|
||||
{
|
||||
if (all[i] != null && all[i].Id == id)
|
||||
return all[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void RebuildCache()
|
||||
{
|
||||
cachedItems = new List<IShopItem>();
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (items[i] is IShopItem shopItem)
|
||||
cachedItems.Add(shopItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate() => cachedItems = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user