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,32 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YachtDice.Dice
|
||||
{
|
||||
[CreateAssetMenu(fileName = "DiceCatalog", menuName = "YachtDice/Dice/Catalog")]
|
||||
public class DiceCatalog : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<DieDefinitionSO> dice = new();
|
||||
|
||||
public IReadOnlyList<DieDefinitionSO> All => dice;
|
||||
|
||||
public DieDefinitionSO FindById(string id)
|
||||
{
|
||||
for (int i = 0; i < dice.Count; i++)
|
||||
{
|
||||
if (dice[i] != null && dice[i].Id == id)
|
||||
return dice[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static DiceCatalog CreateForTest(List<DieDefinitionSO> defs)
|
||||
{
|
||||
var catalog = CreateInstance<DiceCatalog>();
|
||||
catalog.dice = defs ?? new List<DieDefinitionSO>();
|
||||
return catalog;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using YachtDice.Shop;
|
||||
|
||||
namespace YachtDice.Dice
|
||||
{
|
||||
@@ -6,16 +7,23 @@ namespace YachtDice.Dice
|
||||
/// Абстрактное определение типа дайса.
|
||||
/// Наследники описывают конкретные виды (стандартный d6, специальные и т.д.).
|
||||
/// </summary>
|
||||
public abstract class DieDefinitionSO : ScriptableObject
|
||||
public abstract class DieDefinitionSO : ScriptableObject, IShopItem
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField, TextArea] private string description;
|
||||
[SerializeField] private Sprite icon;
|
||||
|
||||
[Header("Economy")]
|
||||
[SerializeField] private int shopPrice;
|
||||
|
||||
public string Id => id;
|
||||
public string DisplayName => displayName;
|
||||
public string Description => description;
|
||||
public Sprite Icon => icon;
|
||||
public int ShopPrice => shopPrice;
|
||||
public bool IsRepurchasable => false;
|
||||
|
||||
/// <summary>Количество граней.</summary>
|
||||
public abstract int FaceCount { get; }
|
||||
@@ -24,11 +32,14 @@ namespace YachtDice.Dice
|
||||
public abstract int[] GetFaceValues();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static T CreateForTest<T>(string id, string displayName = null) where T : DieDefinitionSO
|
||||
public static T CreateForTest<T>(string id, string displayName = null,
|
||||
int shopPrice = 0, string description = null) where T : DieDefinitionSO
|
||||
{
|
||||
var so = CreateInstance<T>();
|
||||
so.id = id;
|
||||
so.displayName = displayName ?? id;
|
||||
so.description = description ?? id;
|
||||
so.shopPrice = shopPrice;
|
||||
return so;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user