BREAKING CHANGE: Removed MonoGame Package
This commit is contained in:
parent
de10a859ae
commit
8cffc43f23
|
@ -0,0 +1,14 @@
|
||||||
|
using Syntriax.Engine.Core.Abstract;
|
||||||
|
|
||||||
|
namespace Syntriax.Engine.Input;
|
||||||
|
|
||||||
|
public interface IButtonInputs<T> : IAssignableStateEnable
|
||||||
|
{
|
||||||
|
void RegisterOnPress(T button, Action<IButtonInputs<T>, T> callback);
|
||||||
|
void UnregisterOnPress(T button, Action<IButtonInputs<T>, T> callback);
|
||||||
|
void RegisterOnRelease(T button, Action<IButtonInputs<T>, T> callback);
|
||||||
|
void UnregisterOnRelease(T button, Action<IButtonInputs<T>, T> callback);
|
||||||
|
|
||||||
|
bool IsPressed(T button);
|
||||||
|
bool WasPressed(T button);
|
||||||
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
|
|
||||||
using Syntriax.Engine.Core.Abstract;
|
|
||||||
|
|
||||||
namespace Syntriax.Engine.Input;
|
|
||||||
|
|
||||||
public interface IKeyboardInputs : IAssignableStateEnable
|
|
||||||
{
|
|
||||||
void RegisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback);
|
|
||||||
void UnregisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback);
|
|
||||||
void RegisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback);
|
|
||||||
void UnregisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback);
|
|
||||||
|
|
||||||
bool IsPressed(Keys key);
|
|
||||||
bool WasPressed(Keys key);
|
|
||||||
}
|
|
|
@ -6,10 +6,6 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
|
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
|
|
||||||
using Syntriax.Engine.Core;
|
|
||||||
|
|
||||||
namespace Syntriax.Engine.Input;
|
|
||||||
|
|
||||||
public class KeyboardInputsBehaviour : BehaviourOverride, IKeyboardInputs
|
|
||||||
{
|
|
||||||
private readonly Dictionary<Keys, Action<IKeyboardInputs, Keys>> OnPressed = new(256);
|
|
||||||
private readonly Dictionary<Keys, Action<IKeyboardInputs, Keys>> OnReleased = new(256);
|
|
||||||
|
|
||||||
private int cachePressedCurrentlyCount = 0;
|
|
||||||
private readonly Keys[] cachePressedCurrently = new Keys[256];
|
|
||||||
|
|
||||||
private int cachePressedPreviouslyCount = 0;
|
|
||||||
private readonly Keys[] cachePressedPreviously = new Keys[256];
|
|
||||||
|
|
||||||
public void RegisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback)
|
|
||||||
{
|
|
||||||
if (OnPressed.TryGetValue(key, out var action))
|
|
||||||
{
|
|
||||||
action += callback;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnPressed.Add(key, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnregisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback)
|
|
||||||
{
|
|
||||||
if (OnPressed.TryGetValue(key, out var action))
|
|
||||||
action -= callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback)
|
|
||||||
{
|
|
||||||
if (OnReleased.TryGetValue(key, out var action))
|
|
||||||
{
|
|
||||||
action += callback;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnReleased.Add(key, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnregisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback)
|
|
||||||
{
|
|
||||||
if (OnReleased.TryGetValue(key, out var action))
|
|
||||||
action -= callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnUpdate(GameTime time)
|
|
||||||
{
|
|
||||||
KeyboardState keyboardState = Keyboard.GetState();
|
|
||||||
keyboardState.GetPressedKeys(cachePressedCurrently);
|
|
||||||
cachePressedCurrentlyCount = keyboardState.GetPressedKeyCount();
|
|
||||||
|
|
||||||
for (int i = 0; i < cachePressedCurrentlyCount; i++)
|
|
||||||
{
|
|
||||||
Keys currentlyPressedKey = cachePressedCurrently[i];
|
|
||||||
|
|
||||||
if (!OnPressed.TryGetValue(currentlyPressedKey, out var action))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (WasPressed(currentlyPressedKey))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
action.Invoke(this, currentlyPressedKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < cachePressedPreviouslyCount; i++)
|
|
||||||
{
|
|
||||||
Keys previouslyPressedKey = cachePressedPreviously[i];
|
|
||||||
|
|
||||||
if (!OnReleased.TryGetValue(previouslyPressedKey, out var action))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (IsPressed(previouslyPressedKey))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
action.Invoke(this, previouslyPressedKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount);
|
|
||||||
cachePressedPreviouslyCount = cachePressedCurrentlyCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsPressed(Keys key)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < cachePressedCurrentlyCount; i++)
|
|
||||||
if (cachePressedCurrently[i] == key)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool WasPressed(Keys key)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < cachePressedPreviouslyCount; i++)
|
|
||||||
if (cachePressedPreviously[i] == key)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue