On this page

← All documentation

Add chart tabs and read the local leaderboard

Add a tab or extra sections to the song selection's chart panel with tabs.register and tabs.extend, with typed panels and a closed list of icons, and read a chart's local ranking with leaderboard.query and leaderboard.best.

The song selection shows a panel for the chart you pick, with tabs: Info, Leaderboard, Mods, Training and Editor. A mod can add a tab of its own and sections to Info, Leaderboard and Mods. A mod can also read the local ranking of a chart. Both are declarative and bounded: Rust validates what you name, resolves the numbers for the selected chart and draws it with the active theme's own classes. You never supply markup, a style, an icon file or code, and you never remove or rewrite what the host draws.

Neither feature needs a permission: the local ranking is the player's own data, read-only, and a script never sees a path, a file or the inputs of a replay. Only mods use them, not skins or map scripts. This page assumes you have made a first mod.

A first tab

This mod adds a Skills tab: a rating, chart facts and the plays count; two bars; the five best plays; a note. It also adds a line below the host's Info section.

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

// A tab in the song selection's chart panel, next to Info, Leaderboard and Mods, and one
// extra section in the host's Info tab. Everything is declared in `setup`: the game
// validates it, resolves the numbers for the selected chart and draws it.
export default defineMod({
  id: "chart-tab",
  name: "Chart Tab",
  version: "1.0.0",
  apiVersion: 2,
  author: "You",
  description: "A Skills tab with a rating, chart facts, the best plays and a note.",
  setup() {
    // A `column` field reads the table of a rating of THIS mod, so the rating comes first.
    const calculator = metron.catalog().calculators.find((entry) => entry.id === "etterna-515");
    if (!calculator) return;
    tables.register({
      id: "skills_rating",
      columns: [
        { name: "overall", kind: "number" },
        { name: "stream", kind: "number" },
        { name: "technical", kind: "number" },
      ],
    });
    ratings.register({
      id: "skills",
      name: "Skills",
      calculator: calculator.id,
      unit: "MSD",
      table: "skills_rating",
      column: "overall",
      version: calculator.version,
    });

    tabs.register({
      id: "skills",
      title: "Skills",
      icon: "gauge", // one of the 16 icons of the closed list
      order: 10,
      panels: [
        {
          kind: "metrics",
          title: "Overview",
          fields: [
            { label: "Overall", source: { kind: "column", rating: "skills", column: "overall" }, unit: "MSD", decimals: 1 },
            { label: "Peak density", source: { kind: "chart", metric: "peakNps" }, unit: "NPS" },
            { label: "Plays", source: { kind: "leaderboard", stat: "plays" }, decimals: 0 },
          ],
        },
        {
          kind: "bars",
          title: "Balance",
          max: 40,
          fields: [
            { label: "Stream", source: { kind: "column", rating: "skills", column: "stream" }, unit: "MSD" },
            { label: "Technical", source: { kind: "column", rating: "skills", column: "technical" }, unit: "MSD" },
          ],
        },
        { kind: "leaderboard", title: "Best plays", limit: 5 },
        { kind: "text", title: "Note", text: "Values are those of the base chart, at rate 1.0." },
      ],
    });

    // Sections are added before (`top`) or after (`bottom`) what the host draws; nothing of
    // the host's content is removed or rewritten.
    tabs.extend({
      tab: "info",
      slot: "bottom",
      order: 10,
      panels: [{ kind: "text", text: "Below the host's Info section." }],
    });
  },
});

Copy the folder chart-tab into your mods folder (Mods page, Open folder), select a chart and open the Skills tab, which comes after the host's tabs. The rest of this page explains each part.

A tab: tabs.register

tabs.register adds one tab to the chart panel. It is called from setup, after the ratings.register of any rating its fields read.

Field Rule
id 1 to 32 characters among a-z, 0-9 and -, unique in your mod. The tab's key is <modId>/<id>.
title 1 to 24 characters, no control character. The tab's label.
icon Optional: one of the 16 icons below. layers when absent.
order Optional, 0 to 1000, 0 by default. Orders only compare mods' tabs with each other: they all come after the host's tabs, sorted by order, then by key.
panels 1 to 8 panels.

The closed list of icons (lucide icon names, drawn by the game): layers, info, trophy, star, gauge, activity, chart-bar, list, flame, music, clock, target, sparkles, bookmark, heart, users. Anything else, a path included, is refused (tab icon "x" is not an allowed icon).

A mod adds 4 tabs at most, and 12 are shown in all: the first ones by order, then by key. The others are left out.

Sections in the host's tabs: tabs.extend

tabs.extend adds panels to one of the host's tabs. It is called from setup too.

