You've already forked Gamedata
mirror of
https://github.com/TeamLumi/Gamedata.git
synced 2026-07-09 18:18:37 -07:00
Add a script to consolidate all of the TM learnsets and fix some regex strings
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def consolidate_tmlearnset():
|
||||
"""
|
||||
Consolidates all individual TMLearnset JSON files into a single file.
|
||||
Format: { monsno: { formno_0: data, formno_1: data, ... } }
|
||||
"""
|
||||
# Define paths
|
||||
tmlearnset_folder = os.path.join(os.path.dirname(__file__), '..', 'TMLearnset')
|
||||
output_file = os.path.join(os.path.dirname(__file__), '..', '3.0Input', 'TMLearnset_consolidated.json')
|
||||
|
||||
# Dictionary to store consolidated data
|
||||
consolidated_data = {}
|
||||
|
||||
# Iterate through all JSON files in the TMLearnset folder
|
||||
for filename in sorted(os.listdir(tmlearnset_folder)):
|
||||
if filename.endswith('.json'):
|
||||
# Extract monsno and formno from filename using regex
|
||||
match = re.match(r'monsno_(\d+)_formno_(\d+)\.json', filename)
|
||||
if match:
|
||||
monsno = match.group(1)
|
||||
formno = match.group(2)
|
||||
|
||||
# Read the file
|
||||
file_path = os.path.join(tmlearnset_folder, filename)
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
file_data = json.load(f)
|
||||
|
||||
# Initialize monsno entry if it doesn't exist
|
||||
if monsno not in consolidated_data:
|
||||
consolidated_data[monsno] = {}
|
||||
|
||||
# Add formno data
|
||||
consolidated_data[monsno][f'formno_{formno}'] = file_data
|
||||
|
||||
# Sort the dictionary by monsno (as integers)
|
||||
sorted_consolidated_data = {}
|
||||
for monsno in sorted(consolidated_data.keys(), key=int):
|
||||
sorted_consolidated_data[monsno] = consolidated_data[monsno]
|
||||
|
||||
# Write to output file
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(sorted_consolidated_data, f, indent=2)
|
||||
|
||||
print(f"Successfully consolidated {len(consolidated_data)} Pokémon entries into {output_file}")
|
||||
print(f"Total files processed: {sum(len(forms) for forms in consolidated_data.values())}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
consolidate_tmlearnset()
|
||||
@@ -273,7 +273,7 @@ KG_TO_LBS_CONSTANT = 0.453592
|
||||
FT_TO_CM_CONSTANT = 30.48
|
||||
IN_TO_CM_CONSTANT = 2.54
|
||||
|
||||
TEAM_REGEX = "Team \d+"
|
||||
TEAM_REGEX = r"Team \d+"
|
||||
LDVAL_PATTERN = r"_LDVAL\(@(.*),\s?([1-9][0-9]*)\)"
|
||||
TRAINER_PATTERN = r"_TRAINER_BTL_SET\s*\(\s*('?[^']+'?|@\w+|\d+)\s*,\s*('?[^']+'?|@\w+|\d+)\s*\)"
|
||||
MULTI_TRAINER_PATTERN = r"_TRAINER_MULTI_BTL_SET\s*\(\s*((?:'[^']*'|@\w+|\d+)\s*(?:,\s*(?:'[^']*'|@\w+|\d+)\s*)*)\)"
|
||||
|
||||
@@ -15,6 +15,7 @@ from pokemonUtils import (get_diff_form_dictionary,
|
||||
get_pokemon_from_trainer_info,
|
||||
get_pokemon_id_from_name, get_pokemon_name,
|
||||
isSpecialPokemon, get_form_pokemon_personal_id)
|
||||
from consolidate_tmlearnset import consolidate_tmlearnset
|
||||
|
||||
# Get the repo file path for cleaner path generating
|
||||
repo_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
@@ -758,6 +759,9 @@ if __name__ == "__main__":
|
||||
diff_forms, NAME_MAP = get_diff_form_dictionary()
|
||||
getPokedexInfo()
|
||||
|
||||
if constants.GAME_MODE == constants.GAME_MODE_3:
|
||||
consolidate_tmlearnset()
|
||||
|
||||
mid_time = time.time()
|
||||
print("Middle Execution time:", mid_time - start_time, "seconds")
|
||||
getEncounterData("mons_no")
|
||||
|
||||
@@ -269,9 +269,9 @@ def slugify(value, pokeapi=False):
|
||||
"""
|
||||
initial_value = value
|
||||
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
|
||||
value = re.sub('[^\w\s-]', '', value).strip().lower()
|
||||
value = re.sub(r"[^\w\s-]", '', value).strip().lower()
|
||||
if pokeapi == False:
|
||||
return re.sub('[-\s]+', '-', value)
|
||||
return re.sub(r'[-\s]+', '-', value)
|
||||
|
||||
if ' ' in value or "-" in value:
|
||||
# Split the string at the last space
|
||||
@@ -289,7 +289,7 @@ def slugify(value, pokeapi=False):
|
||||
value = '-'.join([parts[1], parts[0]])
|
||||
return value
|
||||
|
||||
return re.sub('[-\s]+', '-', value)
|
||||
return re.sub(r'[-\s]+', '-', value)
|
||||
|
||||
def isSpecialPokemon(current_pokemon_name):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user