68c4abace3
Replace the entire static, enum-based modifier pipeline with a composition-based, data-driven architecture using ScriptableObject polymorphism. New modifiers can now be created by assembling SO building blocks (Conditions + Effects + Behaviors) — no core code edits needed. New architecture: - Core/: TriggerType, ModifierPhase, ModifierContext, ICondition, IEffect - Definition/: ModifierDefinitionSO, ModifierBehaviorSO, ConditionSO, EffectSO, ModifierCatalogSO - Conditions/: DieValueCondition, CategoryCondition, MinScoreCondition, DiceCountCondition - Effects/: AddFlat, AddPerDie, Multiply, MultiplyPerDie, PostMultiply, AddCurrency, ConsumeCharge - Runtime/: ModifierInstance, ModifierRegistry (non-static service) - Pipeline/: async ModifierPipeline with phase ordering, tracing, anti-recursion - Editor/: ModifierDefinitionValidator with menu items - Events/: GameEventBus (non-static typed dispatcher) - DI/: GameLifetimeScope (VContainer composition root) Deleted old system: ModifierData, ModifierEffect, ModifierEnums, ModifierPipeline (static), ModifierRuntime, ModifierTarget, ShopCatalog, ModifierAssetCreator. Updated: ScoringSystem (VContainer + async), InventoryModel (delegates to ModifierRegistry), ShopModel (uses ModifierDefinitionSO), GameController (VContainer injection), SaveData (uses Runtime.ModifierSaveEntry), all views/controllers, and all test files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using YachtDice.Modifiers.Definition;
|
|
|
|
namespace YachtDice.Shop
|
|
{
|
|
public class ShopView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform itemContainer;
|
|
[SerializeField] private ShopItemView itemPrefab;
|
|
[SerializeField] private TMP_Text currencyText;
|
|
[SerializeField] private Button closeButton;
|
|
|
|
private readonly List<ShopItemView> spawnedItems = new();
|
|
|
|
public event Action<ModifierDefinitionSO> OnBuyClicked;
|
|
|
|
private void Awake()
|
|
{
|
|
if (closeButton != null)
|
|
closeButton.onClick.AddListener(Hide);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (closeButton != null)
|
|
closeButton.onClick.RemoveListener(Hide);
|
|
}
|
|
|
|
public void Show() => gameObject.SetActive(true);
|
|
public void Hide() => gameObject.SetActive(false);
|
|
public bool IsVisible => gameObject.activeSelf;
|
|
|
|
public void Populate(IReadOnlyList<ModifierDefinitionSO> catalog, ShopModel model)
|
|
{
|
|
ClearItems();
|
|
|
|
for (int i = 0; i < catalog.Count; i++)
|
|
{
|
|
var def = catalog[i];
|
|
if (def == null) continue;
|
|
|
|
var item = Instantiate(itemPrefab, itemContainer);
|
|
var state = model.GetItemState(def);
|
|
item.Setup(def, state);
|
|
item.OnBuyClicked += HandleBuy;
|
|
spawnedItems.Add(item);
|
|
}
|
|
}
|
|
|
|
public void RefreshStates(IReadOnlyList<ModifierDefinitionSO> catalog, ShopModel model)
|
|
{
|
|
for (int i = 0; i < spawnedItems.Count && i < catalog.Count; i++)
|
|
{
|
|
var state = model.GetItemState(catalog[i]);
|
|
spawnedItems[i].SetState(state);
|
|
}
|
|
}
|
|
|
|
public void UpdateCurrencyDisplay(int currency)
|
|
{
|
|
if (currencyText != null)
|
|
currencyText.text = currency.ToString();
|
|
}
|
|
|
|
private void ClearItems()
|
|
{
|
|
for (int i = 0; i < spawnedItems.Count; i++)
|
|
{
|
|
spawnedItems[i].OnBuyClicked -= HandleBuy;
|
|
Destroy(spawnedItems[i].gameObject);
|
|
}
|
|
spawnedItems.Clear();
|
|
}
|
|
|
|
private void HandleBuy(ModifierDefinitionSO def) => OnBuyClicked?.Invoke(def);
|
|
}
|
|
}
|