Files

39 lines
1.7 KiB
Python

# Docs inputs for the Build engine sections of the image / scene pages (tools/fixtures.py; tools/docs_check.py explains
# the inputs): an ART file of three tiles and a random PALETTE.DAT written here (BUILDINF.TXT layout), and the two-room
# map of tools/fixtures/buildmap.py.
# tests/gen/docs_build.luau { files = { [name] = bytes }, vars = { artBytes = "TILES000.ART", ... } }
import importlib.util, os, struct
INPUTS = ["tools/docs_check.py", "tools/fixtures/buildmap.py"]
def mod(ctx, path, name):
spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, path))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def art(rng, first, tiles):
"""tiles: [(w, h, picanm)]; column-major random indices"""
out = bytearray(struct.pack("<4I", 1, 0, first, first + len(tiles) - 1))
out += b"".join(struct.pack("<h", w) for w, _, _ in tiles)
out += b"".join(struct.pack("<h", h) for _, h, _ in tiles)
out += b"".join(struct.pack("<I", a) for _, _, a in tiles)
for w, h, _ in tiles:
out += bytes(rng.randrange(255) for _ in range(w * h))
return bytes(out)
def generate(ctx):
rng = ctx.rng(5)
check = mod(ctx, "tools/docs_check.py", "docs_check")
bm = mod(ctx, "tools/fixtures/buildmap.py", "fx_buildmap")
pal = bytes(rng.randrange(64) for _ in range(768)) + struct.pack("<H", 1) + bytes(range(256))
files = {
"TILES000.ART": art(rng, 0, [(16, 16, 0), (8, 4, 2 | (2 << 6) | (3 << 24)), (0, 0, 0)]),
"PALETTE.DAT": pal,
"E1L1.MAP": bm.rooms(rng).write(7),
}
check.emit_inputs(ctx, files, {"artBytes": "TILES000.ART", "paletteBytes": "PALETTE.DAT", "buildmapBytes": "E1L1.MAP"})