Added script that converts tiled csv maps to in-game maps
authorLukas Krickl <lukas@krickl.dev>
Mon, 21 Oct 2024 18:38:34 +0000 (20:38 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 21 Oct 2024 18:38:34 +0000 (20:38 +0200)
makefile
maps/base_room.s [new file with mode: 0644]
src/map.s
src/video.s
tools/tms2map.py [new file with mode: 0755]

index ae213babad296dd38309456844548a6b4821d591..e61f576fe778b80482c48e0a72e8ae9d2b557078 100644 (file)
--- a/makefile
+++ b/makefile
@@ -14,3 +14,7 @@ test:
 tiles:
        ./tools/png2chr.py assets/tiles0.png > tiles/tileset0.inc
        ./tools/png2chr.py assets/tiles1.png > tiles/tileset1.inc
+
+.PHONY: maps
+maps:
+       ./tools/tms2map.py assets/maps/base.tmx base_room > maps/base_room.s
diff --git a/maps/base_room.s b/maps/base_room.s
new file mode 100644 (file)
index 0000000..85412dd
--- /dev/null
@@ -0,0 +1,4 @@
+base_room_bg:
+.db 0x60, 0x62, 0x62, 0x64, 0x40, 0x40, 0x66, 0x62, 0x62, 0x68, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x46, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe2, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x6c, 0x4a, 0x4a, 0x42, 0x40, 0x40, 0x44, 0x4a, 0x4a, 0x6e
+base_room_flags:
+.db 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1
index 369d981bdff84422b472e131bd0f47b16d52eceb..837d5f4433cf999dabcb2fbdb4feb2abdc3bfe6d 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -146,22 +146,4 @@ room_draw:
   ; base room 
   ; this can be copied and modified 
   ; by the map gen
-base_room:
-.db TCORNUL, TWALLU1, TWALLU1, TDOORUL, TFLOOR1,  TFLOOR1, TDOORUR,  TWALLU1, TWALLU1, TCORNUR 
-.db TWALLL1, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TWALLR1  
-.db TDOORRL, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TDOORLL  
-.db TFLOOR1, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR1  
-.db TFLOOR1, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR1  
-.db TDOORRR, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TDOORLR  
-.db TWALLL1, TFLOOR1, TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TWALLR1  
-.db TCORNBOL,  TWALLD1,  TWALLD1,  TDOORDL,  TFLOOR1,  TFLOOR1,  TDOORDR,  TWALLD1, TWALLD1, TCORNBOR 
-  ; tile flags for the room 
-base_room_flags:
-.db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL 
-.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL 
-.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL 
-.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
-.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
-.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL 
-.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL 
-.db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL 
+#include "./maps/base_room.s"
index c8871ee4243b54c7763d54c6bff434f510e0e0c3..06108abef972aef3cdb28b72abba5bb5a406984a 100644 (file)
@@ -83,9 +83,9 @@ video_init:
 
 
   ; initial test map
-  ldlo a, base_room 
+  ldlo a, base_room_bg 
   ld [curr_room], a
-  ldhi a, base_room
+  ldhi a, base_room_bg
   ld [curr_room+1], a
   
   ldlo a, base_room_flags 
diff --git a/tools/tms2map.py b/tools/tms2map.py
new file mode 100755 (executable)
index 0000000..a2b866f
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import sys 
+import os
+import xml.etree.ElementTree as ET
+
+if len(sys.argv) < 3:
+    print("Usage: tmx2map.py <source> <map name>")
+    sys.exit(-1)
+
+src = sys.argv[1]
+name = sys.argv[2]
+
+def print_data(data, name, layer):
+    print(name + "_" + layer + ":")
+    print(".db ", end = '');
+    split = data.split(",")
+    for i, byte in enumerate(split):
+        val = int(byte)
+        if val > 0:
+            val -= 1
+        if layer == "bg":
+            og = val
+            val = 0x800 + ((val * 16) << 2)
+            val = (val & 0x0FF0) >> 4
+            val -= int(2 * og % 16)
+        
+        end = ', '
+        if i == len(split) - 1:
+            end = '\n'
+        print(hex(val), end=end)
+
+def convert(src, name):
+    tree = ET.parse(src)
+    root = tree.getroot()
+    for child in root:
+        if child.tag == "layer":
+            for data in child:
+                print_data(data.text, name, child.attrib['name'])
+
+
+
+convert(src, name)