model/godot + data/tres + codecs/text/GodotVariant: Godot text scenes (.tscn / .escn) read + write against Godot 4's loader, .tres resources as data
docs/STYLE.md: the layout block lists codecs/text/GodotVariant (DOCS lint).
This commit is contained in:
1 parent
9c02ebdee5
commit
8f26e32a71
24 files changed
+3649
-5
No files matched your search
@@ -0,0 +1,45 @@
|
||||
-- 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
|
||||
Reference in new issue
Block a user