Courage.Settings#
require("Courage.Settings") helps build and validate mod settings schemas for CReact / Courage.UI panels.
Schemas are tables with a groups array. Each group has id, title, optional fields, and optional sections which contain their own fields list. Each field has key, label, kind ("bool" or "enum"), and optional options / default.
API#
| Function | Description |
|---|---|
Settings.defaults(schema) | Default values table from schema |
Settings.apply(schema, target) | Fills missing keys in target with defaults |
Settings.validate(schema, values) | Returns ok, errors |
Settings.toUiState(schema, values) | JSON-friendly payload for Courage.UI.setState |
local Settings = require("Courage.Settings")
local UI = require("Courage.UI")
local schema = {
groups = {
{
id = "gameplay",
title = "Gameplay",
fields = {
{ key = "fastText", label = "Fast text", kind = "bool", default = false },
{
key = "difficulty",
label = "Difficulty",
kind = "enum",
default = 0,
options = {
{ value = 0, label = "Normal" },
{ value = 1, label = "Hard" },
},
},
},
},
},
}
local values = Settings.apply(schema, {})
local ok, errs = Settings.validate(schema, values)
UI.setState("my-mod", Settings.toUiState(schema, values))
import * as Settings from "Courage.Settings"
import * as UI from "Courage.UI"
const schema = {
groups: [
{
id: "gameplay",
title: "Gameplay",
fields: [
{ key: "fastText", label: "Fast text", kind: "bool", default: false },
{
key: "difficulty",
label: "Difficulty",
kind: "enum",
default: 0,
options: [
{ value: 0, label: "Normal" },
{ value: 1, label: "Hard" },
],
},
],
},
],
}
const values = Settings.apply(schema, {})
const [ok, errs] = Settings.validate(schema, values)
UI.setState("my-mod", Settings.toUiState(schema, values))
Pair with Courage.UI and CReact guides for interactive panels.