Appearance
GRC plugins
serversideA server script can add its own tools to GRC. rcplugins.register puts a button on the toolbar of every staff member allowed to use it, and clicking the button opens a window whose contents and logic live in your script. Use plugins for staff tools that fit your game better than the generic editors do:
- an item or shop editor over your own tables
- a report viewer, like the top sellers this week
- a moderation panel for warnings and bans
- a quest or dialogue editor
The script never ships HTML or code to GRC. It describes the window as a tree of widgets (forms, tables, lists, tabs, buttons and so on), and GRC draws them with its own controls. Every click and edit comes back to the script as an event. The plugin's data and rules stay on the server, and every plugin looks and behaves like the rest of GRC.
A first plugin
Register the plugin once, from onCreated or at the top of a server script:
ts
rcplugins.register('hello', {
title: 'Hello',
onOpen(win, staff) {
win.set({ type: 'column', children: [
{ type: 'heading', text: `Hi ${staff.account}!` },
{ id: 'name', type: 'input', label: 'Your name' },
{ id: 'greet', type: 'button', text: 'Greet', variant: 'primary' },
] })
win.on('click', 'greet', () => win.toast(`Hello, ${win.values('name') || 'stranger'}!`))
},
})After you save and reload the script, a Hello button appears on the right of the GRC toolbar. onOpen runs each time a staff member opens the window. It receives that window, a RcPluginWindow, and the staff member, an RcStaff. Each open window is separate, so per-window state belongs in local variables inside onOpen, as in the examples on this page. onClose runs when the window closes. That happens when the staff member closes it, when the script calls win.close(), or when they disconnect.
The second argument to register is an RcPluginOptions: title, an optional right, the starting width/height, onOpen and onClose. Plugin ids use letters, digits, _, - and .. Only one script can own an id at a time.
Building the window
win.set(root) replaces the whole window with a widget tree. A widget is a plain object with a type. Give a widget an id when the script needs to change it, read its value or handle its events. Every widget accepts the common props in RcWidgetBase: id, disabled, hidden, flex, width, height and tooltip.
| Widget | type | Notes |
|---|---|---|
RcStackWidget | 'column', 'row' | Lays out children. Use flex: 1 on a child to fill the free space. |
RcSplitWidget | 'split' | Two resizable panes, such as a list on the left and an editor on the right |
RcTabsWidget | 'tabs' | Each child is a tab, labelled by its title |
RcGroupWidget | 'group' | A titled box |
RcHeadingWidget, RcTextWidget, RcSeparatorWidget | 'heading', 'text', 'separator' | Static content |
RcButtonWidget | 'button' | variant: 'primary' or 'danger' |
RcInputWidget | 'input' | inputType is 'text', 'number' or 'password' |
RcTextAreaWidget, RcCheckboxWidget, RcSelectWidget | 'textarea', 'checkbox', 'select' | Select options are RcSelectOptions |
RcCodeWidget | 'code' | GRC's code editor. Set language to 'json', 'typescript' and so on. |
RcTableWidget | 'table' | rows of plain objects. columns are RcTableColumns. |
RcListWidget | 'list' | items are RcListItems |
RcFormWidget | 'form' | Labelled RcFormFields in a grid |
RcImageWidget | 'image' | An image or a crop of one. See Images. |
RcWidget is the union of all of these. Annotate a function's return type with it to get autocomplete as you build trees.
To update part of the window, call win.patch(id, props). It merges props into the widget with that id and leaves the rest of the window alone. Patch a table's rows after a query, { disabled: true } on a button, { hidden: false } on a panel or { text } on a heading. Use { children: [...] } to rebuild a container. For inputs, { value } sets one input and { values: {...} } fills a whole form. Patching keeps what the staff member is typing elsewhere in the window, so prefer it over calling set again.
Images
An RcImageWidget shows any image the game serves to players. Name it the way a game script would, such as 'items.png' or 'icons/sword.png', or pass a data:image/png;base64,… URL. Staff don't need folder rights to see it: the plugin chose the image, and players can already download it. Each image can be up to about 960 KB.
ts
// One 32×32 icon from a sheet, drawn at 2× with crisp pixels
{ id: 'icon', type: 'image', src: 'items.png', rect: '64,0,32,32', scale: 2 }
// Fitted inside 64×64, keeping the aspect ratio
{ type: 'image', src: 'portraits/merchant.png', width: 64, height: 64, smooth: true }- Crop:
rectselects part of the image ('left,top,width,height'or an array). It works like an item'simagerect. - Size:
scalezooms the image. Alternatively,widthandheightfit it inside that box. - Smoothing: pixel art stays sharp unless you set
smooth: true. - Clicks: with an
id, clicking the image fires'click'with the point in source pixels, anRcPluginImageClickEvent. For example, to let staff pick a 32×32 icon from a sheet:
ts
win.on('click', 'sheet', e => {
const rect = `${Math.floor(e.x! / 32) * 32},${Math.floor(e.y! / 32) * 32},32,32`
win.patch('icon', { rect })
})Tables and lists can show images too. An RcImageSource is an image name, or { src, rect } for a crop:
- Tables: give a column
image: true(24 px tall) or a height. Its cells then hold image sources, for example an icon column in an item list. - Lists: give an item an
icon.iconSizesets the height.
Change src with win.patch to swap an image. After a hot reload the window fetches its images again, so a new upload shows up when you reload.
Reading input
Inputs and form fields hold their values in GRC. Each event carries a snapshot of every value in the window, so inside a handler win.values() is always current:
win.values()returns every value, keyed by widget or field id.win.values('price')returns one input's value: a string, a number, a boolean, ornullfor an empty number input.win.values('form')returns an object holding the values of a form's fields or a container's inputs.
Events
Subscribe with win.on(event, id, handler). Handlers can be async. An error they throw is logged and also shown in the window as an error toast.
| Event | Fired by | Handler receives |
|---|---|---|
'click' | buttons | RcPluginEvent |
'change' | inputs and form fields (text after a short typing pause) | RcPluginChangeEvent with value |
'select', 'activate' | a table row or list item, clicked or double-clicked | RcPluginSelectEvent with index and row/item |
'submit' | Enter in one of a form's fields | RcPluginEvent |
'tab' | switching tabs | RcPluginTabEvent with index and title |
A form field fires 'change' under its own id, not the form's.
Feedback and dialogs
win.toast(message, kind)shows a short notification.kindis'info','success','warning'or'error'.win.setTitle(title)renames the window.await win.confirm(message, options)resolvestrueorfalse. Options areRcDialogOptions.await win.prompt(message, options)resolves the text, ornullif cancelled. Options areRcPromptOptions.
Dialogs are asynchronous, and the rest of your script keeps running while one is open.
Rights
Without a right, every staff member sees the plugin. With right: 'items', only staff holding the items right see the button. The server also refuses to open the window and to deliver its events for anyone else, so a modified GRC can't get around it.
A plugin can reuse an existing right such as sql. It can also name a new one, which then shows up as a checkbox in the Staff Rights editor beside the built-in rights. See Staff rights. Staff members without a rights record hold every right, plugin rights included. Staff whose rights you have edited start without the new right until you grant it.
Rights are re-checked on every event. Revoking a right closes that staff member's open windows of the plugin and removes the button. For finer checks inside a plugin, such as a read-only mode for some staff, use staff.hasRight(name) and staff.hasFolderRight(mode, path).
Hot reload
A plugin belongs to the script that registered it. When you save and reload that script, its open plugin windows stay open. If the new version registers the same id, each window is rebuilt by running onOpen again, and GRC shows Plugin reloaded. Edit, reload and look at the result without reopening anything. If the new version stops registering the id, the button disappears and the open windows close a few seconds later.
TIP
Keep the data a plugin edits in SQLite or files, not in variables that a reload would reset. If game scripts cache that data, call their reload function after a save. The example below edits its own table directly.
Example: item editor
A searchable table of items with an editor form beside it. The layout is one function that returns an RcWidget:
ts
function layout(): RcWidget {
return {
type: 'split', size: '55%', children: [
{
type: 'column', children: [
{ id: 'search', type: 'input', placeholder: 'Search items…' },
{
id: 'items', type: 'table', flex: 1, rows: [], empty: 'No items match.',
columns: [
{ key: 'icon', title: '', width: 36, image: 24 },
{ key: 'id', width: 120 }, 'name', { key: 'price', width: 70 }, 'rarity',
],
},
{ id: 'new', type: 'button', text: 'New item…' },
],
},
{
id: 'editor', type: 'column', hidden: true, children: [
{
type: 'row', children: [
{ id: 'preview', type: 'image', src: '', width: 48, height: 48, hidden: true },
{ id: 'title', type: 'heading', text: '' },
],
},
{
id: 'form', type: 'form', fields: [
{ id: 'name', label: 'Name' },
{ id: 'price', type: 'number', label: 'Price', min: 0 },
{ id: 'rarity', type: 'select', label: 'Rarity', options: ['common', 'rare', 'epic', 'legendary'] },
{ id: 'icon', label: 'Icon image', placeholder: 'e.g. sword.png' },
{ id: 'description', type: 'textarea', label: 'Description', rows: 5 },
],
},
{
type: 'row', children: [
{ id: 'delete', type: 'button', text: 'Delete', variant: 'danger' },
{ type: 'column', flex: 1 },
{ id: 'save', type: 'button', text: 'Save', variant: 'primary' },
],
},
],
},
],
}
}The icon preview follows the Icon image field as staff type:
ts
const showIcon = (icon: string): void => {
win.patch('preview', { src: icon, hidden: !icon })
}
win.on('change', 'icon', e => showIcon(String(e.value).trim()))Each event handler reads the form with win.values and patches the table:
ts
win.on('change', 'search', () => refresh())
win.on('select', 'items', e => edit(rows[e.index] ?? null))
const save = async (): Promise<void> => {
if (!current) return
const { name, price, rarity, icon, description } = win.values('form')
if (!String(name).trim()) { win.toast('An item needs a name.', 'error'); return }
await db.exec('UPDATE items SET name = ?, price = ?, rarity = ?, icon = ?, description = ? WHERE id = ?',
[String(name).trim(), Math.max(0, Math.floor(Number(price) || 0)), rarity, String(icon).trim(),
description, current.id])
echo(`[items] ${staff.account} saved ${current.id}`)
await refresh()
win.toast('Saved.', 'success')
}
win.on('click', 'save', save)
win.on('submit', 'form', save)Complete file: itemeditor.ts (a server script)
ts
// An "Item Editor" button in GRC for staff with the "items" right. Items live
// in the SQLite database data/databases/catalog.db; the window lists them in a
// searchable table and edits the selected one in a form, with a live preview
// of the item's icon (any image the game serves, e.g. 'items.png').
interface Item { id: string; name: string; price: number; rarity: string; icon: string; description: string }
const db = opendatabase('catalog')
async function ensureTable(): Promise<void> {
await db.exec(`CREATE TABLE IF NOT EXISTS items (
id TEXT PRIMARY KEY, name TEXT NOT NULL, price INTEGER NOT NULL DEFAULT 0,
rarity TEXT NOT NULL DEFAULT 'common', icon TEXT NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT '')`)
}
async function findItems(search: string): Promise<Item[]> {
const rows = await db.query(
'SELECT id, name, price, rarity, icon, description FROM items WHERE id LIKE ? OR name LIKE ? ORDER BY id',
[`%${search}%`, `%${search}%`])
return rows as unknown as Item[]
}
function layout(): RcWidget {
return {
type: 'split', size: '55%', children: [
{
type: 'column', children: [
{ id: 'search', type: 'input', placeholder: 'Search items…' },
{
id: 'items', type: 'table', flex: 1, rows: [], empty: 'No items match.',
columns: [
{ key: 'icon', title: '', width: 36, image: 24 },
{ key: 'id', width: 120 }, 'name', { key: 'price', width: 70 }, 'rarity',
],
},
{ id: 'new', type: 'button', text: 'New item…' },
],
},
{
id: 'editor', type: 'column', hidden: true, children: [
{
type: 'row', children: [
{ id: 'preview', type: 'image', src: '', width: 48, height: 48, hidden: true },
{ id: 'title', type: 'heading', text: '' },
],
},
{
id: 'form', type: 'form', fields: [
{ id: 'name', label: 'Name' },
{ id: 'price', type: 'number', label: 'Price', min: 0 },
{ id: 'rarity', type: 'select', label: 'Rarity', options: ['common', 'rare', 'epic', 'legendary'] },
{ id: 'icon', label: 'Icon image', placeholder: 'e.g. sword.png' },
{ id: 'description', type: 'textarea', label: 'Description', rows: 5 },
],
},
{
type: 'row', children: [
{ id: 'delete', type: 'button', text: 'Delete', variant: 'danger' },
{ type: 'column', flex: 1 },
{ id: 'save', type: 'button', text: 'Save', variant: 'primary' },
],
},
],
},
],
}
}
export async function onCreated() {
await ensureTable()
rcplugins.register('itemeditor', {
title: 'Item Editor',
right: 'items',
width: 960,
height: 600,
async onOpen(win, staff) {
let rows: Item[] = []
let current: Item | null = null
win.set(layout())
const refresh = async (): Promise<void> => {
rows = await findItems(String(win.values('search') ?? ''))
const index = current ? rows.findIndex(r => r.id === current!.id) : -1
win.patch('items', { rows, selected: index })
}
const edit = (item: Item | null): void => {
current = item
win.patch('editor', { hidden: item === null })
if (!item) return
win.patch('title', { text: `Editing ${item.id}` })
win.patch('form', { values: item })
showIcon(item.icon)
}
const showIcon = (icon: string): void => {
win.patch('preview', { src: icon, hidden: !icon })
}
win.on('change', 'icon', e => showIcon(String(e.value).trim()))
win.on('change', 'search', () => refresh())
win.on('select', 'items', e => edit(rows[e.index] ?? null))
const save = async (): Promise<void> => {
if (!current) return
const { name, price, rarity, icon, description } = win.values('form')
if (!String(name).trim()) { win.toast('An item needs a name.', 'error'); return }
await db.exec('UPDATE items SET name = ?, price = ?, rarity = ?, icon = ?, description = ? WHERE id = ?',
[String(name).trim(), Math.max(0, Math.floor(Number(price) || 0)), rarity, String(icon).trim(),
description, current.id])
echo(`[items] ${staff.account} saved ${current.id}`)
await refresh()
win.toast('Saved.', 'success')
}
win.on('click', 'save', save)
win.on('submit', 'form', save)
win.on('click', 'new', async () => {
const id = (await win.prompt('Item id:', { title: 'New item', placeholder: 'e.g. iron_sword' }))?.trim()
if (!id) return
if (!/^[a-z0-9_]{1,40}$/.test(id)) { win.toast('Use lowercase letters, digits and _.', 'error'); return }
await db.exec('INSERT OR IGNORE INTO items (id, name) VALUES (?, ?)', [id, id])
win.patch('search', { value: '' })
await refresh()
edit(rows.find(r => r.id === id) ?? null)
await refresh()
})
win.on('click', 'delete', async () => {
if (!current) return
const id = current.id
if (!await win.confirm(`Delete ${id}? This can't be undone.`, { okText: 'Delete' })) return
await db.exec('DELETE FROM items WHERE id = ?', [id])
edit(null)
await refresh()
win.toast(`Deleted ${id}.`)
})
await refresh()
},
})
}