Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
lhearachel committed Jun 12, 2024
1 parent f5916d4 commit e7d4190
Show file tree
Hide file tree
Showing 25 changed files with 275,678 additions and 3,305 deletions.
30 changes: 19 additions & 11 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ def alias(id: str, name: str, T: str) -> list[str]:
[index.extend(alias(id, item['name'], 'item')) for id, item in items.items()]
[index.extend(alias(id, ability['name'], 'ability')) for id, ability in abilities.items()]

for id, location in encounters.items():
if id == 'rates':
continue
index.extend(alias(id, location['name'], 'location'))

index.sort()

# manually rearrange some entries
Expand Down Expand Up @@ -214,23 +219,25 @@ def offset_map(entry: list):
name = ''
match entry[1]:
case 'pokemon':
name = pokedex[id]['name']
name = pokedex.get(id, {}).get('name', ' ')
case 'move':
name = moves[id]['name']
name = moves.get(id, {}).get('name', ' ')
case 'item':
name = items[id]['name']
name = items.get(id, {}).get('name', ' ')
case 'ability':
name = abilities[id]['name']
name = abilities.get(id, {}).get('name', ' ')
case 'location':
name = encounters[id]['name']
name = encounters.get(id, {}).get('name', ' ')

result = ''
i, j, non_alnum = 0, 0, 0
while i < len(id):
while not name[j].isalnum():
j, non_alnum = 0, 0
for _ in range(len(id)):
while j < len(name) and not name[j].isalnum():
j = j + 1
non_alnum = non_alnum + 1

result = result + str(non_alnum)
j = j + 1

if non_alnum:
return result
Expand All @@ -245,7 +252,8 @@ def offset_map(entry: list):

with open('site/data/search-index.js', 'w', encoding='utf-8') as outf:
print('// DO NOT EDIT - automatically built by porydex', file=outf, end='\n\n')
print(f'exports.BattleSearchIndex = {json.dumps(battle_search_index)}', file=outf, end='\n\n')
print(f'exports.BattleSearchIndexOffset = {json.dumps(battle_offset_index)}', file=outf, end='\n\n')
print(f'exports.BattleSearchCountIndex = {json.dumps(battle_count_index)}', file=outf, end='\n\n')
print(f'exports.BattleSearchIndex = {json.dumps(battle_search_index)};', file=outf, end='\n\n')
print(f'exports.BattleSearchIndexOffset = {json.dumps(battle_offset_index)};', file=outf, end='\n\n')
print(f'exports.BattleSearchCountIndex = {json.dumps(battle_count_index)};', file=outf, end='\n\n')
print( 'exports.BattleArticleTitles = {};', file=outf, end='\n\n')

38 changes: 23 additions & 15 deletions porydex.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ def config_set(args):
def config_clear(_):
porydex.config.clear()

def generate_showdown_files(moves: dict, species: dict, learnsets: dict, encounters: dict):
with open(porydex.config.output / 'moves.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleMovedex = ')
json.dump(moves, outf, indent=4)

with open(porydex.config.output / 'species.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattlePokedex = ')
json.dump(species, outf, indent=4)

with open(porydex.config.output / 'learnsets.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleLearnsets = ')
json.dump(learnsets, outf, indent=4)

with open(porydex.config.output / 'encounters.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleLocationdex = ')
json.dump(encounters, outf, indent=4)

def extract(args):
if args.reload:
for f in PICKLE_PATH.glob('*'):
Expand Down Expand Up @@ -83,6 +100,11 @@ def extract(args):
species_names = [mon['name'] for mon in sorted(species.values(), key=lambda m: m['num'])]
encounters = parse_encounters(expansion_data / 'wild_encounters.h', species_names)

# Re-index num to nationalDex on the species before finishing up
for _, mon in species.items():
mon['num'] = mon['nationalDex']
del mon['nationalDex']

if porydex.config.format == porydex.config.OutputFormat.json:
with open(porydex.config.output / 'moves.json', 'w', encoding='utf-8') as outf:
json.dump(moves, outf, indent=4)
Expand All @@ -96,21 +118,7 @@ def extract(args):
with open(porydex.config.output / 'encounters.json', 'w', encoding='utf-8') as outf:
json.dump(encounters, outf, indent=4)
else: # showdown
with open(porydex.config.output / 'moves.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleMovedex = ')
json.dump(moves, outf, indent=4)

with open(porydex.config.output / 'species.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattlePokedex = ')
json.dump(species, outf, indent=4)

with open(porydex.config.output / 'learnsets.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleLearnsets = ')
json.dump(learnsets, outf, indent=4)

with open(porydex.config.output / 'encounters.js', 'w+', encoding='utf-8') as outf:
outf.write('exports.BattleLocationdex = ')
json.dump(encounters, outf, indent=4)
generate_showdown_files(moves, species, learnsets, encounters)

