carotrauma/scripts/libs/input/IInputProvider.cs
Nick Guy c98d7739aa
All checks were successful
/ build (push) Successful in 1m32s
Add custom input mapping on top of Godot's InputMap
2024-06-02 17:10:15 +01:00

48 lines
No EOL
1.2 KiB
C#

using System;
using System.Collections.Generic;
using Godot;
namespace Carotrauma.scripts.libs.input;
public interface IInputProvider {
void CreateInputs();
List<InputAction> Actions { get; }
}
public static class IInputProviderExtensions {
public static KeyInputAction KeyInput(this IInputProvider self, Key key) {
var A = new KeyInputAction
{
Key = key
};
self.Actions.Add(A);
return A;
}
public static MouseButtonInputAction MouseButtonInput(this IInputProvider self, MouseButton button) {
var A = new MouseButtonInputAction
{
Button = button
};
self.Actions.Add(A);
return A;
}
public static AxisInputAction AxisKeyInput(this IInputProvider self, Key axisPos,
Key axisNeg) {
var pos = self.KeyInput(axisPos);
var neg = self.KeyInput(axisNeg);
return new AxisInputAction(pos.Name, neg.Name);
}
public static VectorInputAction VectorKeyInput(this IInputProvider self, Key xPos,
Key xNeg, Key yPos, Key yNeg) {
return new VectorInputAction(self.KeyInput(xPos), self.KeyInput(xNeg), self.KeyInput(yPos), self.KeyInput(yNeg));
}
}