Skip to content

Commit 59320c7

Browse files
committed
Add option -p to print in pack order
1 parent ced31d3 commit 59320c7

File tree

2 files changed

+113
-13
lines changed

2 files changed

+113
-13
lines changed

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ mcdbcli -d 677339
1818
mcdbcli -l 36680
1919
```
2020

21+
-p : Print in pack order
22+
2123
-r : Print in release order
2224

23-
-w : Print in waves ordered by aspect
25+
-w : Print in wave order
2426

2527
Without -d or -l arguments `mcdbcli` will read deck as JSON from stdin
2628

@@ -141,6 +143,78 @@ Wave #4
141143
1 × Shield Spell (Wave #4 The Mad Titan's Shadow #61)
142144
```
143145

146+
Print a popular deck by pack and aspect:
147+
148+
```console
149+
$ mcdbcli -l 13922 -p
150+
Wild Tutor - Adam Warlock
151+
Core Set
152+
Aggression cards
153+
1 × The Power of Aggression (Wave #1 Core Set #55)
154+
Justice cards
155+
1 × The Power of Justice (Wave #1 Core Set #62)
156+
Leadership cards
157+
1 × The Power of Leadership (Wave #1 Core Set #72)
158+
Protection cards
159+
1 × The Power of Protection (Wave #1 Core Set #79)
160+
Basic cards
161+
1 × Nick Fury (Wave #1 Core Set #84)
162+
1 × Energy (Wave #1 Core Set #88)
163+
1 × Genius (Wave #1 Core Set #89)
164+
1 × Strength (Wave #1 Core Set #90)
165+
Ms. Marvel
166+
Justice cards
167+
1 × Concussive Blow (Wave #1 Ms. Marvel #31)
168+
Protection cards
169+
1 × Tackle (Wave #1 Ms. Marvel #15)
170+
Doctor Strange
171+
Protection cards
172+
1 × Brother Voodoo (Wave #1 Doctor Strange #12)
173+
Basic cards
174+
1 × The Sorcerer Supreme (Wave #1 Doctor Strange #26)
175+
Hulk
176+
Aggression cards
177+
1 × Drop Kick (Wave #1 Hulk #14)
178+
1 × Martial Prowess (Wave #1 Hulk #18)
179+
Wasp
180+
Basic cards
181+
1 × The Power in All of Us (Wave #2 Wasp #24)
182+
Scarlet Witch
183+
Basic cards
184+
1 × Spiritual Meditation (Wave #2 Scarlet Witch #19)
185+
Galaxy's Most Wanted
186+
Basic cards
187+
1 × Deft Focus (Wave #3 Galaxy's Most Wanted #24)
188+
Drax
189+
Justice cards
190+
1 × "Think Fast!" (Wave #3 Drax #31)
191+
Basic cards
192+
1 × Gamora (Wave #3 Drax #20)
193+
Venom
194+
Leadership cards
195+
1 × "Welcome Aboard" (Wave #3 Venom #27)
196+
The Mad Titan's Shadow
197+
Adam Warlock cards
198+
1 × Pip the Troll (Wave #4 The Mad Titan's Shadow #32)
199+
1 × Soul World (Wave #4 The Mad Titan's Shadow #33)
200+
1 × Karmic Staff (Wave #4 The Mad Titan's Shadow #34)
201+
1 × Warlock's Cape (Wave #4 The Mad Titan's Shadow #35)
202+
2 × Cosmic Ward (Wave #4 The Mad Titan's Shadow #36)
203+
2 × Mystic Senses (Wave #4 The Mad Titan's Shadow #37)
204+
3 × Karmic Blast (Wave #4 The Mad Titan's Shadow #38)
205+
2 × Cosmic Awareness (Wave #4 The Mad Titan's Shadow #39)
206+
2 × Quantum Magic (Wave #4 The Mad Titan's Shadow #40)
207+
Aggression cards
208+
1 × Magic Attack (Wave #4 The Mad Titan's Shadow #43)
209+
Justice cards
210+
1 × Zone of Silence (Wave #4 The Mad Titan's Shadow #50)
211+
Leadership cards
212+
1 × Kaluu (Wave #4 The Mad Titan's Shadow #14)
213+
1 × Summoning Spell (Wave #4 The Mad Titan's Shadow #55)
214+
Protection cards
215+
1 × Shield Spell (Wave #4 The Mad Titan's Shadow #61)
216+
```
217+
144218
Print a popular deck in absolute release order:
145219

