Skip to content

Commit

Permalink
Merge pull request #5510 from jwarwick/game_list
Browse files Browse the repository at this point in the history
Add option to zoom card as text
  • Loading branch information
NoahTheDuke authored Jan 25, 2021
2 parents 0a2db6a + 6da0515 commit c9d4bcb
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/clj/web/auth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
(if (acknowledged? (mc/update db "users"
{:username username}
{"$set" {:options (select-keys body [:background :pronouns :show-alt-art :blocked-users
:alt-arts :deckstats :gamestats])}}))
:alt-arts :deckstats :gamestats :card-zoom :card-back])}}))
(response 200 {:message "Refresh your browser"})
(response 404 {:message "Account not found"}))
(response 401 {:message "Unauthorized"})))
Expand Down
15 changes: 15 additions & 0 deletions src/cljs/nr/account.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(swap! app-state assoc-in [:options :sounds-volume] (:volume @s))
(swap! app-state assoc-in [:options :background] (:background @s))
(swap! app-state assoc-in [:options :card-back] (:card-back @s))
(swap! app-state assoc-in [:options :card-zoom] (:card-zoom @s))
(swap! app-state assoc-in [:options :show-alt-art] (:show-alt-art @s))
(swap! app-state assoc-in [:options :stacked-servers] (:stacked-servers @s))
(swap! app-state assoc-in [:options :runner-board-order] (:runner-board-order @s))
Expand All @@ -60,6 +61,7 @@
(.setItem js/localStorage "stacked-servers" (:stacked-servers @s))
(.setItem js/localStorage "runner-board-order" (:runner-board-order @s))
(.setItem js/localStorage "card-back" (:card-back @s))
(.setItem js/localStorage "card-zoom" (:card-zoom @s))
(post-options url (partial post-response s)))

(defn add-user-to-block-list
Expand Down Expand Up @@ -303,6 +305,18 @@
:checked (= (:card-back @s) (:ref option))}]
(:name option)]]))]

[:section
[:h3 "Card preview zoom"]
(doall (for [option [{:name "Card Image" :ref "image"}
{:name "Card Text" :ref "text"}]]
[:div.radio {:key (:name option)}
[:label [:input {:type "radio"
:name "card-zoom"
:value (:ref option)
:on-change #(swap! s assoc :card-zoom (.. % -target -value))
:checked (= (:card-zoom @s) (:ref option))}]
(:name option)]]))]

