Skip to content

Commit

Permalink
TMX format: Include propertytype attribute for class members
Browse files Browse the repository at this point in the history
Previously, the custom type information was left out for class members,
because it was essentially redundant. Once we know the type of the
top-level property, the types of the members are known based on the
user-defined class.

However, since the type definitions are stored somewhere else in a
different format (the JSON Tiled project file), it can be very helpful
to include this information anyway.

This currently only affects the TMX format. The JSON and Lua formats
still do not store this information for class members, because it would
make them a lot less convenient to work with.

Closes #3230
  • Loading branch information
bjorn committed Jan 19, 2022
1 parent 33b186b commit 911d2ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/libtiled/mapwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,11 @@ void MapWriterPrivate::writeProperties(QXmlStreamWriter &w,
if (!exportValue.propertyTypeName.isEmpty())
w.writeAttribute(QStringLiteral("propertytype"), exportValue.propertyTypeName);

// For class property values, write out the original value, so that the
// propertytype attribute can also be written for their members where
// applicable.
if (exportValue.value.userType() == QMetaType::QVariantMap) {
writeProperties(w, exportValue.value.toMap());
writeProperties(w, it.value().value<PropertyValue>().value.toMap());
} else {
const QString value = exportValue.value.toString();

Expand Down
7 changes: 5 additions & 2 deletions src/libtiled/propertytype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ QVariant ClassPropertyType::toPropertyValue(const QVariant &value, const ExportC
it.next();

const QVariant classMember = members.value(it.key());
if (!classMember.isValid()) // ignore removed members
continue;
if (!classMember.isValid())
continue; // ignore removed members

if (it.value().userType() == classMember.userType())
continue; // leave members alone that already have the expected type

QVariant propertyValue = context.toPropertyValue(it.value(), classMember.userType());

Expand Down

0 comments on commit 911d2ef

Please sign in to comment.