0f9b162061
- Add abstract dice system (IDie interface, DieDefinitionSO, StandardDieSO, DieInstance) to support future custom dice types while keeping backward compat via int[] DiceValues - Replace YachtCategory enum and CategoryScorer switch with CategoryDefinitionSO hierarchy: SumOfValueCategorySO, NOfAKindCategorySO, FullHouseCategorySO, StraightCategorySO, SumAllCategorySO - Add CategoryCatalogSO for ordered category collections and DiceCheckUtility for shared logic - Refactor ScoringSystem, Views, GameManager, GameController to use SO references - Update CategoryCondition modifier to use SO reference instead of enum - Update all editor tests to use SO-based categories and DieInstance Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using UnityEngine;
|
|
using YachtDice.Categories;
|
|
using YachtDice.Economy;
|
|
using YachtDice.Modifiers.Runtime;
|
|
using YachtDice.Scoring;
|
|
|
|
namespace YachtDice.Inventory
|
|
{
|
|
public 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.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.OnInventoryChanged -= HandleInventoryChanged;
|
|
|
|
if (scoringSystem != null)
|
|
scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
|
|
}
|
|
|
|
private void HandleActivate(ModifierInstance instance)
|
|
{
|
|
model.TryActivate(instance);
|
|
}
|
|
|
|
private void HandleDeactivate(ModifierInstance instance)
|
|
{
|
|
model.Deactivate(instance);
|
|
}
|
|
|
|
private void HandleSell(ModifierInstance instance)
|
|
{
|
|
if (instance.Definition == null) return;
|
|
|
|
int sellPrice = instance.Definition.SellPrice;
|
|
model.RemoveModifier(instance);
|
|
|
|
if (currencyBank != null)
|
|
currencyBank.Add(sellPrice);
|
|
}
|
|
|
|
private void HandleInventoryChanged()
|
|
{
|
|
RefreshView();
|
|
}
|
|
|
|
private void HandleCategoryConfirmed(CategoryDefinitionSO category, ScoreResult result)
|
|
{
|
|
model.ConsumeUseOnActive();
|
|
}
|
|
|
|
private void RefreshView()
|
|
{
|
|
if (inventoryView != null && model != null)
|
|
inventoryView.Refresh(model.OwnedModifiers, model.MaxActiveSlots);
|
|
}
|
|
}
|
|
}
|