On this page

← All documentation

Editor mods

Add panels, commands, tools, note patterns and checks to the map editor with defineEditorMod, and know exactly what loads today and what the registry refuses.

An editor mod adds to the map editor (apps/web/src/mapeditor) panels, commands, toolbar tools, note patterns and consistency checks. It is written in TypeScript against the same SDK file as game mods (modding.d.ts), but it is declared with defineEditorMod and it never runs in the game.

What loads today

Only the editor mods shipped with the editor are loaded: the folders content/mods/editor-* of the repository, bundled when the editor is built. Loading an editor mod from the player's mods folder, or from a .pvmod package, is not implemented. A panel also cannot be a free Svelte component: only the declarative view is open to everyone.

So writing an editor mod today means one of two things: contributing a new editor-<name> folder to the repository (it is picked up at build time), or using this page as the specification of the API. Everything below is how the registry behaves for the shipped mods now.

The folder and the declaration

An editor mod is a folder content/mods/editor-<name>/ with a main.ts. The prefix editor- is reserved: the game host skips every folder named editor-*, in the shipped mods folder and in the player's, so the game never tries to run defineEditorMod.

The smallest editor mod registers one panel. This is the shipped Section editor: its panel body is a first-party component, so the mod only declares it.

/// <reference path="../sdk/modding.d.ts" />

// The section editor panel. The panel body is the first-party sections component, so this mod only
// registers the panel; the editor keeps the sections through the map API.
export default defineEditorMod({
  id: "pvng.editor-sections",
  name: "Section editor",
  version: "1.0.0",
  apiVersion: 1,
  author: "PVNG",
  description: "The layers panel: named sections of the map and their time ranges.",
  permissions: ["map:read"],
  setup(editor) {
    editor.panel({
      id: "sections",
      title: translate("editor.mod_sections_title"),
      icon: "layers",
      rail: "main",
      component: "sections",
    });
  },
});

defineEditorMod is an identity function in the editor: it only types the declaration. The registry then validates it.

A complete example

The example registers one of each of the five registries. It is type-checked, and its declarations pass the editor's real validators (api.ts). It is not in content/mods, so the editor does not load it: it is the model to copy into an editor-<name> folder.

/// <reference path="../../../mods/sdk/modding.d.ts" />

// An editor mod: it adds to the map editor a pattern, a tool, a command, a check and a panel. It is written with `defineEditorMod`
// (not `defineMod`) and never runs in the game, which skips every folder named `editor-*`. Declarations are made in `setup`, once.
// Plain texts here: `translate` reads the editor's own catalogue, a mod has none.
export default defineEditorMod({
  id: "example.editor-stairs",
  name: "Stairs",
  version: "1.0.0",
  apiVersion: 1,
  author: "PVNG",
  description: "A stairs pattern, a tool that selects what is on screen, a command and a check.",
  // `map:write` is needed by every call that changes the map or the selection (`ctx.map.commands`). Reading, patterns and checks need none.
  permissions: ["map:read", "map:write"],
  setup(editor) {
    // A pattern only says which columns are pressed at each step of the grid. The editor places the notes and gives the pattern its
    // shared settings (measures, divisor, allowed columns, randomness and seed, long notes). `color` is required: `#rrggbb`.
    editor.pattern({
      id: "stairs",
      title: "Stairs",
      color: "#2ec4b6",
      description: "One note per step, walking across the allowed columns.",
      params: [
        {
          kind: "select",
          name: "way",
          label: "Direction",
          default: "up",
          options: [
            { value: "up", label: "Left to right" },
            { value: "down", label: "Right to left" },
          ],
        },
        { kind: "number", name: "repeat", label: "Steps per column", default: 1, min: 1, max: 4, step: 1 },
      ],
      // Pure: the same input gives the same notes. Use `input.random()`, never `Math.random()`.
      steps: (input) => {
        const repeat = Number(input.values.repeat);
        return Array.from({ length: input.stepCount }, (_, step) => {
          if (input.randomness === "random") return [input.columns[Math.floor(input.random() * input.columns.length)]];
          const at = Math.floor(step / repeat) % input.columns.length;
          return [input.columns[input.values.way === "down" ? input.columns.length - 1 - at : at]];
        });
      },
    });

    // A tool is a button of the toolbar's Tools group: it runs an action and does not change the active tool.
    editor.tool({
      id: "select-visible",
      title: "Select the notes on screen",
      icon: "wrench",
      run: (ctx) => {
        const { visibleStartUs, visibleEndUs } = ctx.editor.view;
        ctx.map.commands.setSelection(ctx.editor.timing.notesIn(visibleStartUs, visibleEndUs).map((note) => note.id));
        // Private data of the mod: JSON, 32 keys, 64 KiB a value, 256 KiB in all.
        ctx.storage.set("uses", (ctx.storage.get<number>("uses") ?? 0) + 1);
      },
    });

    // A command is listed in the editor's command palette.
    editor.command({
      id: "note-at-cursor",
      title: "Add a note in the first column at the cursor",
      run: async (ctx) => {
        // Times in `ctx.map.commands` are bigint microseconds; the grid line nearest the cursor comes from `timing.snap`.
        await ctx.map.commands.addNote(BigInt(Math.round(ctx.editor.timing.snap(ctx.editor.time.cursorUs))), 0);
      },
    });

    // A check: the Issues panel lists what it returns when the player runs the checks.
    editor.validation({
      id: "dense-chords",
      title: "Chords of four notes or more",
      check: (ctx) => {
        const sizes = new Map<bigint, number>();
        for (const note of ctx.editor.notes) sizes.set(note.timeUs, (sizes.get(note.timeUs) ?? 0) + 1);
        const issues: EditorIssue[] = [];
        for (const [timeUs, size] of sizes) {
          if (size >= 4) issues.push({ severity: "info", message: `${size} notes at ${Number(timeUs) / 1000} ms` });
        }
        return issues.slice(0, 20);
      },
    });

    // A panel is a declarative tree the editor draws: the mod styles nothing. A `view` that reads `ctx.editor` or `ctx.storage` is
    // built again when the value changes.
    editor.panel({
      id: "stairs",
      title: "Stairs",
      icon: "wand",
      rail: "main",
      view: (ctx) => ({
        kind: "section",
        title: "Stairs",
        hint: "Pick the Stairs pattern in the pattern generator.",
        children: [
          { kind: "text", text: `${ctx.editor.selection.count} notes selected, the tool was used ${ctx.storage.get<number>("uses") ?? 0} times.` },
          { kind: "button", label: "Note at the cursor", onClick: () => void ctx.map.commands.addNote(BigInt(Math.round(ctx.editor.timing.snap(ctx.editor.time.cursorUs))), 0) },
        ],
      }),
    });
  },
});

