Skip to content

Commit 7fcbbd8

Browse files
committed
Added brush types.
1 parent 8dcc796 commit 7fcbbd8

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

autotile/src/main/java/com/forgestorm/autotile/AutoTiler.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public class AutoTiler {
7272
@Setter
7373
private boolean yUp = false;
7474

75+
/**
76+
* The brush size for the auto tile.
77+
*/
78+
@Getter
79+
@Setter
80+
private BrushType brushType = BrushType.SINGLE;
81+
7582
public AutoTiler(TileGetterSetter tileGetterSetter) {
7683
this.tileGetterSetter = tileGetterSetter;
7784
this.bitmask4Bit = new Bitmask4Bit(this);
@@ -94,6 +101,21 @@ public boolean autoTile(String tileName, int x, int y) {
94101
// Strip the image id from the tile name. Good for tile comparisons.
95102
String strippedTileName = stripImageId(tileName);
96103

104+
// Set each tile for the brush.
105+
for (BrushType.BrushTileInfo brushTileInfo : brushType.getBrushTileInfo()) {
106+
tileGetterSetter.setTile(strippedTileName + brushTileInfo.getTileId(), x + brushTileInfo.getAddX(), y + brushTileInfo.getAddY());
107+
}
108+
109+
// Now auto tile around these tiles
110+
for (BrushType.BrushTileInfo brushTileInfo : brushType.getBrushTileInfo()) {
111+
performAutoTile(bitmaskingType, strippedTileName, x + brushTileInfo.getAddX(), y + brushTileInfo.getAddY());
112+
}
113+
114+
return true;
115+
}
116+
117+
private void performAutoTile(BitmaskingType bitmaskingType, String strippedTileName, int x, int y) {
118+
97119
// If enabled, prepare neighbor tiles fix.
98120
prepareNeighborTilesFix(strippedTileName, x, y);
99121

@@ -106,8 +128,6 @@ public boolean autoTile(String tileName, int x, int y) {
106128

107129
// If enabled, do neighbor tiles fix.
108130
initNeighborTileFix(x, y);
109-
110-
return true;
111131
}
112132

113133
/**
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.forgestorm.autotile;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@Getter
7+
@AllArgsConstructor
8+
public enum BrushType {
9+
SINGLE(1,
10+
new BrushTileInfo[]{
11+
new BrushTileInfo(0, 0, 0) // Single
12+
}
13+
),
14+
DOUBLE(4,
15+
new BrushTileInfo[]{
16+
// Column 1
17+
new BrushTileInfo(0, 1, 22), // Top Left
18+
new BrushTileInfo(0, 0, 208), // Bottom Left
19+
20+
// Column 2
21+
new BrushTileInfo(1, 1, 11), // Top Right
22+
new BrushTileInfo(1, 0, 104) // Bottom Right
23+
}
24+
),
25+
TRIPLE(6,
26+
new BrushTileInfo[]{
27+
// Column 1
28+
new BrushTileInfo(0, 2, 22), // Left Top
29+
new BrushTileInfo(0, 1, 214), // Left Middle
30+
new BrushTileInfo(0, 0, 208), // Left Bottom
31+
32+
// Column 2
33+
new BrushTileInfo(1, 2, 31), // Middle Top
34+
new BrushTileInfo(1, 1, 255), // Center
35+
new BrushTileInfo(1, 0, 248), // Middle Bottom
36+
37+
// Column 3
38+
new BrushTileInfo(2, 2, 11), // Right Top
39+
new BrushTileInfo(2, 1, 107), // Right Middle
40+
new BrushTileInfo(2, 0, 104) // Right Bottom
41+
}
42+
);
43+
44+
/**
45+
* The number of tiles to be placed for this brush size.
46+
*/
47+
private final int tileCount;
48+
/**
49+
* Contains information needed to place tiles for the specified brush size.
50+
*/
51+
private final BrushTileInfo[] brushTileInfo;
52+
53+
/**
54+
* This contains information about the tile and location of a brush.
55+
*/
56+
@Getter
57+
@AllArgsConstructor
58+
static class BrushTileInfo {
59+
/**
60+
* The value that needs to be added to the X & Y axis in order to place this tile.
61+
*/
62+
private int addX, addY;
63+
/**
64+
* The ID of the tile that needs to be placed for this brush.
65+
*/
66+
private int tileId;
67+
}
68+
}

0 commit comments

Comments
 (0)