vector formats: comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:53:48 -05:00
1 parent d91dc6c597
commit 89a2047349
10 files changed
+34 -126

No files matched your search

+1 -9
View File
@@ -1,6 +1,5 @@
--!strict
-- vector/tiled/Tmx: the TMX (XML) half of vector/tiled: a codecs/text/Xml tree <-> a Types.TileMap, and TSX tilesets.
-- TMX map format, Tiled 1.12 docs. Never throws: failures return nil, message, unsupported?.
-- vector/tiled/Tmx: TMX / TSX (TMX map format, Tiled 1.12 docs) <-> a Types.TileMap.
local Xml = require("@rosetta/codecs/text/Xml")
local Types = require("@rosetta/Types")
local Data = require("@rosetta/vector/tiled/Data")
@@ -28,7 +27,6 @@ local function flag(n: Node, k: string, default: boolean): boolean
end
-- ------------------------------------------------------------------------------------------------ read
-- <properties> -> values, types (types only for the non-string ones)
local function properties(n: Node?): ({ [string]: any }, { [string]: string }?)
local props: { [string]: any } = {}
local types: { [string]: string }? = nil
@@ -68,7 +66,6 @@ local function withProps(t: any, n: Node)
end
end
-- the gids of a <data> (or <chunk>) node
local function gids(d: Node, encoding: string?, compression: string?): ({ number }?, string?, boolean?)
if encoding == "csv" then
return Data.csv(Xml.text(d))
@@ -233,7 +230,6 @@ layer = function(n: Node): (any, string?, boolean?)
return nil
end
-- a <tileset> element (in a map, or a .tsx root) -> Tileset
function Tmx.tileset(n: Node): any
local ts: any = {
firstGid = num(n, "firstgid", 1),
@@ -287,7 +283,6 @@ function Tmx.tileset(n: Node): any
return ts
end
-- read(root) -> TileMap | nil, message, unsupported?
function Tmx.read(root: Node): (any, string?, boolean?)
if root.name ~= "map" then
return nil, "the root element is <" .. root.name .. ">, not <map>"
@@ -330,7 +325,6 @@ end
type Attrs = { [string]: string }
local function el(name: string, attrs: { { any } }, children: { any }?): Node
-- attrs in order; nil / default values dropped by the caller
local o = Types.object()
for _, kv in attrs do
if kv[2] ~= nil then
@@ -533,7 +527,6 @@ writeLayer = function(l: any, o: WriteOptions): (Node?, string?)
return nil, "unknown layer type " .. tostring(t)
end
-- tilesetNode(ts, inMap) -> <tileset>
function Tmx.tilesetNode(ts: any, inMap: boolean): Node
if inMap and type(ts.source) == "string" then
return el("tileset", { { "firstgid", ts.firstGid or 1 }, { "source", ts.source } })
@@ -578,7 +571,6 @@ function Tmx.tilesetNode(ts: any, inMap: boolean): Node
}, kids)
end
-- write(map, opts) -> an XML document node | nil, message
function Tmx.write(map: any, o: WriteOptions): (Node?, string?)
local kids = {}
addProps(kids, map)