Update README.md to include project description, developer documentation links, and license information.
CI / build-test (push) Successful in 1m6s

This commit is contained in:
Leonid Pershin
2026-06-11 04:03:07 +03:00
parent 31aba3aeee
commit ff2231a8ab
72 changed files with 4113 additions and 0 deletions
@@ -0,0 +1,75 @@
using Microsoft.Xna.Framework.Input;
using MrGameEng.Input;
using Xunit;
namespace MrGameEng.Input.Tests;
public class ActionMapTests
{
private enum GameAction
{
Jump,
MoveLeft,
MoveRight,
}
private static void Frame(InputManager input, params Keys[] keys) =>
input.Apply(new KeyboardState(keys), default, GamePadState.Default);
[Fact]
public void IsDown_TrueWhenAnyBindingIsHeld()
{
var input = new InputManager();
var map = new ActionMap<GameAction>(input)
.Bind(GameAction.Jump, Keys.Space)
.Bind(GameAction.Jump, Keys.W);
Frame(input, Keys.W);
Assert.True(map.IsDown(GameAction.Jump));
}
[Fact]
public void IsPressed_EdgeTriggered()
{
var input = new InputManager();
var map = new ActionMap<GameAction>(input).Bind(GameAction.Jump, Keys.Space);
Frame(input, Keys.Space);
Assert.True(map.IsPressed(GameAction.Jump));
Frame(input, Keys.Space);
Assert.False(map.IsPressed(GameAction.Jump));
Assert.True(map.IsDown(GameAction.Jump));
}
[Fact]
public void Unbind_RemovesAllBindings()
{
var input = new InputManager();
var map = new ActionMap<GameAction>(input).Bind(GameAction.Jump, Keys.Space);
map.Unbind(GameAction.Jump);
Frame(input, Keys.Space);
Assert.False(map.IsDown(GameAction.Jump));
}
[Fact]
public void GetAxis_CombinesTwoActions()
{
var input = new InputManager();
var map = new ActionMap<GameAction>(input)
.Bind(GameAction.MoveLeft, Keys.A)
.Bind(GameAction.MoveRight, Keys.D);
Frame(input, Keys.A);
Assert.Equal(-1f, map.GetAxis(GameAction.MoveLeft, GameAction.MoveRight));
Frame(input, Keys.A, Keys.D);
Assert.Equal(0f, map.GetAxis(GameAction.MoveLeft, GameAction.MoveRight));
Frame(input, Keys.D);
Assert.Equal(1f, map.GetAxis(GameAction.MoveLeft, GameAction.MoveRight));
}
}
@@ -0,0 +1,67 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using MrGameEng.Input;
using Xunit;
namespace MrGameEng.Input.Tests;
public class InputManagerTests
{
private static MouseState Mouse(int x = 0, int y = 0, int wheel = 0, ButtonState left = ButtonState.Released) =>
new(x, y, wheel, left, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
private static void Frame(InputManager input, KeyboardState keyboard = default, MouseState mouse = default) =>
input.Apply(keyboard, mouse, GamePadState.Default);
[Fact]
public void KeyPressed_OnlyOnTheFrameItGoesDown()
{
var input = new InputManager();
Frame(input, new KeyboardState(Keys.Space));
Assert.True(input.IsKeyPressed(Keys.Space));
Assert.True(input.IsKeyDown(Keys.Space));
Frame(input, new KeyboardState(Keys.Space));
Assert.False(input.IsKeyPressed(Keys.Space));
Assert.True(input.IsKeyDown(Keys.Space));
}
[Fact]
public void KeyReleased_OnlyOnTheFrameItGoesUp()
{
var input = new InputManager();
Frame(input, new KeyboardState(Keys.A));
Frame(input);
Assert.True(input.IsKeyReleased(Keys.A));
Frame(input);
Assert.False(input.IsKeyReleased(Keys.A));
}
[Fact]
public void MouseDeltaAndWheelDelta_ComputedBetweenFrames()
{
var input = new InputManager();
Frame(input, mouse: Mouse(x: 10, y: 10, wheel: 0));
Frame(input, mouse: Mouse(x: 25, y: 5, wheel: 120));
Assert.Equal(new Point(15, -5), input.MouseDelta);
Assert.Equal(120, input.WheelDelta);
Assert.Equal(new Point(25, 5), input.MousePosition);
}
[Fact]
public void MousePressed_DetectsLeftButtonEdge()
{
var input = new InputManager();
Frame(input, mouse: Mouse());
Frame(input, mouse: Mouse(left: ButtonState.Pressed));
Assert.True(input.IsMousePressed(MouseButton.Left));
Assert.False(input.IsMousePressed(MouseButton.Right));
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MrGameEng.Input\MrGameEng.Input.csproj" />
</ItemGroup>
</Project>