vector/gamemaps: own test file (CONTRACT); type fixes in vswap / gamemaps
This commit is contained in:
1 parent
e51fd3585e
commit
69ee08a600
9 files changed
+1143
-1104
No files matched your search
@@ -85,7 +85,7 @@ function Vswap.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
local b = r.buf
|
||||
local a = Archive.new("vswap")
|
||||
local pages: { Page } = {}
|
||||
local counts = { wall = 0, sprite = 0, sound = 0 }
|
||||
local counts: { [string]: number } = { 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)
|
||||
@@ -94,13 +94,19 @@ function Vswap.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
elseif o + l > size then
|
||||
return nil, Err.new(Err.TRUNCATED, "page " .. i .. " past the end", 6 + i * 4)
|
||||
end
|
||||
local kind: any = if i < ss then "wall" elseif i < so then "sprite" elseif i == n - 1 and so < n then "soundinfo" else "sound"
|
||||
local idx = if kind == "wall" then i elseif kind == "sprite" then i - ss elseif kind == "sound" then i - so else 0
|
||||
local name = if kind == "soundinfo" then "soundinfo" else string.format("%ss/%03d", kind, idx)
|
||||
local kind: string, idx: number = "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 = if kind == "soundinfo" then "soundinfo" else kind .. "s/" .. string.format("%03d", idx)
|
||||
if kind ~= "soundinfo" then
|
||||
counts[kind] += 1
|
||||
end
|
||||
table.insert(pages, { kind = kind, index = idx, offset = o, size = l })
|
||||
table.insert(pages, { kind = kind :: any, 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 }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user