[Fix] Refactor project

This commit is contained in:
2026-03-02 12:49:12 +07:00
parent f65976796d
commit f52131f755
44 changed files with 449 additions and 404 deletions
+10 -12
View File
@@ -7,41 +7,39 @@ namespace YachtDice.Economy
{
[SerializeField] private int startingBalance = 500;
private int _balance;
public int Balance => _balance;
public int Balance { get; private set; }
public event Action<int> OnBalanceChanged;
private void Awake()
{
_balance = startingBalance;
Balance = startingBalance;
}
public void Add(int amount)
{
if (amount <= 0) return;
_balance += amount;
OnBalanceChanged?.Invoke(_balance);
Balance += amount;
OnBalanceChanged?.Invoke(Balance);
}
public bool Spend(int amount)
{
if (amount <= 0) return false;
if (_balance < amount) return false;
if (Balance < amount) return false;
_balance -= amount;
OnBalanceChanged?.Invoke(_balance);
Balance -= amount;
OnBalanceChanged?.Invoke(Balance);
return true;
}
public bool CanAfford(int amount) => _balance >= amount;
public bool CanAfford(int amount) => Balance >= amount;
public void SetBalance(int value)
{
_balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(_balance);
Balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(Balance);
}
}
}