Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove VisualScriptVariableGet VisualScriptVariableSet #55152

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions modules/visual_script/doc_classes/VisualScriptVariableGet.xml

This file was deleted.

21 changes: 0 additions & 21 deletions modules/visual_script/doc_classes/VisualScriptVariableSet.xml

This file was deleted.

2 changes: 0 additions & 2 deletions modules/visual_script/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 19 additions & 16 deletions modules/visual_script/visual_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> ids;
get_node_list(&ids);
for (int &E : ids) {
Ref<VisualScriptVariableGet> nodeget = get_node(E);
if (nodeget.is_valid()) {
if (nodeget->get_variable() == p_name) {
nodeget->set_variable(p_new_name);
}
} else {
Ref<VisualScriptVariableSet> 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<VisualScriptVariableGet> nodeget = get_node(E);
// if (nodeget.is_valid()) {
// if (nodeget->get_variable() == p_name) {
// nodeget->set_variable(p_new_name);
// }
// } else {
// Ref<VisualScriptVariableSet> 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) {
Expand Down
224 changes: 0 additions & 224 deletions modules/visual_script/visual_script_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VisualScript> vs = get_visual_script();
List<StringName> 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<VisualScript> vs = get_visual_script();
List<StringName> 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//////////////////
//////////////////////////////////////////
Expand Down Expand Up @@ -3974,8 +3752,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>);
VisualScriptLanguage::singleton->add_register_func("data/scene_node", create_node_generic<VisualScriptSceneNode>);
VisualScriptLanguage::singleton->add_register_func("data/scene_tree", create_node_generic<VisualScriptSceneTree>);
Expand Down
Loading