# gizgame/settings

what a person sets once for every game (its language, sound, look and captions), and the words of a game in that language. The host keeps the settings for the person (a file beside the game's saves, a page's storage) and gives them back at the next start (HostSetup settings); they are no state of the World, so no snapshot holds them.

```gizlang
import * as Settings from "gizgame/settings";
```

## Types

### `Settings`

```gizlang
type Settings = { language: string; volume: f64; sounds: f64; voices: f64; look: f64; invert: bool; captions: bool; bubbles: bool; text: f64; }
```

What a person sets: the LANGUAGE (a tag; "" follows the system's or the browser's), the VOLUME of all sound and the
share of it the game's SOUNDS and the VOICES take (0 to 1), the LOOK speed of a mouse look (times the game's own) and
whether it is INVERTed, whether CAPTIONS show what is said in the chat's log, whether BUBBLES show it over the
speaker, and how many times its drawn size the display's TEXT is (1 to 1.3).

- `language`: `string`
- `volume`: `f64`
- `sounds`: `f64`
- `voices`: `f64`
- `look`: `f64`
- `invert`: `bool`
- `captions`: `bool`
- `bubbles`: `bool`
- `text`: `f64`

### `Lexicon`

```gizlang
class Lexicon { private catalogs = new Map<string, Map<string, string>>(); constructor() { this.add("ko", korean); } add(tag: string, text: string): void { const c = L.canonical(tag); let into = this.catalogs.get(c) ?? new Map<string, string>(); const v = Json.parse(text).valueOr(Json.Json.null()); for (const k of v.keys()) { if (v.field(k).kind === "string") { into.set(k, v.field(k).text()); } } this.catalogs.set(c, into); } tags(): Vec<string> { return ["en", ...this.catalogs.keys()]; } language(s: Settings, asked: string): string { if (s.language !== "") { return L.canonical(s.language); } return L.best([asked], this.tags()) ?? "en"; } say(tag: string, text: string, values: Vec<string> = []): string { let out = text; if (tag !== "en") { out = this.catalogs.get(tag)?.get(text) ?? text; } for (const [at, v] of values.entries()) { out = out.replaceAll(`{${at } }`, v); } return out; } }
```

The words of games in each language beside English, the language they are written in: the engine's own (its
locales/), then a game's (Game.words), each English text to its translation. A text no catalog has stays English.

- `catalogs`: `_gizlang_sdk_collections.Map<string, _gizlang_sdk_collections.Map<string, string>>`

### `Row`

```gizlang
type Row = { section: string; name: string; shows: (s: Settings, language: string, say: (text: string, values: Vec<string>) => string) => string; step: (s: Settings, by: i64) => Settings; share?: (s: Settings) => f64; slide?: (s: Settings, share: f64) => Settings; on?: (s: Settings) => bool; }
```

One row of the settings menu, under its SECTION: its NAME (English, said in the language), what it SHOWS (said in
LANGUAGE by SAY), and how a STEP left (-1) or right (1) changes it. A slider has its SHARE of its range (0 to 1)
and SLIDEs to a share a pointer gives; a switch is ON or off.

- `section`: `string`
- `name`: `string`
- `shows`: `(arg0: M198.Settings, arg1: string, arg2: (arg0: string, arg1: Vec<string>) => string) => string`
- `step`: `(arg0: M198.Settings, arg1: i64) => M198.Settings`
- `share`: `_gizlang_sdk_core.Option<(arg0: M198.Settings) => f64>`
- `slide`: `_gizlang_sdk_core.Option<(arg0: M198.Settings, arg1: f64) => M198.Settings>`
- `on`: `_gizlang_sdk_core.Option<(arg0: M198.Settings) => bool>`

## Functions

### `defaults`

```gizlang
function defaults(): Settings
```

The settings before a person changed any.

### `parsed`

```gizlang
function parsed(text: string): Settings
```

The settings TEXT (JSON) keeps: each field it lacks or has wrong is the default.

Effects: fail, alloc.

### `written`

```gizlang
function written(s: Settings): string
```

The text the host keeps for S.

Effects: fail, alloc.

### `constructor`

```gizlang
constructor()
```

A lexicon of the engine's own catalogs (Korean).

Effects: fail, read, write, alloc.

### `languageName`

```gizlang
function languageName(tag: string): string
```

The name of the language of TAG in itself ("한국어"), for the menu.

Effects: fail, alloc.

### `rows`

```gizlang
function rows(tags: Vec<string>): Vec<Row>
```

The rows of the settings menu, after the row that resumes play. TAGS are the languages a game speaks.

Effects: fail, alloc.

## Methods

### `Lexicon.add`

```gizlang
add(tag: string, text: string): void
```

Adds the translations of catalog TEXT (JSON: each English text to its translation) in the language TAG.

Effects: fail, read, write, alloc.

### `Lexicon.tags`

```gizlang
tags(): Vec<string>
```

The languages it speaks, English first.

Effects: fail, read, alloc.

### `Lexicon.language`

```gizlang
language(s: Settings, asked: string): string
```

The language of S for a person whose system or browser speaks ASKED: the one S names, else the best of ASKED's
that it speaks, else English.

Effects: fail, read, alloc.

### `Lexicon.say`

```gizlang
say(tag: string, text: string, values: Vec<string> = []): string
```

TEXT in the language TAG, with each {0}, {1}... the value at its place in VALUES (after translation, so a
language may put them in another order).

Effects: fail, read, alloc.

