From 905bdc6869a0677f257cf98ae0f7478749ccee03 Mon Sep 17 00:00:00 2001 From: cardboardtech <5953664+cardboardtech@users.noreply.github.com> Date: Thu, 29 Jul 2021 18:40:35 -0500 Subject: [PATCH 1/4] Don't close discard/deck popup when clicking in the popup --- src/cljs/nr/gameboard/board.cljs | 61 ++++++++++++++++---------------- src/css/gameboard.styl | 12 +++---- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/cljs/nr/gameboard/board.cljs b/src/cljs/nr/gameboard/board.cljs index aaffb300ed..cdd73cb2b8 100644 --- a/src/cljs/nr/gameboard/board.cljs +++ b/src/cljs/nr/gameboard/board.cljs @@ -591,14 +591,14 @@ facedown)) (defn card-view - [card flipped] + [card flipped disable-click] (let [c-state (r/atom {})] (fn [{:keys [zone code type abilities counter advance-counter advancementcost current-advancement-requirement subtype subtypes advanceable rezzed strength current-strength title selected hosted side rec-counter facedown server-target subtype-target icon new runner-abilities subroutines corp-abilities] :as card} - flipped] + flipped disable-click] [:div.card-frame [:div.blue-shade.card {:class (str (when selected "selected") (when new " new") @@ -614,7 +614,8 @@ (= (:side @game-state) (keyword (lower-case side)))) (put! zoom-channel card)) :on-mouse-leave #(put! zoom-channel false) - :on-click #(handle-card-click card c-state)} + :on-click #(when (not disable-click) + (handle-card-click card c-state))} (if (or (not code) flipped facedown) (let [facedown-but-known (or (not (or (not code) flipped facedown)) (spectator-view-hidden?) @@ -804,12 +805,12 @@ (fn [render-side player-side identity deck] ; deck-count is only sent to live games and does not exist in the replay (let [deck-count-number (if (nil? @deck-count) (count @deck) @deck-count)] - [:div.blue-shade.deck - (drop-area title {:on-click #(-> (menu-ref @board-dom) js/$ .toggle)}) - (when (pos? deck-count-number) - [facedown-card (:side @identity) ["bg"] nil]) - [:div.header {:class "darkbg server-label"} - (str title " (" deck-count-number ")")] + [:div.deck-container (drop-area title {}) + [:div.blue-shade.deck {:on-click #(-> (menu-ref @board-dom) js/$ .toggle)} + (when (pos? deck-count-number) + [facedown-card (:side @identity) ["bg"] nil]) + [:div.header {:class "darkbg server-label"} + (str title " (" deck-count-number ")")]] (when (= render-side player-side) [:div.panel.blue-shade.menu {:ref #(swap! board-dom assoc menu-ref %)} [:div {:on-click #(do (send-command "shuffle") @@ -830,12 +831,12 @@ (defn discard-view-runner [player-side discard] (let [s (r/atom {})] (fn [player-side discard] - [:div.blue-shade.discard - (drop-area "Heap" {:on-click #(-> (:popup @s) js/$ .fadeToggle)}) - (when-not (empty? @discard) - [card-view (last @discard)]) - [:div.header {:class "darkbg server-label"} - (str (tr [:game.heap "Heap"]) " (" (count @discard) ")")] + [:div.discard-container (drop-area "Heap" {}) + [:div.blue-shade.discard {:on-click #(-> (:popup @s) js/$ .fadeToggle)} + (when-not (empty? @discard) + [card-view (last @discard) nil true]) + [:div.header {:class "darkbg server-label"} + (str (tr [:game.heap "Heap"]) " (" (count @discard) ")")]] [:div.panel.blue-shade.popup {:ref #(swap! s assoc :popup %) :class (if (= player-side :runner) "me" "opponent")} [:div @@ -849,22 +850,22 @@ (let [s (r/atom {})] (fn [player-side discard] (let [faceup? #(or (:seen %) (:rezzed %)) - draw-card #(if (faceup? %) - [card-view %] + draw-card #(if (faceup? %1) + [card-view %1 nil %2] (if (or (= player-side :corp) (spectator-view-hidden?)) - [:div.unseen [card-view %]] + [:div.unseen [card-view %1 nil %2]] [facedown-card "corp"]))] - [:div.blue-shade.discard - (drop-area "Archives" {:on-click #(-> (:popup @s) js/$ .fadeToggle)}) - (when-not (empty? @discard) - [:<> {:key "discard"} (draw-card (last @discard))]) - [:div.header {:class "darkbg server-label"} - (let [total (count @discard) - face-up (count (filter faceup? @discard))] - (str (tr [:game.archives "Archives"]) - ;; use non-breaking space to keep counts on same line - " (" (tr [:game.up-down-count] total face-up) ")"))] + [:div.discard-container (drop-area "Archives" {}) + [:div.blue-shade.discard {:on-click #(-> (:popup @s) js/$ .fadeToggle)} + (when-not (empty? @discard) + [:<> {:key "discard"} (draw-card (last @discard) true)]) + [:div.header {:class "darkbg server-label"} + (let [total (count @discard) + face-up (count (filter faceup? @discard))] + (str (tr [:game.archives "Archives"]) + ;; use non-breaking space to keep counts on same line + " (" (tr [:game.up-down-count] total face-up) ")"))]] [:div.panel.blue-shade.popup {:ref #(swap! s assoc :popup %) :class (if (= (:side @game-state) :runner) "opponent" "me")} [:div @@ -875,7 +876,7 @@ (doall (for [[idx c] (map-indexed vector @discard)] ^{:key idx} - [:div (draw-card c)]))]])))) + [:div (draw-card c false)]))]])))) (defn rfg-view [cards name popup] (let [dom (atom {})] @@ -1635,7 +1636,7 @@ (when (pos? (count @autocomp)) (-> "#card-title" js/$ (.autocomplete (clj->js {"source" @autocomp})))) (when @show-discard? - (-> ".me .discard .popup" js/$ .fadeIn)) + (-> ".me .discard-container .popup" js/$ .fadeIn)) (if (= "select" @prompt-type) (set! (.-cursor (.-style (.-body js/document))) "url('/img/gold_crosshair.png') 12 12, crosshair") (set! (.-cursor (.-style (.-body js/document))) "default")) diff --git a/src/css/gameboard.styl b/src/css/gameboard.styl index f3804a0409..123352ba9d 100644 --- a/src/css/gameboard.styl +++ b/src/css/gameboard.styl @@ -46,7 +46,7 @@ top: 100% transform: translate(0, -100%) - .card-frame, .deck, .identity, .discard + .card-frame, .deck-container, .identity, .discard-container pointer-events: auto .card-frame @@ -241,7 +241,8 @@ .card float: left - margin: 2px + margin-right: 4px + margin-bottom: 2px a label @@ -305,10 +306,7 @@ margin-left: 16px margin-right: 16px - .discard - position: relative - - .hand-container + .hand-container, .deck-container, .discard-container position: relative .hand-controls @@ -683,7 +681,7 @@ padding: 5px 0 display-flex() - .deck, .discard, .identity + .deck-container, .discard-container, .identity margin-left: 16px margin-right: 16px From aa898df60d4a63be1e01e2048cb2a30c10383068 Mon Sep 17 00:00:00 2001 From: cardboardtech <5953664+cardboardtech@users.noreply.github.com> Date: Sat, 31 Jul 2021 11:39:54 -0500 Subject: [PATCH 2/4] Close discard view when ability with :show-discard ends --- src/clj/game/core/diffs.clj | 3 ++- src/clj/game/core/eid.clj | 2 +- src/clj/web/game.clj | 11 +++++++++++ src/cljs/nr/gameboard/board.cljs | 9 +++++---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/clj/game/core/diffs.clj b/src/clj/game/core/diffs.clj index 8d8655f8b5..ddadd72e6a 100644 --- a/src/clj/game/core/diffs.clj +++ b/src/clj/game/core/diffs.clj @@ -90,7 +90,6 @@ :choices :card :prompt-type - :show-discard ;; traces :player :base @@ -132,6 +131,7 @@ :quote :register :prompt-state + :show-discard :agenda-point :agenda-point-req]) @@ -146,6 +146,7 @@ (update :scored card-summary-vec state side) (update :register select-keys [:spent-click]) (prompt-summary same-side?) + (update :show-discard #(when same-side? %)) (prune-null-fields))) (defn corp-keys [] diff --git a/src/clj/game/core/eid.clj b/src/clj/game/core/eid.clj index fb64bba177..3101ee7528 100644 --- a/src/clj/game/core/eid.clj +++ b/src/clj/game/core/eid.clj @@ -22,7 +22,7 @@ (defn register-effect-completed [state eid effect] (if (get-in @state [:effect-completed (:eid eid)]) - (throw (Exception. (str "Eid has alreasy been registered"))) + (throw (Exception. (str "Eid has already been registered"))) (swap! state assoc-in [:effect-completed (:eid eid)] effect))) (defn clear-eid-wait-prompt diff --git a/src/clj/web/game.clj b/src/clj/web/game.clj index 22f060ce12..58c79c6fd2 100644 --- a/src/clj/web/game.clj +++ b/src/clj/web/game.clj @@ -49,11 +49,22 @@ runner-state)))) (ws/broadcast-to! (map #(:ws-id %) spectators) event (json/generate-string spect-state)))) +(defn finalize-state + [state] + (doseq [side [:corp :runner]] + (let [prompt-show-discard (get-in @state [side :prompt-state :show-discard]) + side-show-discard (get-in @state [side :show-discard]) + set-show-discard #(swap! state assoc-in [side :show-discard] %)] + (cond prompt-show-discard (set-show-discard :show) + (= :show side-show-discard) (set-show-discard :close) + (= :close side-show-discard) (set-show-discard nil))))) + (defn swap-and-send-diffs! "Updates the old-states atom with the new game state, then sends a :netrunner/diff message to game clients." [{:keys [gameid state] :as game}] (when (and state @state) + (finalize-state state) (let [old-state (get @old-states gameid) diffs (public-diffs old-state state)] (swap! state update :history conj (:hist-diff diffs)) diff --git a/src/cljs/nr/gameboard/board.cljs b/src/cljs/nr/gameboard/board.cljs index cdd73cb2b8..58d4f1c602 100644 --- a/src/cljs/nr/gameboard/board.cljs +++ b/src/cljs/nr/gameboard/board.cljs @@ -1624,9 +1624,9 @@ (playable? (get-in @me [:basic-action-card :abilities 0]))) #(send-command "credit")]]))) -(defn button-pane [{:keys [side prompt-state]}] +(defn button-pane [{:keys [me side prompt-state]}] (let [autocomp (r/track (fn [] (get-in @prompt-state [:choices :autocomplete]))) - show-discard? (r/track (fn [] (get-in @prompt-state [:show-discard]))) + show-discard? (r/track (fn [] (get-in @me [:show-discard]))) prompt-type (r/track (fn [] (get-in @prompt-state [:prompt-type])))] (r/create-class {:display-name "button-pane" @@ -1635,8 +1635,9 @@ (fn [] (when (pos? (count @autocomp)) (-> "#card-title" js/$ (.autocomplete (clj->js {"source" @autocomp})))) - (when @show-discard? - (-> ".me .discard-container .popup" js/$ .fadeIn)) + (cond + (= "show" @show-discard?) (-> ".me .discard-container .popup" js/$ .fadeIn) + (= "close" @show-discard?) (-> ".me .discard-container .popup" js/$ .fadeOut)) (if (= "select" @prompt-type) (set! (.-cursor (.-style (.-body js/document))) "url('/img/gold_crosshair.png') 12 12, crosshair") (set! (.-cursor (.-style (.-body js/document))) "default")) From de22c045dbadf49e2c58c1d0fadb55cec5fce641 Mon Sep 17 00:00:00 2001 From: cardboardtech <5953664+cardboardtech@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:15:50 -0500 Subject: [PATCH 3/4] Move finalize state to game.core.diffs --- src/clj/game/core.clj | 3 ++- src/clj/game/core/diffs.clj | 10 ++++++++++ src/clj/web/game.clj | 12 +----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/clj/game/core.clj b/src/clj/game/core.clj index 607cf0874c..78e37a2651 100644 --- a/src/clj/game/core.clj +++ b/src/clj/game/core.clj @@ -272,7 +272,8 @@ [game.core.diffs public-states - public-diffs] + public-diffs + finalize-state] [game.core.drawing draw diff --git a/src/clj/game/core/diffs.clj b/src/clj/game/core/diffs.clj index ddadd72e6a..1f60221eac 100644 --- a/src/clj/game/core/diffs.clj +++ b/src/clj/game/core/diffs.clj @@ -334,3 +334,13 @@ :corp-diff (differ/diff old-corp new-corp) :spect-diff (differ/diff old-spect new-spect) :hist-diff (differ/diff old-hist new-hist)})) + +(defn finalize-state + [state] + (doseq [side [:corp :runner]] + (let [prompt-show-discard (get-in @state [side :prompt-state :show-discard]) + side-show-discard (get-in @state [side :show-discard]) + set-show-discard #(swap! state assoc-in [side :show-discard] %)] + (cond prompt-show-discard (set-show-discard :show) + (= :show side-show-discard) (set-show-discard :close) + (= :close side-show-discard) (set-show-discard nil))))) \ No newline at end of file diff --git a/src/clj/web/game.clj b/src/clj/web/game.clj index 58c79c6fd2..5cb2670fb4 100644 --- a/src/clj/web/game.clj +++ b/src/clj/web/game.clj @@ -9,7 +9,7 @@ [web.lobby :refer [old-states already-in-game? spectator? handle-lobby-watch] :as lobby] [web.stats :as stats] [game.main :as main] - [game.core.diffs :refer [public-diffs public-states]] + [game.core.diffs :refer [public-diffs public-states finalize-state]] [game.core :as core] [jinteki.utils :refer [side-from-str]])) @@ -49,16 +49,6 @@ runner-state)))) (ws/broadcast-to! (map #(:ws-id %) spectators) event (json/generate-string spect-state)))) -(defn finalize-state - [state] - (doseq [side [:corp :runner]] - (let [prompt-show-discard (get-in @state [side :prompt-state :show-discard]) - side-show-discard (get-in @state [side :show-discard]) - set-show-discard #(swap! state assoc-in [side :show-discard] %)] - (cond prompt-show-discard (set-show-discard :show) - (= :show side-show-discard) (set-show-discard :close) - (= :close side-show-discard) (set-show-discard nil))))) - (defn swap-and-send-diffs! "Updates the old-states atom with the new game state, then sends a :netrunner/diff message to game clients." From 48b661be989a62e5871a058fe20c1ef7279912ee Mon Sep 17 00:00:00 2001 From: cardboardtech <5953664+cardboardtech@users.noreply.github.com> Date: Sun, 1 Aug 2021 10:30:13 -0500 Subject: [PATCH 4/4] Purely client-side solution for closing the discard view when it was opened by the system. Reverted server side solutions around modifying state --- src/clj/game/core.clj | 3 +-- src/clj/game/core/diffs.clj | 15 ++------------- src/clj/web/game.clj | 3 +-- src/cljs/nr/gameboard/board.cljs | 14 ++++++++------ 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/clj/game/core.clj b/src/clj/game/core.clj index 78e37a2651..607cf0874c 100644 --- a/src/clj/game/core.clj +++ b/src/clj/game/core.clj @@ -272,8 +272,7 @@ [game.core.diffs public-states - public-diffs - finalize-state] + public-diffs] [game.core.drawing draw diff --git a/src/clj/game/core/diffs.clj b/src/clj/game/core/diffs.clj index 1f60221eac..49e64fb93e 100644 --- a/src/clj/game/core/diffs.clj +++ b/src/clj/game/core/diffs.clj @@ -90,6 +90,7 @@ :choices :card :prompt-type + :show-discard ;; traces :player :base @@ -131,7 +132,6 @@ :quote :register :prompt-state - :show-discard :agenda-point :agenda-point-req]) @@ -146,7 +146,6 @@ (update :scored card-summary-vec state side) (update :register select-keys [:spent-click]) (prompt-summary same-side?) - (update :show-discard #(when same-side? %)) (prune-null-fields))) (defn corp-keys [] @@ -333,14 +332,4 @@ {:runner-diff (differ/diff old-runner new-runner) :corp-diff (differ/diff old-corp new-corp) :spect-diff (differ/diff old-spect new-spect) - :hist-diff (differ/diff old-hist new-hist)})) - -(defn finalize-state - [state] - (doseq [side [:corp :runner]] - (let [prompt-show-discard (get-in @state [side :prompt-state :show-discard]) - side-show-discard (get-in @state [side :show-discard]) - set-show-discard #(swap! state assoc-in [side :show-discard] %)] - (cond prompt-show-discard (set-show-discard :show) - (= :show side-show-discard) (set-show-discard :close) - (= :close side-show-discard) (set-show-discard nil))))) \ No newline at end of file + :hist-diff (differ/diff old-hist new-hist)})) \ No newline at end of file diff --git a/src/clj/web/game.clj b/src/clj/web/game.clj index 5cb2670fb4..22f060ce12 100644 --- a/src/clj/web/game.clj +++ b/src/clj/web/game.clj @@ -9,7 +9,7 @@ [web.lobby :refer [old-states already-in-game? spectator? handle-lobby-watch] :as lobby] [web.stats :as stats] [game.main :as main] - [game.core.diffs :refer [public-diffs public-states finalize-state]] + [game.core.diffs :refer [public-diffs public-states]] [game.core :as core] [jinteki.utils :refer [side-from-str]])) @@ -54,7 +54,6 @@ message to game clients." [{:keys [gameid state] :as game}] (when (and state @state) - (finalize-state state) (let [old-state (get @old-states gameid) diffs (public-diffs old-state state)] (swap! state update :history conj (:hist-diff diffs)) diff --git a/src/cljs/nr/gameboard/board.cljs b/src/cljs/nr/gameboard/board.cljs index 58d4f1c602..90052fbd93 100644 --- a/src/cljs/nr/gameboard/board.cljs +++ b/src/cljs/nr/gameboard/board.cljs @@ -1624,10 +1624,11 @@ (playable? (get-in @me [:basic-action-card :abilities 0]))) #(send-command "credit")]]))) -(defn button-pane [{:keys [me side prompt-state]}] +(defn button-pane [{:keys [side prompt-state]}] (let [autocomp (r/track (fn [] (get-in @prompt-state [:choices :autocomplete]))) - show-discard? (r/track (fn [] (get-in @me [:show-discard]))) - prompt-type (r/track (fn [] (get-in @prompt-state [:prompt-type])))] + show-discard? (r/track (fn [] (get-in @prompt-state [:show-discard]))) + prompt-type (r/track (fn [] (get-in @prompt-state [:prompt-type]))) + opened-by-system (r/atom false)] (r/create-class {:display-name "button-pane" @@ -1635,9 +1636,10 @@ (fn [] (when (pos? (count @autocomp)) (-> "#card-title" js/$ (.autocomplete (clj->js {"source" @autocomp})))) - (cond - (= "show" @show-discard?) (-> ".me .discard-container .popup" js/$ .fadeIn) - (= "close" @show-discard?) (-> ".me .discard-container .popup" js/$ .fadeOut)) + (cond @show-discard? (do (-> ".me .discard-container .popup" js/$ .fadeIn) + (reset! opened-by-system true)) + @opened-by-system (do (-> ".me .discard-container .popup" js/$ .fadeOut) + (reset! opened-by-system false))) (if (= "select" @prompt-type) (set! (.-cursor (.-style (.-body js/document))) "url('/img/gold_crosshair.png') 12 12, crosshair") (set! (.-cursor (.-style (.-body js/document))) "default"))