Skip to content

Commit

Permalink
Merge pull request #7565 from NoahTheDuke/nb/fix-7424-empty-buttons
Browse files Browse the repository at this point in the history
Fix differ issues from json->edn conversion
  • Loading branch information
NoahTheDuke authored Jul 17, 2024
2 parents 6cacbd0 + ae5566b commit 2d7ea55
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
21 changes: 17 additions & 4 deletions src/clj/game/core/diffs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,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
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/nr/gameboard/actions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
20 changes: 10 additions & 10 deletions src/cljs/nr/gameboard/board.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,16 +1660,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
Expand Down
12 changes: 11 additions & 1 deletion src/cljs/nr/gameboard/state.cljs
Original file line number Diff line number Diff line change
@@ -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]))
Expand All @@ -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])]
Expand Down

0 comments on commit 2d7ea55

Please sign in to comment.