From 8495bc3169939d034622dcbf6fb84016a7430ef2 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 22 Mar 2023 15:15:10 +0100 Subject: tilemap build system done --- src/static/makefile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/static/makefile (limited to 'src/static/makefile') diff --git a/src/static/makefile b/src/static/makefile new file mode 100644 index 0000000..a6a18db --- /dev/null +++ b/src/static/makefile @@ -0,0 +1,34 @@ +XXD := xxd +TILEPACK := ../../scripts/tilepack +MANIFEST2HEADER := ../../scripts/manifest2header.awk + +INPUT += shop.hex \ + slime.hex \ + world.hex +USER_META += world.h + +OUT_BIN := $(patsubst %.hex,%.bin, $(INPUT)) +OUT_META := $(patsubst %.hex,%.meta, $(INPUT)) + +.PHONY: all clean + +all: tilemap.bin tilemap.h + +%.bin: %.hex + sed 's/;.*//g' $< | $(XXD) -r | $(TILEPACK) > $@ + +%.meta: %.bin + wc -c $< | tr '.' ' ' | awk '1 { print $$2" "$$1 / 104 }' > $@ + +manifest.txt: $(OUT_BIN) $(OUT_META) + cat $(OUT_META) | sort > $@ + +tilemap.bin: manifest.txt $(OUT_BIN) + awk '1 { print $$1".bin" }' $< | xargs cat > $@ + +tilemap.h: manifest.txt + $(MANIFEST2HEADER) $< > $@ + cat $(USER_META) >> $@ + +clean: + $(RM) $(OUT_BIN) $(OUT_META) manifest.txt tilemap.h tilemap.bin -- cgit v1.2.3 From 657f88952d35145b46d86a04e4b681d91f878c3a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 23 Mar 2023 15:08:29 +0100 Subject: use sort order in makefile and add air tile at index 0 --- src/static/air.hex | 17 +++++++++++++++++ src/static/makefile | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/static/air.hex (limited to 'src/static/makefile') diff --git a/src/static/air.hex b/src/static/air.hex new file mode 100644 index 0000000..5160cd6 --- /dev/null +++ b/src/static/air.hex @@ -0,0 +1,17 @@ +00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + diff --git a/src/static/makefile b/src/static/makefile index a6a18db..d84e31e 100644 --- a/src/static/makefile +++ b/src/static/makefile @@ -2,7 +2,8 @@ XXD := xxd TILEPACK := ../../scripts/tilepack MANIFEST2HEADER := ../../scripts/manifest2header.awk -INPUT += shop.hex \ +INPUT += air.hex \ + shop.hex \ slime.hex \ world.hex USER_META += world.h @@ -21,7 +22,7 @@ all: tilemap.bin tilemap.h wc -c $< | tr '.' ' ' | awk '1 { print $$2" "$$1 / 104 }' > $@ manifest.txt: $(OUT_BIN) $(OUT_META) - cat $(OUT_META) | sort > $@ + cat $(OUT_META) > $@ tilemap.bin: manifest.txt $(OUT_BIN) awk '1 { print $$1".bin" }' $< | xargs cat > $@ -- cgit v1.2.3 From 9df9b163852cd5fd2462e1dec25ad4b00ca12a8c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 23 Mar 2023 16:22:45 +0100 Subject: add scripts for converting tiles to separate png images for tilemap editing --- scripts/tiled.mk.awk | 16 ++++++++++++++++ scripts/tilemap2tiled | 42 ++++++++++++++++++++++++++++++++++++++++++ src/static/.gitignore | 2 ++ src/static/makefile | 9 ++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 scripts/tiled.mk.awk create mode 100755 scripts/tilemap2tiled (limited to 'src/static/makefile') 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 + diff --git a/src/static/.gitignore b/src/static/.gitignore index f24ab90..348c5b9 100644 --- a/src/static/.gitignore +++ b/src/static/.gitignore @@ -2,3 +2,5 @@ **/*.meta manifest.txt tilemap.h +tiled/* +tiled.mk diff --git a/src/static/makefile b/src/static/makefile index d84e31e..6025a55 100644 --- a/src/static/makefile +++ b/src/static/makefile @@ -1,6 +1,8 @@ XXD := xxd TILEPACK := ../../scripts/tilepack MANIFEST2HEADER := ../../scripts/manifest2header.awk +TILEDMK := ../../scripts/tiled.mk.awk +TILEMAP2TILED := ../../scripts/tilemap2tiled INPUT += air.hex \ shop.hex \ @@ -31,5 +33,10 @@ tilemap.h: manifest.txt $(MANIFEST2HEADER) $< > $@ cat $(USER_META) >> $@ +tiled.mk: manifest.txt + $(TILEDMK) < $< > $@ + +include tiled.mk + clean: - $(RM) $(OUT_BIN) $(OUT_META) manifest.txt tilemap.h tilemap.bin + $(RM) -r $(OUT_BIN) $(OUT_META) manifest.txt tilemap.h tilemap.bin tiled.mk tiled -- cgit v1.2.3