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

+9 -6
View File
@@ -79,19 +79,21 @@ type Pair = { head: buffer, maps: buffer, tag: number }
local function pair(r: Bytes.Reader, opts: DecodeOptions?): (Pair?, Err.Err?)
local self = buffer.create(r.limit - r.base)
buffer.copy(self, 0, r.buf, r.base, r.limit - r.base)
local head, maps
local head: buffer, maps: buffer
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")
@@ -171,7 +173,8 @@ function Gamemaps.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?
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: Types.TileLayer = { 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