diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 2dee2dcc..4fdd053e 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -336,55 +336,63 @@ false))) (defn transition-background [entities new-background [x y]] - (run-action entities - (begin [this screen entities] - - (-> entities - (assoc-in [:transition] - (assoc (texture "black.png") - :scale-x 20 - :scale-y 20 - :baseline 9500 - :opacity 0.1)))) - - (continue [this screen entities] - (update-in entities [:transition :opacity] + 0.075)) - - (done? [this screen entities] - (>= (get-in entities [:transition :opacity]) 1.0)) - - (terminate [this screen entities] - entities) - (can-skip? [this screen entities] - false)) - (run-action entities - (begin [this screen entities] - (let [ego (get-in entities [:room :entities :ego]) - old-music (get-in entities [:room :music]) - entities (-> entities - (assoc-in [:room] (get-in entities [:rooms new-background])) - (assoc-in [:room :entities :ego] ego)) - new-music (get-in entities [:room :music])] - (when (not= new-music old-music) - (doseq [[k v] (:musics entities) - :when (and v (not= new-music k))] - (music! v :stop)) - (when new-music - (music! (get-in entities [:musics new-music]) :play))) + (let [old-music (get-in @entities [:room :music]) + new-music (get-in @entities [:rooms new-background :music]) + music-changed? (not= old-music new-music)] + (run-action entities + (begin [this screen entities] + (-> entities - (update-in [:room :entities :ego] #(jump-to screen entities % [x y]))))) + (assoc-in [:transition] + (assoc (texture "black.png") + :scale-x 20 + :scale-y 20 + :baseline 9500 + :opacity 0.1)))) - (continue [this screen entities] - (update-in entities [:transition :opacity] - 0.075)) + (continue [this screen entities] + (when music-changed? + (music! (get-in entities [:musics old-music]) :set-volume (max (- 1.0 (get-in entities [:transition :opacity])) 0.0))) + (update-in entities [:transition :opacity] + 0.05)) - (done? [this screen entities] - (<= (get-in entities [:transition :opacity]) 0.0)) + (done? [this screen entities] + (>= (get-in entities [:transition :opacity]) 1.0)) - (terminate [this screen entities] - (dissoc entities :transition)) + (terminate [this screen entities] + entities) + (can-skip? [this screen entities] + false)) + (run-action entities + (begin [this screen entities] + (let [ego (get-in entities [:room :entities :ego]) + old-music (get-in entities [:room :music]) + entities (-> entities + (assoc-in [:room] (get-in entities [:rooms new-background])) + (assoc-in [:room :entities :ego] ego)) + new-music (get-in entities [:room :music])] + (when (not= new-music old-music) + (doseq [[k v] (:musics entities) + :when (and v (not= new-music k))] + (music! v :stop)) + (when new-music + (music! (get-in entities [:musics new-music]) :set-volume 0) + (music! (get-in entities [:musics new-music]) :play))) + (-> entities + (update-in [:room :entities :ego] #(jump-to screen entities % [x y]))))) - (can-skip? [this screen entities] - false))) + (continue [this screen entities] + (when music-changed? + (music! (get-in entities [:musics new-music]) :set-volume (max (- 1.0 (get-in entities [:transition :opacity])) 0.0))) + (update-in entities [:transition :opacity] - 0.075)) + + (done? [this screen entities] + (<= (get-in entities [:transition :opacity]) 0.0)) + + (terminate [this screen entities] + (dissoc entities :transition)) + + (can-skip? [this screen entities] + false)))) (defn do-dialogue [entities & pairs] (loop [pairs (partition 2 pairs)]