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
This commit is contained in:
Rémi Verschelde
2021-05-05 12:44:11 +02:00
parent b8d198eeed
commit 140350d767
694 changed files with 23283 additions and 12499 deletions

View File

@@ -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);
}
}

View File

@@ -131,8 +131,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>();
}
@@ -191,8 +192,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());
@@ -503,8 +505,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;
@@ -614,16 +617,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);
}
@@ -656,8 +664,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());
@@ -686,10 +695,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) {
ERR_FAIL_COND(instances.size());
@@ -741,8 +751,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());
@@ -765,8 +776,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);
@@ -795,14 +807,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());
@@ -828,8 +842,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());
@@ -904,8 +919,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;
@@ -935,8 +951,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();
@@ -976,8 +993,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
@@ -1000,8 +1018,9 @@ bool VisualScript::are_subnodes_edited() const {
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"];
@@ -1092,10 +1111,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;
}
}
Dictionary VisualScript::_get_data() const {
@@ -1272,8 +1292,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;
@@ -1282,16 +1303,18 @@ bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value)
bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
const Map<StringName, Variant>::Element *E = variables.find(p_name);
if (!E)
if (!E) {
return false;
}
r_ret = E->get();
return true;
}
void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
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;
@@ -1301,13 +1324,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;
}
@@ -1341,8 +1366,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);
}
@@ -1353,8 +1379,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, Variant::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;
@@ -1364,8 +1391,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 != Variant::CallError::CALL_OK)
if (r_error.error != Variant::CallError::CALL_OK) {
return;
}
}
}
@@ -1478,8 +1506,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
}
}
if (error)
if (error) {
break;
}
//setup output pointers
@@ -1563,14 +1592,17 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
bool do_break = false;
if (ScriptDebugger::get_singleton()->get_lines_left() > 0) {
if (ScriptDebugger::get_singleton()->get_depth() <= 0)
if (ScriptDebugger::get_singleton()->get_depth() <= 0) {
ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1);
if (ScriptDebugger::get_singleton()->get_lines_left() <= 0)
}
if (ScriptDebugger::get_singleton()->get_lines_left() <= 0) {
do_break = true;
}
}
if (ScriptDebugger::get_singleton()->is_breakpoint(current_node_id, source))
if (ScriptDebugger::get_singleton()->is_breakpoint(current_node_id, source)) {
do_break = true;
}
if (do_break) {
VisualScriptLanguage::singleton->debug_break("Breakpoint", true);
@@ -1867,17 +1899,20 @@ String VisualScriptInstance::to_string(bool *r_valid) {
Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Variant::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();
}
@@ -1886,8 +1921,9 @@ Ref<Script> VisualScriptInstance::get_script() const {
}
MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode(const StringName &p_method) const {
if (p_method == script->get_default_func())
if (p_method == script->get_default_func()) {
return MultiplayerAPI::RPC_MODE_DISABLED;
}
const Map<StringName, VisualScript::Function>::Element *E = script->functions.find(p_method);
if (!E) {
@@ -1919,16 +1955,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()) {
@@ -2018,10 +2059,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;
@@ -2338,14 +2380,16 @@ 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);
@@ -2354,24 +2398,27 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const {
return *(_call_stack[l].current_id);
}
String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const {
if (_debug_parse_err_node >= 0)
if (_debug_parse_err_node >= 0) {
return "";
}
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
return *_call_stack[l].function;
}
String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const {
if (_debug_parse_err_node >= 0)
if (_debug_parse_err_node >= 0) {
return _debug_parse_err_file;
}
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
return _call_stack[l].instance->get_script_ptr()->get_path();
}
void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
if (_debug_parse_err_node >= 0)
if (_debug_parse_err_node >= 0) {
return;
}
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
@@ -2443,15 +2490,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);

View File

@@ -406,8 +406,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;
@@ -415,8 +416,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;
@@ -500,11 +502,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 (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) {
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1);
}
if (_debug_call_stack_pos >= _debug_max_call_stack) {
//stack overflow
@@ -522,11 +526,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 (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) {
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1);
}
if (_debug_call_stack_pos == 0) {
_debug_error = "Stack Underflow (Engine Bug)";

View File

@@ -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;
@@ -268,95 +269,106 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::REAL, "s");
} break;
case MATH_ATAN2: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "y");
else
} else {
return PropertyInfo(Variant::REAL, "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::REAL, "a");
else
} else {
return PropertyInfo(Variant::REAL, "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::REAL, "base");
else
} else {
return PropertyInfo(Variant::REAL, "exp");
}
} break;
case MATH_EASE: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "s");
else
} else {
return PropertyInfo(Variant::REAL, "curve");
}
} break;
case MATH_DECIMALS: {
return PropertyInfo(Variant::REAL, "step");
} break;
case MATH_STEPIFY: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "s");
else
} else {
return PropertyInfo(Variant::REAL, "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::REAL, "from");
else if (p_idx == 1)
} else if (p_idx == 1) {
return PropertyInfo(Variant::REAL, "to");
else
} else {
return PropertyInfo(Variant::REAL, "weight");
}
} break;
case MATH_RANGE_LERP: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "value");
else if (p_idx == 1)
} else if (p_idx == 1) {
return PropertyInfo(Variant::REAL, "istart");
else if (p_idx == 2)
} else if (p_idx == 2) {
return PropertyInfo(Variant::REAL, "istop");
else if (p_idx == 3)
} else if (p_idx == 3) {
return PropertyInfo(Variant::REAL, "ostart");
else
} else {
return PropertyInfo(Variant::REAL, "ostop");
}
} break;
case MATH_MOVE_TOWARD: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "from");
else if (p_idx == 1)
} else if (p_idx == 1) {
return PropertyInfo(Variant::REAL, "to");
else
} else {
return PropertyInfo(Variant::REAL, "delta");
}
} break;
case MATH_DECTIME: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "value");
else if (p_idx == 1)
} else if (p_idx == 1) {
return PropertyInfo(Variant::REAL, "amount");
else
} else {
return PropertyInfo(Variant::REAL, "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::REAL, "from");
else
} else {
return PropertyInfo(Variant::REAL, "to");
}
} break;
case MATH_SEED:
case MATH_RANDSEED: {
@@ -375,33 +387,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::REAL, "db");
} break;
case MATH_POLAR2CARTESIAN: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "r");
else
} else {
return PropertyInfo(Variant::REAL, "th");
}
} break;
case MATH_CARTESIAN2POLAR: {
if (p_idx == 0)
if (p_idx == 0) {
return PropertyInfo(Variant::REAL, "x");
else
} else {
return PropertyInfo(Variant::REAL, "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::REAL, "value");
else if (p_idx == 1)
} else if (p_idx == 1) {
return PropertyInfo(Variant::REAL, "min");
else
} else {
return PropertyInfo(Variant::REAL, "max");
}
} break;
case LOGIC_NEAREST_PO2: {
return PropertyInfo(Variant::INT, "value");
@@ -410,16 +426,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");
@@ -444,23 +462,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::POOL_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::REAL, "alpha");
}
} break;
case FUNC_MAX: {
}
@@ -539,10 +560,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:
@@ -602,15 +624,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::POOL_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;
@@ -1218,8 +1242,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");

