29 lines
983 B
Luau
29 lines
983 B
Luau
-- tools/fixtures/_ogmo_encode: run by tools/fixtures/ogmo.py (luau CLI, repo root): decodes every Ogmo level with its
|
|
-- project and writes the level and a project made from the map with our encoder, printing "<name>.json\t<hex>" and
|
|
-- "<name>.ogmo\t<hex>" lines for Python to read.
|
|
local Ogmo = require("@rosetta/vector/ogmo")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Fx = require("@tests/gen/ogmo")
|
|
|
|
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 = Ogmo.decode(Bytes.reader(buffer.fromstring(c.data)), { project = c.project })
|
|
if map then
|
|
local lv = Ogmo.encode(map)
|
|
local pj = Ogmo.encode(map, { kind = "project" })
|
|
if lv and pj then
|
|
print(c.name .. ".json\t" .. hex(buffer.tostring(lv)))
|
|
print(c.name .. ".ogmo\t" .. hex(buffer.tostring(pj)))
|
|
end
|
|
end
|
|
end
|