[Fix] Code visual
This commit is contained in:
@@ -5,85 +5,84 @@ using YachtDice.Modifiers;
|
||||
|
||||
namespace YachtDice.Scoring
|
||||
{
|
||||
|
||||
public sealed class ScoringSystem : MonoBehaviour
|
||||
{
|
||||
public event Action<YachtCategory, int> OnCategoryScored;
|
||||
public event Action<int> OnAllCategoriesScored;
|
||||
public event Action<YachtCategory, ScoreResult> OnCategoryConfirmed;
|
||||
|
||||
private readonly Dictionary<YachtCategory, int> scorecard = new();
|
||||
private readonly HashSet<YachtCategory> usedCategories = new();
|
||||
private List<ModifierData> activeModifierData = new();
|
||||
|
||||
public bool IsCategoryUsed(YachtCategory category) => usedCategories.Contains(category);
|
||||
|
||||
public int GetCategoryScore(YachtCategory category)
|
||||
public class ScoringSystem : MonoBehaviour
|
||||
{
|
||||
return scorecard.TryGetValue(category, out int score) ? score : -1;
|
||||
}
|
||||
public event Action<YachtCategory, int> OnCategoryScored;
|
||||
public event Action<int> OnAllCategoriesScored;
|
||||
public event Action<YachtCategory, ScoreResult> OnCategoryConfirmed;
|
||||
|
||||
public int TotalScore
|
||||
{
|
||||
get
|
||||
private readonly Dictionary<YachtCategory, int> scorecard = new();
|
||||
private readonly HashSet<YachtCategory> usedCategories = new();
|
||||
private List<ModifierData> activeModifierData = new();
|
||||
|
||||
public bool IsCategoryUsed(YachtCategory category) => usedCategories.Contains(category);
|
||||
|
||||
public int GetCategoryScore(YachtCategory category)
|
||||
{
|
||||
int total = 0;
|
||||
foreach (var kvp in scorecard) total += kvp.Value;
|
||||
return total;
|
||||
return scorecard.TryGetValue(category, out int score) ? score : -1;
|
||||
}
|
||||
|
||||
public int TotalScore
|
||||
{
|
||||
get
|
||||
{
|
||||
int total = 0;
|
||||
foreach (var kvp in scorecard) total += kvp.Value;
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public int CategoriesFilledCount => usedCategories.Count;
|
||||
|
||||
public int TotalCategoryCount => Enum.GetValues(typeof(YachtCategory)).Length;
|
||||
|
||||
public bool IsComplete => CategoriesFilledCount >= TotalCategoryCount;
|
||||
|
||||
public void SetActiveModifiers(List<ModifierData> modifiers)
|
||||
{
|
||||
activeModifierData = modifiers ?? new List<ModifierData>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<ModifierData> ActiveModifiers => activeModifierData;
|
||||
|
||||
public ScoreResult PreviewScore(int[] diceValues, YachtCategory category)
|
||||
{
|
||||
int baseScore = CategoryScorer.Calculate(diceValues, category);
|
||||
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
|
||||
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ScoreResult ScoreCategory(int[] diceValues, YachtCategory category)
|
||||
{
|
||||
if (usedCategories.Contains(category))
|
||||
throw new InvalidOperationException($"Category {category} has already been scored.");
|
||||
|
||||
int baseScore = CategoryScorer.Calculate(diceValues, category);
|
||||
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
|
||||
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.AnyCategoryClosed);
|
||||
|
||||
int finalScore = result.FinalScore;
|
||||
scorecard[category] = finalScore;
|
||||
usedCategories.Add(category);
|
||||
|
||||
OnCategoryScored?.Invoke(category, finalScore);
|
||||
OnCategoryConfirmed?.Invoke(category, result);
|
||||
|
||||
if (IsComplete)
|
||||
OnAllCategoriesScored?.Invoke(TotalScore);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ResetScorecard()
|
||||
{
|
||||
scorecard.Clear();
|
||||
usedCategories.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public int CategoriesFilledCount => usedCategories.Count;
|
||||
|
||||
public int TotalCategoryCount => Enum.GetValues(typeof(YachtCategory)).Length;
|
||||
|
||||
public bool IsComplete => CategoriesFilledCount >= TotalCategoryCount;
|
||||
|
||||
public void SetActiveModifiers(List<ModifierData> modifiers)
|
||||
{
|
||||
activeModifierData = modifiers ?? new List<ModifierData>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<ModifierData> ActiveModifiers => activeModifierData;
|
||||
|
||||
public ScoreResult PreviewScore(int[] diceValues, YachtCategory category)
|
||||
{
|
||||
int baseScore = CategoryScorer.Calculate(diceValues, category);
|
||||
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
|
||||
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ScoreResult ScoreCategory(int[] diceValues, YachtCategory category)
|
||||
{
|
||||
if (usedCategories.Contains(category))
|
||||
throw new InvalidOperationException($"Category {category} has already been scored.");
|
||||
|
||||
int baseScore = CategoryScorer.Calculate(diceValues, category);
|
||||
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
|
||||
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
|
||||
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.AnyCategoryClosed);
|
||||
|
||||
int finalScore = result.FinalScore;
|
||||
scorecard[category] = finalScore;
|
||||
usedCategories.Add(category);
|
||||
|
||||
OnCategoryScored?.Invoke(category, finalScore);
|
||||
OnCategoryConfirmed?.Invoke(category, result);
|
||||
|
||||
if (IsComplete)
|
||||
OnAllCategoriesScored?.Invoke(TotalScore);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ResetScorecard()
|
||||
{
|
||||
scorecard.Clear();
|
||||
usedCategories.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user