85 lines
4.5 KiB
TypeScript
85 lines
4.5 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readFileSync } from "node:fs";
|
|
import { describe, expect, it } from "vitest";
|
|
import { DUNGEON_DEFINITIONS, requireDungeonDefinition } from "./dungeonRegistry";
|
|
import { wowDungeonMapFor, wowMapContains, wowMapFloorFor, wowMapHeading, wowMapPoint, wowMapWorldPosition, type WowDungeonMap } from "./wowDungeonMap";
|
|
|
|
function mapFor(id: string) {
|
|
const map = wowDungeonMapFor(requireDungeonDefinition(id));
|
|
expect(map, id).not.toBeNull();
|
|
return map!;
|
|
}
|
|
|
|
describe("original WoW dungeon map coordinates", () => {
|
|
it("maps WoW west/north to the top-left, east/south to the bottom-right", () => {
|
|
const map: WowDungeonMap = { mapId: 1, coordinateTransform: "test", runtimeToWow: [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0],
|
|
floors: [{ level: 1, name: "Test", bounds: [0, 100, 0, 150], image: "test", checksum: "test" }] };
|
|
expect(wowMapPoint(map, map.floors[0], [100, 0, 150])).toEqual([0, 0]);
|
|
expect(wowMapPoint(map, map.floors[0], [0, 0, 0])).toEqual([1002, 668]);
|
|
expect(wowMapPoint(map, map.floors[0], [50, 99, 75])).toEqual([501, 334]);
|
|
expect(wowMapContains(map, map.floors[0], [101, 0, 150])).toBe(false);
|
|
});
|
|
|
|
it("uses authored Wailing Caverns coordinates rather than stretching its world bounds", () => {
|
|
const dungeon = requireDungeonDefinition("wailing-caverns"), map = mapFor(dungeon.id);
|
|
const source = wowMapWorldPosition(map, dungeon.entrance.footPosition);
|
|
expect(source[0]).toBeCloseTo(-dungeon.entrance.footPosition[0], 5);
|
|
expect(source[1]).toBeCloseTo(dungeon.entrance.footPosition[2], 5);
|
|
expect(wowMapContains(map, wowMapFloorFor(map, dungeon.entrance.footPosition), dungeon.entrance.footPosition)).toBe(true);
|
|
});
|
|
|
|
it("inverts the shifted Deadmines ADT basis", () => {
|
|
const dungeon = requireDungeonDefinition("deadmines"), map = mapFor(dungeon.id);
|
|
const source = wowMapWorldPosition(map, dungeon.entrance.footPosition);
|
|
expect(source[0]).toBeCloseTo(-16.4, 1);
|
|
expect(source[1]).toBeCloseTo(-383.07, 1);
|
|
expect(source[2]).toBeCloseTo(61.78, 1);
|
|
});
|
|
|
|
it("aligns the event-driven Trial of the Champion arena entrance", () => {
|
|
const dungeon = requireDungeonDefinition("trial-of-the-champion"), map = mapFor(dungeon.id);
|
|
expect(wowMapWorldPosition(map, dungeon.entrance.footPosition)).toEqual([805.227, 618.038, 412.393]);
|
|
expect(wowMapContains(map, wowMapFloorFor(map, dungeon.entrance.footPosition), dungeon.entrance.footPosition)).toBe(true);
|
|
});
|
|
|
|
it.each(["hellfire-ramparts", "razorfen-kraul", "scholomance", "dire-maul"])("aligns the rotated %s environment", (id) => {
|
|
const dungeon = requireDungeonDefinition(id), map = mapFor(id);
|
|
const floor = wowMapFloorFor(map, dungeon.entrance.footPosition);
|
|
expect(wowMapContains(map, floor, dungeon.entrance.footPosition)).toBe(true);
|
|
const heading = wowMapHeading(map, floor, dungeon.entrance.footPosition, 0.7);
|
|
expect(Math.hypot(...heading)).toBeCloseTo(23, 5);
|
|
});
|
|
|
|
it("allows explicitly selecting the other Deadmines floor", () => {
|
|
const dungeon = requireDungeonDefinition("deadmines"), map = mapFor(dungeon.id);
|
|
expect(wowMapFloorFor(map, dungeon.entrance.footPosition, 2).level).toBe(2);
|
|
expect(wowMapFloorFor(map, dungeon.entrance.footPosition, 999).level).not.toBe(999);
|
|
});
|
|
|
|
it("falls back for non-WoW maps and replaced environments", () => {
|
|
expect(wowDungeonMapFor(requireDungeonDefinition("forsaken-abbey"))).toBeNull();
|
|
const dungeon = requireDungeonDefinition("wailing-caverns");
|
|
expect(wowDungeonMapFor({ ...dungeon, provenance: { ...dungeon.provenance, coordinateTransform: "changed" } })).toBeNull();
|
|
});
|
|
|
|
it("packages complete, checksummed PNG floors with each available map", () => {
|
|
let count = 0;
|
|
for (const dungeon of DUNGEON_DEFINITIONS) {
|
|
const map = wowDungeonMapFor(dungeon);
|
|
if (!map) continue;
|
|
count += 1;
|
|
expect(map.runtimeToWow).toHaveLength(12);
|
|
expect(map.runtimeToWow.every(Number.isFinite)).toBe(true);
|
|
expect(new Set(map.floors.map((floor) => floor.level)).size).toBe(map.floors.length);
|
|
for (const floor of map.floors) {
|
|
const png = readFileSync(`public${floor.image}`);
|
|
expect(png.toString("ascii", 1, 4)).toBe("PNG");
|
|
expect([png.readUInt32BE(16), png.readUInt32BE(20)]).toEqual([1002, 668]);
|
|
expect(createHash("sha256").update(png).digest("hex")).toBe(floor.checksum);
|
|
expect(floor.bounds.every(Number.isFinite)).toBe(true);
|
|
}
|
|
}
|
|
expect(count).toBeGreaterThanOrEqual(50);
|
|
});
|
|
});
|