Skip to content

Commit

Permalink
Renaming Classes & StatModel Clear
Browse files Browse the repository at this point in the history
Using 'ReadOnly' on interfaces and classes that are immutable instead of 'Mutable' 'Immutable'

StatModel now has ClearModifiers method
  • Loading branch information
Cory Leach committed Jan 31, 2023
1 parent aad5e27 commit c5984e8
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Gameframe.StatSheet
/// Stat modifiers are adds or multipliers that can be applied to a stat sheet
/// </summary>
/// <typeparam name="TKey"></typeparam>
public abstract class BaseStatModifierImmutableSet<TKey> : IStatModifierSet<TKey>
public abstract class BaseReadOnlyStatModifierSet<TKey> : IReadOnlyStatModifierSet<TKey>
{
/// <summary>
/// Get modifier for a given stat type and mode
Expand Down Expand Up @@ -59,4 +59,4 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Gameframe.StatSheet
{
public abstract class BaseStatModifierMutableSet<TKey> : INotifyStatModifierSet<TKey>
public abstract class BaseStatModifierSet<TKey> : INotifyStatModifierSet<TKey>
{
protected abstract IList<IStatModifier<TKey>> GetModifiersList();

Expand Down Expand Up @@ -119,4 +119,4 @@ private void NotifyChanged(StatModifierSetActionType action, IStatModifier<TKey>
});
}
}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions Runtime/INotifyStatModifierSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public struct StatModifierSetChangedArgs<TKey>
public IStatModifier<TKey> Previous;
}

public delegate void StatModifierSetChangedEventHandler<TKey>(IStatModifierSet<TKey> modifierSet, StatModifierSetChangedArgs<TKey> args);
public delegate void StatModifierSetChangedEventHandler<TKey>(IReadOnlyStatModifierSet<TKey> modifierSet, StatModifierSetChangedArgs<TKey> args);

/// <summary>
/// Interface for a mutable set of stat modifiers that provides an event callback to notify when modifiers change
/// </summary>
/// <typeparam name="TKey"></typeparam>
public interface INotifyStatModifierSet<TKey> : IStatModifierMutableSet<TKey>
public interface INotifyStatModifierSet<TKey> : IStatModifierSet<TKey>
{
event StatModifierSetChangedEventHandler<TKey> ModifiersChanged;
}
Expand Down
16 changes: 16 additions & 0 deletions Runtime/IReadOnlyStatModifierSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace Gameframe.StatSheet
{
/// <summary>
/// Enumerable Set of stat modifiers
/// Generic version
/// </summary>
/// <typeparam name="TKey">Stat key type (Usually an enum)</typeparam>
public interface IReadOnlyStatModifierSet<TKey> : IEnumerable<IStatModifier<TKey>>
{
IStatModifier<TKey> Get(TKey statName, StatMode mode);

IEnumerable<IStatModifier<TKey>> Get(StatMode mode);
}
}
3 changes: 3 additions & 0 deletions Runtime/IReadOnlyStatModifierSet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions Runtime/IStatModifierMutableSet.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Runtime/IStatModifierMutableSet.cs.meta

This file was deleted.

15 changes: 6 additions & 9 deletions Runtime/IStatModifierSet.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System.Collections.Generic;

namespace Gameframe.StatSheet
{
/// <summary>
/// Enumerable Set of stat modifiers
/// Generic version
/// Enumerable set of stat modifiers
/// Mutable version
/// </summary>
/// <typeparam name="TKey">Stat key type (Usually an enum)</typeparam>
public interface IStatModifierSet<TKey> : IEnumerable<IStatModifier<TKey>>
/// <typeparam name="TKey"></typeparam>
public interface IStatModifierSet<TKey> : IReadOnlyStatModifierSet<TKey>
{
IStatModifier<TKey> Get(TKey statName, StatMode mode);

IEnumerable<IStatModifier<TKey>> Get(StatMode mode);
void Set(IStatModifier<TKey> modifier);
void Set(TKey statType, float value, StatMode mode);
}
}
4 changes: 2 additions & 2 deletions Runtime/IStatModifierSet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/IStatModifierSetIndexed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Gameframe.StatSheet
/// Indexed set of stat modifiers for easy index enumeration
/// </summary>
/// <typeparam name="TKey">Stat key type (Usually an enum)</typeparam>
public interface IStatModifierSetIndexed<TKey> : IStatModifierSet<TKey>
public interface IStatModifierSetIndexed<TKey> : IReadOnlyStatModifierSet<TKey>
{
int Count { get; }
StatModifier<TKey> GetIndex(int index);
Expand Down
12 changes: 5 additions & 7 deletions Runtime/StatModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,30 @@ private set
protected ListStatSet<TKey> _statTotals = new ListStatSet<TKey>();
public IStatSet<TKey> StatTotals => _statTotals;

protected List<IStatModifierSet<TKey>> _modifiers = new List<IStatModifierSet<TKey>>();
protected List<IReadOnlyStatModifierSet<TKey>> _modifiers = new List<IReadOnlyStatModifierSet<TKey>>();

public virtual void AddModifierSet(IStatModifierSet<TKey> modifierSet)
public virtual void AddModifierSet(IReadOnlyStatModifierSet<TKey> modifierSet)
{
_modifiers.Add(modifierSet);
//If this modifier set is a notify set then subscribe for changes
if (modifierSet is INotifyStatModifierSet<TKey> notifySet)
{
notifySet.ModifiersChanged += NotifySetOnModifiersChanged;
}

IsDirty = true;
}

public virtual void RemoveModifier(IStatModifierSet<TKey> modifierSet)
public virtual void RemoveModifier(IReadOnlyStatModifierSet<TKey> modifierSet)
{
_modifiers.Remove(modifierSet);
if (modifierSet is INotifyStatModifierSet<TKey> notifySet)
{
notifySet.ModifiersChanged -= NotifySetOnModifiersChanged;
}

IsDirty = true;
}

public void ClearModifiers()
public virtual void ClearModifiers()
{
foreach (var modifierSet in _modifiers)
{
Expand All @@ -84,7 +82,7 @@ public void ClearModifiers()
IsDirty = true;
}

private void NotifySetOnModifiersChanged(IStatModifierSet<TKey> set, StatModifierSetChangedArgs<TKey> args)
private void NotifySetOnModifiersChanged(IReadOnlyStatModifierSet<TKey> set, StatModifierSetChangedArgs<TKey> args)
{
IsDirty = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/StatModifierSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Gameframe.StatSheet
/// Mutable set of stat modifiers
/// </summary>
/// <typeparam name="TKey">Stat key type</typeparam>
public class StatModifierSet<TKey> : BaseStatModifierMutableSet<TKey>
public class StatModifierSet<TKey> : BaseStatModifierSet<TKey>
{
private List<IStatModifier<TKey>> _mods = new List<IStatModifier<TKey>>();

Expand Down

0 comments on commit c5984e8

Please sign in to comment.