tabs.extend({
  tab: "leaderboard",
  slot: "top",
  order: 10,
  panels: [{ kind: "text", title: "Tip", text: "Rates change the ranking." }],
});
Field Rule
tab info, leaderboard or mods. Training and Editor are the host's own tools and stay closed.
slot top: before what the host draws; bottom: after it.
order Optional, 0 to 1000. Sections of the same tab and slot sort by order, then by mod id.
panels 1 to 4 panels.

On Info and Mods, your panels are inserted in the scrolling region. On Leaderboard, two bounded bands surround the list: only the list scrolls. A mod extends 4 times at most, and 24 sections are published in all.

Panels

The four panels of a rating exist here with the same shapes and limits (metrics and bars take 1 to 16 fields, radar 3 to 12, timeline 1 or 2 series with different sources, max finite in (0, 1000000]), and two more.

kind Shows Fields
metrics Values side by side title, fields
bars Values with comparison bars title, fields, optional max
radar Named axes title, fields (3 to 12), optional max
timeline The chart's density or BPM over time title, series
leaderboard The best plays of the selected chart under the current judgement: the ranking the Leaderboard tab has already evaluated, no extra request title, limit (1 to 10)
text A static note optional title, text (1 to 280 characters, no control character, no markup, no link)

Panel titles and field labels are 1 to 64 characters. A field is { label, source, unit?, decimals? }: unit is at most 16 characters, decimals is 0 to 3 (1 by default). The source of a field is one of:

source Reads
{ kind: "column", rating, column } A number column of the table of a rating of the same mod, named by its id ("skills", not the key). The host already reads these values for the chart: at the playback rate the player chose when that rating declares panels, otherwise the stored value of the base chart.
{ kind: "chart", metric } A real statistic of the chart: notes, holds, holdPercent, averageNps, peakNps, bpmMin, bpmMax or duration.
{ kind: "leaderboard", stat } A fact of the local ranking: plays (its size), bestPerformance (the rating of the first play, when a performance calculator ranks the board) or bestAccuracy (percent; known only when the ranking is ordered by accuracy or fits on its first page). The unit is the ranking's own.

A value that is not available shows —. The values are never approximated.

Limits

Limit Value
Tabs per mod / in all 4 / 12
Extensions per mod / in all 4 / 24
Tab title 1 to 24 characters
Panels per tab / per extension 1 to 8 / 1 to 4
Panel title, field label 1 to 64 characters
Fields metrics, bars: 1 to 16; radar: 3 to 12
leaderboard panel 1 to 10 plays
text panel 1 to 280 characters
order 0 to 1000
Icons 16, closed list

Tabs follow their mod

A tab and its sections leave with their mod: when it is disabled, fails or is uninstalled, they disappear live. If the displayed tab disappears, the panel goes back to Info. Registering after setup is refused, and so is registering from a skin or a map script.

The local leaderboard

leaderboard.query asks for a page of the ranking of one chart, and leaderboard.best for its first entry. The answer arrives later as the event leaderboard.result, only to the mod that asked. The mods thread never waits.

This mod logs the best local play of the charts a scan adds.

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

// Logs the best local play of the charts a scan just added. A request is answered later by
// the event `leaderboard.result`, and only to the mod that asked; the mod thread never waits.
//
// A mod learns chart ids from `library.chartAdd` and `library.chartsAdded` (the `Song` it
// plays carries none), so this is where its requests start.
export default defineMod({
  id: "best-plays",
  name: "Best Plays",
  version: "1.0.0",
  apiVersion: 2,
  author: "You",
  description: "Logs the best local play of the newly added charts.",
  setup() {
    ctx.on("library.chartsAdded", ({ chartIds }) => {
      for (const chartId of chartIds) {
        // A mod has 2 requests in flight at most: `null` means the limit is reached, so stop.
        if (leaderboard.best({ chartId }) === null) break;
      }
    });

    ctx.on("leaderboard.result", (result) => {
      if (result.error) {
        // English text from the host: an unknown chart, a library that is not ready…
        log.warn(`chart ${result.chartId}: ${result.error}`);
        return;
      }
      const best = result.entries[0];
      if (!best) return; // nobody has played this chart
      // `playerName` is null for an old replay that recorded none; `performance` is null
      // when the chosen calculator could not rate the play.
      const who = best.playerName ?? "unknown";
      const rating = typeof best.performance === "number" ? `${best.performance.toFixed(2)} ${result.performance?.unit ?? ""}` : "no rating";
      log.info(`chart ${result.chartId}: #${best.rank} ${who}, ${best.accuracy.toFixed(2)} %, ${rating} (${result.judgement}, ${result.total} plays)`);
    });
  },
});

A mod learns chart ids from library.chartAdd and library.chartsAdded, as the example does; the Song of a play carries none.

