vector/ldtk: LDtk projects read + write as a TileMap (levels as groups, worlds, IntGrid / auto / tile / entity layers, fields, external levels through resolve)
This commit is contained in:
1 parent
524179ec67
commit
1f74419ccf
11 files changed
+1557
-6
No files matched your search
@@ -0,0 +1,30 @@
|
||||
-- tools/fixtures/_ldtk_encode: run by tools/fixtures/ldtk.py (luau CLI, repo root): decodes every LDtk case (external
|
||||
-- levels through resolve) and writes it with our encoder, printing "<name>\t<hex>" lines for Python to summarise.
|
||||
local Ldtk = require("@rosetta/vector/ldtk")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Fx = require("@tests/gen/ldtk")
|
||||
|
||||
local HEX = {}
|
||||
for i = 0, 255 do
|
||||
HEX[i] = string.format("%02x", i)
|
||||
end
|
||||
local function hex(s: string): string
|
||||
return (string.gsub(s, ".", function(c: string): string
|
||||
return HEX[string.byte(c)]
|
||||
end))
|
||||
end
|
||||
|
||||
for _, c in Fx.cases do
|
||||
local map = Ldtk.decode(Bytes.reader(buffer.fromstring(c.data)), {
|
||||
resolve = function(p: string): buffer?
|
||||
local f = c.files[p]
|
||||
return if f then buffer.fromstring(f) else nil
|
||||
end,
|
||||
})
|
||||
if map then
|
||||
local out = Ldtk.encode(map)
|
||||
if out then
|
||||
print(c.name .. "\t" .. hex(buffer.tostring(out)))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user