MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _parse_node

Method _parse_node

scene/resources/packed_scene.cpp:746–1061  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

744}
745
746Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, HashMap<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, HashMap<Node *, int> &node_map, HashMap<Node *, int> &nodepath_map) {
747 //discard nodes that do not belong to be processed
748 if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
749 return OK;
750 }
751
752 bool is_editable_instance = false;
753
754 // save the child instantiated scenes that are chosen as editable, so they can be restored
755 // upon load back
756 if (p_node != p_owner && !p_node->get_scene_file_path().is_empty() && p_owner->is_editable_instance(p_node)) {
757 editable_instances.push_back(p_owner->get_path_to(p_node));
758 // Node is the root of an editable instance.
759 is_editable_instance = true;
760 } else if (p_node->get_owner() && p_owner->is_ancestor_of(p_node->get_owner()) && p_owner->is_editable_instance(p_node->get_owner())) {
761 // Node is part of an editable instance.
762 is_editable_instance = true;
763 }
764
765 NodeData nd;
766
767 nd.name = _nm_get_string(p_node->get_name(), name_map);
768 nd.instance = -1; //not instantiated by default
769
770 //really convoluted condition, but it basically checks that index is only saved when part of an inherited scene OR the node parent is from the edited scene
771 if (p_owner->get_scene_inherited_state().is_null() && (p_node == p_owner || (p_node->get_owner() == p_owner && (p_node->get_parent() == p_owner || p_node->get_parent()->get_owner() == p_owner)))) {
772 //do not save index, because it belongs to saved scene and scene is not inherited
773 nd.index = -1;
774 } else if (p_node == p_owner) {
775 //This (hopefully) happens if the node is a scene root, so its index is irrelevant.
776 nd.index = -1;
777 } else {
778 //part of an inherited scene, or parent is from an instantiated scene
779 nd.index = p_node->get_index();
780 }
781
782 // if this node is part of an instantiated scene or sub-instantiated scene
783 // we need to get the corresponding instance states.
784 // with the instance states, we can query for identical properties/groups
785 // and only save what has changed
786
787 bool instantiated_by_owner = false;
788 Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, p_owner, &instantiated_by_owner);
789
790 if (!p_node->get_scene_file_path().is_empty() && p_node->get_owner() == p_owner && instantiated_by_owner) {
791 if (p_node->get_scene_instance_load_placeholder()) {
792 //it's a placeholder, use the placeholder path
793 nd.instance = _vm_get_variant(p_node->get_scene_file_path(), variant_map);
794 nd.instance |= FLAG_INSTANCE_IS_PLACEHOLDER;
795 } else {
796 //must instance ourselves
797 Ref<PackedScene> instance = ResourceLoader::load(p_node->get_scene_file_path());
798 if (instance.is_null()) {
799 return ERR_CANT_OPEN;
800 }
801
802 nd.instance = _vm_get_variant(instance, variant_map);
803 }

Callers

nothing calls this directly

Calls 15

_nm_get_stringFunction · 0.85
_vm_get_variantFunction · 0.85
is_editable_instanceMethod · 0.80
get_scene_file_pathMethod · 0.80
get_path_toMethod · 0.80
is_ancestor_ofMethod · 0.80
find_charMethod · 0.80
substrMethod · 0.80
to_intMethod · 0.80

Tested by

no test coverage detected