import { describe, expect, it } from "vitest"; import type { MapDef, SoundDef, SpriteDef } from "@nengine/core"; import { snapshotAssetRefs } from "../src/sync/asset-refs.js"; function map(): MapDef { return { id: "farm", width: 2, height: 2, tilesetRef: "tiles", spawn: { x: 0, y: 0 }, layers: [{ name: "ground", data: [["grass", "water"], ["grass", "grass"]] }], tiles: { grass: "grass-1", water: "water-1" }, }; } describe("snapshotAssetRefs (D37 wanted-id derivation)", () => { it("collects image assets from the map tiles mapping and sprite image layers", () => { const sprites: SpriteDef[] = [ { id: "s1", frames: [ { layers: [{ shape: "rect", x: 0, y: 0, w: 1, h: 1, fill: "#ff0000" }] }, { layers: [{ shape: "image", src: "plant-sprout" }] }, ], }, ]; const refs = snapshotAssetRefs({ map: map(), sprites }); expect(refs.images.sort()).toEqual(["grass-1", "plant-sprout", "water-1"]); expect(refs.audio).toEqual([]); }); it("collects audio assets from sound def src ids and ignores synth-only defs", () => { const sounds: SoundDef[] = [ { id: "till", src: "drop-1" }, { id: "coin", synth: { wave: "sine", freq: 1, durationMs: 1 } }, ]; const refs = snapshotAssetRefs({ map: map(), sounds }); expect(refs.audio).toEqual(["drop-1"]); expect(refs.images).toEqual(["grass-1", "water-1"]); }); it("returns empty refs for a snapshot with no tiles mapping, no image layers, no src sounds", () => { const plain = { ...map(), tiles: undefined }; const refs = snapshotAssetRefs({ map: plain }); expect(refs.images).toEqual([]); expect(refs.audio).toEqual([]); }); });