Remove obsolete project files for MrGameEng.AI, MrGameEng.Assets, MrGameEng.Atlases, and MrGameEng.Collisions modules. Introduce new AssetManager and related classes for asset loading and management, including support for texture atlases and mod definitions. Enhance mod loading capabilities with DefDatabase and LanguageManager for JSON-based definitions and localization. Implement a shelf packing algorithm for efficient texture atlas creation.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user