Skip to content

Commit

Permalink
Fix built properties still using a slash delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
madmiraal committed May 1, 2021
1 parent 54d639e commit 206e091
Show file tree
Hide file tree
Showing 39 changed files with 674 additions and 584 deletions.
36 changes: 20 additions & 16 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ class AnimationTrackKeyEdit : public Object {
args.resize(p_value);
d_new["args"] = args;
change_notify_deserved = true;
} else if (name.begins_with("args/")) {
} else if (name.begins_with("args_")) {
Vector<Variant> args = d_old["args"];
int idx = name.get_slice("/", 1).to_int();
int idx = name.get_slicec('_', 1).to_int();
ERR_FAIL_INDEX_V(idx, args.size(), false);

String what = name.get_slice("/", 2);
String what = name.get_slicec('_', 2);
if (what == "type") {
Variant::Type t = Variant::Type(int(p_value));

Expand Down Expand Up @@ -444,11 +444,11 @@ class AnimationTrackKeyEdit : public Object {
return true;
}

if (name.begins_with("args/")) {
int idx = name.get_slice("/", 1).to_int();
if (name.begins_with("args_")) {
int idx = name.get_slicec('_', 1).to_int();
ERR_FAIL_INDEX_V(idx, args.size(), false);

String what = name.get_slice("/", 2);
String what = name.get_slicec('_', 2);
if (what == "type") {
r_ret = args[idx].get_type();
return true;
Expand Down Expand Up @@ -570,10 +570,12 @@ class AnimationTrackKeyEdit : public Object {
vtypes += Variant::get_type_name(Variant::Type(i));
}

p_list->push_back(PropertyInfo(Variant::NIL, "Args", PROPERTY_HINT_NONE, "args_", PROPERTY_USAGE_GROUP));
for (int i = 0; i < args.size(); i++) {
p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes));
p_list->push_back(PropertyInfo(Variant::NIL, itos(i), PROPERTY_HINT_NONE, "args_" + itos(i) + "_", PROPERTY_USAGE_SUBGROUP));
p_list->push_back(PropertyInfo(Variant::INT, "args_" + itos(i) + "_type", PROPERTY_HINT_ENUM, vtypes));
if (args[i].get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value"));
p_list->push_back(PropertyInfo(args[i].get_type(), "args_" + itos(i) + "_value"));
}
}

Expand Down Expand Up @@ -825,12 +827,12 @@ class AnimationMultiTrackKeyEdit : public Object {
args.resize(p_value);
d_new["args"] = args;
change_notify_deserved = true;
} else if (name.begins_with("args/")) {
} else if (name.begins_with("args_")) {
Vector<Variant> args = d_old["args"];
int idx = name.get_slice("/", 1).to_int();
int idx = name.get_slicec('_', 1).to_int();
ERR_FAIL_INDEX_V(idx, args.size(), false);

String what = name.get_slice("/", 2);
String what = name.get_slicec('_', 2);
if (what == "type") {
Variant::Type t = Variant::Type(int(p_value));

Expand Down Expand Up @@ -1044,11 +1046,11 @@ class AnimationMultiTrackKeyEdit : public Object {
return true;
}

if (name.begins_with("args/")) {
int idx = name.get_slice("/", 1).to_int();
if (name.begins_with("args_")) {
int idx = name.get_slicec('_', 1).to_int();
ERR_FAIL_INDEX_V(idx, args.size(), false);

String what = name.get_slice("/", 2);
String what = name.get_slicec('_', 2);
if (what == "type") {
r_ret = args[idx].get_type();
return true;
Expand Down Expand Up @@ -1213,10 +1215,12 @@ class AnimationMultiTrackKeyEdit : public Object {
vtypes += Variant::get_type_name(Variant::Type(i));
}

p_list->push_back(PropertyInfo(Variant::NIL, "Args", PROPERTY_HINT_NONE, "args_", PROPERTY_USAGE_GROUP));
for (int i = 0; i < args.size(); i++) {
p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes));
p_list->push_back(PropertyInfo(Variant::NIL, itos(i), PROPERTY_HINT_NONE, "args_" + itos(i) + "_", PROPERTY_USAGE_SUBGROUP));
p_list->push_back(PropertyInfo(Variant::INT, "args_" + itos(i) + "_type", PROPERTY_HINT_ENUM, vtypes));
if (args[i].get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value"));
p_list->push_back(PropertyInfo(args[i].get_type(), "args_" + itos(i) + "_value"));
}
}
} break;
Expand Down
36 changes: 19 additions & 17 deletions editor/array_property_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void ArrayPropertyEdit::_set_value(int p_idx, const Variant &p_value) {
bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) {
String pn = p_name;

if (pn.begins_with("array/")) {
if (pn == "array/size") {
if (pn.begins_with("array_")) {
if (pn == "array_size") {
Variant arr = get_array();
int size = arr.call("size");

Expand Down Expand Up @@ -114,16 +114,16 @@ bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) {
ur->commit_action();
return true;
}
if (pn == "array/page") {
if (pn == "array_page") {
page = p_value;
notify_property_list_changed();
return true;
}

} else if (pn.begins_with("indices")) {
if (pn.find("_") != -1) {
if (pn.ends_with("type")) {
//type
int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int();
int idx = pn.get_slicec('_', 1).to_int();

int type = p_value;

Expand All @@ -146,7 +146,7 @@ bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) {
return true;

} else {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
Variant arr = get_array();

Variant value = arr.get(idx);
Expand All @@ -168,19 +168,19 @@ bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const {
//int size = arr.call("size");

String pn = p_name;
if (pn.begins_with("array/")) {
if (pn == "array/size") {
if (pn.begins_with("array_")) {
if (pn == "array_size") {
r_ret = arr.call("size");
return true;
}
if (pn == "array/page") {
if (pn == "array_page") {
r_ret = page;
return true;
}
} else if (pn.begins_with("indices")) {
if (pn.find("_") != -1) {
if (pn.ends_with("type")) {
//type
int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int();
int idx = pn.get_slicec('_', 1).to_int();
bool valid;
r_ret = arr.get(idx, &valid);
if (valid) {
Expand All @@ -189,7 +189,7 @@ bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const {
return valid;

} else {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
bool valid;
r_ret = arr.get(idx, &valid);

Expand All @@ -208,31 +208,33 @@ void ArrayPropertyEdit::_get_property_list(List<PropertyInfo> *p_list) const {
Variant arr = get_array();
int size = arr.call("size");

p_list->push_back(PropertyInfo(Variant::INT, "array/size", PROPERTY_HINT_RANGE, "0,100000,1"));
p_list->push_back(PropertyInfo(Variant::NIL, "Array", PROPERTY_HINT_NONE, "array_", PROPERTY_USAGE_GROUP));
p_list->push_back(PropertyInfo(Variant::INT, "array_size", PROPERTY_HINT_RANGE, "0,100000,1"));
int pages = size / ITEMS_PER_PAGE;
if (pages > 0) {
p_list->push_back(PropertyInfo(Variant::INT, "array/page", PROPERTY_HINT_RANGE, "0," + itos(pages) + ",1"));
p_list->push_back(PropertyInfo(Variant::INT, "array_page", PROPERTY_HINT_RANGE, "0," + itos(pages) + ",1"));
}

int offset = page * ITEMS_PER_PAGE;

int items = MIN(size - offset, ITEMS_PER_PAGE);

p_list->push_back(PropertyInfo(Variant::NIL, "Indices", PROPERTY_HINT_NONE, "indices_", PROPERTY_USAGE_GROUP));
for (int i = 0; i < items; i++) {
Variant v = arr.get(i + offset);
bool is_typed = arr.get_type() != Variant::ARRAY || subtype != Variant::NIL;

if (!is_typed) {
p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset) + "_type", PROPERTY_HINT_ENUM, vtypes));
p_list->push_back(PropertyInfo(Variant::INT, "indices_" + itos(i + offset) + "_type", PROPERTY_HINT_ENUM, vtypes));
}

if (v.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(v)) {
p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset), PROPERTY_HINT_OBJECT_ID, "Object"));
p_list->push_back(PropertyInfo(Variant::INT, "indices_" + itos(i + offset), PROPERTY_HINT_OBJECT_ID, "Object"));
continue;
}

if (is_typed || v.get_type() != Variant::NIL) {
PropertyInfo pi(v.get_type(), "indices/" + itos(i + offset));
PropertyInfo pi(v.get_type(), "indices_" + itos(i + offset));
if (subtype != Variant::NIL) {
pi.type = Variant::Type(subtype);
pi.hint = PropertyHint(subtype_hint);
Expand Down
11 changes: 6 additions & 5 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ConnectDialogBinds : public Object {
bool _set(const StringName &p_name, const Variant &p_value) {
String name = p_name;

if (name.begins_with("bind/")) {
int which = name.get_slice("/", 1).to_int() - 1;
if (name.begins_with("bind_")) {
int which = name.get_slicec('_', 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
params.write[which] = p_value;
} else {
Expand All @@ -80,8 +80,8 @@ class ConnectDialogBinds : public Object {
bool _get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;

if (name.begins_with("bind/")) {
int which = name.get_slice("/", 1).to_int() - 1;
if (name.begins_with("bind_")) {
int which = name.get_slicec('_', 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
r_ret = params[which];
} else {
Expand All @@ -92,8 +92,9 @@ class ConnectDialogBinds : public Object {
}

void _get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::NIL, "Bind", PROPERTY_HINT_NONE, "bind_", PROPERTY_USAGE_GROUP));
for (int i = 0; i < params.size(); i++) {
p_list->push_back(PropertyInfo(params[i].get_type(), "bind/" + itos(i + 1)));
p_list->push_back(PropertyInfo(params[i].get_type(), "bind_" + itos(i + 1)));
}
}

Expand Down
18 changes: 9 additions & 9 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_
String pn = p_name;

if (pn.begins_with("indices")) {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
array.set(idx, p_value);
return true;
}
Expand All @@ -50,7 +50,7 @@ bool EditorPropertyArrayObject::_get(const StringName &p_name, Variant &r_ret) c
String pn = p_name;

if (pn.begins_with("indices")) {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
bool valid;
r_ret = array.get(idx, &valid);
if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) {
Expand Down Expand Up @@ -90,7 +90,7 @@ bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Varian
}

if (pn.begins_with("indices")) {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
Variant key = dict.get_key_at_index(idx);
dict[key] = p_value;
return true;
Expand All @@ -113,7 +113,7 @@ bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_r
}

if (pn.begins_with("indices")) {
int idx = pn.get_slicec('/', 1).to_int();
int idx = pn.get_slicec('_', 1).to_int();
Variant key = dict.get_key_at_index(idx);
r_ret = dict[key];
if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) {
Expand Down Expand Up @@ -157,7 +157,7 @@ EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() {

void EditorPropertyArray::_property_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing) {
if (p_property.begins_with("indices")) {
int idx = p_property.get_slice("/", 1).to_int();
int idx = p_property.get_slicec('_', 1).to_int();
Variant array = object->get_array();
array.set(idx, p_value);
emit_changed(get_edited_property(), array, "", true);
Expand Down Expand Up @@ -322,7 +322,7 @@ void EditorPropertyArray::update_property() {
object->set_array(array);

for (int i = 0; i < amount; i++) {
String prop_name = "indices/" + itos(i + offset);
String prop_name = "indices_" + itos(i + offset);

EditorProperty *prop = nullptr;
Variant value = array.get(i + offset);
Expand Down Expand Up @@ -554,7 +554,7 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint
int hint_subtype_separator = p_hint_string.find(":");
if (hint_subtype_separator >= 0) {
String subtype_string = p_hint_string.substr(0, hint_subtype_separator);
int slash_pos = subtype_string.find("/");
int slash_pos = subtype_string.find("_");
if (slash_pos >= 0) {
subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int());
subtype_string = subtype_string.substr(0, slash_pos);
Expand Down Expand Up @@ -615,7 +615,7 @@ void EditorPropertyDictionary::_property_changed(const String &p_property, Varia
} else if (p_property == "new_item_value") {
object->set_new_item_value(p_value);
} else if (p_property.begins_with("indices")) {
int idx = p_property.get_slice("/", 1).to_int();
int idx = p_property.get_slicec('_', 1).to_int();
Dictionary dict = object->get_dict();
Variant key = dict.get_key_at_index(idx);
dict[key] = p_value;
Expand Down Expand Up @@ -762,7 +762,7 @@ void EditorPropertyDictionary::update_property() {
Variant value;

if (i < amount) {
prop_name = "indices/" + itos(i + offset);
prop_name = "indices_" + itos(i + offset);
key = dict.get_key_at_index(i + offset);
value = dict.get_value_at_index(i + offset);
} else if (i == amount) {
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/font_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ void EditorInspectorPluginFont::parse_begin(Object *p_object) {
}

bool EditorInspectorPluginFont::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) {
if (p_path.begins_with("language_support_override/") && p_object->is_class("FontData")) {
String lang = p_path.replace("language_support_override/", "");
if (p_path.begins_with("language_support_override_") && p_object->is_class("FontData")) {
String lang = p_path.replace("language_support_override_", "");

FontDataEditor *editor = memnew(FontDataEditor);
if (lang != "_new") {
Expand All @@ -305,8 +305,8 @@ bool EditorInspectorPluginFont::parse_property(Object *p_object, Variant::Type p
return true;
}

if (p_path.begins_with("script_support_override/") && p_object->is_class("FontData")) {
String script = p_path.replace("script_support_override/", "");
if (p_path.begins_with("script_support_override_") && p_object->is_class("FontData")) {
String script = p_path.replace("script_support_override_", "");

FontDataEditor *editor = memnew(FontDataEditor);
if (script != "_new") {
Expand Down
11 changes: 6 additions & 5 deletions editor/plugins/item_list_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
int idx = name.get_slice("/", 0).to_int();
String what = name.get_slice("/", 1);
int idx = name.get_slicec('_', 0).to_int();
String what = name.get_slicec('_', 1);

if (what == "text") {
set_item_text(idx, p_value);
Expand Down Expand Up @@ -70,8 +70,8 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {

bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
int idx = name.get_slice("/", 0).to_int();
String what = name.get_slice("/", 1);
int idx = name.get_slicec('_', 0).to_int();
String what = name.get_slicec('_', 1);

if (what == "text") {
r_ret = get_item_text(idx);
Expand Down Expand Up @@ -101,7 +101,8 @@ bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {

void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
for (int i = 0; i < get_item_count(); i++) {
String base = itos(i) + "/";
String base = itos(i) + "_";
p_list->push_back(PropertyInfo(Variant::NIL, itos(i), PROPERTY_HINT_NONE, base, PROPERTY_USAGE_GROUP));

p_list->push_back(PropertyInfo(Variant::STRING, base + "text"));
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"));
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/ot_features_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ OpenTypeFeaturesEditor::OpenTypeFeaturesEditor() {
/*************************************************************************/

void OpenTypeFeaturesAdd::_add_feature(int p_option) {
get_edited_object()->set("opentype_features/" + TS->tag_to_name(p_option), 1);
get_edited_object()->set("opentype_features_" + TS->tag_to_name(p_option), 1);
}

void OpenTypeFeaturesAdd::update_property() {
Expand Down Expand Up @@ -192,7 +192,7 @@ void EditorInspectorPluginOpenTypeFeatures::parse_category(Object *p_object, con
}

bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) {
if (p_path == "opentype_features/_new") {
if (p_path == "opentype_features__new") {
OpenTypeFeaturesAdd *editor = memnew(OpenTypeFeaturesAdd);
add_property_editor(p_path, editor);
return true;
Expand Down
Loading

0 comments on commit 206e091

Please sign in to comment.