From 61c72a6a782fb7f5e20942e4e052379ac5b09cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: [PATCH] Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- register_types.cpp | 3 +- visual_script.cpp | 156 +++++++++----- visual_script.h | 18 +- visual_script_builtin_funcs.cpp | 135 +++++++----- visual_script_editor.cpp | 308 ++++++++++++++++++---------- visual_script_expression.cpp | 86 +++++--- visual_script_expression.h | 3 +- visual_script_flow_control.cpp | 71 ++++--- visual_script_func_nodes.cpp | 218 +++++++++++++------- visual_script_nodes.cpp | 204 +++++++++++------- visual_script_property_selector.cpp | 65 +++--- visual_script_yield_nodes.cpp | 79 ++++--- 12 files changed, 869 insertions(+), 477 deletions(-) diff --git a/register_types.cpp b/register_types.cpp index 42d0fb3..8afed12 100644 --- a/register_types.cpp +++ b/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/visual_script.cpp b/visual_script.cpp index 4d5e520..f387c0f 100644 --- a/visual_script.cpp +++ b/visual_script.cpp @@ -133,8 +133,9 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp } Ref VisualScriptNode::get_visual_script() const { - if (scripts_used.size()) + if (scripts_used.size()) { return Ref(scripts_used.front()->get()); + } return Ref(); } @@ -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::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::Element *E = ids.front(); E; E = E->next()) { Ref 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 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 *r_custom_signals) co int VisualScript::get_available_id() const { int max_id = 0; for (Map::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 pinfo; Map values; for (Map::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 values; for (Map::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 *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::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::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (Object::cast_to(E->get().node.ptr())) + if (Object::cast_to(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::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::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 *p_properties) const { for (const Map::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 *p_properties) c Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { const Map::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 *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 &p_script, Object *p_o if (Object::cast_to(p_owner)) { //turn on these if they exist and base is a node Node *node = Object::cast_to(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::Element *E = script->variables.front(); E; E = E->next()) { @@ -2156,10 +2198,11 @@ void VisualScriptInstance::create(const Ref &p_script, Object *p_o StringName var_name; - if (Object::cast_to(*node)) + if (Object::cast_to(*node)) { var_name = String(Object::cast_to(*node)->get_var_name()).strip_edges(); - else + } else { var_name = String(Object::cast_to(*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 *p_locals, List *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 *p_members, List *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 vs = _call_stack[l].instance->get_script(); - if (vs.is_null()) + if (vs.is_null()) { return; + } List vars; vs->get_variable_list(&vars); diff --git a/visual_script.h b/visual_script.h index d47f7f2..d54b1fa 100644 --- a/visual_script.h +++ b/visual_script.h @@ -424,8 +424,9 @@ public: bool set_variable(const StringName &p_variable, const Variant &p_value) { Map::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::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/visual_script_builtin_funcs.cpp b/visual_script_builtin_funcs.cpp index 953d9a5..a0dcd76 100644 --- a/visual_script_builtin_funcs.cpp +++ b/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/visual_script_editor.cpp b/visual_script_editor.cpp index fb8aac9..fea7d15 100644 --- a/visual_script_editor.cpp +++ b/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 *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 *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::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 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 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 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(node)) + if (Object::cast_to(node)) { Object::cast_to(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 vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } String text; - if (Object::cast_to(p_name_box)) + if (Object::cast_to(p_name_box)) { text = Object::cast_to(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::Element *F = lst.front(); F; F = F->next()) { Ref 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(func_input_vbox->get_child(i)->get_child(3)); LineEdit *lne = Object::cast_to(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(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 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 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 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 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::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()); + } 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 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(node)) + if (Object::cast_to(node)) { Object::cast_to(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 &p_event) { @@ -1849,8 +1891,9 @@ void VisualScriptEditor::_members_gui_input(const Ref &p_event) { Ref 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::Element *F = lst.front(); F; F = F->next()) { Ref 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 &p_event) { - if (!function_name_edit->is_visible()) + if (!function_name_edit->is_visible()) { return; + } Ref 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 &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