diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
tree | 2b1c31f45add24085b64425ce440f577424c16a1 /modules/visual_script/visual_script_nodes.cpp | |
parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'modules/visual_script/visual_script_nodes.cpp')
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 693 |
1 files changed, 201 insertions, 492 deletions
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 52399d29d0..87aa64211e 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -43,13 +43,12 @@ ////////////////////////////////////////// bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "argument_count") { - int new_argc = p_value; int argc = arguments.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } arguments.resize(new_argc); @@ -66,7 +65,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value ERR_FAIL_INDEX_V(idx, arguments.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); arguments.write[idx].type = new_type; ports_changed_notify(); @@ -75,7 +73,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } if (what == "name") { - arguments.write[idx].name = p_value; ports_changed_notify(); return true; @@ -107,7 +104,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "argument_count") { r_ret = arguments.size(); return true; @@ -148,8 +144,8 @@ bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const return false; } -void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { @@ -171,35 +167,30 @@ void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const } int VisualScriptFunction::get_output_sequence_port_count() const { - return 1; } bool VisualScriptFunction::has_input_sequence_port() const { - return false; } int VisualScriptFunction::get_input_value_port_count() const { - return 0; } -int VisualScriptFunction::get_output_value_port_count() const { +int VisualScriptFunction::get_output_value_port_count() const { return arguments.size(); } String VisualScriptFunction::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const { - ERR_FAIL_V(PropertyInfo()); } -PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo()); PropertyInfo out; out.type = arguments[p_idx].type; @@ -210,55 +201,53 @@ PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { } String VisualScriptFunction::get_caption() const { - return "Function"; } String VisualScriptFunction::get_text() const { - return get_name(); //use name as function name I guess } void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_name, int p_index, const PropertyHint p_hint, const String &p_hint_string) { - Argument arg; arg.name = p_name; arg.type = p_type; arg.hint = p_hint; arg.hint_string = p_hint_string; - if (p_index >= 0) + if (p_index >= 0) { arguments.insert(p_index, arg); - else + } else { arguments.push_back(arg); + } ports_changed_notify(); } -void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) { +void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].type = p_type; ports_changed_notify(); } -Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const { +Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const { ERR_FAIL_INDEX_V(p_argidx, arguments.size(), Variant::NIL); return arguments[p_argidx].type; } -void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) { +void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].name = p_name; ports_changed_notify(); } -String VisualScriptFunction::get_argument_name(int p_argidx) const { +String VisualScriptFunction::get_argument_name(int p_argidx) const { ERR_FAIL_INDEX_V(p_argidx, arguments.size(), String()); return arguments[p_argidx].name; } -void VisualScriptFunction::remove_argument(int p_argidx) { +void VisualScriptFunction::remove_argument(int p_argidx) { ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.remove(p_argidx); @@ -266,7 +255,6 @@ void VisualScriptFunction::remove_argument(int p_argidx) { } int VisualScriptFunction::get_argument_count() const { - return arguments.size(); } @@ -286,7 +274,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - int ac = node->get_argument_count(); for (int i = 0; i < ac; i++) { @@ -310,7 +297,6 @@ public: }; VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction); instance->node = this; instance->instance = p_instance; @@ -318,7 +304,6 @@ VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p } VisualScriptFunction::VisualScriptFunction() { - stack_size = 256; stack_less = false; sequenced = true; @@ -335,23 +320,19 @@ bool VisualScriptFunction::is_stack_less() const { } void VisualScriptFunction::set_sequenced(bool p_enable) { - sequenced = p_enable; } bool VisualScriptFunction::is_sequenced() const { - return sequenced; } void VisualScriptFunction::set_stack_size(int p_size) { - ERR_FAIL_COND(p_size < 1 || p_size > 100000); stack_size = p_size; } int VisualScriptFunction::get_stack_size() const { - return stack_size; } @@ -360,10 +341,12 @@ int VisualScriptFunction::get_stack_size() const { ////////////////////////////////////////// int VisualScriptLists::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } + bool VisualScriptLists::has_input_sequence_port() const { return sequenced; } @@ -375,6 +358,7 @@ String VisualScriptLists::get_output_sequence_port_text(int p_port) const { int VisualScriptLists::get_input_value_port_count() const { return inputports.size(); } + int VisualScriptLists::get_output_value_port_count() const { return outputports.size(); } @@ -387,6 +371,7 @@ PropertyInfo VisualScriptLists::get_input_value_port_info(int p_idx) const { pi.type = inputports[p_idx].type; return pi; } + PropertyInfo VisualScriptLists::get_output_value_port_info(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, outputports.size(), PropertyInfo()); @@ -399,9 +384,11 @@ PropertyInfo VisualScriptLists::get_output_value_port_info(int p_idx) const { bool VisualScriptLists::is_input_port_editable() const { return ((flags & INPUT_EDITABLE) == INPUT_EDITABLE); } + bool VisualScriptLists::is_input_port_name_editable() const { return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE); } + bool VisualScriptLists::is_input_port_type_editable() const { return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE); } @@ -409,22 +396,23 @@ bool VisualScriptLists::is_input_port_type_editable() const { bool VisualScriptLists::is_output_port_editable() const { return ((flags & OUTPUT_EDITABLE) == OUTPUT_EDITABLE); } + bool VisualScriptLists::is_output_port_name_editable() const { return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE); } + bool VisualScriptLists::is_output_port_type_editable() const { return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE); } // for the inspector bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "input_count" && is_input_port_editable()) { - int new_argc = p_value; int argc = inputports.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } inputports.resize(new_argc); @@ -441,7 +429,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, inputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); inputports.write[idx].type = new_type; ports_changed_notify(); @@ -450,7 +437,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - inputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -458,11 +444,11 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (p_name == "output_count" && is_output_port_editable()) { - int new_argc = p_value; int argc = outputports.size(); - if (argc == new_argc) + if (argc == new_argc) { return true; + } outputports.resize(new_argc); @@ -479,7 +465,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, outputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); outputports.write[idx].type = new_type; ports_changed_notify(); @@ -488,7 +473,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - outputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -503,8 +487,8 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { +bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "input_count" && is_input_port_editable()) { r_ret = inputports.size(); return true; @@ -548,8 +532,8 @@ bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { +void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { if (is_input_port_editable()) { p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; @@ -580,25 +564,27 @@ void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { // input data port interaction void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String &p_name, int p_index) { - - if (!is_input_port_editable()) + if (!is_input_port_editable()) { return; + } Port inp; inp.name = p_name; inp.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { inputports.insert(p_index, inp); - else + } else { inputports.push_back(inp); + } ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_input_port_type_editable()) +void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { + if (!is_input_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -606,10 +592,11 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { - if (!is_input_port_name_editable()) +void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { + if (!is_input_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -617,10 +604,11 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name ports_changed_notify(); _change_notify(); } -void VisualScriptLists::remove_input_data_port(int p_argidx) { - if (!is_input_port_editable()) +void VisualScriptLists::remove_input_data_port(int p_argidx) { + if (!is_input_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, inputports.size()); @@ -632,25 +620,27 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) { // output data port interaction void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String &p_name, int p_index) { - - if (!is_output_port_editable()) + if (!is_output_port_editable()) { return; + } Port out; out.name = p_name; out.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { outputports.insert(p_index, out); - else + } else { outputports.push_back(out); + } ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_output_port_type_editable()) +void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { + if (!is_output_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -658,10 +648,11 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ ports_changed_notify(); _change_notify(); } -void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { - if (!is_output_port_name_editable()) +void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { + if (!is_output_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -669,10 +660,11 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam ports_changed_notify(); _change_notify(); } -void VisualScriptLists::remove_output_data_port(int p_argidx) { - if (!is_output_port_editable()) +void VisualScriptLists::remove_output_data_port(int p_argidx) { + if (!is_output_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, outputports.size()); @@ -684,11 +676,13 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) { // sequences void VisualScriptLists::set_sequenced(bool p_enable) { - if (sequenced == p_enable) + if (sequenced == p_enable) { return; + } sequenced = p_enable; ports_changed_notify(); } + bool VisualScriptLists::is_sequenced() const { return sequenced; } @@ -716,10 +710,12 @@ void VisualScriptLists::_bind_methods() { ////////////////////////////////////////// int VisualScriptComposeArray::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } + bool VisualScriptComposeArray::has_input_sequence_port() const { return sequenced; } @@ -731,6 +727,7 @@ String VisualScriptComposeArray::get_output_sequence_port_text(int p_port) const int VisualScriptComposeArray::get_input_value_port_count() const { return inputports.size(); } + int VisualScriptComposeArray::get_output_value_port_count() const { return 1; } @@ -743,6 +740,7 @@ PropertyInfo VisualScriptComposeArray::get_input_value_port_info(int p_idx) cons pi.type = inputports[p_idx].type; return pi; } + PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) const { PropertyInfo pi; pi.name = "out"; @@ -753,6 +751,7 @@ PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) con String VisualScriptComposeArray::get_caption() const { return "Compose Array"; } + String VisualScriptComposeArray::get_text() const { return ""; } @@ -763,11 +762,11 @@ public: virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (input_count > 0) { Array arr; - for (int i = 0; i < input_count; i++) + for (int i = 0; i < input_count; i++) { arr.push_back((*p_inputs[i])); + } Variant va = Variant(arr); *p_outputs[0] = va; @@ -778,7 +777,6 @@ public: }; VisualScriptNodeInstance *VisualScriptComposeArray::instance(VisualScriptInstance *p_instance) { - VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode); instance->input_count = inputports.size(); return instance; @@ -795,31 +793,26 @@ VisualScriptComposeArray::VisualScriptComposeArray() { ////////////////////////////////////////// int VisualScriptOperator::get_output_sequence_port_count() const { - return 0; } bool VisualScriptOperator::has_input_sequence_port() const { - return false; } int VisualScriptOperator::get_input_value_port_count() const { - return (op == Variant::OP_BIT_NEGATE || op == Variant::OP_NOT || op == Variant::OP_NEGATE || op == Variant::OP_POSITIVE) ? 1 : 2; } -int VisualScriptOperator::get_output_value_port_count() const { +int VisualScriptOperator::get_output_value_port_count() const { return 1; } String VisualScriptOperator::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { - static const Variant::Type port_types[Variant::OP_MAX][2] = { { Variant::NIL, Variant::NIL }, //OP_EQUAL, { Variant::NIL, Variant::NIL }, //OP_NOT_EQUAL, @@ -857,10 +850,12 @@ PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = p_idx == 0 ? "A" : "B"; pinfo.type = port_types[op][p_idx]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } + PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { static const Variant::Type port_types[Variant::OP_MAX] = { //comparison @@ -898,8 +893,9 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = ""; pinfo.type = port_types[op]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } @@ -937,7 +933,6 @@ static const char *op_names[] = { }; String VisualScriptOperator::get_caption() const { - static const wchar_t *op_names[] = { //comparison L"A = B", //OP_EQUAL, @@ -974,34 +969,31 @@ String VisualScriptOperator::get_caption() const { } void VisualScriptOperator::set_operator(Variant::Operator p_op) { - - if (op == p_op) + if (op == p_op) { return; + } op = p_op; ports_changed_notify(); } Variant::Operator VisualScriptOperator::get_operator() const { - return op; } void VisualScriptOperator::set_typed(Variant::Type p_op) { - - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); } Variant::Type VisualScriptOperator::get_typed() const { - return typed; } void VisualScriptOperator::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualScriptOperator::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualScriptOperator::get_operator); @@ -1010,8 +1002,9 @@ void VisualScriptOperator::_bind_methods() { String types; for (int i = 0; i < Variant::OP_MAX; i++) { - if (i > 0) + if (i > 0) { types += ","; + } types += op_names[i]; } @@ -1032,25 +1025,23 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; if (unary) { - Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid); } else { Variant::evaluate(op, *p_inputs[0], *p_inputs[1], *p_outputs[0], valid); } if (!valid) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; if (p_outputs[0]->get_type() == Variant::STRING) { r_error_str = *p_outputs[0]; } else { - if (unary) + if (unary) { r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); - else + } else { r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); + } } } @@ -1059,7 +1050,6 @@ public: }; VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator); instance->unary = get_input_value_port_count() == 1; instance->op = op; @@ -1067,14 +1057,12 @@ VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p } VisualScriptOperator::VisualScriptOperator() { - op = Variant::OP_ADD; typed = Variant::NIL; } template <Variant::Operator OP> static Ref<VisualScriptNode> create_op_node(const String &p_name) { - Ref<VisualScriptOperator> node; node.instance(); node->set_operator(OP); @@ -1086,31 +1074,26 @@ static Ref<VisualScriptNode> create_op_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptSelect::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelect::has_input_sequence_port() const { - return false; } int VisualScriptSelect::get_input_value_port_count() const { - return 3; } -int VisualScriptSelect::get_output_value_port_count() const { +int VisualScriptSelect::get_output_value_port_count() const { return 1; } String VisualScriptSelect::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::BOOL, "cond"); } else if (p_idx == 1) { @@ -1119,37 +1102,33 @@ PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { return PropertyInfo(typed, "b"); } } -PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { return PropertyInfo(typed, "out"); } String VisualScriptSelect::get_caption() const { - return "Select"; } String VisualScriptSelect::get_text() const { - return "a if cond, else b"; } void VisualScriptSelect::set_typed(Variant::Type p_op) { - - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); } Variant::Type VisualScriptSelect::get_typed() const { - return typed; } void VisualScriptSelect::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptSelect::set_typed); ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptSelect::get_typed); @@ -1166,25 +1145,23 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool cond = *p_inputs[0]; - if (cond) + if (cond) { *p_outputs[0] = *p_inputs[1]; - else + } else { *p_outputs[0] = *p_inputs[2]; + } return 0; } }; VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect); return instance; } VisualScriptSelect::VisualScriptSelect() { - typed = Variant::NIL; } @@ -1193,36 +1170,30 @@ VisualScriptSelect::VisualScriptSelect() { ////////////////////////////////////////// int VisualScriptVariableGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptVariableGet::has_input_sequence_port() const { - return false; } int VisualScriptVariableGet::get_input_value_port_count() const { - return 0; } -int VisualScriptVariableGet::get_output_value_port_count() const { +int VisualScriptVariableGet::get_output_value_port_count() const { return 1; } String VisualScriptVariableGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "value"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1235,24 +1206,22 @@ PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) cons } String VisualScriptVariableGet::get_caption() const { - return "Get " + variable; } -void VisualScriptVariableGet::set_variable(StringName p_variable) { - if (variable == p_variable) +void VisualScriptVariableGet::set_variable(StringName p_variable) { + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } StringName VisualScriptVariableGet::get_variable() const { - return variable; } void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1260,8 +1229,9 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1272,7 +1242,6 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableGet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableGet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableGet::get_variable); @@ -1286,7 +1255,6 @@ public: StringName variable; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->get_variable(variable, p_outputs[0])) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableGet not found in script: ") + "'" + String(variable) + "'"; @@ -1297,13 +1265,13 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet); instance->node = this; instance->instance = p_instance; instance->variable = variable; return instance; } + VisualScriptVariableGet::VisualScriptVariableGet() { } @@ -1312,31 +1280,26 @@ VisualScriptVariableGet::VisualScriptVariableGet() { ////////////////////////////////////////// int VisualScriptVariableSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptVariableSet::has_input_sequence_port() const { - return true; } int VisualScriptVariableSet::get_input_value_port_count() const { - return 1; } -int VisualScriptVariableSet::get_output_value_port_count() const { +int VisualScriptVariableSet::get_output_value_port_count() const { return 0; } String VisualScriptVariableSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "set"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1349,30 +1312,26 @@ PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptVariableSet::get_caption() const { - return "Set " + variable; } void VisualScriptVariableSet::set_variable(StringName p_variable) { - - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } StringName VisualScriptVariableSet::get_variable() const { - return variable; } void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1380,8 +1339,9 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1392,7 +1352,6 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableSet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableSet::get_variable); @@ -1408,9 +1367,7 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->set_variable(variable, *p_inputs[0])) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableSet not found in script: ") + "'" + String(variable) + "'"; } @@ -1420,13 +1377,13 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet); instance->node = this; instance->instance = p_instance; instance->variable = variable; return instance; } + VisualScriptVariableSet::VisualScriptVariableSet() { } @@ -1435,36 +1392,30 @@ VisualScriptVariableSet::VisualScriptVariableSet() { ////////////////////////////////////////// int VisualScriptConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstant::has_input_sequence_port() const { - return false; } int VisualScriptConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptConstant::get_output_value_port_count() const { +int VisualScriptConstant::get_output_value_port_count() const { return 1; } String VisualScriptConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = String(value); pinfo.type = type; @@ -1472,14 +1423,13 @@ PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { } String VisualScriptConstant::get_caption() const { - return "Constant"; } void VisualScriptConstant::set_constant_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; Callable::CallError ce; @@ -1489,34 +1439,32 @@ void VisualScriptConstant::set_constant_type(Variant::Type p_type) { } Variant::Type VisualScriptConstant::get_constant_type() const { - return type; } void VisualScriptConstant::set_constant_value(Variant p_value) { - - if (value == p_value) + if (value == p_value) { return; + } value = p_value; ports_changed_notify(); } -Variant VisualScriptConstant::get_constant_value() const { +Variant VisualScriptConstant::get_constant_value() const { return value; } void VisualScriptConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "value") { property.type = type; - if (type == Variant::NIL) + if (type == Variant::NIL) { property.usage = 0; //do not save if nil + } } } void VisualScriptConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_type", "type"), &VisualScriptConstant::set_constant_type); ClassDB::bind_method(D_METHOD("get_constant_type"), &VisualScriptConstant::get_constant_type); @@ -1538,21 +1486,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = constant; return 0; } }; VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant); instance->constant = value; return instance; } VisualScriptConstant::VisualScriptConstant() { - type = Variant::NIL; } @@ -1561,36 +1506,30 @@ VisualScriptConstant::VisualScriptConstant() { ////////////////////////////////////////// int VisualScriptPreload::get_output_sequence_port_count() const { - return 0; } bool VisualScriptPreload::has_input_sequence_port() const { - return false; } int VisualScriptPreload::get_input_value_port_count() const { - return 0; } -int VisualScriptPreload::get_output_value_port_count() const { +int VisualScriptPreload::get_output_value_port_count() const { return 1; } String VisualScriptPreload::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.type = Variant::OBJECT; if (preload.is_valid()) { @@ -1611,26 +1550,23 @@ PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { } String VisualScriptPreload::get_caption() const { - return "Preload"; } void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { - - if (preload == p_preload) + if (preload == p_preload) { return; + } preload = p_preload; ports_changed_notify(); } Ref<Resource> VisualScriptPreload::get_preload() const { - return preload; } void VisualScriptPreload::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_preload", "resource"), &VisualScriptPreload::set_preload); ClassDB::bind_method(D_METHOD("get_preload"), &VisualScriptPreload::get_preload); @@ -1643,14 +1579,12 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = preload; return 0; } }; VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload); instance->preload = preload; return instance; @@ -1664,31 +1598,26 @@ VisualScriptPreload::VisualScriptPreload() { ////////////////////////////////////////// int VisualScriptIndexGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptIndexGet::has_input_sequence_port() const { - return false; } int VisualScriptIndexGet::get_input_value_port_count() const { - return 2; } -int VisualScriptIndexGet::get_output_value_port_count() const { +int VisualScriptIndexGet::get_output_value_port_count() const { return 1; } String VisualScriptIndexGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else { @@ -1697,12 +1626,10 @@ PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexGet::get_caption() const { - return "Get Index"; } @@ -1711,7 +1638,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid); @@ -1724,10 +1650,10 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet); return instance; } + VisualScriptIndexGet::VisualScriptIndexGet() { } @@ -1736,31 +1662,26 @@ VisualScriptIndexGet::VisualScriptIndexGet() { ////////////////////////////////////////// int VisualScriptIndexSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptIndexSet::has_input_sequence_port() const { - return true; } int VisualScriptIndexSet::get_input_value_port_count() const { - return 3; } -int VisualScriptIndexSet::get_output_value_port_count() const { +int VisualScriptIndexSet::get_output_value_port_count() const { return 0; } String VisualScriptIndexSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else if (p_idx == 1) { @@ -1772,12 +1693,10 @@ PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexSet::get_caption() const { - return "Set Index"; } @@ -1786,7 +1705,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = *p_inputs[0]; p_outputs[0]->set(*p_inputs[1], *p_inputs[2], &valid); @@ -1800,10 +1718,10 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet); return instance; } + VisualScriptIndexSet::VisualScriptIndexSet() { } @@ -1812,31 +1730,26 @@ VisualScriptIndexSet::VisualScriptIndexSet() { ////////////////////////////////////////// int VisualScriptGlobalConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptGlobalConstant::has_input_sequence_port() const { - return false; } int VisualScriptGlobalConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptGlobalConstant::get_output_value_port_count() const { +int VisualScriptGlobalConstant::get_output_value_port_count() const { return 1; } String VisualScriptGlobalConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1846,12 +1759,10 @@ PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) c } String VisualScriptGlobalConstant::get_caption() const { - return "Global Constant"; } void VisualScriptGlobalConstant::set_global_constant(int p_which) { - index = p_which; _change_notify(); ports_changed_notify(); @@ -1867,37 +1778,33 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = GlobalConstants::get_global_constant_value(index); return 0; } }; VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant); instance->index = index; return instance; } void VisualScriptGlobalConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_global_constant", "index"), &VisualScriptGlobalConstant::set_global_constant); ClassDB::bind_method(D_METHOD("get_global_constant"), &VisualScriptGlobalConstant::get_global_constant); String cc; for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { - - if (i > 0) + if (i > 0) { cc += ","; + } cc += GlobalConstants::get_global_constant_name(i); } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { - index = 0; } @@ -1906,31 +1813,26 @@ VisualScriptGlobalConstant::VisualScriptGlobalConstant() { ////////////////////////////////////////// int VisualScriptClassConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptClassConstant::has_input_sequence_port() const { - return false; } int VisualScriptClassConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptClassConstant::get_output_value_port_count() const { +int VisualScriptClassConstant::get_output_value_port_count() const { return 1; } String VisualScriptClassConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1943,12 +1845,10 @@ PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) co } String VisualScriptClassConstant::get_caption() const { - return "Class Constant"; } void VisualScriptClassConstant::set_class_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -1959,7 +1859,6 @@ StringName VisualScriptClassConstant::get_class_constant() { } void VisualScriptClassConstant::set_base_type(const StringName &p_which) { - base_type = p_which; List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -1992,7 +1891,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid class constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2004,16 +1902,13 @@ public: }; VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant); instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid); return instance; } void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -2028,7 +1923,6 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const } void VisualScriptClassConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_class_constant", "name"), &VisualScriptClassConstant::set_class_constant); ClassDB::bind_method(D_METHOD("get_class_constant"), &VisualScriptClassConstant::get_class_constant); @@ -2040,7 +1934,6 @@ void VisualScriptClassConstant::_bind_methods() { } VisualScriptClassConstant::VisualScriptClassConstant() { - base_type = "Object"; } @@ -2049,41 +1942,34 @@ VisualScriptClassConstant::VisualScriptClassConstant() { ////////////////////////////////////////// int VisualScriptBasicTypeConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptBasicTypeConstant::has_input_sequence_port() const { - return false; } int VisualScriptBasicTypeConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptBasicTypeConstant::get_output_value_port_count() const { +int VisualScriptBasicTypeConstant::get_output_value_port_count() const { return 1; } String VisualScriptBasicTypeConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptBasicTypeConstant::get_caption() const { - return "Basic Constant"; } @@ -2096,7 +1982,6 @@ String VisualScriptBasicTypeConstant::get_text() const { } void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -2107,7 +1992,6 @@ StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const { } void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { - type = p_which; List<StringName> constants; @@ -2141,7 +2025,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid basic type constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2153,16 +2036,13 @@ public: }; VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant); instance->value = Variant::get_constant_value(type, name, &instance->valid); return instance; } void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<StringName> constants; Variant::get_constants_for_type(type, &constants); @@ -2181,7 +2061,6 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c } void VisualScriptBasicTypeConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_basic_type", "name"), &VisualScriptBasicTypeConstant::set_basic_type); ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptBasicTypeConstant::get_basic_type); @@ -2198,7 +2077,6 @@ void VisualScriptBasicTypeConstant::_bind_methods() { } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { - type = Variant::NIL; } @@ -2229,46 +2107,38 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = { }; int VisualScriptMathConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptMathConstant::has_input_sequence_port() const { - return false; } int VisualScriptMathConstant::get_input_value_port_count() const { - return 0; } -int VisualScriptMathConstant::get_output_value_port_count() const { +int VisualScriptMathConstant::get_output_value_port_count() const { return 1; } String VisualScriptMathConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::FLOAT, const_name[constant]); } String VisualScriptMathConstant::get_caption() const { - return "Math Constant"; } void VisualScriptMathConstant::set_math_constant(MathConstant p_which) { - constant = p_which; _change_notify(); ports_changed_notify(); @@ -2284,30 +2154,27 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = value; return 0; } }; VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant); instance->value = const_value[constant]; return instance; } void VisualScriptMathConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_math_constant", "which"), &VisualScriptMathConstant::set_math_constant); ClassDB::bind_method(D_METHOD("get_math_constant"), &VisualScriptMathConstant::get_math_constant); String cc; for (int i = 0; i < MATH_CONSTANT_MAX; i++) { - - if (i > 0) + if (i > 0) { cc += ","; + } cc += const_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); @@ -2324,7 +2191,6 @@ void VisualScriptMathConstant::_bind_methods() { } VisualScriptMathConstant::VisualScriptMathConstant() { - constant = MATH_CONSTANT_ONE; } @@ -2333,46 +2199,38 @@ VisualScriptMathConstant::VisualScriptMathConstant() { ////////////////////////////////////////// int VisualScriptEngineSingleton::get_output_sequence_port_count() const { - return 0; } bool VisualScriptEngineSingleton::has_input_sequence_port() const { - return false; } int VisualScriptEngineSingleton::get_input_value_port_count() const { - return 0; } -int VisualScriptEngineSingleton::get_output_value_port_count() const { +int VisualScriptEngineSingleton::get_output_value_port_count() const { return 1; } String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, singleton); } String VisualScriptEngineSingleton::get_caption() const { - return "Get Engine Singleton"; } void VisualScriptEngineSingleton::set_singleton(const String &p_string) { - singleton = p_string; _change_notify(); @@ -2390,21 +2248,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = singleton; return 0; } }; VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); instance->singleton = Engine::get_singleton()->get_singleton_object(singleton); return instance; } VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); TypeGuess tg; tg.type = Variant::OBJECT; @@ -2417,7 +2272,6 @@ VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output } void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) const { - String cc; List<Engine::Singleton> singletons; @@ -2425,11 +2279,13 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con Engine::get_singleton()->get_singletons(&singletons); for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { - if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") + if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") { continue; //skip these, too simple named + } - if (cc != String()) + if (cc != String()) { cc += ","; + } cc += E->get().name; } @@ -2438,7 +2294,6 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con } void VisualScriptEngineSingleton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_singleton", "name"), &VisualScriptEngineSingleton::set_singleton); ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptEngineSingleton::get_singleton); @@ -2446,7 +2301,6 @@ void VisualScriptEngineSingleton::_bind_methods() { } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { - singleton = String(); } @@ -2455,46 +2309,38 @@ VisualScriptEngineSingleton::VisualScriptEngineSingleton() { ////////////////////////////////////////// int VisualScriptSceneNode::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneNode::has_input_sequence_port() const { - return false; } int VisualScriptSceneNode::get_input_value_port_count() const { - return 0; } -int VisualScriptSceneNode::get_output_value_port_count() const { +int VisualScriptSceneNode::get_output_value_port_count() const { return 1; } String VisualScriptSceneNode::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, path.simplified()); } String VisualScriptSceneNode::get_caption() const { - return "Get Scene Node"; } void VisualScriptSceneNode::set_node_path(const NodePath &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2513,7 +2359,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2535,7 +2380,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode); instance->node = this; instance->instance = p_instance; @@ -2546,19 +2390,21 @@ VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance * #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -2567,31 +2413,34 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Node"; #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return tg; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return tg; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return tg; + } Node *another = script_node->get_node(path); @@ -2604,29 +2453,31 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu } void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { - #ifdef TOOLS_ENABLED if (property.name == "node_path") { - Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return; + } property.hint_string = script_node->get_path(); } @@ -2634,7 +2485,6 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { } void VisualScriptSceneNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_path", "path"), &VisualScriptSceneNode::set_node_path); ClassDB::bind_method(D_METHOD("get_node_path"), &VisualScriptSceneNode::get_node_path); @@ -2642,7 +2492,6 @@ void VisualScriptSceneNode::_bind_methods() { } VisualScriptSceneNode::VisualScriptSceneNode() { - path = String("."); } @@ -2651,41 +2500,34 @@ VisualScriptSceneNode::VisualScriptSceneNode() { ////////////////////////////////////////// int VisualScriptSceneTree::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneTree::has_input_sequence_port() const { - return false; } int VisualScriptSceneTree::get_input_value_port_count() const { - return 0; } -int VisualScriptSceneTree::get_output_value_port_count() const { +int VisualScriptSceneTree::get_output_value_port_count() const { return 1; } String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "Scene Tree", PROPERTY_HINT_TYPE_STRING, "SceneTree"); } String VisualScriptSceneTree::get_caption() const { - return "Get Scene Tree"; } @@ -2697,7 +2539,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2719,7 +2560,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree); instance->node = this; instance->instance = p_instance; @@ -2727,7 +2567,6 @@ VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance * } VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const { - TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "SceneTree"; @@ -2748,46 +2587,38 @@ VisualScriptSceneTree::VisualScriptSceneTree() { ////////////////////////////////////////// int VisualScriptResourcePath::get_output_sequence_port_count() const { - return 0; } bool VisualScriptResourcePath::has_input_sequence_port() const { - return false; } int VisualScriptResourcePath::get_input_value_port_count() const { - return 0; } -int VisualScriptResourcePath::get_output_value_port_count() const { +int VisualScriptResourcePath::get_output_value_port_count() const { return 1; } String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::STRING, path); } String VisualScriptResourcePath::get_caption() const { - return "Resource Path"; } void VisualScriptResourcePath::set_resource_path(const String &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2804,21 +2635,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = path; return 0; } }; VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath); instance->path = path; return instance; } void VisualScriptResourcePath::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_resource_path", "path"), &VisualScriptResourcePath::set_resource_path); ClassDB::bind_method(D_METHOD("get_resource_path"), &VisualScriptResourcePath::get_resource_path); @@ -2826,7 +2654,6 @@ void VisualScriptResourcePath::_bind_methods() { } VisualScriptResourcePath::VisualScriptResourcePath() { - path = ""; } @@ -2835,47 +2662,41 @@ VisualScriptResourcePath::VisualScriptResourcePath() { ////////////////////////////////////////// int VisualScriptSelf::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelf::has_input_sequence_port() const { - return false; } int VisualScriptSelf::get_input_value_port_count() const { - return 0; } -int VisualScriptSelf::get_output_value_port_count() const { +int VisualScriptSelf::get_output_value_port_count() const { return 1; } String VisualScriptSelf::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const { - String type_name; - if (get_visual_script().is_valid()) + if (get_visual_script().is_valid()) { type_name = get_visual_script()->get_instance_base_type(); - else + } else { type_name = "instance"; + } return PropertyInfo(Variant::OBJECT, type_name); } String VisualScriptSelf::get_caption() const { - return "Get Self"; } @@ -2886,28 +2707,26 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = instance->get_owner_ptr(); return 0; } }; VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf); instance->instance = p_instance; return instance; } VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Object"; Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } tg.gdclass = script->get_instance_base_type(); tg.script = script; @@ -2926,7 +2745,6 @@ VisualScriptSelf::VisualScriptSelf() { ////////////////////////////////////////// int VisualScriptCustomNode::get_output_sequence_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) { return get_script_instance()->call("_get_output_sequence_port_count"); } @@ -2934,7 +2752,6 @@ int VisualScriptCustomNode::get_output_sequence_port_count() const { } bool VisualScriptCustomNode::has_input_sequence_port() const { - if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) { return get_script_instance()->call("_has_input_sequence_port"); } @@ -2942,14 +2759,13 @@ bool VisualScriptCustomNode::has_input_sequence_port() const { } int VisualScriptCustomNode::get_input_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) { return get_script_instance()->call("_get_input_value_port_count"); } return 0; } -int VisualScriptCustomNode::get_output_value_port_count() const { +int VisualScriptCustomNode::get_output_value_port_count() const { if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) { return get_script_instance()->call("_get_output_value_port_count"); } @@ -2957,7 +2773,6 @@ int VisualScriptCustomNode::get_output_value_port_count() const { } String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) { return get_script_instance()->call("_get_output_sequence_port_text", p_port); } @@ -2966,7 +2781,6 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx))); @@ -2978,7 +2792,6 @@ PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx))); @@ -2990,7 +2803,6 @@ PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const } String VisualScriptCustomNode::get_caption() const { - if (get_script_instance() && get_script_instance()->has_method("_get_caption")) { return get_script_instance()->call("_get_caption"); } @@ -2998,7 +2810,6 @@ String VisualScriptCustomNode::get_caption() const { } String VisualScriptCustomNode::get_text() const { - if (get_script_instance() && get_script_instance()->has_method("_get_text")) { return get_script_instance()->call("_get_text"); } @@ -3006,7 +2817,6 @@ String VisualScriptCustomNode::get_text() const { } String VisualScriptCustomNode::get_category() const { - if (get_script_instance() && get_script_instance()->has_method("_get_category")) { return get_script_instance()->call("_get_category"); } @@ -3023,7 +2833,6 @@ public: virtual int get_working_memory_size() const { return work_mem_size; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (node->get_script_instance()) { #ifdef DEBUG_ENABLED if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) { @@ -3085,7 +2894,6 @@ public: }; VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode); instance->instance = p_instance; instance->node = this; @@ -3106,7 +2914,6 @@ void VisualScriptCustomNode::_script_changed() { } void VisualScriptCustomNode::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port")); @@ -3150,42 +2957,35 @@ VisualScriptCustomNode::VisualScriptCustomNode() { ////////////////////////////////////////// int VisualScriptSubCall::get_output_sequence_port_count() const { - return 1; } bool VisualScriptSubCall::has_input_sequence_port() const { - return true; } int VisualScriptSubCall::get_input_value_port_count() const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments.size(); } return 0; } -int VisualScriptSubCall::get_output_value_port_count() const { +int VisualScriptSubCall::get_output_value_port_count() const { return 1; } String VisualScriptSubCall::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments[p_idx]; } @@ -3194,7 +2994,6 @@ PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); @@ -3204,25 +3003,24 @@ PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { } String VisualScriptSubCall::get_caption() const { - return "SubCall"; } String VisualScriptSubCall::get_text() const { - Ref<Script> script = get_script(); if (script.is_valid()) { - if (script->get_name() != String()) + if (script->get_name() != String()) { return script->get_name(); - if (script->get_path().is_resource_file()) + } + if (script->get_path().is_resource_file()) { return script->get_path().get_file(); + } return script->get_class(); } return ""; } String VisualScriptSubCall::get_category() const { - return "custom"; } @@ -3236,7 +3034,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Node requires a script with a _subcall(<args>) method to work."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -3248,7 +3045,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall); instance->instance = p_instance; Ref<Script> script = get_script(); @@ -3262,7 +3058,6 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_ } void VisualScriptSubCall::_bind_methods() { - MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments")); scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(scmi); @@ -3276,87 +3071,78 @@ VisualScriptSubCall::VisualScriptSubCall() { ////////////////////////////////////////// int VisualScriptComment::get_output_sequence_port_count() const { - return 0; } bool VisualScriptComment::has_input_sequence_port() const { - return false; } int VisualScriptComment::get_input_value_port_count() const { return 0; } -int VisualScriptComment::get_output_value_port_count() const { +int VisualScriptComment::get_output_value_port_count() const { return 0; } String VisualScriptComment::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptComment::get_caption() const { - return title; } String VisualScriptComment::get_text() const { - return description; } void VisualScriptComment::set_title(const String &p_title) { - - if (title == p_title) + if (title == p_title) { return; + } title = p_title; ports_changed_notify(); } String VisualScriptComment::get_title() const { - return title; } void VisualScriptComment::set_description(const String &p_description) { - - if (description == p_description) + if (description == p_description) { return; + } description = p_description; ports_changed_notify(); } -String VisualScriptComment::get_description() const { +String VisualScriptComment::get_description() const { return description; } void VisualScriptComment::set_size(const Size2 &p_size) { - - if (size == p_size) + if (size == p_size) { return; + } size = p_size; ports_changed_notify(); } -Size2 VisualScriptComment::get_size() const { +Size2 VisualScriptComment::get_size() const { return size; } String VisualScriptComment::get_category() const { - return "data"; } @@ -3367,20 +3153,17 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - return 0; } }; VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment); instance->instance = p_instance; return instance; } void VisualScriptComment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_title", "title"), &VisualScriptComment::set_title); ClassDB::bind_method(D_METHOD("get_title"), &VisualScriptComment::get_title); @@ -3396,7 +3179,6 @@ void VisualScriptComment::_bind_methods() { } VisualScriptComment::VisualScriptComment() { - title = "Comment"; size = Size2(150, 150); } @@ -3406,70 +3188,60 @@ VisualScriptComment::VisualScriptComment() { ////////////////////////////////////////// int VisualScriptConstructor::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstructor::has_input_sequence_port() const { - return false; } int VisualScriptConstructor::get_input_value_port_count() const { return constructor.arguments.size(); } -int VisualScriptConstructor::get_output_value_port_count() const { +int VisualScriptConstructor::get_output_value_port_count() const { return 1; } String VisualScriptConstructor::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const { - return constructor.arguments[p_idx]; } PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptConstructor::get_caption() const { - return "Construct " + Variant::get_type_name(type); } String VisualScriptConstructor::get_category() const { - return "functions"; } void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); } Variant::Type VisualScriptConstructor::get_constructor_type() const { - return type; } void VisualScriptConstructor::set_constructor(const Dictionary &p_info) { - constructor = MethodInfo::from_dict(p_info); ports_changed_notify(); } Dictionary VisualScriptConstructor::get_constructor() const { - return constructor; } @@ -3482,7 +3254,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Callable::CallError ce; *p_outputs[0] = Variant::construct(type, p_inputs, argcount, ce); if (ce.error != Callable::CallError::CALL_OK) { @@ -3494,7 +3265,6 @@ public: }; VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor); instance->instance = p_instance; instance->type = type; @@ -3503,7 +3273,6 @@ VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance } void VisualScriptConstructor::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constructor_type", "type"), &VisualScriptConstructor::set_constructor_type); ClassDB::bind_method(D_METHOD("get_constructor_type"), &VisualScriptConstructor::get_constructor_type); @@ -3515,14 +3284,12 @@ void VisualScriptConstructor::_bind_methods() { } VisualScriptConstructor::VisualScriptConstructor() { - type = Variant::NIL; } static Map<String, Pair<Variant::Type, MethodInfo>> constructor_map; static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { - ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>()); Ref<VisualScriptConstructor> vsc; @@ -3538,69 +3305,60 @@ static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptLocalVar::get_output_sequence_port_count() const { - return 0; } bool VisualScriptLocalVar::has_input_sequence_port() const { - return false; } int VisualScriptLocalVar::get_input_value_port_count() const { return 0; } -int VisualScriptLocalVar::get_output_value_port_count() const { +int VisualScriptLocalVar::get_output_value_port_count() const { return 1; } String VisualScriptLocalVar::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } -PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const { return PropertyInfo(type, name); } String VisualScriptLocalVar::get_caption() const { - return "Get Local Var"; } String VisualScriptLocalVar::get_category() const { - return "data"; } void VisualScriptLocalVar::set_var_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptLocalVar::get_var_name() const { - return name; } void VisualScriptLocalVar::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVar::get_var_type() const { - return type; } @@ -3611,14 +3369,12 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = *p_working_mem; return 0; } }; VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar); instance->instance = p_instance; instance->name = name; @@ -3627,7 +3383,6 @@ VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p } void VisualScriptLocalVar::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVar::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVar::get_var_name); @@ -3644,7 +3399,6 @@ void VisualScriptLocalVar::_bind_methods() { } VisualScriptLocalVar::VisualScriptLocalVar() { - name = "new_local"; type = Variant::NIL; } @@ -3654,74 +3408,64 @@ VisualScriptLocalVar::VisualScriptLocalVar() { ////////////////////////////////////////// int VisualScriptLocalVarSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptLocalVarSet::has_input_sequence_port() const { - return true; } int VisualScriptLocalVarSet::get_input_value_port_count() const { return 1; } -int VisualScriptLocalVarSet::get_output_value_port_count() const { +int VisualScriptLocalVarSet::get_output_value_port_count() const { return 1; } String VisualScriptLocalVarSet::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "set"); } -PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const { return PropertyInfo(type, "get"); } String VisualScriptLocalVarSet::get_caption() const { - return "Set Local Var"; } String VisualScriptLocalVarSet::get_text() const { - return name; } String VisualScriptLocalVarSet::get_category() const { - return "data"; } void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptLocalVarSet::get_var_name() const { - return name; } void VisualScriptLocalVarSet::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVarSet::get_var_type() const { - return type; } @@ -3732,7 +3476,6 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_working_mem = *p_inputs[0]; *p_outputs[0] = *p_working_mem; return 0; @@ -3740,7 +3483,6 @@ public: }; VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet); instance->instance = p_instance; instance->name = name; @@ -3749,7 +3491,6 @@ VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance } void VisualScriptLocalVarSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVarSet::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVarSet::get_var_name); @@ -3766,7 +3507,6 @@ void VisualScriptLocalVarSet::_bind_methods() { } VisualScriptLocalVarSet::VisualScriptLocalVarSet() { - name = "new_local"; type = Variant::NIL; } @@ -3776,34 +3516,30 @@ VisualScriptLocalVarSet::VisualScriptLocalVarSet() { ////////////////////////////////////////// int VisualScriptInputAction::get_output_sequence_port_count() const { - return 0; } bool VisualScriptInputAction::has_input_sequence_port() const { - return false; } int VisualScriptInputAction::get_input_value_port_count() const { return 0; } -int VisualScriptInputAction::get_output_value_port_count() const { +int VisualScriptInputAction::get_output_value_port_count() const { return 1; } String VisualScriptInputAction::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } -PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { +PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { String mstr; switch (mode) { case MODE_PRESSED: { @@ -3824,39 +3560,36 @@ PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) cons } String VisualScriptInputAction::get_caption() const { - return "Action " + name; } String VisualScriptInputAction::get_category() const { - return "data"; } void VisualScriptInputAction::set_action_name(const StringName &p_name) { - - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); } StringName VisualScriptInputAction::get_action_name() const { - return name; } void VisualScriptInputAction::set_action_mode(Mode p_mode) { - - if (mode == p_mode) + if (mode == p_mode) { return; + } mode = p_mode; ports_changed_notify(); } -VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const { +VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const { return mode; } @@ -3867,7 +3600,6 @@ public: VisualScriptInputAction::Mode mode; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (mode) { case VisualScriptInputAction::MODE_PRESSED: { *p_outputs[0] = Input::get_singleton()->is_action_pressed(action); @@ -3888,7 +3620,6 @@ public: }; VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction); instance->instance = p_instance; instance->action = name; @@ -3898,9 +3629,7 @@ VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance } void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { - if (property.name == "action") { - property.hint = PROPERTY_HINT_ENUM; String actions; @@ -3911,8 +3640,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); @@ -3922,8 +3652,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { al.sort(); for (int i = 0; i < al.size(); i++) { - if (actions != String()) + if (actions != String()) { actions += ","; + } actions += al[i]; } @@ -3932,7 +3663,6 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { } void VisualScriptInputAction::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_action_name", "name"), &VisualScriptInputAction::set_action_name); ClassDB::bind_method(D_METHOD("get_action_name"), &VisualScriptInputAction::get_action_name); @@ -3949,7 +3679,6 @@ void VisualScriptInputAction::_bind_methods() { } VisualScriptInputAction::VisualScriptInputAction() { - name = ""; mode = MODE_PRESSED; } @@ -3959,50 +3688,42 @@ VisualScriptInputAction::VisualScriptInputAction() { ////////////////////////////////////////// int VisualScriptDeconstruct::get_output_sequence_port_count() const { - return 0; } bool VisualScriptDeconstruct::has_input_sequence_port() const { - return false; } int VisualScriptDeconstruct::get_input_value_port_count() const { return 1; } -int VisualScriptDeconstruct::get_output_value_port_count() const { +int VisualScriptDeconstruct::get_output_value_port_count() const { return elements.size(); } String VisualScriptDeconstruct::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const { - return PropertyInfo(elements[p_idx].type, elements[p_idx].name); } String VisualScriptDeconstruct::get_caption() const { - return "Deconstruct " + Variant::get_type_name(type); } String VisualScriptDeconstruct::get_category() const { - return "functions"; } void VisualScriptDeconstruct::_update_elements() { - elements.clear(); Variant v; Callable::CallError ce; @@ -4012,7 +3733,6 @@ void VisualScriptDeconstruct::_update_elements() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - Element e; e.name = E->get().name; e.type = E->get().type; @@ -4021,9 +3741,9 @@ void VisualScriptDeconstruct::_update_elements() { } void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { - - if (type == p_type) + if (type == p_type) { return; + } type = p_type; _update_elements(); @@ -4032,12 +3752,10 @@ void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { } Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { - return type; } void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { - ERR_FAIL_COND(p_elements.size() % 2 == 1); elements.resize(p_elements.size() / 2); for (int i = 0; i < elements.size(); i++) { @@ -4047,7 +3765,6 @@ void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { } Array VisualScriptDeconstruct::_get_elem_cache() const { - Array ret; for (int i = 0; i < elements.size(); i++) { ret.push_back(elements[i].name); @@ -4064,7 +3781,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Variant in = *p_inputs[0]; for (int i = 0; i < outputs.size(); i++) { @@ -4082,7 +3798,6 @@ public: }; VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct); instance->instance = p_instance; instance->outputs.resize(elements.size()); @@ -4097,7 +3812,6 @@ void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const { } void VisualScriptDeconstruct::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type); ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type); @@ -4114,7 +3828,6 @@ void VisualScriptDeconstruct::_bind_methods() { } VisualScriptDeconstruct::VisualScriptDeconstruct() { - type = Variant::NIL; } @@ -4127,7 +3840,6 @@ static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) { } void register_visual_script_nodes() { - VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic<VisualScriptVariableSet>); VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic<VisualScriptVariableGet>); VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic<VisualScriptEngineSingleton>); @@ -4199,12 +3911,10 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/compose_array", create_node_generic<VisualScriptComposeArray>); for (int i = 1; i < Variant::VARIANT_MAX; i++) { - List<MethodInfo> constructors; Variant::get_constructor_list(Variant::Type(i), &constructors); for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) { - if (E->get().arguments.size() > 0) { String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "("; for (int j = 0; j < E->get().arguments.size(); j++) { @@ -4229,6 +3939,5 @@ void register_visual_script_nodes() { } void unregister_visual_script_nodes() { - constructor_map.clear(); } |