Skip to content

Commit

Permalink
Merge pull request mtgred#3867 from cwgreene/FixSpectatorSound
Browse files Browse the repository at this point in the history
Extract Sound Into It's own Component
  • Loading branch information
nealterrell authored Sep 24, 2018
2 parents 57dfdbf + c631a6a commit d3d85a0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/cljs/nr/gameboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,9 +1352,8 @@
[:br]
[:button.win-right {:on-click #(swap! app-state assoc :start-shown true) :type "button"} ""]])))))

(defn button-pane [{:keys [side active-player run end-turn runner-phase-12 corp-phase-12 corp runner me opponent sfx] :as cursor}]
(let [s (r/atom {})
autocomp (r/track (fn [] (get-in @game-state [side :prompt 0 :choices :autocomplete])))
(defn audio-component [{:keys [sfx] :as cursor}]
(let [s (r/atom {})
audio-sfx (fn [name] (list (keyword name)
(new js/Howl (clj->js {:src [(str "/sound/" name ".ogg")
(str "/sound/" name ".mp3")]}))))
Expand All @@ -1375,6 +1374,19 @@
(audio-sfx "run-successful")
(audio-sfx "run-unsuccessful")
(audio-sfx "virus-purge")))]
(r/create-class
{:display-name "audio-component"
:component-did-update
(fn []
(update-audio (select-keys @game-state [:sfx :sfx-current-id :gameid]) soundbank))
:reagent-render
(fn [{:keys [sfx] :as cursor}]
(let [_ @sfx]))}))) ;; make this component rebuild when sfx changes.


(defn button-pane [{:keys [side active-player run end-turn runner-phase-12 corp-phase-12 corp runner me opponent] :as cursor}]
(let [s (r/atom {})
autocomp (r/track (fn [] (get-in @game-state [side :prompt 0 :choices :autocomplete])))]
(r/create-class
{:display-name "button-pane"

Expand All @@ -1390,9 +1402,7 @@
(when (= "card-title" (get-in @game-state [side :prompt 0 :prompt-type]))
(-> "#card-title" js/$ .focus))
(doseq [{:keys [msg type options]} (get-in @game-state [side :toast])]
(toast msg type options))
(update-audio {:sfx (:sfx @game-state) :sfx-current-id (:sfx-current-id @game-state)
:gameid (:gameid @game-state)} soundbank))
(toast msg type options)))

:reagent-render
(fn [{:keys [side active-player run end-turn runner-phase-12 corp-phase-12 corp runner me opponent sfx] :as cursor}]
Expand Down Expand Up @@ -1621,6 +1631,7 @@
(= @side :spectator) "opponent"]]

[:div.inner-leftpane
[audio-component {:sfx sfx}]

[:div.left-inner-leftpane
[:div
Expand All @@ -1647,8 +1658,7 @@
(when-not (= @side :spectator)
[button-pane {:side me-side :active-player active-player :run run :end-turn end-turn
:runner-phase-12 runner-phase-12 :corp-phase-12 corp-phase-12
:corp corp :runner runner :me me :opponent opponent
:sfx sfx}])]]
:corp corp :runner runner :me me :opponent opponent}])]]

[:div.me
[hand-view me-user (if (= :corp me-side) "HQ" "Grip") me-hand me-prompt
Expand Down

0 comments on commit d3d85a0

Please sign in to comment.