View File

@@ -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"));
@@ -275,8 +280,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);
@@ -306,8 +312,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++) {
@@ -332,7 +339,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);
@@ -423,7 +430,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);
@@ -514,6 +521,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;
}
@@ -558,8 +566,9 @@ void VisualScriptEditor::_update_graph_connections() {
}
void VisualScriptEditor::_update_graph(int p_only_id) {
if (updating_graph)
if (updating_graph) {
return;
}
updating_graph = true;
@@ -567,8 +576,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++) {
@@ -631,8 +641,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());
@@ -670,8 +681,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
btn->connect("pressed", this, "_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"));
@@ -707,8 +719,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();
c.a = 1;
@@ -957,8 +970,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) {
@@ -973,22 +987,25 @@ 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) {
@@ -1028,8 +1045,9 @@ void VisualScriptEditor::_update_members() {
ti->set_selectable(0, true);
ti->set_metadata(0, E->get());
ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0);
if (selected == E->get())
if (selected == E->get()) {
ti->select(0);
}
}
TreeItem *variables = members->create_item(root);
@@ -1081,8 +1099,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);
@@ -1099,8 +1118,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();
@@ -1128,8 +1148,9 @@ String VisualScriptEditor::_sanitized_variant_text(const StringName &property_na
}
void VisualScriptEditor::_member_selected() {
if (updating_members)
if (updating_members) {
return;
}
TreeItem *ti = members->get_selected();
ERR_FAIL_COND(!ti);
@@ -1150,8 +1171,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);
@@ -1159,8 +1181,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);
@@ -1204,8 +1227,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);
@@ -1275,8 +1299,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);
@@ -1321,8 +1346,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);
@@ -1354,8 +1380,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();
}
}
}
@@ -1444,8 +1471,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;
@@ -1465,8 +1493,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;
@@ -1486,8 +1515,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;
@@ -1496,14 +1526,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);
@@ -1517,8 +1549,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;
@@ -1531,8 +1564,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);
}
}
@@ -1560,8 +1594,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;
@@ -1573,15 +1608,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();
@@ -1607,8 +1644,9 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const
}
}
}
if (exists)
if (exists) {
continue;
}
break;
}
@@ -1648,8 +1686,9 @@ void VisualScriptEditor::_on_nodes_delete() {
}
}
if (to_erase.empty())
if (to_erase.empty()) {
return;
}
undo_redo->create_action(TTR("Remove VisualScript Nodes"));
@@ -1700,8 +1739,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;
@@ -1761,10 +1801,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
@@ -1773,8 +1814,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) {
@@ -1827,8 +1869,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)));
}
}
}
@@ -1864,8 +1907,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);
@@ -1883,8 +1927,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_scancode() == KEY_ENTER) {
@@ -1897,13 +1942,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();
@@ -1974,18 +2021,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;
@@ -2177,8 +2227,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();
@@ -2283,8 +2334,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;
@@ -2302,10 +2354,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();
@@ -2343,10 +2396,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();
@@ -2390,15 +2444,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_stylebox("normal", "Button");
button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
@@ -2411,8 +2467,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);
@@ -2474,10 +2531,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;
}
@@ -2530,8 +2588,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) {
@@ -2546,8 +2605,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);
@@ -2696,8 +2756,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
}
@@ -2738,13 +2799,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);
}
@@ -2812,8 +2875,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;
@@ -2828,8 +2892,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());
@@ -2839,8 +2904,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);
@@ -2941,19 +3007,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;
@@ -3026,8 +3094,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());
@@ -3035,8 +3104,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);
@@ -3081,8 +3151,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);
@@ -3105,12 +3176,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);
@@ -3141,8 +3214,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
continue;
}
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));
}
@@ -3179,12 +3253,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);
@@ -3282,14 +3358,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;
@@ -3308,8 +3386,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);
@@ -3475,8 +3554,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()) {
@@ -3567,8 +3647,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;
@@ -3679,8 +3760,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) {
@@ -3794,8 +3876,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();
@@ -3810,8 +3893,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());
@@ -3824,8 +3908,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);
@@ -3856,10 +3941,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;
@@ -3937,8 +4023,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;
@@ -3951,19 +4038,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;
}
Vector2 new_size = p_new_size;
if (graph->is_using_snap()) {
@@ -4024,8 +4114,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();
@@ -4052,8 +4143,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;
@@ -4082,8 +4174,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!"));
@@ -4195,9 +4288,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;
}
@@ -4226,9 +4319,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;
}
@@ -4891,8 +4984,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() {

View File

@@ -467,8 +467,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 {
@@ -477,8 +478,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();
}
@@ -487,10 +489,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 == '_') {
@@ -619,8 +622,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: {
@@ -636,8 +640,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);
@@ -647,8 +652,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
}
expr2 = _parse_expression();
if (!expr2)
if (!expr2) {
return nullptr;
}
dn->dict.push_back(expr2);
@@ -679,8 +685,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;
@@ -699,8 +706,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
case TK_PARENTHESIS_OPEN: {
//a suexpression
ENode *e = _parse_expression();
if (error_set)
if (error_set) {
return nullptr;
}
_get_token(tk);
if (tk.type != TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')'");
@@ -760,8 +768,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);
@@ -800,8 +809,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);
@@ -850,8 +860,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;
@@ -863,8 +874,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
index->base = expr;
ENode *what = _parse_expression();
if (!what)
if (!what) {
return nullptr;
}
index->index = what;
@@ -903,8 +915,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);
@@ -937,8 +950,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
} break;
}
if (done)
if (done) {
break;
}
}
//push expression
@@ -953,8 +967,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;
@@ -1217,8 +1232,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
}
bool VisualScriptExpression::_compile_expression() {
if (!expression_dirty)
if (!expression_dirty) {
return error_set;
}
if (nodes) {
memdelete(nodes);
@@ -1271,15 +1287,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;
@@ -1295,14 +1313,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);
@@ -1317,8 +1337,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);
@@ -1336,8 +1357,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;
}
@@ -1351,13 +1373,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;
}
@@ -1375,8 +1399,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];
}
@@ -1400,8 +1425,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];
}
@@ -1419,8 +1445,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;
@@ -1430,8 +1457,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];
}

