import test from "node:test"; import assert from "node:assert/strict"; import { spriteCenterFromPivot, tilePivot, ySortLayer, flightSortLayer, Y_SORT_BASE } from "../../shared/render/pivot.js"; test("a 16×16 sprite pivot sits on the tile centre", () => { const pivot = tilePivot(0, 0, 16); const center = spriteCenterFromPivot(pivot.x, pivot.y, 16, 1); assert.equal(pivot.x, 8); assert.equal(pivot.y, 8); assert.equal(center.x, 8); assert.equal(center.y, 8); }); test("a taller sprite keeps its feet 8px from the bottom on the tile centre", () => { const pivot = tilePivot(0, 0, 16); const center = spriteCenterFromPivot(pivot.x, pivot.y, 32, 1); assert.equal(center.x, 8); assert.equal(center.y, 0); }); test("a 48px-tall tree sprite pivots 8px from its bottom on the tile centre", () => { const pivot = tilePivot(0, 0, 16); const center = spriteCenterFromPivot(pivot.x, pivot.y, 48, 1); assert.equal(center.x, 8); assert.equal(center.y, -8); }); test("Y-sort puts a southern tile in front of a northern tile", () => { assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1)); }); test("viewport-relative Y-sort stays below UI edge band at high world Y", () => { const layerEdge = 900_000; const focusY = 50_000; const zoomedTile = 64; // Player around tileY ≈ 780 at zoom 4 — absolute sort used to exceed LAYER_EDGE. const worldY = focusY + zoomedTile * 2; const relative = worldY - focusY; const layer = ySortLayer(relative, 3); assert.ok(layer > Y_SORT_BASE); assert.ok(layer < layerEdge, `expected ${layer} < ${layerEdge}`); const absoluteWouldOverflow = Y_SORT_BASE + Math.round(worldY) * 16 + 3; assert.ok(absoluteWouldOverflow > layerEdge); }); test("S-closed door stays in front of entity equipment overlays on the same tile", () => { const sortY = 128; const entityBody = ySortLayer(sortY, 3); const entityOverlay = ySortLayer(sortY, 3 + 1 + 5); const doorFront = ySortLayer(sortY, 12); const doorBehind = ySortLayer(sortY, 1); assert.ok(doorFront > entityOverlay); assert.ok(doorFront > entityBody); assert.ok(entityBody > doorBehind); assert.ok(ySortLayer(sortY, 14) > doorFront); }); test("flight sort stays above any ground y-sort in view", () => { // In-view relative sortY stays within roughly ±screen height in world px. const farInView = ySortLayer(2_000, 3); assert.ok(flightSortLayer(0, 0) > farInView); assert.ok(flightSortLayer(16, 1) > flightSortLayer(0, 1)); assert.ok(farInView < 900_000); });