| 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("flight sort stays above any ground y-sort in view", () => |
| 37 | { |
| 38 | const farSouthBlock = ySortLayer(50_000, 3); |
| 39 | assert.ok(flightSortLayer(0, 0) > farSouthBlock); |
| 40 | assert.ok(flightSortLayer(16, 1) > flightSortLayer(0, 1)); |
| 41 | }); |