From afd0d21d480d99526d10ef2722ecd4501ad292ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cambr=C3=A9?= Date: Mon, 15 Nov 2021 19:56:10 +0100 Subject: [PATCH] Remove VisualScriptVariableGet VisualScriptVariableSet --- .../doc_classes/VisualScriptVariableGet.xml | 20 -- .../doc_classes/VisualScriptVariableSet.xml | 21 -- modules/visual_script/register_types.cpp | 2 - modules/visual_script/visual_script.cpp | 35 +-- modules/visual_script/visual_script_nodes.cpp | 224 ------------------ modules/visual_script/visual_script_nodes.h | 64 ----- 6 files changed, 19 insertions(+), 347 deletions(-) delete mode 100644 modules/visual_script/doc_classes/VisualScriptVariableGet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptVariableSet.xml diff --git a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml deleted file mode 100644 index e29765d6166a..000000000000 --- a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Gets a variable's value. - - - Returns a variable's value. "Var Name" must be supplied, with an optional type. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]value[/code] - - - - - - The variable's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml deleted file mode 100644 index b2cc70d62e68..000000000000 --- a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - Changes a variable's value. - - - Changes a variable's value to the given input. - [b]Input Ports:[/b] - - Sequence - - Data (variant): [code]set[/code] - [b]Output Ports:[/b] - - Sequence - - - - - - The variable's name. - - - diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 6f56fbbc70b1..292642bae382 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -59,8 +59,6 @@ void register_visual_script_types() { GDREGISTER_VIRTUAL_CLASS(VisualScriptLists); GDREGISTER_CLASS(VisualScriptComposeArray); GDREGISTER_CLASS(VisualScriptOperator); - GDREGISTER_CLASS(VisualScriptVariableSet); - GDREGISTER_CLASS(VisualScriptVariableGet); GDREGISTER_CLASS(VisualScriptConstant); GDREGISTER_CLASS(VisualScriptIndexGet); GDREGISTER_CLASS(VisualScriptIndexSet); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 700cc8567280..55ef3bacbbd7 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -588,22 +588,25 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p variables[p_new_name] = variables[p_name]; variables.erase(p_name); List ids; - get_node_list(&ids); - for (int &E : ids) { - Ref nodeget = get_node(E); - if (nodeget.is_valid()) { - if (nodeget->get_variable() == p_name) { - nodeget->set_variable(p_new_name); - } - } else { - Ref nodeset = get_node(E); - if (nodeset.is_valid()) { - if (nodeset->get_variable() == p_name) { - nodeset->set_variable(p_new_name); - } - } - } - } + + // This code will be neded for proposal #3549 + // So i will keep it comented + //get_node_list(&ids); + //for (int &E : ids) { + // Ref nodeget = get_node(E); + // if (nodeget.is_valid()) { + // if (nodeget->get_variable() == p_name) { + // nodeget->set_variable(p_new_name); + // } + // } else { + // Ref nodeset = get_node(E); + // if (nodeset.is_valid()) { + // if (nodeset->get_variable() == p_name) { + // nodeset->set_variable(p_new_name); + // } + // } + // } + //} } void VisualScript::add_custom_signal(const StringName &p_name) { diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 471d8ef0ae21..9958a6dd6aab 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1243,228 +1243,6 @@ VisualScriptSelect::VisualScriptSelect() { typed = Variant::NIL; } -////////////////////////////////////////// -////////////////VARIABLE GET////////////////// -////////////////////////////////////////// - -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 { - 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)) { - PropertyInfo vinfo = get_visual_script()->get_variable_info(variable); - pinfo.type = vinfo.type; - pinfo.hint = vinfo.hint; - pinfo.hint_string = vinfo.hint_string; - } - return pinfo; -} - -String VisualScriptVariableGet::get_caption() const { - return "Get " + 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 vs = get_visual_script(); - List vars; - vs->get_variable_list(&vars); - - String vhint; - for (const StringName &E : vars) { - if (vhint != String()) { - vhint += ","; - } - - vhint += E.operator String(); - } - - property.hint = PROPERTY_HINT_ENUM; - property.hint_string = vhint; - } -} - -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); - - ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable"); -} - -class VisualScriptNodeInstanceVariableGet : public VisualScriptNodeInstance { -public: - VisualScriptVariableGet *node; - VisualScriptInstance *instance; - 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) + "'"; - return 0; - } - return 0; - } -}; - -VisualScriptNodeInstance *VisualScriptVariableGet::instantiate(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet); - instance->node = this; - instance->instance = p_instance; - instance->variable = variable; - return instance; -} - -VisualScriptVariableGet::VisualScriptVariableGet() { -} - -////////////////////////////////////////// -////////////////VARIABLE SET////////////////// -////////////////////////////////////////// - -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 { - 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)) { - PropertyInfo vinfo = get_visual_script()->get_variable_info(variable); - pinfo.type = vinfo.type; - pinfo.hint = vinfo.hint; - pinfo.hint_string = vinfo.hint_string; - } - return pinfo; -} - -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) { - 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 vs = get_visual_script(); - List vars; - vs->get_variable_list(&vars); - - String vhint; - for (const StringName &E : vars) { - if (vhint != String()) { - vhint += ","; - } - - vhint += E.operator String(); - } - - property.hint = PROPERTY_HINT_ENUM; - property.hint_string = vhint; - } -} - -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); - - ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable"); -} - -class VisualScriptNodeInstanceVariableSet : public VisualScriptNodeInstance { -public: - VisualScriptVariableSet *node; - VisualScriptInstance *instance; - StringName variable; - - //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) + "'"; - } - - return 0; - } -}; - -VisualScriptNodeInstance *VisualScriptVariableSet::instantiate(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet); - instance->node = this; - instance->instance = p_instance; - instance->variable = variable; - return instance; -} - -VisualScriptVariableSet::VisualScriptVariableSet() { -} - ////////////////////////////////////////// ////////////////CONSTANT////////////////// ////////////////////////////////////////// @@ -3974,8 +3752,6 @@ static Ref create_node_deconst_typed(const String &p_name) { } void register_visual_script_nodes() { - VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic); - VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic); VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic); VisualScriptLanguage::singleton->add_register_func("data/scene_node", create_node_generic); VisualScriptLanguage::singleton->add_register_func("data/scene_tree", create_node_generic); diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 78881f0a533a..b4499e449c95 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -262,70 +262,6 @@ class VisualScriptSelect : public VisualScriptNode { VisualScriptSelect(); }; -class VisualScriptVariableGet : public VisualScriptNode { - GDCLASS(VisualScriptVariableGet, VisualScriptNode); - - StringName variable; - -protected: - virtual void _validate_property(PropertyInfo &property) const override; - static void _bind_methods(); - -public: - virtual int get_output_sequence_port_count() const override; - virtual bool has_input_sequence_port() const override; - - virtual String get_output_sequence_port_text(int p_port) const override; - - virtual int get_input_value_port_count() const override; - virtual int get_output_value_port_count() const override; - - virtual PropertyInfo get_input_value_port_info(int p_idx) const override; - virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - - virtual String get_caption() const override; - virtual String get_category() const override { return "data"; } - - void set_variable(StringName p_variable); - StringName get_variable() const; - - virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; - - VisualScriptVariableGet(); -}; - -class VisualScriptVariableSet : public VisualScriptNode { - GDCLASS(VisualScriptVariableSet, VisualScriptNode); - - StringName variable; - -protected: - virtual void _validate_property(PropertyInfo &property) const override; - static void _bind_methods(); - -public: - virtual int get_output_sequence_port_count() const override; - virtual bool has_input_sequence_port() const override; - - virtual String get_output_sequence_port_text(int p_port) const override; - - virtual int get_input_value_port_count() const override; - virtual int get_output_value_port_count() const override; - - virtual PropertyInfo get_input_value_port_info(int p_idx) const override; - virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - - virtual String get_caption() const override; - virtual String get_category() const override { return "data"; } - - void set_variable(StringName p_variable); - StringName get_variable() const; - - virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; - - VisualScriptVariableSet(); -}; - class VisualScriptConstant : public VisualScriptNode { GDCLASS(VisualScriptConstant, VisualScriptNode);