-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from wlsnmrk/controller-input-extensions
- Loading branch information
Showing
11 changed files
with
582 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 110 additions & 99 deletions
209
...ver.Tests/ActionsControlExtensionsTest.cs → ...river.Tests/ActionsInputExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,110 @@ | ||
namespace Chickensoft.GodotTestDriver.Tests; | ||
|
||
using Chickensoft.GoDotTest; | ||
using Godot; | ||
using GodotTestDriver.Input; | ||
using JetBrains.Annotations; | ||
using Shouldly; | ||
|
||
[UsedImplicitly] | ||
public partial class ActionsControlExtensionsTest : DriverTest | ||
{ | ||
private partial class ActionInputEventTestNode : Node | ||
{ | ||
public bool HasInputEventFired { get; set; } | ||
public bool WasInputPressed { get; set; } | ||
public StringName InputEventName { get; set; } = string.Empty; | ||
|
||
public override void _Input(InputEvent @event) | ||
{ | ||
if (@event.IsAction(InputEventName)) | ||
{ | ||
HasInputEventFired = true; | ||
WasInputPressed = @event.IsActionPressed(InputEventName); | ||
} | ||
} | ||
} | ||
|
||
private const string TestAction = "test_action"; | ||
|
||
public ActionsControlExtensionsTest(Node testScene) : base(testScene) | ||
{ | ||
} | ||
|
||
[Test] | ||
public void StartActionSetsGlobalActionPressed() | ||
{ | ||
Input.IsActionPressed(TestAction).ShouldBeFalse(); | ||
RootNode.StartAction(TestAction); | ||
Input.IsActionPressed(TestAction).ShouldBeTrue(); | ||
RootNode.EndAction(TestAction); | ||
} | ||
|
||
[Test] | ||
public void EndActionUnsetsGlobalActionPressed() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
RootNode.EndAction(TestAction); | ||
Input.IsActionPressed(TestAction).ShouldBeFalse(); | ||
} | ||
|
||
[Test] | ||
public void StartActionSetsGlobalActionJustPressed() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
Input.IsActionJustPressed(TestAction).ShouldBeTrue(); | ||
RootNode.EndAction(TestAction); | ||
} | ||
|
||
[Test] | ||
public void EndActionSetsGlobalActionJustReleased() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
RootNode.EndAction(TestAction); | ||
Input.IsActionJustReleased(TestAction).ShouldBeTrue(); | ||
} | ||
|
||
[Test] | ||
public void StartActionSendsInputEvent() | ||
{ | ||
var inputTestNode = new ActionInputEventTestNode | ||
{ | ||
InputEventName = TestAction | ||
}; | ||
RootNode.AddChild(inputTestNode); | ||
inputTestNode.HasInputEventFired.ShouldBeFalse(); | ||
inputTestNode.StartAction(TestAction); | ||
inputTestNode.HasInputEventFired.ShouldBeTrue(); | ||
inputTestNode.WasInputPressed.ShouldBeTrue(); | ||
inputTestNode.EndAction(TestAction); | ||
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free | ||
inputTestNode.QueueFree(); | ||
} | ||
|
||
[Test] | ||
public void EndActionSendsInputEvent() | ||
{ | ||
var inputTestNode = new ActionInputEventTestNode | ||
{ | ||
InputEventName = TestAction | ||
}; | ||
RootNode.AddChild(inputTestNode); | ||
inputTestNode.HasInputEventFired.ShouldBeFalse(); | ||
inputTestNode.EndAction(TestAction); | ||
inputTestNode.HasInputEventFired.ShouldBeTrue(); | ||
inputTestNode.WasInputPressed.ShouldBeFalse(); | ||
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free | ||
inputTestNode.QueueFree(); | ||
} | ||
} | ||
namespace Chickensoft.GodotTestDriver.Tests; | ||
|
||
using Chickensoft.GoDotTest; | ||
using Godot; | ||
using GodotTestDriver.Input; | ||
using JetBrains.Annotations; | ||
using Shouldly; | ||
|
||
[UsedImplicitly] | ||
public partial class ActionsInputExtensionsTest : DriverTest | ||
{ | ||
private partial class ActionInputEventTestNode : Node | ||
{ | ||
public bool HasInputEventFired { get; set; } | ||
public bool WasInputPressed { get; set; } | ||
public StringName InputEventName { get; set; } = string.Empty; | ||
|
||
public override void _Input(InputEvent @event) | ||
{ | ||
if (@event.IsAction(InputEventName)) | ||
{ | ||
HasInputEventFired = true; | ||
WasInputPressed = @event.IsActionPressed(InputEventName); | ||
} | ||
} | ||
} | ||
|
||
private const string TestAction = "test_action"; | ||
|
||
public ActionsInputExtensionsTest(Node testScene) : base(testScene) | ||
{ | ||
} | ||
|
||
[Test] | ||
public void StartActionSetsGlobalActionPressed() | ||
{ | ||
Input.IsActionPressed(TestAction).ShouldBeFalse(); | ||
RootNode.StartAction(TestAction); | ||
Input.IsActionPressed(TestAction).ShouldBeTrue(); | ||
RootNode.EndAction(TestAction); | ||
} | ||
|
||
[Test] | ||
public void StartActionClampsStrengthBetweenZeroAndOne() | ||
{ | ||
RootNode.StartAction(TestAction, -1); | ||
Input.GetActionStrength(TestAction).ShouldBe(0); | ||
RootNode.EndAction(TestAction); | ||
RootNode.StartAction(TestAction, 2); | ||
Input.GetActionStrength(TestAction).ShouldBe(1); | ||
RootNode.EndAction(TestAction); | ||
} | ||
|
||
[Test] | ||
public void EndActionUnsetsGlobalActionPressed() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
RootNode.EndAction(TestAction); | ||
Input.IsActionPressed(TestAction).ShouldBeFalse(); | ||
} | ||
|
||
[Test] | ||
public void StartActionSetsGlobalActionJustPressed() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
Input.IsActionJustPressed(TestAction).ShouldBeTrue(); | ||
RootNode.EndAction(TestAction); | ||
} | ||
|
||
[Test] | ||
public void EndActionSetsGlobalActionJustReleased() | ||
{ | ||
RootNode.StartAction(TestAction); | ||
RootNode.EndAction(TestAction); | ||
Input.IsActionJustReleased(TestAction).ShouldBeTrue(); | ||
} | ||
|
||
[Test] | ||
public void StartActionSendsInputEvent() | ||
{ | ||
var inputTestNode = new ActionInputEventTestNode | ||
{ | ||
InputEventName = TestAction | ||
}; | ||
RootNode.AddChild(inputTestNode); | ||
inputTestNode.HasInputEventFired.ShouldBeFalse(); | ||
inputTestNode.StartAction(TestAction); | ||
inputTestNode.HasInputEventFired.ShouldBeTrue(); | ||
inputTestNode.WasInputPressed.ShouldBeTrue(); | ||
inputTestNode.EndAction(TestAction); | ||
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free | ||
inputTestNode.QueueFree(); | ||
} | ||
|
||
[Test] | ||
public void EndActionSendsInputEvent() | ||
{ | ||
var inputTestNode = new ActionInputEventTestNode | ||
{ | ||
InputEventName = TestAction | ||
}; | ||
RootNode.AddChild(inputTestNode); | ||
inputTestNode.HasInputEventFired.ShouldBeFalse(); | ||
inputTestNode.EndAction(TestAction); | ||
inputTestNode.HasInputEventFired.ShouldBeTrue(); | ||
inputTestNode.WasInputPressed.ShouldBeFalse(); | ||
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free | ||
inputTestNode.QueueFree(); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.