Skip to content

Commit afea20e

Browse files
authored
Merge pull request #8012 from NBKelly/alt-art-grouping
Alt art grouping
2 parents 43eafea + 1444438 commit afea20e

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/clj/tasks/images.clj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@
4343
(println "Removing old images from db cards")
4444
(mc/update db card-collection {} {$unset {:faces 1}} {:multi true})
4545
(mc/update db card-collection {} {$unset {:images 1}} {:multi true}))
46+
;; note: this should select a period, perhaps preceeded by an alphabetic string,
47+
;; so long as it either has front,back,or some numbers behind it
48+
;; the excess dots are because the lookbehind needs to be fixed width
49+
;; but this ensures we don't split on "front.", and instead split on "." for multi-faced cards
50+
(def ^:cost image-select-regex #"(?<=(.tank|house|ewery|front|.back|....[0123456789]))[a-zA-Z]*\.")
4651

4752
(defn- add-flip-card-image
4853
[db base-path lang resolution art-set filename]
49-
(let [code-face (first (str/split filename #"\."))
54+
(let [code-face (first (str/split filename image-select-regex))
5055
code-face-split (str/split code-face #"-")
5156
code (first code-face-split)
5257
face (second code-face-split)
@@ -66,14 +71,14 @@
6671
(let [filename (.getName f)]
6772
(if (str/includes? filename "-")
6873
(add-flip-card-image db base-path lang resolution art-set filename)
69-
(let [code (first (str/split filename #"\."))
74+
(let [code (first (str/split filename image-select-regex))
7075
k (str/join "." ["images" (name lang) (name resolution) (name art-set)])
7176
prev-k-root (if (= :stock art-set) code (name art-set))
7277
prev-k (str/join "." ["images" (name lang) (name resolution) prev-k-root])
7378
path (str/join "/" [base-path (name lang) (name resolution) (name art-set) filename])]
7479
(when-not (some #(= % code) cards-to-skip)
75-
(mc/update db card-collection {:code code} {$set {k path}})
76-
(mc/update db card-collection {:previous-versions {$elemMatch {:code code}}} {$set {prev-k path}})))))))
80+
(mc/update db card-collection {:code code} {$addToSet {k path}})
81+
(mc/update db card-collection {:previous-versions {$elemMatch {:code code}}} {$addToSet {prev-k path}})))))))
7782

7883
(defn- add-alt-images
7984
"All all images in the specified alt directory"

src/cljs/nr/cardbrowser.cljs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,24 @@
199199
[card]
200200
(let [lang (get-in @app-state [:options :language] "en")
201201
res (get-in @app-state [:options :card-resolution] "default")
202-
art (if (keyword? (:art card)) (:art card) :stock)]
203-
(get-image-path (:images card) (keyword lang) (keyword res) art)))
202+
art (if (keyword? (:art card)) (:art card) :stock)
203+
art-index (get card :art-index 0)]
204+
[(nth (get-image-path (:images card) (keyword lang) (keyword res) art) art-index)]))
204205

205206
(defn- alt-version-from-string
206207
"Given a string name, get the keyword version or nil"
207208
[setname]
208209
(when-let [alt (find-first #(= setname (:name %)) (:alt-info @app-state))]
209210
(keyword (:version alt))))
210211

212+
(defn- card-arts-for-key
213+
[card key]
214+
(let [lang (get-in @app-state [:options :language] "en")
215+
res (get-in @app-state [:options :card-resolution] "default")]
216+
(if-let [arts (get-in card [:images (keyword lang) (keyword res) key])]
217+
(vec (map-indexed (fn [idx item] (assoc card :art key :art-index idx)) arts))
218+
[(assoc card :art "" :art-index 0)])))
219+
211220
(defn- expand-alts
212221
[only-version acc card]
213222
(let [lang (get-in @app-state [:options :language] "en")
@@ -225,7 +234,7 @@
225234
(show-alt-art? true))
226235
(->> filtered-images
227236
(concat [""])
228-
(map #(if % (assoc card :art %) card))
237+
(mapcat #(card-arts-for-key card %))
229238
(map #(if (not= "" (:art %)) (dissoc % :previous-versions) %))
230239
(concat acc))
231240
(conj acc card))))
@@ -286,10 +295,11 @@
286295
art (:art card)
287296
code-kw (keyword (:future-version card (:code card)))
288297
alts (:alt-arts (:options @app-state))
298+
alt-index (get card :art-index 0)
289299
new-alts (cond
290-
(keyword? art) (assoc alts code-kw (name art))
300+
(keyword? art) (assoc alts code-kw [(name art) alt-index])
291301
is-old-card (assoc alts code-kw (:code card))
292-
:else (dissoc alts code-kw))] ; remove the key entirely if the newest card is selected
302+
:else (dissoc alts code-kw))]
293303
(swap! app-state assoc-in [:options :alt-arts] new-alts)
294304
(nr.account/post-options (partial post-response))))
295305

src/cljs/nr/gameboard/board.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
"stock")
6161
card (if (or (:face card) (:images card)) card (get @all-cards (get-title card)))
6262
images (image-or-face card)]
63-
(get-image-path images (keyword lang) (keyword res) (keyword art))))
63+
(if (sequential? art)
64+
(let [art-urls (get-image-path images (keyword lang) (keyword res) (keyword (first art)))
65+
chosen-art (nth art-urls (second art))]
66+
[chosen-art])
67+
(get-image-path images (keyword lang) (keyword res) (keyword art)))))
6468

6569

6670
(defonce button-channel (chan))

0 commit comments

Comments
 (0)