[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
+26 -34
View File
@@ -2,13 +2,13 @@ using System;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using YachtDice.Scoring;
using YachtDice.Categories;
namespace YachtDice.UI
{
public class ScoreCardView : MonoBehaviour
{
[Header("Category Rows (in YachtCategory enum order)")]
[Header("Category Rows (порядок соответствует каталогу)")]
[SerializeField] private List<CategoryRowView> categoryRows = new();
[Header("Summary")]
@@ -16,48 +16,41 @@ namespace YachtDice.UI
[SerializeField] private TMP_Text upperBonusText;
[SerializeField] private TMP_Text totalScoreText;
public event Action<YachtCategory> OnCategorySelected;
public event Action<CategoryDefinitionSO> OnCategorySelected;
private static readonly string[] CategoryNames =
private CategoryCatalogSO catalog;
private Dictionary<CategoryDefinitionSO, int> categoryToRowIndex;
/// <summary>
/// Инициализирует скоркарту из каталога категорий.
/// Вызывается из GameController после DI.
/// </summary>
public void Initialize(CategoryCatalogSO categoryCatalog)
{
"Единицы",
"Двойки",
"Тройки",
"Четвёрки",
"Пятёрки",
"Шестёрки",
"Тройка",
"Каре",
"Фулл-хаус",
"Малый стрит",
"Большой стрит",
"Яхта",
"Шанс"
};
catalog = categoryCatalog;
categoryToRowIndex = new Dictionary<CategoryDefinitionSO, int>();
private YachtCategory[] _allCategories;
var all = catalog.All;
int count = Mathf.Min(categoryRows.Count, all.Count);
private void Awake()
{
_allCategories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
for (int i = 0; i < categoryRows.Count && i < _allCategories.Length; i++)
for (int i = 0; i < count; i++)
{
categoryRows[i].Initialize(_allCategories[i], CategoryNames[i]);
categoryRows[i].Initialize(all[i]);
categoryRows[i].OnCategorySelected += HandleCategorySelected;
categoryToRowIndex[all[i]] = i;
}
UpdateTotalDisplay(0, 0, false);
}
public void UpdatePreviews(Dictionary<YachtCategory, int> previews)
public void UpdatePreviews(Dictionary<CategoryDefinitionSO, int> previews)
{
for (int i = 0; i < categoryRows.Count && i < _allCategories.Length; i++)
foreach (var kvp in previews)
{
if (previews.TryGetValue(_allCategories[i], out int preview))
if (categoryToRowIndex.TryGetValue(kvp.Key, out int rowIndex))
{
categoryRows[i].ShowPreview(preview);
categoryRows[i].SetInteractable(true);
categoryRows[rowIndex].ShowPreview(kvp.Value);
categoryRows[rowIndex].SetInteractable(true);
}
}
}
@@ -71,10 +64,9 @@ namespace YachtDice.UI
}
}
public void SetCategoryScored(YachtCategory category, int score)
public void SetCategoryScored(CategoryDefinitionSO category, int score)
{
int index = (int)category;
if (index >= 0 && index < categoryRows.Count)
if (categoryToRowIndex.TryGetValue(category, out int index))
categoryRows[index].SetRecordedScore(score);
}
@@ -99,7 +91,7 @@ namespace YachtDice.UI
UpdateTotalDisplay(0, 0, false);
}
private void HandleCategorySelected(YachtCategory category)
private void HandleCategorySelected(CategoryDefinitionSO category)
{
OnCategorySelected?.Invoke(category);
}