From fa92e111ab5dfb3f386ad53317fea0103111cfbb Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 11 Dec 2022 10:41:23 +0000 Subject: Make Entities layer optional. It can also be disabled using "visible" flag in tiled. Closes issue #19 --- docs/tools.md | 2 +- tools/map.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/tools.md b/docs/tools.md index 67b797a..caf67c4 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -88,7 +88,7 @@ This is a map importer to use with [tiled](https://www.mapeditor.org/) JSON form The map importer supports: -- **entities**: an object layer describing game entities such as enemies. +- **entities**: an optional object layer describing game entities such as enemies. If the "visible" property on this layer is set to "false", the layer will be ignored even if present. - **map**: a tile layer describing the map itself. #### Map requirements diff --git a/tools/map.py b/tools/map.py index 60ef887..476c1cd 100755 --- a/tools/map.py +++ b/tools/map.py @@ -220,8 +220,16 @@ def main(): # ents size placeholder 0 out[i] = [size & 0xFF, size >> 8, 0] + out[i] - entities_layer = find_name(data["layers"], "Entities") - if len(entities_layer): + try: + entities_layer = find_name(data["layers"], "Entities") + except ValueError: + entities_layer = [] + if not args.quiet: + print( + "%s: warning: 'Entities' layer not found" % path.basename(sys.argv[0]), + file=sys.stderr, + ) + if len(entities_layer) and entities_layer["visible"]: map_ents = defaultdict(list) map_ents_w = defaultdict(int) map_ents_bytes = defaultdict(int) -- cgit v1.2.3