diff options
Diffstat (limited to 'modules/visual_script')
18 files changed, 1022 insertions, 1970 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 5ea84a32c4..8afed1229f 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -47,7 +47,6 @@ static _VisualScriptEditor *vs_editor_singleton = nullptr; #endif void register_visual_script_types() { - visual_script_language = memnew(VisualScriptLanguage); //script_language_gd->init(); ScriptServer::register_language(visual_script_language); @@ -125,7 +124,6 @@ void register_visual_script_types() { } void unregister_visual_script_types() { - unregister_visual_script_nodes(); ScriptServer::unregister_language(visual_script_language); @@ -136,6 +134,7 @@ void unregister_visual_script_types() { memdelete(vs_editor_singleton); } #endif - if (visual_script_language) + if (visual_script_language) { memdelete(visual_script_language); + } } diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index fe1d82f977..f387c0f288 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -44,7 +44,6 @@ void VisualScriptNode::set_breakpoint(bool p_breakpoint) { } bool VisualScriptNode::is_breakpoint() const { - return breakpoint; } @@ -53,7 +52,6 @@ void VisualScriptNode::ports_changed_notify() { } void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) { - ERR_FAIL_INDEX(p_port, default_input_values.size()); default_input_values[p_port] = p_value; @@ -66,13 +64,11 @@ void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_valu } Variant VisualScriptNode::get_default_input_value(int p_port) const { - ERR_FAIL_INDEX_V(p_port, default_input_values.size(), Variant()); return default_input_values[p_port]; } void VisualScriptNode::_set_default_input_values(Array p_values) { - default_input_values = p_values; } @@ -81,7 +77,6 @@ void VisualScriptNode::validate_input_default_values() { //actually validate on save for (int i = 0; i < get_input_value_port_count(); i++) { - Variant::Type expected = get_input_value_port_info(i).type; if (expected == Variant::NIL || expected == default_input_values[i].get_type()) { @@ -101,7 +96,6 @@ void VisualScriptNode::validate_input_default_values() { } Array VisualScriptNode::_get_default_input_values() const { - //validate on save, since on load there is little info about this Array values = default_input_values; values.resize(get_input_value_port_count()); @@ -114,7 +108,6 @@ String VisualScriptNode::get_text() const { } void VisualScriptNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_visual_script"), &VisualScriptNode::get_visual_script); ClassDB::bind_method(D_METHOD("set_default_input_value", "port_idx", "value"), &VisualScriptNode::set_default_input_value); ClassDB::bind_method(D_METHOD("get_default_input_value", "port_idx"), &VisualScriptNode::get_default_input_value); @@ -127,7 +120,6 @@ void VisualScriptNode::_bind_methods() { } VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - PropertyInfo pinfo = get_output_value_port_info(p_output); TypeGuess tg; @@ -141,9 +133,9 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp } Ref<VisualScript> VisualScriptNode::get_visual_script() const { - - if (scripts_used.size()) + if (scripts_used.size()) { return Ref<VisualScript>(scripts_used.front()->get()); + } return Ref<VisualScript>(); } @@ -157,13 +149,11 @@ VisualScriptNode::VisualScriptNode() { ///////////////////// VisualScriptNodeInstance::VisualScriptNodeInstance() { - sequence_outputs = nullptr; input_ports = nullptr; } VisualScriptNodeInstance::~VisualScriptNodeInstance() { - if (sequence_outputs) { memdelete_arr(sequence_outputs); } @@ -178,7 +168,6 @@ VisualScriptNodeInstance::~VisualScriptNodeInstance() { } void VisualScript::add_function(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(functions.has(p_name)); @@ -188,16 +177,14 @@ void VisualScript::add_function(const StringName &p_name) { } bool VisualScript::has_function(const StringName &p_name) const { - return functions.has(p_name); } -void VisualScript::remove_function(const StringName &p_name) { +void VisualScript::remove_function(const StringName &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); for (Map<int, Function::NodeData>::Element *E = functions[p_name].nodes.front(); E; E = E->next()) { - E->get().node->disconnect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed)); E->get().node->scripts_used.erase(this); } @@ -206,11 +193,11 @@ void VisualScript::remove_function(const StringName &p_name) { } void VisualScript::rename_function(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -223,19 +210,16 @@ void VisualScript::rename_function(const StringName &p_name, const StringName &p } void VisualScript::set_function_scroll(const StringName &p_name, const Vector2 &p_scroll) { - ERR_FAIL_COND(!functions.has(p_name)); functions[p_name].scroll = p_scroll; } Vector2 VisualScript::get_function_scroll(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), Vector2()); return functions[p_name].scroll; } void VisualScript::get_function_list(List<StringName> *r_functions) const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { r_functions->push_back(E->key()); } @@ -244,18 +228,15 @@ void VisualScript::get_function_list(List<StringName> *r_functions) const { } int VisualScript::get_function_node_id(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), -1); return functions[p_name].function_id; } void VisualScript::_node_ports_changed(int p_id) { - StringName function; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - if (E->get().nodes.has(p_id)) { function = E->key(); break; @@ -276,11 +257,9 @@ void VisualScript::_node_ports_changed(int p_id) { for (Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) { if (E->get().from_node == p_id && E->get().from_output >= vsn->get_output_sequence_port_count()) { - to_remove.push_back(E->get()); } if (E->get().to_node == p_id && !vsn->has_input_sequence_port()) { - to_remove.push_back(E->get()); } } @@ -292,7 +271,6 @@ void VisualScript::_node_ports_changed(int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -317,12 +295,10 @@ void VisualScript::_node_ports_changed(int p_id) { } void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - ERR_FAIL_COND(E->get().nodes.has(p_id)); //id can exist only one in script, even for different functions } @@ -348,7 +324,6 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual } void VisualScript::remove_node(const StringName &p_func, int p_id) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -370,7 +345,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -396,7 +370,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } bool VisualScript::has_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -404,7 +377,6 @@ bool VisualScript::has_node(const StringName &p_func, int p_id) const { } Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Ref<VisualScriptNode>()); const Function &func = functions[p_func]; @@ -414,7 +386,6 @@ Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) } void VisualScript::set_node_position(const StringName &p_func, int p_id, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -424,7 +395,6 @@ void VisualScript::set_node_position(const StringName &p_func, int p_id, const P } Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Point2()); const Function &func = functions[p_func]; @@ -433,7 +403,6 @@ Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const } void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -443,7 +412,6 @@ void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) c } void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -458,7 +426,6 @@ void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, i } void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -472,7 +439,6 @@ void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node } bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -485,7 +451,6 @@ bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_ } void VisualScript::get_sequence_connection_list(const StringName &p_func, List<SequenceConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -495,7 +460,6 @@ void VisualScript::get_sequence_connection_list(const StringName &p_func, List<S } void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -512,7 +476,6 @@ void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p } void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -528,7 +491,6 @@ void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, in } bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -542,20 +504,19 @@ bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node } bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { - if (E->get().to_node == p_node && E->get().to_port == p_port) + if (E->get().to_node == p_node && E->get().to_port == p_port) { return true; + } } return false; } bool VisualScript::get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -571,7 +532,6 @@ bool VisualScript::get_input_value_port_connection_source(const StringName &p_fu } void VisualScript::get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -585,7 +545,6 @@ void VisualScript::set_tool_enabled(bool p_enabled) { } void VisualScript::add_variable(const StringName &p_name, const Variant &p_default_value, bool p_export) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(variables.has(p_name)); @@ -605,12 +564,10 @@ void VisualScript::add_variable(const StringName &p_name, const Variant &p_defau } bool VisualScript::has_variable(const StringName &p_name) const { - return variables.has(p_name); } void VisualScript::remove_variable(const StringName &p_name) { - ERR_FAIL_COND(!variables.has(p_name)); variables.erase(p_name); @@ -620,7 +577,6 @@ void VisualScript::remove_variable(const StringName &p_name) { } void VisualScript::set_variable_default_value(const StringName &p_name, const Variant &p_value) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].default_value = p_value; @@ -629,13 +585,13 @@ void VisualScript::set_variable_default_value(const StringName &p_name, const Va _update_placeholders(); #endif } -Variant VisualScript::get_variable_default_value(const StringName &p_name) const { +Variant VisualScript::get_variable_default_value(const StringName &p_name) const { ERR_FAIL_COND_V(!variables.has(p_name), Variant()); return variables[p_name].default_value; } -void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) { +void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].info = p_info; @@ -645,14 +601,13 @@ void VisualScript::set_variable_info(const StringName &p_name, const PropertyInf _update_placeholders(); #endif } -PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const { +PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const { ERR_FAIL_COND_V(!variables.has(p_name), PropertyInfo()); return variables[p_name].info; } void VisualScript::set_variable_export(const StringName &p_name, bool p_export) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name]._export = p_export; @@ -662,30 +617,32 @@ void VisualScript::set_variable_export(const StringName &p_name, bool p_export) } bool VisualScript::get_variable_export(const StringName &p_name) const { - ERR_FAIL_COND_V(!variables.has(p_name), false); return variables[p_name]._export; } void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) { - PropertyInfo pinfo; - if (p_info.has("type")) + if (p_info.has("type")) { pinfo.type = Variant::Type(int(p_info["type"])); - if (p_info.has("name")) + } + if (p_info.has("name")) { pinfo.name = p_info["name"]; - if (p_info.has("hint")) + } + if (p_info.has("hint")) { pinfo.hint = PropertyHint(int(p_info["hint"])); - if (p_info.has("hint_string")) + } + if (p_info.has("hint_string")) { pinfo.hint_string = p_info["hint_string"]; - if (p_info.has("usage")) + } + if (p_info.has("usage")) { pinfo.usage = p_info["usage"]; + } set_variable_info(p_name, pinfo); } Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { - PropertyInfo pinfo = get_variable_info(p_name); Dictionary d; d["type"] = pinfo.type; @@ -698,7 +655,6 @@ Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { } void VisualScript::get_variable_list(List<StringName> *r_variables) const { - for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { r_variables->push_back(E->key()); } @@ -707,17 +663,16 @@ void VisualScript::get_variable_list(List<StringName> *r_variables) const { } void VisualScript::set_instance_base_type(const StringName &p_type) { - ERR_FAIL_COND(instances.size()); base_type = p_type; } void VisualScript::rename_variable(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -736,13 +691,15 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p for (List<int>::Element *E = ids.front(); E; E = E->next()) { Ref<VisualScriptVariableGet> nodeget = get_node(F->get(), E->get()); if (nodeget.is_valid()) { - if (nodeget->get_variable() == p_name) + if (nodeget->get_variable() == p_name) { nodeget->set_variable(p_new_name); + } } else { Ref<VisualScriptVariableSet> nodeset = get_node(F->get(), E->get()); if (nodeset.is_valid()) { - if (nodeset->get_variable() == p_name) + if (nodeset->get_variable() == p_name) { nodeset->set_variable(p_new_name); + } } } } @@ -750,7 +707,6 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p } void VisualScript::add_custom_signal(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(custom_signals.has(p_name)); @@ -759,48 +715,49 @@ void VisualScript::add_custom_signal(const StringName &p_name) { } bool VisualScript::has_custom_signal(const StringName &p_name) const { - return custom_signals.has(p_name); } -void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) { +void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); Argument arg; arg.type = p_type; arg.name = p_name; - if (p_index < 0) + if (p_index < 0) { custom_signals[p_func].push_back(arg); - else + } else { custom_signals[p_func].insert(0, arg); + } } -void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) { +void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); custom_signals[p_func].write[p_argidx].type = p_type; } -Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const { +Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const { ERR_FAIL_COND_V(!custom_signals.has(p_func), Variant::NIL); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), Variant::NIL); return custom_signals[p_func][p_argidx].type; } + void VisualScript::custom_signal_set_argument_name(const StringName &p_func, int p_argidx, const String &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); custom_signals[p_func].write[p_argidx].name = p_name; } -String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const { +String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const { ERR_FAIL_COND_V(!custom_signals.has(p_func), String()); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), String()); return custom_signals[p_func][p_argidx].name; } -void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) { +void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -808,12 +765,11 @@ void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p } int VisualScript::custom_signal_get_argument_count(const StringName &p_func) const { - ERR_FAIL_COND_V(!custom_signals.has(p_func), 0); return custom_signals[p_func].size(); } -void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) { +void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -821,19 +777,19 @@ void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_a SWAP(custom_signals[p_func].write[p_argidx], custom_signals[p_func].write[p_with_argidx]); } -void VisualScript::remove_custom_signal(const StringName &p_name) { +void VisualScript::remove_custom_signal(const StringName &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); custom_signals.erase(p_name); } void VisualScript::rename_custom_signal(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -846,7 +802,6 @@ void VisualScript::rename_custom_signal(const StringName &p_name, const StringNa } void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { r_custom_signals->push_back(E->key()); } @@ -855,11 +810,11 @@ void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) co } int VisualScript::get_available_id() const { - int max_id = 0; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - if (E->get().nodes.empty()) + if (E->get().nodes.empty()) { continue; + } int last_id = E->get().nodes.back()->key(); max_id = MAX(max_id, last_id + 1); @@ -871,12 +826,10 @@ int VisualScript::get_available_id() const { ///////////////////////////////// bool VisualScript::can_instance() const { - return true; //ScriptServer::is_scripting_enabled(); } StringName VisualScript::get_instance_base_type() const { - return base_type; } @@ -886,21 +839,20 @@ Ref<Script> VisualScript::get_base_script() const { #ifdef TOOLS_ENABLED void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); } void VisualScript::_update_placeholders() { - - if (placeholders.size() == 0) + if (placeholders.size() == 0) { return; //no bother if no placeholders + } List<PropertyInfo> pinfo; Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -909,7 +861,6 @@ void VisualScript::_update_placeholders() { } for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->update(pinfo, values); } } @@ -917,11 +868,9 @@ void VisualScript::_update_placeholders() { #endif ScriptInstance *VisualScript::instance_create(Object *p_this) { - #ifdef TOOLS_ENABLED if (!ScriptServer::is_scripting_enabled() && !is_tool_script) { - PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(VisualScriptLanguage::singleton, Ref<Script>((Script *)this), p_this)); placeholders.insert(sins); @@ -929,9 +878,9 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -958,17 +907,14 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { } bool VisualScript::instance_has(const Object *p_this) const { - return instances.has((Object *)p_this); } bool VisualScript::has_source_code() const { - return false; } String VisualScript::get_source_code() const { - return String(); } @@ -976,12 +922,10 @@ void VisualScript::set_source_code(const String &p_code) { } Error VisualScript::reload(bool p_keep_state) { - return OK; } bool VisualScript::is_tool() const { - return is_tool_script; } @@ -990,19 +934,15 @@ bool VisualScript::is_valid() const { } ScriptLanguage *VisualScript::get_language() const { - return VisualScriptLanguage::singleton; } bool VisualScript::has_script_signal(const StringName &p_signal) const { - return custom_signals.has(p_signal); } void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); for (int i = 0; i < E->get().size(); i++) { @@ -1017,21 +957,19 @@ void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { } bool VisualScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - - if (!variables.has(p_property)) + if (!variables.has(p_property)) { return false; + } r_value = variables[p_property].default_value; return true; } -void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { +void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { for (int i = 0; i < func->get_argument_count(); i++) { @@ -1048,22 +986,20 @@ void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { } bool VisualScript::has_method(const StringName &p_method) const { - return functions.has(p_method); } -MethodInfo VisualScript::get_method_info(const StringName &p_method) const { +MethodInfo VisualScript::get_method_info(const StringName &p_method) const { const Map<StringName, Function>::Element *E = functions.find(p_method); - if (!E) + if (!E) { return MethodInfo(); + } MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { - for (int i = 0; i < func->get_argument_count(); i++) { PropertyInfo arg; arg.name = func->get_argument_name(i); @@ -1081,7 +1017,6 @@ MethodInfo VisualScript::get_method_info(const StringName &p_method) const { } void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { - List<StringName> vars; get_variable_list(&vars); @@ -1098,8 +1033,9 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED if (has_function(p_member)) { for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) + if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) { return E->key(); + } } } #endif @@ -1108,9 +1044,7 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED bool VisualScript::are_subnodes_edited() const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { if (F->get().node->is_edited()) { return true; @@ -1177,15 +1111,14 @@ MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable } void VisualScript::_set_data(const Dictionary &p_data) { - Dictionary d = p_data; - if (d.has("base_type")) + if (d.has("base_type")) { base_type = d["base_type"]; + } variables.clear(); Array vars = d["variables"]; for (int i = 0; i < vars.size(); i++) { - Dictionary v = vars[i]; StringName name = v["name"]; add_variable(name); @@ -1197,7 +1130,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { custom_signals.clear(); Array sigs = d["signals"]; for (int i = 0; i < sigs.size(); i++) { - Dictionary cs = sigs[i]; add_custom_signal(cs["name"]); @@ -1214,7 +1146,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { Vector2 last_size = Vector2(0.0, 0.0); for (int i = 0; i < funcs.size(); i++) { - Dictionary func = funcs[i]; StringName name = func["name"]; @@ -1264,22 +1195,21 @@ void VisualScript::_set_data(const Dictionary &p_data) { Array sequence_connections = func["sequence_connections"]; for (int j = 0; j < sequence_connections.size(); j += 3) { - sequence_connect(name, sequence_connections[j + 0], sequence_connections[j + 1], sequence_connections[j + 2]); } Array data_connections = func["data_connections"]; for (int j = 0; j < data_connections.size(); j += 4) { - data_connect(name, data_connections[j + 0], data_connections[j + 1], data_connections[j + 2], data_connections[j + 3]); } } - if (d.has("is_tool_script")) + if (d.has("is_tool_script")) { is_tool_script = d["is_tool_script"]; - else + } else { is_tool_script = false; + } // Takes all the rpc methods rpc_functions.clear(); @@ -1307,12 +1237,10 @@ void VisualScript::_set_data(const Dictionary &p_data) { } Dictionary VisualScript::_get_data() const { - Dictionary d; d["base_type"] = base_type; Array vars; for (const Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - Dictionary var = _get_variable_info(E->key()); var["name"] = E->key(); //make sure it's the right one var["default_value"] = E->get().default_value; @@ -1323,7 +1251,6 @@ Dictionary VisualScript::_get_data() const { Array sigs; for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - Dictionary cs; cs["name"] = E->key(); Array args; @@ -1341,7 +1268,6 @@ Dictionary VisualScript::_get_data() const { Array funcs; for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - Dictionary func; func["name"] = E->key(); func["function_id"] = E->get().function_id; @@ -1350,7 +1276,6 @@ Dictionary VisualScript::_get_data() const { Array nodes; for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - nodes.push_back(F->key()); nodes.push_back(F->get().pos); nodes.push_back(F->get().node); @@ -1361,7 +1286,6 @@ Dictionary VisualScript::_get_data() const { Array sequence_connections; for (const Set<SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - sequence_connections.push_back(F->get().from_node); sequence_connections.push_back(F->get().from_output); sequence_connections.push_back(F->get().to_node); @@ -1372,7 +1296,6 @@ Dictionary VisualScript::_get_data() const { Array data_connections; for (const Set<DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - data_connections.push_back(F->get().from_node); data_connections.push_back(F->get().from_port); data_connections.push_back(F->get().to_node); @@ -1392,7 +1315,6 @@ Dictionary VisualScript::_get_data() const { } void VisualScript::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_function", "name"), &VisualScript::add_function); ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function); ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function); @@ -1455,7 +1377,6 @@ void VisualScript::_bind_methods() { } VisualScript::VisualScript() { - base_type = "Object"; is_tool_script = false; } @@ -1482,7 +1403,6 @@ Set<int> VisualScript::get_output_sequence_ports_connected(const String &edited_ } VisualScript::~VisualScript() { - while (!functions.empty()) { remove_function(functions.front()->key()); } @@ -1491,10 +1411,10 @@ VisualScript::~VisualScript() { //////////////////////////////////////////// bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) { - Map<StringName, Variant>::Element *E = variables.find(p_name); - if (!E) + if (!E) { return false; + } E->get() = p_value; @@ -1502,45 +1422,45 @@ bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) } bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - const Map<StringName, Variant>::Element *E = variables.find(p_name); - if (!E) + if (!E) { return false; + } r_ret = E->get(); return true; } -void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { +void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; p_properties->push_back(p); } } -Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { +Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { const Map<StringName, VisualScript::Variable>::Element *E = script->variables.find(p_name); if (!E) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } ERR_FAIL_V(Variant::NIL); } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return E->get().info.type; } void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -1548,10 +1468,8 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) { - Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node; if (vsf.is_valid()) { - for (int i = 0; i < vsf->get_argument_count(); i++) { PropertyInfo arg; arg.name = vsf->get_argument_name(i); @@ -1569,10 +1487,11 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { p_list->push_back(mi); } } -bool VisualScriptInstance::has_method(const StringName &p_method) const { - if (p_method == script->get_default_func()) +bool VisualScriptInstance::has_method(const StringName &p_method) const { + if (p_method == script->get_default_func()) { return false; + } return script->functions.has(p_method); } @@ -1581,29 +1500,27 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const { #define VSDEBUG(m_text) void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Callable::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node) { - ERR_FAIL_COND(node->pass_idx == -1); - if (pass_stack[node->pass_idx] == p_pass) + if (pass_stack[node->pass_idx] == p_pass) { return; + } pass_stack[node->pass_idx] = p_pass; if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, r_error_node); - if (r_error.error != Callable::CallError::CALL_OK) + if (r_error.error != Callable::CallError::CALL_OK) { return; + } } } for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1628,7 +1545,6 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int } Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Callable::CallError &r_error) { - Map<StringName, Function>::Element *F = functions.find(p_method); ERR_FAIL_COND_V(!F, Variant()); Function *f = &F->get(); @@ -1659,7 +1575,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p #endif while (true) { - p_pass++; //increment pass current_node_id = node->get_id(); @@ -1678,16 +1593,13 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p input_args[i] = &variant_stack[i]; } } else { - //run dependencies first if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, &node); if (r_error.error != Callable::CallError::CALL_OK) { error = true; @@ -1698,12 +1610,10 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (!error) { - //setup input pointers normally VSDEBUG("INPUT PORTS: " + itos(node->input_port_count)); for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1719,8 +1629,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } } - if (error) + if (error) { break; + } //setup output pointers @@ -1766,7 +1677,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } else { Ref<VisualScriptFunctionState> state = *working_mem; if (!state.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Node yielded, but did not return a function state in the first working memory."); error = true; @@ -1805,15 +1715,17 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool do_break = false; if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - - if (EngineDebugger::get_script_debugger()->get_depth() <= 0) + if (EngineDebugger::get_script_debugger()->get_depth() <= 0) { EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); - if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) + } + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) { do_break = true; + } } - if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) { do_break = true; + } if (do_break) { VisualScriptLanguage::singleton->debug_break("Breakpoint", true); @@ -1828,7 +1740,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p if (ret & VisualScriptNodeInstance::STEP_EXIT_FUNCTION_BIT) { if (node->get_working_memory_size() == 0) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Return value must be assigned to first element of node working memory! Fix your node please."); error = true; @@ -1861,13 +1772,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (flow_stack) { - //update flow stack pos (may have changed) flow_stack[flow_stack_pos] = current_node_id; //add stack push bit if requested if (ret & VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) { - flow_stack[flow_stack_pos] |= VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT; sequence_bits[node->sequence_index] = true; //remember sequence bit VSDEBUG("NEXT SEQ - FLAG BIT"); @@ -1888,7 +1797,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p break; //simply exit without value or error } } else if (next) { - if (sequence_bits[next->sequence_index]) { // what happened here is that we are entering a node that is in the middle of doing a sequence (pushed stack) from the front // because each node has a working memory, we can't really do a sub-sequence @@ -1898,7 +1806,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - if ((flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK) == next->get_id()) { flow_stack_pos = i; //roll back and remove bit flow_stack[i] = next->get_id(); @@ -1940,10 +1847,8 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - VSDEBUG("FS " + itos(i) + " - " + itos(flow_stack[i])); if (flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT) { - node = instances[flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK]; flow_stack_pos = i; found = true; @@ -1959,13 +1864,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p VSDEBUG("NO NEXT NODE, GO BACK TO: " + itos(flow_stack_pos)); } } else { - node = next; //stackless mode, simply assign next node } } if (error) { - //error // function, file, line, error, explanation String err_file = script->get_path(); @@ -1973,7 +1876,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p int err_line = current_node_id; //not a line but it works as one if (node && (r_error.error != Callable::CallError::CALL_ERROR_INVALID_METHOD || error_str == String())) { - if (error_str != String()) { error_str += " "; } @@ -1996,13 +1898,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p // debugger break did not happen if (!VisualScriptLanguage::singleton->debug_break(error_str, false)) { - _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), ERR_HANDLER_SCRIPT); } //} } else { - //return_value= } @@ -2021,7 +1921,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; //ok by default Map<StringName, Function>::Element *F = functions.find(p_method); @@ -2109,7 +2008,6 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p } void VisualScriptInstance::notification(int p_notification) { - //do nothing as this is called using virtual Variant what = p_notification; @@ -2124,22 +2022,24 @@ String VisualScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } Ref<Script> VisualScriptInstance::get_script() const { - return script; } @@ -2184,7 +2084,6 @@ MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_ } void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) { - script = p_script; owner = p_owner; source = p_script->get_path(); @@ -2195,16 +2094,21 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (Object::cast_to<Node>(p_owner)) { //turn on these if they exist and base is a node Node *node = Object::cast_to<Node>(p_owner); - if (p_script->functions.has("_process")) + if (p_script->functions.has("_process")) { node->set_process(true); - if (p_script->functions.has("_physics_process")) + } + if (p_script->functions.has("_physics_process")) { node->set_physics_process(true); - if (p_script->functions.has("_input")) + } + if (p_script->functions.has("_input")) { node->set_process_input(true); - if (p_script->functions.has("_unhandled_input")) + } + if (p_script->functions.has("_unhandled_input")) { node->set_process_unhandled_input(true); - if (p_script->functions.has("_unhandled_key_input")) + } + if (p_script->functions.has("_unhandled_key_input")) { node->set_process_unhandled_key_input(true); + } } for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { @@ -2212,7 +2116,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -2251,7 +2154,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //first create the nodes for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - Ref<VisualScriptNode> node = F->get().node; VisualScriptNodeInstance *instance = node->instance(this); //create instance @@ -2272,7 +2174,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (instance->input_port_count) { instance->input_ports = memnew_arr(int, instance->input_port_count); for (int i = 0; i < instance->input_port_count; i++) { - instance->input_ports[i] = -1; //if not assigned, will become default value } } @@ -2297,10 +2198,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o StringName var_name; - if (Object::cast_to<VisualScriptLocalVar>(*node)) + if (Object::cast_to<VisualScriptLocalVar>(*node)) { var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges(); - else + } else { var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges(); + } if (!local_var_indices.has(var_name)) { local_var_indices[var_name] = function.max_stack; @@ -2327,7 +2229,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //second pass, do data connections for (const Set<VisualScript::DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - VisualScript::DataConnection dc = F->get(); ERR_CONTINUE(!instances.has(dc.from_node)); VisualScriptNodeInstance *from = instances[dc.from_node]; @@ -2337,7 +2238,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o ERR_CONTINUE(dc.to_port >= to->input_port_count); if (from->output_ports[dc.from_port] == -1) { - int stack_pos = function.max_stack++; from->output_ports[dc.from_port] = stack_pos; } @@ -2357,7 +2257,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //third pass, do sequence connections for (const Set<VisualScript::SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - VisualScript::SequenceConnection sc = F->get(); ERR_CONTINUE(!instances.has(sc.from_node)); VisualScriptNodeInstance *from = instances[sc.from_node]; @@ -2373,7 +2272,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // 2) connect unassigned output ports to trash for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - ERR_CONTINUE(!instances.has(F->key())); Ref<VisualScriptNode> node = F->get().node; @@ -2382,7 +2280,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // connect to default values for (int i = 0; i < instance->input_port_count; i++) { if (instance->input_ports[i] == -1) { - //unassigned, connect to default val instance->input_ports[i] = default_values.size() | VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT; default_values.push_back(node->get_default_input_value(i)); @@ -2402,7 +2299,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } ScriptLanguage *VisualScriptInstance::get_language() { - return VisualScriptLanguage::singleton; } @@ -2410,7 +2306,6 @@ VisualScriptInstance::VisualScriptInstance() { } VisualScriptInstance::~VisualScriptInstance() { - { MutexLock lock(VisualScriptLanguage::singleton->lock); @@ -2427,7 +2322,6 @@ VisualScriptInstance::~VisualScriptInstance() { ///////////////////// Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2448,7 +2342,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } else if (p_argcount == 1) { //noooneee, reserved for me, me and only me. } else { - for (int i = 0; i < p_argcount - 1; i++) { args.push_back(*p_args[i]); } @@ -2475,7 +2368,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds) { - Vector<Variant> binds; for (int i = 0; i < p_binds.size(); i++) { binds.push_back(p_binds[i]); @@ -2485,12 +2377,10 @@ void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p } bool VisualScriptFunctionState::is_valid() const { - return function != StringName(); } Variant VisualScriptFunctionState::resume(Array p_args) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2512,7 +2402,6 @@ Variant VisualScriptFunctionState::resume(Array p_args) { } void VisualScriptFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_signal", "obj", "signals", "args"), &VisualScriptFunctionState::connect_to_signal); ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("is_valid"), &VisualScriptFunctionState::is_valid); @@ -2523,7 +2412,6 @@ VisualScriptFunctionState::VisualScriptFunctionState() { } VisualScriptFunctionState::~VisualScriptFunctionState() { - if (function != StringName()) { Variant *s = ((Variant *)stack.ptr()); for (int i = 0; i < variant_stack_size; i++) { @@ -2535,37 +2423,39 @@ VisualScriptFunctionState::~VisualScriptFunctionState() { /////////////////////////////////////////////// String VisualScriptLanguage::get_name() const { - return "VisualScript"; } /* LANGUAGE FUNCTIONS */ void VisualScriptLanguage::init() { } -String VisualScriptLanguage::get_type() const { +String VisualScriptLanguage::get_type() const { return "VisualScript"; } -String VisualScriptLanguage::get_extension() const { +String VisualScriptLanguage::get_extension() const { return "vs"; } -Error VisualScriptLanguage::execute_file(const String &p_path) { +Error VisualScriptLanguage::execute_file(const String &p_path) { return OK; } + void VisualScriptLanguage::finish() { } /* EDITOR FUNCTIONS */ void VisualScriptLanguage::get_reserved_words(List<String> *p_words) const { } + void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { } + void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { } -Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { +Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { Ref<VisualScript> script; script.instance(); script->set_instance_base_type(p_base_class_name); @@ -2573,7 +2463,6 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const } bool VisualScriptLanguage::is_using_templates() { - return true; } @@ -2583,32 +2472,32 @@ void VisualScriptLanguage::make_template(const String &p_class_name, const Strin } bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { - return false; } -Script *VisualScriptLanguage::create_script() const { +Script *VisualScriptLanguage::create_script() const { return memnew(VisualScript); } -bool VisualScriptLanguage::has_named_classes() const { +bool VisualScriptLanguage::has_named_classes() const { return false; } -bool VisualScriptLanguage::supports_builtin_mode() const { +bool VisualScriptLanguage::supports_builtin_mode() const { return true; } -int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const { +int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const { return -1; } -String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { +String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { return String(); } void VisualScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { } + void VisualScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { } @@ -2618,7 +2507,6 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c //break because of parse error if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; _debug_error = p_error; @@ -2630,9 +2518,7 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c } bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_error = p_error; @@ -2644,21 +2530,21 @@ bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_conti } String VisualScriptLanguage::debug_get_error() const { - return _debug_error; } int VisualScriptLanguage::debug_get_stack_level_count() const { - - if (_debug_parse_err_node >= 0) + if (_debug_parse_err_node >= 0) { return 1; + } return _debug_call_stack_pos; } -int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_node >= 0) +int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { + if (_debug_parse_err_node >= 0) { return _debug_parse_err_node; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1); @@ -2666,28 +2552,31 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { return *(_call_stack[l].current_id); } -String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_node >= 0) +String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { + if (_debug_parse_err_node >= 0) { return ""; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; return *_call_stack[l].function; } -String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_node >= 0) +String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { + if (_debug_parse_err_node >= 0) { return _debug_parse_err_file; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; return _call_stack[l].instance->get_script_ptr()->get_path(); } -void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) +void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); @@ -2724,7 +2613,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String } for (int i = 0; i < node->output_port_count; i++) { - String name = node->get_base_node()->get_output_value_port_info(i).name; if (name == String()) { name = "out_" + itos(i); @@ -2759,17 +2647,19 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String } */ } -void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) +void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; Ref<VisualScript> vs = _call_stack[l].instance->get_script(); - if (vs.is_null()) + if (vs.is_null()) { return; + } List<StringName> vars; vs->get_variable_list(&vars); @@ -2783,48 +2673,48 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<Strin } void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - //no globals are really reachable in gdscript } -String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { +String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { return ""; } void VisualScriptLanguage::reload_all_scripts() { } + void VisualScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { } + /* LOADER FUNCTIONS */ void VisualScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("vs"); } + void VisualScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { } + void VisualScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { } void VisualScriptLanguage::profiling_start() { } + void VisualScriptLanguage::profiling_stop() { } int VisualScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } int VisualScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } VisualScriptLanguage *VisualScriptLanguage::singleton = nullptr; void VisualScriptLanguage::add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func) { - ERR_FAIL_COND(register_funcs.has(p_name)); register_funcs[p_name] = p_func; } @@ -2835,21 +2725,18 @@ void VisualScriptLanguage::remove_register_func(const String &p_name) { } Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &p_name) { - ERR_FAIL_COND_V(!register_funcs.has(p_name), Ref<VisualScriptNode>()); return register_funcs[p_name](p_name); } void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) { - for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) { r_names->push_back(E->key()); } } VisualScriptLanguage::VisualScriptLanguage() { - notification = "_notification"; _step = "_step"; _subcall = "_subcall"; @@ -2873,7 +2760,6 @@ VisualScriptLanguage::VisualScriptLanguage() { } VisualScriptLanguage::~VisualScriptLanguage() { - if (_call_stack) { memdelete_arr(_call_stack); } diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index c154e56703..d54b1faf42 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -89,7 +89,6 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0; struct TypeGuess { - Variant::Type type; StringName gdclass; Ref<Script> script; @@ -166,16 +165,13 @@ public: }; class VisualScript : public Script { - GDCLASS(VisualScript, Script); RES_BASE_EXTENSION("vs"); public: struct SequenceConnection { - union { - struct { uint64_t from_node : 24; uint64_t from_output : 16; @@ -185,15 +181,12 @@ public: }; bool operator<(const SequenceConnection &p_connection) const { - return id < p_connection.id; } }; struct DataConnection { - union { - struct { uint64_t from_node : 24; uint64_t from_port : 8; @@ -204,7 +197,6 @@ public: }; bool operator<(const DataConnection &p_connection) const { - return id < p_connection.id; } }; @@ -431,20 +423,20 @@ public: String to_string(bool *r_valid); bool set_variable(const StringName &p_variable, const Variant &p_value) { - Map<StringName, Variant>::Element *E = variables.find(p_variable); - if (!E) + if (!E) { return false; + } E->get() = p_value; return true; } bool get_variable(const StringName &p_variable, Variant *r_variable) const { - const Map<StringName, Variant>::Element *E = variables.find(p_variable); - if (!E) + if (!E) { return false; + } *r_variable = E->get(); return true; @@ -476,7 +468,6 @@ public: }; class VisualScriptFunctionState : public Reference { - GDCLASS(VisualScriptFunctionState, Reference); friend class VisualScriptInstance; @@ -507,11 +498,9 @@ public: typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String &p_type); class VisualScriptLanguage : public ScriptLanguage { - Map<String, VisualScriptNodeRegisterFunc> register_funcs; struct CallLevel { - Variant *stack; Variant **work_mem; const StringName *function; @@ -540,12 +529,13 @@ public: bool debug_break_parse(const String &p_file, int p_node, const String &p_error); _FORCE_INLINE_ void enter_function(VisualScriptInstance *p_instance, const StringName *p_function, Variant *p_stack, Variant **p_work_mem, int *current_id) { - - if (Thread::get_main_id() != Thread::get_caller_id()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1); + } if (_debug_call_stack_pos >= _debug_max_call_stack) { //stack overflow @@ -563,15 +553,15 @@ public: } _FORCE_INLINE_ void exit_function() { - - if (Thread::get_main_id() != Thread::get_caller_id()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1); + } if (_debug_call_stack_pos == 0) { - _debug_error = "Stack Underflow (Engine Bug)"; EngineDebugger::get_script_debugger()->debug(this); return; @@ -645,7 +635,6 @@ public: //aid for registering template <class T> static Ref<VisualScriptNode> create_node_generic(const String &p_name) { - Ref<T> node; node.instance(); return node; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index bb291b1cb6..a0dcd76d10 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -110,30 +110,26 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX }; VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) { - for (int i = 0; i < FUNC_MAX; i++) { - if (p_string == func_name[i]) + if (p_string == func_name[i]) { return BuiltinFunc(i); + } } return FUNC_MAX; } String VisualScriptBuiltinFunc::get_func_name(BuiltinFunc p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String()); return func_name[p_func]; } int VisualScriptBuiltinFunc::get_output_sequence_port_count() const { - return has_input_sequence_port() ? 1 : 0; } bool VisualScriptBuiltinFunc::has_input_sequence_port() const { - switch (func) { - case MATH_RANDOMIZE: case TEXT_PRINT: case TEXT_PRINTERR: @@ -145,9 +141,7 @@ bool VisualScriptBuiltinFunc::has_input_sequence_port() const { } int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { - switch (p_func) { - case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: @@ -228,11 +222,10 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { } int VisualScriptBuiltinFunc::get_input_value_port_count() const { - return get_func_argument_count(func); } -int VisualScriptBuiltinFunc::get_output_value_port_count() const { +int VisualScriptBuiltinFunc::get_output_value_port_count() const { switch (func) { case MATH_RANDOMIZE: case TEXT_PRINT: @@ -250,14 +243,11 @@ int VisualScriptBuiltinFunc::get_output_value_port_count() const { } String VisualScriptBuiltinFunc::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const { - switch (func) { - case MATH_SIN: case MATH_COS: case MATH_TAN: @@ -280,96 +270,106 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::FLOAT, "s"); } break; case MATH_ATAN2: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "y"); - else + } else { return PropertyInfo(Variant::FLOAT, "x"); + } } break; case MATH_FMOD: case MATH_FPOSMOD: case LOGIC_MAX: case LOGIC_MIN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "a"); - else + } else { return PropertyInfo(Variant::FLOAT, "b"); + } } break; case MATH_POSMOD: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "a"); - else + } else { return PropertyInfo(Variant::INT, "b"); + } } break; case MATH_POW: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "base"); - else + } else { return PropertyInfo(Variant::FLOAT, "exp"); + } } break; case MATH_EASE: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "s"); - else + } else { return PropertyInfo(Variant::FLOAT, "curve"); + } } break; case MATH_STEP_DECIMALS: { return PropertyInfo(Variant::FLOAT, "step"); } break; case MATH_STEPIFY: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "s"); - else + } else { return PropertyInfo(Variant::FLOAT, "steps"); + } } break; case MATH_LERP: case MATH_LERP_ANGLE: case MATH_INVERSE_LERP: case MATH_SMOOTHSTEP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "to"); - else + } else { return PropertyInfo(Variant::FLOAT, "weight"); + } } break; case MATH_RANGE_LERP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "istart"); - else if (p_idx == 2) + } else if (p_idx == 2) { return PropertyInfo(Variant::FLOAT, "istop"); - else if (p_idx == 3) + } else if (p_idx == 3) { return PropertyInfo(Variant::FLOAT, "ostart"); - else + } else { return PropertyInfo(Variant::FLOAT, "ostop"); + } } break; case MATH_MOVE_TOWARD: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "to"); - else + } else { return PropertyInfo(Variant::FLOAT, "delta"); + } } break; case MATH_DECTIME: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "amount"); - else + } else { return PropertyInfo(Variant::FLOAT, "step"); + } } break; case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: { - } break; case MATH_RANDOM: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else + } else { return PropertyInfo(Variant::FLOAT, "to"); + } } break; case MATH_SEED: case MATH_RANDSEED: { @@ -388,33 +388,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::FLOAT, "db"); } break; case MATH_POLAR2CARTESIAN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "r"); - else + } else { return PropertyInfo(Variant::FLOAT, "th"); + } } break; case MATH_CARTESIAN2POLAR: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "x"); - else + } else { return PropertyInfo(Variant::FLOAT, "y"); + } } break; case MATH_WRAP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::INT, "min"); - else + } else { return PropertyInfo(Variant::INT, "max"); + } } break; case MATH_WRAPF: case LOGIC_CLAMP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "min"); - else + } else { return PropertyInfo(Variant::FLOAT, "max"); + } } break; case LOGIC_NEAREST_PO2: { return PropertyInfo(Variant::INT, "value"); @@ -423,16 +427,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::OBJECT, "source"); } break; case FUNC_FUNCREF: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::OBJECT, "instance"); - else + } else { return PropertyInfo(Variant::STRING, "funcname"); + } } break; case TYPE_CONVERT: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::NIL, "what"); - else + } else { return PropertyInfo(Variant::STRING, "type"); + } } break; case TYPE_OF: { return PropertyInfo(Variant::NIL, "what"); @@ -453,29 +459,30 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::NIL, "value"); } break; case STR_TO_VAR: { - return PropertyInfo(Variant::STRING, "string"); } break; case VAR_TO_STR: case VAR_TO_BYTES: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::NIL, "var"); - else + } else { return PropertyInfo(Variant::BOOL, "full_objects"); + } } break; case BYTES_TO_VAR: { - - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytes"); - else + } else { return PropertyInfo(Variant::BOOL, "allow_objects"); + } } break; case COLORN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::STRING, "name"); - else + } else { return PropertyInfo(Variant::FLOAT, "alpha"); + } } break; case FUNC_MAX: { } @@ -485,10 +492,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) const { - Variant::Type t = Variant::NIL; switch (func) { - case MATH_SIN: case MATH_COS: case MATH_TAN: @@ -545,10 +550,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case MATH_RANDOMIZE: { - } break; case MATH_RAND: { - t = Variant::INT; } break; case MATH_RANDF: @@ -556,14 +559,13 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons t = Variant::FLOAT; } break; case MATH_SEED: { - } break; case MATH_RANDSEED: { - - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "rnd"); - else + } else { return PropertyInfo(Variant::INT, "seed"); + } } break; case MATH_DEG2RAD: case MATH_RAD2DEG: @@ -582,24 +584,20 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case LOGIC_MAX: case LOGIC_MIN: case LOGIC_CLAMP: { - } break; case LOGIC_NEAREST_PO2: { t = Variant::NIL; } break; case OBJ_WEAKREF: { - t = Variant::OBJECT; } break; case FUNC_FUNCREF: { - t = Variant::OBJECT; } break; case TYPE_CONVERT: { - } break; case TEXT_ORD: case TYPE_OF: { @@ -607,41 +605,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case TYPE_EXISTS: { - t = Variant::BOOL; } break; case TEXT_CHAR: case TEXT_STR: { - t = Variant::STRING; } break; case TEXT_PRINT: { - } break; case TEXT_PRINTERR: { - } break; case TEXT_PRINTRAW: { - } break; case VAR_TO_STR: { t = Variant::STRING; } break; case STR_TO_VAR: { - } break; case VAR_TO_BYTES: { - if (p_idx == 0) + if (p_idx == 0) { t = Variant::PACKED_BYTE_ARRAY; - else + } else { t = Variant::BOOL; + } } break; case BYTES_TO_VAR: { - if (p_idx == 1) + if (p_idx == 1) { t = Variant::BOOL; + } } break; case COLORN: { t = Variant::COLOR; @@ -658,15 +652,14 @@ String VisualScriptBuiltinFunc::get_caption() const { return "BuiltinFunc"; } + */ String VisualScriptBuiltinFunc::get_caption() const { - return func_name[func]; } void VisualScriptBuiltinFunc::set_func(BuiltinFunc p_which) { - ERR_FAIL_INDEX(p_which, FUNC_MAX); func = p_which; _change_notify(); @@ -686,197 +679,159 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::get_func() { } void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Callable::CallError &r_error, String &r_error_str) { - switch (p_func) { case VisualScriptBuiltinFunc::MATH_SIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::sin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COS: { - VALIDATE_ARG_NUM(0); *r_return = Math::cos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::tan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_SINH: { - VALIDATE_ARG_NUM(0); *r_return = Math::sinh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COSH: { - VALIDATE_ARG_NUM(0); *r_return = Math::cosh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TANH: { - VALIDATE_ARG_NUM(0); *r_return = Math::tanh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ASIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::asin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ACOS: { - VALIDATE_ARG_NUM(0); *r_return = Math::acos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::atan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN2: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SQRT: { - VALIDATE_ARG_NUM(0); *r_return = Math::sqrt((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_FMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FPOSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_POSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FLOOR: { - VALIDATE_ARG_NUM(0); *r_return = Math::floor((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_CEIL: { - VALIDATE_ARG_NUM(0); *r_return = Math::ceil((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ROUND: { - VALIDATE_ARG_NUM(0); *r_return = Math::round((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ABS: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = ABS(i); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = Math::abs(r); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case VisualScriptBuiltinFunc::MATH_SIGN: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case VisualScriptBuiltinFunc::MATH_POW: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LOG: { - VALIDATE_ARG_NUM(0); *r_return = Math::log((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EXP: { - VALIDATE_ARG_NUM(0); *r_return = Math::exp((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISNAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_nan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISINF: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_inf((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EASE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_STEP_DECIMALS: { - VALIDATE_ARG_NUM(0); *r_return = Math::step_decimals((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_STEPIFY: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_LERP_ANGLE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_INVERSE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_RANGE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -891,14 +846,12 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_MOVE_TOWARD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -915,20 +868,17 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::randf(); } break; case VisualScriptBuiltinFunc::MATH_RANDOM: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; Math::seed(seed); } break; case VisualScriptBuiltinFunc::MATH_RANDSEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; int ret = Math::rand_from_seed(&seed); @@ -939,22 +889,18 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::MATH_DEG2RAD: { - VALIDATE_ARG_NUM(0); *r_return = Math::deg2rad((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_RAD2DEG: { - VALIDATE_ARG_NUM(0); *r_return = Math::rad2deg((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_LINEAR2DB: { - VALIDATE_ARG_NUM(0); *r_return = Math::linear2db((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_DB2LINEAR: { - VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; @@ -985,9 +931,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::LOGIC_MAX: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MAX(a, b); @@ -1003,9 +947,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::LOGIC_MIN: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MIN(a, b); @@ -1020,9 +962,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } } break; case VisualScriptBuiltinFunc::LOGIC_CLAMP: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; int64_t c = *p_inputs[2]; @@ -1040,15 +980,12 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } } break; case VisualScriptBuiltinFunc::LOGIC_NEAREST_PO2: { - VALIDATE_ARG_NUM(0); int64_t num = *p_inputs[0]; *r_return = next_power_of_2(num); } break; case VisualScriptBuiltinFunc::OBJ_WEAKREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1057,10 +994,8 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } if (p_inputs[0]->is_ref()) { - REF r = *p_inputs[0]; if (!r.is_valid()) { - return; } @@ -1070,7 +1005,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } else { Object *obj = *p_inputs[0]; if (!obj) { - return; } Ref<WeakRef> wref = memnew(WeakRef); @@ -1080,9 +1014,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::FUNC_FUNCREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1090,7 +1022,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in return; } if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING; @@ -1107,11 +1038,9 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::TYPE_CONVERT: { - VALIDATE_ARG_NUM(1); int type = *p_inputs[1]; if (type < 0 || type >= Variant::VARIANT_MAX) { - r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1119,29 +1048,24 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in return; } else { - *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error); } } break; case VisualScriptBuiltinFunc::TYPE_OF: { - *r_return = p_inputs[0]->get_type(); } break; case VisualScriptBuiltinFunc::TYPE_EXISTS: { - *r_return = ClassDB::class_exists(*p_inputs[0]); } break; case VisualScriptBuiltinFunc::TEXT_CHAR: { - CharType result[2] = { *p_inputs[0], 0 }; *r_return = String(result); } break; case VisualScriptBuiltinFunc::TEXT_ORD: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1165,39 +1089,33 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::TEXT_STR: { - String str = *p_inputs[0]; *r_return = str; } break; case VisualScriptBuiltinFunc::TEXT_PRINT: { - String str = *p_inputs[0]; print_line(str); } break; case VisualScriptBuiltinFunc::TEXT_PRINTERR: { - String str = *p_inputs[0]; print_error(str); } break; case VisualScriptBuiltinFunc::TEXT_PRINTRAW: { - String str = *p_inputs[0]; OS::get_singleton()->print("%s", str.utf8().get_data()); } break; case VisualScriptBuiltinFunc::VAR_TO_STR: { - String vars; VariantWriter::write_to_string(*p_inputs[0], vars); *r_return = vars; } break; case VisualScriptBuiltinFunc::STR_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1223,7 +1141,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::VAR_TO_BYTES: { - if (p_inputs[1]->get_type() != Variant::BOOL) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; @@ -1250,7 +1167,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = barr; } break; case VisualScriptBuiltinFunc::BYTES_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::PACKED_BYTE_ARRAY) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1283,7 +1199,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::COLORN: { - VALIDATE_ARG_NUM(1); Color color = Color::named(*p_inputs[0]); @@ -1309,14 +1224,12 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - VisualScriptBuiltinFunc::exec_func(func, p_inputs, p_outputs[0], r_error, r_error_str); return 0; } }; VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceBuiltinFunc *instance = memnew(VisualScriptNodeInstanceBuiltinFunc); instance->node = this; instance->instance = p_instance; @@ -1325,16 +1238,15 @@ VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance } void VisualScriptBuiltinFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_func", "which"), &VisualScriptBuiltinFunc::set_func); ClassDB::bind_method(D_METHOD("get_func"), &VisualScriptBuiltinFunc::get_func); String cc; for (int i = 0; i < FUNC_MAX; i++) { - - if (i > 0) + if (i > 0) { cc += ","; + } cc += func_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, cc), "set_func", "get_func"); @@ -1411,24 +1323,20 @@ void VisualScriptBuiltinFunc::_bind_methods() { } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func) { - this->func = func; } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc() { - func = MATH_SIN; } template <VisualScriptBuiltinFunc::BuiltinFunc func> static Ref<VisualScriptNode> create_builtin_func_node(const String &p_name) { - Ref<VisualScriptBuiltinFunc> node = memnew(VisualScriptBuiltinFunc(func)); return node; } void register_visual_script_builtin_func_node() { - VisualScriptLanguage::singleton->add_register_func("functions/built_in/sin", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIN>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/cos", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COS>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/tan", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TAN>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index d950f858d4..1b186353f1 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptBuiltinFunc : public VisualScriptNode { - GDCLASS(VisualScriptBuiltinFunc, VisualScriptNode); public: diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 3649486724..fea7d151df 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -46,7 +46,6 @@ #ifdef TOOLS_ENABLED class VisualScriptEditorSignalEdit : public Object { - GDCLASS(VisualScriptEditorSignalEdit, Object); StringName sig; @@ -62,22 +61,21 @@ protected: } void _sig_changed() { - _change_notify(); emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - - if (sig == StringName()) + if (sig == StringName()) { return false; + } if (p_name == "argument_count") { - int new_argc = p_value; int argc = script->custom_signal_get_argument_count(sig); - if (argc == new_argc) + if (argc == new_argc) { return true; + } undo_redo->create_action(TTR("Change Signal Arguments")); @@ -87,9 +85,7 @@ protected: undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1); } } else if (new_argc > argc) { - for (int i = argc; i < new_argc; i++) { - undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1); undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc); } @@ -107,7 +103,6 @@ protected: ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false); String what = String(p_name).get_slice("/", 2); if (what == "type") { - int old_type = script->custom_signal_get_argument_type(sig, idx); int new_type = p_value; undo_redo->create_action(TTR("Change Argument Type")); @@ -119,7 +114,6 @@ protected: } if (what == "name") { - String old_name = script->custom_signal_get_argument_name(sig, idx); String new_name = p_value; undo_redo->create_action(TTR("Change Argument name")); @@ -134,9 +128,9 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - - if (sig == StringName()) + if (sig == StringName()) { return false; + } if (p_name == "argument_count") { r_ret = script->custom_signal_get_argument_count(sig); @@ -159,9 +153,9 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - - if (sig == StringName()) + if (sig == StringName()) { return; + } p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Variant"; @@ -177,7 +171,6 @@ protected: public: void edit(const StringName &p_sig) { - sig = p_sig; _change_notify(); } @@ -186,7 +179,6 @@ public: }; class VisualScriptEditorVariableEdit : public Object { - GDCLASS(VisualScriptEditorVariableEdit, Object); StringName var; @@ -203,20 +195,18 @@ protected: } void _var_changed() { - _change_notify(); emit_signal("changed"); } void _var_value_changed() { - _change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - - if (var == StringName()) + if (var == StringName()) { return false; + } if (String(p_name) == "value") { undo_redo->create_action(TTR("Set Variable Default Value")); @@ -232,7 +222,6 @@ protected: Dictionary d = script->call("get_variable_info", var); if (String(p_name) == "type") { - Dictionary dc = d.duplicate(); dc["type"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -245,7 +234,6 @@ protected: } if (String(p_name) == "hint") { - Dictionary dc = d.duplicate(); dc["hint"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -258,7 +246,6 @@ protected: } if (String(p_name) == "hint_string") { - Dictionary dc = d.duplicate(); dc["hint_string"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -280,9 +267,9 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - - if (var == StringName()) + if (var == StringName()) { return false; + } if (String(p_name) == "value") { r_ret = script->get_variable_default_value(var); @@ -312,9 +299,9 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - - if (var == StringName()) + if (var == StringName()) { return; + } String argt = "Variant"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { @@ -330,7 +317,6 @@ protected: public: void edit(const StringName &p_var) { - var = p_var; _change_notify(); } @@ -340,7 +326,7 @@ public: static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { Color color; - if (dark_theme) + if (dark_theme) { switch (p_type) { case Variant::NIL: color = Color(0.41, 0.93, 0.74); @@ -446,7 +432,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { default: color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7); } - else + } else { switch (p_type) { case Variant::NIL: color = Color(0.15, 0.89, 0.63); @@ -552,12 +538,12 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { default: color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.3, 0.3); } + } return color; } void VisualScriptEditor::_update_graph_connections() { - graph->clear_connections(); List<StringName> funcs; @@ -569,12 +555,10 @@ void VisualScriptEditor::_update_graph_connections() { } for (List<StringName>::Element *F = funcs.front(); F; F = F->next()) { - List<VisualScript::SequenceConnection> sequence_conns; script->get_sequence_connection_list(F->get(), &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0); } @@ -582,7 +566,6 @@ void VisualScriptEditor::_update_graph_connections() { script->get_data_connection_list(F->get(), &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - VisualScript::DataConnection dc = E->get(); Ref<VisualScriptNode> from_node = script->get_node(F->get(), E->get().from_node); @@ -600,9 +583,9 @@ void VisualScriptEditor::_update_graph_connections() { } void VisualScriptEditor::_update_graph(int p_only_id) { - - if (updating_graph) + if (updating_graph) { return; + } updating_graph = true; @@ -610,13 +593,12 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (p_only_id >= 0) { if (graph->has_node(itos(p_only_id))) { Node *gid = graph->get_node(itos(p_only_id)); - if (gid) + if (gid) { memdelete(gid); + } } } else { - for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; @@ -681,9 +663,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { StringName editor_icons = "EditorIcons"; for (List<int>::Element *E = ids.front(); E; E = E->next()) { - - if (p_only_id >= 0 && p_only_id != E->get()) + if (p_only_id >= 0 && p_only_id != E->get()) { continue; + } Ref<VisualScriptNode> node = script->get_node(F->get(), E->get()); Vector2 pos = script->get_node_position(F->get(), E->get()); @@ -721,8 +703,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port), varray(E->get()), CONNECT_DEFERRED); } if (nd_list->is_output_port_editable()) { - if (nd_list->is_input_port_editable()) + if (nd_list->is_input_port_editable()) { hbnc->add_spacer(); + } has_gnode_text = true; Button *btn = memnew(Button); btn->set_text(TTR("Add Output Port")); @@ -758,8 +741,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (node_styles.has(node->get_category())) { Ref<StyleBoxFlat> sbf = node_styles[node->get_category()]; - if (gnode->is_comment()) + if (gnode->is_comment()) { sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode"); + } Color c = sbf->get_border_color(); Color ic = c; @@ -807,12 +791,10 @@ void VisualScriptEditor::_update_graph(int p_only_id) { int mixed_seq_ports = 0; if (!single_seq_output) { - if (node->has_mixed_input_and_sequence_ports()) { mixed_seq_ports = node->get_output_sequence_port_count(); } else { for (int i = 0; i < node->get_output_sequence_port_count(); i++) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -824,7 +806,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) { - bool left_ok = false; Variant::Type left_type = Variant::NIL; String left_name; @@ -852,7 +833,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { vbc->add_child(hbc); vbc->add_child(hbc2); if (left_ok) { - Ref<Texture2D> t; if (left_type >= 0 && left_type < Variant::VARIANT_MAX) { t = type_icons[left_type]; @@ -897,7 +877,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (left_type != Variant::NIL && !script->is_input_value_port_connected(F->get(), E->get(), i)) { - PropertyInfo pi = node->get_input_value_port_info(i); Button *button = memnew(Button); Variant value = node->get_default_input_value(i); @@ -913,7 +892,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); button->connect("draw", callable_mp(this, &VisualScriptEditor::_draw_color_over_button), varray(button, value)); } else if (left_type == Variant::OBJECT && Ref<Resource>(value).is_valid()) { - Ref<Resource> res = value; Array arr; arr.push_back(button->get_instance_id()); @@ -921,10 +899,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) { EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr); } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) { - button->set_text(pi.hint_string.get_slice(",", value)); } else { - button->set_text(value); } button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited), varray(button, E->get(), i)); @@ -940,7 +916,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { hbc2->add_spacer(); if (i < mixed_seq_ports) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -948,7 +923,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (right_ok) { - if (is_vslist) { Button *rmbtn = memnew(Button); rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons")); @@ -1019,12 +993,12 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, bool is_input) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } undo_redo->create_action("Change Port Type"); if (is_input) { @@ -1038,24 +1012,27 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b } void VisualScriptEditor::_update_node_size(int p_id) { - Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to<Control>(node)) + if (Object::cast_to<Control>(node)) { Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller + } } + void VisualScriptEditor::_port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input) { StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } String text; - if (Object::cast_to<LineEdit>(p_name_box)) + if (Object::cast_to<LineEdit>(p_name_box)) { text = Object::cast_to<LineEdit>(p_name_box)->get_text(); - else + } else { return; + } undo_redo->create_action("Change Port Name"); if (is_input) { @@ -1086,7 +1063,6 @@ void VisualScriptEditor::_update_members() { List<StringName> func_names; script->get_function_list(&func_names); for (List<StringName>::Element *E = func_names.front(); E; E = E->next()) { - if (E->get() == default_func) { continue; } @@ -1096,8 +1072,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_metadata(0, E->get()); ti->add_button(0, Control::get_theme_icon("Edit", "EditorIcons"), 0); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } TreeItem *variables = members->create_item(root); @@ -1154,8 +1131,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); ti->set_metadata(0, E->get()); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } TreeItem *_signals = members->create_item(root); @@ -1172,8 +1150,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); ti->set_metadata(0, E->get()); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } String base_type = script->get_instance_base_type(); @@ -1189,9 +1168,9 @@ void VisualScriptEditor::_update_members() { } void VisualScriptEditor::_member_selected() { - - if (updating_members) + if (updating_members) { return; + } TreeItem *ti = members->get_selected(); ERR_FAIL_COND(!ti); @@ -1199,7 +1178,6 @@ void VisualScriptEditor::_member_selected() { selected = ti->get_metadata(0); if (ti->get_parent() == members->get_root()->get_children()) { - #ifdef OSX_ENABLED bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -1213,9 +1191,9 @@ void VisualScriptEditor::_member_selected() { } void VisualScriptEditor::_member_edited() { - - if (updating_members) + if (updating_members) { return; + } TreeItem *ti = members->get_edited(); ERR_FAIL_COND(!ti); @@ -1223,11 +1201,11 @@ void VisualScriptEditor::_member_edited() { String name = ti->get_metadata(0); String new_name = ti->get_text(0); - if (name == new_name) + if (name == new_name) { return; + } if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1236,7 +1214,6 @@ void VisualScriptEditor::_member_edited() { } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1247,7 +1224,6 @@ void VisualScriptEditor::_member_edited() { TreeItem *root = members->get_root(); if (ti->get_parent() == root->get_children()) { - selected = new_name; int node_id = script->get_function_node_id(name); @@ -1271,8 +1247,9 @@ void VisualScriptEditor::_member_edited() { script->get_node_list(E->get(), &lst); for (List<int>::Element *F = lst.front(); F; F = F->next()) { Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get()); - if (!fncall.is_valid()) + if (!fncall.is_valid()) { continue; + } if (fncall->get_function() == name) { undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); undo_redo->add_undo_method(fncall.ptr(), "set_function", name); @@ -1292,7 +1269,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Variable")); undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name); @@ -1309,7 +1285,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Signal")); undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name); @@ -1346,8 +1321,9 @@ void VisualScriptEditor::_create_function() { for (int i = 0; i < func_input_vbox->get_child_count(); i++) { OptionButton *opbtn = Object::cast_to<OptionButton>(func_input_vbox->get_child(i)->get_child(3)); LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1)); - if (!opbtn || !lne) + if (!opbtn || !lne) { continue; + } Variant::Type arg_type = Variant::Type(opbtn->get_selected()); String arg_name = lne->get_text(); func_node->add_argument(arg_type, arg_name); @@ -1392,8 +1368,9 @@ void VisualScriptEditor::_add_func_input() { OptionButton *type_box = memnew(OptionButton); type_box->set_custom_minimum_size(Size2(120 * EDSCALE, 0)); - for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) + for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) { type_box->add_item(Variant::get_type_name(Variant::Type(i))); + } type_box->select(1); hbox->add_child(type_box); @@ -1425,13 +1402,13 @@ void VisualScriptEditor::_deselect_input_names() { int cn = func_input_vbox->get_child_count(); for (int i = 0; i < cn; i++) { LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1)); - if (lne) + if (lne) { lne->deselect(); + } } } void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { - TreeItem *ti = Object::cast_to<TreeItem>(p_item); TreeItem *root = members->get_root(); @@ -1446,7 +1423,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt return; } else if (p_button == 0) { - String name = _validate_name("new_function"); selected = name; Vector2 ofs = _get_available_pos(); @@ -1514,12 +1490,12 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } void VisualScriptEditor::_add_input_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1536,12 +1512,12 @@ void VisualScriptEditor::_add_input_port(int p_id) { } void VisualScriptEditor::_add_output_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1558,12 +1534,12 @@ void VisualScriptEditor::_add_output_port(int p_id) { } void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1572,14 +1548,16 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { int conn_from = -1, conn_port = -1; script->get_input_value_port_connection_source(func, p_id, p_port, &conn_from, &conn_port); - if (conn_from != -1) + if (conn_from != -1) { undo_redo->add_do_method(script.ptr(), "data_disconnect", func, conn_from, conn_port, p_id, p_port); + } undo_redo->add_do_method(vsn.ptr(), "remove_input_data_port", p_port); undo_redo->add_do_method(this, "_update_graph", p_id); - if (conn_from != -1) + if (conn_from != -1) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, conn_from, conn_port, p_id, p_port); + } undo_redo->add_undo_method(vsn.ptr(), "add_input_data_port", vsn->get_input_value_port_info(p_port).type, vsn->get_input_value_port_info(p_port).name, p_port); undo_redo->add_undo_method(this, "_update_graph", p_id); @@ -1590,12 +1568,12 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { } void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1608,8 +1586,9 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { for (const List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { if (E->get().from_node == p_id && E->get().from_port == p_port) { // push into the connections map - if (!conn_map.has(E->get().to_node)) + if (!conn_map.has(E->get().to_node)) { conn_map.set(E->get().to_node, Set<int>()); + } conn_map[E->get().to_node].insert(E->get().to_port); } } @@ -1634,12 +1613,12 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { } void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptExpression> vse = script->get_node(func, p_id); - if (!vse.is_valid()) + if (!vse.is_valid()) { return; + } updating_graph = true; @@ -1651,15 +1630,17 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id undo_redo->commit_action(); Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to<Control>(node)) + if (Object::cast_to<Control>(node)) { Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller + } updating_graph = false; } Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const { - if (centered) + if (centered) { ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5; + } if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -1685,8 +1666,9 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } } } - if (exists) + if (exists) { continue; + } break; } @@ -1694,12 +1676,10 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } String VisualScriptEditor::_validate_name(const String &p_name) const { - String valid = p_name; int counter = 1; while (true) { - bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid); if (exists) { @@ -1715,7 +1695,6 @@ String VisualScriptEditor::_validate_name(const String &p_name) const { } void VisualScriptEditor::_on_nodes_delete() { - // delete all the selected nodes List<int> to_erase; @@ -1729,13 +1708,13 @@ void VisualScriptEditor::_on_nodes_delete() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Remove VisualScript Nodes")); for (List<int>::Element *F = to_erase.front(); F; F = F->next()) { - int cr_node = F->get(); StringName func = _get_function_of_node(cr_node); @@ -1747,7 +1726,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_sequence_connection_list(func, &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - if (E->get().from_node == cr_node || E->get().to_node == cr_node) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, E->get().from_node, E->get().from_output, E->get().to_node); } @@ -1757,7 +1735,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_data_connection_list(func, &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - if (E->get().from_node == F->get() || E->get().to_node == F->get()) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } @@ -1770,7 +1747,6 @@ void VisualScriptEditor::_on_nodes_delete() { } void VisualScriptEditor::_on_nodes_duplicate() { - Set<int> to_duplicate; List<StringName> funcs; @@ -1785,8 +1761,9 @@ void VisualScriptEditor::_on_nodes_duplicate() { } } - if (to_duplicate.empty()) + if (to_duplicate.empty()) { return; + } undo_redo->create_action(TTR("Duplicate VisualScript Nodes")); int idc = script->get_available_id() + 1; @@ -1795,7 +1772,6 @@ void VisualScriptEditor::_on_nodes_duplicate() { HashMap<int, int> remap; for (Set<int>::Element *F = to_duplicate.front(); F; F = F->next()) { - // duplicate from the specific function but place it into the default func as it would lack the connections StringName func = _get_function_of_node(F->get()); Ref<VisualScriptNode> node = script->get_node(func, F->get()); @@ -1847,10 +1823,11 @@ void VisualScriptEditor::_on_nodes_duplicate() { } void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool node_centered) { - if (node_centered) + if (node_centered) { port_action_pos = graph->get_size() / 2.0f; - else + } else { port_action_pos = graph->get_viewport()->get_mouse_position() - graph->get_global_position(); + } new_connect_node_select->select_from_visual_script(p_base_type, false, false); // neither connecting nor reset text @@ -1859,8 +1836,9 @@ void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool n pos.x = pos.x > bounds.x ? bounds.x : pos.x; pos.y = pos.y > bounds.y ? bounds.y : pos.y; - if (pos != Vector2()) + if (pos != Vector2()) { new_connect_node_select->set_position(pos); + } } void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) { @@ -1884,7 +1862,6 @@ void VisualScriptEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { if (members->has_focus()) { @@ -1914,21 +1891,19 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> btn = p_event; if (btn.is_valid() && btn->is_doubleclick()) { TreeItem *ti = members->get_selected(); - if (ti && ti->get_parent() == members->get_root()->get_children()) // to check if it's a function + if (ti && ti->get_parent() == members->get_root()->get_children()) { // to check if it's a function _center_on_node(ti->get_metadata(0), script->get_function_node_id(ti->get_metadata(0))); + } } } void VisualScriptEditor::_rename_function(const String &name, const String &new_name) { - if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); return; } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); return; } @@ -1954,8 +1929,9 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_ script->get_node_list(E->get(), &lst); for (List<int>::Element *F = lst.front(); F; F = F->next()) { Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get()); - if (!fncall.is_valid()) + if (!fncall.is_valid()) { continue; + } if (fncall->get_function() == name) { undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); undo_redo->add_undo_method(fncall.ptr(), "set_function", name); @@ -1973,9 +1949,9 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_ } void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) { - - if (!function_name_edit->is_visible()) + if (!function_name_edit->is_visible()) { return; + } Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ENTER) { @@ -1986,31 +1962,28 @@ void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) { } Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (p_from == members) { - TreeItem *it = members->get_item_at_position(p_point); - if (!it) + if (!it) { return Variant(); + } String type = it->get_metadata(0); - if (type == String()) + if (type == String()) { return Variant(); + } Dictionary dd; TreeItem *root = members->get_root(); if (it->get_parent() == root->get_children()) { - dd["type"] = "visual_script_function_drag"; dd["function"] = type; } else if (it->get_parent() == root->get_children()->get_next()) { - dd["type"] = "visual_script_variable_drag"; dd["variable"] = type; } else if (it->get_parent() == root->get_children()->get_next()->get_next()) { - dd["type"] = "visual_script_signal_drag"; dd["signal"] = type; @@ -2027,9 +2000,7 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f } bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (p_from == graph) { - Dictionary d = p_data; if (d.has("type") && (String(d["type"]) == "visual_script_node_drag" || @@ -2040,9 +2011,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & String(d["type"]) == "resource" || String(d["type"]) == "files" || String(d["type"]) == "nodes")) { - if (String(d["type"]) == "obj_property") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else @@ -2051,7 +2020,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "nodes") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else @@ -2060,7 +2028,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "visual_script_variable_drag") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else @@ -2076,26 +2043,27 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; } void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (p_from != graph) { return; } @@ -2130,7 +2098,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_variable_drag") { - #ifdef OSX_ENABLED bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -2151,7 +2118,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnodes->set_variable(d["variable"]); vnode = vnodes; } else { - Ref<VisualScriptVariableGet> vnodeg; vnodeg.instance(); vnodeg->set_variable(d["variable"]); @@ -2175,7 +2141,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_function_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2208,7 +2173,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_signal_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2238,7 +2202,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "resource") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2268,7 +2231,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "files") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2286,10 +2248,10 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->create_action(TTR("Add Preload Node")); for (int i = 0; i < files.size(); i++) { - Ref<Resource> res = ResourceLoader::load(files[i]); - if (!res.is_valid()) + if (!res.is_valid()) { continue; + } Ref<VisualScriptPreload> prnode; prnode.instance(); @@ -2308,7 +2270,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } for (List<int>::Element *E = new_ids.front(); E; E = E->next()) { - Node *node = graph->get_node(itos(E->get())); if (node) { graph->set_selected(node); @@ -2318,7 +2279,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "nodes") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn) { @@ -2350,7 +2310,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } for (int i = 0; i < nodes.size(); i++) { - NodePath np = nodes[i]; Node *node = get_node(np); if (!node) { @@ -2388,7 +2347,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "obj_property") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { @@ -2398,8 +2356,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Object *obj = d["object"]; - if (!obj) + if (!obj) { return; + } Node *node = Object::cast_to<Node>(obj); Vector2 ofs = graph->get_scroll_ofs() + p_point; @@ -2417,18 +2376,17 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da #endif if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { - - if (use_get) + if (use_get) { undo_redo->create_action(TTR("Add Getter Property")); - else + } else { undo_redo->create_action(TTR("Add Setter Property")); + } int base_id = script->get_available_id(); Ref<VisualScriptNode> vnode; if (!use_get) { - Ref<VisualScriptPropertySet> pset; pset.instance(); pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); @@ -2439,7 +2397,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da }*/ vnode = pset; } else { - Ref<VisualScriptPropertyGet> pget; pget.instance(); pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); @@ -2461,18 +2418,17 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->commit_action(); } else { - - if (use_get) + if (use_get) { undo_redo->create_action(TTR("Add Getter Property")); - else + } else { undo_redo->create_action(TTR("Add Setter Property")); + } int base_id = script->get_available_id(); Ref<VisualScriptNode> vnode; if (!use_get) { - Ref<VisualScriptPropertySet> pset; pset.instance(); if (sn == node) { @@ -2484,7 +2440,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnode = pset; } else { - Ref<VisualScriptPropertyGet> pget; pget.instance(); if (sn == node) { @@ -2510,33 +2465,33 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } void VisualScriptEditor::_selected_method(const String &p_method, const String &p_type, const bool p_connecting) { - Ref<VisualScriptFunctionCall> vsfc = script->get_node(default_func, selecting_method_id); - if (!vsfc.is_valid()) + if (!vsfc.is_valid()) { return; + } vsfc->set_function(p_method); } void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { - Button *button = Object::cast_to<Button>(obj); - if (!button) + if (!button) { return; + } Ref<StyleBox> normal = get_theme_stylebox("normal", "Button"); button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color); } void VisualScriptEditor::_button_resource_previewed(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud) { - Array ud = p_ud; ERR_FAIL_COND(ud.size() != 2); ObjectID id = ud[0]; Object *obj = ObjectDB::get_instance(id); - if (!obj) + if (!obj) { return; + } Button *b = Object::cast_to<Button>(obj); ERR_FAIL_COND(!b); @@ -2544,7 +2499,6 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const if (p_preview.is_null()) { b->set_text(ud[1]); } else { - b->set_icon(p_preview); } } @@ -2559,7 +2513,6 @@ RES VisualScriptEditor::get_edited_resource() const { } void VisualScriptEditor::set_edited_resource(const RES &p_res) { - script = p_res; signal_editor->script = script; signal_editor->undo_redo = undo_redo; @@ -2581,7 +2534,6 @@ void VisualScriptEditor::set_edited_resource(const RES &p_res) { } Vector<String> VisualScriptEditor::get_functions() { - return Vector<String>(); } @@ -2589,7 +2541,6 @@ void VisualScriptEditor::reload_text() { } String VisualScriptEditor::get_name() { - String name; if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { @@ -2597,26 +2548,24 @@ String VisualScriptEditor::get_name() { if (is_unsaved()) { name += "(*)"; } - } else if (script->get_name() != "") + } else if (script->get_name() != "") { name = script->get_name(); - else + } else { name = script->get_class() + "(" + itos(script->get_instance_id()) + ")"; + } return name; } Ref<Texture2D> VisualScriptEditor::get_theme_icon() { - return Control::get_theme_icon("VisualScript", "EditorIcons"); } bool VisualScriptEditor::is_unsaved() { - return script->is_edited() || script->are_subnodes_edited(); } Variant VisualScriptEditor::get_edit_state() { - Dictionary d; d["function"] = default_func; d["scroll"] = graph->get_scroll_ofs(); @@ -2627,7 +2576,6 @@ Variant VisualScriptEditor::get_edit_state() { } void VisualScriptEditor::set_edit_state(const Variant &p_state) { - Dictionary d = p_state; if (d.has("function")) { selected = default_func; @@ -2651,15 +2599,15 @@ void VisualScriptEditor::set_edit_state(const Variant &p_state) { } void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { - Node *n = graph->get_node(itos(p_id)); GraphNode *gn = Object::cast_to<GraphNode>(n); // clear selection for (int i = 0; i < graph->get_child_count(); i++) { GraphNode *gnd = Object::cast_to<GraphNode>(graph->get_child(i)); - if (gnd) + if (gnd) { gnd->set_selected(false); + } } if (gn) { @@ -2672,18 +2620,16 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { } void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { - p_line += 1; //add one because script lines begin from 0. - if (p_with_error) + if (p_with_error) { error_line = p_line; + } List<StringName> functions; script->get_function_list(&functions); for (List<StringName>::Element *E = functions.front(); E; E = E->next()) { - if (script->has_node(E->get(), p_line)) { - _update_graph(); _update_members(); @@ -2714,7 +2660,6 @@ void VisualScriptEditor::convert_indent_to_tabs() { } void VisualScriptEditor::ensure_focus() { - graph->grab_focus(); } @@ -2726,15 +2671,12 @@ void VisualScriptEditor::reload(bool p_soft) { } void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { - List<StringName> functions; script->get_function_list(&functions); for (List<StringName>::Element *E = functions.front(); E; E = E->next()) { - List<int> nodes; script->get_node_list(E->get(), &nodes); for (List<int>::Element *F = nodes.front(); F; F = F->next()) { - Ref<VisualScriptNode> vsn = script->get_node(E->get(), F->get()); if (vsn->is_breakpoint()) { p_breakpoints->push_back(F->get() - 1); //subtract 1 because breakpoints in text start from zero @@ -2744,7 +2686,6 @@ void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { } void VisualScriptEditor::add_callback(const String &p_function, PackedStringArray p_args) { - if (script->has_function(p_function)) { _update_members(); _update_graph(); @@ -2755,7 +2696,6 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra Ref<VisualScriptFunction> func; func.instance(); for (int i = 0; i < p_args.size(); i++) { - String name = p_args[i]; Variant::Type type = Variant::NIL; @@ -2763,7 +2703,6 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra String tt = name.get_slice(":", 1); name = name.get_slice(":", 0); for (int j = 0; j < Variant::VARIANT_MAX; j++) { - String tname = Variant::get_type_name(Variant::Type(j)); if (tname == tt) { type = Variant::Type(j); @@ -2790,7 +2729,6 @@ bool VisualScriptEditor::show_members_overview() { } void VisualScriptEditor::update_settings() { - _update_graph(); } @@ -2805,12 +2743,10 @@ void VisualScriptEditor::set_tooltip_request_func(String p_method, Object *p_obj } Control *VisualScriptEditor::get_edit_menu() { - return edit_menu; } void VisualScriptEditor::_change_base_type() { - select_base_type->popup_create(true, true); } @@ -2824,7 +2760,6 @@ void VisualScriptEditor::clear_edit_menu() { } void VisualScriptEditor::_change_base_type_callback() { - String bt = select_base_type->get_selected_type(); ERR_FAIL_COND(bt == String()); @@ -2837,16 +2772,15 @@ void VisualScriptEditor::_change_base_type_callback() { } void VisualScriptEditor::_node_selected(Node *p_node) { - Ref<VisualScriptNode> vnode = p_node->get_meta("__vnode"); - if (vnode.is_null()) + if (vnode.is_null()) { return; + } EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector } static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) { - if (p_slot < p_node->get_output_sequence_port_count()) { r_sequence = true; r_real_slot = p_slot; @@ -2861,7 +2795,6 @@ static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int & } static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) { - if (p_slot == 0 && p_node->has_input_sequence_port()) { r_sequence = true; r_real_slot = 0; @@ -2875,30 +2808,28 @@ static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r } void VisualScriptEditor::_begin_node_move() { - undo_redo->create_action(TTR("Move Node(s)")); } void VisualScriptEditor::_end_node_move() { - undo_redo->commit_action(); } void VisualScriptEditor::_move_node(const StringName &p_func, int p_id, const Vector2 &p_to) { - - if (!script->has_function(p_func)) + if (!script->has_function(p_func)) { return; + } Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to<GraphNode>(node)) + if (Object::cast_to<GraphNode>(node)) { Object::cast_to<GraphNode>(node)->set_offset(p_to); + } script->set_node_position(p_func, p_id, p_to / EDSCALE); } StringName VisualScriptEditor::_get_function_of_node(int p_id) const { - List<StringName> funcs; script->get_function_list(&funcs); for (List<StringName>::Element *E = funcs.front(); E; E = E->next()) { @@ -2911,7 +2842,6 @@ StringName VisualScriptEditor::_get_function_of_node(int p_id) const { } void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) { - StringName func = _get_function_of_node(p_id); undo_redo->add_do_method(this, "_move_node", func, p_id, p_to); @@ -2919,7 +2849,6 @@ void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) { } void VisualScriptEditor::_remove_node(int p_id) { - undo_redo->create_action(TTR("Remove VisualScript Node")); StringName func = _get_function_of_node(p_id); @@ -2931,7 +2860,6 @@ void VisualScriptEditor::_remove_node(int p_id) { script->get_sequence_connection_list(func, &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - if (E->get().from_node == p_id || E->get().to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, E->get().from_node, E->get().from_output, E->get().to_node); } @@ -2941,7 +2869,6 @@ void VisualScriptEditor::_remove_node(int p_id) { script->get_data_connection_list(func, &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - if (E->get().from_node == p_id || E->get().to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } @@ -2954,7 +2881,6 @@ void VisualScriptEditor::_remove_node(int p_id) { } void VisualScriptEditor::_node_ports_changed(const String &p_func, int p_id) { - _update_graph(p_id); } @@ -2966,15 +2892,15 @@ bool VisualScriptEditor::node_has_sequence_connections(const StringName &p_func, int from = E->get().from_node; int to = E->get().to_node; - if (to == p_id || from == p_id) + if (to == p_id || from == p_id) { return true; + } } return false; } void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) { - StringName from_func = _get_function_of_node(p_from.to_int()); Ref<VisualScriptNode> from_node = script->get_node(from_func, p_from.to_int()); @@ -2983,8 +2909,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, bool from_seq; int from_port; - if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) + if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) { return; //can't connect this, it's invalid + } StringName to_func = _get_function_of_node(p_to.to_int()); @@ -2994,8 +2921,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, bool to_seq; int to_port; - if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) + if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) { return; //can't connect this, it's invalid + } ERR_FAIL_COND(from_seq != to_seq); @@ -3096,19 +3024,21 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, Vector2 constructor_pos; if ((to_node_pos.x - from_node_pos.x) < 0) { // to is behind from node - if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240)) + if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240)) { new_to_node_pos.x = from_node_pos.x - to_node_size.x - 240; // approx size of constructor node + padding - else + } else { new_to_node_pos.x = to_node_pos.x; + } new_to_node_pos.y = to_node_pos.y; constructor_pos.x = from_node_pos.x - 210; constructor_pos.y = to_node_pos.y; } else { // to is ahead of from node - if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240)) + if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240)) { new_to_node_pos.x = from_node_size.x + from_node_pos.x + 240; // approx size of constructor node + padding - else + } else { new_to_node_pos.x = to_node_pos.x; + } new_to_node_pos.y = to_node_pos.y; constructor_pos.x = from_node_size.x + from_node_pos.x + 10; constructor_pos.y = to_node_pos.y; @@ -3172,7 +3102,6 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, } void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) { - StringName func = _get_function_of_node(p_from.to_int()); ERR_FAIL_COND(func != _get_function_of_node(p_to.to_int())); @@ -3182,8 +3111,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl bool from_seq; int from_port; - if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) + if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) { return; //can't connect this, it's invalid + } Ref<VisualScriptNode> to_node = script->get_node(func, p_to.to_int()); ERR_FAIL_COND(!to_node.is_valid()); @@ -3191,8 +3121,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl bool to_seq; int to_port; - if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) + if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) { return; //can't connect this, it's invalid + } ERR_FAIL_COND(from_seq != to_seq); @@ -3202,7 +3133,6 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl undo_redo->add_do_method(script.ptr(), "sequence_disconnect", func, p_from.to_int(), from_port, p_to.to_int()); undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, p_from.to_int(), from_port, p_to.to_int()); } else { - can_swap = true; data_disconnect_node = p_to.to_int(); data_disconnect_port = to_port; @@ -3222,7 +3152,6 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl } void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, const StringName &p_func_to, int p_id) { - Set<int> nodes_to_move; HashMap<int, Map<int, int>> seqconns_to_move; // from => List(outp, to) HashMap<int, Map<int, Pair<int, int>>> dataconns_to_move; // to => List(inp_p => from, outp) @@ -3239,8 +3168,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, int from = E->get().from_node; int to = E->get().to_node; int out_p = E->get().from_output; - if (!seqcons.has(from)) + if (!seqcons.has(from)) { seqcons.set(from, Map<int, int>()); + } seqcons[from].insert(out_p, to); sequence_connections.insert(to); sequence_connections.insert(from); @@ -3263,12 +3193,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } continue; } - if (!seen.has(conn)) + if (!seen.has(conn)) { seen.set(conn, Set<int>()); + } seen[conn].insert(E->key()); stack.push_back(conn); - if (!seqconns_to_move.has(conn)) + if (!seqconns_to_move.has(conn)) { seqconns_to_move.set(conn, Map<int, int>()); + } seqconns_to_move[conn].insert(E->key(), E->get()); conn = E->get(); nodes_to_move.insert(conn); @@ -3293,8 +3225,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, int out_p = E->get().from_port; int in_p = E->get().to_port; - if (!connections.has(to)) + if (!connections.has(to)) { connections.set(to, Map<int, Pair<int, int>>()); + } connections[to].insert(in_p, Pair<int, int>(from, out_p)); } @@ -3331,12 +3264,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } } - if (!seen.has(id)) + if (!seen.has(id)) { seen.set(id, Set<int>()); + } seen[id].insert(E->key()); stack.push_back(id); - if (!dataconns_to_move.has(id)) + if (!dataconns_to_move.has(id)) { dataconns_to_move.set(id, Map<int, Pair<int, int>>()); + } dataconns_to_move[id].insert(E->key(), Pair<int, int>(E->get().first, E->get().second)); id = E->get().first; nodes_to_be_added.insert(id); @@ -3432,22 +3367,22 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) { - Node *node = graph->get_node(p_from); GraphNode *gn = Object::cast_to<GraphNode>(node); - if (!gn) + if (!gn) { return; + } StringName func = _get_function_of_node(p_from.to_int()); Ref<VisualScriptNode> vsn = script->get_node(func, p_from.to_int()); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } port_action_pos = p_release_pos; if (p_from_slot < vsn->get_output_sequence_port_count()) { - port_action_node = p_from.to_int(); port_action_output = p_from_slot; _port_action_menu(CREATE_ACTION, func); @@ -3459,12 +3394,12 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro } VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) { - VisualScriptNode::TypeGuess tg; tg.type = Variant::NIL; - if (visited_nodes.has(p_port_action_node)) + if (visited_nodes.has(p_port_action_node)) { return tg; //no loop + } visited_nodes.insert(p_port_action_node); @@ -3473,7 +3408,6 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac Ref<VisualScriptNode> node = script->get_node(func, p_port_action_node); if (!node.is_valid()) { - return tg; } @@ -3490,16 +3424,13 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac int from_port; if (script->get_input_value_port_connection_source(func, p_port_action_node, i, &from_node, &from_port)) { - g = _guess_output_type(from_node, from_port, visited_nodes); } else { Variant defval = node->get_default_input_value(i); if (defval.get_type() == Variant::OBJECT) { - Object *obj = defval; if (obj) { - g.type = Variant::OBJECT; g.gdclass = obj->get_class(); g.script = obj->get_script(); @@ -3515,7 +3446,6 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac } void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -3526,7 +3456,6 @@ void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) Set<int> vn; switch (p_option) { - case CREATE_CALL_SET_GET: { Ref<VisualScriptFunctionCall> n; n.instance(); @@ -3590,7 +3519,6 @@ void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) } void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id) { - undo_redo->create_action(TTR("Connect Node Data")); VisualScriptReturn *vnode_return = Object::cast_to<VisualScriptReturn>(vnode.ptr()); if (vnode_return != nullptr && vnode_old->get_output_value_port_count() > 0) { @@ -3616,7 +3544,6 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua } void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -3638,8 +3565,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == "visualscript") { Ref<VisualScriptNode> vnode_new = VisualScriptLanguage::singleton->create_node_from_name(p_text); Ref<VisualScriptNode> vnode_old; - if (port_node_exists) + if (port_node_exists) { vnode_old = script->get_node(func, port_action_node); + } int new_id = script->get_available_id(); if (Object::cast_to<VisualScriptOperator>(vnode_new.ptr()) && vnode_old.is_valid()) { @@ -3678,18 +3606,15 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri Ref<VisualScriptPropertySet> script_prop_set; if (p_category == String("method")) { - Ref<VisualScriptFunctionCall> n; n.instance(); vnode = n; } else if (p_category == String("set")) { - Ref<VisualScriptPropertySet> n; n.instance(); vnode = n; script_prop_set = n; } else if (p_category == String("get")) { - Ref<VisualScriptPropertyGet> n; n.instance(); n->set_property(p_text); @@ -3698,33 +3623,27 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == String("action")) { if (p_text == "VisualScriptCondition") { - Ref<VisualScriptCondition> n; n.instance(); vnode = n; } if (p_text == "VisualScriptSwitch") { - Ref<VisualScriptSwitch> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptSequence") { - Ref<VisualScriptSequence> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptIterator") { - Ref<VisualScriptIterator> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptWhile") { - Ref<VisualScriptWhile> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptReturn") { - Ref<VisualScriptReturn> n; n.instance(); vnode = n; @@ -3739,15 +3658,15 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri undo_redo->add_undo_method(this, "_update_graph", new_id); undo_redo->commit_action(); - if (script_prop_set.is_valid()) + if (script_prop_set.is_valid()) { script_prop_set->set_property(p_text); + } port_action_new_node = new_id; Ref<VisualScriptNode> vsn = script->get_node(func, port_action_new_node); if (Object::cast_to<VisualScriptFunctionCall>(vsn.ptr())) { - Ref<VisualScriptFunctionCall> vsfc = vsn; vsfc->set_function(p_text); @@ -3852,12 +3771,12 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri } } _update_graph(port_action_new_node); - if (port_node_exists) + if (port_node_exists) { _update_graph_connections(); + } } void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id) { - VisualScriptOperator *vnode_operator = Object::cast_to<VisualScriptOperator>(vnode_new.ptr()); if (vnode_operator != nullptr && !vnode_operator->has_input_sequence_port()) { return; @@ -3905,7 +3824,6 @@ void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<Visual } void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting) { - String name = p_text; if (script->has_function(name)) { EditorNode::get_singleton()->show_warning(vformat(TTR("Script already has function '%s'"), name)); @@ -3968,10 +3886,10 @@ void VisualScriptEditor::_cancel_connect_node() { } int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const Vector2 &p_point, const StringName &p_func) { - StringName func = default_func; - if (p_func != StringName()) + if (p_func != StringName()) { func = p_func; + } Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(p_text); int new_id = script->get_available_id(); @@ -3985,10 +3903,10 @@ int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const V } void VisualScriptEditor::_default_value_changed() { - Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(editing_id), editing_id); - if (vsn.is_null()) + if (vsn.is_null()) { return; + } undo_redo->create_action(TTR("Change Input Value")); undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant()); @@ -4000,15 +3918,14 @@ void VisualScriptEditor::_default_value_changed() { } void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_input_port) { - Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(p_id), p_id); - if (vsn.is_null()) + if (vsn.is_null()) { return; + } PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port); Variant existing = vsn->get_default_input_value(p_input_port); if (pinfo.type != Variant::NIL && existing.get_type() != pinfo.type) { - Callable::CallError ce; const Variant *existingp = &existing; existing = Variant::construct(pinfo.type, &existingp, 1, ce, false); @@ -4018,7 +3935,6 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i default_value_edit->set_size(Size2(1, 1)); if (pinfo.type == Variant::NODE_PATH) { - Node *edited_scene = get_tree()->get_edited_scene_root(); if (edited_scene) { // Fixing an old crash bug ( Visual Script Crashes on editing NodePath with an empty scene open) Node *script_node = _find_script_node(edited_scene, edited_scene, script); @@ -4036,10 +3952,11 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i } if (default_value_edit->edit(nullptr, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) { - if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) + if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) { default_value_edit->popup_centered_ratio(); - else + } else { default_value_edit->popup(); + } } editing_id = p_id; @@ -4047,19 +3964,16 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i } void VisualScriptEditor::_show_hint(const String &p_hint) { - hint_text->set_text(p_hint); hint_text->show(); hint_text_timer->start(); } void VisualScriptEditor::_hide_timer() { - hint_text->hide(); } void VisualScriptEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: { variable_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_members)); @@ -4122,9 +4036,9 @@ void VisualScriptEditor::_notification(int p_what) { } void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { - - if (updating_graph || !script.is_valid()) + if (updating_graph || !script.is_valid()) { return; + } updating_graph = true; @@ -4137,20 +4051,22 @@ void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { } void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_node) { - - if (updating_graph) + if (updating_graph) { return; + } StringName func = _get_function_of_node(p_node); Ref<VisualScriptComment> vsc = script->get_node(func, p_node); - if (vsc.is_null()) + if (vsc.is_null()) { return; + } Node *node = graph->get_node(itos(p_node)); GraphNode *gn = Object::cast_to<GraphNode>(node); - if (!gn) + if (!gn) { return; + } updating_graph = true; @@ -4168,13 +4084,11 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ } void VisualScriptEditor::_menu_option(int p_what) { - switch (p_what) { case EDIT_DELETE_NODES: { _on_nodes_delete(); } break; case EDIT_TOGGLE_BREAKPOINT: { - List<String> reselect; for (int i = 0; i < graph->get_child_count(); i++) { GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); @@ -4204,8 +4118,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } break; case EDIT_COPY_NODES: case EDIT_CUT_NODES: { - if (!script->has_function(default_func)) + if (!script->has_function(default_func)) { break; + } clipboard->nodes.clear(); clipboard->data_connections.clear(); @@ -4216,7 +4131,6 @@ void VisualScriptEditor::_menu_option(int p_what) { GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { - int id = String(gn->get_name()).to_int(); StringName func = _get_function_of_node(id); Ref<VisualScriptNode> node = script->get_node(func, id); @@ -4233,8 +4147,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } } - if (clipboard->nodes.empty()) + if (clipboard->nodes.empty()) { break; + } for (Set<String>::Element *F = funcs.front(); F; F = F->next()) { List<VisualScript::SequenceConnection> sequence_connections; @@ -4242,9 +4157,7 @@ void VisualScriptEditor::_menu_option(int p_what) { script->get_sequence_connection_list(F->get(), &sequence_connections); for (List<VisualScript::SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) { - if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard->sequence_connections.insert(E->get()); } } @@ -4254,9 +4167,7 @@ void VisualScriptEditor::_menu_option(int p_what) { script->get_data_connection_list(F->get(), &data_connections); for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { - if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard->data_connections.insert(E->get()); } } @@ -4267,8 +4178,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } break; case EDIT_PASTE_NODES: { - if (!script->has_function(default_func)) + if (!script->has_function(default_func)) { break; + } if (clipboard->nodes.empty()) { EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!")); @@ -4298,7 +4210,6 @@ void VisualScriptEditor::_menu_option(int p_what) { } for (Map<int, Ref<VisualScriptNode>>::Element *E = clipboard->nodes.front(); E; E = E->next()) { - Ref<VisualScriptNode> node = E->get()->duplicate(); int new_id = idc++; @@ -4317,13 +4228,11 @@ void VisualScriptEditor::_menu_option(int p_what) { } for (Set<VisualScript::SequenceConnection>::Element *E = clipboard->sequence_connections.front(); E; E = E->next()) { - undo_redo->add_do_method(script.ptr(), "sequence_connect", default_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]); undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", default_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]); } for (Set<VisualScript::DataConnection>::Element *E = clipboard->data_connections.front(); E; E = E->next()) { - undo_redo->add_do_method(script.ptr(), "data_connect", default_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port); undo_redo->add_undo_method(script.ptr(), "data_disconnect", default_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port); } @@ -4342,7 +4251,6 @@ void VisualScriptEditor::_menu_option(int p_what) { } } break; case EDIT_CREATE_FUNCTION: { - StringName function = ""; Map<int, Ref<VisualScriptNode>> nodes; Set<int> selections; @@ -4384,9 +4292,9 @@ void VisualScriptEditor::_menu_option(int p_what) { Set<int> end_nodes; if (nodes.size() == 1) { Ref<VisualScriptNode> nd = script->get_node(function, nodes.front()->key()); - if (nd.is_valid() && nd->has_input_sequence_port()) + if (nd.is_valid() && nd->has_input_sequence_port()) { start_node = nodes.front()->key(); - else { + } else { EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port.")); return; } @@ -4415,9 +4323,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } } Ref<VisualScriptNode> nd = script->get_node(function, top_nd); - if (nd.is_valid() && nd->has_input_sequence_port()) + if (nd.is_valid() && nd->has_input_sequence_port()) { start_node = top_nd; - else { + } else { EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port.")); return; } @@ -4614,7 +4522,6 @@ void VisualScriptEditor::_get_ends(int p_node, const List<VisualScript::Sequence } void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { - TreeItem *ti = members->get_selected(); ERR_FAIL_COND(!ti); @@ -4632,7 +4539,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { Ref<Texture2D> edit_icon = Control::get_theme_icon("Edit", "EditorIcons"); if (ti->get_parent() == root->get_children()) { - member_type = MEMBER_FUNCTION; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4643,7 +4549,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } if (ti->get_parent() == root->get_children()->get_next()) { - member_type = MEMBER_VARIABLE; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4654,7 +4559,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - member_type = MEMBER_SIGNAL; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4666,10 +4570,8 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } void VisualScriptEditor::_member_option(int p_option) { - switch (member_type) { case MEMBER_FUNCTION: { - if (p_option == MEMBER_REMOVE) { //delete the function String name = member_name; @@ -4712,7 +4614,6 @@ void VisualScriptEditor::_member_option(int p_option) { } } break; case MEMBER_VARIABLE: { - String name = member_name; if (p_option == MEMBER_REMOVE) { @@ -4760,7 +4661,6 @@ void VisualScriptEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter } void VisualScriptEditor::_bind_methods() { - ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node); ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1)); @@ -4783,7 +4683,6 @@ void VisualScriptEditor::_bind_methods() { } VisualScriptEditor::VisualScriptEditor() { - if (!clipboard) { clipboard = memnew(Clipboard); } @@ -5015,14 +4914,12 @@ VisualScriptEditor::VisualScriptEditor() { } VisualScriptEditor::~VisualScriptEditor() { - undo_redo->clear_history(); // Avoid crashes. memdelete(signal_editor); memdelete(variable_editor); } static ScriptEditorBase *create_editor(const RES &p_resource) { - if (Object::cast_to<VisualScript>(*p_resource)) { return memnew(VisualScriptEditor); } @@ -5033,12 +4930,12 @@ static ScriptEditorBase *create_editor(const RES &p_resource) { VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard = nullptr; void VisualScriptEditor::free_clipboard() { - if (clipboard) + if (clipboard) { memdelete(clipboard); + } } static void register_editor_callback() { - ScriptEditor::register_create_script_editor_function(create_editor); ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"), KEY_DELETE); @@ -5053,13 +4950,11 @@ static void register_editor_callback() { } void VisualScriptEditor::register_editor() { - // Too early to register stuff here, request a callback. EditorNode::add_plugin_init_callback(register_editor_callback); } Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) { - Ref<VisualScriptCustomNode> node; node.instance(); node->set_script(singleton->custom_nodes[p_name]); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index d9494e4d04..37063b2da1 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -152,7 +152,6 @@ class VisualScriptEditor : public ScriptEditorBase { String _validate_name(const String &p_name) const; struct Clipboard { - Map<int, Ref<VisualScriptNode>> nodes; Map<int, Vector2> nodes_positions; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 616a621845..bd41117497 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -31,7 +31,6 @@ #include "visual_script_expression.h" bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_value) { - if (String(p_name) == "expression") { expression = p_value; expression_dirty = true; @@ -52,7 +51,6 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } if (String(p_name) == "input_count") { - int from = inputs.size(); inputs.resize(int(p_value)); for (int i = from; i < inputs.size(); i++) { @@ -70,17 +68,14 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - inputs.write[idx].type = Variant::Type(int(p_value)); } else if (what == "name") { - inputs.write[idx].name = p_value; } else { return false; @@ -95,7 +90,6 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) const { - if (String(p_name) == "expression") { r_ret = expression; return true; @@ -117,17 +111,14 @@ bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) cons } if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - r_ret = inputs[idx].type; } else if (what == "name") { - r_ret = inputs[idx].name; } else { return false; @@ -138,8 +129,8 @@ bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) cons return false; } -void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) const { String argt = "Any"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { argt += "," + Variant::get_type_name(Variant::Type(i)); @@ -151,55 +142,48 @@ void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) cons p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced")); for (int i = 0; i < inputs.size(); i++) { - p_list->push_back(PropertyInfo(Variant::INT, "input_" + itos(i) + "/type", PROPERTY_HINT_ENUM, argt)); p_list->push_back(PropertyInfo(Variant::STRING, "input_" + itos(i) + "/name")); } } int VisualScriptExpression::get_output_sequence_port_count() const { - return sequenced ? 1 : 0; } -bool VisualScriptExpression::has_input_sequence_port() const { +bool VisualScriptExpression::has_input_sequence_port() const { return sequenced; } String VisualScriptExpression::get_output_sequence_port_text(int p_port) const { - return String(); } int VisualScriptExpression::get_input_value_port_count() const { - return inputs.size(); } -int VisualScriptExpression::get_output_value_port_count() const { +int VisualScriptExpression::get_output_value_port_count() const { return 1; } PropertyInfo VisualScriptExpression::get_input_value_port_info(int p_idx) const { - return PropertyInfo(inputs[p_idx].type, inputs[p_idx].name); } -PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const { return PropertyInfo(output_type, "result"); } String VisualScriptExpression::get_caption() const { - return "Expression"; } -String VisualScriptExpression::get_text() const { +String VisualScriptExpression::get_text() const { return expression; } Error VisualScriptExpression::_get_token(Token &r_token) { - while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) @@ -210,58 +194,47 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } switch (cchar) { - case 0: { r_token.type = TK_EOF; return OK; } break; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { - r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { - r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { - r_token.type = TK_COMMA; return OK; }; case ':': { - r_token.type = TK_COLON; return OK; }; case '.': { - r_token.type = TK_PERIOD; return OK; }; case '=': { - cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; @@ -273,7 +246,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '!': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; @@ -283,7 +255,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '>': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; @@ -296,7 +267,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '<': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; @@ -329,7 +299,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '&': { - if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; @@ -339,7 +308,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '|': { - if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; @@ -349,22 +317,18 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '^': { - r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { - r_token.type = TK_OP_BIT_INVERT; return OK; }; case '"': { - String str; while (true) { - CharType ch = GET_CHAR(); if (ch == 0) { @@ -385,7 +349,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -412,7 +375,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; @@ -454,7 +416,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; default: { - if (cchar <= 32) { break; } @@ -476,10 +437,8 @@ Error VisualScriptExpression::_get_token(Token &r_token) { bool is_float = false; while (true) { - switch (reading) { case READING_INT: { - if (c >= '0' && c <= '9') { //pass } else if (c == '.') { @@ -493,9 +452,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; case READING_DEC: { - if (c >= '0' && c <= '9') { - } else if (c == 'e') { reading = READING_EXP; @@ -505,13 +462,13 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; case READING_EXP: { - if (c >= '0' && c <= '9') { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') + if (c == '-') { is_float = true; + } exp_sign = true; } else { @@ -520,8 +477,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; } - if (reading == READING_DONE) + if (reading == READING_DONE) { break; + } num += String::chr(c); c = GET_CHAR(); } @@ -530,19 +488,18 @@ Error VisualScriptExpression::_get_token(Token &r_token) { r_token.type = TK_CONSTANT; - if (is_float) + if (is_float) { r_token.value = num.to_double(); - else + } else { r_token.value = num.to_int(); + } return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { - id += String::chr(cchar); cchar = GET_CHAR(); first = false; @@ -582,7 +539,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } else if (id == "self") { r_token.type = TK_SELF; } else { - for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; @@ -657,7 +613,6 @@ const char *VisualScriptExpression::token_name[TK_MAX] = { }; VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { - Vector<Expression> expression; while (true) { @@ -666,8 +621,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { Token tk; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } switch (tk.type) { case TK_CURLY_BRACKET_OPEN: { @@ -675,7 +631,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { DictionaryNode *dn = alloc_node<DictionaryNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_CURLY_BRACKET_CLOSE) { @@ -684,8 +639,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } dn->dict.push_back(expr2); _get_token(tk); @@ -695,8 +651,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } dn->dict.push_back(expr2); @@ -719,7 +676,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { ArrayNode *an = alloc_node<ArrayNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_BRACKET_CLOSE) { @@ -728,8 +684,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } an->array.push_back(expr2); cofs = str_ofs; @@ -748,8 +705,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { case TK_PARENTHESIS_OPEN: { //a suexpression ENode *e = _parse_expression(); - if (error_set) + if (error_set) { return nullptr; + } _get_token(tk); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')'"); @@ -760,7 +718,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; case TK_IDENTIFIER: { - String what = tk.value; int index = -1; for (int i = 0; i < inputs.size(); i++) { @@ -780,7 +737,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } break; case TK_SELF: { - SelfNode *self = alloc_node<SelfNode>(); expr = self; } break; @@ -803,7 +759,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { constructor->data_type = bt; while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -812,8 +767,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } constructor->arguments.push_back(expr2); @@ -844,7 +800,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { bifunc->func = VisualScriptBuiltinFunc::BuiltinFunc(int(tk.value)); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -853,8 +808,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } bifunc->arguments.push_back(expr2); @@ -878,7 +834,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; case TK_OP_SUB: { - Expression e; e.is_op = true; e.op = Variant::OP_NEGATE; @@ -886,7 +841,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { continue; } break; case TK_OP_NOT: { - Expression e; e.is_op = true; e.op = Variant::OP_NOT; @@ -905,8 +859,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { while (true) { int cofs2 = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } bool done = false; @@ -918,8 +873,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { index->base = expr; ENode *what = _parse_expression(); - if (!what) + if (!what) { return nullptr; + } index->index = what; @@ -950,7 +906,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { func_call->base = expr; while (true) { - int cofs3 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -959,8 +914,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs3; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } func_call->arguments.push_back(expr2); @@ -993,8 +949,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; } - if (done) + if (done) { break; + } } //push expression @@ -1009,8 +966,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { int cofs = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } Variant::Operator op = Variant::OP_MAX; @@ -1099,15 +1057,12 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { - int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { - continue; } @@ -1116,7 +1071,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { bool unary = false; switch (expression[i].op) { - case Variant::OP_BIT_NEGATE: priority = 0; unary = true; @@ -1212,17 +1166,14 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } if (next_op == -1) { - _set_error("Yet another parser bug...."); ERR_FAIL_V(nullptr); } // OK! create operator.. if (is_unary) { - int expr_pos = next_op; while (expression[expr_pos].is_op) { - expr_pos++; if (expr_pos == expression.size()) { //can happen.. @@ -1233,7 +1184,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { - OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; op->nodes[0] = expression[i + 1].node; @@ -1244,7 +1194,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); @@ -1254,7 +1203,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { op->op = expression[next_op].op; if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } @@ -1283,9 +1231,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } bool VisualScriptExpression::_compile_expression() { - - if (!expression_dirty) + if (!expression_dirty) { return error_set; + } if (nodes) { memdelete(nodes); @@ -1320,38 +1268,35 @@ public: //virtual int get_working_memory_size() const { return 0; } //execute by parsing the tree directly virtual bool _execute(const Variant **p_inputs, VisualScriptExpression::ENode *p_node, Variant &r_ret, String &r_error_str, Callable::CallError &ce) { - switch (p_node->type) { case VisualScriptExpression::ENode::TYPE_INPUT: { - const VisualScriptExpression::InputNode *in = static_cast<const VisualScriptExpression::InputNode *>(p_node); r_ret = *p_inputs[in->index]; } break; case VisualScriptExpression::ENode::TYPE_CONSTANT: { - const VisualScriptExpression::ConstantNode *c = static_cast<const VisualScriptExpression::ConstantNode *>(p_node); r_ret = c->value; } break; case VisualScriptExpression::ENode::TYPE_SELF: { - r_ret = instance->get_owner_ptr(); } break; case VisualScriptExpression::ENode::TYPE_OPERATOR: { - const VisualScriptExpression::OperatorNode *op = static_cast<const VisualScriptExpression::OperatorNode *>(p_node); Variant a; bool ret = _execute(p_inputs, op->nodes[0], a, r_error_str, ce); - if (ret) + if (ret) { return true; + } Variant b; if (op->nodes[1]) { ret = _execute(p_inputs, op->nodes[1], b, r_error_str, ce); - if (ret) + if (ret) { return true; + } } bool valid = true; @@ -1363,19 +1308,20 @@ public: } break; case VisualScriptExpression::ENode::TYPE_INDEX: { - const VisualScriptExpression::IndexNode *index = static_cast<const VisualScriptExpression::IndexNode *>(p_node); Variant base; bool ret = _execute(p_inputs, index->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } Variant idx; ret = _execute(p_inputs, index->index, idx, r_error_str, ce); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get(idx, &valid); @@ -1386,13 +1332,13 @@ public: } break; case VisualScriptExpression::ENode::TYPE_NAMED_INDEX: { - const VisualScriptExpression::NamedIndexNode *index = static_cast<const VisualScriptExpression::NamedIndexNode *>(p_node); Variant base; bool ret = _execute(p_inputs, index->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get_named(index->name, &valid); @@ -1408,11 +1354,11 @@ public: Array arr; arr.resize(array->array.size()); for (int i = 0; i < array->array.size(); i++) { - Variant value; bool ret = _execute(p_inputs, array->array[i], value, r_error_str, ce); - if (ret) + if (ret) { return true; + } arr[i] = value; } @@ -1424,16 +1370,17 @@ public: Dictionary d; for (int i = 0; i < dictionary->dict.size(); i += 2) { - Variant key; bool ret = _execute(p_inputs, dictionary->dict[i + 0], key, r_error_str, ce); - if (ret) + if (ret) { return true; + } Variant value; ret = _execute(p_inputs, dictionary->dict[i + 1], value, r_error_str, ce); - if (ret) + if (ret) { return true; + } d[key] = value; } @@ -1441,7 +1388,6 @@ public: r_ret = d; } break; case VisualScriptExpression::ENode::TYPE_CONSTRUCTOR: { - const VisualScriptExpression::ConstructorNode *constructor = static_cast<const VisualScriptExpression::ConstructorNode *>(p_node); Vector<Variant> arr; @@ -1450,11 +1396,11 @@ public: argp.resize(constructor->arguments.size()); for (int i = 0; i < constructor->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, constructor->arguments[i], value, r_error_str, ce); - if (ret) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -1468,7 +1414,6 @@ public: } break; case VisualScriptExpression::ENode::TYPE_BUILTIN_FUNC: { - const VisualScriptExpression::BuiltinFuncNode *bifunc = static_cast<const VisualScriptExpression::BuiltinFuncNode *>(p_node); Vector<Variant> arr; @@ -1477,11 +1422,11 @@ public: argp.resize(bifunc->arguments.size()); for (int i = 0; i < bifunc->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, bifunc->arguments[i], value, r_error_str, ce); - if (ret) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -1495,13 +1440,13 @@ public: } break; case VisualScriptExpression::ENode::TYPE_CALL: { - const VisualScriptExpression::CallNode *call = static_cast<const VisualScriptExpression::CallNode *>(p_node); Variant base; bool ret = _execute(p_inputs, call->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } Vector<Variant> arr; Vector<const Variant *> argp; @@ -1509,11 +1454,11 @@ public: argp.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { - Variant value; bool ret2 = _execute(p_inputs, call->arguments[i], value, r_error_str, ce); - if (ret2) + if (ret2) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -1531,7 +1476,6 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!expression->root || expression->error_set) { r_error_str = expression->error_str; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -1545,7 +1489,6 @@ public: #ifdef DEBUG_ENABLED if (!error && expression->output_type != Variant::NIL && !Variant::can_convert_strict(p_outputs[0]->get_type(), expression->output_type)) { - r_error_str += "Can't convert expression result from " + Variant::get_type_name(p_outputs[0]->get_type()) + " to " + Variant::get_type_name(expression->output_type) + "."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; } @@ -1556,7 +1499,6 @@ public: }; VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance *p_instance) { - _compile_expression(); VisualScriptNodeInstanceExpression *instance = memnew(VisualScriptNodeInstanceExpression); instance->instance = p_instance; @@ -1574,13 +1516,11 @@ VisualScriptExpression::VisualScriptExpression() { } VisualScriptExpression::~VisualScriptExpression() { - if (nodes) { memdelete(nodes); } } void register_visual_script_expression_node() { - VisualScriptLanguage::singleton->add_register_func("operators/expression", create_node_generic<VisualScriptExpression>); } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index 61b50ff99d..dee0213d54 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -35,12 +35,10 @@ #include "visual_script_builtin_funcs.h" class VisualScriptExpression : public VisualScriptNode { - GDCLASS(VisualScriptExpression, VisualScriptNode); friend class VisualScriptNodeInstanceExpression; struct Input { - Variant::Type type; String name; @@ -101,14 +99,14 @@ class VisualScriptExpression : public VisualScriptNode { static const char *token_name[TK_MAX]; struct Token { - TokenType type; Variant value; }; void _set_error(const String &p_err) { - if (error_set) + if (error_set) { return; + } error_str = p_err; error_set = true; } @@ -119,7 +117,6 @@ class VisualScriptExpression : public VisualScriptNode { bool error_set; struct ENode { - enum Type { TYPE_INPUT, TYPE_CONSTANT, @@ -147,7 +144,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct Expression { - bool is_op; union { Variant::Operator op; @@ -158,7 +154,6 @@ class VisualScriptExpression : public VisualScriptNode { ENode *_parse_expression(); struct InputNode : public ENode { - int index; InputNode() { type = TYPE_INPUT; @@ -166,7 +161,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct ConstantNode : public ENode { - Variant value; ConstantNode() { type = TYPE_CONSTANT; @@ -174,7 +168,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct OperatorNode : public ENode { - Variant::Operator op; ENode *nodes[2]; @@ -185,7 +178,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct SelfNode : public ENode { - SelfNode() { type = TYPE_SELF; } diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 8a644c6860..3ed20fab35 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -39,78 +39,70 @@ ////////////////////////////////////////// int VisualScriptReturn::get_output_sequence_port_count() const { - return 0; } bool VisualScriptReturn::has_input_sequence_port() const { - return true; } int VisualScriptReturn::get_input_value_port_count() const { - return with_value ? 1 : 0; } -int VisualScriptReturn::get_output_value_port_count() const { +int VisualScriptReturn::get_output_value_port_count() const { return 0; } String VisualScriptReturn::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptReturn::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "result"; pinfo.type = type; return pinfo; } + PropertyInfo VisualScriptReturn::get_output_value_port_info(int p_idx) const { return PropertyInfo(); } String VisualScriptReturn::get_caption() const { - return "Return"; } String VisualScriptReturn::get_text() const { - return get_name(); } void VisualScriptReturn::set_return_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); } Variant::Type VisualScriptReturn::get_return_type() const { - return type; } void VisualScriptReturn::set_enable_return_value(bool p_enable) { - if (with_value == p_enable) + if (with_value == p_enable) { return; + } with_value = p_enable; ports_changed_notify(); } bool VisualScriptReturn::is_return_value_enabled() const { - return with_value; } void VisualScriptReturn::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_return_type", "type"), &VisualScriptReturn::set_return_type); ClassDB::bind_method(D_METHOD("get_return_type"), &VisualScriptReturn::get_return_type); ClassDB::bind_method(D_METHOD("set_enable_return_value", "enable"), &VisualScriptReturn::set_enable_return_value); @@ -136,7 +128,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (with_value) { *p_working_mem = *p_inputs[0]; return STEP_EXIT_FUNCTION_BIT; @@ -148,7 +139,6 @@ public: }; VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceReturn *instance = memnew(VisualScriptNodeInstanceReturn); instance->node = this; instance->instance = p_instance; @@ -157,14 +147,12 @@ VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_i } VisualScriptReturn::VisualScriptReturn() { - with_value = false; type = Variant::NIL; } template <bool with_value> static Ref<VisualScriptNode> create_return_node(const String &p_name) { - Ref<VisualScriptReturn> node; node.instance(); node->set_enable_return_value(with_value); @@ -176,52 +164,47 @@ static Ref<VisualScriptNode> create_return_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptCondition::get_output_sequence_port_count() const { - return 3; } bool VisualScriptCondition::has_input_sequence_port() const { - return true; } int VisualScriptCondition::get_input_value_port_count() const { - return 1; } -int VisualScriptCondition::get_output_value_port_count() const { +int VisualScriptCondition::get_output_value_port_count() const { return 0; } String VisualScriptCondition::get_output_sequence_port_text(int p_port) const { - - if (p_port == 0) + if (p_port == 0) { return "true"; - else if (p_port == 1) + } else if (p_port == 1) { return "false"; - else + } else { return "done"; + } } PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "cond"; pinfo.type = Variant::BOOL; return pinfo; } + PropertyInfo VisualScriptCondition::get_output_value_port_info(int p_idx) const { return PropertyInfo(); } String VisualScriptCondition::get_caption() const { - return "Condition"; } String VisualScriptCondition::get_text() const { - return "if (cond) is: "; } @@ -238,18 +221,17 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - - if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) + if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) { return 2; - else if (p_inputs[0]->operator bool()) + } else if (p_inputs[0]->operator bool()) { return 0 | STEP_FLAG_PUSH_STACK_BIT; - else + } else { return 1 | STEP_FLAG_PUSH_STACK_BIT; + } } }; VisualScriptNodeInstance *VisualScriptCondition::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceCondition *instance = memnew(VisualScriptNodeInstanceCondition); instance->node = this; instance->instance = p_instance; @@ -264,50 +246,45 @@ VisualScriptCondition::VisualScriptCondition() { ////////////////////////////////////////// int VisualScriptWhile::get_output_sequence_port_count() const { - return 2; } bool VisualScriptWhile::has_input_sequence_port() const { - return true; } int VisualScriptWhile::get_input_value_port_count() const { - return 1; } -int VisualScriptWhile::get_output_value_port_count() const { +int VisualScriptWhile::get_output_value_port_count() const { return 0; } String VisualScriptWhile::get_output_sequence_port_text(int p_port) const { - - if (p_port == 0) + if (p_port == 0) { return "repeat"; - else + } else { return "exit"; + } } PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "cond"; pinfo.type = Variant::BOOL; return pinfo; } + PropertyInfo VisualScriptWhile::get_output_value_port_info(int p_idx) const { return PropertyInfo(); } String VisualScriptWhile::get_caption() const { - return "While"; } String VisualScriptWhile::get_text() const { - return "while (cond): "; } @@ -324,23 +301,23 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool keep_going = p_inputs[0]->operator bool(); - if (keep_going) + if (keep_going) { return 0 | STEP_FLAG_PUSH_STACK_BIT; - else + } else { return 1; + } } }; VisualScriptNodeInstance *VisualScriptWhile::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceWhile *instance = memnew(VisualScriptNodeInstanceWhile); instance->node = this; instance->instance = p_instance; return instance; } + VisualScriptWhile::VisualScriptWhile() { } @@ -349,52 +326,48 @@ VisualScriptWhile::VisualScriptWhile() { ////////////////////////////////////////// int VisualScriptIterator::get_output_sequence_port_count() const { - return 2; } bool VisualScriptIterator::has_input_sequence_port() const { - return true; } int VisualScriptIterator::get_input_value_port_count() const { - return 1; } -int VisualScriptIterator::get_output_value_port_count() const { +int VisualScriptIterator::get_output_value_port_count() const { return 1; } String VisualScriptIterator::get_output_sequence_port_text(int p_port) const { - - if (p_port == 0) + if (p_port == 0) { return "each"; - else + } else { return "exit"; + } } PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "input"; pinfo.type = Variant::NIL; return pinfo; } + PropertyInfo VisualScriptIterator::get_output_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = "elem"; pinfo.type = Variant::NIL; return pinfo; } -String VisualScriptIterator::get_caption() const { +String VisualScriptIterator::get_caption() const { return "Iterator"; } String VisualScriptIterator::get_text() const { - return "for (elem) in (input): "; } @@ -411,7 +384,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_BEGIN_SEQUENCE) { p_working_mem[0] = *p_inputs[0]; bool valid; @@ -423,8 +395,9 @@ public: return 0; } - if (!can_iter) + if (!can_iter) { return 1; //nothing to iterate + } *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid); @@ -445,8 +418,9 @@ public: return 0; } - if (!can_iter) + if (!can_iter) { return 1; //nothing to iterate + } *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid); @@ -462,7 +436,6 @@ public: }; VisualScriptNodeInstance *VisualScriptIterator::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIterator *instance = memnew(VisualScriptNodeInstanceIterator); instance->node = this; instance->instance = p_instance; @@ -477,62 +450,56 @@ VisualScriptIterator::VisualScriptIterator() { ////////////////////////////////////////// int VisualScriptSequence::get_output_sequence_port_count() const { - return steps; } bool VisualScriptSequence::has_input_sequence_port() const { - return true; } int VisualScriptSequence::get_input_value_port_count() const { - return 0; } -int VisualScriptSequence::get_output_value_port_count() const { +int VisualScriptSequence::get_output_value_port_count() const { return 1; } String VisualScriptSequence::get_output_sequence_port_text(int p_port) const { - return itos(p_port + 1); } PropertyInfo VisualScriptSequence::get_input_value_port_info(int p_idx) const { return PropertyInfo(); } + PropertyInfo VisualScriptSequence::get_output_value_port_info(int p_idx) const { return PropertyInfo(Variant::INT, "current"); } -String VisualScriptSequence::get_caption() const { +String VisualScriptSequence::get_caption() const { return "Sequence"; } String VisualScriptSequence::get_text() const { - return "in order: "; } void VisualScriptSequence::set_steps(int p_steps) { - ERR_FAIL_COND(p_steps < 1); - if (steps == p_steps) + if (steps == p_steps) { return; + } steps = p_steps; ports_changed_notify(); } int VisualScriptSequence::get_steps() const { - return steps; } void VisualScriptSequence::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_steps", "steps"), &VisualScriptSequence::set_steps); ClassDB::bind_method(D_METHOD("get_steps"), &VisualScriptSequence::get_steps); @@ -550,9 +517,7 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_BEGIN_SEQUENCE) { - p_working_mem[0] = 0; } @@ -560,9 +525,9 @@ public: *p_outputs[0] = step; - if (step + 1 == steps) + if (step + 1 == steps) { return step; - else { + } else { p_working_mem[0] = step + 1; return step | STEP_FLAG_PUSH_STACK_BIT; } @@ -570,15 +535,14 @@ public: }; VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSequence *instance = memnew(VisualScriptNodeInstanceSequence); instance->node = this; instance->instance = p_instance; instance->steps = steps; return instance; } -VisualScriptSequence::VisualScriptSequence() { +VisualScriptSequence::VisualScriptSequence() { steps = 1; } @@ -587,52 +551,46 @@ VisualScriptSequence::VisualScriptSequence() { ////////////////////////////////////////// int VisualScriptSwitch::get_output_sequence_port_count() const { - return case_values.size() + 1; } bool VisualScriptSwitch::has_input_sequence_port() const { - return true; } int VisualScriptSwitch::get_input_value_port_count() const { - return case_values.size() + 1; } -int VisualScriptSwitch::get_output_value_port_count() const { +int VisualScriptSwitch::get_output_value_port_count() const { return 0; } String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { - - if (p_port == case_values.size()) + if (p_port == case_values.size()) { return "done"; + } return String(); } PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const { - if (p_idx < case_values.size()) { return PropertyInfo(case_values[p_idx].type, " ="); - } else + } else { return PropertyInfo(Variant::NIL, "input"); + } } PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptSwitch::get_caption() const { - return "Switch"; } String VisualScriptSwitch::get_text() const { - return "'input' is:"; } @@ -646,13 +604,11 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) { return case_count; //exit } for (int i = 0; i < case_count; i++) { - if (*p_inputs[i] == *p_inputs[case_count]) { return i | STEP_FLAG_PUSH_STACK_BIT; } @@ -663,7 +619,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSwitch *instance = memnew(VisualScriptNodeInstanceSwitch); instance->instance = p_instance; instance->case_count = case_values.size(); @@ -671,7 +626,6 @@ VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_i } bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) { - if (String(p_name) == "case_count") { case_values.resize(p_value); _change_notify(); @@ -680,7 +634,6 @@ bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) } if (String(p_name).begins_with("case/")) { - int idx = String(p_name).get_slice("/", 1).to_int(); ERR_FAIL_INDEX_V(idx, case_values.size(), false); @@ -695,14 +648,12 @@ bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) } bool VisualScriptSwitch::_get(const StringName &p_name, Variant &r_ret) const { - if (String(p_name) == "case_count") { r_ret = case_values.size(); return true; } if (String(p_name).begins_with("case/")) { - int idx = String(p_name).get_slice("/", 1).to_int(); ERR_FAIL_INDEX_V(idx, case_values.size(), false); @@ -712,8 +663,8 @@ bool VisualScriptSwitch::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "case_count", PROPERTY_HINT_RANGE, "0,128")); String argt = "Any"; @@ -737,56 +688,49 @@ VisualScriptSwitch::VisualScriptSwitch() { ////////////////////////////////////////// int VisualScriptTypeCast::get_output_sequence_port_count() const { - return 2; } bool VisualScriptTypeCast::has_input_sequence_port() const { - return true; } int VisualScriptTypeCast::get_input_value_port_count() const { - return 1; } -int VisualScriptTypeCast::get_output_value_port_count() const { +int VisualScriptTypeCast::get_output_value_port_count() const { return 1; } String VisualScriptTypeCast::get_output_sequence_port_text(int p_port) const { - return p_port == 0 ? "yes" : "no"; } PropertyInfo VisualScriptTypeCast::get_input_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "instance"); } PropertyInfo VisualScriptTypeCast::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_TYPE_STRING, get_base_type()); } String VisualScriptTypeCast::get_caption() const { - return "Type Cast"; } String VisualScriptTypeCast::get_text() const { - - if (script != String()) + if (script != String()) { return "Is " + script.get_file() + "?"; - else + } else { return "Is " + base_type + "?"; + } } void VisualScriptTypeCast::set_base_type(const StringName &p_type) { - - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -794,26 +738,24 @@ void VisualScriptTypeCast::set_base_type(const StringName &p_type) { } StringName VisualScriptTypeCast::get_base_type() const { - return base_type; } void VisualScriptTypeCast::set_base_script(const String &p_path) { - - if (script == p_path) + if (script == p_path) { return; + } script = p_path; _change_notify(); ports_changed_notify(); } -String VisualScriptTypeCast::get_base_script() const { +String VisualScriptTypeCast::get_base_script() const { return script; } VisualScriptTypeCast::TypeGuess VisualScriptTypeCast::guess_output_type(TypeGuess *p_inputs, int p_output) const { - TypeGuess tg; tg.type = Variant::OBJECT; if (script != String()) { @@ -837,7 +779,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Object *obj = *p_inputs[0]; *p_outputs[0] = Variant(); @@ -849,7 +790,6 @@ public: } if (script != String()) { - Ref<Script> obj_script = obj->get_script(); if (!obj_script.is_valid()) { return 1; //well, definitely not the script because object we got has no script. @@ -867,7 +807,6 @@ public: } while (obj_script.is_valid()) { - if (cast_script == obj_script) { *p_outputs[0] = *p_inputs[0]; //copy return 0; // it is the script, yey @@ -882,13 +821,13 @@ public: if (ClassDB::is_parent_class(obj->get_class_name(), base_type)) { *p_outputs[0] = *p_inputs[0]; //copy return 0; - } else + } else { return 1; + } } }; VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceTypeCast *instance = memnew(VisualScriptNodeInstanceTypeCast); instance->instance = p_instance; instance->base_type = base_type; @@ -897,7 +836,6 @@ VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p } void VisualScriptTypeCast::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "type"), &VisualScriptTypeCast::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptTypeCast::get_base_type); @@ -911,8 +849,9 @@ void VisualScriptTypeCast::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -921,12 +860,10 @@ void VisualScriptTypeCast::_bind_methods() { } VisualScriptTypeCast::VisualScriptTypeCast() { - base_type = "Object"; } void register_visual_script_flow_control_nodes() { - VisualScriptLanguage::singleton->add_register_func("flow_control/return", create_return_node<false>); VisualScriptLanguage::singleton->add_register_func("flow_control/return_with_value", create_return_node<true>); VisualScriptLanguage::singleton->add_register_func("flow_control/condition", create_node_generic<VisualScriptCondition>); diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 8597d051db..45b56b3073 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptReturn : public VisualScriptNode { - GDCLASS(VisualScriptReturn, VisualScriptNode); Variant::Type type; @@ -71,7 +70,6 @@ public: }; class VisualScriptCondition : public VisualScriptNode { - GDCLASS(VisualScriptCondition, VisualScriptNode); protected: @@ -99,7 +97,6 @@ public: }; class VisualScriptWhile : public VisualScriptNode { - GDCLASS(VisualScriptWhile, VisualScriptNode); protected: @@ -127,7 +124,6 @@ public: }; class VisualScriptIterator : public VisualScriptNode { - GDCLASS(VisualScriptIterator, VisualScriptNode); protected: @@ -155,7 +151,6 @@ public: }; class VisualScriptSequence : public VisualScriptNode { - GDCLASS(VisualScriptSequence, VisualScriptNode); int steps; @@ -188,7 +183,6 @@ public: }; class VisualScriptSwitch : public VisualScriptNode { - GDCLASS(VisualScriptSwitch, VisualScriptNode); struct Case { @@ -230,7 +224,6 @@ public: }; class VisualScriptTypeCast : public VisualScriptNode { - GDCLASS(VisualScriptTypeCast, VisualScriptNode); StringName base_type; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 3b6ae369ae..f13377f3c8 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -42,33 +42,34 @@ ////////////////////////////////////////// int VisualScriptFunctionCall::get_output_sequence_port_count() const { - - if ((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))) + if ((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))) { return 0; - else + } else { return 1; + } } bool VisualScriptFunctionCall::has_input_sequence_port() const { - return !((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))); } #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -76,30 +77,34 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif Node *VisualScriptFunctionCall::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -111,26 +116,24 @@ Node *VisualScriptFunctionCall::_get_base_node() const { } StringName VisualScriptFunctionCall::_get_base_type() const { - - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { return get_visual_script()->get_instance_base_type(); - else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; } int VisualScriptFunctionCall::get_input_value_port_count() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function); return types.size() + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) + 1; } else { - MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { int defaulted_args = mb->get_argument_count() < use_default_args ? mb->get_argument_count() : use_default_args; @@ -141,10 +144,9 @@ int VisualScriptFunctionCall::get_input_value_port_count() const { return method_cache.arguments.size() + (call_mode == CALL_MODE_INSTANCE ? 1 : 0) + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) - defaulted_args; } } -int VisualScriptFunctionCall::get_output_value_port_count() const { +int VisualScriptFunctionCall::get_output_value_port_count() const { if (call_mode == CALL_MODE_BASIC_TYPE) { - bool returns = false; Variant::get_method_return_type(basic_type, function, &returns); return returns ? 1 : 0; @@ -154,8 +156,9 @@ int VisualScriptFunctionCall::get_output_value_port_count() const { MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { ret = mb->has_return() ? 1 : 0; - } else + } else { ret = 1; //it is assumed that script always returns something + } if (call_mode == CALL_MODE_INSTANCE) { ret++; @@ -166,12 +169,10 @@ int VisualScriptFunctionCall::get_output_value_port_count() const { } String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) { if (p_idx == 0) { PropertyInfo pi; @@ -184,7 +185,6 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } if (rpc_call_mode >= RPC_RELIABLE_TO_ID) { - if (p_idx == 0) { return PropertyInfo(Variant::INT, "peer_id"); } else { @@ -195,13 +195,11 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons #ifdef DEBUG_METHODS_ENABLED if (call_mode == CALL_MODE_BASIC_TYPE) { - Vector<StringName> names = Variant::get_method_argument_names(basic_type, function); Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function); return PropertyInfo(types[p_idx], names[p_idx]); } else { - MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { return mb->get_argument_info(p_idx); @@ -219,14 +217,11 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const { - #ifdef DEBUG_METHODS_ENABLED if (call_mode == CALL_MODE_BASIC_TYPE) { - return PropertyInfo(Variant::get_method_return_type(basic_type, function), ""); } else { - if (call_mode == CALL_MODE_INSTANCE) { if (p_idx == 0) { return PropertyInfo(Variant::OBJECT, "pass", PROPERTY_HINT_TYPE_STRING, get_base_type()); @@ -260,20 +255,21 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con } String VisualScriptFunctionCall::get_caption() const { - if (call_mode == CALL_MODE_SELF) + if (call_mode == CALL_MODE_SELF) { return " " + String(function) + "()"; - if (call_mode == CALL_MODE_SINGLETON) + } + if (call_mode == CALL_MODE_SINGLETON) { return String(singleton) + ":" + String(function) + "()"; - else if (call_mode == CALL_MODE_BASIC_TYPE) + } else if (call_mode == CALL_MODE_BASIC_TYPE) { return Variant::get_type_name(basic_type) + "." + String(function) + "()"; - else if (call_mode == CALL_MODE_NODE_PATH) + } else if (call_mode == CALL_MODE_NODE_PATH) { return " [" + String(base_path.simplified()) + "]." + String(function) + "()"; - else + } else { return " " + base_type + "." + String(function) + "()"; + } } String VisualScriptFunctionCall::get_text() const { - if (rpc_call_mode) { return "RPC"; } @@ -281,9 +277,9 @@ String VisualScriptFunctionCall::get_text() const { } void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { - - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -291,14 +287,13 @@ void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptFunctionCall::get_basic_type() const { - return basic_type; } void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { - - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -306,14 +301,13 @@ void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { } StringName VisualScriptFunctionCall::get_base_type() const { - return base_type; } void VisualScriptFunctionCall::set_base_script(const String &p_path) { - - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -321,14 +315,13 @@ void VisualScriptFunctionCall::set_base_script(const String &p_path) { } String VisualScriptFunctionCall::get_base_script() const { - return base_script; } void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { - - if (singleton == p_type) + if (singleton == p_type) { return; + } singleton = p_type; Object *obj = Engine::get_singleton()->get_singleton_object(singleton); @@ -341,7 +334,6 @@ void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { } StringName VisualScriptFunctionCall::get_singleton() const { - return singleton; } @@ -350,7 +342,6 @@ void VisualScriptFunctionCall::_update_method_cache() { Ref<Script> script; if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { type = node->get_class(); @@ -358,7 +349,6 @@ void VisualScriptFunctionCall::_update_method_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too @@ -366,7 +356,6 @@ void VisualScriptFunctionCall::_update_method_cache() { } } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { type = obj->get_class(); @@ -374,17 +363,13 @@ void VisualScriptFunctionCall::_update_method_cache() { } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -421,16 +406,15 @@ void VisualScriptFunctionCall::_update_method_cache() { } } } else if (script.is_valid() && script->has_method(function)) { - method_cache = script->get_method_info(function); use_default_args = method_cache.default_arguments.size(); } } void VisualScriptFunctionCall::set_function(const StringName &p_type) { - - if (function == p_type) + if (function == p_type) { return; + } function = p_type; @@ -445,15 +429,15 @@ void VisualScriptFunctionCall::set_function(const StringName &p_type) { _change_notify(); ports_changed_notify(); } -StringName VisualScriptFunctionCall::get_function() const { +StringName VisualScriptFunctionCall::get_function() const { return function; } void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { - - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _change_notify(); @@ -461,59 +445,54 @@ void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { } NodePath VisualScriptFunctionCall::get_base_path() const { - return base_path; } void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { - - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _change_notify(); ports_changed_notify(); } -VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const { +VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const { return call_mode; } void VisualScriptFunctionCall::set_use_default_args(int p_amount) { - - if (use_default_args == p_amount) + if (use_default_args == p_amount) { return; + } use_default_args = p_amount; ports_changed_notify(); } void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) { - - if (rpc_call_mode == p_mode) + if (rpc_call_mode == p_mode) { return; + } rpc_call_mode = p_mode; ports_changed_notify(); _change_notify(); } VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const { - return rpc_call_mode; } int VisualScriptFunctionCall::get_use_default_args() const { - return use_default_args; } void VisualScriptFunctionCall::set_validate(bool p_amount) { - validate = p_amount; } bool VisualScriptFunctionCall::get_validate() const { - return validate; } @@ -523,12 +502,10 @@ void VisualScriptFunctionCall::_set_argument_cache(const Dictionary &p_cache) { } Dictionary VisualScriptFunctionCall::_get_argument_cache() const { - return method_cache; } void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -556,8 +533,9 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const property.hint = PROPERTY_HINT_ENUM; String sl; for (List<Engine::Singleton>::Element *E = names.front(); E; E = E->next()) { - if (sl != String()) + if (sl != String()) { sl += ","; + } sl += E->get().name; } property.hint_string = sl; @@ -568,7 +546,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -577,9 +554,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (property.name == "function") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -587,13 +562,11 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE; property.hint_string = itos(obj->get_instance_id()); } else { - property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE; property.hint_string = base_type; //should be cached } @@ -603,15 +576,12 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -631,18 +601,15 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (property.name == "use_default_args") { - property.hint = PROPERTY_HINT_RANGE; int mc = 0; if (call_mode == CALL_MODE_BASIC_TYPE) { - mc = Variant::get_method_default_arguments(basic_type, function).size(); } else { MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { - mc = mb->get_default_argument_count(); } } @@ -650,7 +617,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (mc == 0) { property.usage = 0; //do not show } else { - property.hint_string = "0," + itos(mc) + ",1"; } } @@ -663,7 +629,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } void VisualScriptFunctionCall::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptFunctionCall::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptFunctionCall::get_base_type); @@ -699,8 +664,9 @@ void VisualScriptFunctionCall::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -712,8 +678,9 @@ void VisualScriptFunctionCall::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -761,13 +728,14 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } _FORCE_INLINE_ bool call_rpc(Object *p_base, const Variant **p_args, int p_argcount) { - - if (!p_base) + if (!p_base) { return false; + } Node *node = Object::cast_to<Node>(p_base); - if (!node) + if (!node) { return false; + } int to_id = 0; bool reliable = true; @@ -789,11 +757,8 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptFunctionCall::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); if (rpc_mode) { @@ -805,7 +770,6 @@ public: } } break; case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -831,7 +795,6 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_INSTANCE: case VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE: { - Variant v = *p_inputs[0]; if (rpc_mode) { @@ -863,7 +826,6 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_SINGLETON: { - Object *object = Engine::get_singleton()->get_singleton_object(singleton); if (!object) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -882,7 +844,6 @@ public: } if (!validate) { - //ignore call errors if validation is disabled r_error.error = Callable::CallError::CALL_OK; r_error_str = String(); @@ -893,7 +854,6 @@ public: }; VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall); instance->node = this; instance->instance = p_instance; @@ -909,7 +869,6 @@ VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstanc } VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess *p_inputs, int p_output) const { - if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) { return p_inputs[0]; } @@ -918,7 +877,6 @@ VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type( } VisualScriptFunctionCall::VisualScriptFunctionCall() { - validate = true; call_mode = CALL_MODE_SELF; basic_type = Variant::NIL; @@ -929,7 +887,6 @@ VisualScriptFunctionCall::VisualScriptFunctionCall() { template <VisualScriptFunctionCall::CallMode cmode> static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { - Ref<VisualScriptFunctionCall> node; node.instance(); node->set_call_mode(cmode); @@ -941,41 +898,43 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptPropertySet::get_output_sequence_port_count() const { - return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0; } bool VisualScriptPropertySet::has_input_sequence_port() const { - return call_mode != CALL_MODE_BASIC_TYPE; } Node *VisualScriptPropertySet::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -987,38 +946,34 @@ Node *VisualScriptPropertySet::_get_base_node() const { } StringName VisualScriptPropertySet::_get_base_type() const { - - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { return get_visual_script()->get_instance_base_type(); - else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; } int VisualScriptPropertySet::get_input_value_port_count() const { - int pc = (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 2 : 1; return pc; } -int VisualScriptPropertySet::get_output_value_port_count() const { +int VisualScriptPropertySet::get_output_value_port_count() const { return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0; } String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const { - return String(); } void VisualScriptPropertySet::_adjust_input_index(PropertyInfo &pinfo) const { - if (index != StringName()) { - Variant v; Callable::CallError ce; v = Variant::construct(pinfo.type, nullptr, 0, ce); @@ -1065,7 +1020,6 @@ PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) cons } String VisualScriptPropertySet::get_caption() const { - static const char *opname[ASSIGN_OP_MAX] = { "Set", "Add", "Subtract", "Multiply", "Divide", "Mod", "ShiftLeft", "ShiftRight", "BitAnd", "BitOr", "BitXor" }; @@ -1079,7 +1033,6 @@ String VisualScriptPropertySet::get_caption() const { } String VisualScriptPropertySet::get_text() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); } @@ -1096,22 +1049,21 @@ String VisualScriptPropertySet::get_text() const { void VisualScriptPropertySet::_update_base_type() { //cache it because this information may not be available on load if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { base_type = node->get_class(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { base_type = get_visual_script()->get_instance_base_type(); } } } -void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) +void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -1120,14 +1072,13 @@ void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptPropertySet::get_basic_type() const { - return basic_type; } void VisualScriptPropertySet::set_base_type(const StringName &p_type) { - - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -1135,14 +1086,13 @@ void VisualScriptPropertySet::set_base_type(const StringName &p_type) { } StringName VisualScriptPropertySet::get_base_type() const { - return base_type; } void VisualScriptPropertySet::set_base_script(const String &p_path) { - - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -1150,20 +1100,19 @@ void VisualScriptPropertySet::set_base_script(const String &p_path) { } String VisualScriptPropertySet::get_base_script() const { - return base_script; } void VisualScriptPropertySet::_update_cache() { - - if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) + if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) { return; + } - if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise + if (!Engine::get_singleton()->is_editor_hint()) { //only update cache if editor exists, it's pointless otherwise return; + } if (call_mode == CALL_MODE_BASIC_TYPE) { - //not super efficient.. Variant v; @@ -1174,21 +1123,17 @@ void VisualScriptPropertySet::_update_cache() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { - type_cache = E->get(); } } } else { - StringName type; Ref<Script> script; Node *node = nullptr; if (call_mode == CALL_MODE_NODE_PATH) { - node = _get_base_node(); if (node) { type = node->get_class(); @@ -1196,24 +1141,19 @@ void VisualScriptPropertySet::_update_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too script = get_visual_script(); } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -1224,19 +1164,16 @@ void VisualScriptPropertySet::_update_cache() { List<PropertyInfo> pinfo; if (node) { - node->get_property_list(&pinfo); } else { ClassDB::get_property_list(type, &pinfo); } if (script.is_valid()) { - script->get_script_property_list(&pinfo); } for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { type_cache = E->get(); return; @@ -1246,9 +1183,9 @@ void VisualScriptPropertySet::_update_cache() { } void VisualScriptPropertySet::set_property(const StringName &p_type) { - - if (property == p_type) + if (property == p_type) { return; + } property = p_type; index = StringName(); @@ -1256,15 +1193,15 @@ void VisualScriptPropertySet::set_property(const StringName &p_type) { _change_notify(); ports_changed_notify(); } -StringName VisualScriptPropertySet::get_property() const { +StringName VisualScriptPropertySet::get_property() const { return property; } void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { - - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _update_base_type(); @@ -1273,22 +1210,21 @@ void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { } NodePath VisualScriptPropertySet::get_base_path() const { - return base_path; } void VisualScriptPropertySet::set_call_mode(CallMode p_mode) { - - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _update_base_type(); _change_notify(); ports_changed_notify(); } -VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const { +VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const { return call_mode; } @@ -1297,14 +1233,13 @@ void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) { } Dictionary VisualScriptPropertySet::_get_type_cache() const { - return type_cache; } void VisualScriptPropertySet::set_index(const StringName &p_type) { - - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -1312,15 +1247,14 @@ void VisualScriptPropertySet::set_index(const StringName &p_type) { } StringName VisualScriptPropertySet::get_index() const { - return index; } void VisualScriptPropertySet::set_assign_op(AssignOp p_op) { - ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX); - if (assign_op == p_op) + if (assign_op == p_op) { return; + } assign_op = p_op; _update_cache(); @@ -1333,7 +1267,6 @@ VisualScriptPropertySet::AssignOp VisualScriptPropertySet::get_assign_op() const } void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -1356,7 +1289,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -1365,9 +1297,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } if (property.name == "property") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -1380,15 +1310,12 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -1408,7 +1335,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } if (property.name == "index") { - Callable::CallError ce; Variant v = Variant::construct(type_cache.type, nullptr, 0, ce); List<PropertyInfo> plist; @@ -1421,13 +1347,13 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { property.hint = PROPERTY_HINT_ENUM; property.hint_string = options; property.type = Variant::STRING; - if (options == "") + if (options == "") { property.usage = 0; //hide if type has no usable index + } } } void VisualScriptPropertySet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertySet::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertySet::get_base_type); @@ -1457,8 +1383,9 @@ void VisualScriptPropertySet::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -1470,8 +1397,9 @@ void VisualScriptPropertySet::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -1520,11 +1448,9 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } _FORCE_INLINE_ void _process_get(Variant &source, const Variant &p_argument, bool &valid) { - if (index != StringName() && assign_op == VisualScriptPropertySet::ASSIGN_OP_NONE) { source.set_named(index, p_argument, &valid); } else { - Variant value; if (index != StringName()) { value = source.get_named(index, &valid); @@ -1579,11 +1505,8 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptPropertySet::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); bool valid; @@ -1602,7 +1525,6 @@ public: } } break; case VisualScriptPropertySet::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -1620,7 +1542,6 @@ public: bool valid; if (needs_get) { - Variant value = another->get(property, &valid); _process_get(value, *p_inputs[0], valid); another->set(property, value, &valid); @@ -1636,7 +1557,6 @@ public: } break; case VisualScriptPropertySet::CALL_MODE_INSTANCE: case VisualScriptPropertySet::CALL_MODE_BASIC_TYPE: { - Variant v = *p_inputs[0]; bool valid; @@ -1664,7 +1584,6 @@ public: }; VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet); instance->node = this; instance->instance = p_instance; @@ -1678,15 +1597,14 @@ VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance } VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess *p_inputs, int p_output) const { - if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) { return p_inputs[0]; } return VisualScriptNode::guess_output_type(p_inputs, p_output); } -VisualScriptPropertySet::VisualScriptPropertySet() { +VisualScriptPropertySet::VisualScriptPropertySet() { assign_op = ASSIGN_OP_NONE; call_mode = CALL_MODE_SELF; base_type = "Object"; @@ -1695,7 +1613,6 @@ VisualScriptPropertySet::VisualScriptPropertySet() { template <VisualScriptPropertySet::CallMode cmode> static Ref<VisualScriptNode> create_property_set_node(const String &p_name) { - Ref<VisualScriptPropertySet> node; node.instance(); node->set_call_mode(cmode); @@ -1707,55 +1624,57 @@ static Ref<VisualScriptNode> create_property_set_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptPropertyGet::get_output_sequence_port_count() const { - return 0; // (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1; } bool VisualScriptPropertyGet::has_input_sequence_port() const { - return false; //(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true; } + void VisualScriptPropertyGet::_update_base_type() { //cache it because this information may not be available on load if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { base_type = node->get_class(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { base_type = get_visual_script()->get_instance_base_type(); } } } -Node *VisualScriptPropertyGet::_get_base_node() const { +Node *VisualScriptPropertyGet::_get_base_node() const { #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -1767,34 +1686,31 @@ Node *VisualScriptPropertyGet::_get_base_node() const { } StringName VisualScriptPropertyGet::_get_base_type() const { - - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { return get_visual_script()->get_instance_base_type(); - else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; } int VisualScriptPropertyGet::get_input_value_port_count() const { - return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0; } -int VisualScriptPropertyGet::get_output_value_port_count() const { +int VisualScriptPropertyGet::get_output_value_port_count() const { return 1; } String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) { if (p_idx == 0) { PropertyInfo pi; @@ -1819,12 +1735,10 @@ PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) cons } String VisualScriptPropertyGet::get_caption() const { - return String("Get ") + property; } String VisualScriptPropertyGet::get_text() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); } @@ -1839,9 +1753,9 @@ String VisualScriptPropertyGet::get_text() const { } void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { - - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -1849,14 +1763,13 @@ void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { } StringName VisualScriptPropertyGet::get_base_type() const { - return base_type; } void VisualScriptPropertyGet::set_base_script(const String &p_path) { - - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -1864,14 +1777,11 @@ void VisualScriptPropertyGet::set_base_script(const String &p_path) { } String VisualScriptPropertyGet::get_base_script() const { - return base_script; } void VisualScriptPropertyGet::_update_cache() { - if (call_mode == CALL_MODE_BASIC_TYPE) { - //not super efficient.. Variant v; @@ -1882,22 +1792,18 @@ void VisualScriptPropertyGet::_update_cache() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { - type_cache = E->get().type; return; } } } else { - StringName type; Ref<Script> script; Node *node = nullptr; if (call_mode == CALL_MODE_NODE_PATH) { - node = _get_base_node(); if (node) { type = node->get_class(); @@ -1905,24 +1811,19 @@ void VisualScriptPropertyGet::_update_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too script = get_visual_script(); } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -1942,7 +1843,6 @@ void VisualScriptPropertyGet::_update_cache() { } if (node) { - Variant prop = node->get(property, &valid); if (valid) { type_cache = prop.get_type(); @@ -1951,7 +1851,6 @@ void VisualScriptPropertyGet::_update_cache() { } if (script.is_valid()) { - type_ret = script->get_static_property_type(property, &valid); if (valid) { @@ -1963,9 +1862,9 @@ void VisualScriptPropertyGet::_update_cache() { } void VisualScriptPropertyGet::set_property(const StringName &p_type) { - - if (property == p_type) + if (property == p_type) { return; + } property = p_type; @@ -1973,15 +1872,15 @@ void VisualScriptPropertyGet::set_property(const StringName &p_type) { _change_notify(); ports_changed_notify(); } -StringName VisualScriptPropertyGet::get_property() const { +StringName VisualScriptPropertyGet::get_property() const { return property; } void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { - - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _change_notify(); @@ -1990,29 +1889,28 @@ void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { } NodePath VisualScriptPropertyGet::get_base_path() const { - return base_path; } void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) { - - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _change_notify(); _update_base_type(); ports_changed_notify(); } -VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const { +VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const { return call_mode; } void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { - - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -2020,7 +1918,6 @@ void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptPropertyGet::get_basic_type() const { - return basic_type; } @@ -2029,14 +1926,13 @@ void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { } Variant::Type VisualScriptPropertyGet::_get_type_cache() const { - return type_cache; } void VisualScriptPropertyGet::set_index(const StringName &p_type) { - - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -2044,12 +1940,10 @@ void VisualScriptPropertyGet::set_index(const StringName &p_type) { } StringName VisualScriptPropertyGet::get_index() const { - return index; } void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -2072,7 +1966,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -2081,9 +1974,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } if (property.name == "property") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -2096,15 +1987,12 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -2123,7 +2011,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } if (property.name == "index") { - Callable::CallError ce; Variant v = Variant::construct(type_cache, nullptr, 0, ce); List<PropertyInfo> plist; @@ -2136,13 +2023,13 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { property.hint = PROPERTY_HINT_ENUM; property.hint_string = options; property.type = Variant::STRING; - if (options == "") + if (options == "") { property.usage = 0; //hide if type has no usable index + } } } void VisualScriptPropertyGet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertyGet::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertyGet::get_base_type); @@ -2169,8 +2056,9 @@ void VisualScriptPropertyGet::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -2182,8 +2070,9 @@ void VisualScriptPropertyGet::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "." + E->get(); } @@ -2212,11 +2101,8 @@ public: VisualScriptInstance *instance; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptPropertyGet::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); bool valid; @@ -2234,7 +2120,6 @@ public: } } break; case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2265,7 +2150,6 @@ public: } break; default: { - bool valid; Variant v = *p_inputs[0]; @@ -2286,7 +2170,6 @@ public: }; VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet); instance->node = this; instance->instance = p_instance; @@ -2299,7 +2182,6 @@ VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance } VisualScriptPropertyGet::VisualScriptPropertyGet() { - call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; @@ -2308,7 +2190,6 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { template <VisualScriptPropertyGet::CallMode cmode> static Ref<VisualScriptNode> create_property_get_node(const String &p_name) { - Ref<VisualScriptPropertyGet> node; node.instance(); node->set_call_mode(cmode); @@ -2320,44 +2201,40 @@ static Ref<VisualScriptNode> create_property_get_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptEmitSignal::get_output_sequence_port_count() const { - return 1; } bool VisualScriptEmitSignal::has_input_sequence_port() const { - return true; } int VisualScriptEmitSignal::get_input_value_port_count() const { - Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - - if (!vs->has_custom_signal(name)) + if (!vs->has_custom_signal(name)) { return 0; + } return vs->custom_signal_get_argument_count(name); } return 0; } + int VisualScriptEmitSignal::get_output_value_port_count() const { return 0; } String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const { - Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - - if (!vs->has_custom_signal(name)) + if (!vs->has_custom_signal(name)) { return PropertyInfo(); + } return PropertyInfo(vs->custom_signal_get_argument_type(name, p_idx), vs->custom_signal_get_argument_name(name, p_idx)); } @@ -2366,32 +2243,29 @@ PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptEmitSignal::get_caption() const { - return "Emit " + String(name); } void VisualScriptEmitSignal::set_signal(const StringName &p_type) { - - if (name == p_type) + if (name == p_type) { return; + } name = p_type; _change_notify(); ports_changed_notify(); } -StringName VisualScriptEmitSignal::get_signal() const { +StringName VisualScriptEmitSignal::get_signal() const { return name; } void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "signal") { property.hint = PROPERTY_HINT_ENUM; @@ -2399,15 +2273,14 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - vs->get_custom_signal_list(&sigs); } String ml; for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) { - - if (ml != String()) + if (ml != String()) { ml += ","; + } ml += E->get(); } @@ -2416,7 +2289,6 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { } void VisualScriptEmitSignal::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_signal", "name"), &VisualScriptEmitSignal::set_signal); ClassDB::bind_method(D_METHOD("get_signal"), &VisualScriptEmitSignal::get_signal); @@ -2435,7 +2307,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Object *obj = instance->get_owner_ptr(); obj->emit_signal(name, p_inputs, argcount); @@ -2445,7 +2316,6 @@ public: }; VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal); instance->node = this; instance->instance = p_instance; @@ -2458,7 +2328,6 @@ VisualScriptEmitSignal::VisualScriptEmitSignal() { } static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { - Vector<String> path = p_name.split("/"); ERR_FAIL_COND_V(path.size() < 4, Ref<VisualScriptNode>()); String base_type = path[2]; @@ -2470,7 +2339,6 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { Variant::Type type = Variant::VARIANT_MAX; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (Variant::get_type_name(Variant::Type(i)) == base_type) { type = Variant::Type(i); break; @@ -2487,7 +2355,6 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { } void register_visual_script_func_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/call", create_node_generic<VisualScriptFunctionCall>); VisualScriptLanguage::singleton->add_register_func("functions/set", create_node_generic<VisualScriptPropertySet>); VisualScriptLanguage::singleton->add_register_func("functions/get", create_node_generic<VisualScriptPropertyGet>); @@ -2497,7 +2364,6 @@ void register_visual_script_func_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/emit_signal", create_node_generic<VisualScriptEmitSignal>); for (int i = 0; i < Variant::VARIANT_MAX; i++) { - Variant::Type t = Variant::Type(i); String type_name = Variant::get_type_name(t); Callable::CallError ce; diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 2dba0ae3c1..6921f0e820 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptFunctionCall : public VisualScriptNode { - GDCLASS(VisualScriptFunctionCall, VisualScriptNode); public: @@ -137,7 +136,6 @@ VARIANT_ENUM_CAST(VisualScriptFunctionCall::CallMode); VARIANT_ENUM_CAST(VisualScriptFunctionCall::RPCCallMode); class VisualScriptPropertySet : public VisualScriptNode { - GDCLASS(VisualScriptPropertySet, VisualScriptNode); public: @@ -243,7 +241,6 @@ VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode); VARIANT_ENUM_CAST(VisualScriptPropertySet::AssignOp); class VisualScriptPropertyGet : public VisualScriptNode { - GDCLASS(VisualScriptPropertyGet, VisualScriptNode); public: @@ -325,7 +322,6 @@ public: VARIANT_ENUM_CAST(VisualScriptPropertyGet::CallMode); class VisualScriptEmitSignal : public VisualScriptNode { - GDCLASS(VisualScriptEmitSignal, VisualScriptNode); private: diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 52399d29d0..87aa64211e 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -43,13 +43,12 @@ ////////////////////////////////////////// bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "argument_count") { - int new_argc = p_value; int argc = arguments.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } arguments.resize(new_argc); @@ -66,7 +65,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value ERR_FAIL_INDEX_V(idx, arguments.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); arguments.write[idx].type = new_type; ports_changed_notify(); @@ -75,7 +73,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } if (what == "name") { - arguments.write[idx].name = p_value; ports_changed_notify(); return true; @@ -107,7 +104,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "argument_count") { r_ret = arguments.size(); return true; @@ -148,8 +144,8 @@ bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const return false; } -void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { @@ -171,35 +167,30 @@ void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const } int VisualScriptFunction::get_output_sequence_port_count() const { - return 1; } bool VisualScriptFunction::has_input_sequence_port() const { - return false; } int VisualScriptFunction::get_input_value_port_count() const { - return 0; } -int VisualScriptFunction::get_output_value_port_count() const { +int VisualScriptFunction::get_output_value_port_count() const { return arguments.size(); } String VisualScriptFunction::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const { - ERR_FAIL_V(PropertyInfo()); } -PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo()); PropertyInfo out; out.type = arguments[p_idx].type; @@ -210,55 +201,53 @@ PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { } String VisualScriptFunction::get_caption() const { - return "Function"; } String VisualScriptFunction::get_text() const { - return get_name(); //use name as function name I guess } void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_name, int p_index, const PropertyHint p_hint, const String &p_hint_string) { - Argument arg; arg.name = p_name; arg.type = p_type; arg.hint = p_hint; arg.hint_string = p_hint_string; - if (p_index >= 0) + if (p_index >= 0) { arguments.insert(p_index, arg); - else + } else { arguments.push_back(arg); + } ports_changed_notify(); } -void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) { +void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].type = p_type; ports_changed_notify(); } -Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const { +Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const { ERR_FAIL_INDEX_V(p_argidx, arguments.size(), Variant::NIL); return arguments[p_argidx].type; } -void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) { +void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].name = p_name; ports_changed_notify(); } -String VisualScriptFunction::get_argument_name(int p_argidx) const { +String VisualScriptFunction::get_argument_name(int p_argidx) const { ERR_FAIL_INDEX_V(p_argidx, arguments.size(), String()); return arguments[p_argidx].name; } -void VisualScriptFunction::remove_argument(int p_argidx) { +void VisualScriptFunction::remove_argument(int p_argidx) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.remove(p_argidx); @@ -266,7 +255,6 @@ void VisualScriptFunction::remove_argument(int p_argidx) { } int VisualScriptFunction::get_argument_count() const { - return arguments.size(); } @@ -286,7 +274,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - int ac = node->get_argument_count(); for (int i = 0; i < ac; i++) { @@ -310,7 +297,6 @@ public: }; VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction); instance->node = this; instance->instance = p_instance; @@ -318,7 +304,6 @@ VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p } VisualScriptFunction::VisualScriptFunction() { - stack_size = 256; stack_less = false; sequenced = true; @@ -335,23 +320,19 @@ bool VisualScriptFunction::is_stack_less() const { } void VisualScriptFunction::set_sequenced(bool p_enable) { - sequenced = p_enable; } bool VisualScriptFunction::is_sequenced() const { - return sequenced; } void VisualScriptFunction::set_stack_size(int p_size) { - ERR_FAIL_COND(p_size < 1 || p_size > 100000); stack_size = p_size; } int VisualScriptFunction::get_stack_size() const { - return stack_size; } @@ -360,10 +341,12 @@ int VisualScriptFunction::get_stack_size() const { ////////////////////////////////////////// int VisualScriptLists::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } + bool VisualScriptLists::has_input_sequence_port() const { return sequenced; } @@ -375,6 +358,7 @@ String VisualScriptLists::get_output_sequence_port_text(int p_port) const { int VisualScriptLists::get_input_value_port_count() const { return inputports.size(); } + int VisualScriptLists::get_output_value_port_count() const { return outputports.size(); } @@ -387,6 +371,7 @@ PropertyInfo VisualScriptLists::get_input_value_port_info(int p_idx) const { pi.type = inputports[p_idx].type; return pi; } + PropertyInfo VisualScriptLists::get_output_value_port_info(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, outputports.size(), PropertyInfo()); @@ -399,9 +384,11 @@ PropertyInfo VisualScriptLists::get_output_value_port_info(int p_idx) const { bool VisualScriptLists::is_input_port_editable() const { return ((flags & INPUT_EDITABLE) == INPUT_EDITABLE); } + bool VisualScriptLists::is_input_port_name_editable() const { return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE); } + bool VisualScriptLists::is_input_port_type_editable() const { return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE); } @@ -409,22 +396,23 @@ bool VisualScriptLists::is_input_port_type_editable() const { bool VisualScriptLists::is_output_port_editable() const { return ((flags & OUTPUT_EDITABLE) == OUTPUT_EDITABLE); } + bool VisualScriptLists::is_output_port_name_editable() const { return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE); } + bool VisualScriptLists::is_output_port_type_editable() const { return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE); } // for the inspector bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "input_count" && is_input_port_editable()) { - int new_argc = p_value; int argc = inputports.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } inputports.resize(new_argc); @@ -441,7 +429,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, inputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); inputports.write[idx].type = new_type; ports_changed_notify(); @@ -450,7 +437,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - inputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -458,11 +444,11 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (p_name == "output_count" && is_output_port_editable()) { - int new_argc = p_value; int argc = outputports.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } outputports.resize(new_argc); @@ -479,7 +465,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, outputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); outputports.write[idx].type = new_type; ports_changed_notify(); @@ -488,7 +473,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - outputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -503,8 +487,8 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { +bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "input_count" && is_input_port_editable()) { r_ret = inputports.size(); return true; @@ -548,8 +532,8 @@ bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { if (is_input_port_editable()) { p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; @@ -580,25 +564,27 @@ void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { // input data port interaction void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String &p_name, int p_index) { - - if (!is_input_port_editable()) + if (!is_input_port_editable()) { return; + } Port inp; inp.name = p_name; inp.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { inputports.insert(p_index, inp); - else + } else { inputports.push_back(inp); + } ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_input_port_type_editable()) +void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { + if (!is_input_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -606,10 +592,11 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { - if (!is_input_port_name_editable()) +void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { + if (!is_input_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -617,10 +604,11 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name ports_changed_notify(); _change_notify(); } -void VisualScriptLists::remove_input_data_port(int p_argidx) { - if (!is_input_port_editable()) +void VisualScriptLists::remove_input_data_port(int p_argidx) { + if (!is_input_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, inputports.size()); @@ -632,25 +620,27 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) { // output data port interaction void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String &p_name, int p_index) { - - if (!is_output_port_editable()) + if (!is_output_port_editable()) { return; + } Port out; out.name = p_name; out.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { outputports.insert(p_index, out); - else + } else { outputports.push_back(out); + } ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_output_port_type_editable()) +void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { + if (!is_output_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -658,10 +648,11 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { - if (!is_output_port_name_editable()) +void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { + if (!is_output_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -669,10 +660,11 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam ports_changed_notify(); _change_notify(); } -void VisualScriptLists::remove_output_data_port(int p_argidx) { - if (!is_output_port_editable()) +void VisualScriptLists::remove_output_data_port(int p_argidx) { + if (!is_output_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, outputports.size()); @@ -684,11 +676,13 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) { // sequences void VisualScriptLists::set_sequenced(bool p_enable) { - if (sequenced == p_enable) + if (sequenced == p_enable) { return; + } sequenced = p_enable; ports_changed_notify(); } + bool VisualScriptLists::is_sequenced() const { return sequenced; } @@ -716,10 +710,12 @@ void VisualScriptLists::_bind_methods() { ////////////////////////////////////////// int VisualScriptComposeArray::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } + bool VisualScriptComposeArray::has_input_sequence_port() const { return sequenced; } @@ -731,6 +727,7 @@ String VisualScriptComposeArray::get_output_sequence_port_text(int p_port) const int VisualScriptComposeArray::get_input_value_port_count() const { return inputports.size(); } + int VisualScriptComposeArray::get_output_value_port_count() const { return 1; } @@ -743,6 +740,7 @@ PropertyInfo VisualScriptComposeArray::get_input_value_port_info(int p_idx) cons pi.type = inputports[p_idx].type; return pi; } + PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) const { PropertyInfo pi; pi.name = "out"; @@ -753,6 +751,7 @@ PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) con String VisualScriptComposeArray::get_caption() const { return "Compose Array"; } + String VisualScriptComposeArray::get_text() const { return ""; } @@ -763,11 +762,11 @@ public: virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (input_count > 0) { Array arr; - for (int i = 0; i < input_count; i++) + for (int i = 0; i < input_count; i++) { arr.push_back((*p_inputs[i])); + } Variant va = Variant(arr); *p_outputs[0] = va; @@ -778,7 +777,6 @@ public: }; VisualScriptNodeInstance *VisualScriptComposeArray::instance(VisualScriptInstance *p_instance) { - VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode); instance->input_count = inputports.size(); return instance; @@ -795,31 +793,26 @@ VisualScriptComposeArray::VisualScriptComposeArray() { ////////////////////////////////////////// int VisualScriptOperator::get_output_sequence_port_count() const { - return 0; } bool VisualScriptOperator::has_input_sequence_port() const { - return false; } int VisualScriptOperator::get_input_value_port_count() const { - return (op == Variant::OP_BIT_NEGATE || op == Variant::OP_NOT || op == Variant::OP_NEGATE || op == Variant::OP_POSITIVE) ? 1 : 2; } -int VisualScriptOperator::get_output_value_port_count() const { +int VisualScriptOperator::get_output_value_port_count() const { return 1; } String VisualScriptOperator::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { - static const Variant::Type port_types[Variant::OP_MAX][2] = { { Variant::NIL, Variant::NIL }, //OP_EQUAL, { Variant::NIL, Variant::NIL }, //OP_NOT_EQUAL, @@ -857,10 +850,12 @@ PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = p_idx == 0 ? "A" : "B"; pinfo.type = port_types[op][p_idx]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } + PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { static const Variant::Type port_types[Variant::OP_MAX] = { //comparison @@ -898,8 +893,9 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = ""; pinfo.type = port_types[op]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } @@ -937,7 +933,6 @@ static const char *op_names[] = { }; String VisualScriptOperator::get_caption() const { - static const wchar_t *op_names[] = { //comparison L"A = B", //OP_EQUAL, @@ -974,34 +969,31 @@ String VisualScriptOperator::get_caption() const { } void VisualScriptOperator::set_operator(Variant::Operator p_op) { - - if (op == p_op) + if (op == p_op) { return; + } op = p_op; ports_changed_notify(); } Variant::Operator VisualScriptOperator::get_operator() const { - return op; } void VisualScriptOperator::set_typed(Variant::Type p_op) { - - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); } Variant::Type VisualScriptOperator::get_typed() const { - return typed; } void VisualScriptOperator::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualScriptOperator::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualScriptOperator::get_operator); @@ -1010,8 +1002,9 @@ void VisualScriptOperator::_bind_methods() { String types; for (int i = 0; i < Variant::OP_MAX; i++) { - if (i > 0) + if (i > 0) { types += ","; + } types += op_names[i]; } @@ -1032,25 +1025,23 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; if (unary) { - Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid); } else { Variant::evaluate(op, *p_inputs[0], *p_inputs[1], *p_outputs[0], valid); } if (!valid) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; if (p_outputs[0]->get_type() == Variant::STRING) { r_error_str = *p_outputs[0]; } else { - if (unary) + if (unary) { r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); - else + } else { r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); + } } } @@ -1059,7 +1050,6 @@ public: }; VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator); instance->unary = get_input_value_port_count() == 1; instance->op = op; @@ -1067,14 +1057,12 @@ VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p } VisualScriptOperator::VisualScriptOperator() { - op = Variant::OP_ADD; typed = Variant::NIL; } template <Variant::Operator OP> static Ref<VisualScriptNode> create_op_node(const String &p_name) { - Ref<VisualScriptOperator> node; node.instance(); node->set_operator(OP); @@ -1086,31 +1074,26 @@ static Ref<VisualScriptNode> create_op_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptSelect::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelect::has_input_sequence_port() const { - return false; } int VisualScriptSelect::get_input_value_port_count() const { - return 3; } -int VisualScriptSelect::get_output_value_port_count() const { +int VisualScriptSelect::get_output_value_port_count() const { return 1; } String VisualScriptSelect::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::BOOL, "cond"); } else if (p_idx == 1) { @@ -1119,37 +1102,33 @@ PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { return PropertyInfo(typed, "b"); } } -PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { return PropertyInfo(typed, "out"); } String VisualScriptSelect::get_caption() const { - return "Select"; } String VisualScriptSelect::get_text() const { - return "a if cond, else b"; } void VisualScriptSelect::set_typed(Variant::Type p_op) { - - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); } Variant::Type VisualScriptSelect::get_typed() const { - return typed; } void VisualScriptSelect::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptSelect::set_typed); ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptSelect::get_typed); @@ -1166,25 +1145,23 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool cond = *p_inputs[0]; - if (cond) + if (cond) { *p_outputs[0] = *p_inputs[1]; - else + } else { *p_outputs[0] = *p_inputs[2]; + } return 0; } }; VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect); return instance; } VisualScriptSelect::VisualScriptSelect() { - typed = Variant::NIL; } @@ -1193,36 +1170,30 @@ VisualScriptSelect::VisualScriptSelect() { ////////////////////////////////////////// int VisualScriptVariableGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptVariableGet::has_input_sequence_port() const { - return false; } int VisualScriptVariableGet::get_input_value_port_count() const { - return 0; } -int VisualScriptVariableGet::get_output_value_port_count() const { +int VisualScriptVariableGet::get_output_value_port_count() const { return 1; } String VisualScriptVariableGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "value"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1235,24 +1206,22 @@ PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) cons } String VisualScriptVariableGet::get_caption() const { - return "Get " + variable; } -void VisualScriptVariableGet::set_variable(StringName p_variable) { - if (variable == p_variable) +void VisualScriptVariableGet::set_variable(StringName p_variable) { + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } StringName VisualScriptVariableGet::get_variable() const { - return variable; } void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1260,8 +1229,9 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1272,7 +1242,6 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableGet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableGet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableGet::get_variable); @@ -1286,7 +1255,6 @@ public: StringName variable; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->get_variable(variable, p_outputs[0])) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableGet not found in script: ") + "'" + String(variable) + "'"; @@ -1297,13 +1265,13 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet); instance->node = this; instance->instance = p_instance; instance->variable = variable; return instance; } + VisualScriptVariableGet::VisualScriptVariableGet() { } @@ -1312,31 +1280,26 @@ VisualScriptVariableGet::VisualScriptVariableGet() { ////////////////////////////////////////// int VisualScriptVariableSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptVariableSet::has_input_sequence_port() const { - return true; } int VisualScriptVariableSet::get_input_value_port_count() const { - return 1; } -int VisualScriptVariableSet::get_output_value_port_count() const { +int VisualScriptVariableSet::get_output_value_port_count() const { return 0; } String VisualScriptVariableSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "set"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1349,30 +1312,26 @@ PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptVariableSet::get_caption() const { - return "Set " + variable; } void VisualScriptVariableSet::set_variable(StringName p_variable) { - - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } StringName VisualScriptVariableSet::get_variable() const { - return variable; } void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1380,8 +1339,9 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1392,7 +1352,6 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableSet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableSet::get_variable); @@ -1408,9 +1367,7 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->set_variable(variable, *p_inputs[0])) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableSet not found in script: ") + "'" + String(variable) + "'"; } @@ -1420,13 +1377,13 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet); instance->node = this; instance->instance = p_instance; instance->variable = variable; return instance; } + VisualScriptVariableSet::VisualScriptVariableSet() { } @@ -1435,36 +1392,30 @@ VisualScriptVariableSet::VisualScriptVariableSet() { ////////////////////////////////////////// int VisualScriptConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstant::has_input_sequence_port() const { - return false; } int VisualScriptConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptConstant::get_output_value_port_count() const { +int VisualScriptConstant::get_output_value_port_count() const { return 1; } String VisualScriptConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = String(value); pinfo.type = type; @@ -1472,14 +1423,13 @@ PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { } String VisualScriptConstant::get_caption() const { - return "Constant"; } void VisualScriptConstant::set_constant_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; Callable::CallError ce; @@ -1489,34 +1439,32 @@ void VisualScriptConstant::set_constant_type(Variant::Type p_type) { } Variant::Type VisualScriptConstant::get_constant_type() const { - return type; } void VisualScriptConstant::set_constant_value(Variant p_value) { - - if (value == p_value) + if (value == p_value) { return; + } value = p_value; ports_changed_notify(); } -Variant VisualScriptConstant::get_constant_value() const { +Variant VisualScriptConstant::get_constant_value() const { return value; } void VisualScriptConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "value") { property.type = type; - if (type == Variant::NIL) + if (type == Variant::NIL) { property.usage = 0; //do not save if nil + } } } void VisualScriptConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_type", "type"), &VisualScriptConstant::set_constant_type); ClassDB::bind_method(D_METHOD("get_constant_type"), &VisualScriptConstant::get_constant_type); @@ -1538,21 +1486,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = constant; return 0; } }; VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant); instance->constant = value; return instance; } VisualScriptConstant::VisualScriptConstant() { - type = Variant::NIL; } @@ -1561,36 +1506,30 @@ VisualScriptConstant::VisualScriptConstant() { ////////////////////////////////////////// int VisualScriptPreload::get_output_sequence_port_count() const { - return 0; } bool VisualScriptPreload::has_input_sequence_port() const { - return false; } int VisualScriptPreload::get_input_value_port_count() const { - return 0; } -int VisualScriptPreload::get_output_value_port_count() const { +int VisualScriptPreload::get_output_value_port_count() const { return 1; } String VisualScriptPreload::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.type = Variant::OBJECT; if (preload.is_valid()) { @@ -1611,26 +1550,23 @@ PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { } String VisualScriptPreload::get_caption() const { - return "Preload"; } void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { - - if (preload == p_preload) + if (preload == p_preload) { return; + } preload = p_preload; ports_changed_notify(); } Ref<Resource> VisualScriptPreload::get_preload() const { - return preload; } void VisualScriptPreload::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_preload", "resource"), &VisualScriptPreload::set_preload); ClassDB::bind_method(D_METHOD("get_preload"), &VisualScriptPreload::get_preload); @@ -1643,14 +1579,12 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = preload; return 0; } }; VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload); instance->preload = preload; return instance; @@ -1664,31 +1598,26 @@ VisualScriptPreload::VisualScriptPreload() { ////////////////////////////////////////// int VisualScriptIndexGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptIndexGet::has_input_sequence_port() const { - return false; } int VisualScriptIndexGet::get_input_value_port_count() const { - return 2; } -int VisualScriptIndexGet::get_output_value_port_count() const { +int VisualScriptIndexGet::get_output_value_port_count() const { return 1; } String VisualScriptIndexGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else { @@ -1697,12 +1626,10 @@ PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexGet::get_caption() const { - return "Get Index"; } @@ -1711,7 +1638,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid); @@ -1724,10 +1650,10 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet); return instance; } + VisualScriptIndexGet::VisualScriptIndexGet() { } @@ -1736,31 +1662,26 @@ VisualScriptIndexGet::VisualScriptIndexGet() { ////////////////////////////////////////// int VisualScriptIndexSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptIndexSet::has_input_sequence_port() const { - return true; } int VisualScriptIndexSet::get_input_value_port_count() const { - return 3; } -int VisualScriptIndexSet::get_output_value_port_count() const { +int VisualScriptIndexSet::get_output_value_port_count() const { return 0; } String VisualScriptIndexSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else if (p_idx == 1) { @@ -1772,12 +1693,10 @@ PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexSet::get_caption() const { - return "Set Index"; } @@ -1786,7 +1705,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = *p_inputs[0]; p_outputs[0]->set(*p_inputs[1], *p_inputs[2], &valid); @@ -1800,10 +1718,10 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet); return instance; } + VisualScriptIndexSet::VisualScriptIndexSet() { } @@ -1812,31 +1730,26 @@ VisualScriptIndexSet::VisualScriptIndexSet() { ////////////////////////////////////////// int VisualScriptGlobalConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptGlobalConstant::has_input_sequence_port() const { - return false; } int VisualScriptGlobalConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptGlobalConstant::get_output_value_port_count() const { +int VisualScriptGlobalConstant::get_output_value_port_count() const { return 1; } String VisualScriptGlobalConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1846,12 +1759,10 @@ PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) c } String VisualScriptGlobalConstant::get_caption() const { - return "Global Constant"; } void VisualScriptGlobalConstant::set_global_constant(int p_which) { - index = p_which; _change_notify(); ports_changed_notify(); @@ -1867,37 +1778,33 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = GlobalConstants::get_global_constant_value(index); return 0; } }; VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant); instance->index = index; return instance; } void VisualScriptGlobalConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_global_constant", "index"), &VisualScriptGlobalConstant::set_global_constant); ClassDB::bind_method(D_METHOD("get_global_constant"), &VisualScriptGlobalConstant::get_global_constant); String cc; for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { - - if (i > 0) + if (i > 0) { cc += ","; + } cc += GlobalConstants::get_global_constant_name(i); } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { - index = 0; } @@ -1906,31 +1813,26 @@ VisualScriptGlobalConstant::VisualScriptGlobalConstant() { ////////////////////////////////////////// int VisualScriptClassConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptClassConstant::has_input_sequence_port() const { - return false; } int VisualScriptClassConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptClassConstant::get_output_value_port_count() const { +int VisualScriptClassConstant::get_output_value_port_count() const { return 1; } String VisualScriptClassConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1943,12 +1845,10 @@ PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) co } String VisualScriptClassConstant::get_caption() const { - return "Class Constant"; } void VisualScriptClassConstant::set_class_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -1959,7 +1859,6 @@ StringName VisualScriptClassConstant::get_class_constant() { } void VisualScriptClassConstant::set_base_type(const StringName &p_which) { - base_type = p_which; List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -1992,7 +1891,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid class constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2004,16 +1902,13 @@ public: }; VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant); instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid); return instance; } void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -2028,7 +1923,6 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const } void VisualScriptClassConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_class_constant", "name"), &VisualScriptClassConstant::set_class_constant); ClassDB::bind_method(D_METHOD("get_class_constant"), &VisualScriptClassConstant::get_class_constant); @@ -2040,7 +1934,6 @@ void VisualScriptClassConstant::_bind_methods() { } VisualScriptClassConstant::VisualScriptClassConstant() { - base_type = "Object"; } @@ -2049,41 +1942,34 @@ VisualScriptClassConstant::VisualScriptClassConstant() { ////////////////////////////////////////// int VisualScriptBasicTypeConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptBasicTypeConstant::has_input_sequence_port() const { - return false; } int VisualScriptBasicTypeConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptBasicTypeConstant::get_output_value_port_count() const { +int VisualScriptBasicTypeConstant::get_output_value_port_count() const { return 1; } String VisualScriptBasicTypeConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptBasicTypeConstant::get_caption() const { - return "Basic Constant"; } @@ -2096,7 +1982,6 @@ String VisualScriptBasicTypeConstant::get_text() const { } void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -2107,7 +1992,6 @@ StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const { } void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { - type = p_which; List<StringName> constants; @@ -2141,7 +2025,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid basic type constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2153,16 +2036,13 @@ public: }; VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant); instance->value = Variant::get_constant_value(type, name, &instance->valid); return instance; } void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<StringName> constants; Variant::get_constants_for_type(type, &constants); @@ -2181,7 +2061,6 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c } void VisualScriptBasicTypeConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_basic_type", "name"), &VisualScriptBasicTypeConstant::set_basic_type); ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptBasicTypeConstant::get_basic_type); @@ -2198,7 +2077,6 @@ void VisualScriptBasicTypeConstant::_bind_methods() { } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { - type = Variant::NIL; } @@ -2229,46 +2107,38 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = { }; int VisualScriptMathConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptMathConstant::has_input_sequence_port() const { - return false; } int VisualScriptMathConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptMathConstant::get_output_value_port_count() const { +int VisualScriptMathConstant::get_output_value_port_count() const { return 1; } String VisualScriptMathConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::FLOAT, const_name[constant]); } String VisualScriptMathConstant::get_caption() const { - return "Math Constant"; } void VisualScriptMathConstant::set_math_constant(MathConstant p_which) { - constant = p_which; _change_notify(); ports_changed_notify(); @@ -2284,30 +2154,27 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = value; return 0; } }; VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant); instance->value = const_value[constant]; return instance; } void VisualScriptMathConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_math_constant", "which"), &VisualScriptMathConstant::set_math_constant); ClassDB::bind_method(D_METHOD("get_math_constant"), &VisualScriptMathConstant::get_math_constant); String cc; for (int i = 0; i < MATH_CONSTANT_MAX; i++) { - - if (i > 0) + if (i > 0) { cc += ","; + } cc += const_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); @@ -2324,7 +2191,6 @@ void VisualScriptMathConstant::_bind_methods() { } VisualScriptMathConstant::VisualScriptMathConstant() { - constant = MATH_CONSTANT_ONE; } @@ -2333,46 +2199,38 @@ VisualScriptMathConstant::VisualScriptMathConstant() { ////////////////////////////////////////// int VisualScriptEngineSingleton::get_output_sequence_port_count() const { - return 0; } bool VisualScriptEngineSingleton::has_input_sequence_port() const { - return false; } int VisualScriptEngineSingleton::get_input_value_port_count() const { - return 0; } -int VisualScriptEngineSingleton::get_output_value_port_count() const { +int VisualScriptEngineSingleton::get_output_value_port_count() const { return 1; } String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, singleton); } String VisualScriptEngineSingleton::get_caption() const { - return "Get Engine Singleton"; } void VisualScriptEngineSingleton::set_singleton(const String &p_string) { - singleton = p_string; _change_notify(); @@ -2390,21 +2248,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = singleton; return 0; } }; VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); instance->singleton = Engine::get_singleton()->get_singleton_object(singleton); return instance; } VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); TypeGuess tg; tg.type = Variant::OBJECT; @@ -2417,7 +2272,6 @@ VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output } void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) const { - String cc; List<Engine::Singleton> singletons; @@ -2425,11 +2279,13 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con Engine::get_singleton()->get_singletons(&singletons); for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { - if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") + if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") { continue; //skip these, too simple named + } - if (cc != String()) + if (cc != String()) { cc += ","; + } cc += E->get().name; } @@ -2438,7 +2294,6 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con } void VisualScriptEngineSingleton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_singleton", "name"), &VisualScriptEngineSingleton::set_singleton); ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptEngineSingleton::get_singleton); @@ -2446,7 +2301,6 @@ void VisualScriptEngineSingleton::_bind_methods() { } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { - singleton = String(); } @@ -2455,46 +2309,38 @@ VisualScriptEngineSingleton::VisualScriptEngineSingleton() { ////////////////////////////////////////// int VisualScriptSceneNode::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneNode::has_input_sequence_port() const { - return false; } int VisualScriptSceneNode::get_input_value_port_count() const { - return 0; } -int VisualScriptSceneNode::get_output_value_port_count() const { +int VisualScriptSceneNode::get_output_value_port_count() const { return 1; } String VisualScriptSceneNode::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, path.simplified()); } String VisualScriptSceneNode::get_caption() const { - return "Get Scene Node"; } void VisualScriptSceneNode::set_node_path(const NodePath &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2513,7 +2359,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2535,7 +2380,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode); instance->node = this; instance->instance = p_instance; @@ -2546,19 +2390,21 @@ VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance * #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -2567,31 +2413,34 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Node"; #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return tg; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return tg; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return tg; + } Node *another = script_node->get_node(path); @@ -2604,29 +2453,31 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu } void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { - #ifdef TOOLS_ENABLED if (property.name == "node_path") { - Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return; + } property.hint_string = script_node->get_path(); } @@ -2634,7 +2485,6 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { } void VisualScriptSceneNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_path", "path"), &VisualScriptSceneNode::set_node_path); ClassDB::bind_method(D_METHOD("get_node_path"), &VisualScriptSceneNode::get_node_path); @@ -2642,7 +2492,6 @@ void VisualScriptSceneNode::_bind_methods() { } VisualScriptSceneNode::VisualScriptSceneNode() { - path = String("."); } @@ -2651,41 +2500,34 @@ VisualScriptSceneNode::VisualScriptSceneNode() { ////////////////////////////////////////// int VisualScriptSceneTree::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneTree::has_input_sequence_port() const { - return false; } int VisualScriptSceneTree::get_input_value_port_count() const { - return 0; } -int VisualScriptSceneTree::get_output_value_port_count() const { +int VisualScriptSceneTree::get_output_value_port_count() const { return 1; } String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "Scene Tree", PROPERTY_HINT_TYPE_STRING, "SceneTree"); } String VisualScriptSceneTree::get_caption() const { - return "Get Scene Tree"; } @@ -2697,7 +2539,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2719,7 +2560,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree); instance->node = this; instance->instance = p_instance; @@ -2727,7 +2567,6 @@ VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance * } VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const { - TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "SceneTree"; @@ -2748,46 +2587,38 @@ VisualScriptSceneTree::VisualScriptSceneTree() { ////////////////////////////////////////// int VisualScriptResourcePath::get_output_sequence_port_count() const { - return 0; } bool VisualScriptResourcePath::has_input_sequence_port() const { - return false; } int VisualScriptResourcePath::get_input_value_port_count() const { - return 0; } -int VisualScriptResourcePath::get_output_value_port_count() const { +int VisualScriptResourcePath::get_output_value_port_count() const { return 1; } String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::STRING, path); } String VisualScriptResourcePath::get_caption() const { - return "Resource Path"; } void VisualScriptResourcePath::set_resource_path(const String &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2804,21 +2635,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = path; return 0; } }; VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath); instance->path = path; return instance; } void VisualScriptResourcePath::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_resource_path", "path"), &VisualScriptResourcePath::set_resource_path); ClassDB::bind_method(D_METHOD("get_resource_path"), &VisualScriptResourcePath::get_resource_path); @@ -2826,7 +2654,6 @@ void VisualScriptResourcePath::_bind_methods() { } VisualScriptResourcePath::VisualScriptResourcePath() { - path = ""; } @@ -2835,47 +2662,41 @@ VisualScriptResourcePath::VisualScriptResourcePath() { ////////////////////////////////////////// int VisualScriptSelf::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelf::has_input_sequence_port() const { - return false; } int VisualScriptSelf::get_input_value_port_count() const { - return 0; } -int VisualScriptSelf::get_output_value_port_count() const { +int VisualScriptSelf::get_output_value_port_count() const { return 1; } String VisualScriptSelf::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const { - String type_name; - if (get_visual_script().is_valid()) + if (get_visual_script().is_valid()) { type_name = get_visual_script()->get_instance_base_type(); - else + } else { type_name = "instance"; + } return PropertyInfo(Variant::OBJECT, type_name); } String VisualScriptSelf::get_caption() const { - return "Get Self"; } @@ -2886,28 +2707,26 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = instance->get_owner_ptr(); return 0; } }; VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf); instance->instance = p_instance; return instance; } VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Object"; Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } tg.gdclass = script->get_instance_base_type(); tg.script = script; @@ -2926,7 +2745,6 @@ VisualScriptSelf::VisualScriptSelf() { ////////////////////////////////////////// int VisualScriptCustomNode::get_output_sequence_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) { return get_script_instance()->call("_get_output_sequence_port_count"); } @@ -2934,7 +2752,6 @@ int VisualScriptCustomNode::get_output_sequence_port_count() const { } bool VisualScriptCustomNode::has_input_sequence_port() const { - if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) { return get_script_instance()->call("_has_input_sequence_port"); } @@ -2942,14 +2759,13 @@ bool VisualScriptCustomNode::has_input_sequence_port() const { } int VisualScriptCustomNode::get_input_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) { return get_script_instance()->call("_get_input_value_port_count"); } return 0; } -int VisualScriptCustomNode::get_output_value_port_count() const { +int VisualScriptCustomNode::get_output_value_port_count() const { if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) { return get_script_instance()->call("_get_output_value_port_count"); } @@ -2957,7 +2773,6 @@ int VisualScriptCustomNode::get_output_value_port_count() const { } String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) { return get_script_instance()->call("_get_output_sequence_port_text", p_port); } @@ -2966,7 +2781,6 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx))); @@ -2978,7 +2792,6 @@ PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx))); @@ -2990,7 +2803,6 @@ PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const } String VisualScriptCustomNode::get_caption() const { - if (get_script_instance() && get_script_instance()->has_method("_get_caption")) { return get_script_instance()->call("_get_caption"); } @@ -2998,7 +2810,6 @@ String VisualScriptCustomNode::get_caption() const { } String VisualScriptCustomNode::get_text() const { - if (get_script_instance() && get_script_instance()->has_method("_get_text")) { return get_script_instance()->call("_get_text"); } @@ -3006,7 +2817,6 @@ String VisualScriptCustomNode::get_text() const { } String VisualScriptCustomNode::get_category() const { - if (get_script_instance() && get_script_instance()->has_method("_get_category")) { return get_script_instance()->call("_get_category"); } @@ -3023,7 +2833,6 @@ public: virtual int get_working_memory_size() const { return work_mem_size; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (node->get_script_instance()) { #ifdef DEBUG_ENABLED if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) { @@ -3085,7 +2894,6 @@ public: }; VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode); instance->instance = p_instance; instance->node = this; @@ -3106,7 +2914,6 @@ void VisualScriptCustomNode::_script_changed() { } void VisualScriptCustomNode::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port")); @@ -3150,42 +2957,35 @@ VisualScriptCustomNode::VisualScriptCustomNode() { ////////////////////////////////////////// int VisualScriptSubCall::get_output_sequence_port_count() const { - return 1; } bool VisualScriptSubCall::has_input_sequence_port() const { - return true; } int VisualScriptSubCall::get_input_value_port_count() const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments.size(); } return 0; } -int VisualScriptSubCall::get_output_value_port_count() const { +int VisualScriptSubCall::get_output_value_port_count() const { return 1; } String VisualScriptSubCall::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments[p_idx]; } @@ -3194,7 +2994,6 @@ PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); @@ -3204,25 +3003,24 @@ PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { } String VisualScriptSubCall::get_caption() const { - return "SubCall"; } String VisualScriptSubCall::get_text() const { - Ref<Script> script = get_script(); if (script.is_valid()) { - if (script->get_name() != String()) + if (script->get_name() != String()) { return script->get_name(); - if (script->get_path().is_resource_file()) + } + if (script->get_path().is_resource_file()) { return script->get_path().get_file(); + } return script->get_class(); } return ""; } String VisualScriptSubCall::get_category() const { - return "custom"; } @@ -3236,7 +3034,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Node requires a script with a _subcall(<args>) method to work."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -3248,7 +3045,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall); instance->instance = p_instance; Ref<Script> script = get_script(); @@ -3262,7 +3058,6 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_ } void VisualScriptSubCall::_bind_methods() { - MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments")); scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(scmi); @@ -3276,87 +3071,78 @@ VisualScriptSubCall::VisualScriptSubCall() { ////////////////////////////////////////// int VisualScriptComment::get_output_sequence_port_count() const { - return 0; } bool VisualScriptComment::has_input_sequence_port() const { - return false; } int VisualScriptComment::get_input_value_port_count() const { return 0; } -int VisualScriptComment::get_output_value_port_count() const { +int VisualScriptComment::get_output_value_port_count() const { return 0; } String VisualScriptComment::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptComment::get_caption() const { - return title; } String VisualScriptComment::get_text() const { - return description; } void VisualScriptComment::set_title(const String &p_title) { - - if (title == p_title) + if (title == p_title) { return; + } title = p_title; ports_changed_notify(); } String VisualScriptComment::get_title() const { - return title; } void VisualScriptComment::set_description(const String &p_description) { - - if (description == p_description) + if (description == p_description) { return; + } description = p_description; ports_changed_notify(); } -String VisualScriptComment::get_description() const { +String VisualScriptComment::get_description() const { return description; } void VisualScriptComment::set_size(const Size2 &p_size) { - - if (size == p_size) + if (size == p_size) { return; + } size = p_size; ports_changed_notify(); } -Size2 VisualScriptComment::get_size() const { +Size2 VisualScriptComment::get_size() const { return size; } String VisualScriptComment::get_category() const { - return "data"; } @@ -3367,20 +3153,17 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - return 0; } }; VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment); instance->instance = p_instance; return instance; } void VisualScriptComment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_title", "title"), &VisualScriptComment::set_title); ClassDB::bind_method(D_METHOD("get_title"), &VisualScriptComment::get_title); @@ -3396,7 +3179,6 @@ void VisualScriptComment::_bind_methods() { } VisualScriptComment::VisualScriptComment() { - title = "Comment"; size = Size2(150, 150); } @@ -3406,70 +3188,60 @@ VisualScriptComment::VisualScriptComment() { ////////////////////////////////////////// int VisualScriptConstructor::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstructor::has_input_sequence_port() const { - return false; } int VisualScriptConstructor::get_input_value_port_count() const { return constructor.arguments.size(); } -int VisualScriptConstructor::get_output_value_port_count() const { +int VisualScriptConstructor::get_output_value_port_count() const { return 1; } String VisualScriptConstructor::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const { - return constructor.arguments[p_idx]; } PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptConstructor::get_caption() const { - return "Construct " + Variant::get_type_name(type); } String VisualScriptConstructor::get_category() const { - return "functions"; } void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); } Variant::Type VisualScriptConstructor::get_constructor_type() const { - return type; } void VisualScriptConstructor::set_constructor(const Dictionary &p_info) { - constructor = MethodInfo::from_dict(p_info); ports_changed_notify(); } Dictionary VisualScriptConstructor::get_constructor() const { - return constructor; } @@ -3482,7 +3254,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Callable::CallError ce; *p_outputs[0] = Variant::construct(type, p_inputs, argcount, ce); if (ce.error != Callable::CallError::CALL_OK) { @@ -3494,7 +3265,6 @@ public: }; VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor); instance->instance = p_instance; instance->type = type; @@ -3503,7 +3273,6 @@ VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance } void VisualScriptConstructor::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constructor_type", "type"), &VisualScriptConstructor::set_constructor_type); ClassDB::bind_method(D_METHOD("get_constructor_type"), &VisualScriptConstructor::get_constructor_type); @@ -3515,14 +3284,12 @@ void VisualScriptConstructor::_bind_methods() { } VisualScriptConstructor::VisualScriptConstructor() { - type = Variant::NIL; } static Map<String, Pair<Variant::Type, MethodInfo>> constructor_map; static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { - ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>()); Ref<VisualScriptConstructor> vsc; @@ -3538,69 +3305,60 @@ static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptLocalVar::get_output_sequence_port_count() const { - return 0; } bool VisualScriptLocalVar::has_input_sequence_port() const { - return false; } int VisualScriptLocalVar::get_input_value_port_count() const { return 0; } -int VisualScriptLocalVar::get_output_value_port_count() const { +int VisualScriptLocalVar::get_output_value_port_count() const { return 1; } String VisualScriptLocalVar::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } -PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const { return PropertyInfo(type, name); } String VisualScriptLocalVar::get_caption() const { - return "Get Local Var"; } String VisualScriptLocalVar::get_category() const { - return "data"; } void VisualScriptLocalVar::set_var_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptLocalVar::get_var_name() const { - return name; } void VisualScriptLocalVar::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVar::get_var_type() const { - return type; } @@ -3611,14 +3369,12 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = *p_working_mem; return 0; } }; VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar); instance->instance = p_instance; instance->name = name; @@ -3627,7 +3383,6 @@ VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p } void VisualScriptLocalVar::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVar::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVar::get_var_name); @@ -3644,7 +3399,6 @@ void VisualScriptLocalVar::_bind_methods() { } VisualScriptLocalVar::VisualScriptLocalVar() { - name = "new_local"; type = Variant::NIL; } @@ -3654,74 +3408,64 @@ VisualScriptLocalVar::VisualScriptLocalVar() { ////////////////////////////////////////// int VisualScriptLocalVarSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptLocalVarSet::has_input_sequence_port() const { - return true; } int VisualScriptLocalVarSet::get_input_value_port_count() const { return 1; } -int VisualScriptLocalVarSet::get_output_value_port_count() const { +int VisualScriptLocalVarSet::get_output_value_port_count() const { return 1; } String VisualScriptLocalVarSet::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "set"); } -PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const { return PropertyInfo(type, "get"); } String VisualScriptLocalVarSet::get_caption() const { - return "Set Local Var"; } String VisualScriptLocalVarSet::get_text() const { - return name; } String VisualScriptLocalVarSet::get_category() const { - return "data"; } void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptLocalVarSet::get_var_name() const { - return name; } void VisualScriptLocalVarSet::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVarSet::get_var_type() const { - return type; } @@ -3732,7 +3476,6 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_working_mem = *p_inputs[0]; *p_outputs[0] = *p_working_mem; return 0; @@ -3740,7 +3483,6 @@ public: }; VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet); instance->instance = p_instance; instance->name = name; @@ -3749,7 +3491,6 @@ VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance } void VisualScriptLocalVarSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVarSet::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVarSet::get_var_name); @@ -3766,7 +3507,6 @@ void VisualScriptLocalVarSet::_bind_methods() { } VisualScriptLocalVarSet::VisualScriptLocalVarSet() { - name = "new_local"; type = Variant::NIL; } @@ -3776,34 +3516,30 @@ VisualScriptLocalVarSet::VisualScriptLocalVarSet() { ////////////////////////////////////////// int VisualScriptInputAction::get_output_sequence_port_count() const { - return 0; } bool VisualScriptInputAction::has_input_sequence_port() const { - return false; } int VisualScriptInputAction::get_input_value_port_count() const { return 0; } -int VisualScriptInputAction::get_output_value_port_count() const { +int VisualScriptInputAction::get_output_value_port_count() const { return 1; } String VisualScriptInputAction::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } -PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { String mstr; switch (mode) { case MODE_PRESSED: { @@ -3824,39 +3560,36 @@ PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) cons } String VisualScriptInputAction::get_caption() const { - return "Action " + name; } String VisualScriptInputAction::get_category() const { - return "data"; } void VisualScriptInputAction::set_action_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptInputAction::get_action_name() const { - return name; } void VisualScriptInputAction::set_action_mode(Mode p_mode) { - - if (mode == p_mode) + if (mode == p_mode) { return; + } mode = p_mode; ports_changed_notify(); } -VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const { +VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const { return mode; } @@ -3867,7 +3600,6 @@ public: VisualScriptInputAction::Mode mode; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (mode) { case VisualScriptInputAction::MODE_PRESSED: { *p_outputs[0] = Input::get_singleton()->is_action_pressed(action); @@ -3888,7 +3620,6 @@ public: }; VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction); instance->instance = p_instance; instance->action = name; @@ -3898,9 +3629,7 @@ VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance } void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { - if (property.name == "action") { - property.hint = PROPERTY_HINT_ENUM; String actions; @@ -3911,8 +3640,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); @@ -3922,8 +3652,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { al.sort(); for (int i = 0; i < al.size(); i++) { - if (actions != String()) + if (actions != String()) { actions += ","; + } actions += al[i]; } @@ -3932,7 +3663,6 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { } void VisualScriptInputAction::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_action_name", "name"), &VisualScriptInputAction::set_action_name); ClassDB::bind_method(D_METHOD("get_action_name"), &VisualScriptInputAction::get_action_name); @@ -3949,7 +3679,6 @@ void VisualScriptInputAction::_bind_methods() { } VisualScriptInputAction::VisualScriptInputAction() { - name = ""; mode = MODE_PRESSED; } @@ -3959,50 +3688,42 @@ VisualScriptInputAction::VisualScriptInputAction() { ////////////////////////////////////////// int VisualScriptDeconstruct::get_output_sequence_port_count() const { - return 0; } bool VisualScriptDeconstruct::has_input_sequence_port() const { - return false; } int VisualScriptDeconstruct::get_input_value_port_count() const { return 1; } -int VisualScriptDeconstruct::get_output_value_port_count() const { +int VisualScriptDeconstruct::get_output_value_port_count() const { return elements.size(); } String VisualScriptDeconstruct::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const { - return PropertyInfo(elements[p_idx].type, elements[p_idx].name); } String VisualScriptDeconstruct::get_caption() const { - return "Deconstruct " + Variant::get_type_name(type); } String VisualScriptDeconstruct::get_category() const { - return "functions"; } void VisualScriptDeconstruct::_update_elements() { - elements.clear(); Variant v; Callable::CallError ce; @@ -4012,7 +3733,6 @@ void VisualScriptDeconstruct::_update_elements() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - Element e; e.name = E->get().name; e.type = E->get().type; @@ -4021,9 +3741,9 @@ void VisualScriptDeconstruct::_update_elements() { } void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; _update_elements(); @@ -4032,12 +3752,10 @@ void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { } Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { - return type; } void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { - ERR_FAIL_COND(p_elements.size() % 2 == 1); elements.resize(p_elements.size() / 2); for (int i = 0; i < elements.size(); i++) { @@ -4047,7 +3765,6 @@ void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { } Array VisualScriptDeconstruct::_get_elem_cache() const { - Array ret; for (int i = 0; i < elements.size(); i++) { ret.push_back(elements[i].name); @@ -4064,7 +3781,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Variant in = *p_inputs[0]; for (int i = 0; i < outputs.size(); i++) { @@ -4082,7 +3798,6 @@ public: }; VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct); instance->instance = p_instance; instance->outputs.resize(elements.size()); @@ -4097,7 +3812,6 @@ void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const { } void VisualScriptDeconstruct::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type); ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type); @@ -4114,7 +3828,6 @@ void VisualScriptDeconstruct::_bind_methods() { } VisualScriptDeconstruct::VisualScriptDeconstruct() { - type = Variant::NIL; } @@ -4127,7 +3840,6 @@ static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) { } void register_visual_script_nodes() { - VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic<VisualScriptVariableSet>); VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic<VisualScriptVariableGet>); VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic<VisualScriptEngineSingleton>); @@ -4199,12 +3911,10 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/compose_array", create_node_generic<VisualScriptComposeArray>); for (int i = 1; i < Variant::VARIANT_MAX; i++) { - List<MethodInfo> constructors; Variant::get_constructor_list(Variant::Type(i), &constructors); for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) { - if (E->get().arguments.size() > 0) { String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "("; for (int j = 0; j < E->get().arguments.size(); j++) { @@ -4229,6 +3939,5 @@ void register_visual_script_nodes() { } void unregister_visual_script_nodes() { - constructor_map.clear(); } diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 0df5071491..fa284b216c 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptFunction : public VisualScriptNode { - GDCLASS(VisualScriptFunction, VisualScriptNode); struct Argument { @@ -104,7 +103,6 @@ public: }; class VisualScriptLists : public VisualScriptNode { - GDCLASS(VisualScriptLists, VisualScriptNode) struct Port { @@ -176,7 +174,6 @@ public: }; class VisualScriptComposeArray : public VisualScriptLists { - GDCLASS(VisualScriptComposeArray, VisualScriptLists) public: @@ -201,7 +198,6 @@ public: }; class VisualScriptOperator : public VisualScriptNode { - GDCLASS(VisualScriptOperator, VisualScriptNode); Variant::Type typed; @@ -237,7 +233,6 @@ public: }; class VisualScriptSelect : public VisualScriptNode { - GDCLASS(VisualScriptSelect, VisualScriptNode); Variant::Type typed; @@ -270,7 +265,6 @@ public: }; class VisualScriptVariableGet : public VisualScriptNode { - GDCLASS(VisualScriptVariableGet, VisualScriptNode); StringName variable; @@ -303,7 +297,6 @@ public: }; class VisualScriptVariableSet : public VisualScriptNode { - GDCLASS(VisualScriptVariableSet, VisualScriptNode); StringName variable; @@ -336,7 +329,6 @@ public: }; class VisualScriptConstant : public VisualScriptNode { - GDCLASS(VisualScriptConstant, VisualScriptNode); Variant::Type type; @@ -373,7 +365,6 @@ public: }; class VisualScriptPreload : public VisualScriptNode { - GDCLASS(VisualScriptPreload, VisualScriptNode); Ref<Resource> preload; @@ -405,7 +396,6 @@ public: }; class VisualScriptIndexGet : public VisualScriptNode { - GDCLASS(VisualScriptIndexGet, VisualScriptNode); public: @@ -429,7 +419,6 @@ public: }; class VisualScriptIndexSet : public VisualScriptNode { - GDCLASS(VisualScriptIndexSet, VisualScriptNode); public: @@ -453,7 +442,6 @@ public: }; class VisualScriptGlobalConstant : public VisualScriptNode { - GDCLASS(VisualScriptGlobalConstant, VisualScriptNode); int index; @@ -484,7 +472,6 @@ public: }; class VisualScriptClassConstant : public VisualScriptNode { - GDCLASS(VisualScriptClassConstant, VisualScriptNode); StringName base_type; @@ -521,7 +508,6 @@ public: }; class VisualScriptBasicTypeConstant : public VisualScriptNode { - GDCLASS(VisualScriptBasicTypeConstant, VisualScriptNode); Variant::Type type; @@ -559,7 +545,6 @@ public: }; class VisualScriptMathConstant : public VisualScriptNode { - GDCLASS(VisualScriptMathConstant, VisualScriptNode); public: @@ -609,7 +594,6 @@ public: VARIANT_ENUM_CAST(VisualScriptMathConstant::MathConstant) class VisualScriptEngineSingleton : public VisualScriptNode { - GDCLASS(VisualScriptEngineSingleton, VisualScriptNode); String singleton; @@ -645,7 +629,6 @@ public: }; class VisualScriptSceneNode : public VisualScriptNode { - GDCLASS(VisualScriptSceneNode, VisualScriptNode); NodePath path; @@ -680,7 +663,6 @@ public: }; class VisualScriptSceneTree : public VisualScriptNode { - GDCLASS(VisualScriptSceneTree, VisualScriptNode); protected: @@ -710,7 +692,6 @@ public: }; class VisualScriptResourcePath : public VisualScriptNode { - GDCLASS(VisualScriptResourcePath, VisualScriptNode); String path; @@ -742,7 +723,6 @@ public: }; class VisualScriptSelf : public VisualScriptNode { - GDCLASS(VisualScriptSelf, VisualScriptNode); protected: @@ -771,7 +751,6 @@ public: }; class VisualScriptCustomNode : public VisualScriptNode { - GDCLASS(VisualScriptCustomNode, VisualScriptNode); protected: @@ -819,7 +798,6 @@ public: VARIANT_ENUM_CAST(VisualScriptCustomNode::StartMode); class VisualScriptSubCall : public VisualScriptNode { - GDCLASS(VisualScriptSubCall, VisualScriptNode); protected: @@ -847,7 +825,6 @@ public: }; class VisualScriptComment : public VisualScriptNode { - GDCLASS(VisualScriptComment, VisualScriptNode); String title; @@ -888,7 +865,6 @@ public: }; class VisualScriptConstructor : public VisualScriptNode { - GDCLASS(VisualScriptConstructor, VisualScriptNode); Variant::Type type; @@ -924,7 +900,6 @@ public: }; class VisualScriptLocalVar : public VisualScriptNode { - GDCLASS(VisualScriptLocalVar, VisualScriptNode); StringName name; @@ -960,7 +935,6 @@ public: }; class VisualScriptLocalVarSet : public VisualScriptNode { - GDCLASS(VisualScriptLocalVarSet, VisualScriptNode); StringName name; @@ -997,7 +971,6 @@ public: }; class VisualScriptInputAction : public VisualScriptNode { - GDCLASS(VisualScriptInputAction, VisualScriptNode); public: @@ -1045,7 +1018,6 @@ public: VARIANT_ENUM_CAST(VisualScriptInputAction::Mode) class VisualScriptDeconstruct : public VisualScriptNode { - GDCLASS(VisualScriptDeconstruct, VisualScriptNode); struct Element { diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index b06cf513ba..f14c9ce49d 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -46,23 +46,21 @@ void VisualScriptPropertySelector::_text_changed(const String &p_newtext) { } void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { - Ref<InputEventKey> k = p_ie; if (k.is_valid()) { - switch (k->get_keycode()) { case KEY_UP: case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); search_box->accept_event(); TreeItem *root = search_options->get_root(); - if (!root->get_children()) + if (!root->get_children()) { break; + } TreeItem *current = search_options->get_selected(); @@ -153,11 +151,13 @@ void VisualScriptPropertySelector::_update_search() { } } for (List<PropertyInfo>::Element *F = props.front(); F; F = F->next()) { - if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) + if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { continue; + } - if (type_filter.size() && type_filter.find(F->get().type) == -1) + if (type_filter.size() && type_filter.find(F->get().type) == -1) { continue; + } // capitalize() also converts underscore to space, we'll match again both possible styles String get_text_raw = String(vformat(TTR("Get %s"), F->get().name)); @@ -199,7 +199,6 @@ void VisualScriptPropertySelector::_update_search() { v = Variant::construct(type, nullptr, 0, ce); v.get_method_list(&methods); } else { - Object *obj = ObjectDB::get_instance(script); if (Object::cast_to<Script>(obj)) { Object::cast_to<Script>(obj)->get_script_method_list(&methods); @@ -209,23 +208,24 @@ void VisualScriptPropertySelector::_update_search() { } } for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) { - String name = M->get().name.get_slice(":", 0); - if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) + if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) + if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) + if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } MethodInfo mi = M->get(); String desc_arguments; if (mi.arguments.size() > 0) { desc_arguments = "("; for (int i = 0; i < mi.arguments.size(); i++) { - if (i > 0) { desc_arguments += ", "; } @@ -359,8 +359,9 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt bool in_modifier = p_modifiers.empty(); for (Set<String>::Element *F = p_modifiers.front(); F && in_modifier; F = F->next()) { - if (E->get().findn(F->get()) != -1) + if (E->get().findn(F->get()) != -1) { in_modifier = true; + } } if (!in_modifier) { continue; @@ -411,21 +412,21 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt } void VisualScriptPropertySelector::_confirmed() { - TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } emit_signal("selected", ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2)); set_visible(false); } void VisualScriptPropertySelector::_item_selected() { - help_bit->set_text(""); TreeItem *item = search_options->get_selected(); - if (!item) + if (!item) { return; + } String name = item->get_metadata(0); String class_type; @@ -442,7 +443,6 @@ void VisualScriptPropertySelector::_item_selected() { String at_class = class_type; while (at_class != String()) { - Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class); if (E) { for (int i = 0; i < E->get().properties.size(); i++) { @@ -457,7 +457,6 @@ void VisualScriptPropertySelector::_item_selected() { at_class = class_type; while (at_class != String()) { - Map<String, DocData::ClassDoc>::Element *C = dd->class_list.find(at_class); if (C) { for (int i = 0; i < C->get().methods.size(); i++) { @@ -512,8 +511,9 @@ void VisualScriptPropertySelector::_item_selected() { memdelete(names); - if (text == String()) + if (text == String()) { return; + } help_bit->set_text(text); } @@ -523,15 +523,12 @@ void VisualScriptPropertySelector::_hide_requested() { } void VisualScriptPropertySelector::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed)); } } void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, const bool p_virtuals_only, const bool p_connecting, bool clear_text) { - base_type = p_base; selected = p_current; type = Variant::NIL; @@ -540,10 +537,11 @@ void VisualScriptPropertySelector::select_method_from_base_type(const String &p_ virtuals_only = p_virtuals_only; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); connecting = p_connecting; @@ -555,7 +553,6 @@ void VisualScriptPropertySelector::set_type_filter(const Vector<Variant::Type> & } void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only, bool p_seq_connect, const bool p_connecting, bool clear_text) { - base_type = p_base; selected = p_current; type = Variant::NIL; @@ -565,10 +562,11 @@ void VisualScriptPropertySelector::select_from_base_type(const String &p_base, c virtuals_only = p_virtuals_only; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = p_seq_connect; connecting = p_connecting; @@ -589,10 +587,11 @@ void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_scrip virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -611,10 +610,11 @@ void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -632,10 +632,11 @@ void VisualScriptPropertySelector::select_from_action(const String &p_type, cons virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = true; connecting = p_connecting; @@ -653,10 +654,11 @@ void VisualScriptPropertySelector::select_from_instance(Object *p_instance, cons virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -673,10 +675,11 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas instance = nullptr; virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); connecting = p_connecting; @@ -684,17 +687,14 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas } void VisualScriptPropertySelector::show_window(float p_screen_ratio) { - popup_centered_ratio(p_screen_ratio); } void VisualScriptPropertySelector::_bind_methods() { - ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting"))); } VisualScriptPropertySelector::VisualScriptPropertySelector() { - vbc = memnew(VBoxContainer); add_child(vbc); //set_child_rect(vbc); diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 2296745ad0..dd07cc45a7 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -40,46 +40,38 @@ ////////////////////////////////////////// int VisualScriptYield::get_output_sequence_port_count() const { - return 1; } bool VisualScriptYield::has_input_sequence_port() const { - return true; } int VisualScriptYield::get_input_value_port_count() const { - return 0; } -int VisualScriptYield::get_output_value_port_count() const { +int VisualScriptYield::get_output_value_port_count() const { return 0; } String VisualScriptYield::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptYield::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptYield::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptYield::get_caption() const { - return yield_mode == YIELD_RETURN ? "Yield" : "Wait"; } String VisualScriptYield::get_text() const { - switch (yield_mode) { case YIELD_RETURN: return ""; @@ -108,7 +100,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_RESUME_YIELD) { return 0; //resuming yield } else { @@ -126,7 +117,6 @@ public: int ret = STEP_YIELD_BIT; switch (mode) { - case VisualScriptYield::YIELD_RETURN: ret = STEP_EXIT_FUNCTION_BIT; break; //return the yield @@ -149,7 +139,6 @@ public: }; VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceYield *instance = memnew(VisualScriptNodeInstanceYield); //instance->instance=p_instance; instance->mode = yield_mode; @@ -158,34 +147,31 @@ VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_in } void VisualScriptYield::set_yield_mode(YieldMode p_mode) { - - if (yield_mode == p_mode) + if (yield_mode == p_mode) { return; + } yield_mode = p_mode; ports_changed_notify(); _change_notify(); } VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() { - return yield_mode; } void VisualScriptYield::set_wait_time(float p_time) { - - if (wait_time == p_time) + if (wait_time == p_time) { return; + } wait_time = p_time; ports_changed_notify(); } float VisualScriptYield::get_wait_time() { - return wait_time; } void VisualScriptYield::_validate_property(PropertyInfo &property) const { - if (property.name == "wait_time") { if (yield_mode != YIELD_WAIT) { property.usage = 0; @@ -194,7 +180,6 @@ void VisualScriptYield::_validate_property(PropertyInfo &property) const { } void VisualScriptYield::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_yield_mode", "mode"), &VisualScriptYield::set_yield_mode); ClassDB::bind_method(D_METHOD("get_yield_mode"), &VisualScriptYield::get_yield_mode); @@ -210,14 +195,12 @@ void VisualScriptYield::_bind_methods() { } VisualScriptYield::VisualScriptYield() { - yield_mode = YIELD_FRAME; wait_time = 1; } template <VisualScriptYield::YieldMode MODE> static Ref<VisualScriptNode> create_yield_node(const String &p_name) { - Ref<VisualScriptYield> node; node.instance(); node->set_yield_mode(MODE); @@ -229,30 +212,30 @@ static Ref<VisualScriptNode> create_yield_node(const String &p_name) { ////////////////////////////////////////////////// int VisualScriptYieldSignal::get_output_sequence_port_count() const { - return 1; } bool VisualScriptYieldSignal::has_input_sequence_port() const { - return true; } #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -260,30 +243,34 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif Node *VisualScriptYieldSignal::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -295,60 +282,59 @@ Node *VisualScriptYieldSignal::_get_base_node() const { } StringName VisualScriptYieldSignal::_get_base_type() const { - - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { return get_visual_script()->get_instance_base_type(); - else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; } int VisualScriptYieldSignal::get_input_value_port_count() const { - - if (call_mode == CALL_MODE_INSTANCE) + if (call_mode == CALL_MODE_INSTANCE) { return 1; - else + } else { return 0; + } } -int VisualScriptYieldSignal::get_output_value_port_count() const { +int VisualScriptYieldSignal::get_output_value_port_count() const { MethodInfo sr; - if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) + if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) { return 0; + } return sr.arguments.size(); } String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const { - - if (call_mode == CALL_MODE_INSTANCE) + if (call_mode == CALL_MODE_INSTANCE) { return PropertyInfo(Variant::OBJECT, "instance"); - else + } else { return PropertyInfo(); + } } PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const { - MethodInfo sr; - if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) + if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) { return PropertyInfo(); //no signal + } ERR_FAIL_INDEX_V(p_idx, sr.arguments.size(), PropertyInfo()); return sr.arguments[p_idx]; } String VisualScriptYieldSignal::get_caption() const { - static const char *cname[3] = { "WaitSignal", "WaitNodeSignal", @@ -359,17 +345,17 @@ String VisualScriptYieldSignal::get_caption() const { } String VisualScriptYieldSignal::get_text() const { - - if (call_mode == CALL_MODE_SELF) + if (call_mode == CALL_MODE_SELF) { return " " + String(signal) + "()"; - else + } else { return " " + _get_base_type() + "." + String(signal) + "()"; + } } void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { - - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; @@ -378,29 +364,28 @@ void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { } StringName VisualScriptYieldSignal::get_base_type() const { - return base_type; } void VisualScriptYieldSignal::set_signal(const StringName &p_type) { - - if (signal == p_type) + if (signal == p_type) { return; + } signal = p_type; _change_notify(); ports_changed_notify(); } -StringName VisualScriptYieldSignal::get_signal() const { +StringName VisualScriptYieldSignal::get_signal() const { return signal; } void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { - - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; @@ -409,14 +394,13 @@ void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { } NodePath VisualScriptYieldSignal::get_base_path() const { - return base_path; } void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { - - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; @@ -425,12 +409,10 @@ void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { } VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const { - return call_mode; } void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; @@ -441,7 +423,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -458,8 +439,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { List<String> mstring; for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { - if (E->get().name.begins_with("_")) + if (E->get().name.begins_with("_")) { continue; + } mstring.push_back(E->get().name.get_slice(":", 0)); } @@ -467,9 +449,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { String ml; for (List<String>::Element *E = mstring.front(); E; E = E->next()) { - - if (ml != String()) + if (ml != String()) { ml += ","; + } ml += E->get(); } @@ -478,7 +460,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { } void VisualScriptYieldSignal::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptYieldSignal::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptYieldSignal::get_base_type); @@ -493,8 +474,9 @@ void VisualScriptYieldSignal::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -524,7 +506,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_RESUME_YIELD) { return 0; //resuming yield } else { @@ -533,14 +514,11 @@ public: Object *object = nullptr; switch (call_mode) { - case VisualScriptYieldSignal::CALL_MODE_SELF: { - object = instance->get_owner_ptr(); } break; case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -559,7 +537,6 @@ public: } break; case VisualScriptYieldSignal::CALL_MODE_INSTANCE: { - object = *p_inputs[0]; if (!object) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -583,7 +560,6 @@ public: }; VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceYieldSignal *instance = memnew(VisualScriptNodeInstanceYieldSignal); instance->node = this; instance->instance = p_instance; @@ -593,15 +569,14 @@ VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance instance->output_args = get_output_value_port_count(); return instance; } -VisualScriptYieldSignal::VisualScriptYieldSignal() { +VisualScriptYieldSignal::VisualScriptYieldSignal() { call_mode = CALL_MODE_SELF; base_type = "Object"; } template <VisualScriptYieldSignal::CallMode cmode> static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) { - Ref<VisualScriptYieldSignal> node; node.instance(); node->set_call_mode(cmode); @@ -609,7 +584,6 @@ static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) { } void register_visual_script_yield_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_frame", create_yield_node<VisualScriptYield::YIELD_FRAME>); VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_physics_frame", create_yield_node<VisualScriptYield::YIELD_PHYSICS_FRAME>); VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_time", create_yield_node<VisualScriptYield::YIELD_WAIT>); diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index 4b976bd6c6..4877e8b7e6 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptYield : public VisualScriptNode { - GDCLASS(VisualScriptYield, VisualScriptNode); public: @@ -84,7 +83,6 @@ public: VARIANT_ENUM_CAST(VisualScriptYield::YieldMode) class VisualScriptYieldSignal : public VisualScriptNode { - GDCLASS(VisualScriptYieldSignal, VisualScriptNode); public: |