From 0e5fc5a73b84ad863d8f361afac46c56c15e37db Mon Sep 17 00:00:00 2001 From: Amy Grinn Date: Tue, 17 Dec 2024 12:39:19 -0500 Subject: [PATCH] Optimizing conditionals --- game.scm | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/game.scm b/game.scm index 73e6f9d..60756e6 100644 --- a/game.scm +++ b/game.scm @@ -748,14 +748,14 @@ (let row ((r r-start) (y (- (vec2-y center) (* tile-height (floor (/ height 2)))))) ;; Draw menu background - (if (= r r-start) - (let* ((x (- (vec2-x center) (* tile-width (floor (/ width 2))))) - (w (* tile-width width)) - (h (* tile-height height))) - (set-fill-color! context "#000") - (fill-rect context x y w h) - (set-stroke-color! context "blue") - (stroke-rect context x y w h))) + (when (= r r-start) + (let* ((x (- (vec2-x center) (* tile-width (floor (/ width 2))))) + (w (* tile-width width)) + (h (* tile-height height))) + (set-fill-color! context "#000") + (fill-rect context x y w h) + (set-stroke-color! context "blue") + (stroke-rect context x y w h))) ;; Draw menu text (set-text-align! context "center") (set-font! context "normal 16px monogram") @@ -764,13 +764,12 @@ (if (= r r-start) (fill-text context (menu-name (current-menu)) (vec2-x center) (+ y text-offset-y)) (if (and (>= r -1) (< r-index num-items) (< r r-end)) - (let* ((item (cond - ((= r -1) - (if (= (current-menu-page) 0) "Back" "...")) - ((and (= r (1- r-end)) (< r-index (1- num-items))) - "...") - (else - (menu-item-name (vector-ref (menu-items (current-menu)) r-index))))) + (let* ((item (if (= r -1) + (if (= (current-menu-page) 0) + "Back" "...") + (if (and (= r (1- r-end)) (< r-index (1- num-items))) + "..." + (menu-item-name (vector-ref (menu-items (current-menu)) r-index))))) (text (string-append (if (= r-index (current-menu-index)) "▸ " " ") item))) (fill-text context text (vec2-x center) (+ y text-offset-y)))))) ;; Draw next row