Functions
defineEditorMod
function defineEditorMod(def: EditorModDefinition): EditorModDefinition;
Declares a mod for the map editor of the web app, not for the game: the file is content/mods/editor-<name>/main.ts, exports defineEditorMod({...}) as its default, and the game's own mod scan skips every editor-* folder. The editor loads these files at build time, sorts them by loadOrder then id, and calls setup(editor) once. A mod that is invalid or whose setup throws is left out (its panels and tools are rolled back) and the error is written to the browser console.
| Field | Rule |
|---|---|
id |
^[a-z0-9._-]{1,64}$ |
name |
up to 80 characters |
version |
major.minor.patch digits |
apiVersion |
1; another value is refused |
loadOrder |
integer 0 to 10000, default 1000 |
permissions |
map:read, map:write, each once |
editor.panel, editor.command, editor.tool, editor.pattern and editor.validation register what the mod adds. Panel ids are ^[a-z0-9-]{1,32}$; command, tool, pattern and validation ids are ^[a-z0-9._-]{1,64}$; titles and labels are up to 120 characters. Ids are unique for each kind across all editor mods, not per mod. A panel has exactly one of view or component (the five components belong to the built-in mods). A pattern needs a #rrggbb color, at most 8 params of kind number, select, toggle or sequence (a list of whole numbers 1 to 99 such as "4 2 3 2 4", maxLength 1 to 32, 16 by default), and a pure steps function that draws from input.random(), never Math.random. Param names match ^[a-z][a-zA-Z0-9]{0,31}$.
export default defineEditorMod({
id: "example.editor-jack",
name: "Jack pattern",
version: "1.0.0",
apiVersion: 1,
permissions: ["map:read", "map:write"],
setup(editor) {
editor.pattern({
id: "jack-run",
title: "Jack run",
color: "#ff5c5c",
steps: ({ stepCount, columns }) => Array.from({ length: stepCount }, () => [columns[0]]),
});
},
});
Errors you will see in the console: Invalid mod id: X, Mod x targets editor API 2; host runs 1, Mod x loadOrder must be an integer 0-10000, Mod x repeats permission map:read, Editor pattern id "jack-run" is already registered by pvng.editor-patterns, Pattern jack-run needs a colour like #4d8dff: it is how the pattern is told apart in the picker, Panel x needs exactly one of view or component.
Types
Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.
interface EditorModDefinition {
id: string;
name: string;
version: string;
apiVersion: 1;
author?: string;
description?: string;
loadOrder?: number;
permissions?: ("map:read" | "map:write")[];
setup(editor: EditorApi): void;
}
interface EditorApi {
readonly apiVersion: 1;
panel(def: EditorPanelDef): void;
command(def: EditorCommandDef): void;
tool(def: EditorToolDef): void;
pattern(def: EditorPatternDef): void;
validation(def: EditorValidationDef): void;
}
interface EditorPanelDef {
id: string;
title: string;
icon: EditorIcon;
rail: "main" | "bottom";
view?: (ctx: EditorModContext) => EditorViewNode;
component?: "timing" | "sections" | "markers" | "settings" | "issues";
}
type EditorIcon = "timer" | "layers" | "flag" | "settings" | "wand" | "bookmark" | "music" | "wrench" | "plus" | "trash" | "play";
interface EditorModContext {
/** The map's data and its commands (`map:write` to change it). */
readonly map: MapPluginApi;
/** What the editor is doing right now: cursor, pointer, selection, tool, grid, tempo. Read-only and live. */
readonly editor: EditorStateApi;
/** Small data the mod keeps between sessions, private to it. */
readonly storage: EditorModStorage;
}
interface MapPluginApi {
readonly version: 1;
readonly map: { readonly id: bigint | null; readonly keyCount: number; };
readonly vectors: {
readonly notes: ReadonlyArray<MapNote>;
readonly timingPoints: ReadonlyArray<MapTimingPoint>;
readonly sections: ReadonlyArray<MapSection>;
readonly markers: ReadonlyArray<MapMarker>;
};
readonly cursor: { readonly timeUs: number; };
readonly selection: { readonly noteIds: ReadonlySet<bigint>; readonly count: number; };
readonly commands: {
addNote(timeUs: bigint, column: number): Promise<void>;
addHold(timeUs: bigint, column: number, durationUs: bigint): unknown;
deleteRange(startUs: number, endUs: number): Promise<void>;
seek(timeUs: number): void;
clearSelection(): void;
setSelection(noteIds: bigint[]): void;
addToSelection(noteIds: bigint[]): void;
/**
* Arms a pattern: the editor shows it under the pointer and the next click on the playfield places it, as one step (Shift
* puts it in random lanes, Escape or a right click drops it). `null` drops it. Needs `map:write`. At most 256 notes.
*/
armPlacement(steps: ReadonlyArray<EditorPlacementStep> | null): void;
/** Places a pattern at `timeUs` at once, as one undoable step (the tempo there sets its times). Needs `map:write`. At most 256 notes. */
placePattern(steps: ReadonlyArray<EditorPlacementStep>, timeUs: number): Promise<void>;
};
}
interface MapNote {
readonly id: bigint;
readonly timeUs: bigint;
readonly column: number;
readonly noteType: number;
readonly durationUs: bigint;
}
interface MapTimingPoint {
readonly id: bigint;
readonly timeUs: bigint;
readonly pointType: number;
readonly bpm: number | undefined;
readonly scrollSpeed: number | undefined;
readonly signature: number;
}
interface MapSection {
readonly id: bigint;
readonly name: string | undefined;
readonly startTimeUs: bigint;
readonly endTimeUs: bigint;
}
interface MapMarker {
readonly id: string | bigint;
readonly timeUs: number;
readonly name: string;
readonly color: string;
readonly createdBy?: bigint;
}
interface EditorPlacementStep {
readonly beat: number;
readonly column: number;
readonly holdBeats?: number;
}
interface EditorStateApi {
readonly mapId: bigint | null;
readonly keyCount: number;
/** Every note, by time then lane. */
readonly notes: ReadonlyArray<MapNote>;
/** Every timing point (tempo and scroll speed), as the map holds them. */
readonly timingPoints: ReadonlyArray<MapTimingPoint>;
/** A pattern is armed (`ctx.map.commands.armPlacement`): the next click on the playfield places it. */
readonly placing: boolean;
readonly markers: {
readonly all: ReadonlyArray<MapMarker>;
readonly activeId: string | bigint | null;
readonly loopEnabled: boolean;
readonly loopRange: { readonly startUs: number; readonly endUs: number } | null;
};
readonly time: {
/** The playhead: the audio position while playing, else the cursor. */
readonly cursorUs: number;
readonly playing: boolean;
/** The length of the audio, 0 without any. */
readonly durationUs: number;
/** The mouse over the playfield, `null` when it is elsewhere. */
readonly pointer: EditorPointer | null;
};
readonly view: {
readonly tool: EditorTool;
readonly beatDivisor: number;
readonly snapToGrid: boolean;
readonly snapScroll: boolean;
readonly zoom: number;
readonly metronome: boolean;
/** The stretch of the map on screen. */
readonly visibleStartUs: number;
readonly visibleEndUs: number;
};
readonly selection: {
readonly count: number;
readonly noteIds: ReadonlySet<bigint>;
/** The selected notes, by time then lane. */
readonly notes: ReadonlyArray<MapNote>;
/** The span of the selection, holds included; `null` when nothing is selected. */
readonly startUs: number | null;
readonly endUs: number | null;
/** The lanes the selection uses, ascending. */
readonly columns: ReadonlyArray<number>;
};
readonly timing: {
/** The tempo changes, by time. */
readonly tempos: ReadonlyArray<EditorTempoPoint>;
/** The tempo in force at a time. */
tempoAt(timeUs: number): EditorTempo;
/** The time moved to the nearest grid line (`divisor` defaults to the editor's). */
snap(timeUs: number, divisor?: number): number;
/** The notes that start in [startUs, endUs). */
notesIn(startUs: number, endUs: number): ReadonlyArray<MapNote>;
};
}
interface EditorPointer {
/** The time under the mouse. */
readonly timeUs: number;
/** The same time moved to the nearest line of the grid in use. */
readonly snappedUs: number;
/** The lane under the mouse, or `null` between lanes. */
readonly column: number | null;
}
type EditorTool = "select" | "note" | "hold";
interface EditorTempoPoint {
readonly timeUs: number;
readonly bpm: number;
readonly signature: number;
}
interface EditorTempo {
readonly bpm: number;
readonly beatUs: number;
/** Where the tempo starts: the origin of its grid. */
readonly originUs: number;
/** Beats per measure. */
readonly signature: number;
}
interface EditorModStorage {
get<T = unknown>(key: string): T | undefined;
/** Throws when the value is not JSON or the limits (32 keys, 64 KiB a value, 256 KiB in all) would be passed. */
set(key: string, value: unknown): void;
remove(key: string): void;
keys(): string[];
}
type EditorViewNode =
| { kind: "stack"; children: EditorViewNode[] }
/** A titled group, the editor's own: the same header and surface as its built-in panels. `hint` is one short sentence in a bubble. */
| { kind: "section"; title: string; hint?: string; children: EditorViewNode[] }
/** The pattern generator: every registered pattern, its settings and the button that writes the notes. At most one per panel. */
| { kind: "patterns" }
| { kind: "text"; text: string }
| { kind: "button"; label: string; onClick: () => void; disabled?: boolean }
| { kind: "number"; label: string; value: number; min?: number; max?: number; step?: number; onChange: (v: number) => void }
| { kind: "select"; label: string; value: string; options: { value: string; label: string }[]; onChange: (v: string) => void }
| { kind: "toggle"; label: string; value: boolean; onChange: (v: boolean) => void }
/** A text field that keeps its own text: Enter or the button calls `onSubmit` with it, then the field empties. Labels are unique in a panel. */
| { kind: "input"; label: string; placeholder?: string; maxLength?: number; submitLabel?: string; onSubmit: (text: string) => void }
/** Rows with their own buttons: a title, a detail line and up to three actions each. */
| { kind: "list"; empty: string; items: EditorListItem[] };
interface EditorListItem {
id: string;
title: string;
detail?: string;
/** A colour dot before the title (`#rrggbb`). */
color?: string;
/** A small picture of a pattern before the title. */
preview?: EditorNotePreview;
/** Clicking the row itself. */
onClick?: () => void;
actions: EditorListAction[];
}
interface EditorNotePreview {
columns: number;
length: number;
notes: { at: number; column: number; length?: number }[];
}
interface EditorListAction {
label: string;
icon: EditorIcon;
onClick: () => void;
danger?: boolean;
disabled?: boolean;
}
interface EditorCommandDef {
id: string;
title: string;
run: (ctx: EditorModContext) => void | Promise<void>;
}
interface EditorToolDef {
id: string;
title: string;
icon: EditorIcon;
run: (ctx: EditorModContext) => void | Promise<void>;
}
interface EditorPatternDef {
id: string;
title: string;
/** The colour of the pattern, `#rrggbb`. Required, so every pattern can be told apart at a glance. */
color: string;
/** One short sentence, shown in a bubble. */
description?: string;
/** The pattern's own settings, after the shared ones. */
params?: EditorParamDef[];
/** The columns pressed at each step: one list per step, `[]` for a rest. Pure: use `input.random`, never `Math.random`. */
steps: (input: PatternStepsInput) => number[][];
}
type EditorParamDef =
| { kind: "number"; name: string; label: string; default: number; min: number; max: number; step?: number }
| { kind: "select"; name: string; label: string; default: string; options: { value: string; label: string }[] }
| { kind: "toggle"; name: string; label: string; default: boolean }
/**
* A list of whole numbers the player builds by clicking (a size per entry, from 1 to the map's key count), kept as text such
* as "4 2 3 2 4". It cannot be empty and holds at most `maxLength` entries (16 when it does not say, 32 at most).
*/
| { kind: "sequence"; name: string; label: string; default: string; maxLength?: number };
interface PatternStepsInput {
/** How many steps to give. */
readonly stepCount: number;
/** The grid: one entry per step, with its time, measure and beat. */
readonly grid: ReadonlyArray<PatternStep>;
readonly stepsPerBeat: number;
readonly stepsPerMeasure: number;
/** The range, from the measure line of the cursor to the end of the last measure. */
readonly startUs: number;
readonly endUs: number;
/** The tempo in force at the start of the range. */
readonly bpm: number;
/** The columns the player allows, ascending, never empty: use only these. */
readonly columns: ReadonlyArray<number>;
/** The map's number of columns: the allowed ones are a part of them. */
readonly keyCount: number;
/** What the editor shows right now (notes, selection, tempo…), read-only: a pattern may read the map to adapt. */
readonly editor: EditorStateApi;
readonly randomness: PatternRandomness;
/** Seeded random numbers in [0, 1): the same seed gives the same pattern. */
random(): number;
/** The values of the pattern's own `params`. */
readonly values: Readonly<Record<string, number | string | boolean>>;
}
interface PatternStep {
/** Where the step falls. */
readonly timeUs: number;
/** How long the step lasts: it differs between two measures of different tempos. */
readonly stepUs: number;
/** The measure it belongs to, counted from 0 in the range. */
readonly measure: number;
/** Its place in the measure, from 0. */
readonly inMeasure: number;
/** The beat of the measure it falls on, from 0. */
readonly beat: number;
}
type PatternRandomness = "fixed" | "varied" | "random";
interface EditorValidationDef {
id: string;
title: string;
check: (ctx: EditorModContext) => EditorIssue[];
}
interface EditorIssue {
severity: "info" | "warning" | "error";
message: string;
}