A template tells the game where the parts of a screen stand and how they are wrapped. It is written in TypeScript in theme.ts, and it returns data. This page is the language guide. For the idea behind it, read concepts. For the exhaustive list of constructors and attributes, see the generated nodes reference; for what each screen offers, the contracts reference. Every example below comes from a tested folder: it passes the validator.
How a template runs
The model
theme.ts runs once, when the theme loads (and again when the player chooses Reload themes). It runs in a throwaway script engine on the game's mod thread, with no game API at all: no game, hud, storage, log, no defineMod. It has the language, and the builders that the game puts in front of your source (box, row, text, bind, defineTheme…), which also exist as members of the typed context c.
- The builders return frozen plain values that only they can make.
defineThemehands the whole tree to the game as JSON. A function, aNaNor a cycle in the result is refused; nothing else of your script survives its run. - Because the result is data, you may structure the file as you like: named functions for each zone, tables that drive repetition, helpers, constants. None of it is in the result.
- A script that declares a top-level name of its own (
const box = …,function library) addsexport {};to be a module. - There is no
import. There is no clock (Date), no proxy, no typed array, no weak reference and no web API.RegExpworks.defineThemecan be called once. - Errors in the script (an exception, a wrong argument to a builder, a timeout) fail the whole script: the theme loads without its templates and falls back to
_base. The message is"<id>": theme.ts: <message>with the position in your file.
Budgets
Each script runs under these budgets (ThemeScriptLimits, crates/modding/src/theme.rs). Going over any of them fails the script.
| Budget | Value |
|---|---|
| Wall time of the run | 500 ms |
| Memory of the engine | 16 MiB |
Size of theme.ts |
128 KiB |
| Nodes in the tree the script returns (all templates together) | 4 000 |
| Size of the tree as JSON | 1 MiB |
Limits of the validated tree
After the run, Rust validates the tree. These limits are checked by the validator (crates/themes/src/template/mod.rs):
| Limit | Value |
|---|---|
| Depth of nesting | 24 |
| Nodes in all the templates of one theme | 1 500 |
| Templates (screens and components) | 64 |
| Children of one node | 64 |
| Classes on one node, and conditional classes | 8 each |
Entries of data or of vars on one node |
8 |
Tracks of a grid |
12 |
| Characters of a literal text | 200 |
The typed context
Every template is a function that receives a context c and returns a node. The context is typed by theme.d.ts, a file generated from the table of contracts. In a file that refers to it (see the quick start), write:
// The `c` of the library screen: its input paths, its places and its classes are typed by theme.d.ts.
type Screen = ThemeContext<'screen.library'>;
// The entry point: one template for the screen `screen.library`.
defineTheme({ screens: { library: libraryScreen } });
ThemeContext<'screen.library'> is the builders of the screen screen.library, typed with its input paths, its places, its classes, its variables and its outputs. A path that does not exist, a class that is not allowed, an output with the wrong arguments is a type error in your editor and the same refusal from Rust later. The contract names ('screen.library', 'library.footer') are the keys of ThemeTargets in theme.d.ts.
What theme.d.ts holds, and how to read it:
ThemeContext<K>: the builders for the contractK. Every template function takes one.ThemeTarget_<contract>(for exampleThemeTarget_screen_library): the places (slots), the classes of the host (hostClasses), the variables (cssVars), the outputs with their argument types, and the parts (parts). A comment on each entry says what it is.ThemeScope_<contract>: the paths of the input and the lists thateachloops over, with the scope of their items.ThemeTargets['screen.library']['target']and['scope']: the same pieces by name, when you need to type a helper.
To type a helper that builds the item of a list, take the builders of that list from the scope. The equalizer recipe does it for map.equalizer:
type Screen = ThemeContext<'screen.library'>;
// The element type of `map.equalizer`: `item.bind('live')` reads that bar.
type BarItem = ThemeBuilders<ThemeTargets['screen.library']['target'], ThemeTargets['screen.library']['scope']['lists']['map.equalizer']>;
The untyped globals (box, row, bind('a.b'), on.press('confirm')…) exist too. They accept any string, so they give no completion; prefer c.….
The entry point
defineTheme takes an object with up to two entries:
// The entry point: a screen (to give the list a class of the theme) and two faces.
defineTheme({ screens: { library: libraryScreen }, components: { 'library.setCard': setCard, 'library.chartRow': chartRow } });
screens: one template per screen. The key is the screen's name without itsscreen.prefix:libraryisscreen.library,settingsisscreen.settings; the others aredownload,help,result,lobby,chat,profile,clan,replay,modsandskins.components: one template per contract of a component or a face ('library.footer','library.setCard'). The key is the contract's full name.
A template that you do not write is inherited from _base, then from the game's default render (concepts). A key that is not a screen or a contract is refused with the list of the valid ones (there is no screen "…" (screens: …)).
The constructors in use
The node kinds are a closed list. The nodes reference has every one with every attribute; here are the ones you will use, each in a tested example. In c.row({ attributes }, child, child…) the attributes object comes first and is optional.
Containers
box, row, column and stack hold children: row side by side, column one under the other, stack on top of each other, box a plain block. as picks the HTML element (div, section, header, footer, nav, aside, main, article, ul, li). They take gap and pad (steps 0 to 10 of the --pv-s* spacing tokens), align, justify, wrap and grow. scroll is a scrolling area; spacer is room that grows, or a fixed size.
// The screen: two columns side by side, the list first. `pv-screen` is a class of the screen (the game styles it), `screen` is this theme's, defined in theme.css.
// `--selection-color` is a variable of the screen: the colour of the selected row, read from the input.
function libraryScreen(c: Screen): ThemeNode {
return c.row(
{ class: ['screen', 'pv-screen'], vars: { '--selection-color': c.bind('browser.color') } },
library(c),
selectedMap(c),
);
}
grid lays children out in tracks (auto, 1fr, 120px, 50%, minmax(0,1fr); 12 at most). It is used in the score card of Meters and grids: columns: ['44px', 'minmax(0,1fr)', '150px'].
Text, icons and pictures
text draws a value; as picks span, p, h1 to h3, strong, em, label or small. icon draws one icon of the game's closed list (size 12 to 64). image draws a picture, with a required alt (an empty alt marks it as decoration) and fit. Its source is a file of your images/ folder, or a path of the input (c.bind('map.background')), never a web address.
// The picture and its shade. The `image` node reads a path bound to the input (`map.background`), never a URL of the web.
// It is shown only when the map has a picture.
function backdrop(c: Screen): ThemeNode {
return c.box(
{ class: 'hero-backdrop', role: 'presentation' },
present(c, 'map.background', c.image(c.bind('map.background'), { class: 'hero-art', alt: '', fit: 'cover' })),
c.box({ class: 'hero-shade' }),
);
}
// One tile: a small label with its icon over a big value. `c.t` is the game's translated text for a key.
function factTile(c: Screen, fact: Fact): ThemeNode {
return c.box(
{ class: 'tile' },
c.row({ class: 'tile-head', align: 'center', gap: 1 }, c.icon(fact.icon, { size: 12, class: 'tile-icon' }), c.text(c.t(fact.label), { as: 'small', class: 'tile-label' })),
c.text(fact.value(c), { as: 'strong', class: 'tile-value' }),
);
}
The second example reads a table: each fact is an icon, a translated label and a value. A text may be a list of values, written one after the other: c.text(['+', c.bind('strip.more.count')]).
Buttons and controls
button, toggle and dropdown are the only nodes that can do something. Each takes an on event that calls an output of the screen or contract (see events). button has a variant (primary, plain, quiet), a label and the conditions disabled and pressed; describedBy points to a part that describes it. toggle has label, checked and on.change. dropdown has label, value, options (the path of a list of { value, label, group, detail }), displayValue and on.pick.
// A drop-down list: the options come from the input (`rating.options`), the value is the one in force, and picking an entry calls the output
// `rating.pick` (or `judgement.pick`) with the entry's value appended to the arguments.
function chooser(c: Footer, which: 'rating' | 'judgement'): ThemeNode {
return c.dropdown({
class: 'chooser',
part: which,
label: c.t(which === 'rating' ? 'rating.label' : 'judgement.title'),
value: c.bind(`${which}.value`),
options: `${which}.options`,
displayValue: which === 'judgement' ? c.bind('judgement.label') : undefined,
ariaLabel: which === 'judgement' ? c.bind('judgement.ariaLabel') : c.t('rating.label'),
on: c.on.pick(`${which}.pick`),
});
}
// The main button of a map. It is off in the two states where it cannot start, and the reason is a line of text it points at (`describedBy`), so it stays readable.
function playButton(c: Footer): ThemeNode {
const off = c.field('state').in(['mapBlocked', 'mapRefused']);
return c.row(
{ class: 'go-line', align: 'center', gap: 2 },
c.when(c.field('state').eq('mapBlocked'), c.text(c.bind('reason.text'), { class: 'reason', part: 'reason' })),
c.button({ variant: 'primary', class: 'go', part: 'play', label: c.bind('play.label'), disabled: off, classWhen: { off }, describedBy: 'reason', on: c.on.press('confirm') }),
);
}
The contract of library.footer requires that its confirm output is called by a button: a theme can restyle and move Play, never remove it. If you write the footer without it, you get library.footer: the required output "confirm" is not bound to any control (a button must call it).
Meters and grids
meter draws a gauge from a value, with min, max and a label for assistive technology. It is allowed in a face. This score card puts three columns in a grid, and a gauge under the accuracy:
// One score of the leaderboard, as a FACE: the game keeps the card's plate, its button and the buttons beside it; the theme draws what is inside.
// A `grid` places three columns: the rank, the player with the marks of the play, and the accuracy as a meter under its number.
function scoreCard(c: ScoreCard): ThemeNode {
// A clean run: no misses recorded (`misses` is only there when the card cannot count them by tier). `.and()` joins two conditions.
const clean = c.field('misses').ge(0).and(c.field('misses').lt(1));
// `.not()` turns a condition around: the mark is for plays that DO count for a ranking.
const ranked = c.field('badges.unranked').truthy().not();
return c.grid(
{ class: 'sk', columns: ['44px', 'minmax(0,1fr)', '150px'], align: 'center', gap: 3 },
c.text(c.bind('rank'), { as: 'strong', part: 'rank', class: 'sk-rank' }),
c.column(
{ class: 'sk-main', gap: 1 },
c.row(
{ class: 'sk-head', wrap: true, align: 'center', gap: 1 },
c.text(c.bind('player.label'), { as: 'strong', part: 'name', class: 'sk-name' }),
// The rate with two decimals, and the combo as a compact count (1.9k).
c.text([c.fmt.rate('rate.value', 2), 'x'], { part: 'rate', class: 'sk-tag' }),
c.text(['combo ', c.fmt.count('combo', 1)], { part: 'combo', class: 'sk-tag' }),
c.when(clean, c.text('clean', { class: 'sk-tag sk-good' })),
c.when(ranked, c.icon('trophy', { size: 12, class: 'sk-ranked' })),
),
c.slot('tiers'),
),
c.column(
{ class: 'sk-score', gap: 1 },
// `percent` expects a number that is already a percentage (97.4 gives 97.40%); `fixed` writes a number with a set count of decimals.
c.text(c.fmt.percent('accuracy.value', 2), { as: 'strong', part: 'accuracy', class: 'sk-accuracy' }),
c.meter({ class: 'sk-meter', value: c.bind('accuracy.value'), min: 0, max: 100, label: c.t('facts.best_accuracy') }),
c.when(c.field('misses').gt(0), c.text(['misses ', c.fmt.fixed('misses', 0)], { as: 'small', class: 'sk-meta' })),
),
);
}
Attributes every node takes
| Attribute | Meaning |
|---|---|
class |
Classes: one of your classes (defined in theme.css) or a class the screen or contract lists. Up to 8. A class that is neither is refused; a class that is both is ambiguous. |
classWhen |
{ covered } or { lit: star.field('lit').truthy() }: a class present while a condition holds. |
part |
A data-part of the contract, so a stylesheet or a gesture can find the node. Only the contract's own parts. |
role |
One of group, region, toolbar, tablist, tabpanel, status, search, list, listitem, navigation, none, presentation, img. |
aria |
busy, live, label, pressed, expanded, current, describedby. |
hidden, inert |
Conditions. inert removes the subtree from the keyboard and the accessibility tree. |
focusable |
tabindex="-1": focus by script, never a tab stop. |
data |
data-<name> attributes (at most 24 characters; names the game reserves, layout-* and graph-* are refused). true writes data-name="", false leaves it out. |
vars |
CSS variables: one the screen lists, or your own --tpl-*. Components may use --tpl-* only. Values are text or numbers. |
The order of keyboard focus is the order of the tree (the DOM). There is no positive tabindex. The shortcuts of a screen (arrows, Enter, Escape) never depend on the template.
Bindings, conditions and events
Values
A value is what a node shows or an output receives:
- a literal: a string, a number or a boolean;
c.bind('path'): a path of the input of the screen or contract, read as text, a number or a boolean.[]is only allowed in thefromof aslot;$alias.fieldreads the item inside aneach. A path that holds an object or a list cannot be bound (test it with a condition instead);c.t('key', { name: value }): the game's translated text. A key is lower-case letters, digits,_and.; at most 8 arguments;c.fmt.rate | count | percent | duration | fixed('path', digits?): a number formatted as the game does (concepts);- a list of values, written one after the other.
A path that does not exist is a type error with c. and a validator error at load, with the fields that do exist in its message. At run time, a path that has no data shows nothing and never throws. The paths each contract offers are in the contracts reference.
Conditions
A condition is built from c.field('path'):
.eq(value),.ne(value),.in([values])for text, enumerations and booleans (an enumeration is compared only with its own values;intakes 1 to 16);.gt,.ge,.lt,.lefor numbers;.truthy()and.falsy()for any field, including objects and lists: present, non-empty, non-zero;.and(…),.or(…),.not()to combine. Conditions nest 6 levels deep at most.
Conditions drive when, classWhen, hidden, inert, and the disabled and pressed of a button. The field state that some contracts have is the state of the contract (mapReady, mapBlocked…); the operators have to fit the type of the field.
// The main button of a map. It is off in the two states where it cannot start, and the reason is a line of text it points at (`describedBy`), so it stays readable.
function playButton(c: Footer): ThemeNode {
const off = c.field('state').in(['mapBlocked', 'mapRefused']);
return c.row(
{ class: 'go-line', align: 'center', gap: 2 },
c.when(c.field('state').eq('mapBlocked'), c.text(c.bind('reason.text'), { class: 'reason', part: 'reason' })),
c.button({ variant: 'primary', class: 'go', part: 'play', label: c.bind('play.label'), disabled: off, classWhen: { off }, describedBy: 'reason', on: c.on.press('confirm') }),
);
}
Events
An event is the call an output receives when the player uses a control:
c.on.press('confirm')on abutton: the outputconfirm, no argument.c.on.press('playlist.start', c.bind('playlistId')): arguments come after the name, in the order of the output, with the right types. An argument may be a literal or a value of the input.c.on.change('name', …)on atoggleandc.on.pick('name', …)on adropdown: the control appends its new value (a boolean, a string) as the last argument; you write the ones before it.
The name must be an output of this screen or contract. A name that is not is refused with the list of the valid ones, for example "back" is not an output of screen.library (outputs: …). A component cannot call an output of its screen. A face calls none.
// The two buttons of a playlist: play it map after map, or as one marathon. Each output takes the playlist's id, found in the input.
function playlistButtons(c: Footer): ThemeNode {
const off = c.field('state').eq('playlistBlocked');
return c.row(
{ class: 'go-line', align: 'center', gap: 2 },
c.button({ variant: 'plain', class: 'go', part: 'start', label: c.t('playlists.play'), disabled: off, on: c.on.press('playlist.start', c.bind('playlistId')) }),
c.button({ variant: 'primary', class: 'go', part: 'marathon', label: c.t('playlists.marathon'), disabled: off, on: c.on.press('marathon.start', c.bind('playlistId')) }),
);
}
Places and slots
Placing a place
A screen has places: named positions the game fills with one of its own components. c.slot('footer') puts the footer where you write it. Rules:
- Every required place must be placed at least once, inside a
whenor not (the required slot "footer" is not placed (place it with slot("footer"); inside a when it counts)). The required places are listed in the contracts reference. Optional places may be left out. - A place may be placed more than once (in a
whenbranch and itselse, for example). - You decide the wrapper, the order and the extra nodes around it. You do not decide its content.
// The selected map: the Play strip first (the `footer` place: rating, judgement, Play), then the heading, the tabs and their panels.
// While nothing is selected, `when` draws the heading alone: it is the invitation to pick a map.
function selectedMap(c: Screen): ThemeNode {
return c.column(
{ as: 'section', class: 'map', aria: { label: c.t('ui.selected_map'), busy: c.bind('selection.busy') }, vars: { '--difficulty-color': c.bind('browser.color') } },
c.when(
c.field('selection.shown').truthy(),
[c.box({ class: 'play' }, c.slot('footer')), c.box({ class: 'details' }, c.slot('header'), c.slot('tabs'), c.slot('panels'))],
c.slot('header'),
),
);
}
Here the strip is placed first, and the heading alone stands in for it while nothing is selected.
Mounting a contract
A screen may also mount a contract of the table with the data found at a path: c.slot('library.chartRow', { from: 'entries[]' }). The contract renders with its own template (or the default render), wherever you put it. The path must have exactly the input shape of that contract, and a contract cannot mount itself. Which contracts a screen may mount is in its entry of the contracts reference.
Free places of a component
Inside a component template, c.slot('goal') or c.slot('tiers') is a place the contract leaves free: the game puts one of its own widgets there (a goal mark, a tier count). The contract lists them under slots.
Repeating and choosing: each and when
c.when(condition, then, otherwise?) draws then while the condition holds and otherwise if there is one. Both may be a node or a list of nodes. A small helper makes "only when there is something" easy:
// "Only when": draws `nodes` while the field at `path` is present (not empty, not zero, not null).
function present(c: Screen, path: LibraryPath, ...nodes: ThemeNode[]): ThemeNode {
return c.when(c.field(path).truthy(), nodes);
}
c.each('path', item => node, { as?, key? }) repeats a node for every element of a list of the input. The function receives item, builders typed for the element: item.bind('color') reads the element's own field, item.field('lit') tests it. as names the item for $alias.field paths used by the nodes inside; key names a field that identifies each element. The function must return a node. The equalizer recipe repeats one bar per element:
// The band: a row of bars, drawn only when the map has an equalizer (a playlist has none). `data-listening` is set while the music drives the bars,
// so the stylesheet can light them. `each` repeats `bar` for every element of the list.
function equalizer(c: Screen): ThemeNode {
return c.when(c.field('map.equalizer').truthy(), c.row({ class: 'eq', role: 'presentation', data: { listening: c.bind('map.listening') } }, c.each('map.equalizer', bar)));
}
// One bar: an empty box that hands its live height to the stylesheet as a variable of this theme, `--tpl-live` (a number from 4 to 100).
function bar(item: BarItem): ThemeNode {
return item.box({ class: 'eq-bar', vars: { '--tpl-live': item.bind('live') } });
}
each loops over a list of the input; it never loops over numbers or your own arrays. For your own tables (a list of facts, a list of classes), use ordinary TypeScript (FACTS.map(…)): the tree you return is the result, and the table disappears.
Tab groups, panels alone and the pinned preview
c.tabs({ label, collapsible? }, [{ label, icon?, children }, …]) is a group of tabs of your own: 1 to 12 tabs, each with its name (and an icon from the closed list) and what it shows. The bar is the game's (keyboard, focus, data-selected on the open tab), and the open tab is kept while the screen stays mounted. A group of one tab draws no bar: its content is laid out as it is. A place put in a tab exists only while that tab is open. collapsible: true ends the bar with a fold button (data-part="fold"): folded, the group shows that button alone and carries data-collapsed, which your theme.css turns into a slim strip; the page keeps the folded state for the session. A face cannot hold a group.
On the song selection, each panel of the selected map also has an optional place of its own: infoPanel, leaderboardPanel, modsPanel, trainingPanel, historyPanel, mapsPanel, editorPanel. A panel you place is drawn there, always open, and leaves the tabs bar and panels: nothing is drawn twice. The leaderboard beside the Info panel is c.row({}, c.slot('infoPanel'), c.slot('leaderboardPanel')).
The place visualizer put outside a when that reads browser.visualizer (in a tab of a group, or simply in the screen) is a pinned preview: it starts as soon as it is on screen, follows the selection, never covers the list and never takes the focus or Escape. The Visualize button and key open the tab that holds it when that tab is closed, and otherwise pause and resume it. The game stays usable while it plays. Two shipped themes show it: cinema (a booth down the left edge with two tabs of its own, the preview and the leaderboard placed alone) and blueprint (a view always on beside the drawing's tabs).
Faces
A face is the template of a card that the game keeps drawing the root of: the set card, the difficulty row, the score card (the contracts reference marks every face). You write the inside, as a component template. You read the same input as the default card.
// The set card: a slanted panel on the set's own picture, with the title and the artist over it, then the layout, one round dot per difficulty and the rating range.
// `part` names the parts the game hangs gestures on (Ctrl+click on the artist filters by it).
function setCard(c: SetCard): ThemeNode {
return c.row(
{ class: 'sc', align: 'center', gap: 3 },
panel(c),
c.column(
{ class: 'sc-info', grow: 1, gap: 0 },
c.text(c.bind('title'), { as: 'strong', part: 'title', class: 'sc-title' }),
c.text(c.bind('artist'), { as: 'small', part: 'artist', class: 'sc-artist' }),
c.row({ class: 'sc-foot', align: 'center', gap: 2 }, c.text(c.bind('keysText'), { part: 'keys', class: 'sc-keys' }), dots(c)),
),
c.text(c.bind('rating.range'), { as: 'strong', part: 'rating', class: 'sc-rating' }),
);
}
A face places the game's small widgets where it wants (c.slot('goal'), c.slot('tiers')), loops over lists of the card (strip.chips, the ten stars), and may use part for the gestures the game hangs on parts (Ctrl+click on artist).
// The difficulty row: a round badge with the key count, the name over ten stars, and the rating at the right.
// `stars` is a list of ten entries; the first ones are `lit` according to the rating, and a loop draws one text node for each.
function chartRow(c: ChartRow): ThemeNode {
return c.row(
{ class: 'dr', align: 'center', gap: 3 },
c.box({ class: 'dr-ring', part: 'keys' }, c.text(c.bind('keysText'), { class: 'dr-keys' })),
c.column(
{ class: 'dr-main', grow: 1, gap: 0 },
c.row({ class: 'dr-line', align: 'center', gap: 1 }, c.text(c.bind('name'), { as: 'strong', part: 'name', class: 'dr-name' }), c.slot('missing'), c.slot('goal')),
c.row({ class: 'dr-stars', role: 'presentation' }, c.each('stars', (star: StarItem) => star.text('★', { class: 'dr-star', classWhen: { lit: star.field('lit').truthy() } }))),
),
c.row({ class: 'dr-rate', part: 'rating', align: 'baseline', gap: 1 }, c.text(c.bind('rating'), { as: 'strong', class: 'dr-rating' }), c.text(c.bind('ratingUnit'), { as: 'small', class: 'dr-unit' })),
);
}
What the validator refuses in a face:
| Refused | Why |
|---|---|
button, toggle, dropdown |
They are the game's own controls. A face adds no tab stop and no action. |
A slot that mounts another contract |
A face cannot embed another one. It may place only its own widgets. |
| Any call of an output | There is none to call, and none is required. |
The message reads a button is not allowed in library.setCard: the host draws and owns the card's own button, keyboard, menus and actions…. To reach the card's root in theme.css, use [data-contract='library.setCard'] after a class of your theme; see theme.css.
Screen inputs and outputs
Reading the input
A screen has its own input, built by the game from its stores; a component has its own, usually a slice. For the map selection, the input carries groups such as the selection (its state, colour, whether it is loading, whether it is entering and which tab is open), the browser (the view, whether the list is covered) and the facts of the selected map (null when no map is selected: nothing, a playlist, an invitation). The facts include its artist, title, difficulty, key count, creator, picture, rating, rate, duration, BPM, note counts, density equalizer and skillsets.
Treat what is listed in the contracts reference as the source: it is generated from the contract, always current, and tells for each field its type and its states. When the same path exists in several states (mapReady, mapBlocked…), the validator accepts it if any state has it.
Screen outputs
A screen has outputs of its own, which a button of the screen template may call (a component cannot call them). They are the actions the screen offers: open the menu drawer, pick a random map, open a tab, open the settings. The names and arguments are in the contract of the screen. The Settings window is a screen, and its rail recipe calls none, but places every place it must:
// The window: a left column (the rail) and a right column (the panel), side by side. Every place the contract requires is placed:
// `title`, `search`, `actions`, `close`, `notices`, `rail` and `panel`; `hints` (the keyboard hints) is the only optional one.
function settingsScreen(c: Settings): ThemeNode {
return c.row({ as: 'section', class: 'win' }, rail(c), main(c));
}
// The left column: the title with, under it, how many settings differ from the shipped ones, then the search, the list of categories, and at the foot the window's buttons.
// `changed` is a number of the input of the screen; `c.t` with an argument is the game's translated, pluralised sentence.
function rail(c: Settings): ThemeNode {
return c.column(
{ as: 'aside', class: 'side' },
c.column(
{ class: 'head', gap: 1 },
c.slot('title'),
c.when(c.field('changed').gt(0), c.text(c.t('settings.changed_count', { count: c.bind('changed') }), { as: 'small', class: 'changed' })),
),
c.box({ class: 'find' }, c.slot('search')),
c.slot('rail'),
c.row({ class: 'buttons', align: 'center', gap: 1 }, c.slot('actions'), c.slot('close')),
);
}
c.t('settings.changed_count', { count: c.bind('changed') }) is the game's translated, pluralised sentence. Its argument is a number of the screen's input.
What the validator refuses
Each template is validated alone. A refused template is dropped (the base's, or the game's own render, draws instead) with a notice of the form <contract>[ › <node chain>]: <reason>. The rules, with the messages they give:
- the kinds, attributes, types and sizes of the node list above (
this node has no attribute "…" (it has: …),"…" is not a node kind (kinds: …)); classis a class oftheme.cssor a class the screen or contract lists (the class "…" is neither defined by theme.css nor a class of the game here (game classes: …));- every path exists in the input (
the path "…" is not in the screen: no field "…" in "…" (fields: …)); - the operators go with the type of the field, and an enumeration is only compared with its values;
- every output called exists, with its arguments in order and of the right type; a required output must be called by a control;
- every required place of a screen is placed (
the required slot "…" is not placed); partis a part of the contract;imageis a file ofimages/;- the limits above.
Reading these messages, with a catalogue of the invalid examples, is the subject of reading errors.
Where to look things up
| You want | Look at |
|---|---|
| Every node, attribute and its type | nodes, or hover in your editor |
| What a screen offers: input, outputs, places, classes, variables | contracts |
| Which token does what | tokens |
| A complete working theme to copy | the cookbook |
| What an error means | reading errors |
| The full types | theme.d.ts |