[Refactor] Final fix GameManager & GameController
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user