Skip to content

Commit

Permalink
Implemented saving/loading of custom properties on worlds
Browse files Browse the repository at this point in the history
Custom properties on worlds can only be accessed and modified through
the scripting API at the moment, but since this is possible we better
also save them.

Closes #4025
  • Loading branch information
bjorn committed Sep 11, 2024
1 parent 694705b commit 1ec42df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Scripting: Added `FileFormat.nameFilter`
* Scripting: Added `MapEditor.currentBrushChanged` signal
* Scripting: Added `tiled.cursor` to create mouse cursor values
* Fixed saving/loading of custom properties set on worlds (#4025)
* Fixed crash when accessing a world through a symlink (#4042)
* Fixed error reporting when exporting on the command-line (by Shuhei Nagasawa, #4015)

Expand Down
9 changes: 9 additions & 0 deletions src/libtiled/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ std::unique_ptr<World> World::load(const QString &fileName,
world->patterns.append(pattern);
}

const QJsonArray properties = object.value(QLatin1String("properties")).toArray();
const ExportContext context(dir.path());
world->setProperties(propertiesFromJson(properties, context));

world->onlyShowAdjacentMaps = object.value(QLatin1String("onlyShowAdjacentMaps")).toBool();

if (world->maps.isEmpty() && world->patterns.isEmpty())
Expand Down Expand Up @@ -357,11 +361,16 @@ bool World::save(World &world, QString *errorString)
patterns.append(jsonPattern);
}

const ExportContext context(worldDir.path());
const QJsonArray properties = propertiesToJson(world.properties(), context);

QJsonObject document;
if (!maps.isEmpty())
document.insert(QLatin1String("maps"), maps);
if (!patterns.isEmpty())
document.insert(QLatin1String("patterns"), patterns);
if (!properties.isEmpty())
document.insert(QLatin1String("properties"), properties);
document.insert(QLatin1String("type"), QLatin1String("world"));
document.insert(QLatin1String("onlyShowAdjacentMaps"), world.onlyShowAdjacentMaps);

Expand Down

0 comments on commit 1ec42df

Please sign in to comment.