Skip to content

Commit

Permalink
Added the ability to allow the developer to choose their own tileset …
Browse files Browse the repository at this point in the history
…prefix.
  • Loading branch information
unenergizer committed Jan 23, 2024
1 parent 7fcbbd8 commit 6c984ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
29 changes: 27 additions & 2 deletions autotile/src/main/java/com/forgestorm/autotile/AutoTiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public class AutoTiler {
@Setter
private BrushType brushType = BrushType.SINGLE;

/**
* Let the developer choose the tile prefix for their own tileset.
*/
@Getter
@Setter
private String prefixType4 = BitmaskingType.TYPE_4.getPrefix();
/**
* Let the developer choose the tile prefix for their own tileset.
*/
@Getter
@Setter
private String prefixType8 = BitmaskingType.TYPE_8.getPrefix();

public AutoTiler(TileGetterSetter tileGetterSetter) {
this.tileGetterSetter = tileGetterSetter;
this.bitmask4Bit = new Bitmask4Bit(this);
Expand All @@ -95,7 +108,7 @@ public AutoTiler(TileGetterSetter tileGetterSetter) {
*/
public boolean autoTile(String tileName, int x, int y) {
// Detect the type of bitmask tile we are working with.
BitmaskingType bitmaskingType = BitmaskingType.detectBitmaskingType(tileName);
BitmaskingType bitmaskingType = detectBitmaskingType(tileName);
if (bitmaskingType == null) return false; // Type not detected

// Strip the image id from the tile name. Good for tile comparisons.
Expand Down Expand Up @@ -222,7 +235,7 @@ private void initNeighborTileFix(int x, int y) {
String strippedNeighborName = stripImageId(neighborName);

// Detect bitmasking type for this tile
BitmaskingType bitmaskingType = BitmaskingType.detectBitmaskingType(strippedNeighborName);
BitmaskingType bitmaskingType = detectBitmaskingType(strippedNeighborName);
if (bitmaskingType == null) return; // Type not detected

// Apply bitmasking operations
Expand Down Expand Up @@ -273,4 +286,16 @@ int boolToInt(boolean b) {
public String stripImageId(String textureName) {
return textureName.replaceAll("\\d*$", "");
}

/**
* Detects if the supplied texture name is a wang tile.
*
* @param textureName The name of the texture to check.
* @return Returns the {@link BitmaskingType} if it is detected.
*/
private BitmaskingType detectBitmaskingType(String textureName) {
if (textureName.startsWith(prefixType4)) return BitmaskingType.TYPE_4;
if (textureName.startsWith(prefixType8)) return BitmaskingType.TYPE_8;
return null;
}
}
13 changes: 0 additions & 13 deletions autotile/src/main/java/com/forgestorm/autotile/BitmaskingType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,4 @@ public enum BitmaskingType {
* The default tile image ID used at the end of a texture name. This ID is used to initiate drawing of a wang tile.
*/
private final String defaultTileImageId;

/**
* Detects if the supplied texture name is a wang tile.
*
* @param textureName The name of the texture to check.
* @return Returns the {@link BitmaskingType} if it is detected.
*/
public static BitmaskingType detectBitmaskingType(String textureName) {
for (BitmaskingType BitmaskingType : values()) {
if (textureName.startsWith(BitmaskingType.getPrefix())) return BitmaskingType;
}
return null;
}
}

0 comments on commit 6c984ff

Please sign in to comment.