[Rem] Upper sum Text & upper bonus text | previewText & recordedScoreText (move to scoreText)
This commit is contained in:
@@ -12,13 +12,9 @@ namespace YachtDice.Categories
|
||||
public class CategoryCatalog : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<CategoryDefinition> categories = new();
|
||||
[SerializeField] private int upperBonusThreshold = 63;
|
||||
[SerializeField] private int upperBonusValue = 35;
|
||||
|
||||
public IReadOnlyList<CategoryDefinition> All => categories;
|
||||
public int Count => categories.Count;
|
||||
public int UpperBonusThreshold => upperBonusThreshold;
|
||||
public int UpperBonusValue => upperBonusValue;
|
||||
|
||||
public CategoryDefinition FindById(string id)
|
||||
{
|
||||
@@ -42,12 +38,10 @@ namespace YachtDice.Categories
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static CategoryCatalog CreateForTest(List<CategoryDefinition> defs, int upperBonusThreshold = 63, int upperBonusValue = 35)
|
||||
public static CategoryCatalog CreateForTest(List<CategoryDefinition> defs)
|
||||
{
|
||||
var catalog = CreateInstance<CategoryCatalog>();
|
||||
catalog.categories = defs ?? new List<CategoryDefinition>();
|
||||
catalog.upperBonusThreshold = upperBonusThreshold;
|
||||
catalog.upperBonusValue = upperBonusValue;
|
||||
return catalog;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -16,20 +16,16 @@ namespace YachtDice.Categories
|
||||
[field: SerializeField, TextArea] public string Description { get; private set; }
|
||||
[field: SerializeField] public Sprite Icon { get; private set; }
|
||||
|
||||
[field: Header("Section")]
|
||||
[field: SerializeField] public bool IsUpperSection { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вычисляет очки для данного набора дайсов.
|
||||
/// </summary>
|
||||
public abstract int Calculate(IReadOnlyList<IDice> dice);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void SetTestData(string testId, string testDisplayName, bool upperSection = false)
|
||||
public void SetTestData(string testId, string testDisplayName)
|
||||
{
|
||||
Id = testId;
|
||||
DisplayName = testDisplayName;
|
||||
IsUpperSection = upperSection;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace YachtDice.Categories
|
||||
public static MasterValueCategory CreateForTest(string id, string displayName, int targetValue, int categoryBonus = 0)
|
||||
{
|
||||
var so = CreateInstance<MasterValueCategory>();
|
||||
so.SetTestData(id, displayName, upperSection: true);
|
||||
so.SetTestData(id, displayName);
|
||||
so.TargetValue = targetValue;
|
||||
so.CategoryBonus = categoryBonus;
|
||||
return so;
|
||||
|
||||
@@ -5,7 +5,7 @@ using YachtDice.Dice;
|
||||
namespace YachtDice.Categories
|
||||
{
|
||||
/// <summary>
|
||||
/// Категория верхней секции: суммирует все дайсы с заданным значением.
|
||||
/// Категория, которая суммирует все дайсы с заданным значением.
|
||||
/// Используется для Единиц (1), Двоек (2), ... Шестёрок (6).
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "SumOfValueCategory", menuName = "YachtDice/Categories/Sum Of Value")]
|
||||
@@ -29,7 +29,7 @@ namespace YachtDice.Categories
|
||||
public static SumOfValueCategory CreateForTest(string id, string displayName, int target)
|
||||
{
|
||||
var so = CreateInstance<SumOfValueCategory>();
|
||||
so.SetTestData(id, displayName, upperSection: true);
|
||||
so.SetTestData(id, displayName);
|
||||
so.TargetValue = target;
|
||||
return so;
|
||||
}
|
||||
|
||||
@@ -176,9 +176,6 @@ namespace YachtDice.Dice
|
||||
stillTimer = isSlow ? stillTimer + Time.fixedDeltaTime : 0f;
|
||||
}
|
||||
|
||||
if (didTimeout)
|
||||
Debug.LogWarning($"DiceRoller: бросок принудительно завершён по таймауту ({maxDuration:0.##} c).", this);
|
||||
|
||||
// ── 5. Замораживаем физику и читаем верхнюю грань ───────────
|
||||
rb.linearVelocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
|
||||
@@ -126,11 +126,11 @@ namespace YachtDice.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScoreSummaryService_UsesCatalogConfiguredUpperBonus()
|
||||
public void ScoreSummaryService_ReturnsCurrentScoringTotal()
|
||||
{
|
||||
var ones = MasterValueCategory.CreateForTest("ones", "Единицы", 1, categoryBonus: 1);
|
||||
var twos = MasterValueCategory.CreateForTest("twos", "Двойки", 2, categoryBonus: 2);
|
||||
var catalog = CategoryCatalog.CreateForTest(new List<CategoryDefinition> { ones, twos }, upperBonusThreshold: 15, upperBonusValue: 50);
|
||||
var catalog = CategoryCatalog.CreateForTest(new List<CategoryDefinition> { ones, twos });
|
||||
_createdAssets.Add(ones);
|
||||
_createdAssets.Add(twos);
|
||||
_createdAssets.Add(catalog);
|
||||
@@ -142,12 +142,10 @@ namespace YachtDice.Tests
|
||||
scoringSystem.ScoreCategory(CreateDice(1, 1, 1, 1, 2, 3), ones);
|
||||
scoringSystem.ScoreCategory(CreateDice(2, 2, 2, 2, 5, 6), twos);
|
||||
|
||||
var summaryService = new ScoreSummaryService(scoringSystem, catalog);
|
||||
var summaryService = new ScoreSummaryService(scoringSystem);
|
||||
var summary = summaryService.Calculate();
|
||||
|
||||
Assert.AreEqual(16, summary.UpperSum);
|
||||
Assert.IsTrue(summary.HasUpperBonus);
|
||||
Assert.AreEqual(66, summary.DisplayTotal);
|
||||
Assert.AreEqual(scoringSystem.TotalScore, summary.DisplayTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace YachtDice.UI
|
||||
{
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private TMP_Text categoryNameText;
|
||||
[SerializeField] private TMP_Text previewText;
|
||||
[SerializeField] private TMP_Text recordedScoreText;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private Button selectButton;
|
||||
[SerializeField] private Image background;
|
||||
|
||||
@@ -31,8 +30,7 @@ namespace YachtDice.UI
|
||||
_category = categoryDef;
|
||||
_isUsed = false;
|
||||
categoryNameText.text = categoryDef.DisplayName;
|
||||
previewText.text = "";
|
||||
recordedScoreText.text = "-";
|
||||
scoreText.text = "-";
|
||||
selectButton.onClick.AddListener(HandleClick);
|
||||
SetInteractable(false);
|
||||
background.color = normalColor;
|
||||
@@ -41,22 +39,21 @@ namespace YachtDice.UI
|
||||
public void ShowPreview(int previewScore)
|
||||
{
|
||||
if (_isUsed) return;
|
||||
previewText.text = previewScore.ToString();
|
||||
scoreText.text = previewScore.ToString();
|
||||
background.color = previewScore > 0 ? previewPositiveColor : previewZeroColor;
|
||||
}
|
||||
|
||||
public void HidePreview()
|
||||
{
|
||||
if (_isUsed) return;
|
||||
previewText.text = "";
|
||||
scoreText.text = "-";
|
||||
background.color = normalColor;
|
||||
}
|
||||
|
||||
public void SetRecordedScore(int score)
|
||||
{
|
||||
_isUsed = true;
|
||||
recordedScoreText.text = score.ToString();
|
||||
previewText.text = "";
|
||||
scoreText.text = score.ToString();
|
||||
SetInteractable(false);
|
||||
background.color = usedColor;
|
||||
}
|
||||
@@ -74,8 +71,7 @@ namespace YachtDice.UI
|
||||
public void ResetRow()
|
||||
{
|
||||
_isUsed = false;
|
||||
previewText.text = "";
|
||||
recordedScoreText.text = "-";
|
||||
scoreText.text = "-";
|
||||
SetInteractable(false);
|
||||
background.color = normalColor;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace YachtDice.UI.Presentation
|
||||
|
||||
public void UpdateTotalDisplay(ScoreSummary summary)
|
||||
{
|
||||
_view.UpdateTotalDisplay(summary.DisplayTotal, summary.UpperSum, summary.HasUpperBonus);
|
||||
_view.UpdateTotalDisplay(summary.DisplayTotal);
|
||||
}
|
||||
|
||||
public void ResetAll()
|
||||
|
||||
@@ -3,14 +3,10 @@ namespace YachtDice.UI.Presentation
|
||||
public readonly struct ScoreSummary
|
||||
{
|
||||
public int DisplayTotal { get; }
|
||||
public int UpperSum { get; }
|
||||
public bool HasUpperBonus { get; }
|
||||
|
||||
public ScoreSummary(int displayTotal, int upperSum, bool hasUpperBonus)
|
||||
public ScoreSummary(int displayTotal)
|
||||
{
|
||||
DisplayTotal = displayTotal;
|
||||
UpperSum = upperSum;
|
||||
HasUpperBonus = hasUpperBonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using YachtDice.Categories;
|
||||
using YachtDice.Scoring;
|
||||
|
||||
namespace YachtDice.UI.Presentation
|
||||
@@ -6,43 +5,15 @@ namespace YachtDice.UI.Presentation
|
||||
public sealed class ScoreSummaryService : IScoreSummaryService
|
||||
{
|
||||
private readonly ScoringSystem _scoringSystem;
|
||||
private readonly CategoryCatalog _categoryCatalog;
|
||||
|
||||
public ScoreSummaryService(ScoringSystem scoringSystem, CategoryCatalog categoryCatalog)
|
||||
public ScoreSummaryService(ScoringSystem scoringSystem)
|
||||
{
|
||||
_scoringSystem = scoringSystem;
|
||||
_categoryCatalog = categoryCatalog;
|
||||
}
|
||||
|
||||
public ScoreSummary Calculate()
|
||||
{
|
||||
var upperSum = CalculateUpperSum();
|
||||
var hasUpperBonus = upperSum >= _categoryCatalog.UpperBonusThreshold;
|
||||
|
||||
var total = _scoringSystem.TotalScore;
|
||||
if (hasUpperBonus)
|
||||
total += _categoryCatalog.UpperBonusValue;
|
||||
|
||||
return new ScoreSummary(total, upperSum, hasUpperBonus);
|
||||
}
|
||||
|
||||
private int CalculateUpperSum()
|
||||
{
|
||||
var upperSum = 0;
|
||||
var allCategories = _categoryCatalog.All;
|
||||
|
||||
for (var i = 0; i < allCategories.Count; i++)
|
||||
{
|
||||
var category = allCategories[i];
|
||||
if (!category.IsUpperSection)
|
||||
continue;
|
||||
|
||||
var categoryScore = _scoringSystem.GetCategoryScore(category);
|
||||
if (categoryScore >= 0)
|
||||
upperSum += categoryScore;
|
||||
}
|
||||
|
||||
return upperSum;
|
||||
return new ScoreSummary(_scoringSystem.TotalScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace YachtDice.UI
|
||||
[SerializeField] private List<CategoryRowView> categoryRows = new();
|
||||
|
||||
[Header("Summary")]
|
||||
[SerializeField] private TMP_Text upperSumText;
|
||||
[SerializeField] private TMP_Text upperBonusText;
|
||||
[SerializeField] private TMP_Text totalScoreText;
|
||||
|
||||
public event Action<CategoryDefinition> OnCategorySelected;
|
||||
@@ -40,7 +38,7 @@ namespace YachtDice.UI
|
||||
_categoryToRowIndex[all[i]] = i;
|
||||
}
|
||||
|
||||
UpdateTotalDisplay(0, 0, false);
|
||||
UpdateTotalDisplay(0);
|
||||
}
|
||||
|
||||
public void UpdatePreviews(Dictionary<CategoryDefinition, int> previews)
|
||||
@@ -76,14 +74,9 @@ namespace YachtDice.UI
|
||||
t.SetInteractable(interactable);
|
||||
}
|
||||
|
||||
public void UpdateTotalDisplay(int totalScore, int upperSum, bool hasUpperBonus)
|
||||
public void UpdateTotalDisplay(int totalScore)
|
||||
{
|
||||
var threshold = _catalog != null ? _catalog.UpperBonusThreshold : 63;
|
||||
var bonusValue = _catalog != null ? _catalog.UpperBonusValue : 35;
|
||||
|
||||
totalScoreText.text = totalScore.ToString();
|
||||
upperSumText.text = $"{upperSum} / {threshold}";
|
||||
upperBonusText.text = hasUpperBonus ? $"+{bonusValue}" : "---";
|
||||
}
|
||||
|
||||
public void ResetAll()
|
||||
@@ -91,7 +84,7 @@ namespace YachtDice.UI
|
||||
foreach (var t in categoryRows)
|
||||
t.ResetRow();
|
||||
|
||||
UpdateTotalDisplay(0, 0, false);
|
||||
UpdateTotalDisplay(0);
|
||||
}
|
||||
|
||||
private void HandleCategorySelected(CategoryDefinition category)
|
||||
|
||||
Reference in New Issue
Block a user