# Docs inputs for the 2D pages (tools/fixtures.py; see tools/docs_check.py): a layered PSD written by ImageMagick (three # layers: Sky, Box, a half-transparent Glow; the merged image flattened by ImageMagick), a two-frame Aseprite sprite # (built with the chunk writer of tools/fixtures/aseprite.py), an SVG icon and a Tiled map as TMX and TMJ (hand-written # from the Tiled format docs) with its tileset image tiles.png (ImageMagick). # tests/gen/docs_2d.luau { files, vars = { psdBytes, asepriteBytes, svgText, tmxText, tmjText, tilesPngBytes } } import importlib.util, os, struct, tempfile INPUTS = ["tools/docs_check.py", "tools/fixtures/aseprite.py"] def load(ctx, name): spec = importlib.util.spec_from_file_location("docs2d_" + name, os.path.join(ctx.root, "tools", *name.split("/"))) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m SVG = """ """ # a 4 x 3 map of 16 x 16 tiles: one tileset (tiles.png, 4 columns), a tile layer, an object layer with a spawn point TMX = """ 1,2,2,3, 5,0,0,7, 6,6,6,6 """ TMJ = """{ "type": "map", "version": "1.10", "orientation": "orthogonal", "renderorder": "right-down", "width": 2, "height": 2, "tilewidth": 8, "tileheight": 8, "infinite": false, "nextlayerid": 2, "nextobjectid": 1, "tilesets": [ { "firstgid": 1, "name": "t", "tilewidth": 8, "tileheight": 8, "tilecount": 4, "columns": 2, "image": "t.png", "imagewidth": 16, "imageheight": 16 } ], "layers": [ { "id": 1, "name": "main", "type": "tilelayer", "width": 2, "height": 2, "x": 0, "y": 0, "opacity": 1, "visible": true, "data": [ 1, 2, 3, 2147483652 ] } ] } """ def aseprite(ctx): A = load(ctx, "fixtures/aseprite.py") W, H = 32, 24 sky = bytes((40, 90, 160, 255)) * (W * H) hero = bytes((220, 50, 50, 255)) * 64 f1 = [ A.layer_chunk("Background", flags=1 | 2 | 8), A.layer_chunk("Hero"), A.tags_chunk([("walk", 0, 1, 0, 0)]), A.cel_chunk(0, 0, 0, W, H, sky), A.cel_chunk(1, 4, 8, 8, 8, hero), ] f2 = [ A.cel_chunk(0, 0, 0, W, H, b"", link=0), A.cel_chunk(1, 12, 8, 8, 8, hero), ] return A.sprite(W, H, 32, [(100, f1), (250, f2)]) def generate(ctx): dc = load(ctx, "docs_check.py") files = {"icon.svg": SVG, "level.tmx": TMX, "level.tmj": TMJ, "sprite.aseprite": aseprite(ctx)} with tempfile.TemporaryDirectory() as d: out = os.path.join(d, "art.psd") ctx.nix("imagemagick", ["magick", "(", "-size", "48x32", "xc:#3070c0", "-set", "label", "Sky", ")", "(", "-size", "16x16", "xc:#e04040", "-set", "page", "+8+8", "-set", "label", "Box", ")", "(", "-size", "20x10", "xc:rgba(255,255,0,0.5)", "-set", "page", "+24+18", "-set", "label", "Glow", ")", "(", "-clone", "0--1", "-background", "none", "-flatten", ")", "-insert", "0", "-depth", "8", "-type", "TrueColorAlpha", out]) files["art.psd"] = open(out, "rb").read() tiles = os.path.join(d, "tiles.png") ctx.nix("imagemagick", ["magick", "-size", "64x32", "pattern:checkerboard", "-depth", "8", tiles]) files["tiles.png"] = open(tiles, "rb").read() dc.emit_inputs(ctx, files, { "psdBytes": "art.psd", "asepriteBytes": "sprite.aseprite", "svgText": "icon.svg", "tmxText": "level.tmx", "tmjText": "level.tmj", "tilesPngBytes": "tiles.png", })