Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions scripts/forms-animated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"19": "raticate-alola",
"20_1": "raticate-alola",
"26_1": "raichu-alola",
"27_1": "sandshrew-alola",
"28_1": "sandslash-alola",
"37_1": "vulpix-alola",
"50_1": "dugtrio-alola",
"51_1": "dugtrio-alola",
"52_1": "meowth-alola",
"53_1": "persian-alola",
"74_1": "geodude-alola",
"75_1": "graveler-alola",
"76_1": "golem-alola",
"88_1": "grimer-alola",
"89_1": "muk-alola",
"105_1": "marowak-alola"
}
59 changes: 43 additions & 16 deletions scripts/renameSmogon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Usage: $0 <generationID>
# If not submitted, generationID will be 6

regex="^([0-9]+)_?([0-9]+)?([sbfg]+)?.png$"
regex="^([0-9]+)_?([0-9]+)?([sbfg]+)?\.(png|gif)$"

ensureCommands(){
local commands="jq"
Expand Down Expand Up @@ -36,15 +36,21 @@ convert(){
# Folder where images downloaded from the Smogon spreadsheet are stored.
local files="downloads/"
local formDS
local formDSAnimated
formDS=$(jq . forms.json)
formDSAnimated="$formDS" # default to same as formDS
if [ -f forms-animated.json ]; then
# Merge forms-animated.json into forms.json (animated overrides original)
formDSAnimated=$(jq -n --argjson base "$formDS" --argjson animated "$(jq . forms-animated.json)" '$base * $animated')
fi
# echo "$formDS" | jq -r '.["885"]'

cd "$files" || exit

local destinationRoot='../../sprites/pokemon'
local bwDestinationRoot="$destinationRoot/versions/generation-v/black-white"

for smogonName in *.png; do
for smogonName in *.png *.gif; do
id=""
form=""
isFemale=""
Expand All @@ -54,13 +60,21 @@ convert(){
speciesName=""
pokemonID=""
pokemonName=""
fileExt=""
destination="$destinationRoot"
bwDestination="$bwDestinationRoot"

if [[ $smogonName =~ $regex ]]; then
#id=$(echo "${BASH_REMATCH[1]}" | sed 's/^0*//') # Extremely slow
id=$(removeLeadingZero "${BASH_REMATCH[1]}") # Slow if function
form="${BASH_REMATCH[2]}"
fileExt="${BASH_REMATCH[4]}"

# For .gif files, use animated directory
if [ "$fileExt" == "gif" ]; then
bwDestination="$bwDestination/animated"
fi

if [[ "${BASH_REMATCH[3]}" == *b* ]]; then
isBack="back"
destination="$destination/back"
Expand All @@ -85,13 +99,20 @@ convert(){
if [ $? -ne 0 ]; then
echo "[-] Pkmn $speciesName-$isGmax wasn't found in PokeAPI"
else
echo "[+] Copying GMax $smogonName to $destination/$pokemonID.png"
cp "$smogonName" "$destination/$pokemonID.png"
cp "$smogonName" "$bwDestination/$pokemonID.png"
echo "[+] Copying GMax $smogonName to $bwDestination/$pokemonID.$fileExt"
if [ "$fileExt" == "png" ]; then
mv "$smogonName" "$destination/$pokemonID.$fileExt"
fi
mv "$smogonName" "$bwDestination/$pokemonID.$fileExt"
fi
fi
if [ "$form" ]; then
pokemonName=$(echo "$formDS" | jq -r ".[\"${id}_${form}\"]")
# Use animated forms for .gif, regular forms for .png
if [ "$fileExt" == "gif" ]; then
pokemonName=$(echo "$formDSAnimated" | jq -r ".[\"${id}_${form}\"]")
else
pokemonName=$(echo "$formDS" | jq -r ".[\"${id}_${form}\"]")
fi

if [ $? -ne 0 ] || [ "$pokemonName" == 'null' ]; then
echo "[-] Form ${id}_${form} wasn't found in the JSON mapping"
Expand All @@ -101,9 +122,11 @@ convert(){
pokemonID=$(echo "$response" | jq -r '.id' 2>/dev/null)

if [ -n "$pokemonID" ] && [ "$pokemonID" != "null" ]; then
echo "[+] Found variety by name: Moving $smogonName to $destination/$pokemonID.png"
cp "$smogonName" "$destination/$pokemonID.png"
cp "$smogonName" "$bwDestination/$pokemonID.png"
echo "[+] Found variety by name: Moving $smogonName to $bwDestination/$pokemonID.$fileExt"
if [ "$fileExt" == "png" ]; then
mv "$smogonName" "$destination/$pokemonID.$fileExt"
fi
mv "$smogonName" "$bwDestination/$pokemonID.$fileExt"
else
# Search all forms from Pokémon API
echo "[!] Variety '$pokemonName' not found directly. Searching in Pokémon forms..."
Expand All @@ -116,25 +139,29 @@ convert(){
'.forms[] | select(.name == $name) | .name | sub("^[^#-]+-"; "")' 2>/dev/null)

if [ -n "$formSuffix" ] && [ "$formSuffix" != "null" ] && [ "$formSuffix" != "$pokemonName" ]; then
destFile="${id}-${formSuffix}.png"
destFile="${id}-${formSuffix}.$fileExt"
mkdir -p "$destination"
mkdir -p "$bwDestination"

echo "[+] Found in forms: Moving $smogonName to $destination/$destFile"
cp "$smogonName" "$destination/$destFile"
cp "$smogonName" "$bwDestination/$destFile"
echo "[+] Found in forms: Moving $smogonName to $bwDestination/$destFile"
if [ "$fileExt" == "png" ]; then
mv "$smogonName" "$destination/$destFile"
fi
mv "$smogonName" "$bwDestination/$destFile"
else
echo "[!] No matching form found for $pokemonName."
fi
fi
fi
fi
if [ ! "$form" ] && [ ! "$isGmax" ]; then
echo "[+] Copying Pkmn $smogonName $destination/$id.png"
echo "[+] Copying Pkmn $smogonName to $bwDestination/$id.$fileExt"
mkdir -p "$destination"
mkdir -p "$bwDestination"
cp "$smogonName" "$destination/$id.png"
cp "$smogonName" "$bwDestination/$id.png"
if [ "$fileExt" == "png" ]; then
mv "$smogonName" "$destination/$id.$fileExt"
fi
mv "$smogonName" "$bwDestination/$id.$fileExt"
fi
fi
done
Expand Down
75 changes: 65 additions & 10 deletions scripts/smogon_download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import re
import json
from pathlib import Path

# Image URLs collected from the Smogon Sprite Project spreadsheet
Expand All @@ -8,36 +9,90 @@
# Smogon thread:
# https://www.smogon.com/forums/threads/smogon-sprite-project.3647722/
urls = [
"https://www.smogon.com/forums/attachments/964-png.603593/",
"https://www.smogon.com/forums/attachments/964s-png.603594/",
# "https://www.smogon.com/forums/attachments/964-png.536964/",
# "https://www.smogon.com/forums/attachments/964s-png.536965/",
"https://www.smogon.com/forums/attachments/019-gif.171350/",
"https://www.smogon.com/forums/attachments/19b-gif.177101/",
"https://www.smogon.com/forums/attachments/019s-gif.173309/",
"https://www.smogon.com/forums/attachments/19sb-gif.177103/",
]

# Set a User-Agent to prevent Smogon from blocking the request
HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.31"
}

# Mapping Showdown directories to filename suffixes
SHOWDOWN_SUFFIX_MAP = {
"gen5ani": "",
"gen5ani-back": "b",
"gen5ani-shiny": "s",
"gen5ani-back-shiny": "sb",
}


def load_forms_map(script_dir):
"""Loads forms.json and inverts it to {name: id} for easy lookup."""
forms_path = script_dir / "forms.json"
if not forms_path.exists():
print("⚠️ Warning: forms.json not found. Showdown downloads may fail.")
return {}

with open(forms_path, "r") as f:
data = json.load(f)
# Invert {"764": "comfey"} -> {"comfey": "764"}
return {v.lower(): k for k, v in data.items()}


def download_sprites():
script_dir = Path(__file__).resolve().parent
download_dir = script_dir / "downloads"
download_dir.mkdir(exist_ok=True)

name_to_id = load_forms_map(script_dir)

print(f"📁 Directory ready: {download_dir.absolute()}")
print(f"🚀 Starting download of {len(urls)} files...")

for url in urls:
try:
filename = None

# 1. Extract filename from URL
# Example: 652sb-png.492504/ -> 652sb.png
match = re.search(r"attachments/([\w-]+)-png\.\d+/?", url)
if match:
filename = f"{match.group(1)}.png"
# --- Pokemon Showdown ---
if "play.pokemonshowdown.com" in url:
# Extract the directory and the name (e.g., gen5ani-back and comfey)
# URL pattern: .../sprites/{directory}/{name}.gif
parts = url.rstrip("/").split("/")
directory = parts[-2]
name_with_ext = parts[-1]
name = name_with_ext.split(".")[0].lower()
extension = name_with_ext.split(".")[-1]

pokemon_id = name_to_id.get(name)
suffix = SHOWDOWN_SUFFIX_MAP.get(directory)

if pokemon_id is not None and suffix is not None:
filename = f"{pokemon_id}{suffix}.{extension}"
else:
print(f"⚠️ Could not map Showdown URL: {url}")
continue

# --- Smogon Forums ---
else:
# Fallback if regex fails
filename = f"{Path(url).parts[-1].split('-')[0]}.png"
# Capture the name and the extension type (e.g., 762-gif.369401 -> 762 and gif)
match = re.search(r"attachments/([\w-]+)-(png|gif)\.\d+/?", url)
if match:
base_name = match.group(1)
extension = match.group(2)
filename = f"{base_name}.{extension}"
else:
# Handles cases where the regex might miss a specific format
raw_part = Path(url).parts[-1].split(".")[0] # e.g., "762-gif"
if "-" in raw_part:
name, ext = raw_part.rsplit("-", 1)
filename = f"{name}.{ext}"
else:
print(f"⚠️ Could not parse Smogon URL: {url}")
continue

save_path = download_dir / filename

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading