Files
YachtDice/Assets/Scripts/Inventory/InventoryView.cs
T
horooko 68c4abace3 [Refactor] Replace enum-driven modifier system with data-driven SO composition
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>
2026-03-01 06:20:23 +07:00

79 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using YachtDice.Modifiers.Runtime;
namespace YachtDice.Inventory
{
public class InventoryView : MonoBehaviour
{
[SerializeField] private Transform slotContainer;
[SerializeField] private InventorySlotView slotPrefab;
[SerializeField] private TMP_Text slotCountText;
[SerializeField] private Button closeButton;
private readonly List<InventorySlotView> spawnedSlots = new();
public event Action<ModifierInstance> OnActivateClicked;
public event Action<ModifierInstance> OnDeactivateClicked;
public event Action<ModifierInstance> OnSellClicked;
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 Refresh(IReadOnlyList<ModifierInstance> owned, int maxSlots)
{
ClearSlots();
int activeCount = 0;
for (int i = 0; i < owned.Count; i++)
{
var inst = owned[i];
if (inst.IsActive) activeCount++;
var slot = Instantiate(slotPrefab, slotContainer);
slot.Setup(inst, activeCount <= maxSlots);
slot.OnActivateClicked += HandleActivate;
slot.OnDeactivateClicked += HandleDeactivate;
slot.OnSellClicked += HandleSell;
spawnedSlots.Add(slot);
}
if (slotCountText != null)
slotCountText.text = $"{activeCount}/{maxSlots}";
}
private void ClearSlots()
{
for (int i = 0; i < spawnedSlots.Count; i++)
{
spawnedSlots[i].OnActivateClicked -= HandleActivate;
spawnedSlots[i].OnDeactivateClicked -= HandleDeactivate;
spawnedSlots[i].OnSellClicked -= HandleSell;
Destroy(spawnedSlots[i].gameObject);
}
spawnedSlots.Clear();
}
private void HandleActivate(ModifierInstance inst) => OnActivateClicked?.Invoke(inst);
private void HandleDeactivate(ModifierInstance inst) => OnDeactivateClicked?.Invoke(inst);
private void HandleSell(ModifierInstance inst) => OnSellClicked?.Invoke(inst);
}
}