Files
rosetta/tools/fixtures/_godot_encode.luau
2026-11-01 19:25:15 -06:00

46 lines
1.4 KiB
Luau

-- tools/fixtures/_godot_encode: run by tools/fixtures/godot.py (luau CLI, repo root): decodes every Godot scene case
-- (files through resolve) and writes it with our .tscn writer, printing "ours_<name>.tscn\t<hex>" lines for Godot to
-- load, and every .tres case through data/tres ("ours_<name>.tres").
local Godot = require("@rosetta/model/godot")
local Bytes = require("@rosetta/core/Bytes")
local Fx = require("@tests/gen/godot")
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 scene, err = Godot.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 scene then
local out = Godot.encode(scene)
if out then
local base = string.gsub(c.name, "%.%w+$", "")
print("ours_" .. base .. ".tscn\t" .. hex(buffer.tostring(out)))
end
else
print("decode failed " .. c.name .. ": " .. tostring(err))
end
end
local Tres = require("@rosetta/data/tres")
for _, c in Fx.tres do
local v = Tres.decode(Bytes.reader(buffer.fromstring(c.data)))
if v then
local out = Tres.encode(v)
if out then
print("ours_" .. c.name .. "\t" .. hex(buffer.tostring(out)))
end
end
end