diff --git a/examples/BeehaveTestScene.gd b/examples/BeehaveTestScene.gd index a3480a6d..f62ea683 100644 --- a/examples/BeehaveTestScene.gd +++ b/examples/BeehaveTestScene.gd @@ -1,6 +1,6 @@ extends Node2D -@onready var sprite := $Sprite2D +@onready var sprite := $ColorChangingSprite @onready var tree := %BeehaveTree @onready var condition_label := %ConditionLabel @onready var action_label := %ActionLabel diff --git a/examples/BeehaveTestScene.tscn b/examples/BeehaveTestScene.tscn index 8f7f6ed6..e81f1b6b 100644 --- a/examples/BeehaveTestScene.tscn +++ b/examples/BeehaveTestScene.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://y24m3r3eydsu"] +[gd_scene load_steps=12 format=3 uid="uid://y24m3r3eydsu"] [ext_resource type="Script" path="res://examples/BeehaveTestScene.gd" id="1_s45or"] [ext_resource type="Texture2D" uid="uid://bphl1evimyk6u" path="res://splash.png" id="2_yf6a3"] +[ext_resource type="Script" path="res://examples/ColorChangingSprite.gd" id="3_4a21r"] [ext_resource type="Script" path="res://addons/beehave/nodes/beehave_tree.gd" id="3_hid2l"] [ext_resource type="Script" path="res://addons/beehave/nodes/composites/selector.gd" id="4_8ftoq"] [ext_resource type="Script" path="res://addons/beehave/nodes/composites/sequence.gd" id="5_ifctq"] @@ -22,38 +23,39 @@ position = Vector2(32, 46) scale = Vector2(2.63487, 2.57664) texture = ExtResource("2_yf6a3") -[node name="Sprite2D" type="Sprite2D" parent="."] +[node name="ColorChangingSprite" type="Sprite2D" parent="."] scale = Vector2(0.1, 0.1) texture = SubResource("CompressedTexture2D_atdvc") +script = ExtResource("3_4a21r") -[node name="BeehaveTree" type="Node" parent="Sprite2D" node_paths=PackedStringArray("blackboard")] +[node name="BeehaveTree" type="Node" parent="ColorChangingSprite" node_paths=PackedStringArray("blackboard")] unique_name_in_owner = true script = ExtResource("3_hid2l") actor_node_path = NodePath("") blackboard = NodePath("../../Blackboard") -[node name="SelectorComposite" type="Node" parent="Sprite2D/BeehaveTree"] +[node name="SelectorComposite" type="Node" parent="ColorChangingSprite/BeehaveTree"] script = ExtResource("4_8ftoq") -[node name="SequenceComposite" type="Node" parent="Sprite2D/BeehaveTree/SelectorComposite"] +[node name="SequenceComposite" type="Node" parent="ColorChangingSprite/BeehaveTree/SelectorComposite"] script = ExtResource("5_ifctq") -[node name="HasPositivePosition" parent="Sprite2D/BeehaveTree/SelectorComposite/SequenceComposite" instance=ExtResource("6_7qx5k")] +[node name="HasPositivePosition" parent="ColorChangingSprite/BeehaveTree/SelectorComposite/SequenceComposite" instance=ExtResource("6_7qx5k")] -[node name="SetModulateColor" parent="Sprite2D/BeehaveTree/SelectorComposite/SequenceComposite" instance=ExtResource("7_b4xjm")] +[node name="SetModulateColor" parent="ColorChangingSprite/BeehaveTree/SelectorComposite/SequenceComposite" instance=ExtResource("7_b4xjm")] modulate_color = Color(1, 0, 0, 1) -[node name="SequenceComposite2" type="Node" parent="Sprite2D/BeehaveTree/SelectorComposite"] +[node name="SequenceComposite2" type="Node" parent="ColorChangingSprite/BeehaveTree/SelectorComposite"] script = ExtResource("5_ifctq") -[node name="HasNegativePosition" parent="Sprite2D/BeehaveTree/SelectorComposite/SequenceComposite2" instance=ExtResource("8_dorjh")] +[node name="HasNegativePosition" parent="ColorChangingSprite/BeehaveTree/SelectorComposite/SequenceComposite2" instance=ExtResource("8_dorjh")] -[node name="SetModulateColor" parent="Sprite2D/BeehaveTree/SelectorComposite/SequenceComposite2" instance=ExtResource("7_b4xjm")] +[node name="SetModulateColor" parent="ColorChangingSprite/BeehaveTree/SelectorComposite/SequenceComposite2" instance=ExtResource("7_b4xjm")] modulate_color = Color(0, 0, 1, 1) -[node name="SetModulateColor" parent="Sprite2D/BeehaveTree/SelectorComposite" instance=ExtResource("7_b4xjm")] +[node name="SetModulateColor" parent="ColorChangingSprite/BeehaveTree/SelectorComposite" instance=ExtResource("7_b4xjm")] -[node name="Camera2D" type="Camera2D" parent="Sprite2D"] +[node name="Camera2D" type="Camera2D" parent="ColorChangingSprite"] [node name="Blackboard" type="Node" parent="."] script = ExtResource("9_k8008") diff --git a/examples/ColorChangingSprite.gd b/examples/ColorChangingSprite.gd new file mode 100644 index 00000000..b2e9d319 --- /dev/null +++ b/examples/ColorChangingSprite.gd @@ -0,0 +1,3 @@ +class_name ColorChangingSprite extends Sprite2D + +signal color_changed diff --git a/examples/actions/SetModulateColor.gd b/examples/actions/SetModulateColor.gd index 93133ea8..311de366 100644 --- a/examples/actions/SetModulateColor.gd +++ b/examples/actions/SetModulateColor.gd @@ -16,13 +16,15 @@ func tick(actor: Node, _blackboard: Blackboard) -> int: .set_ease(Tween.EASE_IN_OUT)\ .set_trans(Tween.TRANS_CUBIC) tween.tween_property(actor, "modulate", current_color, interpolation_time)\ - .finished.connect(_finished) + .finished.connect(_finished.bind(actor)) if current_color != null: return RUNNING else: return SUCCESS -func _finished() -> void: +func _finished(actor: Node) -> void: current_color = null tween = null + if actor is ColorChangingSprite: + actor.color_changed.emit() diff --git a/test/e2e_test.gd b/test/e2e_test.gd new file mode 100644 index 00000000..a8b90c5d --- /dev/null +++ b/test/e2e_test.gd @@ -0,0 +1,30 @@ +# GdUnit generated TestSuite +class_name E2ETest +extends GdUnitTestSuite +@warning_ignore("unused_parameter") +@warning_ignore("return_value_discarded") + +# TestSuite generated from +const __source = "res://examples/BeehaveTestScene.tscn" + +func create_scene() -> Node2D: + return auto_free(load(__source).instantiate()) + + +func test_changing_to_all_colours() -> void: + var scene = create_scene() + var runner := scene_runner(scene) + # speed up the test + runner.set_time_factor(100.0) + scene.sprite.position = Vector2(200, 200) + await runner.simulate_until_object_signal(scene.sprite, "color_changed") + assert_that(scene.sprite.modulate).is_equal(Color.RED) + scene.sprite.position = Vector2(-200, 200) + await runner.simulate_until_object_signal(scene.sprite, "color_changed") + assert_that(scene.sprite.modulate).is_equal(Color.WHITE) + scene.sprite.position = Vector2(-200, -200) + await runner.simulate_until_object_signal(scene.sprite, "color_changed") + assert_that(scene.sprite.modulate).is_equal(Color.BLUE) + scene.sprite.position = Vector2(200, -200) + await runner.simulate_until_object_signal(scene.sprite, "color_changed") + assert_that(scene.sprite.modulate).is_equal(Color.WHITE)