clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

main
atlas / render / test / fixtures.ts
fixtures.ts 2.6K
1// Reading the corpus, for the tests that judge the lane against real data.2//3// `testdata/corpus/bundles/<slug>/` is a committed extraction of one build:4// the manifest, each world's payload and unpacked locations, and a per-pyramid5// tile inventory with content and decoded-pixel digests. No rasters and no6// archives are in the repository, so everything here is JSON — which is7// exactly enough to hold a reader to the format.89import { readFileSync, readdirSync } from "node:fs";10import { join } from "node:path";11import { fileURLToPath } from "node:url";12import type { TileGrid, WorldPayload } from "../data/payload.ts";1314const here = fileURLToPath(new URL(".", import.meta.url));1516/** The repository's corpus root. */17export const FIXTURES = join(here, "..", "..", "testdata", "corpus", "bundles");1819/** Every fixture volume, by slug. */20export function volumes(): string[] {21 return readdirSync(FIXTURES).filter((name) => !name.startsWith("."));22}2324function read<T>(...path: string[]): T {25 return JSON.parse(readFileSync(join(FIXTURES, ...path), "utf8")) as T;26}2728/** The manifest's tile grid: the world square every pyramid is cut over. */29export function tileGrid(slug: string): TileGrid {30 return read<{ tileGrid: TileGrid }>(slug, "manifest.json").tileGrid;31}3233/** Every world payload of a volume, keyed by world slug. */34export function payloads(slug: string): Map<string, WorldPayload> {35 const out = new Map<string, WorldPayload>();36 for (const name of readdirSync(join(FIXTURES, slug, "worlds"))) {37 if (!name.endsWith(".payload.json")) continue;38 out.set(name.replace(".payload.json", ""), read<WorldPayload>(slug, "worlds", name));39 }40 return out;41}4243/** One packed-locations extraction: the records, and the digest of the bytes. */44export interface LocationsFixture {45 readonly count: number;46 readonly packedBytes: number;47 readonly packedSha256: string;48 readonly world: string;49 readonly locations: readonly {50 id: number; owner: number; lat: number; lng: number;51 member: number; shard: number; title: string;52 }[];53}5455export function locations(slug: string, world: string): LocationsFixture {56 return read<LocationsFixture>(slug, "worlds", `${world}.locations.json`);57}5859/** One pyramid's tile inventory: names, in the order it records them. */60export interface Inventory {61 readonly pyramid: string;62 readonly count: number;63 readonly tiles: readonly { name: string }[];64}6566export function inventories(slug: string): Inventory[] {67 const dir = join(FIXTURES, slug, "tiles");68 return readdirSync(dir)69 .filter((name) => name.endsWith(".json"))70 .map((name) => read<Inventory>(slug, "tiles", name));71}