CI / build-test (push) Successful in 1m24s
Core now depends only on Friflo.Engine.ECS — no MonoGame, no platform. The windowed MonoGame host moves to the new MrGameEng.Host library: GameHost, GameHostOptions, visual scene transitions (OverlayTransition, Transitions.Fade/Wipe, TransitionRenderer) and the Input feature (namespace MrGameEng.Input is unchanged). Transition timing stays in Core (SceneManager exposes ActiveTransition/TransitionCoverage/ TransitionPhase; the host draws the overlay). EngineContext loses its GraphicsDevice property: hosts publish the device as a service and graphics code reads it via context.GetGraphicsDevice() in Graphics. Core gains HeadlessHost: a fixed-timestep loop without a window or GPU (Tick/RunTicks, Run with wall-clock pacing and lag resync) for dedicated servers, batch simulation and tests. Graphics and Audio now carry their own MonoGame.Framework.DesktopGL reference instead of inheriting it from Core. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
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));
|
|
}
|
|
}
|