Fonctions
defineEditorMod
function defineEditorMod(def: EditorModDefinition): EditorModDefinition;
Déclare un mod pour l'éditeur de maps de l'application web, pas pour le jeu : le fichier est content/mods/editor-<nom>/main.ts, exporte defineEditorMod({...}) par défaut, et le balayage des mods du jeu ignore tout dossier editor-*. L'éditeur charge ces fichiers à la compilation, les trie par loadOrder puis par id, et appelle setup(editor) une fois. Un mod invalide, ou dont setup lève une exception, est écarté (ses panneaux et outils sont annulés) et l'erreur est écrite dans la console du navigateur.
| Champ | Règle |
|---|---|
id |
^[a-z0-9._-]{1,64}$ |
name |
jusqu'à 80 caractères |
version |
chiffres majeur.mineur.correctif |
apiVersion |
1 ; toute autre valeur est refusée |
loadOrder |
entier de 0 à 10000, 1000 par défaut |
permissions |
map:read, map:write, une fois chacune |
editor.panel, editor.command, editor.tool, editor.pattern et editor.validation déclarent ce que le mod ajoute. Les ids de panneau suivent ^[a-z0-9-]{1,32}$ ; les ids de commande, d'outil, de pattern et de validation suivent ^[a-z0-9._-]{1,64}$ ; titres et libellés font 120 caractères au plus. Les ids sont uniques pour chaque sorte sur l'ensemble des mods de l'éditeur, pas par mod. Un panneau a exactement l'un de view ou component (les cinq composants appartiennent aux mods intégrés). Un pattern exige une color #rrggbb, 8 params au plus de kind number, select, toggle ou sequence (une liste d'entiers de 1 à 99 comme "4 2 3 2 4", maxLength de 1 à 32, 16 par défaut), et une fonction steps pure qui tire ses nombres de input.random(), jamais de Math.random. Les noms de paramètre suivent ^[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]]),
});
},
});
Erreurs que vous verrez dans la 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
Définitions lues dans le SDK. Un type employé ici et défini sur une autre page est listé sous Défini ailleurs.
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;
}