Skip to content

Commit

Permalink
Adding OnBecameDirty event to StatModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Leach committed Jan 31, 2023
1 parent 53da92e commit aad5e27
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Runtime/StatModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ public IStatSet<TKey> BaseStats
set => _baseStats = value;
}

public bool IsDirty { get; private set; }
private bool _dirty = false;
public bool IsDirty
{
get => _dirty;
private set
{
if (_dirty == value)
{
return;
}
_dirty = value;
if (_dirty)
{
OnBecameDirty?.Invoke();
}
}
}

public delegate void StatModelDelegate();

public event StatModelDelegate OnBecameDirty;

protected ListStatSet<TKey> _statTotals = new ListStatSet<TKey>();
public IStatSet<TKey> StatTotals => _statTotals;
Expand Down Expand Up @@ -51,6 +71,19 @@ public virtual void RemoveModifier(IStatModifierSet<TKey> modifierSet)
IsDirty = true;
}

public void ClearModifiers()
{
foreach (var modifierSet in _modifiers)
{
if (modifierSet is INotifyStatModifierSet<TKey> notifySet)
{
notifySet.ModifiersChanged -= NotifySetOnModifiersChanged;
}
}
_modifiers.Clear();
IsDirty = true;
}

private void NotifySetOnModifiersChanged(IStatModifierSet<TKey> set, StatModifierSetChangedArgs<TKey> args)
{
IsDirty = true;
Expand Down

0 comments on commit aad5e27

Please sign in to comment.