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 --- tools/map.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tools') 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