Skip to content

Commit

Permalink
Fix Object encoded as id in dictionnaries to be represented as int in…
Browse files Browse the repository at this point in the history
… the inspector.
  • Loading branch information
ajreckof committed Jul 22, 2024
1 parent e25f3c0 commit f46e94d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Varian
}

bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_ret) const {
if (!get_by_property_name(p_name, r_ret)) {
return false;
}
if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) {
r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id();
}
return true;
}

bool EditorPropertyDictionaryObject::get_by_property_name(const String &p_name, Variant &r_ret) const {
String name = p_name;

if (name == "new_item_key") {
Expand All @@ -140,10 +150,6 @@ bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_r
int index = name.get_slicec('/', 1).to_int();
Variant key = dict.get_key_at_index(index);
r_ret = dict[key];
if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) {
r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id();
}

return true;
}

Expand Down Expand Up @@ -1050,7 +1056,8 @@ void EditorPropertyDictionary::update_property() {
if (!slot_visible) {
continue;
}
Variant value = object->get(slot.prop_name);
Variant value;
object->get_by_property_name(slot.prop_name, value);
Variant::Type value_type = value.get_type();

// Check if the editor property needs to be updated.
Expand Down
1 change: 1 addition & 0 deletions editor/editor_properties_array_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class EditorPropertyDictionaryObject : public RefCounted {
NEW_VALUE_INDEX,
};

bool get_by_property_name(const String &p_name, Variant &r_ret) const;
void set_dict(const Dictionary &p_dict);
Dictionary get_dict();

Expand Down

0 comments on commit f46e94d

Please sign in to comment.