vector/gamemaps: own test file (CONTRACT); type fixes in vswap / gamemaps

This commit is contained in:
4DBug committed 2026-11-01 18:54:01 -06:00
1 parent e51fd3585e
commit 69ee08a600
9 files changed
+1143 -1104

No files matched your search

+21 -12
View File
@@ -11333,7 +11333,7 @@ if r:remaining() < 6 then
local b = r.buf
local a = Archive.new("vswap")
local pages= {}
local counts = { wall = 0, sprite = 0, sound = 0 }
local counts= { wall = 0, sprite = 0, sound = 0 }
for i = 0, n - 1 do
local o = buffer.readu32(b, r.base + 6 + i * 4)
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
@@ -11342,13 +11342,19 @@ if r:remaining() < 6 then
elseif o + l > size then
return nil, Err.new(Err.TRUNCATED, "page " .. i .. " past the end", 6 + i * 4)
end
local kind= i < ss and"wall" or(i < so and"sprite" or(i == n - 1 and so < n and"soundinfo" or"sound"
)) local idx = (kind == "wall" and{i }or{(kind == "sprite" and((i - ss ))or((kind == "sound" and((i - so ))or(0
))))})[1] local name = kind == "soundinfo" and"soundinfo" or string.format("%ss/%03d", kind, idx)
local kind, idx= "sound", i - so
if i < ss then
kind, idx = "wall", i
elseif i < so then
kind, idx = "sprite", i - ss
elseif i == n - 1 and so < n then
kind, idx = "soundinfo", 0
end
local name = kind == "soundinfo" and"soundinfo" or kind .. "s/" .. string.format("%03d", idx)
if kind ~= "soundinfo" then
counts[kind]=counts[kind]+ 1
end
table.insert(pages, { kind = kind, index = idx, offset = o, size = l })
table.insert(pages, { kind = kind , index = idx, offset = o, size = l })
Archive.put(a, { name = name, size = l, dir = false, method = "store", page = i, kind = kind, load = Archive.slice(b, r.base + o, l) })
end
a.meta.source = { format = "vswap", chunks = n, spriteStart = ss, soundStart = so, walls = counts.wall, sprites = counts.sprite, soundPages = counts.sound }
@@ -185163,19 +185169,21 @@ end
local function pair(r, opts)
local self = buffer.create(r.limit - r.base)
buffer.copy(self, 0, r.buf, r.base, r.limit - r.base)
local head, maps
if buffer.len(self) >= 8 and buffer.readstring(self, 0, 8) == MAGIC then
local head, maps
if buffer.len(self) >= 8 and buffer.readstring(self, 0, 8) == MAGIC then
maps = self
head = asBuffer(opts and opts.mapHead) or sibling(opts, "MAPHEAD")
if not head then
local got = asBuffer(opts and opts.mapHead) or sibling(opts, "MAPHEAD")
if not got then
return nil, Err.new(Err.UNSUPPORTED, "MAPHEAD not available (opts.mapHead / opts.files / opts.resolve)")
end
head = got
else
head = self
maps = asBuffer(opts and opts.gameMaps) or sibling(opts, "GAMEMAPS")
if not maps then
local got = asBuffer(opts and opts.gameMaps) or sibling(opts, "GAMEMAPS")
if not got then
return nil, Err.new(Err.UNSUPPORTED, "GAMEMAPS not available (opts.gameMaps / opts.files / opts.resolve)")
end
maps = got
end
if buffer.len(head) < 2 then
return nil, Err.new(Err.TRUNCATED, "MAPHEAD")
@@ -185255,7 +185263,8 @@ local p, err = pair(r, opts)
for i = 0, w * h - 1 do
data[i + 1] = buffer.readu16(plane, i * 2)
end
table.insert(tm.layers, { type = "tiles", id = k + 1, name = LAYERS[k + 1], width = w, height = h, data = data, visible = true, opacity = 1, properties = {} })
local layer= { type = "tiles", id = k + 1, name = LAYERS[k + 1], width = w, height = h, data = data, visible = true, opacity = 1, properties = {} }
table.insert(tm.layers, layer)
end
end
tm.properties.name = m.name