Plain texts are used here because translate(key, values?) only reads the editor's own message catalogue: a mod has no catalogue of its own, and its titles are translated when the mod loads, not live.

The definition

Field Rule
id ^[a-z0-9._-]{1,64}$, unique among the loaded editor mods
name 1 to 80 characters
version major.minor.patch, three whole numbers
apiVersion 1. Another value is refused.
author, description optional strings
loadOrder optional integer from 0 to 10 000, 1000 by default. Mods load in loadOrder, then by id.
permissions optional list of "map:read" and "map:write", no repeat. map:read is the default.
setup(editor) required; makes the registrations with the editor object

setup runs once at load. A mod whose setup throws is deactivated with everything it registered, the error is logged and the editor keeps running.

The five registries

editor has five methods: panel, command, tool, pattern and validation. Every item has an id and, except for the panel, the same id rule: ^[a-z0-9._-]{1,64}$. A title is 1 to 120 characters. Ids are unique per kind across all mods, not just within your mod.

Panels

A panel is a button in a rail and the panel it opens.

Field Rule
id ^[a-z0-9-]{1,32}$
title 1 to 120 characters
icon one of timer, layers, flag, settings, wand, bookmark, music, wrench, plus, trash, play
rail "main" (left, with the other content panels) or "bottom" (the settings rail)
view (ctx) => EditorViewNode, a declarative tree the editor draws
component "timing", "sections", "markers", "settings" or "issues": an internal component. Shipped mods only.

Give exactly one of view and component. A third-party mod that names a component is refused.

A view that reads ctx.editor or ctx.storage is built again when the value changes. A callback that throws, or a promise that rejects, becomes an error toast and never an uncaught error. The editor draws every control in a column of the same width, with the game's own components: a mod styles nothing.

View nodes

kind Fields What it draws
stack children the children one after the other
section title, hint?, children a titled group with the header and surface of the built-in panels; hint is one short sentence in a bubble
text text a paragraph
button label, onClick, disabled? a button
number label, value, min?, max?, step?, onChange a number field
select label, value, options: { value, label }[], onChange a drop-down list
toggle label, value, onChange a switch
input label, placeholder?, maxLength?, submitLabel?, onSubmit a text field that keeps its own text; Enter or the button calls onSubmit(text), then the field empties. Labels are unique in a panel.
list empty, items rows, see below
patterns none the pattern generator: every registered pattern, its settings and the button that writes the notes. At most one per panel.

A list item is { id, title, detail?, color?, preview?, onClick?, actions }: color is a #rrggbb dot before the title, preview a miniature of a pattern { columns, length, notes: [{ at, column, length? }] } (lanes across, time upward, in the unit of length), onClick is the click on the row, and actions are up to three buttons { label, icon, onClick, danger?, disabled? }.

