feat(stdlib): Tiled P0.5 — TMX/TSX reader over the XML reader (#68)
Tiled.read / Tiled.read_tsx (runtime/native/tiled.ludic): map the native
XML formats (TMX/TSX/TX) onto the SAME intermediate the JSON path produces
— a Value tree in Tiled's JSON schema — so one format-independent core
(P1) consumes either reader.
- tmx_to_value walks a <map> into {orientation, width/height, tilewidth/
height, tilesets[], layers[]}; every tile layer's <data> is decoded to a
dense GID int list (CSV split, or base64 -> zlib/gzip inflate ->
little-endian u32s), so a CSV .tmx and a base64 .tmj of the same map read
structurally identically.
- External tilesets keep the {firstgid, source} reference (as TMJ does);
embedded tilesets and standalone .tsx (tsx_to_value) inline full geometry
+ per-tile metadata (animation frames, collision objectgroup, class,
properties) for later phases.
- Object layers, shapes (rect/ellipse/point/polygon/polyline/text),
image/group layers and custom properties are parsed into the tree now so
P2/P4/P5 just read it.
- tmj_normalize decodes base64 `data` strings in a parsed .tmj so the JSON
path matches the XML path.
Proven by library/tiled_p05.ludic (30 assertions) incl. the in-repo Kenney
sampleMap.tmx + external sampleSheet.tsx and TMX-vs-TMJ structural
identity. Docs + inventory added; x test: 91 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
79776d1f6a
commit
071c268de7
11 changed files with 5721 additions and 4986 deletions
7
docs/language/tiled/_section.md
Normal file
7
docs/language/tiled/_section.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
id: tiled
|
||||
title: Tiled
|
||||
order: 42
|
||||
---
|
||||
|
||||
Load and draw <a href="https://www.mapeditor.org/">Tiled</a> maps. Both native format families — TMX/TSX/TX (XML) and TMJ/TSJ/TJ (JSON) — read onto one intermediate, a <a href="value"><code>Value</code></a> tree in Tiled's JSON schema, with layer data decoded to a dense GID list; so a CSV <code>.tmx</code> and a base64+zlib <code>.tmj</code> of the same map read identically. <a href="tiled-read"><code>Tiled.read</code></a> returns that intermediate tree for a map file and <a href="tiled-read_tsx"><code>Tiled.read_tsx</code></a> for a tileset file. Spliced on demand when a program mentions <code>Tiled.*</code>, alongside the <a href="xml"><code>Xml</code></a>, <a href="base64"><code>Base64</code></a> and <a href="value"><code>Value</code></a> runtimes it builds on.
|
||||
14
docs/language/tiled/tiled-read.md
Normal file
14
docs/language/tiled/tiled-read.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
id: tiled-read
|
||||
name: Tiled.read
|
||||
category: tiled
|
||||
kind: namespace-method
|
||||
tokens: Tiled.read
|
||||
sig: Tiled.read(path: string) -> value
|
||||
tip: Read a map file into the intermediate value tree.
|
||||
order: 1
|
||||
ns: Tiled
|
||||
member: read
|
||||
---
|
||||
|
||||
Reads a Tiled map file at <code>path</code> — auto-detecting TMX (XML) vs TMJ (JSON) by its first byte — and returns the intermediate map <a href="value"><code>Value</code></a> tree in Tiled's JSON schema: <code>orientation</code>, <code>width</code>/<code>height</code>, <code>tilewidth</code>/<code>tileheight</code>, a <code>tilesets</code> list and a <code>layers</code> list. Every tile layer's <code>data</code> is decoded to a dense GID int list (CSV split, or base64 → zlib/gzip inflate → little-endian u32s), so the two formats yield structurally identical trees.
|
||||
14
docs/language/tiled/tiled-read_tsx.md
Normal file
14
docs/language/tiled/tiled-read_tsx.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
id: tiled-read_tsx
|
||||
name: Tiled.read_tsx
|
||||
category: tiled
|
||||
kind: namespace-method
|
||||
tokens: Tiled.read_tsx
|
||||
sig: Tiled.read_tsx(path: string) -> value
|
||||
tip: Read a tileset file into a value object.
|
||||
order: 2
|
||||
ns: Tiled
|
||||
member: read_tsx
|
||||
---
|
||||
|
||||
Reads a standalone Tiled tileset file at <code>path</code> (TSX or TSJ) and returns a tileset <a href="value"><code>Value</code></a> object: <code>name</code>, <code>tilewidth</code>/<code>tileheight</code>, <code>spacing</code>, <code>margin</code>, <code>columns</code>, <code>tilecount</code>, the <code>image</code> and its size, and a <code>tiles</code> list of per-tile metadata (animation frames, collision shapes, properties). This is what a map's external <code>{firstgid, source}</code> tileset reference resolves to.
|
||||
Loading…
Add table
Add a link
Reference in a new issue