| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { spriteCenterFromPivot, tilePivot, ySortLayer, flightSortLayer } from "../../shared/render/pivot.js"; |
| 4 | |
| 5 | test("a 16×16 sprite pivot sits on the tile centre", () => |
| 6 | { |
| 7 | const pivot = tilePivot(0, 0, 16); |
| 8 | const center = spriteCenterFromPivot(pivot.x, pivot.y, 16, 1); |
| 9 | assert.equal(pivot.x, 8); |
| 10 | assert.equal(pivot.y, 8); |
| 11 | assert.equal(center.x, 8); |
| 12 | assert.equal(center.y, 8); |
| 13 | }); |
| 14 | |
| 15 | test("a taller sprite keeps its feet 8px from the bottom on the tile centre", () => |
| 16 | { |
| 17 | const pivot = tilePivot(0, 0, 16); |
| 18 | const center = spriteCenterFromPivot(pivot.x, pivot.y, 32, 1); |
| 19 | assert.equal(center.x, 8); |
| 20 | assert.equal(center.y, 0); |
| 21 | }); |
| 22 | |
| 23 | test("a 48px-tall tree sprite pivots 8px from its bottom on the tile centre", () => |
| 24 | { |
| 25 | const pivot = tilePivot(0, 0, 16); |
| 26 | const center = spriteCenterFromPivot(pivot.x, pivot.y, 48, 1); |
| 27 | assert.equal(center.x, 8); |
| 28 | assert.equal(center.y, -8); |
| 29 | }); |
| 30 | |
| 31 | test("Y-sort puts a southern tile in front of a northern tile", () => |
| 32 | { |
| 33 | assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1)); |
| 34 | }); |
| 35 | |
| 36 | test("S-closed door stays in front of entity equipment overlays on the same tile", () => |
| 37 | { |
| 38 | const sortY = 128; |
| 39 | const entityBody = ySortLayer(sortY, 3); |
| 40 | const entityOverlay = ySortLayer(sortY, 3 + 1 + 5); |
| 41 | const doorFront = ySortLayer(sortY, 12); |
| 42 | const doorBehind = ySortLayer(sortY, 1); |
| 43 | assert.ok(doorFront > entityOverlay); |
| 44 | assert.ok(doorFront > entityBody); |
| 45 | assert.ok(entityBody > doorBehind); |
| 46 | assert.ok(ySortLayer(sortY, 14) > doorFront); |
| 47 | }); |
| 48 | |
| 49 | test("flight sort stays above any ground y-sort in view", () => |
| 50 | { |
| 51 | const farSouthBlock = ySortLayer(50_000, 3); |
| 52 | assert.ok(flightSortLayer(0, 0) > farSouthBlock); |
| 53 | assert.ok(flightSortLayer(16, 1) > flightSortLayer(0, 1)); |
| 54 | }); |