Skip to content

Commit 8cfce26

Browse files
committed
Fix wave number for Rise of Red Skull
1 parent 5a8721d commit 8cfce26

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

mcdbcli

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#!/bin/bash
22

33
declare MCDB_API_URL='https://marvelcdb.com/api/public'
4-
declare CARDS_CACHE="${HOME}/.mcdb/cards"
4+
declare MCDB_CACHE="${HOME}/.mcdb"
5+
declare PACKS_CACHE="${MCDB_CACHE}/packs.json"
6+
declare CARDS_CACHE="${MCDB_CACHE}/cards"
57
declare ALPHABETICAL_ORDER=false
68
declare PACK_ORDER=false
79
declare RELEASE_ORDER=false
810
declare SUPER_ALPHABETICAL_ORDER=false
911
declare WAVE_ORDER=false
1012
declare DECK_JSON
1113

14+
init_packs() {
15+
if [ ! -d $MCDB_CACHE ]; then
16+
mkdir -p $MCDB_CACHE
17+
fi
18+
19+
if [ ! -f $PACKS_CACHE ]; then
20+
curl -so "$PACKS_CACHE" "${MCDB_API_URL}/packs/"
21+
fi
22+
23+
local -a pack_positions=($(jq -r '.[] | @text "\(.code)=\(.position)"' <$PACKS_CACHE))
24+
export "${pack_positions[@]}"
25+
}
26+
1227
print_faction_color() {
1328
local faction_code="$1"
1429
case $faction_code in
@@ -37,24 +52,24 @@ print_faction_color() {
3752
}
3853

3954
get_wave_number() {
40-
local pack_id=${1:0:2}
41-
local -i pack_number=${pack_id#0}
55+
local pack_code=$1
56+
local pack_position=$(jq -nr --arg pack_code $pack_code 'env[$pack_code]')
4257

43-
if [ $pack_number -lt 11 ]; then
58+
if [ $pack_position -lt 10 ]; then
4459
echo 1
45-
elif [ $pack_number -lt 16 ]; then
60+
elif [ $pack_position -lt 16 ]; then
4661
echo 2
47-
elif [ $pack_number -lt 21 ]; then
62+
elif [ $pack_position -lt 21 ]; then
4863
echo 3
49-
elif [ $pack_number -lt 27 ]; then
64+
elif [ $pack_position -lt 27 ]; then
5065
echo 4
51-
elif [ $pack_number -lt 32 ]; then
66+
elif [ $pack_position -lt 32 ]; then
5267
echo 5
53-
elif [ $pack_number -lt 39 ]; then
68+
elif [ $pack_position -lt 40 ]; then
5469
echo 6
55-
elif [ $pack_number -lt 45 ]; then
70+
elif [ $pack_position -lt 45 ]; then
5671
echo 7
57-
elif [ $pack_number -lt 50 ]; then
72+
elif [ $pack_position -lt 50 ]; then
5873
echo 8
5974
else
6075
echo 99
@@ -65,7 +80,8 @@ print_card() {
6580
local card_json="$1"
6681

6782
local card_id="$(jq -r '.code' <<<$card_json)"
68-
local wave_number=$(get_wave_number "$card_id")
83+
local pack_code="$(jq -r '.pack_code' <<<$card_json)"
84+
local wave_number=$(get_wave_number "$pack_code")
6985
local amount=$(jq -r --arg card_id $card_id '.slots[$card_id]' <<<"${DECK_JSON}")
7086
local faction_code="$(jq -r '.faction_code' <<<$card_json)"
7187
local card_name="$(jq -r '.real_name' <<<$card_json)"
@@ -165,8 +181,8 @@ print_waves() {
165181
local IFS='
166182
'
167183
for wave_json in $(jq -c '.[]' <<<"$waves_json"); do
168-
local card_id=$(jq -r '.[0].code' <<<"$wave_json")
169-
local wave_number=$(get_wave_number $card_id)
184+
local pack_code=$(jq -r '.[0].pack_code' <<<"$wave_json")
185+
local wave_number=$(get_wave_number $pack_code)
170186
printf 'Wave #%d\n' "$wave_number"
171187
local faction_json=$(group_by_faction "$wave_json")
172188
print_factions "$faction_json"
@@ -217,19 +233,19 @@ print_deck() {
217233
elif $RELEASE_ORDER; then
218234
print_cards "${card_files[@]}"
219235
elif $WAVE_ORDER; then
220-
local cards_json=$(jq -cn '[inputs] | group_by(.code | .[0:2] | tonumber |
221-
if . < 11 then 1
236+
local cards_json=$(jq -cn '[inputs] | group_by(.pack_code as $pack | env[$pack] | tonumber |
237+
if . < 10 then 1
222238
elif . < 16 then 2
223239
elif . < 21 then 3
224240
elif . < 27 then 4
225241
elif . < 32 then 5
226-
elif . < 39 then 6
242+
elif . < 40 then 6
227243
elif . < 45 then 7
228244
elif . < 50 then 8
229245
else 99 end)' "${card_files[@]}")
230246
print_waves "$cards_json"
231247
elif $PACK_ORDER; then
232-
local cards_json=$(jq -cn '[inputs] | group_by(.code | .[0:2] | tonumber)' "${card_files[@]}")
248+
local cards_json=$(jq -cn '[inputs] | group_by(.pack_code as $pack | env[$pack])' "${card_files[@]}")
233249
print_packs "$cards_json"
234250
else
235251
local cards_json=$(jq -cn '[inputs] | group_by(.faction_code |
@@ -245,6 +261,8 @@ print_deck() {
245261
fi
246262
}
247263

264+
init_packs
265+
248266
while getopts 'd:l:aprw' opt; do
249267
case $opt in
250268
d)

0 commit comments

Comments
 (0)