Skip to content

Commit

Permalink
New event added
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitebrim committed Aug 17, 2022
1 parent 12e948f commit 3fdd558
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 12 additions & 9 deletions Runtime/Wallet/CurrencyAccount.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Security.Cryptography;

namespace CurrencySystem
{
Expand All @@ -10,16 +9,26 @@ public sealed class CurrencyAccount : ICurrency
private float _multiplier = 1;
private IVault _vault;

/// <summary>
/// Передает общее кол-во денег на счету
/// </summary>
[field: NonSerialized]
public event ICurrency.CurrencyEvent OnCurrencyChange;

public event ICurrency.CurrencyEvent OnNewAmount;
/// <summary>
/// Передает сумму, на которую счет изменился
/// </summary>
[field: NonSerialized]
public event ICurrency.CurrencyEvent OnChange;

private double Amount
{
get { return _vault.Amount; }
set
{
OnChange?.Invoke(value - _vault.Amount);
_vault.Amount = value;
NotifyEvent();
OnNewAmount?.Invoke(value);
}
}

Expand All @@ -35,12 +44,6 @@ public CurrencyAccount(string currencyCode, double amount, float multiplier = 1)
_vault = new Vault(amount, currencyCode);
}

private void NotifyEvent()
{
Aes.Create();
OnCurrencyChange?.Invoke(Amount);
}

public void Add(double amount)
{
Amount += amount * _multiplier;
Expand Down
5 changes: 3 additions & 2 deletions Runtime/Wallet/ICurrency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ namespace CurrencySystem
{
public interface ICurrency
{
delegate void CurrencyEvent(double newAmount);
event CurrencyEvent OnCurrencyChange;
delegate void CurrencyEvent(double amount);
event CurrencyEvent OnNewAmount;
event CurrencyEvent OnChange;
public string CurrencyCode { get; }
public double Get();
public void Add(double amount);
Expand Down

0 comments on commit 3fdd558

Please sign in to comment.