Add new methods to input handler, add RectangleShape2d, modify test game.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using DaggerFramework.Utils;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
@@ -7,16 +9,20 @@ namespace DaggerFramework
|
||||
public InputHandler()
|
||||
{
|
||||
inputMappings = new Dictionary<string, IEnumerable<InputAction>>();
|
||||
CreateDefaultMappings();
|
||||
}
|
||||
public Action OnInput;
|
||||
public bool Handled { get => _handled; set => _handled = value; }
|
||||
public abstract bool IsKeyboardKeyDown(KeyboardKey key);
|
||||
public abstract bool KeyboardKeyJustPressed(KeyboardKey key);
|
||||
public abstract bool KeyboardKeyJustReleased(KeyboardKey key);
|
||||
public abstract Vector2 GetInputDirection(KeyboardKey leftKey, KeyboardKey rightKey, KeyboardKey upKey, KeyboardKey downKey);
|
||||
public abstract Vector2 GetInputDirection(string leftAction, string rightAction, string upAction, string downAction);
|
||||
public abstract int GetCharPressed();
|
||||
|
||||
public abstract bool IsActionDown(string action);
|
||||
public abstract bool IsActionJustPressed(string action);
|
||||
public abstract bool IsActionPressed(string action);
|
||||
public abstract bool IsActionReleased(string action);
|
||||
|
||||
public abstract bool IsMouseButtonDown(MouseButton button);
|
||||
public abstract float GetMouseWheelMovement();
|
||||
@@ -33,8 +39,46 @@ namespace DaggerFramework
|
||||
inputMappings.Add(actionName, inputActions);
|
||||
}
|
||||
|
||||
private void CreateDefaultMappings()
|
||||
{
|
||||
AddInputMapping("up", new InputAction[] {
|
||||
new KeyInputAction(KeyboardKey.W),
|
||||
new KeyInputAction(KeyboardKey.Up),
|
||||
});
|
||||
AddInputMapping("down", new InputAction[] {
|
||||
new KeyInputAction(KeyboardKey.S),
|
||||
new KeyInputAction(KeyboardKey.Down),
|
||||
});
|
||||
AddInputMapping("left", new InputAction[] {
|
||||
new KeyInputAction(KeyboardKey.A),
|
||||
new KeyInputAction(KeyboardKey.Left),
|
||||
});
|
||||
AddInputMapping("right", new InputAction[] {
|
||||
new KeyInputAction(KeyboardKey.D),
|
||||
new KeyInputAction(KeyboardKey.Right),
|
||||
});
|
||||
}
|
||||
|
||||
protected bool TryGetInputMappings(string forAction, [NotNullWhen(true)] out IEnumerable<InputAction>? inputActions)
|
||||
{
|
||||
var contains = inputMappings.ContainsKey(forAction);
|
||||
inputActions = null;
|
||||
|
||||
if (!contains)
|
||||
{
|
||||
_logger.Error($"The action \"{forAction}\" is not present in the input mappings!");
|
||||
return false;
|
||||
}
|
||||
|
||||
inputActions = inputMappings[forAction];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool _handled;
|
||||
protected Dictionary<string, IEnumerable<InputAction>> inputMappings;
|
||||
|
||||
private Logger _logger = new(nameof(InputHandler));
|
||||
}
|
||||
|
||||
public enum KeyboardKey
|
||||
|
||||
Reference in New Issue
Block a user