Skip to content

Commit

Permalink
Merge pull request #42170 from Razoric480/fix-vscript-value-by-type-32
Browse files Browse the repository at this point in the history
Add a VScript func to sanitize variant values (3.2)
  • Loading branch information
akien-mga authored Sep 23, 2020
2 parents 79f1502 + d35ced0 commit 26512dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions modules/visual_script/visual_script_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ void VisualScriptEditor::_update_members() {
TreeItem *ti = members->create_item(variables);

ti->set_text(0, E->get());
Variant var = script->get_variable_default_value(E->get());
ti->set_suffix(0, "= " + String(var));

ti->set_suffix(0, "= " + _sanitized_variant_text(E->get()));
ti->set_icon(0, type_icons[script->get_variable_info(E->get()).type]);

ti->set_selectable(0, true);
Expand Down Expand Up @@ -1032,6 +1032,18 @@ void VisualScriptEditor::_update_members() {
updating_members = false;
}

String VisualScriptEditor::_sanitized_variant_text(const StringName &property_name) {
Variant var = script->get_variable_default_value(property_name);

if (script->get_variable_info(property_name).type != Variant::NIL) {
Variant::CallError ce;
const Variant *converted = &var;
var = Variant::construct(script->get_variable_info(property_name).type, &converted, 1, ce, false);
}

return String(var);
}

void VisualScriptEditor::_member_selected() {

if (updating_members)
Expand Down
1 change: 1 addition & 0 deletions modules/visual_script/visual_script_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class VisualScriptEditor : public ScriptEditorBase {
bool updating_members;

void _update_members();
String _sanitized_variant_text(const StringName &property_name);

StringName selected;

Expand Down

0 comments on commit 26512dd

Please sign in to comment.