22# Usage: $0 <generationID>
33# If not submitted, generationID will be 6
44
5- regex=" ^([0-9]+)_?([0-9]+)?([sbfg]+)?. png$"
5+ regex=" ^([0-9]+)_?([0-9]+)?([sbfg]+)?\.( png|gif) $"
66
77ensureCommands (){
88 local commands=" jq"
@@ -36,15 +36,21 @@ convert(){
3636 # Folder where images downloaded from the Smogon spreadsheet are stored.
3737 local files=" downloads/"
3838 local formDS
39+ local formDSAnimated
3940 formDS=$( jq . forms.json)
41+ formDSAnimated=" $formDS " # default to same as formDS
42+ if [ -f forms-animated.json ]; then
43+ # Merge forms-animated.json into forms.json (animated overrides original)
44+ formDSAnimated=$( jq -n --argjson base " $formDS " --argjson animated " $( jq . forms-animated.json) " ' $base * $animated' )
45+ fi
4046 # echo "$formDS" | jq -r '.["885"]'
4147
4248 cd " $files " || exit
4349
4450 local destinationRoot=' ../../sprites/pokemon'
4551 local bwDestinationRoot=" $destinationRoot /versions/generation-v/black-white"
4652
47- for smogonName in * .png; do
53+ for smogonName in * .png * .gif ; do
4854 id=" "
4955 form=" "
5056 isFemale=" "
@@ -54,13 +60,21 @@ convert(){
5460 speciesName=" "
5561 pokemonID=" "
5662 pokemonName=" "
63+ fileExt=" "
5764 destination=" $destinationRoot "
5865 bwDestination=" $bwDestinationRoot "
5966
6067 if [[ $smogonName =~ $regex ]]; then
6168 # id=$(echo "${BASH_REMATCH[1]}" | sed 's/^0*//') # Extremely slow
6269 id=$( removeLeadingZero " ${BASH_REMATCH[1]} " ) # Slow if function
6370 form=" ${BASH_REMATCH[2]} "
71+ fileExt=" ${BASH_REMATCH[4]} "
72+
73+ # For .gif files, use animated directory
74+ if [ " $fileExt " == " gif" ]; then
75+ bwDestination=" $bwDestination /animated"
76+ fi
77+
6478 if [[ " ${BASH_REMATCH[3]} " == * b* ]]; then
6579 isBack=" back"
6680 destination=" $destination /back"
@@ -85,13 +99,20 @@ convert(){
8599 if [ $? -ne 0 ]; then
86100 echo " [-] Pkmn $speciesName -$isGmax wasn't found in PokeAPI"
87101 else
88- echo " [+] Copying GMax $smogonName to $destination /$pokemonID .png"
89- cp " $smogonName " " $destination /$pokemonID .png"
90- cp " $smogonName " " $bwDestination /$pokemonID .png"
102+ echo " [+] Copying GMax $smogonName to $bwDestination /$pokemonID .$fileExt "
103+ if [ " $fileExt " == " png" ]; then
104+ mv " $smogonName " " $destination /$pokemonID .$fileExt "
105+ fi
106+ mv " $smogonName " " $bwDestination /$pokemonID .$fileExt "
91107 fi
92108 fi
93109 if [ " $form " ]; then
94- pokemonName=$( echo " $formDS " | jq -r " .[\" ${id} _${form} \" ]" )
110+ # Use animated forms for .gif, regular forms for .png
111+ if [ " $fileExt " == " gif" ]; then
112+ pokemonName=$( echo " $formDSAnimated " | jq -r " .[\" ${id} _${form} \" ]" )
113+ else
114+ pokemonName=$( echo " $formDS " | jq -r " .[\" ${id} _${form} \" ]" )
115+ fi
95116
96117 if [ $? -ne 0 ] || [ " $pokemonName " == ' null' ]; then
97118 echo " [-] Form ${id} _${form} wasn't found in the JSON mapping"
@@ -101,9 +122,11 @@ convert(){
101122 pokemonID=$( echo " $response " | jq -r ' .id' 2> /dev/null)
102123
103124 if [ -n " $pokemonID " ] && [ " $pokemonID " != " null" ]; then
104- echo " [+] Found variety by name: Moving $smogonName to $destination /$pokemonID .png"
105- cp " $smogonName " " $destination /$pokemonID .png"
106- cp " $smogonName " " $bwDestination /$pokemonID .png"
125+ echo " [+] Found variety by name: Moving $smogonName to $bwDestination /$pokemonID .$fileExt "
126+ if [ " $fileExt " == " png" ]; then
127+ mv " $smogonName " " $destination /$pokemonID .$fileExt "
128+ fi
129+ mv " $smogonName " " $bwDestination /$pokemonID .$fileExt "
107130 else
108131 # Search all forms from Pokémon API
109132 echo " [!] Variety '$pokemonName ' not found directly. Searching in Pokémon forms..."
@@ -116,25 +139,29 @@ convert(){
116139 ' .forms[] | select(.name == $name) | .name | sub("^[^#-]+-"; "")' 2> /dev/null)
117140
118141 if [ -n " $formSuffix " ] && [ " $formSuffix " != " null" ] && [ " $formSuffix " != " $pokemonName " ]; then
119- destFile=" ${id} -${formSuffix} .png "
142+ destFile=" ${id} -${formSuffix} .$fileExt "
120143 mkdir -p " $destination "
121144 mkdir -p " $bwDestination "
122145
123- echo " [+] Found in forms: Moving $smogonName to $destination /$destFile "
124- cp " $smogonName " " $destination /$destFile "
125- cp " $smogonName " " $bwDestination /$destFile "
146+ echo " [+] Found in forms: Moving $smogonName to $bwDestination /$destFile "
147+ if [ " $fileExt " == " png" ]; then
148+ mv " $smogonName " " $destination /$destFile "
149+ fi
150+ mv " $smogonName " " $bwDestination /$destFile "
126151 else
127152 echo " [!] No matching form found for $pokemonName ."
128153 fi
129154 fi
130155 fi
131156 fi
132157 if [ ! " $form " ] && [ ! " $isGmax " ]; then
133- echo " [+] Copying Pkmn $smogonName $destination /$id .png "
158+ echo " [+] Copying Pkmn $smogonName to $bwDestination /$id .$fileExt "
134159 mkdir -p " $destination "
135160 mkdir -p " $bwDestination "
136- cp " $smogonName " " $destination /$id .png"
137- cp " $smogonName " " $bwDestination /$id .png"
161+ if [ " $fileExt " == " png" ]; then
162+ mv " $smogonName " " $destination /$id .$fileExt "
163+ fi
164+ mv " $smogonName " " $bwDestination /$id .$fileExt "
138165 fi
139166 fi
140167 done
0 commit comments