-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFlipTilesInBrush.js
71 lines (57 loc) · 2.25 KB
/
FlipTilesInBrush.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Adds actions to the Edit menu to flip tiles in the current brush
horizontally or vertically, while keeping their position.\
Useful mainly in combination with Tiled's built-in brush flipping to flip
large arrangements of tiles without flipping each tile in them, but it's
useful for automapping and such too.
*/
var flipBrushHorizontally = tiled.registerAction("FlipTilesHorizontally", function(action) {
var brush = tiled.mapEditor.currentBrush;
if(brush && brush.size && brush.size.width > 0 && brush.size.height > 0) {
var numLayers = brush.layerCount;
for(var layerID = 0; layerID < numLayers; layerID++) {
var curLayer = brush.layerAt(layerID);
var curEdit = curLayer.edit();
if(curLayer.isTileLayer && curLayer.visible) {
for(var x = 0; x < curLayer.size.width; x++) {
for(var y = 0; y < curLayer.size.height; y++) {
var cell = curLayer.cellAt(x, y);
if(cell && cell.tileId > -1) {
curEdit.setTile(x, y, curLayer.tileAt(x, y), curLayer.flagsAt(x, y) ^ Tile.FlippedHorizontally);
}
}
}
curEdit.apply();
}
}
}
tiled.mapEditor.currentBrush = brush;
});
flipBrushHorizontally.text = "Flip Brush Tiles Horizontally";
var flipBrushVertically = tiled.registerAction("FlipTilesVertically", function(action) {
var brush = tiled.mapEditor.currentBrush;
if(brush && brush.size && brush.size.width > 0 && brush.size.height > 0) {
var numLayers = brush.layerCount;
for(var layerID = 0; layerID < numLayers; layerID++) {
var curLayer = brush.layerAt(layerID);
var curEdit = curLayer.edit();
if(curLayer.isTileLayer && curLayer.visible) {
for(var x = 0; x < curLayer.size.width; x++) {
for(var y = 0; y < curLayer.size.height; y++) {
var cell = curLayer.cellAt(x, y);
if(cell && cell.tileId > -1) {
curEdit.setTile(x, y, curLayer.tileAt(x, y), curLayer.flagsAt(x, y) ^ Tile.FlippedVertically);
}
}
}
curEdit.apply();
}
}
}
tiled.mapEditor.currentBrush = brush;
});
flipBrushVertically.text = "Flip Brush Tiles Vertically";
tiled.extendMenu("Edit", [
{ action: "FlipTilesHorizontally", before: "Preferences" },
{ action: "FlipTilesVertically" },
{ separator: true }
]);