On this page

← All documentation

A first mod

A working HUD mod in five minutes: the file, the folder, where to put it, the Mods page, type checking, exporting, and what an error looks like.

This mod draws the combo in big type on the right of the screen, and the accuracy under it. It is short on purpose: every line is something you will write in your own mods.

The mod

Create a folder hello-hud with one file, main.ts:

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

// Hello HUD: the combo in big type on the right of the screen, the accuracy below it.
// Nothing here runs per judgement: `bind` makes the overlay refresh the values itself.

export default defineMod({
  id: "hello-hud", // a-z, 0-9, ., -, _ ; 1 to 64 characters ; stable
  name: "Hello HUD",
  version: "1.0.0", // semantic version
  apiVersion: 2, // must equal the game's API version
  author: "Me",
  description: "The combo in big type, and the accuracy below it.",
  setup() {
    ctx.on("game.songStart", () => {
      hud.group({
        id: "panel",
        flow: { direction: "column", align: "end", gap: 0.004 },
        layout: { x: 0.98, y: 0.5, anchor: "topRight" },
      });
      hud.text({ id: "combo", parent: "panel", text: "", bind: { kind: "combo" }, style: { size: 0.06 } });
      hud.text({ id: "acc", parent: "panel", text: "", bind: { kind: "accuracy", decimals: 2 }, style: { size: 0.03 } });
    });
    ctx.on("game.songEnd", () => hud.clear());
    log.info("Hello HUD loaded");
  },
});

What each part does:

  • export default defineMod({ … }) is the whole declaration. It must be called once, at the top level of the file. id, name, version and apiVersion are required.
  • id names the mod for the game and for other mods. It is not the folder name. Use lowercase letters, digits, ., - and _, 1 to 64 characters, starting and ending with a letter or digit. Keep it stable: the player's settings and the mod's storage are filed under it.
  • version is a semantic version (1.0.0, 2.0.0-beta.1). The game compares versions when a package replaces an installed mod.
  • apiVersion must equal the API version of the game, which is 2.
  • setup() runs once, after the declaration is valid. Everything beyond declaring and logging happens there or in a handler.
  • ctx.on("game.songStart", …) registers a handler for an event. This one builds the HUD each time a map starts. game.songEnd clears it.
  • hud.group and hud.text describe nodes. The overlay draws them; the script never draws a pixel.
  • bind: { kind: "combo" } makes the overlay refresh the text itself on every judgement. Nothing in the script runs per judgement.
  • Lengths such as size and gap are fractions of the screen height. layout.x and layout.y are fractions of the parent (the screen at the top level). With x: 0.98 and anchor: "topRight" the group's top-right corner sits at 98 % of the width.
  • log.info(…) writes a line that appears under the mod on the Mods page.

The folder

A mod is a folder. The entry file is main.ts, or index.ts if there is no main.ts.

hello-hud/
  main.ts            the entry point, required
  lib/format.ts      modules that main.ts imports with a relative path
  fonts/Title.ttf    fonts named in `fonts` (.ttf, .otf)
  images/star.png    PNG images that hud.image or stage.sprite show
  • The folder name is free. It is not the id.
  • A folder whose name starts with . is ignored. So is a folder without an entry file (content/mods/sdk is one).
  • A folder whose name starts with editor- is never loaded by the game, in any root: those are editor mods. Do not name your mod folder that way.
  • Imports must stay inside the folder. A script cannot read any other file, and cannot reach the network.
  • If two folders declare the same id, the first one loaded keeps it. The other fails with another mod already uses the id `hello-hud`: the folder `…` loaded first and keeps it.

Where to put it

The game reads two roots, in this order:

Order Root Use it for
1 mods\ next to prism.exe (in a source checkout, content/mods/) The mods that ship with the game. Leave it alone.
2 %LOCALAPPDATA%\Prism\PrismNG\data\mods Your mods, and the ones the player installs.

The second root is data\mods inside the data folder. The game creates it at start. Two variables move things:

  • PRISM_MODS_DIR replaces the second root only. The mods next to prism.exe stay where they are.
  • PRISM_DATA_DIR replaces the whole data folder, and mods with it.

