Integrate input library with comprehensive testing functionality

This commit is contained in:
Will Stuckey
2025-10-24 14:03:19 -05:00
parent 7399c1570e
commit 56ce300cd9
4 changed files with 197 additions and 2 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"godotTools.editorPath.godot4": "/Users/u229331/GameDev/Godot/Godot_mono.app"
}

View File

@@ -1,12 +1,129 @@
using Godot; using Godot;
using EinSoftworks.Utilities;
using EinSoftworks.Input;
namespace TestGame namespace TestGame
{ {
public partial class Main : Node2D public partial class Main : Node2D
{ {
private InputManager _inputManager;
private Label _statusLabel;
private Label _inputStatusLabel;
public override void _Ready() public override void _Ready()
{ {
GD.Print("Clean test game started!"); GD.Print("Test Game Started!");
// Test the utilities library
TestMathUtils();
// Initialize input manager
_inputManager = new InputManager();
AddChild(_inputManager);
// Create UI labels for testing
CreateTestUI();
// Connect to input events
_inputManager.ActionPressed += OnActionPressed;
_inputManager.ActionReleased += OnActionReleased;
}
public override void _Process(double delta)
{
TestInputSystem();
}
private void TestMathUtils()
{
// Test degree/radian conversion
float testAngle = 90f;
float radians = MathUtils.DegreesToRadians(testAngle);
float backToDegrees = MathUtils.RadiansToDegrees(radians);
GD.Print($"90° → {radians} rad → {backToDegrees}°");
// Test clamping
float clampedValue = MathUtils.Clamp01(1.5f);
GD.Print($"Clamped 1.5 to 0-1 range: {clampedValue}");
// Test approximation
bool isApprox = MathUtils.Approximately(0.1f, 0.100001f);
GD.Print($"0.1 ≈ 0.100001: {isApprox}");
}
private void CreateTestUI()
{
// Main status label (existing)
_statusLabel = GetNode<Label>("Label");
// Create input status label
_inputStatusLabel = new Label();
_inputStatusLabel.Position = new Vector2(10, 100);
_inputStatusLabel.Size = new Vector2(600, 400);
_inputStatusLabel.Text = "Input Test Area\nUse WASD to move, Space to jump, E to interact";
AddChild(_inputStatusLabel);
}
private void TestInputSystem()
{
var inputText = "=== INPUT TESTING ===\n";
// Test movement input
Vector2 moveVector = _inputManager.GetVector("move_left", "move_right", "move_forward", "move_back");
inputText += $"Movement Vector: {moveVector}\n";
// Test individual actions
if (_inputManager.IsActionPressed("move_forward"))
inputText += "Moving Forward (W)\n";
if (_inputManager.IsActionPressed("move_back"))
inputText += "Moving Back (S)\n";
if (_inputManager.IsActionPressed("move_left"))
inputText += "Moving Left (A)\n";
if (_inputManager.IsActionPressed("move_right"))
inputText += "Moving Right (D)\n";
// Test action timing
float jumpHoldTime = _inputManager.GetActionHoldTime("jump");
if (jumpHoldTime > 0)
{
inputText += $"Jump held for: {jumpHoldTime:F2}s\n";
}
// Test buffered input
if (_inputManager.WasActionPressedInWindow("jump", 0.2f))
{
inputText += "Jump buffered (within 0.2s)\n";
}
// Test interaction
if (_inputManager.IsActionJustPressed("interact"))
{
inputText += "Interaction triggered!\n";
TestInputBuffering();
}
_inputStatusLabel.Text = inputText;
}
private void TestInputBuffering()
{
GD.Print("Testing input buffering...");
// Test consuming buffered input
if (_inputManager.ConsumeBufferedInput("interact"))
{
GD.Print("Consumed buffered interact input");
}
}
private void OnActionPressed(string action)
{
GD.Print($"Action pressed: {action}");
}
private void OnActionReleased(string action)
{
GD.Print($"Action released: {action}");
} }
} }
} }

View File

@@ -17,3 +17,36 @@ config/features=PackedStringArray("4.5", "C#", "Forward Plus")
[dotnet] [dotnet]
project/assembly_name="test-game" project/assembly_name="test-game"
[input]
move_forward={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_back={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
interact={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}

42
test-game.sln Normal file
View File

@@ -0,0 +1,42 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test-game", "test-game.csproj", "{91FECB75-6A7A-FC49-EC05-221FF569DFB8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{F2E35B3E-9711-EDEC-6202-DB40BDEED14A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Input", "Libraries\input\Input.csproj", "{B7A55389-A9B6-C4FD-992D-C647805A73F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utilities", "Libraries\utilities\Utilities.csproj", "{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{91FECB75-6A7A-FC49-EC05-221FF569DFB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91FECB75-6A7A-FC49-EC05-221FF569DFB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91FECB75-6A7A-FC49-EC05-221FF569DFB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91FECB75-6A7A-FC49-EC05-221FF569DFB8}.Release|Any CPU.Build.0 = Release|Any CPU
{B7A55389-A9B6-C4FD-992D-C647805A73F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7A55389-A9B6-C4FD-992D-C647805A73F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7A55389-A9B6-C4FD-992D-C647805A73F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7A55389-A9B6-C4FD-992D-C647805A73F8}.Release|Any CPU.Build.0 = Release|Any CPU
{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B7A55389-A9B6-C4FD-992D-C647805A73F8} = {F2E35B3E-9711-EDEC-6202-DB40BDEED14A}
{A42DA6EC-BCC6-A369-89AE-08C27BC7C6E2} = {F2E35B3E-9711-EDEC-6202-DB40BDEED14A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A7E4B81B-D0E4-4523-9CA9-568F166DBBC9}
EndGlobalSection
EndGlobal