Commands and tools

  • A command { id, title, run(ctx) } is listed in the editor's command palette.
  • A tool { id, title, icon, run(ctx) } is a button in the Tools group of the toolbar. It runs an action and does not change the active tool.

run may be asynchronous. Both receive the mod's context, ctx.

Patterns

A pattern is a shape of notes the player can generate. Your mod only says which columns are pressed at each step of the grid; the editor places the notes, and gives every pattern the same settings: measures or a time range, the beat divisor, the allowed columns, the randomness and the seed, and the long notes (with the rules of Full long notes). A pattern never writes to the map itself, so it needs no permission.

steps(input) → number[][]   // one list of columns per step, [] for a rest
Field Rule
id, title as above
color required, #rrggbb (six hex digits): the badge of the pattern in the picker. A pattern without a valid colour is refused.
description optional, 1 to 120 characters, shown in a bubble
params optional, at most 8 settings of its own, after the shared ones
steps a function, see below

steps receives:

Field Meaning
stepCount how many steps to give
grid one entry per step: { timeUs, stepUs, measure, inMeasure, beat }. stepUs differs between two measures of different tempos.
stepsPerBeat, stepsPerMeasure the grid's resolution
startUs, endUs the range, from the measure line of the cursor to the end of the last measure
bpm the tempo in force at the start of the range
columns the columns the player allows, ascending, never empty: use only these
keyCount the map's number of columns
editor the editor's state, read-only: a pattern may read the map to adapt
randomness "fixed" (the textbook shape), "varied" (the same shape, changed now and then) or "random" (columns drawn at each step)
random() seeded numbers in [0, 1): the same seed gives the same pattern. Never use Math.random().
values the values of the pattern's own params

The engine keeps from your answer only integer columns that are allowed, with no repeat in a step, at most 8 per step; steps beyond stepCount are ignored, and a grid has at most 20 000 steps. Anything else is dropped. A function that does not return a list throws A pattern must return one list of columns per step. The seed is the one the player sets (0 draws a different one each time); the long notes the player asks for are added by the engine after your function.

Pattern parameters

Each parameter has a name (^[a-z][a-zA-Z0-9]{0,31}$, unique in the pattern), a label (1 to 120 characters) and a kind.

kind Fields Rule
number default, min, max, step? finite, min <= max, default inside the range, step > 0
select default, options: { value, label }[] at least one option, no duplicate value, default is one of them
toggle default a boolean
sequence default, maxLength? a list of whole numbers from 1 to 99 separated by spaces ("4 2 3 2 4"), the player builds it by clicking, never empty, at most maxLength entries (1 to 32, 16 by default)

Before it calls steps, the editor checks the values against the declaration (type, bounds, a listed option, a well-formed sequence): a missing or unknown value is refused. In steps read them from input.values; a number is a number and a sequence is the text, which you split on spaces.

Checks

A check { id, title, check(ctx) } returns a list of { severity, message } with severity one of "info", "warning", "error". The Issues panel lists the result of every registered check when the player presses Run checks. A check that throws is reported with its error and does not stop the others; a result that is not a list of well-formed issues is an error too. No shipped mod registers a check yet: until one does, the panel says "No checks are registered. Editor mods add checks here."

The context: ctx

Every callback receives { map, editor, storage }.

ctx.map

The map and the commands that edit it.

Part What it has
map id (bigint or null), keyCount
vectors notes, timingPoints, sections, markers, read-only
cursor timeUs
selection noteIds (a ReadonlySet<bigint>), count
commands addNote(timeUs, column), addHold(timeUs, column, durationUs), deleteRange(startUs, endUs), seek(timeUs), clearSelection(), setSelection(ids), addToSelection(ids), armPlacement(steps | null), placePattern(steps, timeUs)

Times of notes (MapNote.timeUs, durationUs) and the arguments of addNote, addHold are bigint microseconds; deleteRange, seek and placePattern take number microseconds. armPlacement and placePattern take steps { beat, column, holdBeats? } measured in beats from the start of the pattern, at most 256 notes; the tempo where they land sets their times. armPlacement shows the pattern under the pointer and the next click on the playfield places it as one undoable step (Shift: random lanes, Escape or a right click: drop it); placePattern places it at once.

ctx.editor: the editor's live state

Read-only, always current, with no permission. A view that reads it is rebuilt when it changes. Times are microseconds.

Field Content
mapId, keyCount the open map and its number of columns
placing a pattern is armed: the next click on the playfield places it
notes every note, by time then column
timingPoints every timing point (tempo and scroll speed)
markers all, activeId, loopEnabled, loopRange
time cursorUs (the playhead while playing, else the cursor), playing, durationUs, pointer
time.pointer the mouse over the playfield: timeUs, snappedUs (on the grid in use), column; null elsewhere
view tool, beatDivisor, snapToGrid, snapScroll, zoom, metronome, visibleStartUs, visibleEndUs
selection count, noteIds, notes (resolved, by time), startUs and endUs (the span, holds included, null if empty), columns
timing tempos, tempoAt(t) (bpm, beatUs, originUs, signature), snap(t, divisor?), notesIn(start, end)

ctx.storage

Private data of the mod: JSON values by key, with get<T>(key), set(key, value), remove(key) and keys(). Each mod has its own space, kept in the editor page's own storage; values are read back as written (nothing is ever executed), and reading in a view makes the view follow it. The limits are 32 keys, 64 KiB a value and 256 KiB in all; set throws past them (storage: "x" is over 65536 bytes, storage: more than 32 keys, storage: over 262144 bytes in all) and when the value is not JSON.

Permissions

Permission Effect
map:read (the default) reading the map, the cursor, the selection and ctx.editor. Reads are not blocked for a mod that does not list it.
map:write in addition, every command of ctx.map.commands: adding, deleting and moving notes, timing points and sections, seek, the selection, armPlacement and placePattern

A mod without map:write still gets the commands, but each one rejects with Plugin is missing the map:write permission. Patterns, checks and ctx.editor need no permission.

What the registry refuses

The editor never trusts a value that comes from a mod. The first problem throws and the item (or the mod) is not registered:

Invalid mod id: My Mod
Mod example.x has an invalid version
Mod example.x targets editor API 2; host runs 1
Mod example.x loadOrder must be an integer 0-10000
Mod example.x repeats permission map:write
Editor mod "example.x" is already loaded
Invalid panel id: Stairs
Panel stairs needs exactly one of view or component
Panel stairs uses a first-party component but its mod is not first-party
Panel stairs has an unknown icon: star
Editor pattern id "stairs" is already registered by example.other
Pattern stairs needs a colour like #4d8dff: it is how the pattern is told apart in the picker
Pattern stairs params must be a list of at most 8
Pattern stairs repeats parameter way
Parameter repeat default is out of range
Parameter way default is not one of its options
Parameter queue default must be 1 to 16 whole numbers from 1 to 99 separated by spaces

The shipped editor mods

Mod (id) Folder Panel Rail What it is
pvng.editor-timing editor-timing timing main component: "timing"
pvng.editor-sections editor-sections sections main component: "sections"
pvng.editor-markers editor-markers markers main component: "markers"
pvng.editor-patterns editor-patterns patterns main a { kind: "patterns" } view and eight patterns, no permission
pvng.editor-snippets editor-snippets snippets main a view and map:read, map:write

The panels notes, audio and waveform are in the editor itself, with no mod. The settings rail (settings) and the Issues panel (issues) belong to the core mod pvng.editor-core.

editor-patterns registers eight patterns, each with its colour: stream, trill, jack, chordfill, jumpstream, handstream, quadstream and chordjack. They show the three kinds of parameter in use: stream has a select and two toggles, trill a number, chordjack a sequence (a list of chord sizes such as 4 3 repeated over the range) and a select for anchors. Their panel is just view: () => ({ kind: "patterns" }): it lists every registered pattern, whichever mod added it, so a pattern from your mod appears there without a panel of your own.

editor-snippets places short patterns with placePattern on the grid line nearest the cursor (ctx.editor.timing.snap), saves the player's own from the selected notes (ctx.editor.selection.notes) in ctx.storage (24 at most) and shows them as a list with previews and actions.

Pitfalls

  • Not loaded from the player's folder. Do not tell players to drop an editor mod in their mods folder: it will be ignored, as every editor-* folder is.
  • bigint against number. ctx.editor.notes and ctx.map.vectors.notes carry bigint times; ctx.editor.time.cursorUs is a number. Convert with BigInt(Math.round(x)) and Number(x).
  • A command without map:write rejects at run time, not at load time: declare the permission.
  • Math.random() in a pattern. It breaks the player's seed: use input.random().
  • A view with a side effect. It is built again whenever what it reads changes: keep it a pure description and put actions in onClick.
  • Two input nodes with the same label in a panel. Labels are unique in a panel.
  • An id used by another mod. Pattern, command, tool, panel and check ids are unique across mods per kind: prefix yours (example.stairs) if collision is likely.

Reference

Source in the game repository: apps/web/src/mapeditor/lib/mods/api.ts,apps/web/src/mapeditor/lib/mods/registry.svelte.ts,apps/web/src/mapeditor/lib/mods/load.ts,apps/web/src/mapeditor/lib/mods/pattern-engine.ts,apps/web/src/mapeditor/lib/mods/storage.svelte.ts,apps/web/src/mapeditor/lib/map/plugin-api.ts,content/mods/sdk/modding.d.ts,content/mods/editor-sections/main.ts,content/mods/editor-patterns/main.ts,content/mods/editor-snippets/main.ts,content/examples/mods/editor-stairs/main.ts,crates/modding/src/manifest.rs