146220
```console

mcdbcli

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
declare MCDB_API_URL='https://marvelcdb.com/api/public'
44
declare CARDS_CACHE="${HOME}/.mcdb/cards"
5-
declare WAVE_ORDER=false
5+
declare PACK_ORDER=false
66
declare RELEASE_ORDER=false
7+
declare WAVE_ORDER=false
78
declare DECK_JSON
89

910
print_faction_color() {
@@ -139,24 +140,44 @@ print_factions() {
139140
done
140141
}
141142

142-
print_waves() {
143+
group_by_faction() {
143144
local cards_json="$1"
144-
145145
local IFS='
146146
'
147-
for wave_json in $(jq -c '.[]' <<<"$cards_json"); do
148-
local card_id=$(jq -r '.[0].code' <<<"$wave_json")
149-
local wave_number=$(get_wave_number $card_id)
150-
printf 'Wave #%d\n' "$wave_number"
151-
local faction_json=$(jq -c 'group_by(.faction_code |
147+
jq -c 'group_by(.faction_code |
152148
if . == "hero" then 1
153149
elif . == "aggression" then 2
154150
elif . == "justice" then 3
155151
elif . == "leadership" then 4
156152
elif . == "protection" then 5
157153
elif . == "pool" then 5
158154
elif . == "basic" then 6
159-
else 99 end)' <<<"$wave_json")
155+
else 99 end)' <<<"$cards_json"
156+
}
157+
158+
print_waves() {
159+
local waves_json="$1"
160+
161+
local IFS='
162+
'
163+
for wave_json in $(jq -c '.[]' <<<"$waves_json"); do
164+
local card_id=$(jq -r '.[0].code' <<<"$wave_json")
165+
local wave_number=$(get_wave_number $card_id)
166+
printf 'Wave #%d\n' "$wave_number"
167+
local faction_json=$(group_by_faction "$wave_json")
168+
print_factions "$faction_json"
169+
done
170+
}
171+
172+
print_packs() {
173+
local packs_json="$1"
174+
175+
local IFS='
176+
'
177+
for pack_json in $(jq -c '.[]' <<<"$packs_json"); do
178+
local pack_name=$(jq -r '.[0].pack_name' <<<"$pack_json")
179+
printf '%s\n' "$pack_name"
180+
local faction_json=$(group_by_faction "$pack_json")
160181
print_factions "$faction_json"
161182
done
162183
}
@@ -175,7 +196,7 @@ print_deck() {
175196
printf '%s\n' "$deck_name"
176197

177198
local -a card_files
178-
for card_id_json in $(jq -cr '.slots | keys | .[]' <<<"$DECK_JSON"); do
199+
for card_id_json in $(jq -r '.slots | keys | .[]' <<<"$DECK_JSON"); do
179200
card_files+=($(get_card_file $card_id_json))
180201
done
181202

@@ -191,8 +212,10 @@ print_deck() {
191212
elif . < 50 then 8
192213
else 99 end)' "${card_files[@]}")
193214
print_waves "$cards_json"
215+
elif $PACK_ORDER; then
216+
local cards_json=$(jq -cn '[inputs] | group_by(.code | .[0:2] | tonumber)' "${card_files[@]}")
217+
print_packs "$cards_json"
194218
elif $RELEASE_ORDER; then
195-
# local cards_json=$(jq -cn '[inputs]' "${card_files[@]}")
196219
print_cards "${card_files[@]}"
197220
else
198221
local cards_json=$(jq -cn '[inputs] | group_by(.faction_code |
@@ -208,14 +231,17 @@ print_deck() {
208231
fi
209232
}
210233

211-
while getopts 'd:l:rw' opt; do
234+
while getopts 'd:l:rwp' opt; do
212235
case $opt in
213236
d)
214237
DECK_JSON="$(curl -s "${MCDB_API_URL}/deck/${OPTARG}")"
215238
;;
216239
l)
217240
DECK_JSON="$(curl -s "${MCDB_API_URL}/decklist/${OPTARG}")"
218241
;;
242+
p)
243+
PACK_ORDER=true
244+
;;
219245
r)
220246
RELEASE_ORDER=true
221247
;;

0 commit comments

Comments
 (0)