-
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 #1 from wlsnmrk/synchronicity
feat: fire input action events, synchronize methods
- Loading branch information
Showing
30 changed files
with
383 additions
and
335 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[gd_scene format=3 uid="uid://busk27caw7oi8"] | ||
|
||
[node name="ActionsControlExtensionsTest" type="Node"] |
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
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
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
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
Oops, something went wrong.