[Add] GameLoop base

This commit is contained in:
2026-03-18 09:13:48 +07:00
parent c819c0d045
commit 537ae1ce5c
28 changed files with 997 additions and 40 deletions
@@ -69,6 +69,12 @@ namespace YachtDice.UI.Presentation
_view.SetDiceLocked(index, isLocked);
}
public void SetRollingEnabled(bool enabled)
{
_view.SetRollButtonInteractable(enabled);
_view.SetDiceInteractable(enabled && _gameLoopController.CurrentRoll > 0);
}
private void HandleRollClicked()
{
RollClicked?.Invoke();
@@ -4,6 +4,7 @@ using YachtDice.Economy;
using YachtDice.Game;
using YachtDice.Inventory;
using YachtDice.Player;
using YachtDice.Run;
using YachtDice.Shop;
namespace YachtDice.UI.Presentation
@@ -57,6 +58,13 @@ namespace YachtDice.UI.Presentation
_gameLoopController.OnRollComplete += HandleRollComplete;
_gameLoopController.OnScored += HandleScored;
_gameLoopController.OnGameOver += HandleGameOver;
_gameLoopController.OnBetStarted += HandleBetStarted;
_gameLoopController.OnShopOpened += HandleShopOpened;
_gameLoopController.OnShopClosed += HandleShopClosed;
_gameLoopController.OnStoredRollsChanged += HandleStoredRollsChanged;
_gameLoopController.OnQuotaChanged += HandleQuotaChanged;
_gameLoopController.OnCycleCompleted += HandleCycleCompleted;
_gameLoopController.OnPhaseChanged += HandlePhaseChanged;
_dicePanelPresenter.RollClicked += HandleRollClicked;
_dicePanelPresenter.DiceToggled += HandleDiceToggled;
@@ -70,6 +78,7 @@ namespace YachtDice.UI.Presentation
_saveService.Load();
_gameInfoPresenter.SetCurrencyText(_currencyBank.Balance);
_gameInfoPresenter.SetShopButtonInteractable(false);
_gameLoopController.StartNewGame();
}
@@ -79,6 +88,13 @@ namespace YachtDice.UI.Presentation
_gameLoopController.OnRollComplete -= HandleRollComplete;
_gameLoopController.OnScored -= HandleScored;
_gameLoopController.OnGameOver -= HandleGameOver;
_gameLoopController.OnBetStarted -= HandleBetStarted;
_gameLoopController.OnShopOpened -= HandleShopOpened;
_gameLoopController.OnShopClosed -= HandleShopClosed;
_gameLoopController.OnStoredRollsChanged -= HandleStoredRollsChanged;
_gameLoopController.OnQuotaChanged -= HandleQuotaChanged;
_gameLoopController.OnCycleCompleted -= HandleCycleCompleted;
_gameLoopController.OnPhaseChanged -= HandlePhaseChanged;
_dicePanelPresenter.RollClicked -= HandleRollClicked;
_dicePanelPresenter.DiceToggled -= HandleDiceToggled;
@@ -95,8 +111,9 @@ namespace YachtDice.UI.Presentation
private void HandleTurnStarted(int turn)
{
_gameInfoPresenter.SetTurnText(turn, _categoryCatalog.Count);
UpdateRunInfoText();
_dicePanelPresenter.ResetForNewTurn();
_dicePanelPresenter.SetRollingEnabled(true);
_scoreCardPresenter.ClearAllPreviews();
}
@@ -110,6 +127,7 @@ namespace YachtDice.UI.Presentation
{
_scoreCardPresenter.SetCategoryScored(category, finalScore);
_scoreCardPresenter.UpdateTotalDisplay(_scoreSummaryService.Calculate());
UpdateRunInfoText();
_saveService.Save();
}
@@ -118,6 +136,8 @@ namespace YachtDice.UI.Presentation
_dicePanelPresenter.HandleGameOver();
_scoreCardPresenter.SetAllInteractable(false);
_gameInfoPresenter.ShowGameOver(_scoreSummaryService.Calculate().DisplayTotal);
_shopController.Close();
_gameInfoPresenter.SetShopButtonInteractable(false);
_saveService.Save();
}
@@ -142,6 +162,8 @@ namespace YachtDice.UI.Presentation
private void HandleNewGameClicked()
{
_gameInfoPresenter.HideGameOver();
_shopController.Close();
_gameInfoPresenter.SetShopButtonInteractable(false);
_scoreCardPresenter.ResetAll();
_dicePanelPresenter.ResetForNewGame();
_gameLoopController.StartNewGame();
@@ -149,7 +171,18 @@ namespace YachtDice.UI.Presentation
private void HandleShopClicked()
{
_shopController.ToggleVisibility();
if (!_gameLoopController.CanOpenShopManually())
return;
if (_shopController.IsOpen)
{
_shopController.Close();
_gameLoopController.CompleteShop();
}
else
{
_shopController.Open();
}
}
private void HandleInventoryClicked()
@@ -160,11 +193,63 @@ namespace YachtDice.UI.Presentation
private void HandleCurrencyChanged(int newBalance)
{
_gameInfoPresenter.SetCurrencyText(newBalance);
UpdateRunInfoText();
}
private void HandlePlayerChangedForSave()
{
_saveService.Save();
}
private void HandleBetStarted(int betIndex)
{
UpdateRunInfoText();
}
private void HandleShopOpened()
{
_shopController.Open();
_gameInfoPresenter.SetShopButtonInteractable(true);
_dicePanelPresenter.SetRollingEnabled(false);
UpdateRunInfoText();
}
private void HandleShopClosed()
{
_shopController.Close();
_gameInfoPresenter.SetShopButtonInteractable(false);
UpdateRunInfoText();
}
private void HandleStoredRollsChanged(int value)
{
UpdateRunInfoText();
}
private void HandleQuotaChanged(int value)
{
UpdateRunInfoText();
}
private void HandleCycleCompleted(int bonus, int storedRolls)
{
_scoreCardPresenter.ResetAll();
_scoreCardPresenter.UpdateTotalDisplay(_scoreSummaryService.Calculate());
UpdateRunInfoText();
}
private void HandlePhaseChanged(RunPhase phase)
{
if (phase != RunPhase.Shop)
_gameInfoPresenter.SetShopButtonInteractable(false);
UpdateRunInfoText();
}
private void UpdateRunInfoText()
{
var info = $"Bet {_gameLoopController.CurrentBet} | Stage {_gameLoopController.CurrentStage}/3 | Target {_gameLoopController.CurrentStageTarget} | Quota {_gameLoopController.CurrentBaseQuota} | Bank {_gameLoopController.StoredRolls}";
_gameInfoPresenter.SetRunInfoText(info);
}
}
}
@@ -34,11 +34,21 @@ namespace YachtDice.UI.Presentation
_view.SetTurnText(turn, maxTurns);
}
public void SetRunInfoText(string text)
{
_view.SetRunInfoText(text);
}
public void SetCurrencyText(int amount)
{
_view.SetCurrencyText(amount);
}
public void SetShopButtonInteractable(bool interactable)
{
_view.SetShopButtonInteractable(interactable);
}
public void ShowGameOver(int finalScore)
{
_view.ShowGameOver(finalScore);
@@ -9,6 +9,7 @@ namespace YachtDice.UI.Presentation
public sealed class ScoreCardPresenter : IDisposable
{
private readonly ScoreCardView _view;
private readonly GameLoopController _gameLoopController;
private readonly CategoryCatalog _categoryCatalog;
private readonly ScoringSystem _scoringSystem;
private readonly DiceManager _diceManager;
@@ -17,11 +18,13 @@ namespace YachtDice.UI.Presentation
public ScoreCardPresenter(
ScoreCardView view,
GameLoopController gameLoopController,
CategoryCatalog categoryCatalog,
ScoringSystem scoringSystem,
DiceManager diceManager)
{
_view = view;
_gameLoopController = gameLoopController;
_categoryCatalog = categoryCatalog;
_scoringSystem = scoringSystem;
_diceManager = diceManager;
@@ -55,11 +58,12 @@ namespace YachtDice.UI.Presentation
if (_scoringSystem.IsCategoryUsed(category))
continue;
var result = _scoringSystem.PreviewScore(dice, category);
var result = _gameLoopController.PreviewCategory(category);
previews[category] = result.FinalScore;
}
_view.UpdatePreviews(previews);
SetAvailableCategoriesInteractable();
}
public void SetCategoryScored(CategoryDefinition category, int finalScore)
@@ -72,6 +76,19 @@ namespace YachtDice.UI.Presentation
_view.SetAllInteractable(interactable);
}
public void SetAvailableCategoriesInteractable()
{
var allCategories = _categoryCatalog.All;
for (var i = 0; i < allCategories.Count; i++)
{
var category = allCategories[i];
if (_scoringSystem.IsCategoryUsed(category))
continue;
_view.SetCategoryInteractable(category, _gameLoopController.CanScoreCategory(category));
}
}
public void UpdateTotalDisplay(ScoreSummary summary)
{
_view.UpdateTotalDisplay(summary.DisplayTotal);