Skip to content

Utilities

There are also a few utility functions provided to help the user convert typical string names to the relevant ID for their corresponding Dex Class.

Dex Data Utilities:

Provides tools for cleaning Dex IDs back and forth from strings, as well as other utility functions.

cast2dex(name, dex_class)

Clean and cast name to the corresponding entry in the given dex_class.

EX: Magikarp -> Cleaned to: MAGIKARP -> DexPokemon.POKEMON_MAGIKARP (Which is secretly the int 129000)

EX: Scizor-Mega -> Cleaned to: SCIZORMEGA -> DexPokemon.POKEMON_SCIZORMEGA (Which is secretly the int 208001)

Parameters:

Name Type Description Default
name str

The name of the entry.

required
dex_class AnyDex

Which Dex Enum to use in labeling. Must be a valid Dex{NAME} class.

required

Returns:

Name Type Description
int int

The corresponding value for this cleaned entry.

Source code in poketypes\dex\dexdata.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def cast2dex(name: str, dex_class: AnyDex) -> int:
    """Clean and cast name to the corresponding entry in the given dex_class.

    EX:
    Magikarp -> Cleaned to: MAGIKARP -> DexPokemon.POKEMON_MAGIKARP (Which is secretly the int 129000)

    EX:
    Scizor-Mega -> Cleaned to: SCIZORMEGA -> DexPokemon.POKEMON_SCIZORMEGA (Which is secretly the int 208001)

    Args:
        name (str): The name of the entry.
        dex_class (AnyDex): Which Dex Enum to use in labeling. Must be a valid Dex{NAME} class.

    Returns:
        int: The corresponding value for this cleaned entry.
    """
    clean_id = clean_name(name)

    if clean_id is None:
        return clean_id

    if dex_class == DexAbility:
        return DexAbility.Value(f"ABILITY_{clean_id}")
    elif dex_class == DexCondition:
        return DexCondition.Value(f"CONDITION_{clean_id}")
    elif dex_class == DexGen:
        return DexGen.Value(f"GEN_{clean_id}")
    elif dex_class == DexItem:
        return DexItem.Value(f"ITEM_{clean_id}")
    elif dex_class == DexMove:
        return DexMove.Value(f"MOVE_{clean_id}")
    elif dex_class == DexMoveCategory:
        return DexMoveCategory.Value(f"MOVECATEGORY_{clean_id}")
    elif dex_class == DexMoveTarget:
        return DexMoveTarget.Value(f"MOVETARGET_{clean_id}")
    elif dex_class == DexNature:
        return DexNature.Value(f"NATURE_{clean_id}")
    elif dex_class == DexPokemon:
        return DexPokemon.Value(f"POKEMON_{clean_id}")
    elif dex_class == DexStat:
        return DexStat.Value(f"STAT_{clean_id}")
    elif dex_class == DexStatus:
        return DexStatus.Value(f"STATUS_{clean_id}")
    elif dex_class == DexType:
        return DexType.Value(f"TYPE_{clean_id}")
    elif dex_class == DexWeather:
        return DexWeather.Value(f"WEATHER_{clean_id}")

clean_forme(species)

Transform a pokemon species (DexPokemon) into the string name of it's base forme.

Makes use of the fact that DexPokemon are of the form {dex_number}{3-digit forme number}, and that the base forme is always forme-number 000. If this changes, this function will no longer work.

Parameters:

Name Type Description Default
species ValueType

The input species to clean to base forme.

required

Returns:

Type Description
ValueType

DexPokemon.ValueType: The corresponding ID of the base forme species.

Source code in poketypes\dex\dexdata.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def clean_forme(species: DexPokemon.ValueType) -> DexPokemon.ValueType:
    """Transform a pokemon species (DexPokemon) into the string name of it's base forme.

    Makes use of the fact that DexPokemon are of the form {dex_number}{3-digit forme number},
    and that the base forme is always forme-number `000`.
    If this changes, this function will no longer work.

    Args:
        species (DexPokemon.ValueType): The input species to clean to base forme.

    Returns:
        DexPokemon.ValueType: The corresponding ID of the base forme species.
    """
    clean_species = (species // 1000) * 1000
    return clean_species

clean_name(name)

Format a given uncleaned string name as the format needed for searching the corresponding Enum.

Parameters:

Name Type Description Default
name Optional[str]

An optional name to clean. If None is given, we immediately return None.

required

Returns:

Type Description
Optional[str]

Optional[str]: The clean-form of the input name, if it wasn't None or blank.

Source code in poketypes\dex\dexdata.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def clean_name(name: Optional[str]) -> Optional[str]:
    """Format a given uncleaned string name as the format needed for searching the corresponding Enum.

    Args:
        name (Optional[str]): An optional name to clean. If None is given, we immediately return None.

    Returns:
        Optional[str]: The clean-form of the input name, if it wasn't None or blank.
    """
    if name is None or name == "":
        return None

    clean_id = (
        unicodedata.normalize(
            "NFKD",
            name.upper()
            .replace("-", "")
            .replace("’", "")
            .replace("'", "")
            .replace(" ", "")
            .replace("*", "")
            .replace(":", "")
            .replace("%", "")
            .replace(".", "")
            .replace(")", "")
            .replace("(", ""),
        )
        .encode("ASCII", "ignore")
        .decode("ASCII")
    )
    return clean_id