diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2023-04-06 12:32:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-06 12:32:23 +0200 |
commit | d1c00c98ca0f2ca498284e60fa057a610cc5c461 (patch) | |
tree | a2efebcb9917d7f4f3666a722338f50b9590e843 /scripts | |
parent | 1771aaa12736b4dbc24419270cf595de6d345969 (diff) | |
parent | 93e9426d5642dfab7a13d5a34873b296de1d9642 (diff) |
Merge pull request #58 from UnavailableDev/dev
Dynamic tilemap
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/manifest2header.awk | 23 | ||||
-rwxr-xr-x | scripts/tiled.mk.awk | 16 | ||||
-rwxr-xr-x | scripts/tilemap2png | 47 | ||||
-rwxr-xr-x | scripts/tilemap2tiled | 42 | ||||
-rwxr-xr-x | scripts/tilepack | 22 |
5 files changed, 150 insertions, 0 deletions
diff --git a/scripts/manifest2header.awk b/scripts/manifest2header.awk new file mode 100755 index 0000000..b141a8b --- /dev/null +++ b/scripts/manifest2header.awk @@ -0,0 +1,23 @@ +#!/bin/awk -f +BEGIN { + offset = 0 + groups = 0 + arr = "0" + print "#pragma once" + print "#include <stddef.h>" +} +(offset > 0) { + arr = arr ", " offset +} +1 { + sub(".*/", "", $1) + print "#define HH_TM_"toupper($1)"_OFFSET "offset + print "#define HH_TM_"toupper($1)"_SIZE "$2 + groups += 1 + offset += $2 +} +END { + print "#define HH_TM_SIZE "offset + print "#define HH_TM_GROUPS "groups + print "const static uint8_t hh_palette_lut[]={"arr", NULL};" +} diff --git a/scripts/tiled.mk.awk b/scripts/tiled.mk.awk new file mode 100755 index 0000000..7728cf3 --- /dev/null +++ b/scripts/tiled.mk.awk @@ -0,0 +1,16 @@ +#!/bin/awk -f +BEGIN { + targets="" + print "tiled_dir:\n\tmkdir -p tiled" +} +1 { + for (i = 0; i < $2; i++) { + target = sprintf("tiled/%s_%02d.png", $1,i) + printf target" " + targets = targets" "target + } + printf "&: %s.bin\n",$1 + printf "\t$(TILEMAP2TILED) $<\n\n" +} +END { print "tiled: tiled_dir"targets } + diff --git a/scripts/tilemap2png b/scripts/tilemap2png new file mode 100755 index 0000000..e37bfab --- /dev/null +++ b/scripts/tilemap2png @@ -0,0 +1,47 @@ +#!/bin/python3 +# read packed tilemap file from stdin and output png on stdout + +import sys +import io +import struct +from PIL import Image + +color_map = ( + (0x00, 0x00, 0x00), + (0x24, 0x24, 0x24), + (0x49, 0x49, 0x49), + (0x6d, 0x6d, 0x6d), + (0x92, 0x92, 0x92), + (0xb6, 0xb6, 0xb6), + (0xda, 0xda, 0xda), + (0xff, 0xff, 0xff), +) + +buf = [] +for byte in sys.stdin.buffer.read(): + buf.append(byte) + +size_horizontal = 16 * 16 +size_vertical = ((len(buf) // 104) // 16 + 1) * 16 +img = Image.new('RGB', (size_horizontal, size_vertical)) + +i = 0 +sprite_idx = 0 +for x in range(0, len(buf), 2): + word = 0x0000 + word |= buf[x] + word |= buf[x+1] << 8 + + for p in range(5): + img.putpixel(((i % 16) + (16 * (sprite_idx % 16)), (i // 16) + (16 * (sprite_idx // 16))), color_map[(word >> (p * 3)) & 0b111]) + i += 1 + if i > 0xff: + i = 0 + sprite_idx += 1 + break + +with io.BytesIO() as out: + img.save(out, format="PNG") + sys.stdout.buffer.write(out.getvalue()) + sys.stdout.buffer.flush() + diff --git a/scripts/tilemap2tiled b/scripts/tilemap2tiled new file mode 100755 index 0000000..905f801 --- /dev/null +++ b/scripts/tilemap2tiled @@ -0,0 +1,42 @@ +#!/bin/python3 +# read packed tilemap file from argv[1] and output pngs + +import sys +import io +import struct +from PIL import Image + +color_map = ( + (0x00, 0x00, 0x00), + (0x24, 0x24, 0x24), + (0x49, 0x49, 0x49), + (0x6d, 0x6d, 0x6d), + (0x92, 0x92, 0x92), + (0xb6, 0xb6, 0xb6), + (0xda, 0xda, 0xda), + (0xff, 0xff, 0xff), +) + +img = Image.new('RGB', (16, 16)) + +buf = "" +with open(sys.argv[1], "rb") as f: + buf = f.read() + +i = 0 +sprite_idx = 0 +for x in range(0, len(buf), 2): + word = 0x0000 + word |= buf[x] + word |= buf[x+1] << 8 + + for p in range(5): + img.putpixel((i % 16, i // 16), color_map[(word >> (p * 3)) & 0b111]) + i += 1 + if i > 0xff: + i = 0 + img.save(f"tiled/{sys.argv[1].replace('.bin','')}_{str(sprite_idx).zfill(2)}.png", format="PNG") + img = Image.new('RGB', (16, 16)) + sprite_idx += 1 + break + diff --git a/scripts/tilepack b/scripts/tilepack new file mode 100755 index 0000000..a07cbb6 --- /dev/null +++ b/scripts/tilepack @@ -0,0 +1,22 @@ +#!/bin/python3 +# read bytes from input and pack into ppu format +# each input sprite is 256 bytes + +import sys +import struct + +i = 0 +word = 0x0000 +for byte in sys.stdin.buffer.read(): + pixel_idx = i % 5 + word |= (byte & 0b111) << 3 * pixel_idx + + if pixel_idx == 4 or i == 0xff: + sys.stdout.buffer.write(struct.pack('<H', word)) + word = 0x0000 + + i += 1 + if i > 0xff: i = 0 + +sys.stdout.buffer.flush() + |