aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-15 20:58:47 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-15 20:58:47 +0100
commit4b465f9480c848d74f3127638bdce82539cb7604 (patch)
treec14de076467dc18849de1a73d63e169f3dad80dd /tools
parent31259bbbcddaeecd50bafd8de1a5f1ef1bd7a8a2 (diff)
downloadgold-mine-run-4b465f9480c848d74f3127638bdce82539cb7604.tar.gz
gold-mine-run-4b465f9480c848d74f3127638bdce82539cb7604.zip
Check we don't go over the max number of entities
Diffstat (limited to 'tools')
-rwxr-xr-xtools/map.py11
1 files changed, 11 insertions, 0 deletions
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"])