cirnogodot/Scripts/Components/Actors/MovementHandler.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2025-02-18 17:40:33 +01:00
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Components.Actors;
2025-02-17 21:53:05 +01:00
using Godot;
2025-02-20 18:26:53 +01:00
public abstract partial class MovementHandler : ActorModule
2025-02-17 21:53:05 +01:00
{
2025-02-18 17:40:33 +01:00
protected Actor _parent;
public abstract Vector2 MovementDirection { get; set; }
public abstract Vector2 FacingDirection { get; set; }
2025-02-17 21:53:05 +01:00
2025-02-18 17:40:33 +01:00
protected readonly List<InputProvider> _inputProviders = new();
2025-02-20 18:26:53 +01:00
public override void Init(Actor parent)
2025-02-18 17:40:33 +01:00
{
_parent = parent;
var children = GetChildren();
foreach (var child in children) {
if (child is InputProvider inputProvider)
{
_inputProviders.Add(inputProvider);
}
}
}
public virtual Vector2 AggregateInputProviders()
{
2025-02-18 18:18:13 +01:00
return _inputProviders.Aggregate(Vector2.Zero, (current, inputProvider) => current + inputProvider.GetMovementInput());
}
public virtual Vector2 GetAimingDirection()
{
return _inputProviders.Aggregate(Vector2.Zero, (current, inputProvider) => current + inputProvider.GetAimInput());
}
public virtual bool GetStrafing()
{
return _inputProviders.Aggregate(false, (current, inputProvider) => current && inputProvider.GetStrafing());
2025-02-18 17:40:33 +01:00
}
2025-02-17 21:53:05 +01:00
}