-- vector/gamemaps tests: Wolfenstein 3D GAMEMAPS + MAPHEAD written by the fixture's own writer (Carmack near / far -- copies and escapes, RLEW runs and a literal tag) against the source tiles. Fixtures: tools/fixtures/wolf3d.py. local T = require("@tests/T") local F = require("@rosetta") local Gamemaps = require("@rosetta/vector/gamemaps") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") local Err = require("@rosetta/core/Err") local Fx = require("@tests/gen/wolf3d") local t = T.suite("gamemaps") t:eq(Gamemaps.name, "gamemaps", "name") do t:eq(F.detect(Fx.gamemaps, { name = "GAMEMAPS.WL6" }), "gamemaps", "F.detect GAMEMAPS") t:eq(F.detect(Fx.maphead, { name = "MAPHEAD.WL6" }), "gamemaps", "F.detect MAPHEAD") local files = { ["MAPHEAD.WL6"] = Fx.maphead, ["GAMEMAPS.WL6"] = Fx.gamemaps } local list = Gamemaps.maps(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { name = "GAMEMAPS.WL6", files = files }) :: any t:eq(#list, #Fx.maps, "maps listed (slot 2 is -1)") for _, m in Fx.maps do for _, from in { "gamemaps", "maphead" } do local src = if from == "gamemaps" then Fx.gamemaps else Fx.maphead local tm, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(src)), { name = string.upper(from) .. ".WL6", files = files, map = m.slot }) t:check(tm, m.name .. " from " .. from .. ": " .. tostring(e)) local x = tm :: any t:eq(x.width, m.width, m.name .. ": width") t:eq(x.height, m.height, m.name .. ": height") t:eq(x.properties.name, m.name, m.name .. ": name") t:eq(#x.layers, 3, m.name .. ": planes") for k, crc in m.planes do local b = buffer.create(m.width * m.height * 2) for i, v in x.layers[k].data do buffer.writeu16(b, (i - 1) * 2, v) end t:eq(Crc32.of(b), crc, m.name .. ": plane " .. k .. " after Carmack + RLEW") end end end local tm = F.load(Fx.gamemaps, { name = "GAMEMAPS.WL6", files = files }) :: any t:check(tm and tm.kind == "tilemap" and tm.layers[1].name == "walls", "F.load: a TileMap") local _, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps))) t:check(e and e.code == Err.UNSUPPORTED, "no MAPHEAD") local _, e2 = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { mapHead = Fx.maphead, map = 2 }) t:check(e2 and e2.code == Err.ARG, "empty slot") end t:fuzz("gamemaps", function(b: buffer) return Gamemaps.decode(Bytes.reader(b), { mapHead = Fx.maphead, map = 3 }) end, { buffer.fromstring(Fx.gamemaps) }, { mutations = 300 }) t:fuzz("maphead", function(b: buffer) return Gamemaps.decode(Bytes.reader(b), { gameMaps = Fx.gamemaps }) end, { buffer.fromstring(Fx.maphead) }, { mutations = 300 }) t:done()