示例#1
0
 def test_load_inherited(self):
     """ Can load an inherited scene and read the nodes """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         node = tree.get_node("Health/LifeBar")
         self.assertIsNotNone(node)
         self.assertEqual(node.type, "TextureProgress")
示例#2
0
 def test_disappear_sections(self):
     """ Inherited nodes are removed from sections if we change their configuration to match parent """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         sprite = tree.get_node("Sprite")
         sprite["flip_h"] = False
     # Sprite should match parent now, and not be in file
     node = scene.find_section("node", name="Sprite")
     self.assertIsNone(node)
示例#3
0
 def test_inherit_properties(self):
     """ Inherited nodes inherit properties """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         self.assertEqual(tree.root["shape"], SubResource(1))
         self.assertEqual(tree.root["collision_layer"], 4)
         self.assertEqual(tree.root.get("collision_layer"), 4)
         self.assertEqual(tree.root.get("missing"), None)
         self.assertRaises(KeyError, lambda: tree.root["missing"])
示例#4
0
 def test_overwrite_sections(self):
     """ Inherited nodes appear in sections if we change their configuration """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         node = tree.get_node("Health/LifeBar")
         node["pause_mode"] = 2
     num_nodes = len(scene.get_nodes())
     self.assertEqual(num_nodes, 3)
     node = scene.find_section("node", name="LifeBar", parent="Health")
     self.assertIsNotNone(node)
示例#5
0
 def test_cannot_remove(self):
     """ Cannot remove inherited nodes """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         node = tree.get_node("Health")
         self.assertRaises(TreeMutationException, node.remove_from_parent)
         self.assertRaises(TreeMutationException,
                           lambda: tree.root.remove_child(0))
         self.assertRaises(TreeMutationException,
                           lambda: tree.root.remove_child("Health"))
示例#6
0
 def test_unchanged_sections(self):
     """ Inherited nodes do not appear in sections """
     scene = GDScene.load(self.leaf_scene)
     num_nodes = len(scene.get_nodes())
     self.assertEqual(num_nodes, 2)
     with scene.use_tree() as tree:
         sprite = tree.get_node("Sprite")
         sprite["flip_v"] = True
     # No new nodes
     num_nodes = len(scene.get_nodes())
     self.assertEqual(num_nodes, 2)
示例#7
0
 def test_add_new_nodes(self):
     """ Can add new nodes to an inherited scene """
     scene = GDScene.load(self.leaf_scene)
     with scene.use_tree() as tree:
         tree.get_node("Health/LifeBar")
         node = Node("NewChild", type="Control")
         tree.root.add_child(node)
         # Non-inherited node can change name, type, instance
         node.instance = 2
         node.type = "Node2D"
         node.name = "NewChild2"
     found = scene.find_section("node", name="NewChild2")
     self.assertIsNotNone(found)
     self.assertEqual(found.type, "Node2D")
     self.assertEqual(found.parent, ".")
     self.assertEqual(found.index, 3)
示例#8
0
    def test_cannot_mutate(self):
        """ Cannot change the name/type/instance of inherited nodes """
        scene = GDScene.load(self.leaf_scene)

        def change_name(x):
            x.name = "foo"

        def change_type(x):
            x.type = "foo"

        def change_instance(x):
            x.instance = 2

        with scene.use_tree() as tree:
            node = tree.get_node("Health")
            self.assertRaises(TreeMutationException, lambda: change_name(node))
            self.assertRaises(TreeMutationException, lambda: change_type(node))
            self.assertRaises(TreeMutationException,
                              lambda: change_instance(node))
示例#9
0
 def test_missing_ext_resource(self):
     """ Raise exception when GDScene is inherited but ext_resource is missing """
     scene = GDScene.load(self.leaf_scene)
     for section in scene.get_ext_resources():
         scene.remove_section(section)
     self.assertRaises(RuntimeError, lambda: scene.get_node("Root"))