The calls

const requestId = leaderboard.query({ chartId: 42, limit: 20, offset: 40 }); // number | null
const best = leaderboard.best({ chartId: 42 }); // the same as limit 1
Field Rule
chartId The library's chart id: a positive integer.
limit 1 to 100, 20 by default.
offset 0 to 100 000, 0 by default.

leaderboard.best takes an object, { chartId }, not a bare number. A field out of range, of the wrong type or unknown throws.

The return value is a request number, or null when requests pile up: 2 waiting per mod and 16 for all the mods. null is not a failure; ask again later, and handle it as in the example. The host's worker also answers null when it cannot take the job. A request is released when its result is delivered, so a handler of leaderboard.result may ask for the next page at once.

Message Cause
chartId must be a library chart id (a positive integer) A chartId below 1.
limit must be between 1 and 100 A limit out of range.
offset must be at most 100000 An offset out of range.
only mods read the local leaderboard Called by a skin or a map script.
local scores are unavailable The host has no local scores.

The result

leaderboard.result carries:

Field Meaning
requestId The number the call returned.
chartId, offset What you asked for.
total The size of the whole ranking (0 when it failed).
entries The page, in rank order.
judgement The name of the judgement the ranking was evaluated under.
performance { calculator, unit } of the rating calculator that ranked it, or null.
unavailableReplays Plays whose replay could not be read or rejudged: they are not in total.
error An English message when the ranking could not be evaluated (an unknown chart, a library or workers that are unavailable), else null.

An entry:

Field Meaning
rank The place in the whole ranking, from 1.
replayId The replay's id.
playerName The name recorded with the play, or null for an older replay that recorded none. It is never the current player's name.
received true for a replay imported from a file: the name is whoever the file names.
accuracy Percent from 0 to 100, under the current judgement.
performance, performanceNonstandard The calculator's rating, or null when it cannot be calculated; true when the accuracy comes from another model than the calculator's own, so it is not an official pp or SSR.
maxCombo, misses From the rejudgement.
tiers [{ name, count }] in the current judgement's order, the miss listed once.
rate The playback rate the play was recorded at.
modified Played with chart modifiers.
playedAtMs When it was recorded, in ms since the Unix epoch.

What the ranking is

It is the interface's own ranking: every replay of the chart is rejudged with the player's current judgement (see judgement sets), rated by the chosen performance calculator, and ranked by performance when there is one. Accuracy, combo, misses and date only break ties. Abandoned plays do not count. Imported replays do, with received. The board is not cached: each request rejudges the chart, which is why a page is limited to 100 entries and a mod to two requests at a time.

What you will see

The registration errors throw in setup:

Message Cause
tab id must be 1 to 32 characters among a-z, 0-9 and -, got "Skills" An invalid id.
tab title must have 1 to 24 characters, got "" An empty or long title.
tab icon "x" is not an allowed icon An icon outside the list.
order must be between 0 and 1000 An order out of range.
panels must hold 1 to 8 panels No panel, or too many (1 to 4 for an extension).
panel must have 1 to 16 fields The wrong number of fields for the panel (3 to 12 for a radar).
field Overallreads columnxof ratingskills: register that rating first (ratings.register, same mod) and name one of its numeric columns A column source that does not name a number column of a rating registered earlier by this mod.
a leaderboard panel lists 1 to 10 plays A limit out of range.
panel text must have 1 to 280 characters, got "" An empty or long text.
panel text must not contain control characters A line break or another control character.
tab skills is registered twice The same id twice.
a mod registers at most 4 tabs / a mod extends the host's tabs at most 4 times The fifth tab or extension.
tabs.register is only available in a mod's setup / tabs.extend is only available in a mod's setup Called later, or by a skin or a map script.

An unknown kind, an unknown field (style, html) or a value like tab: "training" fails the call: the shapes are closed.

Pitfalls

  • Reading a rating column in a tab before registering that rating: register the table and the rating first.
  • Naming the rating by its key (mod/skills) in a column source: use its id.
  • Expecting the Song of a play to give a chart id for leaderboard.query: only the library events do.
  • Calling leaderboard.query in a loop without testing for null: after two requests it returns null.
  • Passing a number to leaderboard.best: it takes { chartId }.
  • Assuming the order of the ranking is stable: it follows the player's current judgement and performance calculator.

See also

Source in the game repository: crates/modding/src/tabs.rs,crates/modding/src/leaderboard.rs,crates/modding/src/api.rs,crates/modding/src/runtime.rs,content/examples/mods/chart-tab/main.ts,content/examples/mods/best-plays/main.ts,docs/modding.md,docs/mods-leaderboard-et-onglets.md