View File

@@ -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;
}

View File

@@ -76,8 +76,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();
}
@@ -87,8 +88,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();
@@ -175,12 +177,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 {
@@ -214,12 +217,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, Variant::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;
}
}
};
@@ -253,10 +257,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 {
@@ -292,10 +297,11 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::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;
}
}
};
@@ -328,10 +334,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 {
@@ -378,8 +385,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);
@@ -400,8 +408,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);
@@ -465,8 +474,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();
@@ -502,9 +512,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;
}
@@ -542,8 +552,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();
}
@@ -551,8 +562,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 {
@@ -691,15 +703,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();
@@ -711,8 +725,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();
@@ -788,8 +803,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;
}
}
};
@@ -815,8 +831,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();
}

View File

@@ -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;
@@ -145,8 +155,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++;
@@ -243,16 +254,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 {
@@ -263,8 +276,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();
@@ -276,8 +290,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();
@@ -289,8 +304,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();
@@ -302,8 +318,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);
@@ -394,8 +411,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;
@@ -415,8 +433,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();
@@ -428,8 +447,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();
@@ -440,16 +460,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();
@@ -508,8 +530,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;
@@ -638,8 +661,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));
}
@@ -651,8 +675,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();
}
@@ -700,12 +725,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;
@@ -878,28 +905,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);
@@ -911,12 +943,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;
@@ -1023,8 +1056,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();
@@ -1037,8 +1071,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();
@@ -1050,8 +1085,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();
@@ -1063,11 +1099,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..
@@ -1140,8 +1178,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();
@@ -1154,8 +1193,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();
@@ -1168,8 +1208,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();
@@ -1189,8 +1230,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();
@@ -1203,8 +1245,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();
@@ -1297,8 +1340,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
}
}
}
@@ -1332,8 +1376,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));
}
@@ -1345,8 +1390,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();
}
@@ -1592,28 +1638,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);
@@ -1625,12 +1676,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;
@@ -1690,8 +1742,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();
@@ -1703,8 +1756,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();
@@ -1797,8 +1851,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;
@@ -1811,8 +1866,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();
@@ -1825,8 +1881,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();
@@ -1838,8 +1895,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();
@@ -1859,8 +1917,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();
@@ -1951,8 +2010,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
}
}
}
@@ -1983,8 +2043,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));
}
@@ -1996,8 +2057,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();
}
@@ -2137,8 +2199,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);
}
@@ -2156,8 +2219,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));
}
@@ -2174,8 +2238,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;
@@ -2199,8 +2264,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();
}

