fcceb0ce45
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>
75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using YachtDice.Dice;
|
|
|
|
namespace YachtDice.Player
|
|
{
|
|
public class DiceCollection
|
|
{
|
|
private readonly List<DieDefinitionSO> ownedDice = new();
|
|
|
|
public event Action OnChanged;
|
|
|
|
public IReadOnlyList<DieDefinitionSO> OwnedDice => ownedDice;
|
|
|
|
public void Add(DieDefinitionSO definition)
|
|
{
|
|
if (definition == null) return;
|
|
if (OwnsById(definition.Id)) return;
|
|
|
|
ownedDice.Add(definition);
|
|
OnChanged?.Invoke();
|
|
}
|
|
|
|
public void Remove(DieDefinitionSO definition)
|
|
{
|
|
if (ownedDice.Remove(definition))
|
|
OnChanged?.Invoke();
|
|
}
|
|
|
|
public bool OwnsById(string id)
|
|
{
|
|
for (int i = 0; i < ownedDice.Count; i++)
|
|
{
|
|
if (ownedDice[i] != null && ownedDice[i].Id == id)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public List<string> GetSaveData()
|
|
{
|
|
var ids = new List<string>();
|
|
for (int i = 0; i < ownedDice.Count; i++)
|
|
ids.Add(ownedDice[i].Id);
|
|
return ids;
|
|
}
|
|
|
|
public void LoadSaveData(List<string> diceIds, DiceCatalog catalog)
|
|
{
|
|
ownedDice.Clear();
|
|
|
|
if (diceIds == null)
|
|
{
|
|
OnChanged?.Invoke();
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < diceIds.Count; i++)
|
|
{
|
|
var def = catalog.FindById(diceIds[i]);
|
|
if (def != null)
|
|
ownedDice.Add(def);
|
|
}
|
|
|
|
OnChanged?.Invoke();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
ownedDice.Clear();
|
|
OnChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|