129 lines
4.1 KiB
C#
129 lines
4.1 KiB
C#
using Godot;
|
|
using EinSoftworks.Utilities;
|
|
using EinSoftworks.Input;
|
|
|
|
namespace TestGame
|
|
{
|
|
public partial class Main : Node2D
|
|
{
|
|
private InputManager _inputManager;
|
|
private Label _statusLabel;
|
|
private Label _inputStatusLabel;
|
|
|
|
public override void _Ready()
|
|
{
|
|
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}");
|
|
}
|
|
}
|
|
} |