From 4b465f9480c848d74f3127638bdce82539cb7604 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 15 Jul 2023 20:58:47 +0100 Subject: Check we don't go over the max number of entities --- src/Makefile | 2 +- tools/map.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 5815e88..6984376 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,7 +35,7 @@ $(IMG_OBJS): %.o: ../data/%.png ../tools/pngpix.py $< $@ $(MAP_OBJS): %.o: ../data/%.json - ../tools/map.py $< $@ + ../tools/map.py --max-ents 15 $< $@ $(WAV_OBJS): %.o: ../data/%.wav ../tools/raw.py $< $@ diff --git a/tools/map.py b/tools/map.py index 825f307..c959c50 100755 --- a/tools/map.py +++ b/tools/map.py @@ -49,6 +49,13 @@ def main(): parser.add_argument( "--version", action="version", version="%(prog)s " + __version__ ) + parser.add_argument( + "--max-ents", + dest="max_ents", + type=int, + default=None, + help="limit of entities in the map", + ) parser.add_argument("file_json", help="JSON map to convert") parser.add_argument("output", help="object name for the map data") @@ -82,6 +89,10 @@ def main(): # some entities will never change their y coordinate, so sorting them by y # should help the drawing order in the game objs_sorted = sorted(entity_layer["objects"], key=lambda o: o["y"]) + + if args.max_ents and len(objs_sorted) > args.max_ents: + parser.error("Too many entities (limit: %s)" % args.max_ents) + for ent in objs_sorted: try: typ = entity_types.index(ent["name"]) -- cgit v1.2.3