[Refactor] Replace [SerializeField] + getter with [field: SerializeField] auto-properties
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,20 +10,14 @@ namespace YachtDice.Categories
|
||||
/// </summary>
|
||||
public abstract class CategoryDefinition : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField, TextArea] private string description;
|
||||
[SerializeField] private Sprite icon;
|
||||
[field: Header("Identity")]
|
||||
[field: SerializeField] public string Id { get; private set; }
|
||||
[field: SerializeField] public string DisplayName { get; private set; }
|
||||
[field: SerializeField, TextArea] public string Description { get; private set; }
|
||||
[field: SerializeField] public Sprite Icon { get; private set; }
|
||||
|
||||
[Header("Section")]
|
||||
[SerializeField] private bool isUpperSection;
|
||||
|
||||
public string Id => id;
|
||||
public string DisplayName => displayName;
|
||||
public string Description => description;
|
||||
public Sprite Icon => icon;
|
||||
public bool IsUpperSection => isUpperSection;
|
||||
[field: Header("Section")]
|
||||
[field: SerializeField] public bool IsUpperSection { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вычисляет очки для данного набора дайсов.
|
||||
@@ -33,9 +27,9 @@ namespace YachtDice.Categories
|
||||
#if UNITY_EDITOR
|
||||
public void SetTestData(string testId, string testDisplayName, bool upperSection = false)
|
||||
{
|
||||
id = testId;
|
||||
displayName = testDisplayName;
|
||||
isUpperSection = upperSection;
|
||||
Id = testId;
|
||||
DisplayName = testDisplayName;
|
||||
IsUpperSection = upperSection;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11,17 +11,15 @@ namespace YachtDice.Categories
|
||||
[CreateAssetMenu(fileName = "SumOfValueCategory", menuName = "YachtDice/Categories/Sum Of Value")]
|
||||
public class SumOfValueCategory : CategoryDefinition
|
||||
{
|
||||
[Header("Scoring")]
|
||||
[Tooltip("Значение грани для суммирования (1-6)")]
|
||||
[SerializeField, Range(1, 6)] private int targetValue = 1;
|
||||
|
||||
public int TargetValue => targetValue;
|
||||
[field: Header("Scoring")]
|
||||
[field: Tooltip("Значение грани для суммирования (1-6)")]
|
||||
[field: SerializeField, Range(1, 6)] public int TargetValue { get; private set; } = 1;
|
||||
|
||||
public override int Calculate(IReadOnlyList<IDie> dice)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < dice.Count; i++)
|
||||
if (dice[i].Value == targetValue) sum += targetValue;
|
||||
if (dice[i].Value == TargetValue) sum += TargetValue;
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -30,7 +28,7 @@ namespace YachtDice.Categories
|
||||
{
|
||||
var so = CreateInstance<SumOfValueCategory>();
|
||||
so.SetTestData(id, displayName, upperSection: true);
|
||||
so.targetValue = target;
|
||||
so.TargetValue = target;
|
||||
return so;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,15 +9,12 @@ namespace YachtDice.Dice
|
||||
[Serializable]
|
||||
public struct Entry : IEquatable<Entry>
|
||||
{
|
||||
[SerializeField] private int value;
|
||||
[SerializeField] private Transform point;
|
||||
[field: SerializeField] public int Value { get; private set; }
|
||||
[field: SerializeField] public Transform Point { get; private set; }
|
||||
|
||||
public int Value => value;
|
||||
public Transform Point => point;
|
||||
|
||||
public bool Equals(Entry other) => point == other.point;
|
||||
public bool Equals(Entry other) => Point == other.Point;
|
||||
public override bool Equals(object obj) => obj is Entry other && Equals(other);
|
||||
public override int GetHashCode() => point != null ? point.GetHashCode() : 0;
|
||||
public override int GetHashCode() => Point != null ? Point.GetHashCode() : 0;
|
||||
}
|
||||
|
||||
[SerializeField] private List<Entry> entries = new();
|
||||
|
||||
@@ -8,14 +8,10 @@ namespace YachtDice.Dice
|
||||
/// </summary>
|
||||
public abstract class DieDefinitionSO : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField] private Sprite icon;
|
||||
|
||||
public string Id => id;
|
||||
public string DisplayName => displayName;
|
||||
public Sprite Icon => icon;
|
||||
[field: Header("Identity")]
|
||||
[field: SerializeField] public string Id { get; private set; }
|
||||
[field: SerializeField] public string DisplayName { get; private set; }
|
||||
[field: SerializeField] public Sprite Icon { get; private set; }
|
||||
|
||||
/// <summary>Количество граней.</summary>
|
||||
public abstract int FaceCount { get; }
|
||||
@@ -27,8 +23,8 @@ namespace YachtDice.Dice
|
||||
public static T CreateForTest<T>(string id, string displayName = null) where T : DieDefinitionSO
|
||||
{
|
||||
var so = CreateInstance<T>();
|
||||
so.id = id;
|
||||
so.displayName = displayName ?? id;
|
||||
so.Id = id;
|
||||
so.DisplayName = displayName ?? id;
|
||||
return so;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,17 +7,14 @@ namespace YachtDice.Modifiers.Definition
|
||||
{
|
||||
public abstract class Effect : ScriptableObject, IEffect
|
||||
{
|
||||
[SerializeField] private ModifierPhase phase = ModifierPhase.Additive;
|
||||
[SerializeField] private int priority;
|
||||
|
||||
public ModifierPhase Phase => phase;
|
||||
public int Priority => priority;
|
||||
[field: SerializeField] public ModifierPhase Phase { get; private set; } = ModifierPhase.Additive;
|
||||
[field: SerializeField] public int Priority { get; private set; }
|
||||
|
||||
public abstract UniTask Apply(ModifierContext context, ModifierInstance instance);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void SetPhaseForTest(ModifierPhase p) => phase = p;
|
||||
public void SetPriorityForTest(int p) => priority = p;
|
||||
public void SetPhaseForTest(ModifierPhase p) => Phase = p;
|
||||
public void SetPriorityForTest(int p) => Priority = p;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ namespace YachtDice.Modifiers.Definition
|
||||
[CreateAssetMenu(fileName = "NewBehavior", menuName = "YachtDice/Modifiers/Behavior")]
|
||||
public class ModifierBehavior : ScriptableObject
|
||||
{
|
||||
[SerializeField] private TriggerType trigger;
|
||||
[field: SerializeField] public TriggerType Trigger { get; private set; }
|
||||
[SerializeField] private List<Condition> conditions = new();
|
||||
[SerializeField] private List<Effect> effects = new();
|
||||
|
||||
public TriggerType Trigger => trigger;
|
||||
public IReadOnlyList<Condition> Conditions => conditions;
|
||||
public IReadOnlyList<Effect> Effects => effects;
|
||||
|
||||
@@ -33,7 +32,7 @@ namespace YachtDice.Modifiers.Definition
|
||||
List<Effect> effects)
|
||||
{
|
||||
var so = CreateInstance<ModifierBehavior>();
|
||||
so.trigger = trigger;
|
||||
so.Trigger = trigger;
|
||||
so.conditions = conditions ?? new List<Condition>();
|
||||
so.effects = effects ?? new List<Effect>();
|
||||
return so;
|
||||
|
||||
@@ -7,35 +7,24 @@ namespace YachtDice.Modifiers.Definition
|
||||
[CreateAssetMenu(fileName = "NewModifier", menuName = "YachtDice/Modifiers/Definition")]
|
||||
public class ModifierDefinition : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField, TextArea] private string description;
|
||||
[SerializeField] private Sprite icon;
|
||||
[SerializeField] private ModifierRarity rarity;
|
||||
[field: Header("Identity")]
|
||||
[field: SerializeField] public string Id { get; private set; }
|
||||
[field: SerializeField] public string DisplayName { get; private set; }
|
||||
[field: SerializeField, TextArea] public string Description { get; private set; }
|
||||
[field: SerializeField] public Sprite Icon { get; private set; }
|
||||
[field: SerializeField] public ModifierRarity Rarity { get; private set; }
|
||||
|
||||
[Header("Economy")]
|
||||
[SerializeField] private int shopPrice;
|
||||
[SerializeField] private int sellPrice;
|
||||
[field: Header("Economy")]
|
||||
[field: SerializeField] public int ShopPrice { get; private set; }
|
||||
[field: SerializeField] public int SellPrice { get; private set; }
|
||||
|
||||
[Header("Durability")]
|
||||
[SerializeField] private bool hasLimitedUses;
|
||||
[SerializeField] private int maxUses;
|
||||
[SerializeField] private int maxStacks = 1;
|
||||
[field: Header("Durability")]
|
||||
[field: SerializeField] public bool HasLimitedUses { get; private set; }
|
||||
[field: SerializeField] public int MaxUses { get; private set; }
|
||||
[field: SerializeField] public int MaxStacks { get; private set; } = 1;
|
||||
|
||||
[Header("Behaviors")]
|
||||
[SerializeField] private List<ModifierBehavior> behaviors = new();
|
||||
|
||||
public string Id => id;
|
||||
public string DisplayName => displayName;
|
||||
public string Description => description;
|
||||
public Sprite Icon => icon;
|
||||
public ModifierRarity Rarity => rarity;
|
||||
public int ShopPrice => shopPrice;
|
||||
public int SellPrice => sellPrice;
|
||||
public bool HasLimitedUses => hasLimitedUses;
|
||||
public int MaxUses => maxUses;
|
||||
public int MaxStacks => maxStacks;
|
||||
public IReadOnlyList<ModifierBehavior> Behaviors => behaviors;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -49,14 +38,14 @@ namespace YachtDice.Modifiers.Definition
|
||||
ModifierRarity rarity = ModifierRarity.Common)
|
||||
{
|
||||
var so = CreateInstance<ModifierDefinition>();
|
||||
so.id = id;
|
||||
so.displayName = id;
|
||||
so.description = id;
|
||||
so.rarity = rarity;
|
||||
so.shopPrice = shopPrice;
|
||||
so.sellPrice = sellPrice;
|
||||
so.hasLimitedUses = hasLimitedUses;
|
||||
so.maxUses = maxUses;
|
||||
so.Id = id;
|
||||
so.DisplayName = id;
|
||||
so.Description = id;
|
||||
so.Rarity = rarity;
|
||||
so.ShopPrice = shopPrice;
|
||||
so.SellPrice = sellPrice;
|
||||
so.HasLimitedUses = hasLimitedUses;
|
||||
so.MaxUses = maxUses;
|
||||
so.behaviors = behaviors ?? new List<ModifierBehavior>();
|
||||
return so;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user