From 8c4ed28fce43ecb964a154a72cb62822cb672d8c Mon Sep 17 00:00:00 2001 From: Amatsune Date: Fri, 28 Jun 2024 13:45:07 +0200 Subject: [PATCH] Removed console log entries, moved script to tools --- src/data/pokemon-species.ts | 13 -- .../{ => tools}/fusion-affixes-generator.py | 135 +++++++++++------- 2 files changed, 87 insertions(+), 61 deletions(-) rename src/locales/{ => tools}/fusion-affixes-generator.py (56%) diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index a0ffd285e8a..959e2e248d0 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -54,32 +54,19 @@ export function getFusedSpeciesName(speciesA: PokemonSpecies, speciesB: PokemonS let firstKey = "fusionPrefix"; let secondKey = "fusionSuffix"; - const shouldReverse = i18next.t("fusionAffixes:shouldReverse"); - console.log(`shouldReverse: ${shouldReverse}`); // logs the value of shouldReverse - if (i18next.t("fusionAffixes:shouldReverse") === "true") { - firstKey = "fusionSuffix"; secondKey = "fusionPrefix"; - - console.log(`firstKey: ${firstKey}, secondKey: ${secondKey}`); // logs the values of firstKey and secondKey } - const radKey = i18next.t(`fusionAffixes:${Species[speciesA.speciesId].toLowerCase()}.${firstKey}`); const desKey = i18next.t(`fusionAffixes:${Species[speciesB.speciesId].toLowerCase()}.${secondKey}`); - let prefix = radKey; let suffix = desKey; - if (i18next.t("fusionAffixes:shouldReverse") === "true") { prefix = desKey; suffix = radKey; } - - console.log(`prefix: ${prefix}, suffix: ${suffix}`); // logs the values of prefix and suffix - const fusedName =`${prefix}${suffix}`; - return fusedName; } diff --git a/src/locales/fusion-affixes-generator.py b/src/locales/tools/fusion-affixes-generator.py similarity index 56% rename from src/locales/fusion-affixes-generator.py rename to src/locales/tools/fusion-affixes-generator.py index b145cec1c35..f42babc705f 100644 --- a/src/locales/fusion-affixes-generator.py +++ b/src/locales/tools/fusion-affixes-generator.py @@ -19,63 +19,101 @@ def is_latin(word): return False return True -#Compare Name Prefixes (to first consonant) -def find_prefixes(word_list): +#Compare Name Prefixes (to consonant) -> Try to keep shorter than 6ch long +def find_prefixes(pokemon_name): result = [] - for word in word_list: - prefix = "" - for other_word in word_list: - if word != other_word: - temp_prefix = "" - for w, o in zip(word, other_word): - if w == o: - temp_prefix += w + processed = {} # This dictionary will keep track of the names that have been processed + for word in pokemon_name: + base_word = word # Treat regional variants as separate entries + if base_word not in processed: # Only process the name if it hasn't been processed before + prefix = "" + for other_word in pokemon_name: + other_base_word = other_word + if base_word != other_base_word: + temp_prefix = "" + for w, o in zip(base_word, other_base_word): + if w == o: + temp_prefix += w + else: + break + if len(temp_prefix) > len(prefix): + prefix = temp_prefix + # Check if the longest shared prefix is the entire species name + if len(prefix) == len(base_word): + processed[base_word] = prefix + else: + # Add the next character in the name to the 'root' of the prefix + root = prefix + base_word[len(prefix)] + # If the root of the prefix ends in a consonant, that should be the result + if root[-1].lower() in "bcdfghjklmnpqrstvwxzçßñ": + processed[base_word] = root + elif len(root) >= 6: # Check if the 'root' is 6 characters or longer + processed[base_word] = root + else: # Try to create an extension to the next consonant + extension = "" + for char in base_word[len(root):]: + extension += char + if char.lower() in "bcdfghjklmnpqrstvwxzçßñ": + break + # Check if the root+extension will be longer than 6 characters + if len(root + extension) > 6: + processed[base_word] = root else: - break - if len(temp_prefix) > len(prefix): - prefix = temp_prefix - # Find the first consonant after the prefix - suffix = "" - for i, char in enumerate(word[len(prefix):]): - suffix += char - if char.lower() in "bcdfghjklmnpqrstvwxzçßñ": - # Check if the next character is a hyphen - if i+1 < len(word[len(prefix):]) and word[len(prefix)+i+1] == '-': - suffix += '-' - break - result.append(prefix + suffix) + processed[base_word] = root + extension + result.append(processed[base_word]) return result -#Compare Name Suffixes (to vowel) + +#Compare Name Suffixes (to vowel) -> Try to keep shorter than 6ch long def find_suffixes(pokemon_name): result = [] + processed = {} # This dictionary will keep track of the names that have been processed for word in pokemon_name: - suffix = "" - for other_word in pokemon_name: - if word != other_word: - temp_suffix = "" - for w, o in zip(word[::-1], other_word[::-1]): - if w == o: - temp_suffix = w + temp_suffix + base_word = word # Treat regional variants as separate entries + if base_word not in processed: # Only process the name if it hasn't been processed before + suffix = "" + for other_word in pokemon_name: + other_base_word = other_word + if base_word != other_base_word: + temp_suffix = "" + for w, o in zip(base_word[::-1], other_base_word[::-1]): + if w == o: + temp_suffix = w + temp_suffix + else: + break + if len(temp_suffix) > len(suffix): + suffix = temp_suffix + # Check if the longest shared suffix is the entire species name + if len(suffix) == len(base_word): + processed[base_word] = suffix + else: + # Add the next character in the name to the 'root' of the suffix + root = base_word[len(base_word) - len(suffix) - 1] + suffix + # If the root of the suffix ends in a vowel, that should be the result + if root[0].lower() in "aeiouyáééíóúàèìòùâêîôûäëïöüãẽĩõũæœøýỳÿŷỹ": + processed[base_word] = root + elif len(root) >= 6: # Check if the 'root' is 6 characters or longer + processed[base_word] = root + else: # Try to create an extension to the next vowel + extension = "" + for char in base_word[len(base_word) - len(root) - 1::-1]: + extension = char + extension + if char.lower() in "aeiouyáééíóúàèìòùâêîôûäëïöüãẽĩõũæœøýỳÿŷỹ": + break + # Check if the root+extension will be longer than 6 characters + if len(extension + root) > 6: + processed[base_word] = root else: - break - if len(temp_suffix) > len(suffix): - suffix = temp_suffix - # Find the first vowel before the suffix - prefix = "" - for i, char in enumerate(word[len(word)-len(suffix)-1::-1]): - prefix = char + prefix - if char.lower() in "aeiouyáééíóúàèìòùâêîôûäëïöüãẽĩõũæœøýỳÿŷỹ": - # Check if the next character is a hyphen - if i+1 < len(word) and word[len(word)-len(suffix)-i-2] == '-': - prefix = '-' + prefix - break - # Make sure the first character is lowercase - output = (prefix + suffix) - output = output[0].lower() + output[1:] - result.append(output) + processed[base_word] = extension + root + # Ensure the first character of the suffix is a lowercase letter + processed[base_word] = processed[base_word][0].lower() + processed[base_word][1:] + # Check if the character before the suffix is a hyphen + if len(base_word) > len(processed[base_word]) and base_word[len(base_word) - len(processed[base_word]) - 2] == '-': + processed[base_word] = '-' + processed[base_word] + result.append(processed[base_word]) return result + def generate_pokemon(file_path): with open(file_path, 'r', encoding='utf-8') as file: # Specify the encoding here lines = file.readlines() @@ -101,7 +139,7 @@ def combine_scripts(file_path): output = "import { FusionTranslationEntries } from \"#app/interfaces/locales\";\n\n" output += "export const fusionAffixes: FusionTranslationEntries = {\n" - output += " shouldReverse: \"true\",\n" + output += " shouldReverse: \"false\",\n" for word, prefix, suffix in zip(pokemon_dict.keys(), prefixes, suffixes): output += f" {word}: {{\n" @@ -123,6 +161,7 @@ file_path = r"pokemon.ts" # Call the combined function combine_scripts(file_path) + #universal-fusion-affixes-generator """"import re