Skip to content

Commit

Permalink
Scripting: Fixed setting/getting nested object reference values
Browse files Browse the repository at this point in the history
When the object reference was nested in a custom class, it was not
getting converted between `EditableMapObject*` and `ObjectRef`.
  • Loading branch information
bjorn committed Jun 21, 2024
1 parent f3f359e commit fdce601
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Scripting: Made Tileset.margin and Tileset.tileSpacing writable
* Scripting: Restored compatibility for MapObject.polygon (#3845)
* Scripting: Fixed issues with editing properties after setting class values from script
* Scripting: Fixed setting/getting object reference values when nested as a class member
* TMX format: Embedded images are now also supported on tilesets and image layers
* JSON format: Fixed tile order when loading a tileset using the old format
* Godot 4 plugin: Added support for exporting objects (by Rick Yorgason, #3615)
Expand Down
16 changes: 15 additions & 1 deletion src/tiled/editableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,31 @@ QVariant EditableObject::toScript(const QVariant &value) const
}
}

if (type == propertyValueId()) {
auto propertyValue = value.value<PropertyValue>();
propertyValue.value = toScript(propertyValue.value);
return QVariant::fromValue(propertyValue);
}

return value;
}

QVariant EditableObject::fromScript(const QVariant &value) const
{
if (value.userType() == QMetaType::QVariantMap)
const int type = value.userType();

if (type == QMetaType::QVariantMap)
return fromScript(value.toMap());

if (auto editableMapObject = value.value<EditableMapObject*>())
return QVariant::fromValue(ObjectRef { editableMapObject->id() });

if (type == propertyValueId()) {
auto propertyValue = value.value<PropertyValue>();
propertyValue.value = fromScript(propertyValue.value);
return QVariant::fromValue(propertyValue);
}

return value;
}

Expand Down

0 comments on commit fdce601

Please sign in to comment.