All files / src/packlets/editor-core lane-layouts.ts

37.5% Statements 3/8
0% Branches 0/2
33.33% Functions 1/3
50% Lines 3/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                          1x                                                                                                                     1x                     19x                            
/**
 * @packageDocumentation
 *
 * Lane layout definitions for game modes.
 *
 * A lane is a gameplay column inside a level. Each game mode defines its own
 * lane layout: how many lanes, their widths, names, and background colors.
 */
 
export interface LaneDefinition {
  /** The lane index used in note entities, e.g. 1, 2, 8. */
  laneIndex: number;
  /** Display name of the lane, e.g. "1", "2", "SC". */
  name: string;
  /** Width of the lane in pixels. */
  width: number;
  /** Optional background color for the lane. */
  backgroundColor?: string;
  /** Color for notes placed in this lane. */
  noteColor: string;
}
 
export interface GameModeLayout {
  /** Game mode identifier, e.g. "beat-7k". */
  mode: string;
  /** Ordered lane definitions from left to right. */
  lanes: LaneDefinition[];
}
 
const BEAT_7K_LANES: LaneDefinition[] = [
  {
    laneIndex: 8,
    name: "SC",
    width: 56,
    backgroundColor: "var(--red-2)",
    noteColor: "var(--red-7)",
  },
  {
    laneIndex: 1,
    name: "1",
    width: 36,
    backgroundColor: "var(--gray-2)",
    noteColor: "var(--gray-7)",
  },
  {
    laneIndex: 2,
    name: "2",
    width: 28,
    backgroundColor: "var(--indigo-2)",
    noteColor: "var(--indigo-7)",
  },
  {
    laneIndex: 3,
    name: "3",
    width: 36,
    backgroundColor: "var(--gray-2)",
    noteColor: "var(--gray-7)",
  },
  {
    laneIndex: 4,
    name: "4",
    width: 28,
    backgroundColor: "var(--indigo-2)",
    noteColor: "var(--indigo-7)",
  },
  {
    laneIndex: 5,
    name: "5",
    width: 36,
    backgroundColor: "var(--gray-2)",
    noteColor: "var(--gray-7)",
  },
  {
    laneIndex: 6,
    name: "6",
    width: 28,
    backgroundColor: "var(--indigo-2)",
    noteColor: "var(--indigo-7)",
  },
  {
    laneIndex: 7,
    name: "7",
    width: 36,
    backgroundColor: "var(--gray-2)",
    noteColor: "var(--gray-7)",
  },
];
 
const GAME_MODE_LAYOUTS: Record<string, GameModeLayout> = {
  "beat-7k": { mode: "beat-7k", lanes: BEAT_7K_LANES },
};
 
/**
 * Look up the lane layout for a given game mode.
 *
 * @param mode Game mode identifier, e.g. "beat-7k".
 * @returns The layout definition, or undefined if the mode is not known.
 */
export function getGameModeLayout(mode: string): GameModeLayout | undefined {
  return GAME_MODE_LAYOUTS[mode];
}
 
/**
 * Get the total width of all lanes in a mode.
 *
 * @param mode Game mode identifier, e.g. "beat-7k".
 * @returns Total lane width in pixels, or 0 if mode is unknown.
 */
export function getModeLaneWidth(mode: string): number {
  const layout = getGameModeLayout(mode);
  if (!layout) return 0;
  return layout.lanes.reduce((sum, lane) => sum + lane.width, 0);
}