#!/usr/bin/env python3 """Original, code-authored pixel art. Standard library only; no external art input.""" import argparse import hashlib import json from pathlib import Path import struct import zlib ROOT = Path(__file__).resolve().parents[1] BANK_UUID = "baec0001-2026-4000-8000-000000000001" SCENE_UUID = "baec0001-2026-4000-8000-000000000002" PALETTE = [0x00000000, 0x101c2aff, 0x233549ff, 0x39556aff, 0x70aec0ff, 0xc9edf0ff, 0x4de3b5ff, 0x269281ff, 0xffbf69ff, 0xe27858ff, 0xb95772ff, 0x675b8fff, 0xf9ead3ff, 0x182735ff, 0x86d8e8ff, 0xffffffff] DIRECTIONS = [("s", 0, 1), ("se", 1, 1), ("e", 1, 0), ("ne", 1, -1), ("n", 0, -1), ("nw", -1, -1), ("w", -1, 0), ("sw", -1, 1)] def png(pixels): def chunk(kind, data): return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data)) raw = b"".join(b"\0" + b"".join(PALETTE[c].to_bytes(4, "big") for c in row) for row in pixels) return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", 32, 32, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")) def canvas(fill=0): return [[fill] * 32 for _ in range(32)] def rect(p, x, y, w, h, color): for yy in range(max(0, y), min(32, y + h)): for xx in range(max(0, x), min(32, x + w)): p[yy][xx] = color def robot(dx, dy, step): p = canvas() # Broad little repair automaton, brass antenna and a teal glass face. rect(p, 8, 25, 17, 3, 1) for x, phase in [(9, step), (20, 1 - step)]: rect(p, x, 22 + phase, 5, 5, 1) rect(p, x + 1, 22 + phase, 3, 3, 4) rect(p, 6, 11, 20, 13, 1) rect(p, 8, 12, 16, 10, 4) rect(p, 8, 12, 16, 2, 5) rect(p, 11, 18, 10, 4, 3) rect(p, 14, 19, 4, 2, 8) rect(p, 3, 14 + step, 4, 8, 1) rect(p, 4, 15 + step, 3, 5, 7) rect(p, 25, 15 - step, 4, 8, 1) rect(p, 25, 16 - step, 3, 4, 7) rect(p, 9, 4, 14, 10, 1) rect(p, 10, 5, 12, 8, 5) rect(p, 11 + dx * 2, 7 + dy, 9, 4, 2) rect(p, 12 + dx * 2, 8 + dy, 2, 2, 6) rect(p, 17 + dx * 2, 8 + dy, 2, 2, 6) rect(p, 15, 1, 2, 4, 8) rect(p, 14, 1, 4, 2, 12) return p def drone(step): p = canvas() rect(p, 7, 25, 18, 2, 1) rect(p, 3, 9 + step, 26, 3, 1) rect(p, 4, 9 + step, 8, 1, 8) rect(p, 20, 9 + step, 8, 1, 8) rect(p, 7, 10 + step, 18, 12, 1) rect(p, 9, 11 + step, 14, 9, 9) rect(p, 10, 12 + step, 12, 2, 8) rect(p, 12, 15 + step, 8, 3, 2) rect(p, 14, 15 + step, 4, 2, 12) rect(p, 10, 21 + step, 4, 2, 10) rect(p, 18, 21 + step, 4, 2, 10) return p def beacon(on): p = canvas() rect(p, 5, 26, 22, 3, 1) rect(p, 8, 23, 16, 4, 3) rect(p, 11, 17, 10, 7, 1) rect(p, 13, 18, 6, 6, 4) rect(p, 7, 5, 18, 14, 1) rect(p, 9, 7, 14, 10, 7 if on else 3) rect(p, 11, 8, 10, 8, 6 if on else 2) rect(p, 12, 8, 3, 5, 12 if on else 4) rect(p, 8, 4, 16, 2, 8) if on: rect(p, 2, 9, 3, 2, 6) rect(p, 27, 9, 3, 2, 6) rect(p, 15, 0, 2, 3, 6) return p def pulse(phase): p = canvas() radius = [5, 10, 14][phase] for y in range(32): for x in range(32): d = abs(x - 15) + abs(y - 15) if radius - 2 <= d <= radius: p[y][x] = 6 if phase < 2 else 14 rect(p, 14, 14, 3, 3, 12) return p def terrain(wall=False): p = canvas(2 if wall else 13) rect(p, 0, 0, 32, 1, 4 if wall else 2) rect(p, 0, 0, 1, 32, 3 if wall else 2) rect(p, 0, 30, 32, 2, 1) rect(p, 30, 0, 2, 32, 1) if wall: rect(p, 3, 4, 26, 23, 3) rect(p, 5, 6, 22, 2, 4) for x in (7, 23): rect(p, x, 22, 2, 2, 8) else: for x, y in ((5, 5), (25, 5), (5, 25), (25, 25)): rect(p, x, y, 1, 1, 3) return p def door(opened): p = canvas() rect(p, 1, 0, 30, 32, 1) rect(p, 3, 2, 26, 30, 4) rect(p, 6, 4, 20, 28, 7 if opened else 2) rect(p, 9, 7, 14, 23, 6 if opened else 3) rect(p, 14, 13, 4, 11, 12 if opened else 9) return p def json_bytes(value): return (json.dumps(value, indent=2) + "\n").encode() def generated(): files, artifacts, clips = {}, [], [] def glyph(name, pixels): data = png(pixels) index = len(artifacts) fingerprint = hashlib.sha256(data).hexdigest() artifacts.append(dict(artifact_id=name, file=name + ".png", index=index, fingerprint=fingerprint)) files["assets/workshop/" + name + ".png"] = data return name for name, dx, dy in DIRECTIONS: idle = glyph("robot_" + name + "_idle", robot(dx, dy, 0)) moving = glyph("robot_" + name + "_step", robot(dx, dy, 1)) clips.append(dict(name="idle_" + name, mode="loop", frames=[dict(artifact_id=idle, duration_ticks=6)])) clips.append(dict(name="move_" + name, mode="loop", frames=[dict(artifact_id=idle, duration_ticks=6), dict(artifact_id=moving, duration_ticks=6)])) fly = [glyph("drone_" + str(i), drone(i)) for i in range(2)] effect = [glyph("pulse_" + str(i), pulse(i)) for i in range(3)] for name, image in [("beacon_off", beacon(False)), ("beacon_on", beacon(True)), ("floor", terrain()), ("wall", terrain(True)), ("exit_closed", door(False)), ("exit_open", door(True))]: glyph(name, image) bank = dict(schema_version=1, asset_uuid=BANK_UUID, name="Beacon Workshop", type="glyph_bank", preload=dict(enabled=True), output=dict(format="GLYPH/indexed_v1", codec="NONE", metadata=dict(tile_size="32x32"), pipeline=dict(palettes=[dict(index=0, palette=dict( rgba8888=[color if color < 0x80000000 else color - 0x100000000 for color in PALETTE]))])), artifacts=artifacts) files["assets/workshop/asset.json"] = json_bytes(bank) binding = [dict(artifact_id=a["artifact_id"], glyph_id=a["index"], fingerprint=a["fingerprint"]) for a in artifacts] animators = [dict(id="robot", initial_clip="idle_s", clips=clips), dict(id="drone", initial_clip="fly", clips=[dict(name="fly", mode="loop", frames=[dict(artifact_id=g, duration_ticks=6) for g in fly])]), dict(id="pulse", initial_clip="pulse", clips=[dict(name="pulse", mode="once", frames=[dict(artifact_id=g, duration_ticks=4) for g in effect])])] files["assets/workshop/animations.studio.json"] = json_bytes(dict(schema_version=1, bank_asset_uuid=BANK_UUID, bindings=binding, animators=animators)) ids = {a["artifact_id"]: a["index"] for a in artifacts} tiles = [] for y in range(12): for x in range(20): solid = x in (0, 19) or y in (1, 10, 11) or (9 <= x <= 10 and 4 <= y <= 5) tiles.append(dict(active=True, glyph_id=ids["wall" if solid else "floor"], palette_id=0, flip_x=False, flip_y=False)) layer = dict(active=True, glyph_asset_id=1, tile_size=32, parallax_factor_x=1.0, parallax_factor_y=1.0, width=20, height=12, tiles=tiles) files["assets/room/asset.json"] = json_bytes(dict(schema_version=1, asset_uuid=SCENE_UUID, name="Workshop room", type="scene_bank", preload=dict(enabled=True), output=dict(format="SCENE/tilemap_v1", codec="NONE"))) inactive = dict(active=False, glyph_asset_id=1, tile_size=32, parallax_factor_x=1.0, parallax_factor_y=1.0, width=1, height=1, tiles=[dict(active=False, glyph_id=0, palette_id=0, flip_x=False, flip_y=False)]) files["assets/room/scene-bank.pack-request.json"] = json_bytes(dict(schema_version=1, format="SCENE/tilemap_v1", version=1, layers=[layer, inactive, inactive, inactive])) files["assets/.prometeu/index.json"] = json_bytes(dict(schema_version=1, next_asset_id=3, assets=[dict(asset_id=1, asset_uuid=BANK_UUID, root="workshop", included_in_build=True), dict(asset_id=2, asset_uuid=SCENE_UUID, root="room", included_in_build=True)])) files["src/glyphs.pbs"] = ("// Generated by tools/author_assets.py from original code-authored art.\n" + "\n".join("declare const GLYPH_" + name.upper() + ": int = " + str(index) + ";" for name, index in ids.items()) + "\n").encode() return files if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true", help="verify checked-in outputs without changing them") args = parser.parse_args() for relative, data in generated().items(): destination = ROOT / relative if args.check: if not destination.is_file() or destination.read_bytes() != data: raise SystemExit("Out-of-date generated asset: " + relative) else: destination.parent.mkdir(parents=True, exist_ok=True) destination.write_bytes(data) print("Beacon Workshop: original assets " + ("verified" if args.check else "generated"))