Adding plugins
This commit is contained in:
parent
bafdaacfb9
commit
125d264454
3 changed files with 114 additions and 1 deletions
31
random-tile-placer.js
Normal file
31
random-tile-placer.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
tiled.registerTool("RandomTilePlacer", {
|
||||
name: "Random Tile Placer",
|
||||
|
||||
mousePressed: function (button, x, y, modifiers) {
|
||||
if (button !== 1) return;
|
||||
|
||||
var map = tiled.activeAsset;
|
||||
if (!map || !map.isTileMap) return;
|
||||
|
||||
var layer = map.currentLayer;
|
||||
if (!layer || !layer.isTileLayer) {
|
||||
tiled.warn("Select a tile layer first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedTiles = tiled.mapEditor.tilesetsView.selectedTiles;
|
||||
if (!selectedTiles || selectedTiles.length === 0) {
|
||||
tiled.warn("Select some tiles in the Tilesets panel first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tile = selectedTiles[Math.floor(Math.random() * selectedTiles.length)];
|
||||
|
||||
var tileX = Math.floor(x / map.tileWidth);
|
||||
var tileY = Math.floor(y / map.tileHeight);
|
||||
|
||||
var edit = layer.edit();
|
||||
edit.setTile(tileX, tileY, tile);
|
||||
edit.apply();
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue