Conventions
Song times are in microseconds (timeUs) except where a field says milliseconds (Hit.offsetMs, judgement windows). Layout and style lengths are fractions of the screen height; x, y are fractions of the parent. An out-of-range value throws in the script. The permissions are stage, skinImport and network, declared in defineMod.
Functions
defineChart
function defineChart(input: ChartDefinition): ChartManifest;
Declares a map script, a script that ships with one map and only reshapes its playfield. Call it once at the top level and export the result. The declaration has no id: only apiVersion (2: "the map script requires modding API version 1; this game provides version 2"), permissions and images. Errors: "defineChart must be called exactly once", "defineChart declares a map script: this mod declares itself with defineMod", "defineChart can only be called at the top level of the map script"; without it, "the map script must declare itself with export default defineChart({ … })".
setup(play) receives the PlayContext. A map script may call playfield.*, lanes.*, game.*, log.* and ctx.on; hud.* and storage.* throw "X is not available to map scripts: they only change the playfield". It has no uses, so ctx.has is always false for it.
export default defineChart({
apiVersion: 2,
setup(play) {
playfield.set({ scroll: play.columns > 4 ? "up" : "down" });
},
});
defineMod
function defineMod(input: ModDefinition): ModManifest;
Declares the mod. Call it exactly once, at the top level of main.ts (or index.ts), and export the result as the default export. setup(mod) runs once the declaration is accepted, with the validated manifest. Anything else is refused: "defineMod can only be called at the top level of the mod's entry file", "defineMod must be called exactly once" (the first error is kept even when the script catches it), "defineMod declares a mod: this skin declares itself with defineSkin". Without a declaration the host reports "main.ts must declare the mod with export default defineMod({ … }) at its top level".
Checks: id is 1 to 64 characters from a-z 0-9 . - _, starts and ends with a letter or digit, no ..; name and author at most 64 characters, description at most 1024, homepage an http(s) URL of at most 256 characters; version is a semantic version ("version must be a semantic version such as 1.0.0, got "1.0""); apiVersion must be the game's (2): "my-mod requires modding API version 1; this game provides version 2"; loadOrder 0 to 10000 (1000 by default); images at most 64 .png paths. An unknown field is refused ("unknown field x, expected one of …"). Ids are shared with the skin and every other mod: "another mod already uses the id X: the folder Y loaded first and keeps it". Only stage, skinImport and network exist as permissions.
At load time only defineMod, log.* and ctx.on work; every other call throws "X is not available while the mod loads: call it from setup or an event handler".
export default defineMod({
id: "hello",
name: "Hello",
version: "1.0.0",
apiVersion: 2,
setup(mod) {
log.info(`${mod.name} ${mod.version} is ready`);
},
});
defineSkin
function defineSkin(input: SkinDefinition): SkinManifest;
Declares the skin script (skin.ts of a skin package). Same rules, limits and messages as defineMod (identity checks, apiVersion 2, one call at the top level, shared id space), with defineSkin in the text: a mod that calls it gets "defineSkin declares a skin: this mod declares itself with defineMod". There is no loadOrder. setup(play) receives the PlayContext of the map being launched: mode, layout, column count, screen size, the song and the judgement tiers. It is where a skin calls playfield.set and lanes.set; the host waits for it at most 1000 ms. A skin may use hud.* and storage.* (its storage file is mod-storage/skins/<id>.json) but never register functions.
If the skin script fails three times in a row or times out three times, it is disabled until the next map launch (a mod stays disabled until the game restarts).
export default defineSkin({
id: "wide-lanes",
name: "Wide lanes",
version: "1.0.0",
apiVersion: 2,
setup(play) {
log.info(`${play.song.title}: ${play.columns} columns`);
playfield.set({ scroll: "down" });
},
});
translate
function translate(key: string, values?: Record<string, string | number>): string;
Returns the game's translated text for an interface key, in the language the player uses, filling {name} placeholders from values. It exists only in editor mods (defineEditorMod), which run in the map editor of the web interface, never in the game. The language is the editor's (English, French, Chinese or Korean); a {name} in the text is replaced by the matching entry of values, or stays as written when values has none. A key the catalogue does not know throws. Prefer it to hard-coded English for every label an editor mod shows.
const title: string = translate("editor.mod_markers_title");
The ctx global
on<K extends keyof HostEvents>(event: K, handler: HostEventHandler<K>): void;
off<K extends keyof HostEvents>(event: K, handler: HostEventHandler<K>): void;
has(id: string): boolean;
element(id: string): { configure(options: Record<string, unknown>): void };
The script's own context. Every script (mod, skin, map script) has it as a global.
ctx.on(event, handler)registers a handler for one of the 25 events; handlers of an event run in registration order, anasynchandler is awaited. Register at the top level or insetup.ctx.off(event, handler)removes the first registration of that function; a delivery already in progress still runs it.ctx.has(id)is true when a package named inusesis present, version-compatible and running.ctx.element("pkg/element").configure(options)hands options to an element another package provides: the options are checked against the provider's declaration ("unknown optionx, expected one of …"), it throws "addpkgtousesto configure its elements" whenpkgis not inuses, and does nothing when the provider is absent. Both exist once the script has declared itself, and a map script has nouses.ctx.hot(data,save,dispose) and the timers are declared but inert today: Prism never reloads a script in place, sosaveanddisposecallbacks never run, andsetTimeout/setIntervalcallbacks never fire. Do not build on them; usegame.tickandgame.beatfor time.import { ctx, console, setTimeout, setInterval, clearTimeout, clearInterval } from "manivelle:env"reaches the same objects as a module import.console.*writes to the process error output, not to the Mods page: uselog.infoandlog.warn. A dynamicimport()is refused ("dynamic import() is not supported; use a static import").- Every handler runs under the mod's budget: 30 ms per call, 16 MiB of heap; 3 consecutive errors or 3 timeouts disable the script, with the message "exceeded the 30ms execution budget N times" or "failed 3 times in a row; last error: …".
ctx.on("game.songEnd", (end) => {
log.info(`finished at ${end.accuracy.toFixed(2)}%`);
});
Types
Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.
type Permission = "stage" | "skinImport" | "network";
type ChartDefinition = {
apiVersion: number;
permissions?: Permission[];
images?: string[];
setup?: ChartSetup;
};
type ChartSetup = (play: PlayContext) => void | Promise<void>;
type PlayContext = {
mode: string;
layout: string;
layoutSkin: string;
columns: number;
screenWidth: number;
screenHeight: number;
song: Song;
judgements: JudgementConfig;
};
type Song = {
title: string;
artist: string;
creator: string;
difficulty: string;
mode: string;
layout: string;
keys: number;
durationUs: number;
noteCount: number;
ratings: Record<string, number>;
holdCount: number;
bpm?: BpmRange | null;
timing: TimingPoint[];
};
type BpmRange = {
min: number;
max: number;
main: number;
};
type TimingPoint = {
timeUs: number;
bpm: number;
beatUs: number;
meter: number;
};
type JudgementConfig = { preset: string; tiers: TierInfo[]; };
type TierInfo = {
index: number;
id: string;
name: string;
symbol?: string | null;
color: string;
gradient?: string[] | null;
earlyMs?: number | null;
lateMs?: number | null;
weight?: number | null;
breaksCombo: boolean;
};
type ChartManifest = {
apiVersion: number;
permissions?: Permission[];
images?: string[];
};
type ModDefinition = {
id: string;
name: string;
version: string;
apiVersion: number;
author?: string | null;
description?: string | null;
homepage?: string | null;
fonts?: Record<string, string>;
uses?: Record<string, Dependency>;
provides?: Provides;
permissions?: Permission[];
images?: string[];
loadOrder?: number;
setup?: ModSetup;
};
type Dependency = string | DependencySpec;
type DependencySpec = {
version: string;
required?: boolean;
feature?: string | null;
};
type Provides = { elements?: Record<string, ElementDeclaration>; };
type ElementDeclaration = { root?: string | null; options?: Record<string, ElementOption>; };
type ElementOption = {
type: OptionKind;
min?: number | null;
max?: number | null;
values?: string[];
maxLength?: number | null;
default?: unknown | null;
label?: string | null;
player?: boolean;
};
type OptionKind = "number" | "integer" | "boolean" | "string" | "color" | "enum" | "colors";
type ModSetup = (mod: ModManifest) => void | Promise<void>;
type ModManifest = {
id: string;
name: string;
version: string;
apiVersion: number;
author?: string | null;
description?: string | null;
homepage?: string | null;
fonts?: Record<string, string>;
uses?: Record<string, Dependency>;
provides?: Provides;
permissions?: Permission[];
images?: string[];
loadOrder?: number;
};
type SkinDefinition = {
id: string;
name: string;
version: string;
apiVersion: number;
author?: string | null;
description?: string | null;
homepage?: string | null;
fonts?: Record<string, string>;
uses?: Record<string, Dependency>;
provides?: Provides;
permissions?: Permission[];
images?: string[];
setup?: SkinSetup;
};
type SkinSetup = (play: PlayContext) => void | Promise<void>;
type SkinManifest = {
id: string;
name: string;
version: string;
apiVersion: number;
author?: string | null;
description?: string | null;
homepage?: string | null;
fonts?: Record<string, string>;
uses?: Record<string, Dependency>;
provides?: Provides;
permissions?: Permission[];
images?: string[];
};
type HostEventContext = {
on<K extends keyof HostEvents>(event: K, handler: HostEventHandler<K>): void;
off<K extends keyof HostEvents>(event: K, handler: HostEventHandler<K>): void;
has(id: string): boolean;
element(id: string): { configure(options: Record<string, unknown>): void };
};
type HostEvents = {
"chart.transform": ChartTransformEvent;
"controls.action": ModActionEvent;
"elements.configure": ElementConfigure;
"game.beat": Beat;
"game.judgement": JudgementEvent;
"game.lobbyLive": LobbyLiveEvent;
"game.pause": SongTime;
"game.pauseMenu": PauseMenuState;
"game.playfieldChange": Playfield;
"game.resume": SongTime;
"game.settingsChange": ModSettings;
"game.songEnd": SongEndEvent;
"game.songStart": SongStartEvent;
"game.tick": TickEvent;
"leaderboard.result": LeaderboardResult;
"library.chartAdd": ChartAdded;
"library.chartsAdded": ChartsAdded;
"library.ready": LibraryReady;
"metron.performanceResult": PerformanceResult;
"playfield.noteMask": NoteMaskEvent;
"ratings.progress": RatingProgress;
"skinImport.action": SkinImportAction;
"skinImport.created": SkinImportCreated;
"skinImport.opened": SkinImportOpened;
"skinImport.staged": SkinImportStaged;
"ui.action": PopupActionEvent;
};
type ChartTransformEvent = { id: string; };
type ModActionEvent = {
id: string;
pressed: boolean;
timeUs: number;
};
type ElementConfigure = {
element: string;
from: string;
options: unknown;
};
type Beat = {
index: number;
timeUs: number;
bpm: number;
meterBeat: number;
};
type JudgementEvent = {
column: number;
timeUs: number;
offsetUs: number;
tier: TierRef;
combo: number;
counts: number[];
accuracy: number;
};
type TierRef = {
index: number;
id: string;
name: string;
color: string;
};
type LobbyLiveEvent = {
rank: number;
players: number;
accuracy: number;
rival?: LobbyRival | null;
coop?: LobbyCoopLive | null;
};
type LobbyRival = {
name: string;
accuracy: number;
rank: number;
gap: number;
chosen: boolean;
};
type LobbyCoopLive = {
partner: string;
partnerAccuracy: number;
pairAccuracy?: number | null;
};
type SongTime = { timeUs: number; };
type PauseMenuState = {
rows: PauseMenuRow[];
selection: number;
volume: number;
rate: number;
};
type PauseMenuRow = "continue" | "restart" | "quit" | "volume" | "swap" | "seekBack" | "seekForward" | "speed";
type Playfield = {
keys: number;
lanes: Lane[];
sides: PlayfieldSide[];
hitY: number;
spawnY: number;
scrollTimeUs: number;
};
type Lane = {
column: number;
x: number;
width: number;
};
type PlayfieldSide = {
x: number;
y: number;
width: number;
height: number;
zoom: number;
aspect: number;
};
type ModSettings = {
volume: number;
showFps: boolean;
scrollTimeMs: number;
audioOffsetMs: number;
ratingSystem: string;
};
type SongEndEvent = {
counts: number[];
maxCombo: number;
accuracy: number;
aborted: boolean;
};
type SongStartEvent = {
song: Song;
judgements: JudgementConfig;
versusCentre: number;
playfield: Playfield;
timeUs: number;
};
type TickEvent = { timeUs: number; hitCount: number; };
type LeaderboardResult = {
requestId: number;
chartId: number;
offset: number;
total: number;
entries: LeaderboardEntry[];
judgement: string;
performance?: LeaderboardPerformance | null;
unavailableReplays: number;
error?: string | null;
};
type LeaderboardEntry = {
rank: number;
replayId: string;
playerName?: string | null;
received: boolean;
accuracy: number;
performance?: number | null;
performanceNonstandard: boolean;
maxCombo: number;
misses: number;
tiers: TierCount[];
rate: number;
modified: boolean;
playedAtMs: number;
};
type TierCount = { name: string; count: number; };
type LeaderboardPerformance = { calculator: string; unit: string; };
type ChartAdded = { chartId: number; };
type ChartsAdded = { chartIds: number[]; truncated: boolean; };
type LibraryReady = {};
type PerformanceResult = {
requestId: number;
calculator: string;
value?: number | null;
unit: string;
error?: string | null;
};
type NoteMaskEvent = { id: string; params: Record<string, number>; };
type RatingProgress = {
requestId: number;
id: string;
done: number;
total: number;
failed: number;
finished: boolean;
error?: string | null;
ahead: number;
};
type SkinImportAction = { id: string; };
type SkinImportCreated = {
requestId: number;
id?: string | null;
error?: string | null;
};
type SkinImportOpened = {
importerId: string;
locale: string;
source?: SkinSource | null;
error?: string | null;
};
type SkinSource = {
sourceId: number;
label: string;
kind: SourceKind;
ini?: SkinIni | null;
images: SourceImage[];
sections: IniSection[];
files: SourceFile[];
truncated: boolean;
totalBytes: number;
problems: string[];
};
type SourceKind = "folder" | "archive";
type SkinIni = {
general: IniGeneral;
mania: ManiaSection[];
fontsUsed: boolean;
problems: string[];
};
type IniGeneral = {
name?: string | null;
author?: string | null;
version?: string | null;
};
type ManiaSection = {
keys: number;
columnStart?: number | null;
columnWidth: number[];
columnSpacing: number[];
columnLineWidth: number[];
hitPosition?: number | null;
lightPosition?: number | null;
scorePosition?: number | null;
comboPosition?: number | null;
judgementLine?: boolean | null;
upsideDown?: boolean | null;
noteBodyStyle?: number | null;
lightFramePerSecond?: number | null;
barlineHeight?: number | null;
widthForNoteHeightScale?: number | null;
specialStyle?: number | null;
keysUnderNotes?: boolean | null;
colourColumnLine?: string | null;
colourBarline?: string | null;
colourJudgementLine?: string | null;
colourHold?: string | null;
stageLeft?: string | null;
stageRight?: string | null;
stageBottom?: string | null;
stageHint?: string | null;
stageLight?: string | null;
lightingN?: string | null;
lightingL?: string | null;
columns: ManiaColumn[];
ignored: string[];
};
type ManiaColumn = {
noteImage?: string | null;
noteImageH?: string | null;
noteImageL?: string | null;
noteImageT?: string | null;
keyImage?: string | null;
keyImageD?: string | null;
noteBodyStyle?: number | null;
colour?: string | null;
colourLight?: string | null;
};
type SourceImage = {
name: string;
frames: number;
hasStill: boolean;
scale: number;
width: number;
height: number;
bytes: number;
blank?: boolean | null;
bounds?: PixelBox | null;
peakColor?: string | null;
peakWidth?: number | null;
};
type PixelBox = {
left: number;
top: number;
width: number;
height: number;
};
type IniSection = { name: string; entries: IniEntry[]; };
type IniEntry = { key: string; value: string; };
type SourceFile = {
path: string;
width: number;
height: number;
bytes: number;
};
type SkinImportStaged = {
requestId: number;
stageId?: number | null;
report?: Report | null;
error?: string | null;
};
type Report = {
files: StagedFile[];
totalBytes: number;
budgetBytes: number;
overBudget: boolean;
problems: string[];
};
type StagedFile = {
path: string;
bytes: number;
width: number;
height: number;
};
type PopupActionEvent = { id: string; };
type HostEventHandler<K extends keyof HostEvents> = (
payload: HostEvents[K],
) => HostEventReply<K>;
type HostEventReply<K extends keyof HostEvents> = K extends keyof HostReplies
? HostReplies[K] | Promise<HostReplies[K]>
: void | Promise<void>;
type HostReplies = {};
type HostHotContext = {
readonly data: unknown;
save(snapshot: () => unknown): void;
dispose(cleanup: () => void): void;
};