mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
44 lines
No EOL
1.2 KiB
C#
44 lines
No EOL
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cirno.Scripts.Components.Actors;
|
|
using Godot;
|
|
|
|
public abstract partial class MovementHandler : ActorModule
|
|
{
|
|
protected Actor _parent;
|
|
|
|
public abstract Vector2 MovementDirection { get; set; }
|
|
|
|
public abstract Vector2 FacingDirection { get; set; }
|
|
|
|
protected readonly List<InputProvider> _inputProviders = new();
|
|
|
|
public override void Init(Actor parent)
|
|
{
|
|
_parent = parent;
|
|
|
|
var children = GetChildren();
|
|
foreach (var child in children) {
|
|
if (child is InputProvider inputProvider)
|
|
{
|
|
_inputProviders.Add(inputProvider);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual Vector2 AggregateInputProviders()
|
|
{
|
|
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());
|
|
}
|
|
|
|
} |