ported from perforce
This commit is contained in:
48
RobotAndDonkey.Game/Modifiers/Entity.cs
Normal file
48
RobotAndDonkey.Game/Modifiers/Entity.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using RobotAndDonkey.Game.Intents;
|
||||
|
||||
namespace RobotAndDonkey.Game.Modifiers;
|
||||
|
||||
public record Entity()
|
||||
{
|
||||
protected Entity(Entity clone)
|
||||
{
|
||||
m_Modifiers = [];
|
||||
foreach (var modifier in clone.Modifiers)
|
||||
AddModifier(modifier.DeepClone(), []);
|
||||
}
|
||||
|
||||
public void InsertModifier(Modifier modifier, List<Intent> newIntents)
|
||||
{
|
||||
if (m_Modifiers.Any(m => m.Id == modifier.Id))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
m_Modifiers.Insert(0, modifier);
|
||||
modifier.OnAdded(this, newIntents);
|
||||
}
|
||||
|
||||
public void AddModifier(Modifier modifier, List<Intent> newIntents)
|
||||
{
|
||||
if (m_Modifiers.Any(m => m.Id == modifier.Id))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
m_Modifiers.Add(modifier);
|
||||
modifier.OnAdded(this, newIntents);
|
||||
}
|
||||
|
||||
public void RemoveModifier(Modifier modifier, List<Intent> newIntents)
|
||||
{
|
||||
if (!m_Modifiers.Remove(modifier))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
modifier.OnRemoved(this, newIntents);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "[" + string.Join(", ", m_Modifiers) + "]";
|
||||
}
|
||||
|
||||
public IReadOnlyList<Modifier> Modifiers => m_Modifiers;
|
||||
|
||||
private readonly List<Modifier> m_Modifiers = [];
|
||||
}
|
||||
Reference in New Issue
Block a user