diff --git a/addons/gut/input_sender.gd b/addons/gut/input_sender.gd index 26b666d..9702e09 100644 --- a/addons/gut/input_sender.gd +++ b/addons/gut/input_sender.gd @@ -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: diff --git a/player.gd b/player.gd index 2c05371..d45222b 100644 --- a/player.gd +++ b/player.gd @@ -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) \ No newline at end of file + $CollisionShape2D.set_deferred("disabled", true) \ No newline at end of file diff --git a/test/unit/test_player.gd b/test/unit/test_player.gd index 8af0ce3..38ca43d 100644 --- a/test/unit/test_player.gd +++ b/test/unit/test_player.gd @@ -2,7 +2,7 @@ extends GutTest var Player: PackedScene = load('res://player.tscn') -var _sender = InputSender.new() +var _sender = InputSender.new(Input) func after_each(): _sender.release_all() @@ -10,11 +10,19 @@ func after_each(): 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") - \ No newline at end of file + 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") +