[:section
[:h3 " Game Win/Lose statistics "]
(doall (for [option [{:name "Always" :ref "always"}
Expand Down Expand Up @@ -398,6 +412,7 @@
state (r/atom {:flash-message ""
:background (get-in @app-state [:options :background])
:card-back (get-in @app-state [:options :card-back])
:card-zoom (get-in @app-state [:options :card-zoom])
:pronouns (get-in @app-state [:options :pronouns])
:sounds (get-in @app-state [:options :sounds])
:lobby-sounds (get-in @app-state [:options :lobby-sounds])
Expand Down
1 change: 1 addition & 0 deletions src/cljs/nr/appstate.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:user (js->clj js/user :keywordize-keys true)
:options (merge {:background "lobby-bg"
:card-back (get-local-value "card-back" "nisei")
:card-zoom (get-local-value "card-zoom" "image")
:pronouns "none"
:show-alt-art true
:stacked-servers (= (get-local-value "stacked-servers" "true") "true")
Expand Down
125 changes: 65 additions & 60 deletions src/cljs/nr/cardbrowser.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[nr.account :refer [alt-art-name]]
[nr.ajax :refer [GET]]
[nr.utils :refer [toastr-options banned-span restricted-span rotated-span set-scroll-top store-scroll-top
influence-dots slug->format format->slug render-icons non-game-toast]]
influence-dots slug->format format->slug render-icons non-game-toast faction-icon]]
[reagent.core :as r]))

(def cards-channel (chan))
Expand Down Expand Up @@ -193,65 +193,70 @@
:banned "invalid"
"casual"))

(defn- card-as-text
(defn card-as-text
"Generate text html representation a card"
[card]
[:div
[:h4 (:title card)]
(when-let [memory (:memoryunits card)]
(if (< memory 3)
[:div.anr-icon {:class (str "mu" memory)} ""]
[:div.heading (str "Memory: " memory) [:span.anr-icon.mu]]))
(when-let [cost (:cost card)]
[:div.heading (str "Cost: " cost)])
(when-let [trash-cost (:trash card)]
[:div.heading (str "Trash cost: " trash-cost)])
(when-let [strength (:strength card)]
[:div.heading (str "Strength: " strength)])
(when-let [requirement (:advancementcost card)]
[:div.heading (str "Advancement requirement: " requirement)])
(when-let [agenda-point (:agendapoints card)]
[:div.heading (str "Agenda points: " agenda-point)])
(when-let [min-deck-size (:minimumdecksize card)]
[:div.heading (str "Minimum deck size: " min-deck-size)])
(when-let [influence-limit (:influencelimit card)]
[:div.heading (str "Influence limit: " influence-limit)])
(when-let [influence (:factioncost card)]
(when-let [faction (:faction card)]
[:div.heading "Influence "
[:span.influence
{:class (-> faction s/lower-case (s/replace " " "-"))}
(influence-dots influence)]]))
[:div.text
[:p [:span.type (str (:type card))]
(if (empty? (:subtype card)) "" (str ": " (:subtype card)))]
[:pre (render-icons (:text (first (filter #(= (:title %) (:title card)) @all-cards))))]

[:div.formats
(doall (for [[k name] (-> slug->format butlast)]
(let [status (keyword (get-in card [:format (keyword k)] "unknown"))
c (text-class-for-status status)]
^{:key k}
[:div {:class c} name
(case status
:banned banned-span
:restricted restricted-span
:rotated rotated-span
nil)])))]

[:div.pack
(when-let [pack (:setname card)]
(when-let [number (:number card)]
(str pack " " number
(when-let [art (:art card)]
(str " [" (alt-art-name art) "]")))))]
(when (show-alt-art?)
(if (selected-alt-art card)
[:div.selected-alt "Selected Alt Art"]
(when (or (:art card) (:previous-versions card) (:future-version card))
[:button.alt-art-selector
{:on-click #(select-alt-art card)}
"Select Art"])))]])
[card show-extra-info]
(let [title (:title card)
icon (faction-icon (:faction card) title)
uniq (when (:uniqueness card) "")]
[:div
[:h4 uniq title icon]
(when-let [memory (:memoryunits card)]
(if (< memory 3)
[:div.anr-icon {:class (str "mu" memory)} ""]
[:div.heading (str "Memory: " memory) [:span.anr-icon.mu]]))
(when-let [cost (:cost card)]
[:div.heading (str "Cost: " cost)])
(when-let [trash-cost (:trash card)]
[:div.heading (str "Trash cost: " trash-cost)])
(when-let [strength (:strength card)]
[:div.heading (str "Strength: " strength)])
(when-let [requirement (:advancementcost card)]
[:div.heading (str "Advancement requirement: " requirement)])
(when-let [agenda-point (:agendapoints card)]
[:div.heading (str "Agenda points: " agenda-point)])
(when-let [min-deck-size (:minimumdecksize card)]
[:div.heading (str "Minimum deck size: " min-deck-size)])
(when-let [influence-limit (:influencelimit card)]
[:div.heading (str "Influence limit: " influence-limit)])
(when-let [influence (:factioncost card)]
(when-let [faction (:faction card)]
[:div.heading "Influence "
[:span.influence
{:class (-> faction s/lower-case (s/replace " " "-"))}
(influence-dots influence)]]))
[:div.text
[:p [:span.type (str (:type card))]
(if (empty? (:subtype card)) "" (str ": " (:subtype card)))]
[:pre (render-icons (:text (first (filter #(= (:title %) (:title card)) @all-cards))))]

(when show-extra-info
[:<>
[:div.formats
(doall (for [[k name] (-> slug->format butlast)]
(let [status (keyword (get-in card [:format (keyword k)] "unknown"))
c (text-class-for-status status)]
^{:key k}
[:div {:class c} name
(case status
:banned banned-span
:restricted restricted-span
:rotated rotated-span
nil)])))]

[:div.pack
(when-let [pack (:setname card)]
(when-let [number (:number card)]
(str pack " " number
(when-let [art (:art card)]
(str " [" (alt-art-name art) "]")))))]
(when (show-alt-art?)
(if (selected-alt-art card)
[:div.selected-alt "Selected Alt Art"]
(when (or (:art card) (:previous-versions card) (:future-version card))
[:button.alt-art-selector
{:on-click #(select-alt-art card)}
"Select Art"])))])]]))

(defn types [side]
(let [runner-types ["Identity" "Program" "Hardware" "Resource" "Event"]
Expand Down Expand Up @@ -338,7 +343,7 @@
nil)}
(if (or (= card (:selected-card @state))
(:show-text @cv))
[card-as-text card]
[card-as-text card true]
(when-let [url (base-image-url card)]
[:img {:src url
:alt (:title card)
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/nr/chat.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[nr.appstate :refer [app-state]]
[nr.auth :refer [authenticated] :as auth]
[nr.avatar :refer [avatar]]
[nr.gameboard :refer [card-preview-mouse-over card-preview-mouse-out card-zoom] :as gameboard]
[nr.gameboard :refer [card-preview-mouse-over card-preview-mouse-out] :as gameboard]
[nr.news :refer [news]]
[nr.cardbrowser :refer [image-url]]
[nr.utils :refer [toastr-options render-message set-scroll-top store-scroll-top]]
Expand Down
43 changes: 8 additions & 35 deletions src/cljs/nr/gameboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[nr.appstate :refer [app-state]]
[nr.auth :as auth]
[nr.avatar :refer [avatar]]
[nr.cardbrowser :refer [card-as-text]]
[nr.end-of-game-stats :refer [build-game-stats]]
[nr.utils :refer [banned-span influence-dot influence-dots map-longest
toastr-options render-icons render-message
Expand Down Expand Up @@ -777,47 +778,19 @@
nil [:span.unimplemented "Unimplemented"]
[:span.impl-msg implemented])]))))

(defn card-as-text
(defn card-zoom-display
[card]
[:div.card-preview.blue-shade
[:h4 (:title card)]
(when-let [memory (:memoryunits card)]
(if (< memory 3)
[:div.anr-icon {:class (str "mu" memory)} ""]
[:div.heading (str "Memory: " memory) [:span.anr-icon.mu]]))
(when-let [cost (:cost card)]
[:div.heading (str "Cost: " cost)])
(when-let [trash-cost (:trash card)]
[:div.heading (str "Trash cost: " trash-cost)])
(when-let [strength (:strength card)]
[:div.heading (str "Strength: " strength)])
(when-let [requirement (:advancementcost card)]
[:div.heading (str "Advancement requirement: " requirement)])
(when-let [agenda-point (:agendatpoints card)]
[:div.heading (str "Agenda points: " agenda-point)])
(when-let [min-deck-size (:minimumdecksize card)]
[:div.heading (str "Minimum deck size: " min-deck-size)])
(when-let [influence-limit (:influencelimit card)]
[:div.heading (str "Influence limit: " influence-limit)])
(when-let [influence (:factioncost card)]
(when-let [faction (:faction card)]
[:div.heading "Influence "
[:span.influence
{:class (-> faction lower-case (s/replace " " "-"))}
(influence-dots influence)]]))
[:div.heading
[:span.type (str (:type card))]
(when-let [subtypes (seq (:subtype card))]
(str ": " subtypes))]
[:div.text
(render-icons (:text (first (filter #(= (:title %) (:title card)) @all-cards))))]
(when-let [url (image-url card)]
[:img {:src url :alt (:title card) :onLoad #(-> % .-target js/$ .show)}])])
(let [url (image-url card)
show-img (= "image" (get-in @app-state [:options :card-zoom] "image"))]
(if (and url show-img)
[:img {:src url :alt (:title card) :onLoad #(-> % .-target js/$ .show)}]
[card-as-text card false]))])

(defn card-zoom [zoom-card]
(if-let [card @zoom-card]
(do (-> ".card-zoom" js/$ (.addClass "fade"))
[card-as-text card])
[card-zoom-display card])
(do (-> ".card-zoom" js/$ (.removeClass "fade")) nil)))

(defn server-menu
Expand Down

0 comments on commit c9d4bcb

Please sign in to comment.