[Refactor] Final fix GameManager & GameController

This commit is contained in:
2026-03-04 07:20:42 +07:00
parent 3031d2e4c2
commit 3793686dcf
10 changed files with 47 additions and 81 deletions
-2
View File
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 06752cfc00e8dc24f8004581af1a1933
@@ -12,14 +12,14 @@ using YachtDice.UI.Presentation;
namespace YachtDice.UI
{
public class GameController : MonoBehaviour
public class GamePresentationRoot : MonoBehaviour
{
[Header("MVP Views")]
[SerializeField] private ScoreCardView scoreCardView;
[SerializeField] private DicePanelView dicePanelView;
[SerializeField] private GameInfoView gameInfoView;
private GameManager _gameManager;
private GameLoopController _gameLoopController;
private ScoringSystem _scoringSystem;
private DiceManager _diceManager;
private CurrencyBank _currencyBank;
@@ -37,7 +37,7 @@ namespace YachtDice.UI
[Inject]
public void Construct(
GameManager gameManager,
GameLoopController gameLoopController,
ScoringSystem scoringSystem,
DiceManager diceManager,
CurrencyBank currencyBank,
@@ -48,7 +48,7 @@ namespace YachtDice.UI
IGameSaveService saveService,
IScoreSummaryService scoreSummaryService)
{
this._gameManager = gameManager;
this._gameLoopController = gameLoopController;
this._scoringSystem = scoringSystem;
this._diceManager = diceManager;
this._currencyBank = currencyBank;
@@ -62,13 +62,12 @@ namespace YachtDice.UI
private void Start()
{
_dicePanelPresenter = new DicePanelPresenter(dicePanelView, _gameManager, _diceManager);
_dicePanelPresenter = new DicePanelPresenter(dicePanelView, _gameLoopController, _diceManager);
_scoreCardPresenter = new ScoreCardPresenter(scoreCardView, _categoryCatalog, _scoringSystem, _diceManager);
_gameInfoPresenter = new GameInfoPresenter(gameInfoView);
_gameFlowPresenter = new GameFlowPresenter(
_gameManager,
_scoringSystem,
_gameLoopController,
_diceManager,
_currencyBank,
_shopController,
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 06752cfc00e8dc24f8004581af1a1933
@@ -6,16 +6,16 @@ namespace YachtDice.UI.Presentation
public sealed class DicePanelPresenter : IDisposable
{
private readonly DicePanelView _view;
private readonly GameManager _gameManager;
private readonly GameLoopController _gameLoopController;
private readonly DiceManager _diceManager;
public event Action RollClicked;
public event Action<int> DiceToggled;
public DicePanelPresenter(DicePanelView view, GameManager gameManager, DiceManager diceManager)
public DicePanelPresenter(DicePanelView view, GameLoopController gameLoopController, DiceManager diceManager)
{
_view = view;
_gameManager = gameManager;
_gameLoopController = gameLoopController;
_diceManager = diceManager;
}
@@ -36,32 +36,32 @@ namespace YachtDice.UI.Presentation
public void ResetForNewTurn()
{
_view.ResetForNewTurn();
_view.SetRollButtonState(true, 0, _gameManager.MaxRollsPerTurn);
_view.SetRollButtonState(true, 0, _gameLoopController.MaxRollsPerTurn);
}
public void PrepareForRoll()
{
_view.SetRollButtonState(false, _gameManager.CurrentRoll, _gameManager.MaxRollsPerTurn);
_view.SetRollButtonState(false, _gameLoopController.CurrentRoll, _gameLoopController.MaxRollsPerTurn);
_view.SetDiceInteractable(false);
}
public void HandleRollComplete(int rollNumber)
{
var canRollAgain = _gameManager.CanRoll;
_view.SetRollButtonState(canRollAgain, rollNumber, _gameManager.MaxRollsPerTurn);
var canRollAgain = _gameLoopController.CanRoll;
_view.SetRollButtonState(canRollAgain, rollNumber, _gameLoopController.MaxRollsPerTurn);
_view.SetDiceInteractable(true);
_view.SetAllDiceValues(_diceManager.GetCurrentValues());
}
public void HandleGameOver()
{
_view.SetRollButtonState(false, _gameManager.MaxRollsPerTurn, _gameManager.MaxRollsPerTurn);
_view.SetRollButtonState(false, _gameLoopController.MaxRollsPerTurn, _gameLoopController.MaxRollsPerTurn);
_view.SetDiceInteractable(false);
}
public void ResetForNewGame()
{
_view.ResetForNewGame(_gameManager.MaxRollsPerTurn);
_view.ResetForNewGame(_gameLoopController.MaxRollsPerTurn);
}
public void SetDiceLocked(int index, bool isLocked)
@@ -4,15 +4,13 @@ using YachtDice.Economy;
using YachtDice.Game;
using YachtDice.Inventory;
using YachtDice.Player;
using YachtDice.Scoring;
using YachtDice.Shop;
namespace YachtDice.UI.Presentation
{
public sealed class GameFlowPresenter : IDisposable
{
private readonly GameManager _gameManager;
private readonly ScoringSystem _scoringSystem;
private readonly GameLoopController _gameLoopController;
private readonly DiceManager _diceManager;
private readonly CurrencyBank _currencyBank;
private readonly ShopController _shopController;
@@ -26,8 +24,7 @@ namespace YachtDice.UI.Presentation
private readonly GameInfoPresenter _gameInfoPresenter;
public GameFlowPresenter(
GameManager gameManager,
ScoringSystem scoringSystem,
GameLoopController gameLoopController,
DiceManager diceManager,
CurrencyBank currencyBank,
ShopController shopController,
@@ -40,8 +37,7 @@ namespace YachtDice.UI.Presentation
ScoreCardPresenter scoreCardPresenter,
GameInfoPresenter gameInfoPresenter)
{
_gameManager = gameManager;
_scoringSystem = scoringSystem;
_gameLoopController = gameLoopController;
_diceManager = diceManager;
_currencyBank = currencyBank;
_shopController = shopController;
@@ -57,10 +53,10 @@ namespace YachtDice.UI.Presentation
public void Initialize()
{
_gameManager.OnTurnStarted += HandleTurnStarted;
_gameManager.OnRollComplete += HandleRollComplete;
_gameManager.OnScored += HandleScored;
_gameManager.OnGameOver += HandleGameOver;
_gameLoopController.OnTurnStarted += HandleTurnStarted;
_gameLoopController.OnRollComplete += HandleRollComplete;
_gameLoopController.OnScored += HandleScored;
_gameLoopController.OnGameOver += HandleGameOver;
_dicePanelPresenter.RollClicked += HandleRollClicked;
_dicePanelPresenter.DiceToggled += HandleDiceToggled;
@@ -74,15 +70,15 @@ namespace YachtDice.UI.Presentation
_saveService.Load();
_gameInfoPresenter.SetCurrencyText(_currencyBank.Balance);
_gameManager.StartNewGame();
_gameLoopController.StartNewGame();
}
public void Dispose()
{
_gameManager.OnTurnStarted -= HandleTurnStarted;
_gameManager.OnRollComplete -= HandleRollComplete;
_gameManager.OnScored -= HandleScored;
_gameManager.OnGameOver -= HandleGameOver;
_gameLoopController.OnTurnStarted -= HandleTurnStarted;
_gameLoopController.OnRollComplete -= HandleRollComplete;
_gameLoopController.OnScored -= HandleScored;
_gameLoopController.OnGameOver -= HandleGameOver;
_dicePanelPresenter.RollClicked -= HandleRollClicked;
_dicePanelPresenter.DiceToggled -= HandleDiceToggled;
@@ -127,35 +123,20 @@ namespace YachtDice.UI.Presentation
private void HandleRollClicked()
{
if (!_gameManager.CanRoll)
return;
_dicePanelPresenter.PrepareForRoll();
_scoreCardPresenter.SetAllInteractable(false);
_gameManager.Roll();
_gameLoopController.Roll();
}
private void HandleDiceToggled(int index)
{
if (_gameManager.CurrentRoll == 0)
return;
if (_diceManager.IsAnyRolling)
return;
_gameManager.ToggleDiceLock(index);
_gameLoopController.ToggleDiceLock(index);
_dicePanelPresenter.SetDiceLocked(index, _diceManager.IsLocked(index));
}
private void HandleCategorySelected(CategoryDefinition category)
{
if (!_gameManager.CanScore)
return;
if (_scoringSystem.IsCategoryUsed(category))
return;
_gameManager.ScoreInCategory(category);
_gameLoopController.ScoreInCategory(category);
}
private void HandleNewGameClicked()
@@ -163,7 +144,7 @@ namespace YachtDice.UI.Presentation
_gameInfoPresenter.HideGameOver();
_scoreCardPresenter.ResetAll();
_dicePanelPresenter.ResetForNewGame();
_gameManager.StartNewGame();
_gameLoopController.StartNewGame();
}
private void HandleShopClicked()