From 43e1a88efcf03b5229ae027778d2a0d140623c2f Mon Sep 17 00:00:00 2001 From: Noah Bogart Date: Wed, 17 Jul 2024 14:37:18 -0400 Subject: [PATCH 1/2] Fix differ issues from json->edn conversion --- project.clj | 2 +- src/cljs/nr/gameboard/actions.cljs | 2 +- src/cljs/nr/gameboard/board.cljs | 20 ++++++++++---------- src/cljs/nr/gameboard/state.cljs | 12 +++++++++++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/project.clj b/project.clj index 60ccce7f3a..66617debfc 100644 --- a/project.clj +++ b/project.clj @@ -59,7 +59,7 @@ [potemkin "0.4.5"] [cond-plus "1.1.1"] [org.clojure/data.csv "1.0.0"] - [medley "1.3.0"] + [dev.weavejester/medley "1.8.0"] [org.slf4j/slf4j-nop "1.7.32"] [integrant "0.8.0"] [cljc.java-time "0.1.18"] diff --git a/src/cljs/nr/gameboard/actions.cljs b/src/cljs/nr/gameboard/actions.cljs index 2880cfc7c6..9ecee9c518 100644 --- a/src/cljs/nr/gameboard/actions.cljs +++ b/src/cljs/nr/gameboard/actions.cljs @@ -43,7 +43,7 @@ (defn handle-diff! [{:keys [gameid diff]}] (when (= gameid (str (current-gameid app-state))) - (swap! game-state #(differ/patch @last-state diff)) + (reset! game-state (differ/patch @last-state diff)) (check-lock?) (reset! last-state @game-state))) diff --git a/src/cljs/nr/gameboard/board.cljs b/src/cljs/nr/gameboard/board.cljs index f94022da2c..329ffa984d 100644 --- a/src/cljs/nr/gameboard/board.cljs +++ b/src/cljs/nr/gameboard/board.cljs @@ -1606,16 +1606,16 @@ ;; otherwise choice of all present choices :else - (doall (for [{:keys [idx uuid value]} choices] - (when (not= value "Hide") - [:button {:key idx - :on-click #(do (send-command "choice" {:choice {:uuid uuid}}) - (card-highlight-mouse-out % value button-channel)) - :on-mouse-over - #(card-highlight-mouse-over % value button-channel) - :on-mouse-out - #(card-highlight-mouse-out % value button-channel)} - (render-message (or (not-empty (get-title value)) value))]))))])) + (doall (for [{:keys [idx uuid value]} choices + :when (not= value "Hide")] + [:button {:key idx + :on-click #(do (send-command "choice" {:choice {:uuid uuid}}) + (card-highlight-mouse-out % value button-channel)) + :on-mouse-over + #(card-highlight-mouse-over % value button-channel) + :on-mouse-out + #(card-highlight-mouse-out % value button-channel)} + (render-message (or (not-empty (get-title value)) value))])))])) (defn basic-actions [{:keys [side active-player end-turn runner-phase-12 corp-phase-12 me]}] [:div.panel.blue-shade diff --git a/src/cljs/nr/gameboard/state.cljs b/src/cljs/nr/gameboard/state.cljs index 372cce9cb6..c3e7e9a1bf 100644 --- a/src/cljs/nr/gameboard/state.cljs +++ b/src/cljs/nr/gameboard/state.cljs @@ -1,5 +1,6 @@ (ns nr.gameboard.state (:require + [clojure.walk :as walk] [nr.appstate :refer [app-state]] [nr.ws :as ws] [reagent.core :as r])) @@ -13,7 +14,16 @@ (defonce replay-side (r/atom :spectator)) (defn parse-state [state] - (js->clj (.parse js/JSON state) :keywordize-keys true)) + (let [state (js->clj (.parse js/JSON state) :keywordize-keys true)] + (if-let [diff (:diff state)] + (assoc state :diff (walk/postwalk + (fn [obj] + (if (or (list? obj) + (vector? obj)) + (mapv #(if (= "+" %) :+ %) obj) + obj)) + diff)) + state))) (defn get-side [state] (let [user-id (get-in @app-state [:user :_id])] From ae5566b42e7d5b7907e6c592b33895cda4bf291f Mon Sep 17 00:00:00 2001 From: Noah Bogart Date: Wed, 17 Jul 2024 15:04:44 -0400 Subject: [PATCH 2/2] Slim prompt choices when cards --- src/clj/game/core/diffs.clj | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/clj/game/core/diffs.clj b/src/clj/game/core/diffs.clj index 339cc01636..48c8c574de 100644 --- a/src/clj/game/core/diffs.clj +++ b/src/clj/game/core/diffs.clj @@ -204,13 +204,26 @@ (defn prompt-summary [prompt same-side?] - (if same-side? - (not-empty (select-non-nil-keys prompt prompt-keys)) - nil)) + (when same-side? + (-> prompt + (update :card #(not-empty (select-non-nil-keys % card-keys))) + (update :choices (fn [choices] + (if (sequential? choices) + (->> choices + (mapv + (fn [choice] + (if (-> choice :value :cid) + (update choice :value select-non-nil-keys card-keys) + choice))) + (not-empty)) + choices))) + (select-non-nil-keys prompt-keys) + (not-empty)))) (defn toast-summary [toast same-side?] - (if same-side? toast nil)) + (when same-side? + toast)) (def player-keys [:aid