Core · interface

PreferenceSchema

Persisted player preferences: a validated record in a KeyValueStore.

Explained in The loop.

interface PreferenceSchema<T extends object>
import type { PreferenceSchema } from '@driftengine/core';

In depth

Generic on purpose. A game declares which preferences exist and what their legal values are; everything below — reading, validating field by field, clamping, writing and announcing changes — is the same work in any game.

Where the bytes actually live is the store's problem, not this module's, so a game can persist to the browser, a server or nothing at all without any of this changing. See storage.ts for why that seam is synchronous.

Properties

NameTypeDescription
keyreadonlystringStorage key. Namespace it — the store is shared with everything else.
defaultsreadonlyTThe complete set of fields, and the value each falls back to.
rangesreadonlyoptionalPartial<Record<keyof T, readonly [number, number]>>Inclusive [min, max] for numeric fields. Values outside are clamped.
optionsreadonlyoptionalPartial<Record<keyof T, readonly string[]>>Legal values for string fields. Anything else falls back to the default.