mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
49 lines
No EOL
1.5 KiB
C#
49 lines
No EOL
1.5 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 GetActionJustPressed(string action)
|
|
{
|
|
return _inputProviders.Aggregate(false, (current, inputProvider) => current || inputProvider.GetActionJustPressed(action));
|
|
}
|
|
|
|
public virtual bool GetActionPressed(string action)
|
|
{
|
|
return _inputProviders.Aggregate(false, (current, inputProvider) => current || inputProvider.GetActionPressed(action));
|
|
}
|
|
|
|
} |