diff --git a/synced_animation_graph.cpp b/synced_animation_graph.cpp index c52eb94..8805c08 100644 --- a/synced_animation_graph.cpp +++ b/synced_animation_graph.cpp @@ -38,15 +38,10 @@ void SyncedAnimationGraph::_update_properties_for_node(const String &p_base_path for (PropertyInfo &pinfo : plist) { StringName key = pinfo.name; - if (!property_map.has(p_base_path + key)) { - Pair param; - param.first = p_node->get_parameter_default_value(key); - param.second = p_node->is_parameter_read_only(key); - property_map[p_base_path + key] = param; + if (!parameter_to_node_parameter_map.has(p_base_path + key)) { + parameter_to_node_parameter_map[p_base_path + key] = Pair, StringName>(p_node, key); } - property_node_map[p_base_path + key] = Pair, StringName>(p_node, key); - pinfo.name = p_base_path + key; properties.push_back(pinfo); } @@ -65,8 +60,7 @@ void SyncedAnimationGraph::_update_properties() const { } properties.clear(); - property_map.clear(); - property_node_map.clear(); + parameter_to_node_parameter_map.clear(); if (root_animation_node.is_valid()) { _update_properties_for_node(Animation::PARAMETERS_BASE_PATH, root_animation_node); @@ -89,23 +83,14 @@ bool SyncedAnimationGraph::_set(const StringName &p_name, const Variant &p_value _update_properties(); } - if (property_map.has(p_name)) { - if (is_inside_tree() && property_map[p_name].second) { - return false; // Prevent to set property by user. + if (parameter_to_node_parameter_map.has(p_name)) { + const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; + if (!property_node.first.is_valid()) { + print_error(vformat("Cannot set property '%s' node not found.", p_name)); + return false; } - Pair &prop = property_map[p_name]; - Variant value = p_value; - if (Animation::validate_type_match(prop.first, value)) { - Pair, StringName> property_node = property_node_map[p_name]; - if (!property_node.first.is_valid()) { - print_error(vformat("Cannot set property '%s' node not found.", p_name)); - return false; - } - property_node.first->set_parameter(property_node.second, value); - // also set value in the graph's copy of the value. Should probably be removed at some point... - prop.first = value; - } + property_node.first->set_parameter(property_node.second, p_value); return true; } @@ -123,8 +108,13 @@ bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const _update_properties(); } - if (property_map.has(p_name)) { - r_ret = property_map[p_name].first; + if (parameter_to_node_parameter_map.has(p_name)) { + const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; + if (!property_node.first.is_valid()) { + print_error(vformat("Cannot get property '%s' node not found.", p_name)); + return false; + } + r_ret = property_node.first->get_parameter(property_node.second); return true; } diff --git a/synced_animation_graph.h b/synced_animation_graph.h index 489a62a..2ee715a 100644 --- a/synced_animation_graph.h +++ b/synced_animation_graph.h @@ -19,8 +19,7 @@ private: AnimationData graph_output; mutable List properties; - mutable AHashMap> property_map; // Property value and read-only flag. - mutable AHashMap, StringName>> property_node_map; + mutable AHashMap, StringName>> parameter_to_node_parameter_map; mutable bool properties_dirty = true;