aboutsummaryrefslogtreecommitdiff
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
parent31259bbbcddaeecd50bafd8de1a5f1ef1bd7a8a2 (diff)
downloadgold-mine-run-4b465f9480c848d74f3127638bdce82539cb7604.tar.gz
gold-mine-run-4b465f9480c848d74f3127638bdce82539cb7604.zip
Check we don't go over the max number of entities
-rw-r--r--src/Makefile2
-rwxr-xr-xtools/map.py11
2 files changed, 12 insertions, 1 deletions
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"])