View File

@@ -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);
@@ -210,10 +211,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();
}
@@ -331,8 +333,9 @@ int VisualScriptFunction::get_stack_size() const {
//////////////////////////////////////////
int VisualScriptLists::get_output_sequence_port_count() const {
if (sequenced)
if (sequenced) {
return 1;
}
return 0;
}
bool VisualScriptLists::has_input_sequence_port() const {
@@ -392,8 +395,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);
@@ -427,8 +431,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);
@@ -542,23 +547,26 @@ 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());
@@ -567,8 +575,9 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type
_change_notify();
}
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());
@@ -577,8 +586,9 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name
_change_notify();
}
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());
@@ -590,23 +600,26 @@ 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());
@@ -615,8 +628,9 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ
_change_notify();
}
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());
@@ -625,8 +639,9 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam
_change_notify();
}
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());
@@ -638,8 +653,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();
}
@@ -670,8 +686,9 @@ void VisualScriptLists::_bind_methods() {
//////////////////////////////////////////
int VisualScriptComposeArray::get_output_sequence_port_count() const {
if (sequenced)
if (sequenced) {
return 1;
}
return 0;
}
bool VisualScriptComposeArray::has_input_sequence_port() const {
@@ -719,8 +736,9 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::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;
@@ -803,8 +821,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;
}
PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const {
@@ -844,8 +863,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;
}
@@ -919,8 +939,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();
}
@@ -930,8 +951,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();
@@ -950,8 +972,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];
}
@@ -984,10 +1007,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());
}
}
}
@@ -1060,8 +1084,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();
@@ -1089,10 +1114,11 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::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;
}
@@ -1150,8 +1176,9 @@ String VisualScriptVariableGet::get_caption() const {
return "Get " + variable;
}
void VisualScriptVariableGet::set_variable(StringName p_variable) {
if (variable == p_variable)
if (variable == p_variable) {
return;
}
variable = p_variable;
ports_changed_notify();
}
@@ -1168,8 +1195,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();
}
@@ -1256,8 +1284,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();
}
@@ -1274,8 +1303,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();
}
@@ -1359,8 +1389,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;
Variant::CallError ce;
@@ -1374,8 +1405,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();
@@ -1387,8 +1419,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
}
}
}
@@ -1481,8 +1514,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();
@@ -1719,8 +1753,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");
@@ -2091,8 +2126,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");
@@ -2196,11 +2232,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;
}
@@ -2304,18 +2342,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;
@@ -2330,24 +2371,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);
@@ -2363,24 +2408,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();
}
@@ -2587,10 +2636,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);
}
@@ -2623,8 +2673,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;
@@ -2907,10 +2958,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 "";
@@ -3002,8 +3055,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();
}
@@ -3013,8 +3067,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();
}
@@ -3023,8 +3078,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();
}
@@ -3113,8 +3169,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();
@@ -3227,8 +3284,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();
@@ -3331,8 +3389,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();
@@ -3448,8 +3507,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();
@@ -3460,8 +3520,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();
@@ -3517,8 +3578,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());
@@ -3528,8 +3590,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];
}
@@ -3615,8 +3678,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();

View File

@@ -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();
@@ -148,11 +149,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));
@@ -204,14 +207,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;
@@ -351,8 +357,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;
@@ -404,8 +411,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));
hide();
}
@@ -414,8 +422,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;
@@ -500,8 +509,9 @@ void VisualScriptPropertySelector::_item_selected() {
memdelete(names);
if (text == String())
if (text == String()) {
return;
}
help_bit->set_text(text);
}
@@ -522,10 +532,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;
@@ -547,10 +558,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;
@@ -571,10 +583,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;
@@ -594,10 +607,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;
@@ -616,10 +630,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;
@@ -638,10 +653,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;

View File

@@ -146,8 +146,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();
@@ -158,8 +159,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();
}
@@ -218,18 +220,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;
@@ -239,27 +244,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);
@@ -271,28 +281,31 @@ 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();
}
@@ -302,17 +315,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];
}
@@ -328,15 +343,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;
@@ -349,8 +366,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;
@@ -362,8 +380,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;
@@ -376,8 +395,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;
@@ -416,8 +436,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));
}
@@ -425,8 +446,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();
}
@@ -449,8 +471,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));
}