Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / topmenu

TopMenu

Admin & chat

@s2script/sdk/topmenu

Shared admin/top-menu registry. Plugins declare a tab with addTab({ id, title }) then addItem(tabId, item). Items default to the admin sheet (sm_admin); opt into the player hub (sm_menu) with sheets: ["menu"]. Snapshot tabs is { id, title }[]; categories stays tab ids.

Import

import { TopMenuSheet } from "@s2script/sdk/topmenu";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

type
TopMenuSheet
interface
TopMenuTab

A plugin-owned dashboard tab. id is the TopMenuItem grouping key (addItem first argument); title is what the hub paints on the tab bar.

id: string
— Stable id, e.g. "playercommands". A duplicate id updates the title.
title?: string
— Tab label. Defaults to TopMenuTab.id.
interface
TopMenuItem

A single registered top-menu entry (an admin command surfaced in the adminmenu).

id: string
— Plugin-namespaced unique id, e.g. "playercommands:slap". A duplicate id replaces.
name: string
— Shown label.
flags: number
— Required ADMFLAG bit mask (adminmenu hides items the caller lacks flags for).
sheets?: TopMenuSheet[]
— Sheets in which this item is rendered. Defaults to the admin sheet.
onSelect: (adminSlot: number) => void
— Runs in THIS plugin's context when an admin selects the item; receives the admin's 0-based slot.
interface
TopMenuSnapshot

A handler-free copy of the whole registry — what a menu renderer reads to build the display.

categories: string[]
— Tab ids, in registration order. Same sequence as TopMenuSnapshot.tabs.
tabs: { id: string; title: string }[]
— Dashboard tabs with display titles. addCategory(name) is { id: name, title: name }.
items: { id: string; category: string; name: string; flags: number; sheets: TopMenuSheet[] }[]
— Every registered item's metadata (no onSelect), tagged with its tab id (category).
const
TopMenu

The shared admin/top-menu registry — renderers read TopMenu.snapshot and dispatch picks through TopMenu.select; items are contributed by plugins via topmenu.

import { TopMenu } from "@s2script/sdk/topmenu";
const snap = TopMenu.snapshot();
for (const cat of snap.categories) renderCategory(cat);
// when the admin picks an item id, dispatch it back to its owner plugin:
m.onSelect(e => { TopMenu.select(e.info, slot); });
snapshot(): TopMenuSnapshot
— All categories + item metadata (no handlers) — the adminmenu renderer reads this.
select(id: string, slot: number): void
— Fire an item's onSelect (dispatched post-frame to the owner's context).
Back to modules All packages