Skip to content

Commit

Permalink
Merge pull request #5515 from lostgeek/replay-fix
Browse files Browse the repository at this point in the history
Fix for "unknown UUID" messages
  • Loading branch information
NoahTheDuke authored Feb 1, 2021
2 parents 51e8ac2 + cb54db1 commit a1c28de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
27 changes: 16 additions & 11 deletions src/cljs/nr/gameboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

(defn populate-replay-timeline
[init-state]
(let [state (dissoc init-state :replay-diffs)
(let [state (replay-prepare-state (dissoc init-state :replay-diffs))
diffs (:replay-diffs init-state)]
(reset! replay-timeline [{:type :start-of-game :state state}])
(dorun (loop [old-state @game-state
Expand Down Expand Up @@ -232,8 +232,8 @@
(reset! last-state @game-state)
(reset! lock false)
(when (:replay-diffs state)
(.setItem js/localStorage "gameid" "replay")
(swap! app-state assoc :gameid "replay")
(.setItem js/localStorage "gameid" "local-replay")
(swap! app-state assoc :gameid "local-replay") ;set for main.cljs
(populate-replay-timeline state)
(if (:replay-jump-to state)
(replay-jump-to (:replay-jump-to state))
Expand Down Expand Up @@ -286,7 +286,8 @@
(defn send-command
([command] (send-command command nil))
([command {:keys [no-lock card] :as args}]
(when (or (not @lock) no-lock)
(when (and (not (:replay @game-state))
(or (not @lock) no-lock))
(let [card (select-keys card [:cid :zone :side :host :type])
args (merge args (when (seq card) {:card card}))]
(try (js/ga "send" "event" "game" command) (catch js/Error e))
Expand All @@ -296,8 +297,9 @@
:args args}])))))

(defn mute-spectators [mute-state]
(ws/ws-send! [:netrunner/mute-spectators {:gameid-str (:gameid @game-state)
:mute-state mute-state}]))
(when (not (:replay @game-state))
(ws/ws-send! [:netrunner/mute-spectators {:gameid-str (:gameid @game-state)
:mute-state mute-state}])))

(defn stack-servers []
(swap! app-state update-in [:options :stacked-servers] not))
Expand All @@ -307,7 +309,8 @@
(swap! app-state assoc-in [:options :runner-board-order] layout)))

(defn concede []
(ws/ws-send! [:netrunner/concede {:gameid-str (:gameid @game-state)}]))
(when (not (:replay @game-state))
(ws/ws-send! [:netrunner/concede {:gameid-str (:gameid @game-state)}])))

(defn build-exception-msg [msg error]
(letfn [(build-report-url [error]
Expand Down Expand Up @@ -605,7 +608,8 @@

(defn send-msg [s]
(let [text (:msg @s)]
(when-not (empty? text)
(when (and (not (:replay @game-state))
(not (empty? text)))
(reset! should-scroll {:update false :send-msg true})
(ws/ws-send! [:netrunner/say {:gameid-str (:gameid @game-state)
:msg text}])
Expand All @@ -615,7 +619,8 @@
"Send a typing event to server for this user if it is not already set in game state AND user is not a spectator"
(let [text (:msg @s)
username (get-in @app-state [:user :username])]
(when (not-spectator?)
(when (and (not (:replay @game-state))
(not-spectator?))
(if (empty? text)
(ws/ws-send! [:netrunner/typing {:gameid-str (:gameid @game-state)
:typing false}])
Expand Down Expand Up @@ -2218,8 +2223,8 @@
:title "Forward to next log entry"} "⏩︎"]
[:button.small {:on-click #(replay-step-forward) :type "button"
:title "Forward one click"} "⏭︎"]
(when-not (= "replay" (:gameid @game-state)) ; when saved replay
(when-not (= "local-replay" (:gameid @game-state)) ; when not locally uploaded replay
[:button {:on-click #(swap! show-replay-link not)} "Share"])
(when-not (= "replay" (:gameid @game-state))
(when-not (= "local-replay" (:gameid @game-state))
[:input {:style (if @show-replay-link {:display "block"} {:display "none"})
:type "text" :value (generate-replay-link (.-origin (.-location js/window)))}])]]])])))})))))
7 changes: 3 additions & 4 deletions src/cljs/nr/gamelobby.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
(authenticated
(fn [user]
(swap! s assoc
:gameid "replay"
:gameid "local-replay"
:title (str (:username user) "'s game")
:side "Corp"
:format "standard"
Expand Down Expand Up @@ -182,9 +182,8 @@
history (:history replay)
init-state (first history)
init-state (assoc-in init-state [:options :spectatorhands] true)
init-state (assoc init-state :gameid "replay")
diffs (rest history)
init-state (assoc init-state :replay-diffs diffs)]
init-state (assoc init-state :replay-diffs diffs :gameid "local-replay")]
(ws/handle-netrunner-msg [:netrunner/start (.stringify js/JSON (clj->js init-state))])))]
(aset reader "onload" onload)
(.readAsText reader file)))
Expand All @@ -198,7 +197,7 @@
(swap! s assoc :flash-message (tr [:lobby.replay-invalid-file "Select a valid replay file."]))

:else
(do (swap! s assoc :editing false :gameid "replay")
(do (swap! s assoc :editing false)
(start-replay @s)))
(cond
(empty? (:title @s))
Expand Down
14 changes: 4 additions & 10 deletions src/cljs/nr/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
(when is-player
[:a.concede-button {:on-click #(concede)} (tr [:game.concede "Concede"])])
[:a.leave-button {:on-click #(leave-game)} (if (:replay game) (tr [:game.leave-replay "Leave replay"]) (tr [:game.leave "Leave game"]))]
(when (:replay game)
[:a.replay-button {:on-click #(set-replay-side :corp)} (tr [:game.corp-view "Corp View"])])
(when (:replay game)
[:a.replay-button {:on-click #(set-replay-side :runner)} (tr [:game.runner-view "Runner View"])])
(when (:replay game)
[:a.replay-button {:on-click #(set-replay-side :spectator)} (tr [:game.spec-view "Spectator View"])])
(when is-player
[:a.mute-button {:on-click #(mute-spectators (not (:mute-spectators game)))}
(if (:mute-spectators game) (tr [:game.unmute "Unmute spectators"]) (tr [:game.mute "Mute spectators"]))])
Expand All @@ -55,12 +49,12 @@
(tr [:game.rig-irl "Rig layout: IRL"]) (tr [:game.rig-jnet "Rig layout: jnet"]))])]))
(when (not (nil? @gameid))
[:div.float-right
[:a {:on-click #(leave-game)} (if (= "replay" @gameid) (tr [:game.leave-replay "Leave replay"]) (tr [:game.leave "Leave game"]))]
(when (= "replay" @gameid)
[:a {:on-click #(leave-game)} (if (= "local-replay" @gameid) (tr [:game.leave-replay "Leave replay"]) (tr [:game.leave "Leave game"]))]
(when (= "local-replay" @gameid)
[:a.replay-button {:on-click #(set-replay-side :corp)} (tr [:game.corp-view "Corp View"])])
(when (= "replay" @gameid)
(when (= "local-replay" @gameid)
[:a.replay-button {:on-click #(set-replay-side :runner)} (tr [:game.runner-view "Runner View"])])
(when (= "replay" @gameid)
(when (= "local-replay" @gameid)
[:a.replay-button {:on-click #(set-replay-side :spectator)} (tr [:game.spec-view "Spectator View"])])]))
(when-let [game (some #(when (= @gameid (:gameid %)) %) @games)]
(when (:started game)
Expand Down

0 comments on commit a1c28de

Please sign in to comment.