merge ws/source (codecs/text/KeyValues for .vmt materials)

This commit is contained in:
4DBug committed 2026-11-01 18:46:27 -06:00
commit d8212c6839
15 files changed
+7929 -1132

No files matched your search

+2
View File
@@ -147,6 +147,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| data | plist | .plist | yes | yes | binary: "read", ordered: true | `tests/data/plist.luau` |
| data | snbt | .snbt | yes | yes | ordered: true, typed: true | `tests/data/snbt.luau` |
| data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` |
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
| data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` |
| data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` |
| vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` |
@@ -258,6 +259,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/model/Vrml: VRML97 / X3D scene-graph engine (classic and XML encodings) for model/vrml and model/x3d.
- **text**
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it)
- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT").
- codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting.
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), local-path classification and percent-encoding.
+2 -1
View File
@@ -33,7 +33,7 @@ src/Rosetta/
audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample
SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack
video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry)
text/ Json Nbt Text Url Xml
text/ Json KeyValues Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler SourceAnim Vrml
host/ host (layer 2) runtime adapters; only the api uses them
@@ -244,6 +244,7 @@ them. Anything generic goes down a layer and is called:
| polygons with holes -> triangles | `codecs/model/Polygon` |
| studio model animation values (GoldSrc / Source run-length shorts, Quaternion48 / 64, bone records) | `codecs/model/SourceAnim` |
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
| Valve KeyValues (text, binary, the BSP entity lump) | `codecs/text/KeyValues` |
| Roblox instance trees and property values | `codecs/model/Rbx` |
| bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` |
| CRC-16 (XMODEM / ARC), xxHash32 | `core/Crc16`, `codecs/compress/Xxh32` |
+22 -1
View File
@@ -306,6 +306,26 @@ local xml = assert(F.saveString(p, { format = "plist" }))
assert(string.find(xml, "<key>CFBundleName</key>\n\t<string>Demo</string>", 1, true))
```
## VDF (Valve KeyValues)
`.vdf`, `.acf`, `.res` and other KeyValues files decode to `Types.object`s of strings; a key that repeats gets an array
of its values (`duplicates = "last"` / `"first"` keep one). `[$CONDITION]`s are evaluated for a PC (`defines =
{ OSX = true }` changes the flags, `defines = false` keeps every pair), `#include` / `#base` files come through
`resolve`, `escapes = false` reads backslashes as they are. `pairs = true` gives the ordered pair list of
`codecs/text/KeyValues` (`{ key, value, cond?, type? }`), which keeps everything. Binary KeyValues (`shortcuts.vdf`)
are sniffed; encode with `binary = true`.
```luau
local acf = assert(F.data.load('"AppState"\n{\n\t"appid"\t"440"\n\t"x" "1"\n\t"x" "2"\n}\n', { format = "vdf" }))
assert(acf.AppState.appid == "440" and acf.AppState.x[2] == "2")
local text = assert(F.saveString(acf, { format = "vdf" }))
assert(string.find(text, '\t"x"\t"1"\n\t"x"\t"2"\n', 1, true))
local pairs = assert(F.data.load('"r" { "a" "1" [$X360] }', { format = "vdf", pairs = true, defines = false }))
assert(pairs[1].value[1].cond == "$X360")
local bin = assert(F.save(acf, nil, { format = "vdf", binary = true }))
assert(F.data.load(bin, { format = "vdf" }).AppState.appid == "440")
```
## Save and convert
Data values have no `kind`, so saving needs `opts.format` or a destination extension (an `XmlNode` document too):
@@ -337,6 +357,7 @@ is an error there), CSV needs rows, INI needs sections of scalars, JSON has no b
| toml (`.toml`) | yes | yes | ordered tables, Dates |
| csv (`.csv`, `.tsv`) | yes | yes | rows (arrays or records) |
| ini (`.ini`, `.cfg`, `.conf`, `.desktop`) | yes | yes | sections of strings |
| vdf (`.vdf`, `.acf`, `.res`, `.kv`) | text + binary | text + binary | ordered objects of strings, or pairs |
| msgpack (`.msgpack`, `.mpk`) | yes | yes | values, buffers, Dates |
| cbor (`.cbor`) | yes | yes | values, buffers, Dates, tagged values |
| plist (`.plist`) | XML + binary | XML | values, buffers, Dates |
@@ -351,7 +372,7 @@ Full capability list: [FORMATS.md](../FORMATS.md).
- Luau has one number type: `1.0` reads back as `1`, and TOML / plist write integral floats as integers. Integers
past 2^53 need `bigInts = "string"` to survive.
- An empty plain table `{}` is written as an array; use `F.Types.object()` (or `emptyTable = "object"`) for `{}`.
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, CSV, MessagePack and CBOR without
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, VDF, CSV, MessagePack and CBOR without
its self-describe tag.
- XML whitespace-only text between elements is dropped by default (`whitespace = true` keeps it); text is never
trimmed otherwise.