Hi,
I know how to add properties to objects, but I am having some problems to add them to a tile in a tileset. For instance, I want to add a int property called surfaceTypeId.
// Register a new action called "TemplateAction"
let surfaceTypeAction = tiled.registerAction("surfaceTypeAction", function(action)
{
let tilemap = tiled.activeAsset;
// Ensure there's a valid tilemap
if (!tilemap) {
tiled.alert("No active tilemap found.");
return;
}
const selectedTiles = tiled.tilesetEditor?.currentTiles;
if (!selectedTiles || selectedTiles.length === 0) {
tiled.alert("No tiles selected in the Tileset Editor.");
return;
}
else
{
selectedTiles.forEach(tile =>
{
// Check if the "imagePath" property exists by trying to get its value
let surfaceTypeId = tile.property("surfaceTypeId");
if (surfaceTypeId === undefined)
{
let id = parseInt(0); // Ensure the value is treated as an int
tile.setProperty("surfaceTypeId", id);
}
else
{
tiled.alert("entityType already exists");
}
});
}
});
surfaceTypeAction.text = "add surfaceType attr"; // Display name in the menu
tiled.extendMenu("Edit", [
{ action: "surfaceTypeAction", before: "MapProperties" }
]);
The problem is that it keeps triggering “No tiles selected in the Tileset Editor.” even if I have them selected. I guess I am mixing up the tileset selection and the main editor selection?
I am not sure how to solve it.
Thx