Files
rosetta/tools/fixtures/docs_quake.py
T

50 lines
2.7 KiB
Python

# Docs inputs for the Quake sections of the scene / archive / image / data pages (tools/fixtures.py; tools/docs_check.py
# explains the inputs): the room .map of map.py with its WAD2, the same room compiled by ericw-tools (qbsp + vis, the
# lighting lump filled by _qbsp.light), a gfx.wad-like WAD2 (wad2.py's writer), a qpic .lmp and a random palette.lmp
# (Quake's own is GPL), a Half-Life sprite (spr.py), a shader script and a .skin (q3shader.py).
# tests/gen/docs_quake.luau { files = { [name] = bytes }, vars = { roomMapText = "room.map", ... } }
import importlib.util, os, struct
INPUTS = ["tools/docs_check.py", "tools/fixtures/_qbsp.py", "tools/fixtures/map.py", "tools/fixtures/spr.py",
"tools/fixtures/q3shader.py"]
def mod(ctx, name):
spec = importlib.util.spec_from_file_location("fx_" + name, os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def generate(ctx):
rng = ctx.rng(9)
spec = importlib.util.spec_from_file_location("docs_check", os.path.join(ctx.root, "tools", "docs_check.py"))
check = importlib.util.module_from_spec(spec)
spec.loader.exec_module(check)
H, M, B = mod(ctx, "_qbsp"), mod(ctx, "map"), mod(ctx, "brush")
files = {}
pal = bytes(rng.randrange(256) for _ in range(768))
texwad = H.wad([(n, 0x44, H.miptex(n, w, h, rng)) for n, w, h in M.TEX])
world, door = M.layout(rng)
text = M.write(B, "quake", world, door, rng, "gfx/tex.wad")
files["room.map"] = text
files["tex.wad"] = texwad
res = H.compile(ctx, text.replace("gfx/tex.wad", "tex.wad"), {"tex.wad": texwad}, ["-nopercent"], vis=True)
files["room.bsp"], _ = H.light(H.read_bsp(res["bsp"]), rng)
qp = bytes(rng.randrange(256) for _ in range(24 * 24))
files["palette.lmp"] = pal
files["disc.lmp"] = struct.pack("<II", 24, 24) + qp
mips = [bytes(rng.randrange(256) for _ in range((32 >> m) * (32 >> m))) for m in range(4)]
files["gfx.wad"] = H.wad([("palette", 0x40, pal), ("disc", 0x42, files["disc.lmp"]),
("brick", 0x44, H.miptex("brick", 32, 32, rng, pixels=mips))])
S = mod(ctx, "spr")
files["flame.spr"] = S.sprite(rng, 2, [("single", (-16, 16, 32, 32)), ("group", [0.1, 0.2], [(-8, 8, 16, 16), (-8, 8, 16, 16)])], pal)["data"]
Q = mod(ctx, "q3shader")
files["base.shader"] = Q.SCRIPTS[0]
files["sarge.skin"] = Q.SKINS[0]
check.emit_inputs(ctx, files, {
"roomMapText": "room.map", "texWadBytes": "tex.wad", "roomBspBytes": "room.bsp", "quakePaletteBytes": "palette.lmp",
"discLmpBytes": "disc.lmp", "gfxWadBytes": "gfx.wad", "flameSprBytes": "flame.spr", "shaderText": "base.shader",
"skinText": "sarge.skin",
})