You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to write a custom property to a world file using asset.setProperty and asset.save() methods.
after doing so asset.property('propName') resolves with the correct value but it is ultimately not being written to the
actual .world file
i've attach a script to reproduce bug.
function findWorldOfMap(map) {
return tiled.worlds.find((world) => {
if (world.containsMap(map.fileName)) {
return world;
}
});
}
function onAssetAboutToBeSaved(asset) {
switch (asset.assetType) {
case AssetType.TileMap:
const world = findWorldOfMap(asset);
if (world) {
tiled.log(`world ${world.fileName}`);
// Define the new property
let newPropertyName = "foo";
let newPropertyValue = "bar";
world.setProperty(newPropertyName, newPropertyValue);
world.save();
}
break;
case AssetType.World:
tiled.log(`saved world ${asset.assetType}`);
const val = asset.property('foo')
tiled.log(`val ${val}`);
break;
}
}
// Register an event handler
tiled.assetAboutToBeSaved.connect(onAssetAboutToBeSaved);
the script finds the associated world asset and then attempts to write a property/value to it.
My environment:
MacOS - 14.3.1
Tiled - 1.11.0
The text was updated successfully, but these errors were encountered:
Minimal reproducible example, via the console:
Set a property on the first (and hopefully only) loaded world: tiled.worlds[0].setProperty("foo", "bar");
Verify the property exists on the world: JSON.stringify(tiled.worlds[0].properties())
World >Save World >(the world)
World > Unload World > (the world)
World > Load World... (the same world)
Check for the properties again, and they won't be there: JSON.stringify(tiled.worlds[0].properties())
I imagine this issue is due to Worlds having no way to view/edit custom properties via the GUI, so custom properties were overlooked in World::save() (in src/libtiled/world.cpp). But, since Worlds are Assets now, they do inherit that capability from Assets, and therefore probably should also write those properties out.
bjorn
added a commit
to bjorn/tiled-dev
that referenced
this issue
Sep 11, 2024
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.
Closesmapeditor#4025
Yeah, this was somewhat of an oversight when we decided to derive World from Object as part of #3859. I had even made a note of this in 08d39f9... Anyway, implemented in #4055 now. :)
I am attempting to write a custom property to a world file using asset.setProperty and asset.save() methods.
after doing so asset.property('propName') resolves with the correct value but it is ultimately not being written to the
actual .world file
i've attach a script to reproduce bug.
the script finds the associated world asset and then attempts to write a property/value to it.
My environment:
MacOS - 14.3.1
Tiled - 1.11.0
The text was updated successfully, but these errors were encountered: