all repos — emchess @ 6b60c743e0c7b7cfb599852d110f27b229626bcb

src/board/pieces.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
export type PieceType = "p" | "n" | "b" | "r" | "q" | "k";
export type SetId = "kingdom" | "forest" | "gothic" | "minimal";

export interface PieceSet {
  id: SetId;
  name: string;
  traditional: boolean;
  glyphs: Record<PieceType, string>;
}

// One fixed glyph per piece type, so a pawn always reads as a pawn.
const SETS: Record<SetId, PieceSet> = {
  kingdom: {
    id: "kingdom",
    name: "Kingdom",
    traditional: false,
    glyphs: { k: "🤴", q: "👸", b: "🧙", n: "🏇", r: "🏰", p: "🧑" },
  },
  forest: {
    id: "forest",
    name: "Forest",
    traditional: false,
    glyphs: { k: "🦁", q: "🦊", b: "🦉", n: "🦌", r: "🌳", p: "🐿️" },
  },
  gothic: {
    id: "gothic",
    name: "Gothic",
    traditional: false,
    glyphs: { k: "🧛", q: "🧛‍♀️", b: "🧙‍♂️", n: "🐺", r: "🏰", p: "🧟" },
  },
  minimal: {
    id: "minimal",
    name: "Minimal",
    traditional: true,
    // Color comes from the .w / .b classes, not the glyph.
    glyphs: { k: "♚", q: "♛", b: "♝", n: "♞", r: "♜", p: "♟" },
  },
};

export const PIECE_SETS = Object.values(SETS);

export function getSet(id: SetId): PieceSet {
  return SETS[id] ?? SETS.kingdom;
}