mapeditor/tiled


Do you want to work on this issue?
You can request for a bounty in order to promote it!
custom properties are not being saved to world files. #4025
BertoGz posted onGitHub
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