Skip to content

Commit

Permalink
Filter properties with hint node_type
Browse files Browse the repository at this point in the history
  • Loading branch information
warriormaster12 committed Oct 9, 2023
1 parent 57a6813 commit 6926783
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
19 changes: 17 additions & 2 deletions scene/property_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,31 @@ Variant PropertyUtils::get_property_default_value(const Object *p_object, const
for (int i = 0; i < states_stack.size(); ++i) {
const SceneState::PackState &ia = states_stack[i];
bool found = false;
Variant value_in_ancestor = ia.state->get_property_value(ia.node, p_property, found);
bool is_path_node = false;
Variant value_in_ancestor = ia.state->get_property_value(ia.node, p_property, found, is_path_node);
if (found) {
if (r_is_valid) {
*r_is_valid = true;
}

if (is_path_node) {
if (value_in_ancestor.get_type() == Variant::ARRAY) {
Array arr = value_in_ancestor;
for (int j = 0; j < arr.size(); j++) {
if (arr[j].get_type() == Variant::NODE_PATH) {
arr[j] = node->get_node(arr[j]);
}
}
value_in_ancestor = arr;
} else {
value_in_ancestor = node->get_node(value_in_ancestor);
}
}
return value_in_ancestor;
}
// Save script for later
bool has_script = false;
Variant script = ia.state->get_property_value(ia.node, SNAME("script"), has_script);
Variant script = ia.state->get_property_value(ia.node, SNAME("script"), has_script, is_path_node);
if (has_script) {
Ref<Script> scr = script;
if (scr.is_valid()) {
Expand Down
8 changes: 6 additions & 2 deletions scene/resources/packed_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,9 @@ int SceneState::_find_base_scene_node_remap_key(int p_idx) const {
return -1;
}

Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found) const {
Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found, bool &is_path_node) const {
found = false;
is_path_node = false;

ERR_FAIL_COND_V(p_node < 0, Variant());

Expand All @@ -1246,6 +1247,9 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property,
const NodeData::Property *p = nodes[p_node].properties.ptr();
for (int i = 0; i < pc; i++) {
if (p_property == namep[p[i].name & FLAG_PROP_NAME_MASK]) {
if (p[i].name & FLAG_PATH_PROPERTY_IS_NODE) {
is_path_node = true;
}
found = true;
return variants[p[i].value];
}
Expand All @@ -1255,7 +1259,7 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property,
//property not found, try on instance

if (base_scene_node_remap.has(p_node)) {
return get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found);
return get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found, is_path_node);
}

return Variant();
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/packed_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SceneState : public RefCounted {
static Ref<Resource> get_remap_resource(const Ref<Resource> &p_resource, HashMap<Ref<Resource>, Ref<Resource>> &remap_cache, const Ref<Resource> &p_fallback, Node *p_for_scene);

int find_node_by_path(const NodePath &p_node) const;
Variant get_property_value(int p_node, const StringName &p_property, bool &found) const;
Variant get_property_value(int p_node, const StringName &p_property, bool &found, bool &is_path_node) const;
bool is_node_in_group(int p_node, const StringName &p_group) const;
bool is_connection(int p_node, const StringName &p_signal, int p_to_node, const StringName &p_to_method) const;

Expand Down

0 comments on commit 6926783

Please sign in to comment.