Exemplo n.º 1
0
 def test_invalid_tree(self):
     """ Raise exception when tree is invalid """
     scene = GDScene()
     scene.add_node("RootNode")
     scene.add_node("Child", parent="Missing")
     self.assertRaises(TreeMutationException,
                       lambda: scene.get_node("Child"))
Exemplo n.º 2
0
 def test_get_node(self):
     """ Test for get_node() """
     scene = GDScene()
     scene.add_node("RootNode")
     scene.add_node("Child", parent=".")
     child = scene.add_node("Child2", parent="Child")
     node = scene.get_node("Child/Child2")
     self.assertEqual(node, child)
Exemplo n.º 3
0
 def test_find_node(self):
     """Test GDScene.find_node"""
     scene = GDScene()
     n1 = scene.add_node("Root", "Node")
     n2 = scene.add_node("Child", "Node", parent=".")
     node = scene.find_node(name="Root")
     self.assertEqual(node, n1)
     node = scene.find_node(parent=".")
     self.assertEqual(node, n2)
Exemplo n.º 4
0
 def test_properties(self):
     """ Test for changing properties on a node """
     scene = GDScene()
     scene.add_node("RootNode")
     with scene.use_tree() as tree:
         tree.root["vframes"] = 10
         self.assertEqual(tree.root["vframes"], 10)
         tree.root["hframes"] = 10
         del tree.root["hframes"]
         del tree.root["hframes"]
         self.assertIsNone(tree.root.get("hframes"))
     child = scene.find_section("node")
     self.assertEqual(child["vframes"], 10)
Exemplo n.º 5
0
    def test_node(self):
        """Test serializing a scene with a node"""
        scene = GDScene()
        scene.add_node("RootNode", type="Node2D")
        scene.add_node("Child", type="Area2D", parent=".")
        self.assertEqual(
            str(scene),
            """[gd_scene load_steps=1 format=2]

[node name="RootNode" type="Node2D"]

[node name="Child" type="Area2D" parent="."]
""",
        )
Exemplo n.º 6
0
 def test_insert_child(self):
     """ Test for insert_child() """
     scene = GDScene()
     scene.add_node("RootNode")
     scene.add_node("Child1", parent=".")
     with scene.use_tree() as tree:
         child = Node("Child2", type="Node")
         tree.root.insert_child(0, child)
     child1 = scene.find_section("node", name="Child1")
     child2 = scene.find_section("node", name="Child2")
     idx1 = scene.get_sections().index(child1)
     idx2 = scene.get_sections().index(child2)
     print(scene.get_sections())
     self.assertLess(idx2, idx1)
Exemplo n.º 7
0
 def test_section_ordering(self):
     """Sections maintain an ordering"""
     scene = GDScene()
     node = scene.add_node("RootNode")
     scene.add_ext_resource("res://Other.tscn", "PackedScene")
     res = scene.find_section("ext_resource")
     self.assertEqual(scene.get_sections()[1:], [res, node])
Exemplo n.º 8
0
    def test_remove_node(self):
        """ Test for remove_node() """
        scene = GDScene()
        scene.add_node("RootNode")
        scene.add_node("Child", parent=".")
        node = scene.find_section("node", name="Child")
        self.assertIsNotNone(node)

        # Remove by name
        with scene.use_tree() as tree:
            tree.root.remove_child("Child")
        node = scene.find_section("node", name="Child")
        self.assertIsNone(node)

        # Remove by index
        scene.add_node("Child", parent=".")
        with scene.use_tree() as tree:
            tree.root.remove_child(0)
        node = scene.find_section("node", name="Child")
        self.assertIsNone(node)

        # Remove by reference
        scene.add_node("Child", parent=".")
        with scene.use_tree() as tree:
            node = tree.root.get_children()[0]
            tree.root.remove_child(node)
        node = scene.find_section("node", name="Child")
        self.assertIsNone(node)

        # Remove child
        scene.add_node("Child", parent=".")
        with scene.use_tree() as tree:
            node = tree.root.get_child(0)
            node.remove_from_parent()
        node = scene.find_section("node", name="Child")
        self.assertIsNone(node)
Exemplo n.º 9
0
    def test_addremove_ext_res(self):
        """Test adding and removing an ext_resource"""
        scene = GDScene()
        res = scene.add_ext_resource("res://Res.tscn", "PackedScene")
        self.assertEqual(res.id, 1)
        res2 = scene.add_ext_resource("res://Sprite.png", "Texture")
        self.assertEqual(res2.id, 2)
        node = scene.add_node("Sprite", "Sprite")
        node["texture"] = res2.reference
        node["textures"] = [res2.reference]
        node["texture_map"] = {"tex": res2.reference}
        node["texture_pool"] = GDObject("ResourcePool", res2.reference)

        s = scene.find_section(path="res://Res.tscn")
        scene.remove_section(s)
        scene.renumber_resource_ids()

        s = scene.find_section("ext_resource")
        self.assertEqual(s.id, 1)
        self.assertEqual(node["texture"], s.reference)
        self.assertEqual(node["textures"][0], s.reference)
        self.assertEqual(node["texture_map"]["tex"], s.reference)
        self.assertEqual(node["texture_pool"].args[0], s.reference)
Exemplo n.º 10
0
 def test_get_missing_node(self):
     """ get_node on missing node should return None """
     scene = GDScene()
     scene.add_node("RootNode")
     node = scene.get_node("Foo/Bar/Baz")
     self.assertIsNone(node)