| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { describe, expect, it } from "vitest";
- import type { MapDef } from "@nengine/core";
- import { TILE_COLORS, UNKNOWN_TILE_COLOR, tileAssetId, tileColor } from "../src/tiles.js";
- function map(tiles?: Record<string, string>): MapDef {
- return {
- id: "farm",
- width: 2,
- height: 2,
- tilesetRef: "tiles",
- spawn: { x: 0, y: 0 },
- layers: [{ name: "ground", data: [["grass", "water"], ["grass", "tilled"]] }],
- ...(tiles !== undefined ? { tiles } : {}),
- };
- }
- describe("tile palette", () => {
- it("maps known tile ids to their colors", () => {
- expect(tileColor("grass")).toBe(TILE_COLORS.grass);
- expect(tileColor("tilled")).toBe(TILE_COLORS.tilled);
- expect(tileColor("water")).toBe(TILE_COLORS.water);
- expect(TILE_COLORS.grass).toBe(0x7cb342);
- expect(TILE_COLORS.tilled).toBe(0x8d6e63);
- expect(TILE_COLORS.water).toBe(0x4fc3f7);
- });
- it("falls back to a neutral color for unknown tile ids", () => {
- expect(tileColor("void")).toBe(UNKNOWN_TILE_COLOR);
- expect(tileColor("")).toBe(UNKNOWN_TILE_COLOR);
- });
- });
- describe("tileAssetId (D31 map tiles mapping)", () => {
- it("resolves a mapped tile id to its image asset id", () => {
- expect(tileAssetId(map({ grass: "grass-1" }), "grass")).toBe("grass-1");
- expect(tileAssetId(map({ grass: "grass-1" }), "water")).toBeUndefined();
- });
- it("returns undefined when the map has no tiles mapping (palette fallback)", () => {
- expect(tileAssetId(map(), "grass")).toBeUndefined();
- });
- });
|