[Refactor] Replace hardcoded categories with data-driven SO system and abstract dice

- Add abstract dice system (IDie interface, DieDefinitionSO, StandardDieSO, DieInstance)
  to support future custom dice types while keeping backward compat via int[] DiceValues
- Replace YachtCategory enum and CategoryScorer switch with CategoryDefinitionSO hierarchy:
  SumOfValueCategorySO, NOfAKindCategorySO, FullHouseCategorySO, StraightCategorySO, SumAllCategorySO
- Add CategoryCatalogSO for ordered category collections and DiceCheckUtility for shared logic
- Refactor ScoringSystem, Views, GameManager, GameController to use SO references
- Update CategoryCondition modifier to use SO reference instead of enum
- Update all editor tests to use SO-based categories and DieInstance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 11:46:50 +07:00
parent 6a48d68f75
commit 0f9b162061
31 changed files with 845 additions and 298 deletions
+39 -36
View File
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using VContainer;
using YachtDice.Categories;
using YachtDice.Dice;
using YachtDice.Game;
using YachtDice.Scoring;
using YachtDice.Economy;
@@ -34,33 +35,25 @@ namespace YachtDice.UI
[SerializeField] private int maxRollsPerTurn = 3;
[SerializeField] private int maxActiveModifierSlots = 5;
private static readonly YachtCategory[] UpperCategories =
{
YachtCategory.Ones, YachtCategory.Twos, YachtCategory.Threes,
YachtCategory.Fours, YachtCategory.Fives, YachtCategory.Sixes
};
private const int UpperBonusThreshold = 63;
private const int UpperBonusValue = 35;
private int totalCategoryCount;
private ModifierRegistry modifierRegistry;
private CategoryCatalogSO categoryCatalog;
private InventoryModel inventoryModel;
private ShopModel shopModel;
[Inject]
public void Construct(ModifierRegistry modifierRegistry)
public void Construct(ModifierRegistry modifierRegistry, CategoryCatalogSO categoryCatalog)
{
this.modifierRegistry = modifierRegistry;
this.categoryCatalog = categoryCatalog;
}
// ── Lifecycle ──────────────────────────────────────────────
private void Awake()
{
totalCategoryCount = Enum.GetValues(typeof(YachtCategory)).Length;
// Model → Controller
gameManager.OnTurnStarted += HandleTurnStarted;
gameManager.OnRollComplete += HandleRollComplete;
@@ -83,6 +76,9 @@ namespace YachtDice.UI
private void Start()
{
// Инициализируем скоркарту из каталога категорий
scoreCardView.Initialize(categoryCatalog);
InitializeModifierSystems();
}
@@ -197,6 +193,7 @@ namespace YachtDice.UI
private void HandleTurnStarted(int turn)
{
int totalCategoryCount = categoryCatalog.Count;
gameInfoView.SetTurnText(turn, totalCategoryCount);
dicePanelView.ResetForNewTurn();
dicePanelView.SetRollButtonState(true, 0, maxRollsPerTurn);
@@ -212,7 +209,7 @@ namespace YachtDice.UI
int[] values = diceManager.GetCurrentValues();
dicePanelView.SetAllDiceValues(values);
UpdatePreviewScores(values);
UpdatePreviewScores();
}
private void HandleDieSettled(int index, int value)
@@ -220,7 +217,7 @@ namespace YachtDice.UI
dicePanelView.SetDieValue(index, value);
}
private void HandleScored(YachtCategory category, int finalScore)
private void HandleScored(CategoryDefinitionSO category, int finalScore)
{
scoreCardView.SetCategoryScored(category, finalScore);
UpdateTotalDisplay();
@@ -262,7 +259,7 @@ namespace YachtDice.UI
dicePanelView.SetDieLocked(index, isLocked);
}
private void HandleCategorySelected(YachtCategory category)
private void HandleCategorySelected(CategoryDefinitionSO category)
{
if (!gameManager.CanScore) return;
if (scoringSystem.IsCategoryUsed(category)) return;
@@ -317,17 +314,19 @@ namespace YachtDice.UI
// ── Helpers ────────────────────────────────────────────────
private void UpdatePreviewScores(int[] diceValues)
private void UpdatePreviewScores()
{
var previews = new Dictionary<YachtCategory, int>();
var categories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
var dice = diceManager.GetDice();
var previews = new Dictionary<CategoryDefinitionSO, int>();
var allCategories = categoryCatalog.All;
for (int i = 0; i < categories.Length; i++)
for (int i = 0; i < allCategories.Count; i++)
{
if (scoringSystem.IsCategoryUsed(categories[i])) continue;
var cat = allCategories[i];
if (scoringSystem.IsCategoryUsed(cat)) continue;
ScoreResult result = scoringSystem.PreviewScore(diceValues, categories[i]);
previews[categories[i]] = result.FinalScore;
ScoreResult result = scoringSystem.PreviewScore(dice, cat);
previews[cat] = result.FinalScore;
}
scoreCardView.UpdatePreviews(previews);
@@ -335,29 +334,33 @@ namespace YachtDice.UI
private void UpdateTotalDisplay()
{
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
}
int upperSum = CalculateUpperSum();
bool hasBonus = upperSum >= UpperBonusThreshold;
int displayTotal = CalculateDisplayTotal();
scoreCardView.UpdateTotalDisplay(displayTotal, upperSum, hasBonus);
}
private int CalculateUpperSum()
{
int upperSum = 0;
var allCategories = categoryCatalog.All;
for (int i = 0; i < allCategories.Count; i++)
{
if (!allCategories[i].IsUpperSection) continue;
int catScore = scoringSystem.GetCategoryScore(allCategories[i]);
if (catScore >= 0) upperSum += catScore;
}
return upperSum;
}
private int CalculateDisplayTotal()
{
int total = scoringSystem.TotalScore;
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
}
int upperSum = CalculateUpperSum();
if (upperSum >= UpperBonusThreshold)
total += UpperBonusValue;