Skip to content

Commit ab85e74

Browse files
committed
Add multiple scenes project test
1 parent 1dfa19a commit ab85e74

File tree

11 files changed

+118
-8
lines changed

11 files changed

+118
-8
lines changed

src/test/kotlin/com/tomwyr/GeneratorTest.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ import kotlin.test.assertEquals
1111

1212
class GeneratorTest {
1313
@Test
14-
fun `generates expected output for simple project`() {
14+
fun `generates expected output for project with single scene`() {
1515
test("simple", "com.simple.game")
1616
}
1717

1818
@Test
19-
fun `generates expected output for the example project`() {
20-
test("example", "com.example.game")
19+
fun `generates expected ouput for project with multiple independent scenes`() {
20+
test("scene-changer", "com.scenes.changer")
21+
}
22+
23+
@Test
24+
fun `generates expected output for project with multiple scenes`() {
25+
test("dodge-the-creeps", "com.example.game")
2126
}
2227

2328
@BeforeTest
@@ -44,20 +49,20 @@ const val basePath = "src/test/resources/"
4449

4550
fun setUpTestProject(testCase: String, targetPackage: String): GodotKotlinProject {
4651
return GodotKotlinProject(
47-
"$basePath/$testCase/input",
48-
"$basePath/$testCase/output/Actual",
52+
"$basePath/$testCase/scenes",
53+
"$basePath/$testCase/Actual",
4954
targetPackage,
5055
)
5156
}
5257

5358
fun assertOutputsEqual(testCase: String) {
54-
val expected = File("$basePath/$testCase/output/Expected").readText(Charsets.UTF_8)
55-
val actual = File("$basePath/$testCase/output/Actual").readText(Charsets.UTF_8)
59+
val expected = File("$basePath/$testCase/Expected").readText(Charsets.UTF_8)
60+
val actual = File("$basePath/$testCase/Actual").readText(Charsets.UTF_8)
5661
assertEquals(expected, actual)
5762
}
5863

5964
fun cleanUpGeneratedOutput(testCase: String) {
60-
File("$basePath/$testCase/output/Actual").run {
65+
File("$basePath/$testCase/Actual").run {
6166
if (exists()) delete()
6267
}
6368
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.scenes.changer
2+
3+
import godot.*
4+
import godot.core.NodePath
5+
import kotlin.reflect.KProperty
6+
7+
object GDTree {
8+
object SceneA : NodeRef<Panel>("/root/SceneA", "Panel") {
9+
val Label = NodeRef<Label>("/root/SceneA/Label", "Label")
10+
val GoToScene = NodeRef<Button>("/root/SceneA/GoToScene", "Button")
11+
}
12+
13+
object SceneB : NodeRef<Panel>("/root/SceneB", "Panel") {
14+
val Label = NodeRef<Label>("/root/SceneB/Label", "Label")
15+
val GoToScene = NodeRef<Button>("/root/SceneB/GoToScene", "Button")
16+
}
17+
}
18+
19+
open class NodeRef<T : Node>(
20+
private val path: String,
21+
private val type: String,
22+
) {
23+
operator fun getValue(thisRef: Node, property: KProperty<*>): T {
24+
val node = thisRef.getNode(NodePath(path)) ?: throw NodeNotFoundException(path)
25+
@Suppress("UNCHECKED_CAST")
26+
(node as? T) ?: throw NodeInvalidTypeException(type)
27+
return node
28+
}
29+
}
30+
31+
class NodeNotFoundException(expectedPath: String) : Exception("Node not found under given path $expectedPath")
32+
33+
class NodeInvalidTypeException(expectedType: String?) : Exception("Node is not an instance of $expectedType")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://dnveeke63vq8x"]
2+
3+
[ext_resource type="Script" path="res://scene_a.gd" id="1"]
4+
5+
[node name="SceneA" type="Panel"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
size_flags_horizontal = 2
12+
size_flags_vertical = 2
13+
script = ExtResource("1")
14+
15+
[node name="Label" type="Label" parent="."]
16+
layout_mode = 0
17+
offset_left = 64.0
18+
offset_top = 48.0
19+
offset_right = 104.0
20+
offset_bottom = 62.0
21+
size_flags_vertical = 0
22+
text = "This is scene A."
23+
24+
[node name="GoToScene" type="Button" parent="."]
25+
layout_mode = 0
26+
offset_left = 64.0
27+
offset_top = 128.0
28+
offset_right = 277.0
29+
offset_bottom = 182.0
30+
size_flags_horizontal = 2
31+
size_flags_vertical = 2
32+
theme_override_colors/font_color = Color(0.639216, 1, 0.639216, 1)
33+
theme_override_font_sizes/font_size = 24
34+
text = "Go to Scene B"
35+
36+
[connection signal="pressed" from="GoToScene" to="." method="_on_goto_scene_pressed"]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://c71ureg6hk2u1"]
2+
3+
[ext_resource type="Script" path="res://scene_b.gd" id="1"]
4+
5+
[node name="SceneB" type="Panel"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
size_flags_horizontal = 2
12+
size_flags_vertical = 2
13+
script = ExtResource("1")
14+
15+
[node name="Label" type="Label" parent="."]
16+
layout_mode = 0
17+
offset_left = 64.0
18+
offset_top = 48.0
19+
offset_right = 164.0
20+
offset_bottom = 62.0
21+
size_flags_vertical = 0
22+
text = "This is scene B."
23+
24+
[node name="GoToScene" type="Button" parent="."]
25+
layout_mode = 0
26+
offset_left = 64.0
27+
offset_top = 128.0
28+
offset_right = 277.0
29+
offset_bottom = 182.0
30+
size_flags_horizontal = 2
31+
size_flags_vertical = 2
32+
theme_override_colors/font_color = Color(0.905882, 0.627451, 0.984314, 1)
33+
theme_override_font_sizes/font_size = 24
34+
text = "Go to Scene A"
35+
36+
[connection signal="pressed" from="GoToScene" to="." method="_on_goto_scene_pressed"]

0 commit comments

Comments
 (0)