def main():
argp = argparse.ArgumentParser(prog='porydex',
Expand Down
2 changes: 1 addition & 1 deletion porydex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def argparse(s):
compiler: pathlib.Path = pathlib.Path('gcc')
expansion: pathlib.Path = pathlib.Path('../pokeemerald-expansion').resolve()
output: pathlib.Path = pathlib.Path('./site/data').resolve()
format: OutputFormat = OutputFormat.jsobj
format: OutputFormat = OutputFormat.showdown

_CONFIG_FILE: pathlib.Path = pathlib.Path('porydex.ini')

Expand Down
22 changes: 11 additions & 11 deletions porydex/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ class EvoMethod():
EvoMethod('trade', ''),
EvoMethod('tradeItem', 'while holding'),
EvoMethod('useItem', ''),
EvoMethod('level', 'with attack > defense'),
EvoMethod('level', 'with attack = defense'),
EvoMethod('level', 'with attack < defense'),
EvoMethod('level', 'with more Attack than Defense'),
EvoMethod('level', 'with equal Attack and Defense'),
EvoMethod('level', 'with more Defense than Attack'),
EvoMethod('level', 'based on personality'), # Silcoon
EvoMethod('level', 'based on personality'), # Cascoon
EvoMethod('level', ''), # Ninjask
EvoMethod('level', 'with empty party slot + extra Poke Ball'),
EvoMethod('level', 'with maximum Beauty'),
EvoMethod('level', 'with empty party slot and an extra Poké Ball'),
EvoMethod('levelExtra', 'with maximum Beauty'),
EvoMethod('level', 'if Female gender'),
EvoMethod('level', 'if Male gender'),
EvoMethod('level', 'at night'),
Expand All @@ -153,19 +153,19 @@ class EvoMethod():
EvoMethod('levelHold', 'during the day'),
EvoMethod('levelHold', 'at night'),
EvoMethod('levelMove', ''),
EvoMethod('levelMove', 'and two levels of Affection'), # Sylveon (param is "a Fairy-type move")
EvoMethod('levelMap', 'in'), # Magnezone, etc. (param is the name of the zone)
EvoMethod('levelMove', 'and with high Friendship'), # Sylveon (param is "a Fairy-type move")
EvoMethod('levelMap', ''), # Magnezone, etc. (param is the name of the zone)
EvoMethod('useItem', 'if Male gender'),
EvoMethod('useItem', 'if Female gender'),
EvoMethod('level', 'in rainy weather'),
EvoMethod('levelMove', 'in the party'), # Mantine (param is Remoraid)
EvoMethod('levelMove', 'in the party'), # Pangoro (param is "a Dark-type mon")
EvoMethod('levelParty', ''), # Mantine (param is Remoraid)
EvoMethod('level', 'while a Dark-type Pokémon is in the party'), # Pangoro (param is "a Dark-type mon")
EvoMethod('tradeSpecies', 'with a'), # Accelgor, Escavalier (param is Karrablast, Shelmet, respectively)
EvoMethod('level', 'in'), # special one used for Leafeon and Glaceon, for some reason
EvoMethod('level', 'if Amped Nature'),
EvoMethod('level', 'if Low-Key Nature'),
EvoMethod('other', 'land 3 critical hits in 1 battle'),
EvoMethod('other', 'have 49+ HP lost and walk under stone sculpture in Dusty Bowl'), # Runerigus-G
EvoMethod('other', 'take 49 or more damage and walk under stone sculpture in Dusty Bowl'), # Runerigus-G
EvoMethod('other', 'interact with the Scroll of Darkness'),
EvoMethod('other', 'interact with the Scroll of Waters'),
EvoMethod('useItem', 'at night'),
Expand All @@ -179,6 +179,6 @@ class EvoMethod():
EvoMethod('useMove', '20 times'), # Wyrdeer, Annihilape
EvoMethod('other', 'receive 294+ recoil damage without fainting'), # Basculegion-M
EvoMethod('other', 'receive 294+ recoil damage without fainting'), # Basculegion-F
EvoMethod('level', 'with 999 coins in the bag'), # Gholdengo
EvoMethod('levelExtra', 'with 999 coins in the bag'), # Gholdengo
]

6 changes: 3 additions & 3 deletions porydex/parse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ def extract_compound_str(expr) -> str:

# arm-none-eabi-gcc expands the macro to Cast(FuncCall(ExprList([Constant])))
if isinstance(expr, Cast):
return expr.expr.args.exprs[0].value.replace('\\n', ' ')[1:-1]
return expr.expr.args.exprs[-1].value.replace('\\n', ' ')[1:-1]

# clang expands the macro to CompoundLiteral(InitList([Constant]))
if isinstance(expr, CompoundLiteral):
return expr.init.exprs[0].value.replace('\\n', ' ')[1:-1]
return expr.init.exprs[-1].value.replace('\\n', ' ')[1:-1]

if isinstance(expr.exprs[0], FuncCall):
if isinstance(expr.exprs[-1], FuncCall):
return extract_compound_str(expr.exprs[0].args)
return expr.exprs[-1].value.replace('\\n', ' ')[1:-1]

