Skip to content

Commit

Permalink
🧪 simulate example scene in e2e test (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbrain authored Jan 28, 2023
1 parent 3a416b2 commit 4e3b6c3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/BeehaveTestScene.gd
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 14 additions & 12 deletions examples/BeehaveTestScene.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions examples/ColorChangingSprite.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class_name ColorChangingSprite extends Sprite2D

signal color_changed
6 changes: 4 additions & 2 deletions examples/actions/SetModulateColor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
30 changes: 30 additions & 0 deletions test/e2e_test.gd
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4e3b6c3

Please sign in to comment.