Skip to content

Commit

Permalink
Update legacy input VIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Aug 14, 2024
1 parent 16d3a24 commit 6abd3bd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions Hypercube.Client/ClientConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public static class ClientConstants
{
public static bool MultiThreadingWindow = false;

}
16 changes: 8 additions & 8 deletions Hypercube.Client/Graphics/Viewports/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ public void UpdateInput(ICamera? camera, float delta)

var speed = 60f;

if (_inputHandler.IsKeyDown(Key.W))
if (_inputHandler.IsKeyHeld(Key.W))
position += Vector3.UnitY * speed * delta;

if (_inputHandler.IsKeyDown(Key.S))
if (_inputHandler.IsKeyHeld(Key.S))
position -= Vector3.UnitY * speed * delta;

if (_inputHandler.IsKeyDown(Key.A))
if (_inputHandler.IsKeyHeld(Key.A))
position -= Vector3.UnitX * speed * delta;

if (_inputHandler.IsKeyDown(Key.D))
if (_inputHandler.IsKeyHeld(Key.D))
position += Vector3.UnitX * speed * delta;

if (_inputHandler.IsKeyDown(Key.Q))
if (_inputHandler.IsKeyHeld(Key.Q))
rotation -= Vector3.UnitZ * delta;

if (_inputHandler.IsKeyDown(Key.E))
if (_inputHandler.IsKeyHeld(Key.E))
rotation += Vector3.UnitZ * delta;

if (_inputHandler.IsKeyDown(Key.T))
if (_inputHandler.IsKeyHeld(Key.T))
scale -= Vector3.One * delta;

if (_inputHandler.IsKeyDown(Key.Y))
if (_inputHandler.IsKeyHeld(Key.Y))
scale += Vector3.One * delta;

camera.SetPosition(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ private static KeyState Convert(InputAction action)
return action switch
{
InputAction.Release => KeyState.Release,
InputAction.Press => KeyState.Press,
InputAction.Repeat => KeyState.Repeat,
InputAction.Press => KeyState.Pressed,
InputAction.Repeat => KeyState.Held,
_ => throw new ArgumentOutOfRangeException()
};
}
Expand Down
6 changes: 5 additions & 1 deletion Hypercube.Client/Input/Handler/IInputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ namespace Hypercube.Client.Input.Handler;
/// </summary>
public interface IInputHandler : IEventSubscriber
{
bool IsKeyDown(Key key);
bool IsKeyState(Key key, KeyState state);
bool IsKeyHeld(Key key);
bool IsKeyPressed(Key key);
bool IsKeyReleased(Key key);
void KeyClear();
}
4 changes: 2 additions & 2 deletions Hypercube.Example.Client/Controls/ControlsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public override void FrameUpdate(UpdateFrameEvent args)
{
base.FrameUpdate(args);

var inputX = (_inputHandler.IsKeyDown(Key.D) ? 1 : 0) - (_inputHandler.IsKeyDown(Key.A) ? 1 : 0);
var inputY = (_inputHandler.IsKeyDown(Key.W) ? 1 : 0) - (_inputHandler.IsKeyDown(Key.S) ? 1 : 0);
var inputX = (_inputHandler.IsKeyHeld(Key.D) ? 1 : 0) - (_inputHandler.IsKeyHeld(Key.A) ? 1 : 0);
var inputY = (_inputHandler.IsKeyHeld(Key.W) ? 1 : 0) - (_inputHandler.IsKeyHeld(Key.S) ? 1 : 0);

foreach (var entity in GetEntities<ControlsComponent>())
{
Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Input/KeyState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public enum KeyState
{
Release,
Press,
Repeat
Pressed,
Held
}

0 comments on commit 6abd3bd

Please sign in to comment.