From 2ddec2370e490ade7b64b7da23f6b8a023698175 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sat, 23 Mar 2013 23:07:04 -0400 Subject: [PATCH] Fix eval for :game to allow modifying state again --- src/hottub/core.clj | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/hottub/core.clj b/src/hottub/core.clj index 2527b27..d67e641 100644 --- a/src/hottub/core.clj +++ b/src/hottub/core.clj @@ -78,7 +78,21 @@ (defn reload [] (reset! *newscreen* (scr/reload-screen s))) -(defmethod slick/eval-with-bindings :default [state game f] - (binding [g game s state *newscreen* (atom nil)] - (let [gsnew (gs/update-gs (:gs state) (f))] - (slick/game-setscreen! game (or @*newscreen* (assoc state :gs gsnew)))))) +(defn- simple-eval [screen game f] + (binding [g game s screen *newscreen* (atom nil)] + (f) + (if @*newscreen* (slick/game-setscreen! game @*newscreen*)))) + +(defmethod slick/eval-with-bindings :game [screen game f] + (simple-eval screen game + (fn [] + (let [tln (:tln screen) + gsnew (gs/update-gs (tln/timeline-last-value tln) (f))] + (if-not @*newscreen* + (let [tslast (-> tln last key) + tlnnew (tln/timeline-insert tln tslast gsnew) + screennew (assoc screen :tln tlnnew)] + (reset! *newscreen* screennew))))))) + +(defmethod slick/eval-with-bindings :default [screen game f] + (simple-eval screen game f))