Class LineTools
java.lang.Object
com.github.yellowstonegames.grid.LineTools
Tools for constructing patterns using box-drawing characters in grids.
This can be useful in both text-based games and graphical ones, where graphical games would use a single box-drawing
character, like any of
The rest of this class is some sort of mad science experiment, meant for procedurally generating decorations in some area (like a circle, square, diamond, shield-shape...). Methods like
"╴╵┘╶─└┴╷┐│┤┌┬├┼" to determine which wall graphic to draw at a position. The methods
hashesToLines(char[][]) and pruneLines(char[][], Region, char[][]) are especially commonly-used.
The first creates a map that uses box-drawing characters from a "bare" map that represents walls with '#';
there is a variant that fills an existing 2D char array with the box-drawing character map (instead of creating a new
2D array). The second is meant to be used in tandem with FOV to limit the set of small lines in each
box-drawing character to those matching walls a viewer can see. It may be better to use VisionFramework for
handling vision and lighting, because it calls pruneLines() automatically and keeps its parameters up-to-date.
The rest of this class is some sort of mad science experiment, meant for procedurally generating decorations in some area (like a circle, square, diamond, shield-shape...). Methods like
encode4x4(char[][]),
decode4x4(long), rotateClockwise(long), flipHorizontal4x4(long), and so on are probably
not widely useful, but if you find a good use for them (or have a feature request to make them better), an issue on
the SquidSquad repo would be a good place to mention it.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final char[]static final char[]static final char[]static final char[]static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final char[]static final char[]static final char[]static final char[]static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.static final longA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. -
Method Summary
Modifier and TypeMethodDescriptionstatic char[][]decode4x4(long encoded) Produces a 4x4 2D char array by interpreting the bits of the given long as line information.static char[][]decode4x4(long encoded, char[] symbols) Produces a 4x4 2D char array by interpreting the bits of the given long as line information.static char[][]decodeInto4x4(long encoded, char[] symbols, char[][] into, int startX, int startY) Fills a 4x4 area of the given 2D char arrayintoby interpreting the bits of the given long as line information.static longencode4x4(char[][] decoded) Reads a 2D char arraydecoded, which must be at least 4x4 in size, and returns a long that encodes the cells from 0,0 to 3,3 in a way that this class can interpret and manipulate.static longflipHorizontal4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the left side is flipped to the right side and vice versa.static longflipVertical4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the top side is flipped to the bottom side and vice versa.static char[][]hashesToLines(char[][] map) Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '.static char[][]hashesToLines(char[][] map, boolean keepSingleHashes) Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '.static char[][]hashesToLinesInto(char[][] source, char[][] target, boolean keepSingleHashes) Takes a char[][] placesourcethat uses '#' to represent walls, and fills a different char[][]targetwith Unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '.static char[][]linesToHashes(char[][] map) Reverses most of the effects of hashesToLines() that may have been applied tomapand returns the result in a new char[][].static char[][]linesToHashesInto(char[][] source, char[][] target) Reverses most of the effects of hashesToLinesInto() that may have been applied tosourceand stores the result intarget.static char[][]pruneLines(char[][] map, Region seen, char[][] writeInto) Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered.static char[][]pruneLines(char[][] map, Region seen, char[] symbols, char[][] writeInto) Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered.static longrotateClockwise(long encoded) Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees clockwise, changing their positions as well as what chars they will decode to.static longrotateCounterclockwise(long encoded) Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees counterclockwise, changing their positions as well as what chars they will decode to.static longtranspose4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the x and y axes are interchanged, making the top side become the left side and vice versa, while the bottom side becomes the right side and vice versa.static char[][]transposeLines(char[][] map) If you call hashesToLines() on a map that uses [y][x] conventions instead of [x][y], it will have the lines not connect as you expect.static char[][]transposeLinesInPlace(char[][] changing) If you call hashesToLines() on a map that uses [y][x] conventions instead of [x][y], it will have the lines not connect as you expect.
-
Field Details
-
lightA0
public static final char[] lightA0 -
lightAlt
public static final char[] lightAlt -
heavyA0
public static final char[] heavyA0 -
heavyAlt
public static final char[] heavyAlt -
light0
public static final char[] light0 -
light
public static final char[] light -
heavy0
public static final char[] heavy0 -
heavy
public static final char[] heavy -
interiorSquare
public static final long interiorSquareA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorSquare
public static final long exteriorSquareA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
interiorPlus
public static final long interiorPlusA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorPlus
public static final long exteriorPlusA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
interiorSquareLarge
public static final long interiorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorSquareLarge
public static final long exteriorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
shallowInteriorSquareLarge
public static final long shallowInteriorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
shallowExteriorSquareLarge
public static final long shallowExteriorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
shallowerInteriorSquareLarge
public static final long shallowerInteriorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
shallowerExteriorSquareLarge
public static final long shallowerExteriorSquareLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
interiorPlusLarge
public static final long interiorPlusLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorPlusLarge
public static final long exteriorPlusLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
interiorCircleLarge
public static final long interiorCircleLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorCircleLarge
public static final long exteriorCircleLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
interiorDiamondLarge
public static final long interiorDiamondLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
exteriorDiamondLarge
public static final long exteriorDiamondLargeA constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as withLineTools.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can useexteriorSquareand bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
}- See Also:
-
-
Method Details
-
decode4x4
public static char[][] decode4x4(long encoded) Produces a 4x4 2D char array by interpreting the bits of the given long as line information. Uses the box drawing chars fromlight, which are compatible with most fonts.- Parameters:
encoded- a long, which can be random, that encodes some pattern of (typically box drawing) characters- Returns:
- a 4x4 2D char array containing elements from symbols assigned based on encoded
-
decode4x4
public static char[][] decode4x4(long encoded, char[] symbols) Produces a 4x4 2D char array by interpreting the bits of the given long as line information. Uses the given char array, which must have at least 16 elements and is usually one oflight,heavy,lightAlt, orheavyAlt, with the last two usable only if using a font that supports the chars╴╵╶╷(this is true for Iosevka and Source Code Pro, for instance, but not Inconsolata or GoMono).- Parameters:
encoded- a long, which can be random, that encodes some pattern of (typically box drawing) characterssymbols- a 16-element-or-larger char array; usually a constant in this class likelight- Returns:
- a 4x4 2D char array containing elements from symbols assigned based on encoded
-
decodeInto4x4
public static char[][] decodeInto4x4(long encoded, char[] symbols, char[][] into, int startX, int startY) Fills a 4x4 area of the given 2D char arrayintoby interpreting the bits of the given long as line information. Uses the given char arraysymbols, which must have at least 16 elements and is usually one oflight,heavy,lightAlt, orheavyAlt, with the last two usable only if using a font that supports the chars╴╵╶╷(this is true for Iosevka and Source Code Pro, for instance, but not Inconsolata or GoMono).- Parameters:
encoded- a long, which can be random, that encodes some pattern of (typically box drawing) characterssymbols- a 16-element-or-larger char array; usually a constant in this class likelightinto- a 2D char array that will be modified in a 4x4 areastartX- the first x position to modify in intostartY- the first y position to modify in into- Returns:
- into, after modification
-
encode4x4
public static long encode4x4(char[][] decoded) Reads a 2D char arraydecoded, which must be at least 4x4 in size, and returns a long that encodes the cells from 0,0 to 3,3 in a way that this class can interpret and manipulate. The 2D arraydecodedmust contain box drawing symbols, which can be any of those fromlight,heavy,lightAlt, orheavyAlt. Valid chars are╴╵┘╶─└┴╷┐│┤┌┬├┼╸╹┛╺━┗┻╻┓┃┫┏┳┣╋; any other chars will be treated as empty space.- Parameters:
decoded- a 2D char array that must be at least 4x4 and should usually contain box drawing characters- Returns:
- a long that encodes the box drawing information in decoded so this class can manipulate it
-
flipHorizontal4x4
public static long flipHorizontal4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the left side is flipped to the right side and vice versa.- Parameters:
encoded- an encoded pattern long that represents a 4x4 area- Returns:
- a different encoded pattern long that represents the argument flipped left-to-right
-
flipVertical4x4
public static long flipVertical4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the top side is flipped to the bottom side and vice versa.- Parameters:
encoded- an encoded pattern long that represents a 4x4 area- Returns:
- a different encoded pattern long that represents the argument flipped top-to-bottom
-
transpose4x4
public static long transpose4x4(long encoded) Makes a variant on the given encoded 4x4 pattern so the x and y axes are interchanged, making the top side become the left side and vice versa, while the bottom side becomes the right side and vice versa.- Parameters:
encoded- an encoded pattern long that represents a 4x4 area- Returns:
- a different encoded pattern long that represents the argument transposed top-to-left and bottom-to-right
-
rotateClockwise
public static long rotateClockwise(long encoded) Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees clockwise, changing their positions as well as what chars they will decode to. This can be called twice to get a 180 degree rotation, butrotateCounterclockwise(long)should be used for a 270 degree rotation.- Parameters:
encoded- an encoded pattern long that represents a 4x4 area- Returns:
- a different encoded pattern long that represents the argument rotated 90 degrees clockwise
-
rotateCounterclockwise
public static long rotateCounterclockwise(long encoded) Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees counterclockwise, changing their positions as well as what chars they will decode to. This can be called twice to get a 180 degree rotation, butrotateClockwise(long)should be used for a 270 degree rotation.- Parameters:
encoded- an encoded pattern long that represents a 4x4 area- Returns:
- a different encoded pattern long that represents the argument rotated 90 degrees counterclockwise
-
pruneLines
Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered. Takes a map that was produced usinghashesToLines(char[][])and a Region that stores already-seen cells, and writes an altered version of the 2D char arraymaptowriteInto, leaving non-box-drawing chars unchanged. This method modifies writeInto in-place, and also returns it after those changesare made. The way this works is explained well with an example: if the player is north of a T-junction wall, '┬', then unless he has already explored the area south of his position, the bottom segment of the wall isn't visible to him, and so '─' should be rendered instead of '┬'. If a cell has already been seen, it is considered still visible for the purpose of calculating shown segments (it won't change once you leave an area).- Parameters:
map- a 2D char array that should have been produced byhashesToLines(char[][])seen- a Region where "on" cells are visible now or were visible in the pastwriteInto- a 2D char array that must have at least the dimensions of map; will be modified- Returns:
- writeInto, after modifications
-
pruneLines
Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered. Takes a map that was produced usinghashesToLines(char[][])a Region that stores already-seen cells, an optional char array that refers to a line drawing style constant in this class (defaults tolight, and writes an altered version of the 2D char arraymaptowriteInto, leaving non-box-drawing chars unchanged. This method modifies writeInto in-place, and also returns it after those changes are made. The way this works is explained well with an example: if the player is north of a T-junction wall, '┬', then unless he has already explored the area south of his position, the bottom segment of the wall isn't visible to him, and so '─' should be rendered instead of '┬'. If a cell has already been seen (it is true inseen), it is considered still visible for the purpose of calculating shown segments (that is, it won't change once you leave an area).- Parameters:
map- a 2D char array that should have been produced byhashesToLines(char[][])seen- a Region where "on" cells are visible now or were visible in the pastsymbols- a char array that should belightorheavyunless you know your font supports the chars "╴╵╶╷", in which case you can uselightAlt, or the heavy-weight versions of those chars, in which case you can useheavyAltwriteInto- a 2D char array that must have at least the dimensions of map; will be modified- Returns:
- writeInto, after modifications
-
hashesToLines
public static char[][] hashesToLines(char[][] map) Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '. If the lines "point the wrong way," such as having multiple horizontally adjacent vertical lines where there should be horizontal lines, call transposeLines() on the returned map, which will keep the dimensions of the map the same and only change the line chars. You will also need to call transposeLines if you call hashesToLines on a map that already has "correct" line-drawing characters, which means hashesToLines should only be called on maps that use '#' for walls. If you have a jumbled map that contains two or more of the following: "correct" line-drawing characters, "incorrect" line-drawing characters, and '#' characters for walls, you can reset by calling linesToHashes() and then potentially calling hashesToLines() again.
This also treats any '+' and '/' chars that are next to a cell this is changing as if they were walls, even though neither '+' nor '/' will be changed itself. This is because '+' and '/' are typically used as door glyphs, and since walls connect to doors, the box-drawing characters for adjacent walls should connect to the door as if it is or is embedded in a wall.- Parameters:
map- a 2D char array indexed with x,y that uses '#' for walls- Returns:
- a copy of the map passed as an argument with box-drawing characters replacing '#' walls
-
hashesToLines
public static char[][] hashesToLines(char[][] map, boolean keepSingleHashes) Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '. If keepSingleHashes is true, then '#' will be used if a wall has no orthogonal wall neighbors; if it is false, then a horizontal line will be used for stand-alone wall cells. If the lines "point the wrong way," such as having multiple horizontally adjacent vertical lines where there should be horizontal lines, calltransposeLines(char[][])on the returned map, which will keep the dimensions of the map the same and only change the line chars. You will also need to call transposeLines if you call hashesToLines on a map that already has "correct" line-drawing characters, which means hashesToLines should only be called on maps that use '#' for walls. If you have a jumbled map that contains two or more of the following: "correct" line-drawing characters, "incorrect" line-drawing characters, and '#' characters for walls, you can reset by calling linesToHashes() and then potentially calling hashesToLines() again.
This also treats any '+' and '/' chars that are next to a cell this is changing as if they were walls, even though neither '+' nor '/' will be changed itself. This is because '+' and '/' are typically used as door glyphs, and since walls connect to doors, the box-drawing characters for adjacent walls should connect to the door as if it is or is embedded in a wall.- Parameters:
map- a 2D char array indexed with x,y that uses '#' for wallskeepSingleHashes- true if walls that are not orthogonally adjacent to other walls should stay as '#'- Returns:
- a copy of the map passed as an argument with box-drawing characters replacing '#' walls
-
hashesToLinesInto
public static char[][] hashesToLinesInto(char[][] source, char[][] target, boolean keepSingleHashes) Takes a char[][] placesourcethat uses '#' to represent walls, and fills a different char[][]targetwith Unicode box drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were filled with more walls before) with space characters, ' '. If keepSingleHashes is true, then '#' will be used if a wall has no orthogonal wall neighbors; if it is false, then a horizontal line will be used for stand-alone wall cells. If the lines "point the wrong way," such as having multiple horizontally adjacent vertical lines where there should be horizontal lines, calltransposeLines(char[][])on the returned map, which will keep the dimensions of the map the same and only change the line chars. You will also need to call transposeLines if you call hashesToLinesInto() on a map that already has "correct" line-drawing characters, which means hashesToLinesInto() should only be called on maps that use '#' for walls. If you have a jumbled map that contains two or more of the following: "correct" line-drawing characters, "incorrect" line-drawing characters, and '#' characters for walls, you can reset by calling linesToHashes() and then potentially calling hashesToLinesInto() again.
This also treats any '+' and '/' chars that are next to a cell this is changing as if they were walls, even though neither '+' nor '/' will be changed itself. This is because '+' and '/' are typically used as door glyphs, and since walls connect to doors, the box-drawing characters for adjacent walls should connect to the door as if it is or is embedded in a wall.- Parameters:
source- a 2D char array indexed with x,y that uses '#' for wallstarget- a 2D char array that will be entirely modified in-place; if null, a new array will be madekeepSingleHashes- true if walls that are not orthogonally adjacent to other walls should stay as '#'- Returns:
- into, with box-drawing characters replacing '#' walls
-
linesToHashes
public static char[][] linesToHashes(char[][] map) Reverses most of the effects of hashesToLines() that may have been applied tomapand returns the result in a new char[][]. The only things that will not be reversed are the placement of space characters in unreachable wall-cells-behind-wall-cells, which remain as spaces. This is useful if you have a modified map that contains wall characters of conflicting varieties, as described in hashesToLines().- Parameters:
map- a 2D char array indexed with x,y that uses box-drawing characters for walls- Returns:
- a copy of the map passed as an argument with '#' replacing box-drawing characters for walls
-
linesToHashesInto
public static char[][] linesToHashesInto(char[][] source, char[][] target) Reverses most of the effects of hashesToLinesInto() that may have been applied tosourceand stores the result intarget. The only things that will not be reversed are the placement of space characters in unreachable wall-cells-behind-wall-cells, which remain as spaces. This is useful if you have a modified map that contains wall characters of conflicting varieties, as described in hashesToLinesInto().- Parameters:
source- a 2D char array indexed with x,y that uses box-drawing characters for wallstarget- a 2D char array that will be entirely modified in-place; if null, a new array will be made- Returns:
- into, with '#' replacing box-drawing characters for walls
-
transposeLines
public static char[][] transposeLines(char[][] map) If you call hashesToLines() on a map that uses [y][x] conventions instead of [x][y], it will have the lines not connect as you expect. Use this function to change the directions of the box-drawing characters only, without altering the dimensions in any way. This returns a new char[][], instead of modifying the parameter in place. transposeLines is also needed if the lines in a map have become transposed when they were already correct; calling this method on an incorrectly transposed map will change the directions on all of its lines.
This method simply callstransposeLinesInPlace(char[][])on a copy ofmapmade withArrayTools.copy(char[][]). You may want to just use transposeLinesInPlace() if map is incorrect.- Parameters:
map- a 2D char array indexed with y,x that uses box-drawing characters for walls- Returns:
- a copy of map that uses box-drawing characters for walls that will be correct when indexed with x,y
-
transposeLinesInPlace
public static char[][] transposeLinesInPlace(char[][] changing) If you call hashesToLines() on a map that uses [y][x] conventions instead of [x][y], it will have the lines not connect as you expect. Use this function to change the directions of the box-drawing characters only, without altering the dimensions in any way. This modifies the parameterchangingin-place. Calling transposeLines() is also needed if the lines in a map have become transposed when they were already correct; calling this method on an incorrectly transposed map will change the directions on all of its lines.- Parameters:
changing- a 2D char array that will be modified in-place to use different box-drawing characters- Returns:
- changing, modified in-place to use x,y instead of y,x box-drawing characters
-