2
2
3
3
declare MCDB_API_URL=' https://marvelcdb.com/api/public'
4
4
declare CARDS_CACHE=" ${HOME} /.mcdb/cards"
5
- declare WAVE_ORDER =false
5
+ declare PACK_ORDER =false
6
6
declare RELEASE_ORDER=false
7
+ declare WAVE_ORDER=false
7
8
declare DECK_JSON
8
9
9
10
print_faction_color () {
@@ -139,24 +140,44 @@ print_factions() {
139
140
done
140
141
}
141
142
142
- print_waves () {
143
+ group_by_faction () {
143
144
local cards_json=" $1 "
144
-
145
145
local IFS='
146
146
'
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 |
152
148
if . == "hero" then 1
153
149
elif . == "aggression" then 2
154
150
elif . == "justice" then 3
155
151
elif . == "leadership" then 4
156
152
elif . == "protection" then 5
157
153
elif . == "pool" then 5
158
154
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 " )
160
181
print_factions " $faction_json "
161
182
done
162
183
}
@@ -175,7 +196,7 @@ print_deck() {
175
196
printf ' %s\n' " $deck_name "
176
197
177
198
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
179
200
card_files+=($( get_card_file $card_id_json ) )
180
201
done
181
202
@@ -191,8 +212,10 @@ print_deck() {
191
212
elif . < 50 then 8
192
213
else 99 end)' " ${card_files[@]} " )
193
214
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 "
194
218
elif $RELEASE_ORDER ; then
195
- # local cards_json=$(jq -cn '[inputs]' "${card_files[@]}")
196
219
print_cards " ${card_files[@]} "
197
220
else
198
221
local cards_json=$( jq -cn ' [inputs] | group_by(.faction_code |
@@ -208,14 +231,17 @@ print_deck() {
208
231
fi
209
232
}
210
233
211
- while getopts ' d:l:rw ' opt; do
234
+ while getopts ' d:l:rwp ' opt; do
212
235
case $opt in
213
236
d)
214
237
DECK_JSON=" $( curl -s " ${MCDB_API_URL} /deck/${OPTARG} " ) "
215
238
;;
216
239
l)
217
240
DECK_JSON=" $( curl -s " ${MCDB_API_URL} /decklist/${OPTARG} " ) "
218
241
;;
242
+ p)
243
+ PACK_ORDER=true
244
+ ;;
219
245
r)
220
246
RELEASE_ORDER=true
221
247
;;
0 commit comments