Timescalable components
This commit is contained in:
parent
df940e2ba6
commit
e527d1da44
11 changed files with 83 additions and 24 deletions
|
|
@ -4,6 +4,7 @@ using Newlon.Systems.Effects;
|
|||
|
||||
namespace Newlon.Components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class Entity : Node2D
|
||||
{
|
||||
#region Health points
|
||||
|
|
@ -58,13 +59,13 @@ public partial class Entity : Node2D
|
|||
#endregion
|
||||
#region Effects
|
||||
[Export] private Array<Effect> _effectImmunities = new();
|
||||
private readonly Dictionary<string,Effect> _activeEffectSlots = new();
|
||||
private readonly Dictionary<string,Timer> _effectSlotTimers = new();
|
||||
private readonly Dictionary<string, Effect> _activeEffectSlots = new();
|
||||
private readonly Dictionary<string, Timer> _effectSlotTimers = new();
|
||||
|
||||
[Signal] public delegate void EffectStartedEventHandler(Effect what);
|
||||
[Signal] public delegate void EffectEndedEventHandler(Effect what);
|
||||
[Signal] public delegate void EffectContinuedEventHandler(Effect what);
|
||||
|
||||
|
||||
|
||||
public virtual void GiveEffect(Effect what)
|
||||
{
|
||||
|
|
@ -108,7 +109,7 @@ public partial class Entity : Node2D
|
|||
var timer = new Timer() { Autostart = false, OneShot = true };
|
||||
AddChild(timer);
|
||||
timer.Timeout += () => { EndEffectAtSlot(key); };
|
||||
|
||||
|
||||
_effectSlotTimers.Add(key, timer);
|
||||
|
||||
}
|
||||
|
|
@ -120,7 +121,7 @@ public partial class Entity : Node2D
|
|||
|
||||
public void ProcessEffects()
|
||||
{
|
||||
foreach(string key in _activeEffectSlots.Keys)
|
||||
foreach (string key in _activeEffectSlots.Keys)
|
||||
_activeEffectSlots[key]?.Process(this);
|
||||
}
|
||||
|
||||
|
|
@ -148,8 +149,8 @@ public partial class Entity : Node2D
|
|||
#endregion
|
||||
#region Godot overrides
|
||||
public override void _Ready()
|
||||
{
|
||||
HP = MaxHP;
|
||||
}
|
||||
{
|
||||
HP = MaxHP;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue