Fix eval for :game to allow modifying state again

This commit is contained in:
Jeremy Penner 2013-03-23 23:07:04 -04:00
parent 0e9de617fa
commit 2ddec2370e

View file

@ -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))