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