# archive/wad2 fixtures (tools/fixtures.py): a Quake gfx.wad-like WAD2 (palette, conchars, a qpic, miptex textures, one # '{' keyed) and a Half-Life WAD3 (miptex with their palettes, a qpic with its palette, a font), written with # tools/fixtures/_qbsp.py's WAD writer from wad.h; expected pixels decoded here (index -> palette, 255 or 0 keyed); # plus the WAD2 compiled into a map by ericw-tools qbsp (it reads the miptex lumps: the BSP's copies must match). # tests/gen/wad2.luau { wad2 = { data, palette, images = { [name] = { w, h, crc, kind } } }, wad3 = ..., bsp } import importlib.util, os, struct, zlib INPUTS = ["tools/fixtures/_qbsp.py"] def helper(ctx): spec = importlib.util.spec_from_file_location("_qbsp", os.path.join(ctx.root, "tools", "fixtures", "_qbsp.py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def rgba(pix, pal, key=None): out = bytearray() for i in pix: if key is not None and i == key: out += pal[i * 3:i * 3 + 3] + b"\0" else: out += pal[i * 3:i * 3 + 3] + b"\xff" return zlib.crc32(bytes(out)) def generate(ctx): H = helper(ctx) rng = ctx.rng(22) pal = bytes(rng.randrange(256) for _ in range(768)) images = {} lumps = [("palette", 0x40, pal)] con = bytes(rng.randrange(256) for _ in range(128 * 128)) lumps.append(("conchars", 0x44, con)) images["conchars"] = {"w": 128, "h": 128, "crc": rgba(con, pal, 0), "kind": "conchars"} qw, qh = 24, 10 qp = bytes(rng.randrange(256) for _ in range(qw * qh)) lumps.append(("disc", 0x42, struct.pack("> m) * (h >> m))) for m in range(4)] lumps.append((name, 0x44, H.miptex(name, w, h, rng, pixels=mips))) images[name] = {"w": w, "h": h, "crc": rgba(mips[0], pal, 255 if name[0] == "{" else None), "kind": "miptex", "mip2": rgba(mips[2], pal, 255 if name[0] == "{" else None)} wad2 = H.wad(lumps) out = {"wad2": {"data": wad2, "palette": pal, "images": images, "names": [l[0] for l in lumps]}} # WAD3 images3 = {} lumps3 = [] for name, w, h in (("CRETE", 32, 32), ("{GRATE", 16, 32)): p3 = bytes(rng.randrange(256) for _ in range(768)) mips = [bytes(rng.randrange(256) for _ in range((w >> m) * (h >> m))) for m in range(4)] lumps3.append((name, 0x43, H.miptex(name, w, h, rng, p3, pixels=mips))) images3[name] = {"w": w, "h": h, "crc": rgba(mips[0], p3, 255 if name[0] == "{" else None), "kind": "miptex"} p3 = bytes(rng.randrange(256) for _ in range(768)) qp = bytes(rng.randrange(256) for _ in range(20 * 12)) lumps3.append(("LOGO", 0x42, struct.pack("