Files
YachtDice/Assets/Scripts/Inventory/InventoryController.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

99 lines
2.6 KiB
C#

using UnityEngine;
using YachtDice.Economy;
using YachtDice.Modifiers;
using YachtDice.Scoring;
namespace YachtDice.Inventory
{
public sealed class InventoryController : MonoBehaviour
{
[SerializeField] private InventoryView inventoryView;
[SerializeField] private ScoringSystem scoringSystem;
[SerializeField] private CurrencyBank currencyBank;
private InventoryModel model;
public InventoryModel Model => model;
public void Initialize(InventoryModel inventoryModel)
{
model = inventoryModel;
inventoryView.OnActivateClicked += HandleActivate;
inventoryView.OnDeactivateClicked += HandleDeactivate;
inventoryView.OnSellClicked += HandleSell;
model.OnActiveModifiersChanged += HandleActiveModifiersChanged;
model.OnInventoryChanged += HandleInventoryChanged;
if (scoringSystem != null)
scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
RefreshView();
}
private void OnDestroy()
{
if (inventoryView != null)
{
inventoryView.OnActivateClicked -= HandleActivate;
inventoryView.OnDeactivateClicked -= HandleDeactivate;
inventoryView.OnSellClicked -= HandleSell;
}
if (model != null)
{
model.OnActiveModifiersChanged -= HandleActiveModifiersChanged;
model.OnInventoryChanged -= HandleInventoryChanged;
}
if (scoringSystem != null)
scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
}
private void HandleActivate(ModifierRuntime runtime)
{
model.TryActivate(runtime);
}
private void HandleDeactivate(ModifierRuntime runtime)
{
model.Deactivate(runtime);
}
private void HandleSell(ModifierRuntime runtime)
{
if (runtime.Data == null) return;
int sellPrice = runtime.Data.SellPrice;
model.RemoveModifier(runtime);
if (currencyBank != null)
currencyBank.Add(sellPrice);
}
private void HandleActiveModifiersChanged(System.Collections.Generic.List<ModifierData> activeModifiers)
{
if (scoringSystem != null)
scoringSystem.SetActiveModifiers(activeModifiers);
}
private void HandleInventoryChanged()
{
RefreshView();
}
private void HandleCategoryConfirmed(YachtCategory category, ScoreResult result)
{
model.ConsumeUseOnActive();
}
private void RefreshView()
{
if (inventoryView != null && model != null)
inventoryView.Refresh(model.OwnedModifiers, model.MaxActiveSlots);
}
}
}