aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-03-23 16:22:45 +0100
committerlonkaars <loek@pipeframe.xyz>2023-03-23 16:22:45 +0100
commit9df9b163852cd5fd2462e1dec25ad4b00ca12a8c (patch)
tree9590f1e2068871920ffdd214873ca60583276ab0 /scripts
parent657f88952d35145b46d86a04e4b681d91f878c3a (diff)
add scripts for converting tiles to separate png images for tilemap editingtilemap-build-system
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tiled.mk.awk16
-rwxr-xr-xscripts/tilemap2tiled42
2 files changed, 58 insertions, 0 deletions
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/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
+