From 0849e5c85a10dcb3abc7722651dcb9b71ab1ec7b Mon Sep 17 00:00:00 2001 From: Christine Lemmer-Webber Date: Sat, 25 May 2024 14:48:48 -0400 Subject: [PATCH] Better error messages when properties are missing from levels --- scripts/compile-map.scm | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/compile-map.scm b/scripts/compile-map.scm index 908584a..ec33dd1 100644 --- a/scripts/compile-map.scm +++ b/scripts/compile-map.scm @@ -604,38 +604,44 @@ the default ORIENTATION value of 'orthogonal' is supported." (properties (map-object-properties obj)) (r (map-object-shape obj)) (x (/ (rect-x r) tw)) - (y (/ (rect-y r) th))) + (y (/ (rect-y r) th)) + (property-ref + (lambda (key) + (or (assq-ref properties key) + (and (not (assq key properties)) + (error "Property missing:" + key 'on type 'at x y)))))) (match type ('player-spawn (list x y obj:player-spawn)) ('block - (match (assq-ref properties 'kind) + (match (property-ref 'kind) ("crate" (list x y obj:block:crate)) ("copper" (list x y obj:block:copper)) (kind (error "unsupported block kind" kind)))) ('floor-switch (list x y obj:floor-switch - (assq-ref properties 'target-x) - (assq-ref properties 'target-y))) + (property-ref 'target-x) + (property-ref 'target-y))) ('gem (list x y obj:gem)) ('gate (list x y obj:gate)) ('clock-emitter (list x y obj:clock-emitter - (assq-ref properties 'interval))) + (property-ref 'interval))) ('switched-emitter (list x y obj:switched-emitter - (assq-ref properties 'interval))) + (property-ref 'interval))) ('and-gate (list x y obj:and-gate (parse-direction - (assq-ref properties 'direction)))) + (property-ref 'direction)))) ('xor-gate (list x y obj:xor-gate (parse-direction - (assq-ref properties 'direction)))) + (property-ref 'direction)))) ('or-gate (list x y obj:or-gate (parse-direction - (assq-ref properties 'direction)))) + (property-ref 'direction)))) ('electric-switch (list x y obj:electric-switch - (assq-ref properties 'target-x) - (assq-ref properties 'target-y))) + (property-ref 'target-x) + (property-ref 'target-y))) ('electron-warp (list x y obj:electron-warp - (assq-ref properties 'target-x) - (assq-ref properties 'target-y))) + (property-ref 'target-x) + (property-ref 'target-y))) ('bomb (list x y obj:bomb)) ('brick (list x y obj:brick)) (_ (error "unsupported object type" type))))) @@ -662,7 +668,7 @@ the default ORIENTATION value of 'orthogonal' is supported." ,(compile-tile-layer tile-map "background") ,(u8-list->bytevector (append - (compile-environment-layer tile-map "background") - (compile-object-layer tile-map "objects"))) + (pk 'tmap (compile-environment-layer tile-map "background")) + (pk 'ol (compile-object-layer tile-map "objects")))) collected-gem?)))))) (_ (error "file name expected")))