[Refactor] Replace [SerializeField] + getter with [field: SerializeField] auto-properties
This commit is contained in:
@@ -6,11 +6,11 @@ namespace YachtDice.Dice
|
||||
[CreateAssetMenu(fileName = "DiceCatalog", menuName = "YachtDice/Dice/Catalog")]
|
||||
public class DiceCatalog : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<DieDefinitionSO> dice = new();
|
||||
[SerializeField] private List<DiсeDefinition> dice = new();
|
||||
|
||||
public IReadOnlyList<DieDefinitionSO> All => dice;
|
||||
public IReadOnlyList<DiсeDefinition> All => dice;
|
||||
|
||||
public DieDefinitionSO FindById(string id)
|
||||
public DiсeDefinition FindById(string id)
|
||||
{
|
||||
for (int i = 0; i < dice.Count; i++)
|
||||
{
|
||||
@@ -21,10 +21,10 @@ namespace YachtDice.Dice
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static DiceCatalog CreateForTest(List<DieDefinitionSO> defs)
|
||||
public static DiceCatalog CreateForTest(List<DiсeDefinition> defs)
|
||||
{
|
||||
var catalog = CreateInstance<DiceCatalog>();
|
||||
catalog.dice = defs ?? new List<DieDefinitionSO>();
|
||||
catalog.dice = defs ?? new List<DiсeDefinition>();
|
||||
return catalog;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace YachtDice.Dice
|
||||
[Header("References")]
|
||||
[SerializeField] private Dice dice;
|
||||
[SerializeField] private Rigidbody rb;
|
||||
[SerializeField] private DieDefinitionSO definition;
|
||||
[SerializeField] private DiсeDefinition definition;
|
||||
|
||||
/// <summary>Определение типа дайса (назначается в инспекторе).</summary>
|
||||
public DieDefinitionSO Definition => definition;
|
||||
public DiсeDefinition Definition => definition;
|
||||
|
||||
[Header("Throw Settings")]
|
||||
[Tooltip("Сила подброса вверх")]
|
||||
|
||||
@@ -6,18 +6,18 @@ namespace YachtDice.Dice
|
||||
/// </summary>
|
||||
public class DieInstance : IDie
|
||||
{
|
||||
public DieDefinitionSO Definition { get; }
|
||||
public DiсeDefinition Definition { get; }
|
||||
public int Value { get; set; }
|
||||
public bool IsLocked { get; set; }
|
||||
|
||||
public DieInstance(DieDefinitionSO definition)
|
||||
public DieInstance(DiсeDefinition definition)
|
||||
{
|
||||
Definition = definition;
|
||||
Value = 0;
|
||||
IsLocked = false;
|
||||
}
|
||||
|
||||
public DieInstance(DieDefinitionSO definition, int initialValue)
|
||||
public DieInstance(DiсeDefinition definition, int initialValue)
|
||||
{
|
||||
Definition = definition;
|
||||
Value = initialValue;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YachtDice.Dice
|
||||
/// Абстрактное определение типа дайса.
|
||||
/// Наследники описывают конкретные виды (стандартный d6, специальные и т.д.).
|
||||
/// </summary>
|
||||
public abstract class DieDefinitionSO : ScriptableObject, IShopItem
|
||||
public abstract class DiсeDefinition : ScriptableObject, IShopItem
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
@@ -33,7 +33,7 @@ namespace YachtDice.Dice
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static T CreateForTest<T>(string id, string displayName = null,
|
||||
int shopPrice = 0, string description = null) where T : DieDefinitionSO
|
||||
int shopPrice = 0, string description = null) where T : DiсeDefinition
|
||||
{
|
||||
var so = CreateInstance<T>();
|
||||
so.id = id;
|
||||
@@ -10,6 +10,6 @@ namespace YachtDice.Dice
|
||||
int Value { get; }
|
||||
|
||||
/// <summary>Определение типа дайса (ScriptableObject).</summary>
|
||||
DieDefinitionSO Definition { get; }
|
||||
DiсeDefinition Definition { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YachtDice.Dice
|
||||
/// По умолчанию — классический d6 (1-6).
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "StandardDie", menuName = "YachtDice/Dice/Standard Die")]
|
||||
public class StandardDieSO : DieDefinitionSO
|
||||
public class StandardDiсe : DiсeDefinition
|
||||
{
|
||||
[Header("Configuration")]
|
||||
[SerializeField] private int[] faceValues = { 1, 2, 3, 4, 5, 6 };
|
||||
@@ -22,9 +22,9 @@ namespace YachtDice.Dice
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static StandardDieSO CreateStandardD6ForTest()
|
||||
public static StandardDiсe CreateStandardD6ForTest()
|
||||
{
|
||||
var so = CreateForTest<StandardDieSO>("standard_d6", "Стандартный d6");
|
||||
var so = CreateForTest<StandardDiсe>("standard_d6", "Стандартный d6");
|
||||
so.faceValues = new[] { 1, 2, 3, 4, 5, 6 };
|
||||
return so;
|
||||
}
|
||||
@@ -6,13 +6,13 @@ namespace YachtDice.Player
|
||||
{
|
||||
public class DiceCollection
|
||||
{
|
||||
private readonly List<DieDefinitionSO> ownedDice = new();
|
||||
private readonly List<DiсeDefinition> ownedDice = new();
|
||||
|
||||
public event Action OnChanged;
|
||||
|
||||
public IReadOnlyList<DieDefinitionSO> OwnedDice => ownedDice;
|
||||
public IReadOnlyList<DiсeDefinition> OwnedDice => ownedDice;
|
||||
|
||||
public void Add(DieDefinitionSO definition)
|
||||
public void Add(DiсeDefinition definition)
|
||||
{
|
||||
if (definition == null) return;
|
||||
if (OwnsById(definition.Id)) return;
|
||||
@@ -21,7 +21,7 @@ namespace YachtDice.Player
|
||||
OnChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void Remove(DieDefinitionSO definition)
|
||||
public void Remove(DiсeDefinition definition)
|
||||
{
|
||||
if (ownedDice.Remove(definition))
|
||||
OnChanged?.Invoke();
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace YachtDice.Shop
|
||||
case ModifierDefinition modifier:
|
||||
inventoryModel.AddModifier(modifier);
|
||||
break;
|
||||
case DieDefinitionSO die:
|
||||
case DiсeDefinition die:
|
||||
diceCollection.Add(die);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void Add_IncreasesCount()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void Add_DuplicateId_Ignored()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
collection.Add(die);
|
||||
@@ -47,7 +47,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void OwnsById_ReturnsTrueWhenOwned()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void Remove_DecreasesCount()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
collection.Remove(die);
|
||||
@@ -74,7 +74,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void GetSaveData_ReturnsIds()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
|
||||
@@ -86,8 +86,8 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void LoadSaveData_RestoresDice()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var catalog = DiceCatalog.CreateForTest(new List<DieDefinitionSO> { die });
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
var catalog = DiceCatalog.CreateForTest(new List<DiсeDefinition> { die });
|
||||
var ids = new List<string> { "standard_d6" };
|
||||
|
||||
collection.LoadSaveData(ids, catalog);
|
||||
@@ -99,7 +99,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void LoadSaveData_SkipsMissingIds()
|
||||
{
|
||||
var catalog = DiceCatalog.CreateForTest(new List<DieDefinitionSO>());
|
||||
var catalog = DiceCatalog.CreateForTest(new List<DiсeDefinition>());
|
||||
var ids = new List<string> { "nonexistent" };
|
||||
|
||||
collection.LoadSaveData(ids, catalog);
|
||||
@@ -110,7 +110,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void Clear_RemovesAll()
|
||||
{
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
|
||||
collection.Add(die);
|
||||
collection.Clear();
|
||||
@@ -124,7 +124,7 @@ namespace YachtDice.Tests
|
||||
bool fired = false;
|
||||
collection.OnChanged += () => fired = true;
|
||||
|
||||
var die = StandardDieSO.CreateStandardD6ForTest();
|
||||
var die = StandardDiсe.CreateStandardD6ForTest();
|
||||
collection.Add(die);
|
||||
|
||||
Assert.IsTrue(fired);
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace YachtDice.Tests
|
||||
private CategoryDefinition twosCategory;
|
||||
private CategoryDefinition chanceCategory;
|
||||
private CategoryCatalog catalog;
|
||||
private DieDefinitionSO standardDie;
|
||||
private DiсeDefinition _standardDiсe;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
standardDie = DieDefinitionSO.CreateForTest<StandardDieSO>("d6", "d6");
|
||||
_standardDiсe = DiсeDefinition.CreateForTest<StandardDiсe>("d6", "d6");
|
||||
|
||||
yachtCategory = NOfAKindCategory.CreateForTest("yacht", "Яхта", 5, fixedScoreMode: true, score: 50);
|
||||
onesCategory = SumOfValueCategory.CreateForTest("ones", "Единицы", 1);
|
||||
@@ -43,7 +43,7 @@ namespace YachtDice.Tests
|
||||
Object.DestroyImmediate(twosCategory);
|
||||
Object.DestroyImmediate(chanceCategory);
|
||||
Object.DestroyImmediate(catalog);
|
||||
Object.DestroyImmediate(standardDie);
|
||||
Object.DestroyImmediate(_standardDiсe);
|
||||
}
|
||||
|
||||
private ScoringSystem CreateScoringSystem()
|
||||
@@ -56,7 +56,7 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var dice = new DieInstance[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
dice[i] = new DieInstance(standardDie, values[i]);
|
||||
dice[i] = new DieInstance(_standardDiсe, values[i]);
|
||||
return dice;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void TryPurchase_DieItem_AddsToDiceCollection()
|
||||
{
|
||||
var die = DieDefinitionSO.CreateForTest<StandardDieSO>("test_die", shopPrice: 100);
|
||||
var die = DiсeDefinition.CreateForTest<StandardDiсe>("test_die", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(die);
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void TryPurchase_DieItem_CannotBeBoughtTwice()
|
||||
{
|
||||
var die = DieDefinitionSO.CreateForTest<StandardDieSO>("unique_die", shopPrice: 100);
|
||||
var die = DiсeDefinition.CreateForTest<StandardDiсe>("unique_die", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(die);
|
||||
bool secondResult = shop.TryPurchase(die);
|
||||
@@ -167,7 +167,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void GetItemState_Die_Owned_AfterPurchase()
|
||||
{
|
||||
var die = DieDefinitionSO.CreateForTest<StandardDieSO>("die1", shopPrice: 50);
|
||||
var die = DiсeDefinition.CreateForTest<StandardDiсe>("die1", shopPrice: 50);
|
||||
|
||||
shop.TryPurchase(die);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user