diff options
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/register_types.cpp | 3 | ||||
-rw-r--r-- | modules/visual_script/visual_script.cpp | 156 | ||||
-rw-r--r-- | modules/visual_script/visual_script.h | 18 | ||||
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.cpp | 135 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 308 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.cpp | 86 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.h | 3 | ||||
-rw-r--r-- | modules/visual_script/visual_script_flow_control.cpp | 71 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 218 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 204 | ||||
-rw-r--r-- | modules/visual_script/visual_script_property_selector.cpp | 65 | ||||
-rw-r--r-- | modules/visual_script/visual_script_yield_nodes.cpp | 79 |
12 files changed, 869 insertions, 477 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 42d0fb37fe..8afed1229f 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -134,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 4d5e5200b6..f387c0f288 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -133,8 +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>(); } @@ -194,8 +195,9 @@ 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()); @@ -506,8 +508,9 @@ bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p 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; @@ -620,16 +623,21 @@ bool VisualScript::get_variable_export(const StringName &p_name) const { 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); } @@ -662,8 +670,9 @@ void VisualScript::set_instance_base_type(const StringName &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()); @@ -682,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); + } } } } @@ -713,10 +724,11 @@ void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant: 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) { @@ -775,8 +787,9 @@ void VisualScript::remove_custom_signal(const StringName &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()); @@ -799,8 +812,9 @@ 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); @@ -829,14 +843,16 @@ void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *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()); @@ -862,8 +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()); @@ -940,8 +957,9 @@ 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; @@ -973,8 +991,9 @@ bool VisualScript::has_method(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(); @@ -1014,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 @@ -1092,8 +1112,9 @@ 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"]; @@ -1184,10 +1205,11 @@ void VisualScript::_set_data(const Dictionary &p_data) { } } - 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(); @@ -1390,8 +1412,9 @@ 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; @@ -1400,8 +1423,9 @@ 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; @@ -1409,8 +1433,9 @@ bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) 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; @@ -1421,13 +1446,15 @@ void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c 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; } @@ -1462,8 +1489,9 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { } bool VisualScriptInstance::has_method(const StringName &p_method) const { - if (p_method == script->get_default_func()) + if (p_method == script->get_default_func()) { return false; + } return script->functions.has(p_method); } @@ -1474,8 +1502,9 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const { 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; @@ -1485,8 +1514,9 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int 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; + } } } @@ -1599,8 +1629,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } } - if (error) + if (error) { break; + } //setup output pointers @@ -1684,14 +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); @@ -1988,17 +2022,20 @@ 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(); } @@ -2057,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()) { @@ -2156,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; @@ -2491,15 +2534,17 @@ String VisualScriptLanguage::debug_get_error() const { } 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) + if (_debug_parse_err_node >= 0) { return _debug_parse_err_node; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1); @@ -2509,8 +2554,9 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { } String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_node >= 0) + 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; @@ -2518,8 +2564,9 @@ String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { } String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_node >= 0) + 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; @@ -2527,8 +2574,9 @@ String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { } 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) + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); @@ -2601,15 +2649,17 @@ 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) + 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); diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index d47f7f2a4b..d54b1faf42 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -424,8 +424,9 @@ public: 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; @@ -433,8 +434,9 @@ public: 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; @@ -527,11 +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 @@ -549,11 +553,13 @@ 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)"; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 953d9a5fed..a0dcd76d10 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -111,8 +111,9 @@ 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; @@ -269,95 +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: { @@ -376,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"); @@ -411,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"); @@ -445,23 +463,26 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const } 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: { } @@ -540,10 +561,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons 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: @@ -603,15 +625,17 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons 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; @@ -1220,8 +1244,9 @@ void VisualScriptBuiltinFunc::_bind_methods() { 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"); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index fb8aac9a01..fea7d151df 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -66,14 +66,16 @@ protected: } 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")); @@ -126,8 +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); @@ -150,8 +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"; @@ -200,8 +204,9 @@ protected: } 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")); @@ -262,8 +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); @@ -293,8 +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++) { @@ -319,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); @@ -425,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); @@ -531,6 +538,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.3, 0.3); } + } return color; } @@ -575,8 +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; @@ -584,8 +593,9 @@ 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++) { @@ -653,8 +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()); @@ -692,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")); @@ -729,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; @@ -983,8 +996,9 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b 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) { @@ -999,23 +1013,26 @@ 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) { @@ -1055,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); @@ -1113,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); @@ -1131,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(); @@ -1148,8 +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); @@ -1170,8 +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); @@ -1179,8 +1201,9 @@ 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); @@ -1224,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); @@ -1297,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); @@ -1343,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); @@ -1376,8 +1402,9 @@ 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(); + } } } @@ -1466,8 +1493,9 @@ 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; @@ -1487,8 +1515,9 @@ 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; @@ -1508,8 +1537,9 @@ 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; @@ -1518,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); @@ -1539,8 +1571,9 @@ 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; @@ -1553,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); } } @@ -1582,8 +1616,9 @@ 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; @@ -1595,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(); @@ -1629,8 +1666,9 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } } } - if (exists) + if (exists) { continue; + } break; } @@ -1670,8 +1708,9 @@ void VisualScriptEditor::_on_nodes_delete() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Remove VisualScript Nodes")); @@ -1722,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; @@ -1783,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 @@ -1795,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) { @@ -1849,8 +1891,9 @@ 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))); + } } } @@ -1886,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); @@ -1905,8 +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) { @@ -1919,13 +1964,15 @@ 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(); @@ -1996,18 +2043,21 @@ 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; @@ -2199,8 +2249,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da 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(); @@ -2305,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; @@ -2324,10 +2376,11 @@ 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(); @@ -2365,10 +2418,11 @@ 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(); @@ -2412,15 +2466,17 @@ 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); @@ -2433,8 +2489,9 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const 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); @@ -2491,10 +2548,11 @@ 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; } @@ -2547,8 +2605,9 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { // 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) { @@ -2563,8 +2622,9 @@ 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); @@ -2713,8 +2773,9 @@ 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 } @@ -2755,13 +2816,15 @@ void VisualScriptEditor::_end_node_move() { } 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); } @@ -2829,8 +2892,9 @@ 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; @@ -2845,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()); @@ -2856,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); @@ -2958,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; @@ -3043,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()); @@ -3052,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); @@ -3098,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); @@ -3122,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); @@ -3152,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)); } @@ -3190,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); @@ -3293,14 +3369,16 @@ 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; @@ -3319,8 +3397,9 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac 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); @@ -3486,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()) { @@ -3578,8 +3658,9 @@ 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; @@ -3690,8 +3771,9 @@ 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) { @@ -3805,8 +3887,9 @@ 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(); @@ -3821,8 +3904,9 @@ 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()); @@ -3835,8 +3919,9 @@ 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); @@ -3867,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; @@ -3950,8 +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; @@ -3964,19 +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; @@ -4028,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(); @@ -4056,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; @@ -4086,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!")); @@ -4199,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; } @@ -4230,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; } @@ -4837,8 +4930,9 @@ 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() { diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index ee166082bd..bd41117497 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -466,8 +466,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') + if (c == '-') { is_float = true; + } exp_sign = true; } else { @@ -476,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(); } @@ -486,10 +488,11 @@ 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 == '_') { @@ -618,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: { @@ -635,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); @@ -646,8 +651,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } dn->dict.push_back(expr2); @@ -678,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; @@ -698,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 ')'"); @@ -759,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); @@ -799,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); @@ -849,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; @@ -862,8 +873,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { index->base = expr; ENode *what = _parse_expression(); - if (!what) + if (!what) { return nullptr; + } index->index = what; @@ -902,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); @@ -936,8 +949,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; } - if (done) + if (done) { break; + } } //push expression @@ -952,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; @@ -1216,8 +1231,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } bool VisualScriptExpression::_compile_expression() { - if (!expression_dirty) + if (!expression_dirty) { return error_set; + } if (nodes) { memdelete(nodes); @@ -1270,15 +1286,17 @@ public: 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; @@ -1294,14 +1312,16 @@ public: 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); @@ -1316,8 +1336,9 @@ public: 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); @@ -1335,8 +1356,9 @@ public: 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; } @@ -1350,13 +1372,15 @@ public: 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; } @@ -1374,8 +1398,9 @@ public: 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]; } @@ -1399,8 +1424,9 @@ public: 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]; } @@ -1418,8 +1444,9 @@ public: 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; @@ -1429,8 +1456,9 @@ public: 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]; } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index ed0857ab9f..dee0213d54 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -104,8 +104,9 @@ class VisualScriptExpression : public VisualScriptNode { }; void _set_error(const String &p_err) { - if (error_set) + if (error_set) { return; + } error_str = p_err; error_set = true; } diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 96616c281e..3ed20fab35 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -78,8 +78,9 @@ String VisualScriptReturn::get_text() const { } void VisualScriptReturn::set_return_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); } @@ -89,8 +90,9 @@ Variant::Type VisualScriptReturn::get_return_type() const { } 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(); @@ -178,12 +180,13 @@ int VisualScriptCondition::get_output_value_port_count() const { } 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 { @@ -218,12 +221,13 @@ 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; + } } }; @@ -258,10 +262,11 @@ int VisualScriptWhile::get_output_value_port_count() const { } 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 { @@ -298,10 +303,11 @@ 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) { 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; + } } }; @@ -336,10 +342,11 @@ int VisualScriptIterator::get_output_value_port_count() const { } 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 { @@ -388,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); @@ -410,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); @@ -478,8 +487,9 @@ String VisualScriptSequence::get_text() const { 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(); @@ -515,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; } @@ -557,8 +567,9 @@ int VisualScriptSwitch::get_output_value_port_count() const { } 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(); } @@ -566,8 +577,9 @@ String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { 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 { @@ -708,15 +720,17 @@ String VisualScriptTypeCast::get_caption() const { } 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(); @@ -728,8 +742,9 @@ StringName VisualScriptTypeCast::get_base_type() const { } void VisualScriptTypeCast::set_base_script(const String &p_path) { - if (script == p_path) + if (script == p_path) { return; + } script = p_path; _change_notify(); @@ -806,8 +821,9 @@ 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; + } } }; @@ -833,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(); } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index e7cb2f5473..f13377f3c8 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -42,10 +42,11 @@ ////////////////////////////////////////// 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 { @@ -54,18 +55,21 @@ bool VisualScriptFunctionCall::has_input_sequence_port() const { #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; @@ -75,27 +79,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const 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); @@ -107,12 +116,13 @@ 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; @@ -146,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++; @@ -244,16 +255,18 @@ 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 { @@ -264,8 +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(); @@ -277,8 +291,9 @@ Variant::Type VisualScriptFunctionCall::get_basic_type() const { } 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(); @@ -290,8 +305,9 @@ StringName VisualScriptFunctionCall::get_base_type() const { } 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(); @@ -303,8 +319,9 @@ String VisualScriptFunctionCall::get_base_script() const { } 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); @@ -395,8 +412,9 @@ void VisualScriptFunctionCall::_update_method_cache() { } void VisualScriptFunctionCall::set_function(const StringName &p_type) { - if (function == p_type) + if (function == p_type) { return; + } function = p_type; @@ -417,8 +435,9 @@ StringName VisualScriptFunctionCall::get_function() const { } 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(); @@ -430,8 +449,9 @@ NodePath VisualScriptFunctionCall::get_base_path() const { } 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(); @@ -443,16 +463,18 @@ VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() con } 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(); @@ -511,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; @@ -641,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)); } @@ -654,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(); } @@ -703,12 +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; @@ -881,28 +908,33 @@ bool VisualScriptPropertySet::has_input_sequence_port() const { 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); @@ -914,12 +946,13 @@ 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; @@ -1028,8 +1061,9 @@ void VisualScriptPropertySet::_update_base_type() { } void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -1042,8 +1076,9 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const { } 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(); @@ -1055,8 +1090,9 @@ StringName VisualScriptPropertySet::get_base_type() const { } 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(); @@ -1068,11 +1104,13 @@ String VisualScriptPropertySet::get_base_script() const { } 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.. @@ -1145,8 +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(); @@ -1160,8 +1199,9 @@ StringName VisualScriptPropertySet::get_property() const { } 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(); @@ -1174,8 +1214,9 @@ NodePath VisualScriptPropertySet::get_base_path() const { } 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(); @@ -1196,8 +1237,9 @@ Dictionary VisualScriptPropertySet::_get_type_cache() const { } void VisualScriptPropertySet::set_index(const StringName &p_type) { - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -1210,8 +1252,9 @@ StringName VisualScriptPropertySet::get_index() const { 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(); @@ -1304,8 +1347,9 @@ 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 + } } } @@ -1339,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)); } @@ -1352,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(); } @@ -1602,28 +1648,33 @@ void VisualScriptPropertyGet::_update_base_type() { 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); @@ -1635,12 +1686,13 @@ 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; @@ -1701,8 +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(); @@ -1714,8 +1767,9 @@ StringName VisualScriptPropertyGet::get_base_type() const { } 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(); @@ -1808,8 +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; @@ -1823,8 +1878,9 @@ StringName VisualScriptPropertyGet::get_property() const { } 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(); @@ -1837,8 +1893,9 @@ NodePath VisualScriptPropertyGet::get_base_path() const { } 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(); @@ -1851,8 +1908,9 @@ VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const } 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(); @@ -1872,8 +1930,9 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const { } void VisualScriptPropertyGet::set_index(const StringName &p_type) { - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -1964,8 +2023,9 @@ 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 + } } } @@ -1996,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)); } @@ -2009,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(); } @@ -2149,8 +2211,9 @@ bool VisualScriptEmitSignal::has_input_sequence_port() const { 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); } @@ -2169,8 +2232,9 @@ String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const { 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)); } @@ -2187,8 +2251,9 @@ String VisualScriptEmitSignal::get_caption() const { } void VisualScriptEmitSignal::set_signal(const StringName &p_type) { - if (name == p_type) + if (name == p_type) { return; + } name = p_type; @@ -2213,8 +2278,9 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { String ml; for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) { - if (ml != String()) + if (ml != String()) { ml += ","; + } ml += E->get(); } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 8d35da2685..87aa64211e 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -46,8 +46,9 @@ 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); @@ -213,10 +214,11 @@ void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_na 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(); } @@ -339,8 +341,9 @@ int VisualScriptFunction::get_stack_size() const { ////////////////////////////////////////// int VisualScriptLists::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } @@ -407,8 +410,9 @@ 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); @@ -442,8 +446,9 @@ 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); @@ -559,24 +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()) + if (!is_input_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -586,8 +594,9 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type } void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { - if (!is_input_port_name_editable()) + if (!is_input_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -597,8 +606,9 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name } void VisualScriptLists::remove_input_data_port(int p_argidx) { - if (!is_input_port_editable()) + if (!is_input_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, inputports.size()); @@ -610,24 +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()) + if (!is_output_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -637,8 +650,9 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ } void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { - if (!is_output_port_name_editable()) + if (!is_output_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -648,8 +662,9 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam } void VisualScriptLists::remove_output_data_port(int p_argidx) { - if (!is_output_port_editable()) + if (!is_output_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, outputports.size()); @@ -661,8 +676,9 @@ 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(); } @@ -694,8 +710,9 @@ void VisualScriptLists::_bind_methods() { ////////////////////////////////////////// int VisualScriptComposeArray::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } @@ -747,8 +764,9 @@ 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 (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; @@ -832,8 +850,9 @@ 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; } @@ -874,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; } @@ -949,8 +969,9 @@ 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(); } @@ -960,8 +981,9 @@ Variant::Operator VisualScriptOperator::get_operator() const { } void VisualScriptOperator::set_typed(Variant::Type p_op) { - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); @@ -980,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]; } @@ -1014,10 +1037,11 @@ public: 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()); + } } } @@ -1092,8 +1116,9 @@ String VisualScriptSelect::get_text() const { } void VisualScriptSelect::set_typed(Variant::Type p_op) { - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); @@ -1121,10 +1146,11 @@ 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) { 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; } @@ -1184,8 +1210,9 @@ String VisualScriptVariableGet::get_caption() const { } void VisualScriptVariableGet::set_variable(StringName p_variable) { - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } @@ -1202,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(); } @@ -1292,8 +1320,9 @@ String VisualScriptVariableSet::get_caption() const { } void VisualScriptVariableSet::set_variable(StringName p_variable) { - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } @@ -1310,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(); } @@ -1397,8 +1427,9 @@ String VisualScriptConstant::get_caption() const { } void VisualScriptConstant::set_constant_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; Callable::CallError ce; @@ -1412,8 +1443,9 @@ Variant::Type VisualScriptConstant::get_constant_type() const { } void VisualScriptConstant::set_constant_value(Variant p_value) { - if (value == p_value) + if (value == p_value) { return; + } value = p_value; ports_changed_notify(); @@ -1426,8 +1458,9 @@ Variant VisualScriptConstant::get_constant_value() const { 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 + } } } @@ -1521,8 +1554,9 @@ String VisualScriptPreload::get_caption() const { } void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { - if (preload == p_preload) + if (preload == p_preload) { return; + } preload = p_preload; ports_changed_notify(); @@ -1762,8 +1796,9 @@ void VisualScriptGlobalConstant::_bind_methods() { 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"); @@ -2137,8 +2172,9 @@ void VisualScriptMathConstant::_bind_methods() { 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"); @@ -2243,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; } @@ -2352,18 +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; @@ -2378,24 +2419,28 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu #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); @@ -2411,24 +2456,28 @@ 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(); } @@ -2638,10 +2687,11 @@ PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const { 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); } @@ -2674,8 +2724,9 @@ VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inp 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; @@ -2958,10 +3009,12 @@ String VisualScriptSubCall::get_caption() const { 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 ""; @@ -3054,8 +3107,9 @@ String VisualScriptComment::get_text() const { } void VisualScriptComment::set_title(const String &p_title) { - if (title == p_title) + if (title == p_title) { return; + } title = p_title; ports_changed_notify(); } @@ -3065,8 +3119,9 @@ String VisualScriptComment::get_title() const { } void VisualScriptComment::set_description(const String &p_description) { - if (description == p_description) + if (description == p_description) { return; + } description = p_description; ports_changed_notify(); } @@ -3076,8 +3131,9 @@ String VisualScriptComment::get_description() const { } void VisualScriptComment::set_size(const Size2 &p_size) { - if (size == p_size) + if (size == p_size) { return; + } size = p_size; ports_changed_notify(); } @@ -3168,8 +3224,9 @@ String VisualScriptConstructor::get_category() const { } void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); @@ -3284,8 +3341,9 @@ String VisualScriptLocalVar::get_category() const { } void VisualScriptLocalVar::set_var_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3390,8 +3448,9 @@ String VisualScriptLocalVarSet::get_category() const { } void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3509,8 +3568,9 @@ String VisualScriptInputAction::get_category() const { } void VisualScriptInputAction::set_action_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3521,8 +3581,9 @@ StringName VisualScriptInputAction::get_action_name() const { } void VisualScriptInputAction::set_action_mode(Mode p_mode) { - if (mode == p_mode) + if (mode == p_mode) { return; + } mode = p_mode; ports_changed_notify(); @@ -3579,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()); @@ -3590,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]; } @@ -3678,8 +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(); diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index 3cdf3f5d75..f14c9ce49d 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -58,8 +58,9 @@ void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { 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(); @@ -150,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)); @@ -206,14 +209,17 @@ 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; @@ -353,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; @@ -406,8 +413,9 @@ 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); } @@ -416,8 +424,9 @@ 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; @@ -502,8 +511,9 @@ void VisualScriptPropertySelector::_item_selected() { memdelete(names); - if (text == String()) + if (text == String()) { return; + } help_bit->set_text(text); } @@ -527,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; @@ -551,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; @@ -575,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; @@ -597,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; @@ -618,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; @@ -639,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; @@ -659,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; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index a035efd25d..dd07cc45a7 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -147,8 +147,9 @@ 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(); @@ -159,8 +160,9 @@ VisualScriptYield::YieldMode VisualScriptYield::get_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(); } @@ -219,18 +221,21 @@ bool VisualScriptYieldSignal::has_input_sequence_port() const { #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; @@ -240,27 +245,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const 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); @@ -272,29 +282,32 @@ 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 { 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(); } @@ -304,17 +317,19 @@ String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const } 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]; } @@ -330,15 +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; @@ -351,8 +368,9 @@ StringName VisualScriptYieldSignal::get_base_type() const { } void VisualScriptYieldSignal::set_signal(const StringName &p_type) { - if (signal == p_type) + if (signal == p_type) { return; + } signal = p_type; @@ -365,8 +383,9 @@ StringName VisualScriptYieldSignal::get_signal() const { } void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; @@ -379,8 +398,9 @@ NodePath VisualScriptYieldSignal::get_base_path() const { } void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; @@ -419,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)); } @@ -428,8 +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(); } @@ -452,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)); } |