[Add] Dice & Refactor private names

This commit is contained in:
2026-03-02 11:22:01 +07:00
parent 4890fa946e
commit f65976796d
36 changed files with 883 additions and 489 deletions
+11 -11
View File
@@ -6,32 +6,32 @@ namespace YachtDice.Player
{
public class DiceCollection
{
private readonly List<DiceDefinition> ownedDice = new();
private readonly List<DiceDefinition> _ownedDice = new();
public event Action OnChanged;
public IReadOnlyList<DiceDefinition> OwnedDice => ownedDice;
public IReadOnlyList<DiceDefinition> OwnedDice => _ownedDice;
public void Add(DiceDefinition definition)
{
if (definition == null) return;
if (OwnsById(definition.Id)) return;
ownedDice.Add(definition);
_ownedDice.Add(definition);
OnChanged?.Invoke();
}
public void Remove(DiceDefinition definition)
{
if (ownedDice.Remove(definition))
if (_ownedDice.Remove(definition))
OnChanged?.Invoke();
}
public bool OwnsById(string id)
{
for (int i = 0; i < ownedDice.Count; i++)
for (int i = 0; i < _ownedDice.Count; i++)
{
if (ownedDice[i] != null && ownedDice[i].Id == id)
if (_ownedDice[i] != null && _ownedDice[i].Id == id)
return true;
}
return false;
@@ -40,14 +40,14 @@ namespace YachtDice.Player
public List<string> GetSaveData()
{
var ids = new List<string>();
for (int i = 0; i < ownedDice.Count; i++)
ids.Add(ownedDice[i].Id);
for (int i = 0; i < _ownedDice.Count; i++)
ids.Add(_ownedDice[i].Id);
return ids;
}
public void LoadSaveData(List<string> diceIds, DiceCatalog catalog)
{
ownedDice.Clear();
_ownedDice.Clear();
if (diceIds == null)
{
@@ -59,7 +59,7 @@ namespace YachtDice.Player
{
var def = catalog.FindById(diceIds[i]);
if (def != null)
ownedDice.Add(def);
_ownedDice.Add(def);
}
OnChanged?.Invoke();
@@ -67,7 +67,7 @@ namespace YachtDice.Player
public void Clear()
{
ownedDice.Clear();
_ownedDice.Clear();
OnChanged?.Invoke();
}
}