Simplified actor modules

This commit is contained in:
Marco 2025-02-20 18:26:53 +01:00
commit a7f4f4eb28
8 changed files with 57 additions and 34 deletions

View file

@ -14,40 +14,35 @@ public partial class Actor : CharacterBody2D
private GameManager _gameManager;
private List<MovementHandler> _movementHandlers = new();
private List<AnimationHandler> _animationHandlers = new();
private List<ActorModule> _modules = new();
public override void _Ready()
{
_gameManager = this.GetGameManager();
var children = GetChildren();
foreach (var child in children) {
if (child is MovementHandler movementHandler)
{
_movementHandlers.Add(movementHandler);
movementHandler.Init(this);
}
else if (child is AnimationHandler animationHandler)
{
_animationHandlers.Add(animationHandler);
animationHandler.Init(this);
}
foreach (var child in children)
{
if (child is not ActorModule actorModule) continue;
_modules.Add(actorModule);
actorModule.Init(this);
}
}
public override void _PhysicsProcess(double delta)
public override void _Process(double delta)
{
foreach (var handler in _movementHandlers)
{
handler.Move(delta);
}
foreach (var handler in _animationHandlers)
foreach (var handler in _modules)
{
handler.Update(delta);
}
}
public override void _PhysicsProcess(double delta)
{
foreach (var handler in _modules)
{
handler.PhysicsUpdate(delta);
}
}
}