Skip to content

Commit

Permalink
Applied patch to make the InputSender properly send the input for the…
Browse files Browse the repository at this point in the history
… Input global Singleton again. See: bitwes/Gut#587

Then, adjusted test for moving the player right to actually work instead of just fooling myself with the newly set position. :)
  • Loading branch information
ArSn committed Apr 14, 2024
1 parent bf310c0 commit 7947aed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions addons/gut/input_sender.gd
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ func _send_event(event):
for r in _receivers:
if(r == Input):
Input.parse_input_event(event)
if(event is InputEventAction):
if(event.pressed):
Input.action_press(event.action)
else:
Input.action_release(event.action)
if(_auto_flush_input):
Input.flush_buffered_events()
else:
Expand Down
2 changes: 1 addition & 1 deletion player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ func _on_body_entered(body):
hide() # Player disappears after being hit.
hit.emit()
# Must be deferred as we can't change physics properties on a physics callback.
$CollisionShape2D.set_deferred("disabled", true)
$CollisionShape2D.set_deferred("disabled", true)
18 changes: 13 additions & 5 deletions test/unit/test_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ extends GutTest

var Player: PackedScene = load('res://player.tscn')

var _sender = InputSender.new()
var _sender = InputSender.new(Input)

func after_each():
_sender.release_all()
_sender.clear()

func test_move_right_adds_positive_x_velocity():
var player = add_child_autofree(Player.instantiate())
# todo: find out why it only works when setting the position here, 0,0 does not work
player.position = Vector2(1, 1)
var previous_x: float = player.position.x

_sender.action_down("move_right").wait_frames(1)
await(_sender.idle)

assert_gt(player.position.x, 0.0, "Player should move right")

assert_gt(player.position.x, previous_x, "Player should move right")

#func test_move_left_adds_negative_x_velocity():
# var player = add_child_autofree(Player.instantiate())
# player.position = Vector2(1, 1)
#
# _sender.action_down("move_left").wait_frames(1)
# await(_sender.idle)
#
# assert_lt(player.position.x, 0.0, "Player should move left")

0 comments on commit 7947aed

Please sign in to comment.