BlueGit

timfa questward

Files

questward / server / tests / pivot.test.js

pivot.test.js

1823a2b4 History
pivot.test.js 1.3 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { spriteCenterFromPivot, tilePivot, ySortLayer, flightSortLayer } from "../../shared/render/pivot.js";
4
5test("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
15test("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
23test("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
31test("Y-sort puts a southern tile in front of a northern tile", () =>
32{
33 assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1));
34});
35
36test("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});