Add a terrain autotile kind for 6x4 sheets like TD Plains
Sheets such as "TD - Tileset - Plains" draw an autotile as a 6 x 4 block: a 3 x 3 nine-slice, a vertical and a horizontal strip and a single tile on the left, the inner corners on the right. The floor kind only knew the RPG Maker 2 x 3 layout, so these sheets could not be used as autotiles at all. - New TileKind "terrain" with 16 px tiles in a 6 x 4 block. All 47 neighbour combinations are resolved per quarter, so the renderer, the collision and the palette stay untouched. - Whole tiles are used where the sheet draws them: the 16 side cases, the four single notches and the two diagonal pairs. Hand-drawn strips and single blocks therefore look as drawn. - Only the missing cases are composed, for example an edge with a notch or two notches side by side. They take the side tile and put the notch quarters in. - A notch also takes the quarter above or below from its notch tile when fill would stand there. Tall cliff notches keep their wall. On ground and stones fill meets fill, so nothing changes there. - The label rule for floor and terrain now runs through one notch function. Floor still passes the MZ table test. Not touched: the tile board only refits on open and on Fit. Switching an open tile to a kind with another tile size leaves it small until Fit is pressed. That was the case before. Tests: - ./check.sh: 156 files, 2290 tests, CHECK EXIT 0 (before 2283). - e2e 39,40: ALL PASSED, 90 checks (before 86). 39j checks 47 tiles, pixels of single, notch, pair and composed tiles, and undo to floor. - Counter-checks: without whole notch and pair tiles one unit test and one e2e check fail. Without the taken quarter one of each fails. Originals restored by cmp and rebuilt. - Check sum: 1363 measured by CI plus 4 is 1367, computed only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
32cb5b4ba5
commit
c1a702bc39
6 files changed
+297
-28
No files matched your search
+95
-18
@@ -4,8 +4,9 @@ import type { QuadPos, TileKind } from './tile';
|
||||
* Which quarter goes into which corner of a drawn tile, given its neighbours – what makes a
|
||||
* hand-drawn edge continue across tile borders (#118). `floor` and `wall` are the two block shapes
|
||||
* the classic RPG-Maker sheets use: `floor` is 2 × 3 tiles and has inner corners, `wall` is 2 × 2
|
||||
* and has none. A plain tile (`none`, #131) goes through the same code and simply takes the same
|
||||
* four quarters whatever lies around it. Everything counts in quadrants, see `model/tile.ts`.
|
||||
* and has none. `terrain` is the 6 × 4 block of the common top-down sheets. A plain tile (`none`,
|
||||
* #131) goes through the same code and simply takes the same four quarters whatever lies around it.
|
||||
* Everything counts in quadrants, see `model/tile.ts`.
|
||||
*/
|
||||
|
||||
/** Which of the eight neighbouring cells hold the same tile. */
|
||||
@@ -75,16 +76,12 @@ const plainCorner = (position: QuadPos): CornerSpec => ({
|
||||
});
|
||||
const PLAIN_CORNERS: readonly CornerSpec[] = [at(0, 0), at(1, 0), at(0, 1), at(1, 1)].map(plainCorner);
|
||||
|
||||
const CORNERS: Record<TileKind, readonly CornerSpec[]> = {
|
||||
const CORNERS: Record<Exclude<TileKind, 'terrain'>, readonly CornerSpec[]> = {
|
||||
none: PLAIN_CORNERS,
|
||||
floor: FLOOR_CORNERS,
|
||||
wall: WALL_CORNERS,
|
||||
};
|
||||
|
||||
function cornersOf(kind: TileKind): readonly CornerSpec[] {
|
||||
return CORNERS[kind];
|
||||
}
|
||||
|
||||
/**
|
||||
* `sideH` is the neighbour left or right of the tile, `sideV` the one above or below, `diagonal`
|
||||
* the one between them. Without notches a diagonal says nothing, so a wall ignores it.
|
||||
@@ -96,9 +93,94 @@ function quadrantFor(spec: CornerSpec, sideH: boolean, sideV: boolean, diagonal:
|
||||
return spec.corner;
|
||||
}
|
||||
|
||||
/** The four quarters of the whole tile at tile column `tx`, row `ty` of the block. */
|
||||
const wholeTile = (tx: number, ty: number): TileQuadrants => [
|
||||
at(2 * tx, 2 * ty),
|
||||
at(2 * tx + 1, 2 * ty),
|
||||
at(2 * tx, 2 * ty + 1),
|
||||
at(2 * tx + 1, 2 * ty + 1),
|
||||
];
|
||||
|
||||
/**
|
||||
* The terrain block, 6 × 4 tiles: a bordered 3 × 3 in columns 1–3, a vertical strip in column 0, a
|
||||
* horizontal strip and the lone tile in row 3 – together one tile for each of the 16 ways the four
|
||||
* sides can join. East and west pick the column, north and south the row, and where neither of a
|
||||
* pair is there it is the strip's column or row.
|
||||
*/
|
||||
function terrainSides(around: Neighbours): TileQuadrants {
|
||||
const column = around.e ? (around.w ? 2 : 1) : around.w ? 3 : 0;
|
||||
const row = around.s ? (around.n ? 1 : 0) : around.n ? 2 : 3;
|
||||
return wholeTile(column, row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns 4–5 hold the notches: the 2 × 2 on top is a hole seen from its four sides, so each of its
|
||||
* tiles has one notch, in reading order of the corners, and row 2 the two diagonal pairs.
|
||||
*/
|
||||
const TERRAIN_NOTCH_TILES: readonly TileQuadrants[] = [
|
||||
wholeTile(5, 1),
|
||||
wholeTile(4, 1),
|
||||
wholeTile(5, 0),
|
||||
wholeTile(4, 0),
|
||||
];
|
||||
const TERRAIN_PAIRS = { tlbr: wholeTile(4, 2), trbl: wholeTile(5, 2) };
|
||||
|
||||
/** The corner above or below, which shares the notch tile's half column. */
|
||||
const VERTICAL_PARTNER = [2, 3, 0, 1];
|
||||
|
||||
/**
|
||||
* A terrain tile is taken whole wherever the sheet draws it – so a strip or a lone rock looks the
|
||||
* way it was drawn – and composed only for what the sheet leaves out, an edge with a notch or
|
||||
* notches next to each other: the tile of its sides, with the notch quarters put in. A notch brings
|
||||
* the quarter above or below it along when that quarter would be plain inside, because a cliff's
|
||||
* notch reaches over the crossing into it; on flat ground that quarter is inside too and changes
|
||||
* nothing.
|
||||
*/
|
||||
function terrainQuadrants(around: Neighbours): TileQuadrants {
|
||||
const sides = terrainSides(around);
|
||||
const notched = notchedCorners(around);
|
||||
const count = notched.filter(Boolean).length;
|
||||
if (count === 0) return sides;
|
||||
const all = around.n && around.e && around.s && around.w;
|
||||
if (all && count === 1) return TERRAIN_NOTCH_TILES[notched.indexOf(true)]!;
|
||||
if (count === 2 && notched[0] && notched[3]) return TERRAIN_PAIRS.tlbr;
|
||||
if (count === 2 && notched[1] && notched[2]) return TERRAIN_PAIRS.trbl;
|
||||
const quadrants = [...sides] as TileQuadrants;
|
||||
const inside = insideCorners(around);
|
||||
notched.forEach((notch, corner) => {
|
||||
if (!notch) return;
|
||||
const source = TERRAIN_NOTCH_TILES[corner]!;
|
||||
quadrants[corner] = source[corner]!;
|
||||
const partner = VERTICAL_PARTNER[corner]!;
|
||||
if (inside[partner]) quadrants[partner] = source[partner]!;
|
||||
});
|
||||
return quadrants;
|
||||
}
|
||||
|
||||
/** The corners, in reading order, whose two sides are there – the ones that can be inside or notched. */
|
||||
function joinedCorners(around: Neighbours): boolean[] {
|
||||
return [around.n && around.w, around.n && around.e, around.s && around.w, around.s && around.e];
|
||||
}
|
||||
|
||||
function cornerDiagonals(around: Neighbours): boolean[] {
|
||||
return [around.nw, around.ne, around.sw, around.se];
|
||||
}
|
||||
|
||||
/** The corners whose sides are there but whose diagonal is not. */
|
||||
function notchedCorners(around: Neighbours): boolean[] {
|
||||
const diagonals = cornerDiagonals(around);
|
||||
return joinedCorners(around).map((joined, corner) => joined && !diagonals[corner]);
|
||||
}
|
||||
|
||||
function insideCorners(around: Neighbours): boolean[] {
|
||||
const diagonals = cornerDiagonals(around);
|
||||
return joinedCorners(around).map((joined, corner) => joined && diagonals[corner]!);
|
||||
}
|
||||
|
||||
/** The four quarters a tile with these neighbours is drawn from. */
|
||||
export function tileQuadrants(kind: TileKind, around: Neighbours): TileQuadrants {
|
||||
const [tl, tr, bl, br] = cornersOf(kind) as [CornerSpec, CornerSpec, CornerSpec, CornerSpec];
|
||||
if (kind === 'terrain') return terrainQuadrants(around);
|
||||
const [tl, tr, bl, br] = CORNERS[kind] as [CornerSpec, CornerSpec, CornerSpec, CornerSpec];
|
||||
return [
|
||||
quadrantFor(tl, around.w, around.n, around.nw),
|
||||
quadrantFor(tr, around.e, around.n, around.ne),
|
||||
@@ -138,7 +220,7 @@ export interface AutotileCombination {
|
||||
}
|
||||
|
||||
/**
|
||||
* Every tile the kind can produce, without repeats: 47 for a floor, 16 for a wall, 1 for a plain
|
||||
* Every tile the kind can produce, without repeats: 47 for a floor or terrain, 16 for a wall, 1 for a plain
|
||||
* tile. Built by walking all neighbourhoods and keeping the first that draws a tile nobody drew
|
||||
* before – so a diagonal is only set where it changes something, and the list starts with the
|
||||
* lone tile.
|
||||
@@ -154,22 +236,17 @@ export function autotileCombinations(kind: TileKind): AutotileCombination[] {
|
||||
const signature = quadrants.map((q) => `${q.x},${q.y}`).join(' ');
|
||||
if (seen.has(signature)) continue;
|
||||
seen.add(signature);
|
||||
combinations.push({ neighbours, quadrants, label: combinationLabel(neighbours, quadrants, kind) });
|
||||
combinations.push({ neighbours, quadrants, label: combinationLabel(neighbours, kind) });
|
||||
}
|
||||
return combinations;
|
||||
}
|
||||
|
||||
function combinationLabel(around: Neighbours, quadrants: TileQuadrants, kind: TileKind): string {
|
||||
function combinationLabel(around: Neighbours, kind: TileKind): string {
|
||||
const sides = SIDES.filter((side) => around[side])
|
||||
.map((side) => side.toUpperCase())
|
||||
.join('');
|
||||
const corners = cornersOf(kind);
|
||||
const notched = DIAGONALS.filter((_, index) => {
|
||||
const corner = NOTCH_ORDER[index]!;
|
||||
const inner = corners[corner]?.inner;
|
||||
const drawn = quadrants[corner]!;
|
||||
return inner !== undefined && drawn.x === inner.x && drawn.y === inner.y;
|
||||
});
|
||||
const corners = kind === 'floor' || kind === 'terrain' ? notchedCorners(around) : [];
|
||||
const notched = DIAGONALS.filter((_, index) => corners[NOTCH_ORDER[index]!]);
|
||||
return `${sides || '·'}${notched.length > 0 ? `-${notched.join(',')}` : ''}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ import { type FrameRect, resolvePicture, type TextureRef } from './texture';
|
||||
* A tile is one picture per animation step, and every picture is a *block* the editor cuts into
|
||||
* quarter tiles. `none` is the plain case: the block is the tile itself and every cell shows it as
|
||||
* it is (#131). `floor` and `wall` are the two autotile blocks of the classic RPG-Maker sheets,
|
||||
* whose quarters are picked by the neighbours – that part is `model/autotile.ts`.
|
||||
* `terrain` the 6 × 4 block of the common top-down sheets; their quarters are picked by the
|
||||
* neighbours – that part is `model/autotile.ts`.
|
||||
*
|
||||
* Everything below counts in *quadrants* – quarter tiles – with (0, 0) at the block's top-left
|
||||
* corner, so all three kinds are drawn the same way: four quarters per tile.
|
||||
* corner, so all kinds are drawn the same way: four quarters per tile.
|
||||
*/
|
||||
export const TILE_KINDS = ['none', 'floor', 'wall'] as const;
|
||||
export const TILE_KINDS = ['none', 'floor', 'wall', 'terrain'] as const;
|
||||
export type TileKind = (typeof TILE_KINDS)[number];
|
||||
|
||||
export const TILE_KIND_KEY = 'kind';
|
||||
@@ -36,11 +37,11 @@ export const TILE_COLLISION_SCALE_MAX = 2;
|
||||
const TILE_PLAYBACKS = ['loop', 'pingpong'] as const;
|
||||
export type TilePlayback = (typeof TILE_PLAYBACKS)[number];
|
||||
|
||||
/** Quadrant columns of a block: one tile for `none`, two for the autotile blocks. */
|
||||
const BLOCK_COLUMNS: Record<TileKind, number> = { none: 2, floor: 4, wall: 4 };
|
||||
/** Quadrant columns of a block: one tile for `none`, two for the RPG-Maker blocks, six for `terrain`. */
|
||||
const BLOCK_COLUMNS: Record<TileKind, number> = { none: 2, floor: 4, wall: 4, terrain: 12 };
|
||||
|
||||
/** Quadrant rows of a block: `none` is one tile tall, `floor` three and `wall` two. */
|
||||
const BLOCK_ROWS: Record<TileKind, number> = { none: 2, floor: 6, wall: 4 };
|
||||
/** Quadrant rows of a block: `none` is one tile tall, `floor` three, `wall` two and `terrain` four. */
|
||||
const BLOCK_ROWS: Record<TileKind, number> = { none: 2, floor: 6, wall: 4, terrain: 8 };
|
||||
|
||||
export function tileKind(asset: TileAsset): TileKind {
|
||||
const value = textOf(asset.props[TILE_KIND_KEY] ?? 'none');
|
||||
|
||||
Reference in new issue
Block a user