Files
YachtDice/Assets/Scripts/UI/Presentation/ScoreCardPresenter.cs
T

91 lines
2.5 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 CategoryCatalog _categoryCatalog;
private readonly ScoringSystem _scoringSystem;
private readonly DiceManager _diceManager;
public event Action<CategoryDefinition> CategorySelected;
public ScoreCardPresenter(
ScoreCardView view,
CategoryCatalog categoryCatalog,
ScoringSystem scoringSystem,
DiceManager diceManager)
{
_view = view;
_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 = _scoringSystem.PreviewScore(dice, category);
previews[category] = result.FinalScore;
}
_view.UpdatePreviews(previews);
}
public void SetCategoryScored(CategoryDefinition category, int finalScore)
{
_view.SetCategoryScored(category, finalScore);
}
public void SetAllInteractable(bool interactable)
{
_view.SetAllInteractable(interactable);
}
public void UpdateTotalDisplay(ScoreSummary summary)
{
_view.UpdateTotalDisplay(summary.DisplayTotal);
}
public void ResetAll()
{
_view.ResetAll();
}
private void HandleCategorySelected(CategoryDefinition category)
{
CategorySelected?.Invoke(category);
}
}
}