SugarCube Macro Extensions
Estimated reading time: 5 minutesOverview
The framework provides a set of enhanced SugarCube macros focused on multi-language support and UI optimization. These macros let your game text follow the current language setting and offer flexible interface components.
Language-related macros
<<language>>
Shows different content blocks based on the current game language.
Syntax:
Notes:
- Content is chosen by
maplebirch.Language - Supports all languages supported by the framework
- Blocks may contain any valid SugarCube code
Example:
lanSwitch
Returns different text by language; usable as a function or macro.
As a function:
As a macro:
Parameters:
- Multiple string arguments: pass in framework language order
- Object argument:
{ languageCode: text }
Example:
<<lanButton>>
Creates a multi-language button; label updates with the current language.
Syntax:
Parameters:
- First argument: translation key (string)
- Optional: format mode
'title','upper','lower','capitalize','camel','pascal','snake','kebab','constant' class:className: CSS classstyle:inline_style: inline style
Features:
- Button label is translated automatically
- Text format conversion
- Custom styling
- Label updates when language changes
Example:
<<lanLink>>
Creates a multi-language link; text updates with the current language.
Syntax:
Parameters:
- First argument: translation key (string)
- Second (optional): target passage name
- Optional: format mode (same as
convert),class:className,style:inline_style
SugarCube link compatibility:
- Supports
[[text|passage]]form:<<lanLink [[translation_key|passage]]>>
Features:
- Link text translated automatically
- Visited link styling
- Invalid link detection
- Updates on language change
- Tooltip support
- Compatible with native SugarCube link syntax
Example:
<<lanListbox>>
Creates a multi-language dropdown; option labels update with the current language.
Syntax:
Parameters:
- First argument: variable name for selected value (starts with
$or_) - Options:
<<option "translation_key" "value">>,<<optionsfrom "expression">> - Optional:
autoselect,class:className,style:inline_style
Option types:
- Static:
<<option>> - Dynamic:
<<optionsfrom>>— expression may return array, object, Map, Set; re-evaluated on language change
Example:
<<radiobuttonsfrom>>
Creates a set of multi-language radio buttons from a data source.
Syntax:
Parameters:
- First argument: variable for selected value
- Second: option data (multiple formats supported)
- Third (optional): separator between options, default
" | "
Data formats:
- Array:
[ ["Label", value], ... ] - String:
"Option1[value1] | Option2[value2]" - Multi-language:
[ ["English", ["中文", value]], ... ] - Multi-language key-value:
[ {EN: "English", CN: "中文"}, value ]
Example:
<<maplebirchReplace>>
Internal macro for replacing custom overlay content.
Notes:
- Replaces overlay title and content
- Handles overlay show/hide
Example:
Stat and grace display macros
These are provided by maplebirch.tool.macro (defineMacros) for outputting stat changes or Grace as coloured fragments. Typically used in custom widgets or scripts.
statChange
Outputs a coloured fragment for a stat change (e.g. "+ 5", "- 3"), often used in combat or events.
Signature: statChange(statType, amount, colorClass, condition)
Behaviour:
amountis truncated to integer; if result is not finite (e.g.NaN) or0, returns an empty document fragment.- If
V.settings.blindStatsEnabledis true orcondition()isfalse, also returns an empty fragment.
Returns: DocumentFragment (can be inserted into DOM or output by a widget).
grace
Outputs a coloured fragment for Grace changes, used with the temple rank system.
Signature: grace(amount, expectedRank?)
Behaviour:
- Same truncation rules as
statChange; no output in blind mode. - If the player is not in the temple or the
expectedRankcomparison fails, returns an empty fragment; otherwise outputs a coloured fragment similar tostatChange('Grace', amount, ...).
Returns: DocumentFragment.
