22
33declare MCDB_API_URL=' https://marvelcdb.com/api/public'
44declare CARDS_CACHE=" ${HOME} /.mcdb/cards"
5- declare WAVE_ORDER =false
5+ declare PACK_ORDER =false
66declare RELEASE_ORDER=false
7+ declare WAVE_ORDER=false
78declare DECK_JSON
89
910print_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