Expand Down
8 changes: 4 additions & 4 deletions porydex/parse/encounters.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse_encounter_header(header: InitList,

def parse_encounter_def(entry: InitList, species_names: list[str]) -> Encounter:
return Encounter(
species=species_names[extract_int(entry.exprs[2])],
species=name_key(species_names[extract_int(entry.exprs[2])]),
min_lvl=extract_int(entry.exprs[0]),
max_lvl=extract_int(entry.exprs[1]),
)
Expand Down Expand Up @@ -170,11 +170,11 @@ def parse_encounters_data(exts, jd: dict, species_names: list[str]) -> dict[str,
all_encounters['rates']['rock'] = field['encounter_rates']
case 'fishing_mons':
rates = field['encounter_rates']
for slot in field['groups']['old_rod']:
for slot in field['groups'].get('old_rod', []):
all_encounters['rates']['fish']['old'].append(rates[slot])
for slot in field['groups']['good_rod']:
for slot in field['groups'].get('good_rod', []):
all_encounters['rates']['fish']['good'].append(rates[slot])
for slot in field['groups']['super_rod']:
for slot in field['groups'].get('super_rod', []):
all_encounters['rates']['fish']['super'].append(rates[slot])

for header in headers:
Expand Down
4 changes: 3 additions & 1 deletion porydex/parse/form_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def parse_table_decl(minimal: Decl, full: Decl) -> tuple[str, dict[int, str]]:
.replace('Galarian', 'Galar') \
.replace('Hisuian', 'Hisui') \
.replace('Paldean', 'Paldea') \
.replace('Gigantamax', 'Gmax')
.replace('Gigantamax', 'Gmax') \
.replace('-Cloak', '') \
.replace('-Family-Of', '')

return name, result

Expand Down
19 changes: 8 additions & 11 deletions porydex/parse/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse_mon(struct_init: NamedInitializer,
form_tables: dict[str, dict[int, str]],
level_up_learnsets: dict[str, dict[str, list[int]]],
teachable_learnsets: dict[str, dict[str, list[str]]],
national_dex: dict[str, int]) -> tuple[dict, list, dict, list]:
national_dex: dict[str, int]) -> tuple[dict, list, dict, dict]:
init_list = struct_init.expr.exprs
mon = {}
mon['num'] = extract_int(struct_init.name[0])
Expand All @@ -30,7 +30,7 @@ def parse_mon(struct_init: NamedInitializer,

evos = []
lvlup_learnset = {}
teach_learnset = []
teach_learnset = {}

for field_init in init_list:
field_name = field_init.name[0].name
Expand Down Expand Up @@ -191,7 +191,7 @@ def parse_mon(struct_init: NamedInitializer,
case 'levelUpLearnset':
lvlup_learnset = level_up_learnsets.get(extract_id(field_expr), {})
case 'teachableLearnset':
teach_learnset = teachable_learnsets.get(extract_id(field_expr), [])
teach_learnset = teachable_learnsets.get(extract_id(field_expr), {})

return mon, evos, lvlup_learnset, teach_learnset

Expand Down Expand Up @@ -271,14 +271,14 @@ def zip_evos(all_data: dict,
# These evo methods interpret the parameter as a specific move
case ExpansionEvoMethod.MOVE \
| ExpansionEvoMethod.MOVE_TWO_SEGMENT \
| ExpansionEvoMethod.MOVE_THREE_SEGMENT:
| ExpansionEvoMethod.MOVE_THREE_SEGMENT \
| ExpansionEvoMethod.USE_MOVE_TWENTY_TIMES:
parent_mon['evoMove'] = moves[param]
pass

# These evo methods interpret the parameter as another species
case ExpansionEvoMethod.SPECIFIC_MON_IN_PARTY \
| ExpansionEvoMethod.TRADE_SPECIFIC_MON \
| ExpansionEvoMethod.USE_MOVE_TWENTY_TIMES:
| ExpansionEvoMethod.TRADE_SPECIFIC_MON:
parent_mon['evoSpecies'] = all_data[param][0]['name']

# This evo method interprets the parameter as a damage type
Expand All @@ -293,9 +293,8 @@ def zip_evos(all_data: dict,
raise ValueError('Unimplemented evo method: ', evo[0])

descriptor = EVO_METHOD[method.value]
if descriptor.condition:
parent_mon['evoType'] = descriptor.type
parent_mon['evoCondition'] = descriptor.condition
parent_mon['evoType'] = descriptor.type
parent_mon['evoCondition'] = descriptor.condition

def zip_learnsets(lvlup_learnset: dict[str, list[int]],
teach_learnset: list[str]) -> dict:
Expand Down Expand Up @@ -346,8 +345,6 @@ def parse_species_data(species_data: ExprList,
for mon, _ in all_species_data.values():
if 'name' not in mon or not mon['name']: # egg has no name; don't try
continue
mon['num'] = mon['nationalDex']
del mon['nationalDex']
final_species[name_key(mon['name'])] = mon

return final_species, all_learnsets
Expand Down
File renamed without changes.
Loading

0 comments on commit e7d4190

Please sign in to comment.