aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-22 22:10:28 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-22 22:10:28 +0100
commit4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5 (patch)
tree05b820a74bcaffa340eede419b3e1fe24059c477 /tools
parent7723c5f8a9f0ea5345ebefecd31fe22f3601b32e (diff)
downloadgold-mine-run-4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5.tar.gz
gold-mine-run-4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5.zip
Import entities from the map and spawn them
Diffstat (limited to 'tools')
-rwxr-xr-xtools/map.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/tools/map.py b/tools/map.py
index 5522a9e..7e0210f 100755
--- a/tools/map.py
+++ b/tools/map.py
@@ -10,12 +10,23 @@ __version__ = "1.0"
ld = os.environ.get("LD", "i586-pc-msdosdjgpp-ld")
strip = os.environ.get("STRIP", "i586-pc-msdosdjgpp-strip")
+entity_types = ("Player",)
+
def get_layer(data, name):
for layer in data["layers"]:
if layer["name"] == name:
return layer
- raise ValueError("Layer %s not found" % name)
+ raise ValueError("Layer %r not found" % name)
+
+
+def get_prop(data, name, default):
+ if "properties" not in data:
+ return default
+ for prop in data["properties"]:
+ if prop["name"] == name:
+ return prop["value"]
+ return default
def main():
@@ -55,7 +66,29 @@ def main():
out.extend(map(lambda x: (x - tileset["firstgid"]) & 0xFF, gold_layer["data"]))
- # TODO: process map entities
+ entity_layer = get_layer(data, "Entities")
+
+ for ent in entity_layer["objects"]:
+ try:
+ typ = entity_types.index(ent["name"])
+ except ValueError:
+ parser.error("Entity in map %r not found in entity types" % ent["name"])
+
+ x = ent["x"] // tileset["tilewidth"]
+ y = ent["y"] // tileset["tileheight"]
+
+ flags = 0
+
+ dir = get_prop(ent, "dir", "right")
+ if dir not in ("left", "right"):
+ parser.error("Invalid value for property dir: %r" % dir)
+ if dir == "left":
+ flags |= 1
+
+ out.extend([typ, x, y, flags])
+
+ # end of entity list
+ out.append(0xFF)
tmp = args.output.rstrip(".o")
with open(tmp, "wb") as fd: