108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using YachtDice.Categories;
|
|
using YachtDice.Game;
|
|
using YachtDice.Scoring;
|
|
|
|
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;
|
|
|
|
public event Action<CategoryDefinition> CategorySelected;
|
|
|
|
public ScoreCardPresenter(
|
|
ScoreCardView view,
|
|
GameLoopController gameLoopController,
|
|
CategoryCatalog categoryCatalog,
|
|
ScoringSystem scoringSystem,
|
|
DiceManager diceManager)
|
|
{
|
|
_view = view;
|
|
_gameLoopController = gameLoopController;
|
|
_categoryCatalog = categoryCatalog;
|
|
_scoringSystem = scoringSystem;
|
|
_diceManager = diceManager;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
_view.Initialize(_categoryCatalog);
|
|
_view.OnCategorySelected += HandleCategorySelected;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_view.OnCategorySelected -= HandleCategorySelected;
|
|
}
|
|
|
|
public void ClearAllPreviews()
|
|
{
|
|
_view.ClearAllPreviews();
|
|
}
|
|
|
|
public void UpdatePreviewScores()
|
|
{
|
|
var dice = _diceManager.GetDice();
|
|
var previews = new Dictionary<CategoryDefinition, int>();
|
|
var allCategories = _categoryCatalog.All;
|
|
|
|
for (var i = 0; i < allCategories.Count; i++)
|
|
{
|
|
var category = allCategories[i];
|
|
if (_scoringSystem.IsCategoryUsed(category))
|
|
continue;
|
|
|
|
var result = _gameLoopController.PreviewCategory(category);
|
|
previews[category] = result.FinalScore;
|
|
}
|
|
|
|
_view.UpdatePreviews(previews);
|
|
SetAvailableCategoriesInteractable();
|
|
}
|
|
|
|
public void SetCategoryScored(CategoryDefinition category, int finalScore)
|
|
{
|
|
_view.SetCategoryScored(category, finalScore);
|
|
}
|
|
|
|
public void SetAllInteractable(bool interactable)
|
|
{
|
|
_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);
|
|
}
|
|
|
|
public void ResetAll()
|
|
{
|
|
_view.ResetAll();
|
|
}
|
|
|
|
private void HandleCategorySelected(CategoryDefinition category)
|
|
{
|
|
CategorySelected?.Invoke(category);
|
|
}
|
|
}
|
|
}
|