Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule preset.module·originates fromworld 07158574-5…

document

A preset's `preset.yaml`: decoding it, reading it and writing it.

by◐lumi·posted 2d ago
What it does

document

A preset's preset.yaml: decoding it, reading it and writing it.

The typed form names the declarer the values are for and the values:

target: { __ref: "<guid>", type: assetType, name: texture }
values:
  filter: nearest

target is written as a guid envelope, which the preset's .refs pins by guid; type and the target's plain name say what it points at to a person reading the file, and name is never an identity, so the guid is the one link. A target written as an identity string ("@builtin::assetTypes.texture", or a world asset's identity) is accepted on read. The component-only form, component: + properties:, reads as authored.

Exports

  • Document.pathOf(ref) -> string
  • Document.decode(body: string) -> Doc
  • Document.read(ref) -> Doc
  • Document.encode(envelope: Envelope, values) -> string
  • Document.write(ref, envelope: Envelope, values)

Types:

  • Envelope = { __ref: string, type: string?, name: string? }
  • Doc = { format: "typed" | "legacy", target: string?, envelope: Envelope?, component: string?, title: string?, values: { [string]: any } }

Usage

local Document = require("@builtin::modules.preset.document")
local doc = Document.read(presetRef)

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

module PresetDocument A preset's `preset.yaml`. The typed form names the declarer the values are for (`target`) and the values themselves (`values`). `target` is written as a guid envelope, `{ __ref: <guid>, type: <type>, name: <name> }`, which `.refs` pins by that guid; an identity string is accepted on read. The component-only form names a component by its registered name (`component`) and lists `properties`.

trim(s: ?) → void

argtypedescription
s?

starts_with(s: ?, prefix: ?) → void

argtypedescription
s?
prefix?

decode_scalar(raw: ?) → void

argtypedescription
raw?

parse_preset_yaml(content: ?) → void

argtypedescription
content?

typed(target: any, values: any) → Doc

The typed Doc for a decoded `target` value, or nil when `target` is neither an envelope nor an identity string.

argtypedescription
targetany
valuesany

pathOf(ref: any) → string

The `preset.yaml` path of a preset asset.

argtypedescription
refanyThe preset.

examples

local path = Document.pathOf(presetRef)

decode(body: string) → Doc

Decode a `preset.yaml` body. A body with a `target` is typed; a body with `component` or `properties` is component-only. A component-only body `Yaml.decode` refuses is read by the line parser presets have always been read with. A typed body that does not decode, or whose `target` is neither an envelope nor an identity string, raises.

argtypedescription
bodystringThe file's text.

examples

local doc = Document.decode(vfs.read(path))

read(ref: any) → Doc

Read and decode a preset's `preset.yaml`.

argtypedescription
refanyThe preset.

examples

local doc = Document.read(presetRef)

encode(envelope: Envelope, values: { [string]: any }) → string

The typed `preset.yaml` body for a target envelope and values.

argtypedescription
envelopeEnvelopeThe target, `{ __ref = <guid>, type = <type>, name = <name> }`.
values{ [string]: any }The values.

examples

local body = Document.encode(Target.envelopeFor(texType), { filter = "nearest" })

write(ref: any, envelope: Envelope, values: { [string]: any }) → void

Write the typed `preset.yaml` for a target envelope and values, raising when the write does not land. Inside an open undo operation the write is recorded into it, so undoing the operation puts back what the file held.

argtypedescription
refanyThe preset.
envelopeEnvelopeThe target envelope.
values{ [string]: any }The values.

examples

Document.write(presetRef, envelope, { filter = "nearest" })
⌬ Types
Envelope = { __ref: string, type: string?, name: string? }Doc = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

10items
·
other · born here
▤file
▲ 0↑ born
▣
module · born here
❒asset
# json JSON encode/decode library for Luau. Encodes Lua values to JSON strings and decodes JSON strings back to Lua values. Used for communication with the Rust side of the engine, the VFS read/write bridge, and any wire-format that needs JSON. Pure Luau, no engine dependencies. Compact and pretty-printed encoders, plus a hand-rolled decoder that streams the input by position so it works under WASM as well as native. ## Exports - `Json.encode(value: any, indent?: string, currentIndent?: string) -> string` — compact encode. Functions / unknown types and NaN/Inf encode as `null`. - `Json.encodePretty(value: any, indentStr?: string) -> string` — pretty-printed encode with sorted object keys (diff-friendly). - `Json.encodeArgs(...: any) -> string` — encode varargs as a JSON array. - `Json.decode(str: string) -> any` — decode a JSON string. Returns the decoded value, or `nil` + error message on failure. ## Usage ```luau local Json = require("@builtin::modules.json") local widget = { type = "button", text = "Click Me" } local compact = Json.encode(widget) -- '{"text":"Click Me","type":"button"}' local pretty = Json.encodePretty(widget, " ") local decoded = Json.decode(compact) local v, err = Json.decode("oops") -- v = nil, err = error message ``` ## Notes - Object keys are sorted alphabetically in both encoders for consistent output across runs. - Numeric keys on objects are stringified at encode time (JSON has no numeric keys). Pure-integer key sets get detected as arrays via `isArray` and encoded with brackets. - NaN, +Inf, -Inf encode as `null` — JSON has no representation. Round trips through `decode` recover `null` (Lua `nil`), so they don't preserve. - Unicode `\uXXXX` escapes decode to UTF-8 by hand to stay WASM-safe. Only the BMP is covered; supplementary planes via surrogate pairs are not. - Functions encode as `null`. - Decode is character-streamed — no regex, no `string.match` patterns on the whole input — so the line-and-column information needs to be reconstructed from the position offset.
▲ 0↑ born
▣
module · born here
❒asset
# yaml.module YAML decode + encode for authored engine content. Pure Luau, no engine dependencies — a general parsing library, not data-system plumbing. ```luau local Yaml = require("@builtin::modules.yaml") local doc = Yaml.decode(vfs.read(path)) vfs.write(path, Yaml.encode(doc)) ``` ## Supported subset - Block mappings (`key: value`) and block sequences (`- item`), nested to any depth. - Compact sequence-of-mapping entries (`- path: x` / ` kind: y`). - Flow collections — `{ a: 1, b: 2 }` and `[1, 2, 3]` — single line. - Plain scalars with type inference: `~` / `null` → nil, `true` / `false` → boolean, numeric literals → number, everything else → string. - Single- and double-quoted strings (`''` escapes a literal quote inside a single-quoted string; `\n` `\t` `\r` `\\` `\"` inside a double-quoted one). A quote opens a quoted scalar where a scalar begins — after `key:`, after a `- ` entry marker, or inside a flow collection — so a plain scalar carries an apostrophe as data (`note: the world's rules`). Quoted keys are read in flow mappings. - `#` comments — honored outside quotes, so a `#` inside a quoted string is kept as data. - Literal (`|`) and folded (`>`) block scalars — the bare indicators only. A block scalar's content is literal text: quotes (balanced or not), `#`, `key: value` and `---` inside it are data. - An optional leading `---` document marker. ## Loud-error contract Constructs outside the subset above raise instead of misparsing: anchors/aliases (`&`, `*`), tags (`!`), directives (`%`), multi-document streams (a second `---`), block-scalar chomping/indentation indicators (`|-`, `|+`, `>-`, `|2`, ...), tab indentation, and inconsistent indentation (both block structure and block-scalar bodies). Every error carries the offending line number (`yaml: line N: ...`), so a bad config points straight at the line to fix. Tab indentation is rejected everywhere — including block-scalar body lines whose leading whitespace contains a tab. A tab after the first non-space character of a line is content and passes through. ## API - `Yaml.decode(text: string): any` — decode a YAML document into a Luau value (table, scalar, or nil for an empty document). Raises on malformed input or an unsupported construct. - `Yaml.decodeWithComments(text: string): (any, boolean)` — decode as `decode` does, and report whether the text carries a comment by the decoder's own rule: a `#` at a line's start or after whitespace, outside a quoted scalar and outside a block scalar. Re-encoding the value drops such comments, so an editor that writes a document back reads this first. - `Yaml.encode(value: table): string` — encode a Luau table as YAML (block style, two-space indent, alphabetically sorted keys). Raises on values YAML can't represent (functions, userdata, non-string mapping keys). A top-level empty table encodes to an empty document, which decodes back to `nil` (the YAML empty-document ambiguity).
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.