vec: vector/tiled (TMX + TMJ + TSX/TSJ read/write into TileMap: all data encodings, chunks, objects, typed properties, tilesets as references); core/Base64 (new, small); Types: TileMap.new + open TileMap/Tileset/TileLayer fields; api: F.save passes the destination extension as opts.format when none is given (tmx vs tmj). Tests vs Tiled exports and Tiled reading our files

This commit is contained in:
4DBug committed 2026-10-31 08:54:35 -05:00
1 parent 63294e13bd
commit a762554f2c
13 files changed
+2239 -3

No files matched your search

+32
View File
@@ -111,6 +111,32 @@ local function aseDoc(): Types.Layered
return doc
end
-- a Tiled map (tools/fixtures/tiled.py has Tiled read our TMX and TMJ of it)
local function tiledMap(): Types.TileMap
local m: any = Types.TileMap.new(5, 4, 16, 16)
m.nextLayerId, m.nextObjectId = 5, 4
m.properties = { name = "ours", n = 7, f = 0.5, ok = false, c = "#ff112233" }
m.propertyTypes = { c = "color" }
m.tilesets = { { firstGid = 1, name = "tiles", tileWidth = 16, tileHeight = 16, columns = 4, count = 8, spacing = 0, margin = 0, imageSource = "tiles.png", imageWidth = 64, imageHeight = 32, properties = {}, tiles = { { id = 2, class = "Wall", properties = { hard = true } }, { id = 4, properties = {}, animation = { { tileId = 4, duration = 120 }, { tileId = 5, duration = 80 } } } } } }
local data = {}
for i = 1, 20 do
data[i] = (i * 3) % 9
end
data[2] += 0x80000000
data[10] += 0x40000000
local tiles = { type = "tiles", id = 1, name = "ground", width = 5, height = 4, data = data, visible = true, opacity = 0.8, offsetX = 2, offsetY = 0, properties = { deep = 3 }, encoding = "base64", compression = "zlib" }
local objs = {
{ id = 1, name = "a", class = "Spawn", x = 4, y = 5.5, width = 8, height = 8, rotation = 30, visible = true, shape = "rectangle", properties = { team = "red" } },
{ id = 2, name = "b", class = "", x = 20, y = 10, width = 0, height = 0, rotation = 0, visible = true, shape = "polyline", points = { { 0, 0 }, { 8, 4 }, { 16, 0 } }, properties = {} },
{ id = 3, name = "c", class = "", x = 30, y = 30, width = 60, height = 14, rotation = 0, visible = false, shape = "text", text = { text = "hi there", fontFamily = "sans-serif", pixelSize = 14, wrap = true, color = "#00ff00", bold = false, italic = true, underline = false, strikeout = false, kerning = true, halign = "right", valign = "top" }, properties = {} },
}
local og = { type = "objects", id = 3, name = "things", visible = true, opacity = 1, drawOrder = "topdown", objects = objs, properties = {} }
local img = { type = "image", id = 4, name = "sky", visible = true, opacity = 1, imageSource = "sky.png", imageWidth = 40, imageHeight = 20, repeatX = true, repeatY = false, properties = {} }
local group = { type = "group", id = 2, name = "grp", visible = true, opacity = 0.5, layers = { og, img }, properties = {} }
m.layers = { tiles, group }
return m
end
local which = ...
if which == "psd" then
local Psd = require("@formats/layered/psd")
@@ -132,4 +158,10 @@ elseif which == "aseprite" then
frames[f] = hex((LayerOps.flatten(doc, { frame = f }) :: Types.Image).pixels)
end
print(json({ data = hex(data), nframes = 3, frames = frames }))
elseif which == "tiled" then
local Tiled = require("@formats/vector/tiled")
local m = tiledMap()
local tmx = Tiled.encode(m, { format = "tmx" }) :: buffer
local tmj = Tiled.encode(m, { format = "tmj" }) :: buffer
print(json({ tmx = hex(tmx), tmj = hex(tmj) }))
end