Skip to content

Commit 8144dc8

Browse files
authored
Merge pull request #8548 from jwarwick/alts
Fixed alt art selection in cardbrowser, chat, and deckbuilder
2 parents 83a7cdd + e6f6294 commit 8144dc8

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/cljs/nr/cardbrowser.cljs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@
190190
([card allow-all-users]
191191
(let [lang (get-in @app-state [:options :card-language] "en")
192192
res (get-in @app-state [:options :card-resolution] "default")
193-
art (if (show-alt-art? allow-all-users)
194-
(get-in @app-state [:options :alt-arts (keyword (:code card))] "stock")
195-
"stock")
193+
alt-art (if (show-alt-art? allow-all-users)
194+
(get-in @app-state [:options :alt-arts (keyword (:code card))] "stock")
195+
"stock")
196+
art (if (sequential? alt-art) (first alt-art) alt-art)
197+
art-index (if (sequential? alt-art) (second alt-art) 0)
196198
images (image-or-face card)]
197-
(get-image-path images (keyword lang) (keyword res) (keyword art)))))
199+
(nth (get-image-path images (keyword lang) (keyword res) (keyword art)) art-index))))
198200

199201
(defn- base-image-url
200202
"The default card image. Displays an alternate image if the card is specified as one."
@@ -284,18 +286,32 @@
284286
selected-art (get selected-alts (keyword (:code card)))]
285287
(nil? selected-art)))
286288

289+
(defn- card-image-properties [card]
290+
(let [base-card-art (:art card)
291+
card-art (if (= "" base-card-art) :stock base-card-art)
292+
art-index (:art-index card)]
293+
[card-art art-index]))
294+
295+
(defn- desired-card-image-properties [code]
296+
(let [selected-alts (:alt-arts (:options @app-state))
297+
selected-alt (get selected-alts code [:stock 0])]
298+
(if (sequential? selected-alt)
299+
[(keyword (first selected-alt)) (second selected-alt)]
300+
[(keyword selected-alt) 0])))
301+
302+
;; Alts can be defined in a few different ways
303+
;; Either as a string for legacy cards
304+
;; Or as [alt-set index] for more recent alts
287305
(defn- selected-alt-art [card]
288306
(cond (contains? card :future-version) (future-selected-alt-art card)
289307
(contains? card :previous-versions) (previous-selected-alt-art card)
290308
:else
291-
(let [code (keyword (:code card))
292-
selected-alts (:alt-arts (:options @app-state))
293-
selected-art (keyword (get selected-alts code))
294-
card-art (:art card)]
295-
(or (and card-art (nil? selected-art) (= "" card-art))
296-
(and selected-art (= card-art selected-art))))))
297-
298-
;; Alts can only be set on th most recent version of a card
309+
(let [curr-card-properties (card-image-properties card)
310+
code (keyword (:code card))
311+
desired-card-properties (desired-card-image-properties code)]
312+
(= curr-card-properties desired-card-properties))))
313+
314+
;; Alts can only be set on the most recent version of a card
299315
;; So if the card has a :future-version key, we apply the alt to
300316
;; that card, setting the alt to the code of the old card.
301317
(defn- select-alt-art [card]

0 commit comments

Comments
 (0)