Extend VContainer DI: eliminate manual composition and duplicate references
- Register InventoryModel, ShopModel as container-managed singletons - Register GameController, ShopController, InventoryController via RegisterComponent - Replace [SerializeField] with [Inject] for service dependencies in controllers - Move maxActiveModifierSlots config to GameLifetimeScope (composition root) - Remove manual model creation and Initialize() calls from GameController - Add ToggleVisibility() to ShopController/InventoryController, removing GetComponentInChildren - Move event subscriptions from Awake to Start for safe VContainer injection order - Transfer game startup orchestration to GameController.Start() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using YachtDice.Categories;
|
||||
using YachtDice.Economy;
|
||||
using YachtDice.Modifiers.Runtime;
|
||||
@@ -9,25 +10,29 @@ namespace YachtDice.Inventory
|
||||
public class InventoryController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private InventoryView inventoryView;
|
||||
[SerializeField] private ScoringSystem scoringSystem;
|
||||
[SerializeField] private CurrencyBank currencyBank;
|
||||
|
||||
private InventoryModel model;
|
||||
private ScoringSystem scoringSystem;
|
||||
private CurrencyBank currencyBank;
|
||||
|
||||
public InventoryModel Model => model;
|
||||
|
||||
public void Initialize(InventoryModel inventoryModel)
|
||||
[Inject]
|
||||
public void Construct(InventoryModel model, ScoringSystem scoringSystem, CurrencyBank currencyBank)
|
||||
{
|
||||
model = inventoryModel;
|
||||
this.model = model;
|
||||
this.scoringSystem = scoringSystem;
|
||||
this.currencyBank = currencyBank;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
inventoryView.OnActivateClicked += HandleActivate;
|
||||
inventoryView.OnDeactivateClicked += HandleDeactivate;
|
||||
inventoryView.OnSellClicked += HandleSell;
|
||||
|
||||
model.OnInventoryChanged += HandleInventoryChanged;
|
||||
|
||||
if (scoringSystem != null)
|
||||
scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
|
||||
scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
|
||||
|
||||
RefreshView();
|
||||
}
|
||||
@@ -48,6 +53,16 @@ namespace YachtDice.Inventory
|
||||
scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
|
||||
}
|
||||
|
||||
public void ToggleVisibility()
|
||||
{
|
||||
if (inventoryView == null) return;
|
||||
|
||||
if (inventoryView.IsVisible)
|
||||
inventoryView.Hide();
|
||||
else
|
||||
inventoryView.Show();
|
||||
}
|
||||
|
||||
private void HandleActivate(ModifierInstance instance)
|
||||
{
|
||||
model.TryActivate(instance);
|
||||
|
||||
Reference in New Issue
Block a user