48 lines
1.2 KiB
C#
48 lines
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));
|
|||
|
}
|
|||
|
}
|