Copy your folder in:

Copy-Item -Recurse hello-hud "$env:LOCALAPPDATA\Prism\PrismNG\data\mods\"

Within a root, mods load in folder-name order. Then the game sorts them by dependencies, then by loadOrder (an optional number from 0 to 10000, default 1000) and id. That order is also the order in which events reach the mods and the order in which their HUD layers stack.

The Mods page

Open Mods from the menu. The page lists every mod with its state (Active, Failed or Disabled), its name, version and author, and its messages.

Control What it does
Open folder Opens the player's mods root in Explorer.
Reload Starts the mod host again: it re-reads every folder and runs every mod's load and setup again. There is no automatic reload and no file watcher: press it after every edit.
Install… Picks a .pvmod file and installs it. You can also drop a .pvmod file on the window.
Export Writes the mod as <id>-<version>.pvmod in a folder you choose. See Export a .pvmod.
Uninstall Deletes the mod's folder. The mod's storage file is kept, so a reinstall finds its data.
The switch of each mod Turns it on or off. The choice is kept, and the mod stays installed. A change made during a play waits for the return to the menu.

Install, export, uninstall and reload are refused during a play: Mods cannot be reloaded during a play.

A mod that declares the stage permission also gets a switch that lets the player forbid its native drawing. Concepts explains the three permissions.

Type checking

The game transpiles your TypeScript without checking types. A wrong option name only shows up when the call runs. Let tsc find it first.

  1. Put modding.d.ts next to main.ts.
  2. Start main.ts with /// <reference path="./modding.d.ts" />. In the repository the examples point at ../../../mods/sdk/modding.d.ts instead.
  3. Add a tsconfig.json:
{
  "compilerOptions": {
    "strict": true,
    "noEmit": true,
    "target": "es2022",
    "lib": ["es2022"],
    "module": "esnext",
    "moduleResolution": "bundler",
    "types": []
  },
  "include": ["main.ts", "lib"]
}
  1. Run tsc in the folder (npx tsc, or bunx tsc).

A typo is caught before the game ever runs it:

hud.txt({ id: "combo", text: "" });

The error=TS2551 marks this block as a documented mistake: it fails with exactly that code, and tsc suggests text.

Export a .pvmod

Export on the Mods page writes a ZIP archive named <id>-<version>.pvmod. Give that file to a player: they press Install… or drop it on the game window. Installing a mod with the same id replaces the installed one, so the same file updates, reinstalls or rolls back.

The archive holds main.ts or index.ts and the files the mod uses. Only .ts, .ttf, .otf, .png, .json, .md and .txt files are allowed, and hidden entries and node_modules are left out. Limits: 64 MiB, 1024 entries, 256 files. The .pvmod format lists the rules and every refusal.

When something is wrong

Errors do not crash the game. They show on the Mods page, under the mod, with the level error, and the mod's state changes.

When State What you see
The declaration is wrong, or the file throws while loading Failed The reason, once. The other mods load normally.
setup throws Failed The exception.
A handler throws, or runs longer than 30 ms Active One error line per failure.
Three failures in a row, or three overruns in all Disabled disabled: failed 3 times in a row; last error: … or disabled: exceeded the 30ms execution budget 3 times. The mod stays off until the mod host starts again (Reload, or a restart of the game).

The messages you will meet first, quoted as the game writes them:

`hello-hud` requires modding API version 1; this game provides version 2
`version` must be a semantic version such as 1.0.0, got "1.0" (…)
unknown field `descripton`, expected one of id, name, version, …
`main.ts` must declare the mod with `export default defineMod({ … })` at its top level
defineMod must be called exactly once
`hud.text` is not available while the mod loads: call it from `setup` or an event handler

The last one is the most common first mistake: at load time only defineMod, log.* and ctx.on work. Put everything else in setup or in a handler.

Concepts explains what is disabled when, and Troubleshooting lists more messages.

Next

Source in the game repository: content/examples/mods/hello-hud/main.ts,crates/modding/src/manifest.rs,crates/modding/src/package.rs,apps/desktop/src/app/mods.rs,crates/modding/tests/docs_examples_start.rs