[Refactor] Final fix GameManager & GameController
This commit is contained in:
@@ -158,9 +158,9 @@ MonoBehaviour:
|
||||
shopCatalog: {fileID: 11400000, guid: 7efc21139c0b2234194047239dcf8a71, type: 2}
|
||||
scoringSystem: {fileID: 1016044386}
|
||||
currencyBank: {fileID: 389543052}
|
||||
gameManager: {fileID: 2136136801}
|
||||
gameLoopController: {fileID: 2136136801}
|
||||
diceManager: {fileID: 822363842}
|
||||
gameController: {fileID: 1035691492}
|
||||
gamePresentationRoot: {fileID: 1035691492}
|
||||
shopController: {fileID: 1102794499}
|
||||
inventoryController: {fileID: 2034939427}
|
||||
maxActiveModifierSlots: 5
|
||||
@@ -802,7 +802,7 @@ GameObject:
|
||||
- component: {fileID: 1035691491}
|
||||
- component: {fileID: 1035691492}
|
||||
m_Layer: 0
|
||||
m_Name: GameController
|
||||
m_Name: GamePresentationRoot
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -834,11 +834,10 @@ MonoBehaviour:
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 06752cfc00e8dc24f8004581af1a1933, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: YachtDice.Runtime::YachtDice.UI.GameController
|
||||
m_EditorClassIdentifier: YachtDice.Runtime::YachtDice.UI.GamePresentationRoot
|
||||
scoreCardView: {fileID: 0}
|
||||
dicePanelView: {fileID: 0}
|
||||
gameInfoView: {fileID: 0}
|
||||
maxRollsPerTurn: 3
|
||||
--- !u!4 &1077005091 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 6590077607741954368, guid: b59e9f48ded300a44bdf1f3f3a43e1ae, type: 3}
|
||||
@@ -1466,7 +1465,7 @@ GameObject:
|
||||
- component: {fileID: 2136136800}
|
||||
- component: {fileID: 2136136801}
|
||||
m_Layer: 0
|
||||
m_Name: GameManager
|
||||
m_Name: GameLoopController
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -1498,7 +1497,7 @@ MonoBehaviour:
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 187be5e60b9cc014fbe755fbe18578be, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: YachtDice.Runtime::YachtDice.Game.GameManager
|
||||
m_EditorClassIdentifier: YachtDice.Runtime::YachtDice.Game.GameLoopController
|
||||
maxRollsPerTurn: 3
|
||||
--- !u!1001 &3765562131710099387
|
||||
PrefabInstance:
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace YachtDice.DI
|
||||
[Header("Scene References")]
|
||||
[SerializeField] private ScoringSystem scoringSystem;
|
||||
[SerializeField] private CurrencyBank currencyBank;
|
||||
[SerializeField] private GameManager gameManager;
|
||||
[SerializeField] private GameLoopController gameLoopController;
|
||||
[SerializeField] private DiceManager diceManager;
|
||||
[SerializeField] private GameController gameController;
|
||||
[SerializeField] private GamePresentationRoot gamePresentationRoot;
|
||||
[SerializeField] private ShopController shopController;
|
||||
[SerializeField] private InventoryController inventoryController;
|
||||
|
||||
@@ -69,9 +69,9 @@ namespace YachtDice.DI
|
||||
// Scene MonoBehaviour components
|
||||
builder.RegisterComponent(scoringSystem);
|
||||
builder.RegisterComponent(currencyBank);
|
||||
builder.RegisterComponent(gameManager);
|
||||
builder.RegisterComponent(gameLoopController);
|
||||
builder.RegisterComponent(diceManager);
|
||||
builder.RegisterComponent(gameController);
|
||||
builder.RegisterComponent(gamePresentationRoot);
|
||||
builder.RegisterComponent(shopController);
|
||||
builder.RegisterComponent(inventoryController);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using YachtDice.Scoring;
|
||||
|
||||
namespace YachtDice.Game
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
public class GameLoopController : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private int maxRollsPerTurn = 3;
|
||||
@@ -47,7 +47,6 @@ namespace YachtDice.Game
|
||||
CurrentRoll = 0;
|
||||
_diceManager.UnlockAll();
|
||||
OnTurnStarted?.Invoke(CurrentTurn);
|
||||
Debug.Log($"=== Turn {CurrentTurn} ===");
|
||||
}
|
||||
|
||||
public void Roll()
|
||||
@@ -62,10 +61,6 @@ namespace YachtDice.Game
|
||||
private void HandleAllDiceSettled()
|
||||
{
|
||||
_diceManager.OnAllDiceSettled -= HandleAllDiceSettled;
|
||||
|
||||
var values = _diceManager.GetCurrentValues();
|
||||
Debug.Log($"Roll {CurrentRoll}/{maxRollsPerTurn} | Dice: [{string.Join(", ", values)}]");
|
||||
|
||||
OnRollComplete?.Invoke(CurrentRoll);
|
||||
}
|
||||
|
||||
@@ -74,9 +69,6 @@ namespace YachtDice.Game
|
||||
if (_diceManager.IsAnyRolling) return;
|
||||
if (CurrentRoll == 0) return;
|
||||
_diceManager.ToggleLock(index);
|
||||
|
||||
var isLocked = _diceManager.IsLocked(index);
|
||||
Debug.Log($"Dice {index + 1} (value={_diceManager.GetValue(index)}): {(isLocked ? "LOCKED" : "UNLOCKED")}");
|
||||
}
|
||||
|
||||
public void ScoreInCategory(CategoryDefinition category)
|
||||
@@ -85,18 +77,13 @@ namespace YachtDice.Game
|
||||
if (_scoringSystem.IsCategoryUsed(category)) return;
|
||||
|
||||
var dice = _diceManager.GetDice();
|
||||
ScoreResult result = _scoringSystem.ScoreCategory(dice, category);
|
||||
|
||||
Debug.Log($"Scored {category.DisplayName}: base={result.baseScore}, " +
|
||||
$"bonus=+{result.flatBonus}, mult=x{result.multiplier:F1}, " +
|
||||
$"FINAL={result.FinalScore} | Total={_scoringSystem.TotalScore}");
|
||||
var result = _scoringSystem.ScoreCategory(dice, category);
|
||||
|
||||
OnScored?.Invoke(category, result.FinalScore);
|
||||
|
||||
if (_scoringSystem.IsComplete)
|
||||
{
|
||||
var total = _scoringSystem.TotalScore;
|
||||
Debug.Log($"*** GAME OVER *** Total Score: {total}");
|
||||
OnGameOver?.Invoke(total);
|
||||
}
|
||||
else
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 187be5e60b9cc014fbe755fbe18578be
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 187be5e60b9cc014fbe755fbe18578be
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user