diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..de4d1f0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/devWrapper.ts b/devWrapper.ts index da04111..8ef3784 100644 --- a/devWrapper.ts +++ b/devWrapper.ts @@ -9,22 +9,51 @@ const main = async () => { const data = await generate({ raw: process.argv.includes('--raw'), test: process.argv.includes('--test'), - pokeApi: process.argv.includes('--pokeapi') || { baseStats, tempEvos, types }, + pokeApi: process.argv.includes('--pokeapi') || { + baseStats, + tempEvos, + types, + }, }) if (process.argv.includes('--test')) { if (process.argv.includes('--invasions')) { - fs.writeFile('./invasions.json', JSON.stringify(await invasions(), null, 2), 'utf8', () => {}) + fs.writeFile( + './invasions.json', + JSON.stringify(await invasions(), null, 2), + 'utf8', + () => {}, + ) } if (data?.AllPokeApi) { const { baseStats, tempEvos, types } = data.AllPokeApi - fs.writeFile('./static/baseStats.json', JSON.stringify(baseStats, null, 2), 'utf8', () => {}) - fs.writeFile('./static/tempEvos.json', JSON.stringify(tempEvos, null, 2), 'utf8', () => {}) - fs.writeFile('./static/types.json', JSON.stringify(types, null, 2), 'utf8', () => {}) + fs.writeFile( + './static/baseStats.json', + JSON.stringify(baseStats, null, 2), + 'utf8', + () => {}, + ) + fs.writeFile( + './static/tempEvos.json', + JSON.stringify(tempEvos, null, 2), + 'utf8', + () => {}, + ) + fs.writeFile( + './static/types.json', + JSON.stringify(types, null, 2), + 'utf8', + () => {}, + ) delete data.AllPokeApi } if (data) { - fs.writeFile('./masterfile.json', JSON.stringify(data, null, 2), 'utf8', () => {}) + fs.writeFile( + './masterfile.json', + JSON.stringify(data, null, 2), + 'utf8', + () => {}, + ) } } console.timeEnd('Generated in') diff --git a/package.json b/package.json index 14e7bae..edb976a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "invasions": "ts-node devWrapper.ts --test --invasions", "test": "tsc && ./node_modules/.bin/jest", "format": "prettier --config .prettierrc 'src/**/*.ts' --write", - "publishBuild": "rm -r dist && tsc" + "publishBuild": "rm -r dist && tsc", + "prettier": "prettier --write \"**/*.ts\"" }, "repository": { "type": "git", diff --git a/src/base.ts b/src/base.ts index 25a3d30..973cdec 100644 --- a/src/base.ts +++ b/src/base.ts @@ -328,7 +328,16 @@ const baseTemplate: FullTemplate = { prefix: '{{', suffix: '}}', }, - questTitleTermsToSkip: ['gofest', 'gotour', 'dialog', 'title', 'summer_return', '_complete_', 'location', 'vote'], + questTitleTermsToSkip: [ + 'gofest', + 'gotour', + 'dialog', + 'title', + 'summer_return', + '_complete_', + 'location', + 'vote', + ], masterfileLocale: false, manualTranslations: true, mergeCategories: true, diff --git a/src/classes/Invasion.ts b/src/classes/Invasion.ts index 125a755..5dcd968 100644 --- a/src/classes/Invasion.ts +++ b/src/classes/Invasion.ts @@ -17,7 +17,10 @@ export default class Invasion extends Masterfile { async customInvasions(override: boolean = false): Promise { try { - if (this.options.customInvasions === true || (this.options.customInvasions === undefined && override)) { + if ( + this.options.customInvasions === true || + (this.options.customInvasions === undefined && override) + ) { return this.fetch( 'https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/custom-invasions.json', ) @@ -47,10 +50,20 @@ export default class Invasion extends Masterfile { } formatGrunts(character: string) { - const base = character.replace('CHARACTER_', '').replace('_MALE', '').replace('_FEMALE', '') - const type = base.replace('EXECUTIVE_', '').replace('_GRUNT', '').replace('EVENT_', '') - const grunt = base.split('_').length > 1 ? base.replace(`${type}`, '').replace('_', '') : base - let gender = character.includes('MALE') || character.includes('FEMALE') ? 1 : 0 + const base = character + .replace('CHARACTER_', '') + .replace('_MALE', '') + .replace('_FEMALE', '') + const type = base + .replace('EXECUTIVE_', '') + .replace('_GRUNT', '') + .replace('EVENT_', '') + const grunt = + base.split('_').length > 1 + ? base.replace(`${type}`, '').replace('_', '') + : base + let gender = + character.includes('MALE') || character.includes('FEMALE') ? 1 : 0 if (character.includes('FEMALE')) { gender = 2 } @@ -70,7 +83,10 @@ export default class Invasion extends Masterfile { Object.entries(Rpc.EnumWrapper.InvasionCharacter).forEach((proto) => { try { const [name, id] = proto - if ((this.options.includeBalloons && name.includes('BALLOON')) || !name.includes('BALLOON_')) { + if ( + (this.options.includeBalloons && name.includes('BALLOON')) || + !name.includes('BALLOON_') + ) { const pogoInfo = invasionData[id] this.parsedInvasions[id] = { id: +id, @@ -82,20 +98,31 @@ export default class Invasion extends Masterfile { thirdReward: false, } if (pogoInfo && pogoInfo.active) { - this.parsedInvasions[id].firstReward = pogoInfo.lineup.rewards.includes(0) - this.parsedInvasions[id].secondReward = pogoInfo.lineup.rewards.includes(1) - this.parsedInvasions[id].thirdReward = pogoInfo.lineup.rewards.includes(2) + this.parsedInvasions[id].firstReward = + pogoInfo.lineup.rewards.includes(0) + this.parsedInvasions[id].secondReward = + pogoInfo.lineup.rewards.includes(1) + this.parsedInvasions[id].thirdReward = + pogoInfo.lineup.rewards.includes(2) this.parsedInvasions[id].encounters = [] positions.forEach((position, i) => { pogoInfo.lineup.team[i].forEach((pkmn) => { - this.parsedInvasions[id].encounters.push({ id: pkmn.id, formId: pkmn.form, position }) + this.parsedInvasions[id].encounters.push({ + id: pkmn.id, + formId: pkmn.form, + position, + }) }) this.parsedInvasions[id].encounters.sort((a, b) => a.id - b.id) - this.parsedInvasions[id].encounters.sort((a, b) => a.position.localeCompare(b.position)) + this.parsedInvasions[id].encounters.sort((a, b) => + a.position.localeCompare(b.position), + ) }) } else if (this.options.placeholderData) { - this.parsedInvasions[id].encounters = positions.map((position) => ({ position })) + this.parsedInvasions[id].encounters = positions.map((position) => ({ + position, + })) } } } catch (e) { diff --git a/src/classes/Item.ts b/src/classes/Item.ts index df82b34..1dab183 100644 --- a/src/classes/Item.ts +++ b/src/classes/Item.ts @@ -24,8 +24,13 @@ export default class Item extends Masterfile { }, templateId, } = object - if (!this.options.minTrainerLevel || !dropTrainerLevel || dropTrainerLevel <= this.options.minTrainerLevel) { - const id = typeof itemId === 'string' ? Rpc.Item[itemId as ItemProto] : itemId + if ( + !this.options.minTrainerLevel || + !dropTrainerLevel || + dropTrainerLevel <= this.options.minTrainerLevel + ) { + const id = + typeof itemId === 'string' ? Rpc.Item[itemId as ItemProto] : itemId this.parsedItems[id] = { itemId: id, itemName: this.capitalize(templateId.replace('ITEM_', '')), diff --git a/src/classes/Masterfile.ts b/src/classes/Masterfile.ts index f94df5d..bd44105 100644 --- a/src/classes/Masterfile.ts +++ b/src/classes/Masterfile.ts @@ -8,8 +8,7 @@ if (typeof fetch === 'undefined') { export default class Masterfile { customFieldNames: { [id: string]: string } genders: { [id: string]: string } - protos: any - + constructor() { this.customFieldNames = {} this.genders = { @@ -20,7 +19,7 @@ export default class Masterfile { static templateMerger( template: { [key: string]: any }, - base: FullTemplate + base: FullTemplate, ): FullTemplate { const baseline: { [key: string]: any } = base const merged: { [key: string]: any } = {} @@ -126,7 +125,7 @@ export default class Masterfile { templater( data: any, settings: { template: any; options: Options }, - reference: FinalResult = {} + reference: FinalResult = {}, ) { // loops through the raw data and outputs the desired template const { template, options } = settings @@ -145,7 +144,7 @@ export default class Masterfile { fieldKey: string, fieldValue: any, templateChild: any, - data: any + data: any, ) => { // turns integer references into values const isObj = options.keys[fieldKey] @@ -192,7 +191,7 @@ export default class Masterfile { fieldKey: string, x: number, templateChild: any, - data: any + data: any, ) => { // checks which fields are in the template and if the data is an object, loops through again let returnedObj: any = {} @@ -224,7 +223,7 @@ export default class Masterfile { subFieldKey, subFieldValue, templateChild[fieldKey], - data + data, ) } else { if (options.customChildObj[subFieldKey]) { @@ -232,7 +231,7 @@ export default class Masterfile { returnedObj, subFieldKey, customKey, - subFieldValue + subFieldValue, ) } else if (subFieldValue !== undefined) { returnedObj[customKey] = subFieldValue @@ -242,7 +241,7 @@ export default class Masterfile { }) } catch (e) { console.warn( - `Ref or X is undefined and it probably shouldn't be for ${reference}[${fieldKey}][${x}]` + `Ref or X is undefined and it probably shouldn't be for ${reference}[${fieldKey}][${x}]`, ) } return returnedObj @@ -252,7 +251,7 @@ export default class Masterfile { target: any, key: string, customKey: string, - field: any + field: any, ) => { const customObj = options.customChildObj[key] if (!target[customObj]) { @@ -280,7 +279,7 @@ export default class Masterfile { fieldKey, fieldValue, template, - data[id] + data[id], ) } else { if (options.customChildObj[fieldKey]) { diff --git a/src/classes/Move.ts b/src/classes/Move.ts index 47d0793..00536e2 100644 --- a/src/classes/Move.ts +++ b/src/classes/Move.ts @@ -32,7 +32,8 @@ export default class Moves extends Masterfile { data: { combatMove }, } = object try { - const id: number = Rpc.HoloPokemonMove[templateId.substring(18) as MoveProto] + const id: number = + Rpc.HoloPokemonMove[templateId.substring(18) as MoveProto] this.parsedMoves[id] = { moveId: id, moveName: this.capitalize(combatMove.uniqueId.replace('_FAST', '')), diff --git a/src/classes/PokeApi.ts b/src/classes/PokeApi.ts index 3e24fe7..5fa20e9 100644 --- a/src/classes/PokeApi.ts +++ b/src/classes/PokeApi.ts @@ -17,28 +17,50 @@ export default class PokeApi extends Masterfile { this.types = {} } - attack(normal: number, special: number, speed: number, nerf: boolean = false): number { + attack( + normal: number, + special: number, + speed: number, + nerf: boolean = false, + ): number { return Math.round( - Math.round(2 * (0.875 * Math.max(normal, special) + 0.125 * Math.min(normal, special))) * + Math.round( + 2 * + (0.875 * Math.max(normal, special) + + 0.125 * Math.min(normal, special)), + ) * (1 + (speed - 75) / 500) * (nerf ? 0.91 : 1), ) } - defense(normal: number, special: number, speed: number, nerf: boolean = false): number { + defense( + normal: number, + special: number, + speed: number, + nerf: boolean = false, + ): number { return Math.round( - Math.round(2 * (0.625 * Math.max(normal, special) + 0.375 * Math.min(normal, special))) * + Math.round( + 2 * + (0.625 * Math.max(normal, special) + + 0.375 * Math.min(normal, special)), + ) * (1 + (speed - 75) / 500) * (nerf ? 0.91 : 1), ) } stamina(hp: number, nerf: boolean = false): number { - return nerf ? Math.round((1.75 * hp + 50) * 0.91) : Math.floor(1.75 * hp + 50) + return nerf + ? Math.round((1.75 * hp + 50) * 0.91) + : Math.floor(1.75 * hp + 50) } cp(atk: number, def: number, sta: number, cpm: number): number { - return Math.floor(((atk + 15) * (def + 15) ** 0.5 * (sta + 15) ** 0.5 * cpm ** 2) / 10) + return Math.floor( + ((atk + 15) * (def + 15) ** 0.5 * (sta + 15) ** 0.5 * cpm ** 2) / 10, + ) } megaLookup(id: string, type: string): string | 1 | 2 | 3 { @@ -63,7 +85,9 @@ export default class PokeApi extends Masterfile { } async baseStatsApi(parsedPokemon: AllPokemon, pokeApiIds: number[]) { - const inconsistentStats: { [id: string]: { attack?: number; defense?: number; stamina?: number } } = { + const inconsistentStats: { + [id: string]: { attack?: number; defense?: number; stamina?: number } + } = { 24: { attack: 167, }, @@ -133,36 +157,80 @@ export default class PokeApi extends Masterfile { parsedPokemon[id].types.length === 0 || (pokeApiIds && pokeApiIds.includes(+id)) ) { - const statsData: PokeApiStats = await this.fetch(`https://pokeapi.co/api/v2/pokemon/${id}/`) + const statsData: PokeApiStats = await this.fetch( + `https://pokeapi.co/api/v2/pokemon/${id}/`, + ) const baseStats: { [stat: string]: number } = {} statsData.stats.forEach((stat) => { baseStats[stat.stat.name] = stat.base_stat }) - const initial: { attack: number; defense: number; stamina: number; cp?: number } = { - attack: this.attack(baseStats.attack, baseStats['special-attack'], baseStats.speed), - defense: this.defense(baseStats.defense, baseStats['special-defense'], baseStats.speed), + const initial: { + attack: number + defense: number + stamina: number + cp?: number + } = { + attack: this.attack( + baseStats.attack, + baseStats['special-attack'], + baseStats.speed, + ), + defense: this.defense( + baseStats.defense, + baseStats['special-defense'], + baseStats.speed, + ), stamina: this.stamina(baseStats.hp), } - initial.cp = this.cp(initial.attack, initial.defense, initial.stamina, 0.79030001) + initial.cp = this.cp( + initial.attack, + initial.defense, + initial.stamina, + 0.79030001, + ) const nerfCheck = { attack: initial.cp > 4000 - ? this.attack(baseStats.attack, baseStats['special-attack'], baseStats.speed, true) + ? this.attack( + baseStats.attack, + baseStats['special-attack'], + baseStats.speed, + true, + ) : initial.attack, defense: initial.cp > 4000 - ? this.defense(baseStats.defense, baseStats['special-defense'], baseStats.speed, true) + ? this.defense( + baseStats.defense, + baseStats['special-defense'], + baseStats.speed, + true, + ) : initial.defense, - stamina: initial.cp > 4000 ? this.stamina(baseStats.hp, true) : initial.stamina, + stamina: + initial.cp > 4000 + ? this.stamina(baseStats.hp, true) + : initial.stamina, } this.baseStats[id] = { - attack: inconsistentStats[id] ? inconsistentStats[id].attack || nerfCheck.attack : nerfCheck.attack, - defense: inconsistentStats[id] ? inconsistentStats[id].defense || nerfCheck.defense : nerfCheck.defense, - stamina: inconsistentStats[id] ? inconsistentStats[id].stamina || nerfCheck.stamina : nerfCheck.stamina, + attack: inconsistentStats[id] + ? inconsistentStats[id].attack || nerfCheck.attack + : nerfCheck.attack, + defense: inconsistentStats[id] + ? inconsistentStats[id].defense || nerfCheck.defense + : nerfCheck.defense, + stamina: inconsistentStats[id] + ? inconsistentStats[id].stamina || nerfCheck.stamina + : nerfCheck.stamina, types: statsData.types - .map((type) => Rpc.HoloPokemonType[`POKEMON_TYPE_${type.type.name.toUpperCase()}` as TypeProto]) + .map( + (type) => + Rpc.HoloPokemonType[ + `POKEMON_TYPE_${type.type.name.toUpperCase()}` as TypeProto + ], + ) .sort((a, b) => a - b), unreleased: true, } @@ -179,10 +247,16 @@ export default class PokeApi extends Masterfile { Object.keys(this.baseStats).map(async (id) => { try { if (!evolvedPokemon.has(+id)) { - const evoData: SpeciesApi = await this.fetch(`https://pokeapi.co/api/v2/pokemon-species/${id}`) + const evoData: SpeciesApi = await this.fetch( + `https://pokeapi.co/api/v2/pokemon-species/${id}`, + ) if (evoData.evolves_from_species) { const prevEvoId = - Rpc.HoloPokemonId[evoData.evolves_from_species.name.toUpperCase().replace('-', '_') as PokemonIdProto] + Rpc.HoloPokemonId[ + evoData.evolves_from_species.name + .toUpperCase() + .replace('-', '_') as PokemonIdProto + ] if (prevEvoId) { if (!this.baseStats[prevEvoId]) { this.baseStats[prevEvoId] = {} @@ -194,12 +268,16 @@ export default class PokeApi extends Masterfile { evoId: +id, formId: 0, }) - this.baseStats[prevEvoId].evolutions.sort((a, b) => a.evoId - b.evoId) + this.baseStats[prevEvoId].evolutions.sort( + (a, b) => a.evoId - b.evoId, + ) evolvedPokemon.add(+id) } else { console.warn( 'Unable to find proto ID for', - evoData.evolves_from_species.name.toUpperCase().replace('-', '_'), + evoData.evolves_from_species.name + .toUpperCase() + .replace('-', '_'), ) } } @@ -292,22 +370,42 @@ export default class PokeApi extends Masterfile { await Promise.all( ids.map(async (id) => { try { - const pokemonId = Rpc.HoloPokemonId[id.split('-')[0].toUpperCase() as PokemonIdProto] - const statsData: PokeApiStats = await this.fetch(`https://pokeapi.co/api/v2/pokemon/${id}/`) + const pokemonId = + Rpc.HoloPokemonId[ + id.split('-')[0].toUpperCase() as PokemonIdProto + ] + const statsData: PokeApiStats = await this.fetch( + `https://pokeapi.co/api/v2/pokemon/${id}/`, + ) const baseStats: { [stat: string]: number } = {} statsData.stats.forEach((stat) => { baseStats[stat.stat.name] = stat.base_stat }) const types = statsData.types - .map((type) => Rpc.HoloPokemonType[`POKEMON_TYPE_${type.type.name.toUpperCase()}` as TypeProto]) + .map( + (type) => + Rpc.HoloPokemonType[ + `POKEMON_TYPE_${type.type.name.toUpperCase()}` as TypeProto + ], + ) .sort((a, b) => a - b) const newTheoretical: TempEvolutions = { tempEvoId: this.megaLookup(id, type), - attack: this.attack(baseStats.attack, baseStats['special-attack'], baseStats.speed), - defense: this.defense(baseStats.defense, baseStats['special-defense'], baseStats.speed), + attack: this.attack( + baseStats.attack, + baseStats['special-attack'], + baseStats.speed, + ), + defense: this.defense( + baseStats.defense, + baseStats['special-defense'], + baseStats.speed, + ), stamina: this.stamina(baseStats.hp), - types: this.compare(types, parsedPokemon[pokemonId].types) ? undefined : types, + types: this.compare(types, parsedPokemon[pokemonId].types) + ? undefined + : types, unreleased: true, } if (!this.tempEvos[type][pokemonId]) { @@ -319,7 +417,9 @@ export default class PokeApi extends Masterfile { if ( !parsedPokemon[pokemonId].tempEvolutions || (parsedPokemon[pokemonId].tempEvolutions && - !parsedPokemon[pokemonId].tempEvolutions.some((temp) => temp.tempEvoId === newTheoretical.tempEvoId)) + !parsedPokemon[pokemonId].tempEvolutions.some( + (temp) => temp.tempEvoId === newTheoretical.tempEvoId, + )) ) { this.tempEvos[type][pokemonId].tempEvolutions.push(newTheoretical) } @@ -334,7 +434,12 @@ export default class PokeApi extends Masterfile { async typesApi() { const getTypeIds = (types: { name: string }[]) => types - .map((type) => Rpc.HoloPokemonType[`POKEMON_TYPE_${type.name.toUpperCase()}` as TypeProto]) + .map( + (type) => + Rpc.HoloPokemonType[ + `POKEMON_TYPE_${type.name.toUpperCase()}` as TypeProto + ], + ) .sort((a, b) => a - b) await Promise.all( @@ -350,7 +455,11 @@ export default class PokeApi extends Masterfile { no_damage_to, }, }: PokeApiTypes = id - ? await this.fetch(`https://pokeapi.co/api/v2/type/${type.substring(13).toLowerCase()}`) + ? await this.fetch( + `https://pokeapi.co/api/v2/type/${type + .substring(13) + .toLowerCase()}`, + ) : { damage_relations: {} } this.types[id] = { strengths: id ? getTypeIds(double_damage_to) : [], diff --git a/src/classes/Pokemon.ts b/src/classes/Pokemon.ts index 7aa592d..a392a4e 100644 --- a/src/classes/Pokemon.ts +++ b/src/classes/Pokemon.ts @@ -126,7 +126,7 @@ export default class Pokemon extends Masterfile { id === Rpc.HoloPokemonId.NIDORAN_FEMALE || id === Rpc.HoloPokemonId.NIDORAN_MALE ? 8 - : Rpc.HoloPokemonId[id].length + 1 + : Rpc.HoloPokemonId[id].length + 1, ) return this.capitalize(name) } catch (e) { @@ -260,7 +260,7 @@ export default class Pokemon extends Masterfile { } catch (e) { console.warn( e, - `Failed to compile evos for ${JSON.stringify(mfObject, null, 2)}` + `Failed to compile evos for ${JSON.stringify(mfObject, null, 2)}`, ) } } @@ -268,7 +268,7 @@ export default class Pokemon extends Masterfile { compileTempEvos( mfObject: TempEvo[], evoBranch: EvoBranch[], - primaryForm: SinglePokemon + primaryForm: SinglePokemon, ): TempEvolutions[] { try { const tempEvolutions: TempEvolutions[] = mfObject @@ -300,7 +300,7 @@ export default class Pokemon extends Masterfile { newTempEvolution.types = types } const energy = evoBranch.find( - (branch) => branch.temporaryEvolution === tempEvo.tempEvoId + (branch) => branch.temporaryEvolution === tempEvo.tempEvoId, ) if (energy) { newTempEvolution.firstEnergyCost = @@ -311,12 +311,12 @@ export default class Pokemon extends Masterfile { return newTempEvolution }) return tempEvolutions.sort( - (a, b) => (a.tempEvoId as number) - (b.tempEvoId as number) + (a, b) => (a.tempEvoId as number) - (b.tempEvoId as number), ) } catch (e) { console.warn( e, - `Failed to compile temp evos for ${JSON.stringify(mfObject, null, 2)}` + `Failed to compile temp evos for ${JSON.stringify(mfObject, null, 2)}`, ) } } @@ -394,7 +394,7 @@ export default class Pokemon extends Masterfile { this.evolutionQuests[object.templateId].assetsRef = this.evolutionQuests[object.templateId].assetsRef.replace( 'single', - 'plural' + 'plural', ) } if (evolutionQuestTemplate.goals[1]) { @@ -403,7 +403,7 @@ export default class Pokemon extends Masterfile { } catch (e) { console.warn( e, - `Failed to add evolution quest for ${JSON.stringify(object, null, 2)}` + `Failed to add evolution quest for ${JSON.stringify(object, null, 2)}`, ) } } @@ -486,7 +486,7 @@ export default class Pokemon extends Masterfile { const primaryForm = this.parsedPokemon[id] const formName = this.formName( id, - split.filter((word, i) => i > 1 && word).join('_') + split.filter((word, i) => i > 1 && word).join('_'), ) if (!this.skipForms(formName)) { @@ -547,14 +547,14 @@ export default class Pokemon extends Masterfile { form.evolutions = [] } form.evolutions.push( - ...this.compileEvos(pokemonSettings.evolutionBranch) + ...this.compileEvos(pokemonSettings.evolutionBranch), ) } if (pokemonSettings.tempEvoOverrides) { form.tempEvolutions = this.compileTempEvos( pokemonSettings.tempEvoOverrides, pokemonSettings.evolutionBranch, - this.parsedPokemon[id] + this.parsedPokemon[id], ) } if ( @@ -562,7 +562,7 @@ export default class Pokemon extends Masterfile { primaryForm.tempEvolutions ) { form.tempEvolutions = Object.values(primaryForm.tempEvolutions).map( - (tempEvo) => tempEvo + (tempEvo) => tempEvo, ) } if (pokemonSettings.shadow) { @@ -573,7 +573,7 @@ export default class Pokemon extends Masterfile { } if (pokemonSettings.obCostumeEvolution) { form.costumeOverrideEvos = this.getCostumeOverrides( - pokemonSettings.obCostumeEvolution + pokemonSettings.obCostumeEvolution, ) } } @@ -616,19 +616,19 @@ export default class Pokemon extends Masterfile { pokemonSettings.evolutionBranch.some((evo) => evo.evolution) ) { this.parsedPokemon[id].evolutions = this.compileEvos( - pokemonSettings.evolutionBranch + pokemonSettings.evolutionBranch, ) } if (pokemonSettings.tempEvoOverrides) { this.parsedPokemon[id].tempEvolutions = this.compileTempEvos( pokemonSettings.tempEvoOverrides, pokemonSettings.evolutionBranch, - this.parsedPokemon[id] + this.parsedPokemon[id], ) } if (pokemonSettings.obCostumeEvolution) { this.parsedPokemon[id].costumeOverrideEvos = this.getCostumeOverrides( - pokemonSettings.obCostumeEvolution + pokemonSettings.obCostumeEvolution, ) } } @@ -636,7 +636,7 @@ export default class Pokemon extends Masterfile { console.warn( e, `Failed to parse Pokemon for ${id}`, - JSON.stringify(object, null, 2) + JSON.stringify(object, null, 2), ) } } @@ -729,7 +729,7 @@ export default class Pokemon extends Masterfile { Object.entries(this.parsedPokemon).forEach(([id, pokemon]) => { const allowed = this.jungleCupRules.types.some((type) => - pokemon.types.includes(type) + pokemon.types.includes(type), ) && !this.jungleCupRules.banned.includes(+id) if (allowed) pokemon.jungle = true }) @@ -815,31 +815,31 @@ export default class Pokemon extends Masterfile { ) { Object.keys(tempEvos[category]).forEach((id) => { try { - const tempEvolutions = [ - ...tempEvos[category][id].tempEvolutions, - ...(this.parsedPokemon[id].tempEvolutions - ? this.parsedPokemon[id].tempEvolutions - : []), - ] - this.parsedPokemon[id] = { - ...this.parsedPokemon[id], - tempEvolutions, - } - if (this.parsedPokemon[id].forms) { - this.parsedPokemon[id].forms.forEach((form) => { - if ( - this.parsedForms[form].formName === 'Normal' || - this.parsedForms[form].formName === 'Purified' - ) { - this.parsedForms[form].tempEvolutions = tempEvolutions - } - }) - } + const tempEvolutions = [ + ...tempEvos[category][id].tempEvolutions, + ...(this.parsedPokemon[id].tempEvolutions + ? this.parsedPokemon[id].tempEvolutions + : []), + ] + this.parsedPokemon[id] = { + ...this.parsedPokemon[id], + tempEvolutions, + } + if (this.parsedPokemon[id].forms) { + this.parsedPokemon[id].forms.forEach((form) => { + if ( + this.parsedForms[form].formName === 'Normal' || + this.parsedForms[form].formName === 'Purified' + ) { + this.parsedForms[form].tempEvolutions = tempEvolutions + } + }) + } } catch (e) { console.warn(e, `Failed to parse temp evos for ${category}-${id}`) } }) - } + } } catch (e) { console.warn(e, `Failed to parse temp evos for ${category}`) } diff --git a/src/classes/Quest.ts b/src/classes/Quest.ts index 9685247..9c69583 100644 --- a/src/classes/Quest.ts +++ b/src/classes/Quest.ts @@ -42,7 +42,10 @@ export default class Quests extends Masterfile { parseTarget[id] = { id, proto: name, - formatted: category === 'types' ? this.capitalize(name.replace('QUEST_', '')) : this.capitalize(name), + formatted: + category === 'types' + ? this.capitalize(name.replace('QUEST_', '')) + : this.capitalize(name), } } catch (e) { console.warn(e, `Failed to parse quest ${proto}`) diff --git a/src/classes/Translations.ts b/src/classes/Translations.ts index eea1d72..6ee8e6b 100644 --- a/src/classes/Translations.ts +++ b/src/classes/Translations.ts @@ -1,5 +1,12 @@ import { Rpc } from 'pogo-protos' -import { AllForms, AllInvasions, AllPokemon, AllQuests, FinalResult, TranslationKeys } from '../typings/dataTypes' +import { + AllForms, + AllInvasions, + AllPokemon, + AllQuests, + FinalResult, + TranslationKeys, +} from '../typings/dataTypes' import { EvolutionQuest } from '../typings/general' import { Options, Locales } from '../typings/inputs' import { TypeProto } from '../typings/protos' @@ -137,7 +144,10 @@ export default class Translations extends Masterfile { return str.replace(/\r/g, '').replace(/\n/g, '').replace(/\"/g, '”') } - async fetchTranslations(locale: Locales[number], availableManualTranslations: string[]) { + async fetchTranslations( + locale: Locales[number], + availableManualTranslations: string[], + ) { this.rawTranslations[locale] = {} this.parsedTranslations[locale] = {} this.manualTranslations[locale] = { @@ -167,36 +177,41 @@ export default class Translations extends Masterfile { this.generics[locale] = this.generics.en console.warn(`Generics unavailable for ${locale}, using English`) } - const { data }: { data: string[] } = await this.fetch( + const { data }: { data: string[] } = (await this.fetch( `https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20APK/JSON/i18n_${ this.codes[locale]?.toLowerCase() || 'english' }.json`, - ) || { data: [] } + )) || { data: [] } for (let i = 0; i < data.length; i += 2) { this.rawTranslations[locale][data[i]] = this.removeEscapes(data[i + 1]) } - const textFile = ['hi', 'id'].includes(locale) ? '' : await this.fetch( - `https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20Remote/${ - this.codes[locale] || 'English' - }.txt`, - true, - ) || '' + const textFile = ['hi', 'id'].includes(locale) + ? '' + : (await this.fetch( + `https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20Remote/${ + this.codes[locale] || 'English' + }.txt`, + true, + )) || '' const splitText = textFile.split('\n') splitText.forEach((line: string, i: number) => { if (line?.startsWith('RESOURCE ID')) { - this.rawTranslations[locale][this.removeEscapes(line.replace('RESOURCE ID: ', ''))] = this.removeEscapes( - splitText[i + 1].replace('TEXT: ', ''), - ) + this.rawTranslations[locale][ + this.removeEscapes(line.replace('RESOURCE ID: ', '')) + ] = this.removeEscapes(splitText[i + 1].replace('TEXT: ', '')) } }) } catch (e) { console.warn(e, '\n', `Unable to process ${locale} from GM`) } try { - if (this.options.manualTranslations && availableManualTranslations.includes(`${locale}.json`)) { + if ( + this.options.manualTranslations && + availableManualTranslations.includes(`${locale}.json`) + ) { const manual: { [key: string]: string } = await this.fetch( `https://raw.githubusercontent.com/WatWowMap/pogo-translations/master/static/manual/${locale}.json`, ) @@ -205,16 +220,28 @@ export default class Translations extends Masterfile { const [key, value] = pair let trimmedKey if (key.startsWith('poke_type')) { - trimmedKey = key.replace('poke_type_', this.options.prefix.types || 'poke_type_') + trimmedKey = key.replace( + 'poke_type_', + this.options.prefix.types || 'poke_type_', + ) this.manualTranslations[locale].types[trimmedKey] = value } else if (key.startsWith('poke')) { - trimmedKey = key.replace('poke_', this.options.prefix.pokemon || 'poke_') + trimmedKey = key.replace( + 'poke_', + this.options.prefix.pokemon || 'poke_', + ) this.manualTranslations[locale].pokemon[trimmedKey] = value } else if (key.startsWith('form')) { - trimmedKey = key.replace('form_', this.options.prefix.forms || 'form_') + trimmedKey = key.replace( + 'form_', + this.options.prefix.forms || 'form_', + ) this.manualTranslations[locale].forms[trimmedKey] = value } else if (key.startsWith('costume')) { - trimmedKey = key.replace('costume_', this.options.prefix.costumes || 'costume_') + trimmedKey = key.replace( + 'costume_', + this.options.prefix.costumes || 'costume_', + ) this.manualTranslations[locale].costumes[trimmedKey] = value } else if (key.startsWith('quest_')) { const newValue = @@ -225,32 +252,57 @@ export default class Translations extends Masterfile { : value if (key.startsWith('quest_condition_')) { this.manualTranslations[locale].questConditions[ - key.replace('quest_condition_', this.options.prefix.questConditions || 'quest_condition_') + key.replace( + 'quest_condition_', + this.options.prefix.questConditions || 'quest_condition_', + ) ] = newValue } else if (key.startsWith('quest_reward_')) { this.manualTranslations[locale].questRewardTypes[ - key.replace('quest_reward_', this.options.prefix.questRewardTypes || 'quest_reward_') + key.replace( + 'quest_reward_', + this.options.prefix.questRewardTypes || 'quest_reward_', + ) ] = newValue } else if (key.startsWith('quest_title_')) { this.manualTranslations[locale].questRewardTypes[ - key.replace('quest_title_', this.options.prefix.questTitles || 'quest_title_') + key.replace( + 'quest_title_', + this.options.prefix.questTitles || 'quest_title_', + ) ] = newValue } else { this.manualTranslations[locale].questTypes[ - key.replace('quest_', this.options.prefix.questTypes || 'quest_') + key.replace( + 'quest_', + this.options.prefix.questTypes || 'quest_', + ) ] = newValue } } else if (key.startsWith('grunt')) { - trimmedKey = key.replace('grunt_', this.options.prefix.grunts || 'grunt_') + trimmedKey = key.replace( + 'grunt_', + this.options.prefix.grunts || 'grunt_', + ) this.manualTranslations[locale].grunts[trimmedKey] = value } else if (key.startsWith('character')) { - trimmedKey = key.replace('character_', this.options.prefix.characterCategories || 'character_category_') - this.manualTranslations[locale].characterCategories[trimmedKey] = value + trimmedKey = key.replace( + 'character_', + this.options.prefix.characterCategories || 'character_category_', + ) + this.manualTranslations[locale].characterCategories[trimmedKey] = + value } else if (key.startsWith('weather')) { - trimmedKey = key.replace('weather_', this.options.prefix.weather || 'weather_') + trimmedKey = key.replace( + 'weather_', + this.options.prefix.weather || 'weather_', + ) this.manualTranslations[locale].weather[trimmedKey] = value } else if (key.startsWith('throw')) { - trimmedKey = key.replace('throw_type_', this.options.prefix.throwTypes || 'throw_type_') + trimmedKey = key.replace( + 'throw_type_', + this.options.prefix.throwTypes || 'throw_type_', + ) this.manualTranslations[locale].misc[trimmedKey] = value } else { this.manualTranslations[locale].misc[key] = value @@ -276,7 +328,9 @@ export default class Translations extends Masterfile { ...this.manualTranslations[locale][category], } sorted[category] = {} - const sortedKeys = Object.keys(merged[category]).sort(this.collator.compare) + const sortedKeys = Object.keys(merged[category]).sort( + this.collator.compare, + ) sortedKeys.forEach((key) => { sorted[category][key] = merged[category][key] }) @@ -291,14 +345,19 @@ export default class Translations extends Masterfile { languageRef(locale: string) { try { if (!this.reference) { - this.reference = this.parsedTranslations[this.options.useLanguageAsRef as string] + this.reference = + this.parsedTranslations[this.options.useLanguageAsRef as string] } const languageRef: TranslationKeys = {} Object.keys(this.parsedTranslations[locale]).forEach((category) => { languageRef[category] = {} Object.keys(this.parsedTranslations[locale][category]).forEach((x) => { - if (this.reference[category][x] && !languageRef[category][this.reference[category][x]]) { - languageRef[category][this.reference[category][x]] = this.parsedTranslations[locale][category][x] + if ( + this.reference[category][x] && + !languageRef[category][this.reference[category][x]] + ) { + languageRef[category][this.reference[category][x]] = + this.parsedTranslations[locale][category][x] } }) }) @@ -323,13 +382,19 @@ export default class Translations extends Masterfile { } } - translateMasterfile(data: FinalResult, locale: string, formsSeparate: boolean) { + translateMasterfile( + data: FinalResult, + locale: string, + formsSeparate: boolean, + ) { try { const language = this.parsedTranslations[locale] if (language) { Object.keys(data).forEach((category) => { - const ref = this.options.mergeCategories ? language : language[category] + const ref = this.options.mergeCategories + ? language + : language[category] if (ref) { this.masterfile[category] = {} @@ -348,29 +413,44 @@ export default class Translations extends Masterfile { ), } } else if (this.options.prefix[category]) { - const actualId = category === 'pokemon' && formsSeparate ? data[category][id].pokedexId : id + const actualId = + category === 'pokemon' && formsSeparate + ? data[category][id].pokedexId + : id - if (ref[`${this.options.prefix[category]}${actualId}`] !== undefined) { + if ( + ref[`${this.options.prefix[category]}${actualId}`] !== + undefined + ) { const fieldKey = category === 'pokemon' && formsSeparate ? 'pokemonName' - : Object.keys(data[category][id]).find((field) => field.includes('Name')) + : Object.keys(data[category][id]).find((field) => + field.includes('Name'), + ) if (fieldKey) { this.masterfile[category][id] = { ...data[category][id], - [fieldKey]: ref[`${this.options.prefix[category]}${actualId}`], + [fieldKey]: + ref[`${this.options.prefix[category]}${actualId}`], } } else { - console.warn(`Unable to determine field key for ${id} in ${category}, proceeding with default.`) + console.warn( + `Unable to determine field key for ${id} in ${category}, proceeding with default.`, + ) this.masterfile[category][id] = data[category][id] } } else { - console.warn(`Missing ${locale} key for id: ${id} in ${category}, proceeding with default.`) + console.warn( + `Missing ${locale} key for id: ${id} in ${category}, proceeding with default.`, + ) this.masterfile[category][id] = data[category][id] } } else { - console.warn(`Missing prefix for category ${category}, proceeding with default.`) + console.warn( + `Missing prefix for category ${category}, proceeding with default.`, + ) this.masterfile[category][id] = data[category][id] } }) @@ -379,7 +459,9 @@ export default class Translations extends Masterfile { } }) } else { - console.warn(`Missing ${locale} translation, please check your template to make sure it's being parsed.`) + console.warn( + `Missing ${locale} translation, please check your template to make sure it's being parsed.`, + ) } } catch (e) { console.warn(e, '\n', `Unable to translate masterfile for ${locale}`) @@ -397,7 +479,10 @@ export default class Translations extends Masterfile { [`${this.options.prefix.pokemon}0`]: this.generics[locale].substitute, } this.parsedTranslations[locale].forms = { - [`${this.options.prefix.forms}0`]: unsetFormName === undefined ? this.generics[locale].unknown : unsetFormName, + [`${this.options.prefix.forms}0`]: + unsetFormName === undefined + ? this.generics[locale].unknown + : unsetFormName, } this.parsedTranslations[locale].descriptions = { [`${this.options.prefix.descriptions}0`]: this.generics[locale].none, @@ -406,59 +491,92 @@ export default class Translations extends Masterfile { Object.keys(pokemon).forEach((id) => { try { - const name = this.rawTranslations[locale][`pokemon_name_${String(id).padStart(4, '0')}`] || pokemon[id].pokemonName + const name = + this.rawTranslations[locale][ + `pokemon_name_${String(id).padStart(4, '0')}` + ] || pokemon[id].pokemonName const description = `pokemon_desc_${String(id).padStart(4, '0')}` if (id) { if (name && subItems.names) { - this.parsedTranslations[locale].pokemon[`${this.options.prefix.pokemon}${id}`] = name + this.parsedTranslations[locale].pokemon[ + `${this.options.prefix.pokemon}${id}` + ] = name } - if (this.rawTranslations[locale][description] && subItems.descriptions) { - this.parsedTranslations[locale].descriptions[`${this.options.prefix.descriptions}${id}`] = - this.rawTranslations[locale][description] + if ( + this.rawTranslations[locale][description] && + subItems.descriptions + ) { + this.parsedTranslations[locale].descriptions[ + `${this.options.prefix.descriptions}${id}` + ] = this.rawTranslations[locale][description] } if (pokemon[id] && pokemon[id].forms) { pokemon[id].forms.forEach((formId) => { const formName = forms[formId].formName - const formDescription = this.rawTranslations[locale][`${description}_${String(formId).padStart(4, '0')}`] + const formDescription = + this.rawTranslations[locale][ + `${description}_${String(formId).padStart(4, '0')}` + ] if (formName && subItems.forms) { let checkAssets = formName.replace(' ', '_').toLowerCase() if (id === '413' || id === '412') checkAssets += '_cloak' - const formAsset = this.rawTranslations[locale][`form_${checkAssets}`] - const typeId = Rpc.HoloPokemonType[`POKEMON_TYPE_${checkAssets.toUpperCase()}` as TypeProto] + const formAsset = + this.rawTranslations[locale][`form_${checkAssets}`] + const typeId = + Rpc.HoloPokemonType[ + `POKEMON_TYPE_${checkAssets.toUpperCase()}` as TypeProto + ] if ( this.parsedTranslations[locale].misc && this.parsedTranslations[locale].misc[formName.toLowerCase()] ) { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = this.parsedTranslations[locale].misc[formName.toLowerCase()] } else if (formAsset && checkAssets !== 'normal') { // Couple of edge cases here due to Niantic not being specific enough in the masterfile if (checkAssets === 'white' || checkAssets === 'black') { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = - formId === 147 || formId === 148 ? formAsset : formName + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = formId === 147 || formId === 148 ? formAsset : formName } else if (checkAssets === 'ice') { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = formId === 2540 || formId === 2541 ? formAsset - : this.parsedTranslations[locale].types[`${this.options.prefix.types}${typeId}`] || formName + : this.parsedTranslations[locale].types[ + `${this.options.prefix.types}${typeId}` + ] || formName } else { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = formAsset + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = formAsset } } else if (formName === 'Normal') { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = - this.generics[locale].normal + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = this.generics[locale].normal } else if (typeId && this.parsedTranslations[locale].types) { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = - this.parsedTranslations[locale].types[`${this.options.prefix.types}${typeId}`] + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = + this.parsedTranslations[locale].types[ + `${this.options.prefix.types}${typeId}` + ] } else { - this.parsedTranslations[locale].forms[`${this.options.prefix.forms}${formId}`] = formName + this.parsedTranslations[locale].forms[ + `${this.options.prefix.forms}${formId}` + ] = formName } } if (formDescription && subItems.descriptions) { - this.parsedTranslations[locale].descriptions[`${this.options.prefix.descriptions}${id}_${formId}`] = - formDescription + this.parsedTranslations[locale].descriptions[ + `${this.options.prefix.descriptions}${id}_${formId}` + ] = formDescription } }) } @@ -469,7 +587,9 @@ export default class Translations extends Masterfile { }) Object.entries(Rpc.PokemonDisplayProto.Costume).forEach((proto) => { const [name, id] = proto - this.parsedTranslations[locale].costumes[`${this.options.prefix.costumes}${id}`] = this.capitalize(name) + this.parsedTranslations[locale].costumes[ + `${this.options.prefix.costumes}${id}` + ] = this.capitalize(name) }) } @@ -480,12 +600,18 @@ export default class Translations extends Masterfile { if (key.startsWith(`pokemon_category_`)) { const split = key.replace('pokemon_category_', '').split('_') this.parsedTranslations[locale].pokemonCategories[ - `${this.options.prefix.pokemonCategories}${split.map((x) => +x || x).join('_')}` + `${this.options.prefix.pokemonCategories}${split + .map((x) => +x || x) + .join('_')}` ] = this.rawTranslations[locale][key] } }) } catch (e) { - console.warn(e, '\n', `Unable to translate pokemon categories for ${locale}`) + console.warn( + e, + '\n', + `Unable to translate pokemon categories for ${locale}`, + ) } } @@ -498,8 +624,13 @@ export default class Translations extends Masterfile { const [name, id] = proto if (!id) return - const move = this.rawTranslations[locale][`move_name_${String(id).padStart(4, '0')}`] - this.parsedTranslations[locale].moves[`${this.options.prefix.moves}${id}`] = move || this.capitalize(name) + const move = + this.rawTranslations[locale][ + `move_name_${String(id).padStart(4, '0')}` + ] + this.parsedTranslations[locale].moves[ + `${this.options.prefix.moves}${id}` + ] = move || this.capitalize(name) }) } catch (e) { console.warn(e, '\n', `Unable to translate moves for ${locale}`) @@ -516,21 +647,27 @@ export default class Translations extends Masterfile { const [name, id] = proto if (!id) return - let item = this.rawTranslations[locale][`${name.toLowerCase()}_name`] || this.capitalize(name) - this.parsedTranslations[locale].items[`${this.options.prefix.items}${id}`] = - item || this.capitalize(name.replace('ITEM_', '')) + let item = + this.rawTranslations[locale][`${name.toLowerCase()}_name`] || + this.capitalize(name) + this.parsedTranslations[locale].items[ + `${this.options.prefix.items}${id}` + ] = item || this.capitalize(name.replace('ITEM_', '')) if (name.startsWith('ITEM_TROY_DISK')) { - const base = this.rawTranslations[locale].item_troy_disk_name.split(' ') + const base = + this.rawTranslations[locale].item_troy_disk_name.split(' ') if (name === 'ITEM_TROY_DISK') { - this.parsedTranslations[locale].lures[`${this.options.prefix.lures}${id}`] = this.generics[locale].normal + this.parsedTranslations[locale].lures[ + `${this.options.prefix.lures}${id}` + ] = this.generics[locale].normal } else { base.forEach((word) => { item = item.replace(word, '') }) item = item.replace('Mód. ', '') - this.parsedTranslations[locale].lures[`${this.options.prefix.lures}${id}`] = this.capitalize( - item.replace('-', '').trim(), - ) + this.parsedTranslations[locale].lures[ + `${this.options.prefix.lures}${id}` + ] = this.capitalize(item.replace('-', '').trim()) } } }) @@ -546,9 +683,14 @@ export default class Translations extends Masterfile { } Object.entries(Rpc.HoloPokemonType).forEach((proto) => { const [name, id] = proto - const type = this.rawTranslations[locale][`pokemon_type_${name.replace('POKEMON_TYPE_', '').toLowerCase()}`] + const type = + this.rawTranslations[locale][ + `pokemon_type_${name.replace('POKEMON_TYPE_', '').toLowerCase()}` + ] if (type) { - this.parsedTranslations[locale].types[`${this.options.prefix.types}${id}`] = type + this.parsedTranslations[locale].types[ + `${this.options.prefix.types}${id}` + ] = type } }) } catch (e) { @@ -569,44 +711,80 @@ export default class Translations extends Masterfile { switch (info.grunt) { case 'Grunt': const base = `${ - this.rawTranslations[locale][info.type === 'Decoy' ? 'combat_grunt_decoy_name' : 'combat_grunt_name'] - } (${this.rawTranslations[locale][`gender_${info.gender === 1 ? 'male' : 'female'}`]})` - const type = this.rawTranslations[locale][`pokemon_type_${info.type.replace(' Balloon', '').toLowerCase()}`] + this.rawTranslations[locale][ + info.type === 'Decoy' + ? 'combat_grunt_decoy_name' + : 'combat_grunt_name' + ] + } (${ + this.rawTranslations[locale][ + `gender_${info.gender === 1 ? 'male' : 'female'}` + ] + })` + const type = + this.rawTranslations[locale][ + `pokemon_type_${info.type + .replace(' Balloon', '') + .toLowerCase()}` + ] assetRef = type ? `${type} - ${base}` : base shortRef = assetRef .replace( - ` (${this.rawTranslations[locale][`gender_${info.gender === 1 ? 'male' : 'female'}`]})`, + ` (${ + this.rawTranslations[locale][ + `gender_${info.gender === 1 ? 'male' : 'female'}` + ] + })`, info.gender === 1 ? ' ♂' : ' ♀', ) - .replace(` - ${this.rawTranslations[locale]['combat_grunt_name']}`, '') || info.type + .replace( + ` - ${this.rawTranslations[locale]['combat_grunt_name']}`, + '', + ) || info.type break case 'Executive': - assetRef = this.rawTranslations[locale][`combat_${info.type.toLowerCase()}_name`] || info.type + assetRef = + this.rawTranslations[locale][ + `combat_${info.type.toLowerCase()}_name` + ] || info.type break case 'Event': assetRef = - this.rawTranslations[locale][`event_npc${info.type.split(' ')[1].padStart(2, '0')}_name`] || info.type + this.rawTranslations[locale][ + `event_npc${info.type.split(' ')[1].padStart(2, '0')}_name` + ] || info.type break default: assetRef = - this.rawTranslations[locale][`combat_${info.type.toLowerCase()}`] || - this.rawTranslations[locale][`combat_${info.type.toLowerCase()}_name`] || + this.rawTranslations[locale][ + `combat_${info.type.toLowerCase()}` + ] || + this.rawTranslations[locale][ + `combat_${info.type.toLowerCase()}_name` + ] || info.type } if (assetRef) { - this.parsedTranslations[locale].grunts[`${this.options.prefix.grunts}${id}`] = assetRef + this.parsedTranslations[locale].grunts[ + `${this.options.prefix.grunts}${id}` + ] = assetRef } if (shortRef) { - this.parsedTranslations[locale].grunts[`${this.options.prefix.gruntsAlt}${id}`] = shortRef + this.parsedTranslations[locale].grunts[ + `${this.options.prefix.gruntsAlt}${id}` + ] = shortRef } else if (assetRef && id !== '0') { - this.parsedTranslations[locale].grunts[`${this.options.prefix.gruntsAlt}${id}`] = assetRef + this.parsedTranslations[locale].grunts[ + `${this.options.prefix.gruntsAlt}${id}` + ] = assetRef } }) Object.entries(Rpc.EnumWrapper.CharacterCategory).forEach((proto) => { const [name, id] = proto - this.parsedTranslations[locale].characterCategories[`${this.options.prefix.characterCategories}${id}`] = - this.capitalize(name) + this.parsedTranslations[locale].characterCategories[ + `${this.options.prefix.characterCategories}${id}` + ] = this.capitalize(name) }) } catch (e) { console.warn(e, '\n', `Unable to translate characters for ${locale}`) @@ -618,15 +796,19 @@ export default class Translations extends Masterfile { this.parsedTranslations[locale].weather = { [`${this.options.prefix.weather}0`]: this.generics[locale].none, } - Object.entries(Rpc.GameplayWeatherProto.WeatherCondition).forEach((proto) => { - const [name, id] = proto - const type = id - ? this.rawTranslations[locale][`weather_${name.toLowerCase()}`] - : this.rawTranslations[locale][`weather_extreme`] - if (type) { - this.parsedTranslations[locale].weather[`${this.options.prefix.weather}${id}`] = type - } - }) + Object.entries(Rpc.GameplayWeatherProto.WeatherCondition).forEach( + (proto) => { + const [name, id] = proto + const type = id + ? this.rawTranslations[locale][`weather_${name.toLowerCase()}`] + : this.rawTranslations[locale][`weather_extreme`] + if (type) { + this.parsedTranslations[locale].weather[ + `${this.options.prefix.weather}${id}` + ] = type + } + }, + ) } catch (e) { console.warn(e, '\n', `Unable to translate weather for ${locale}`) } @@ -644,7 +826,9 @@ export default class Translations extends Masterfile { mythical: this.rawTranslations[locale].filter_key_mythical, } Object.keys(this.parsedTranslations[locale].misc).forEach((entry) => { - this.parsedTranslations[locale].misc[entry] = this.capitalize(this.parsedTranslations[locale].misc[entry]) + this.parsedTranslations[locale].misc[entry] = this.capitalize( + this.parsedTranslations[locale].misc[entry], + ) }) for (let i = 0; i < 4; i += 1) { const teamName = this.rawTranslations[locale][`team_name_team${i}`] @@ -656,22 +840,24 @@ export default class Translations extends Masterfile { Object.entries(Rpc.HoloActivityType).forEach((proto) => { const [name, id] = proto if (name.endsWith('THROW') || name.endsWith('CURVEBALL')) { - this.parsedTranslations[locale].misc[`${this.options.prefix.throwTypes}${id}`] = this.capitalize( + this.parsedTranslations[locale].misc[ + `${this.options.prefix.throwTypes}${id}` + ] = this.capitalize( name.replace('ACTIVITY_CATCH_', '').replace('_THROW', ''), ) } }) Object.entries(Rpc.HoloTemporaryEvolutionId).forEach((proto) => { const [name, id] = proto - this.parsedTranslations[locale].misc[`${this.options.prefix.evolutions}${id}`] = this.capitalize( - name.replace('TEMP_EVOLUTION_', ''), - ) + this.parsedTranslations[locale].misc[ + `${this.options.prefix.evolutions}${id}` + ] = this.capitalize(name.replace('TEMP_EVOLUTION_', '')) }) Object.entries(Rpc.PokemonDisplayProto.Alignment).forEach((proto) => { const [name, id] = proto - this.parsedTranslations[locale].misc[`${this.options.prefix.alignment}${id}`] = this.capitalize( - name.replace('POKEMON_ALIGNMENT_', ''), - ) + this.parsedTranslations[locale].misc[ + `${this.options.prefix.alignment}${id}` + ] = this.capitalize(name.replace('POKEMON_ALIGNMENT_', '')) }) } catch (e) { console.warn(e, '\n', `Unable to translate misc for ${locale}`) @@ -684,7 +870,9 @@ export default class Translations extends Masterfile { this.parsedTranslations[locale][category] = {} Object.keys(data[category]).forEach((proto) => { const value = data[category][proto].formatted.replace('With ', '') - this.parsedTranslations[locale][category][`${this.options.prefix[category]}${proto}`] = value + this.parsedTranslations[locale][category][ + `${this.options.prefix[category]}${proto}` + ] = value }) }) this.parsedTranslations[locale].questTitles = {} @@ -697,10 +885,14 @@ export default class Translations extends Masterfile { key.startsWith('score') || key.startsWith('geotarget_quest') || key.startsWith('challenge')) && - this.options.questTitleTermsToSkip.every((term) => !key.includes(term)) && + this.options.questTitleTermsToSkip.every( + (term) => !key.includes(term), + ) && !value.includes('%PLAYERNAME%') ) { - this.parsedTranslations[locale].questTitles[`${this.options.prefix.questTitles}${key}`] = value + this.parsedTranslations[locale].questTitles[ + `${this.options.prefix.questTitles}${key}` + ] = value } }) } catch (e) { @@ -716,9 +908,14 @@ export default class Translations extends Masterfile { '{0}', `${this.options.questVariables.prefix}amount${this.options.questVariables.suffix}`, ) - this.parsedTranslations[locale].evolutionQuests[info.assetsRef] = translated + this.parsedTranslations[locale].evolutionQuests[info.assetsRef] = + translated } catch (e) { - console.warn(e, '\n', `Unable to translate evo quests for ${info} in ${locale}`) + console.warn( + e, + '\n', + `Unable to translate evo quests for ${info} in ${locale}`, + ) } }) } diff --git a/src/classes/Weather.ts b/src/classes/Weather.ts index 61efe2b..e4cae64 100644 --- a/src/classes/Weather.ts +++ b/src/classes/Weather.ts @@ -15,19 +15,21 @@ export default class Weather extends Masterfile { } buildWeather() { - Object.entries(Rpc.GameplayWeatherProto.WeatherCondition).forEach((proto) => { - try { - const [name, id] = proto - this.parsedWeather[id] = { - weatherId: +id, - weatherName: this.capitalize(name), - proto: name, - types: this.rawWeather[name] || [], + Object.entries(Rpc.GameplayWeatherProto.WeatherCondition).forEach( + (proto) => { + try { + const [name, id] = proto + this.parsedWeather[id] = { + weatherId: +id, + weatherName: this.capitalize(name), + proto: name, + types: this.rawWeather[name] || [], + } + } catch (e) { + console.warn(e, proto) } - } catch (e) { - console.warn(e, proto) - } - }) + }, + ) } addWeather(object: NiaMfObj) { diff --git a/src/index.ts b/src/index.ts index 0d88802..6ca1a81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,14 +10,28 @@ import Translations from './classes/Translations' import PokeApi from './classes/PokeApi' import base from './base' -import { Input, InvasionsOnly, Locales, PokemonTemplate, TranslationsTemplate } from './typings/inputs' +import { + Input, + InvasionsOnly, + Locales, + PokemonTemplate, + TranslationsTemplate, +} from './typings/inputs' import { AllInvasions, FinalResult } from './typings/dataTypes' import { InvasionInfo } from './typings/pogoinfo' import { NiaMfObj } from './typings/general' -export async function generate({ template, url, raw, pokeApi, test }: Input = {}): Promise { +export async function generate({ + template, + url, + raw, + pokeApi, + test, +}: Input = {}): Promise { const final: FinalResult = {} - const urlToFetch = url || 'https://raw.githubusercontent.com/PokeMiners/game_masters/master/latest/latest.json' + const urlToFetch = + url || + 'https://raw.githubusercontent.com/PokeMiners/game_masters/master/latest/latest.json' const { pokemon, types, @@ -31,7 +45,8 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} weather, translations, } = Masterfile.templateMerger(template || base, base) - const localeCheck = translations.enabled && translations.options.masterfileLocale + const localeCheck = + translations.enabled && translations.options.masterfileLocale const AllPokemon = new Pokemon(pokemon.options) const AllItems = new Items(items.options) @@ -55,13 +70,17 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} AllItems.addItem(data[i]) } else if (data[i].data.combatMove) { AllMoves.addMove(data[i]) - } else if (data[i].templateId === 'COMBAT_LEAGUE_VS_SEEKER_GREAT_LITTLE') { + } else if ( + data[i].templateId === 'COMBAT_LEAGUE_VS_SEEKER_GREAT_LITTLE' + ) { AllPokemon.lcBanList = new Set(data[i].data.combatLeague.bannedPokemon) } else if (data[i].data.weatherAffinities) { AllWeather.addWeather(data[i]) } else if (data[i].data.evolutionQuestTemplate) { AllPokemon.addEvolutionQuest(data[i]) - } else if (data[i].templateId === 'COMBAT_LEAGUE_VS_SEEKER_LITTLE_JUNGLE') { + } else if ( + data[i].templateId === 'COMBAT_LEAGUE_VS_SEEKER_LITTLE_JUNGLE' + ) { AllPokemon.jungleCup(data[i]) } } @@ -77,13 +96,18 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} AllPokemon.sortForms() if (pokeApi === true) { - await AllPokeApi.baseStatsApi(AllPokemon.parsedPokemon, pokemon.options.pokeApiIds) + await AllPokeApi.baseStatsApi( + AllPokemon.parsedPokemon, + pokemon.options.pokeApiIds, + ) await AllPokeApi.evoApi(AllPokemon.evolvedPokemon) await AllPokeApi.tempEvoApi(AllPokemon.parsedPokemon) await AllPokeApi.typesApi() } - const getDataSource = async (category: 'baseStats' | 'tempEvos' | 'types') => { + const getDataSource = async ( + category: 'baseStats' | 'tempEvos' | 'types', + ) => { if (pokeApi === true) return AllPokeApi[category] if (pokeApi) return pokeApi[category] return AllPokeApi.fetch( @@ -94,7 +118,10 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} AllTypes.parsePokeApi(await getDataSource('types')) if (pokemon.options.includeEstimatedPokemon) { - AllPokemon.parsePokeApi(await getDataSource('baseStats'), await getDataSource('tempEvos')) + AllPokemon.parsePokeApi( + await getDataSource('baseStats'), + await getDataSource('tempEvos'), + ) } if ((pokemon.template as PokemonTemplate).little) { @@ -113,11 +140,19 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} AllMoves.protoMoves() } AllWeather.buildWeather() - if (invasions.enabled || (translations.template as TranslationsTemplate).characters) { + if ( + invasions.enabled || + (translations.template as TranslationsTemplate).characters + ) { const invasionData: InvasionInfo = await AllInvasions.fetch( 'https://raw.githubusercontent.com/WatWowMap/event-info/main/grunts/classic.json', ) - AllInvasions.invasions(AllInvasions.mergeInvasions(invasionData, await AllInvasions.customInvasions())) + AllInvasions.invasions( + AllInvasions.mergeInvasions( + invasionData, + await AllInvasions.customInvasions(), + ), + ) } if (translations.enabled) { @@ -128,7 +163,10 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} Object.entries(translations.locales).map(async (langCode) => { const [localeCode, bool] = langCode if (bool) { - await AllTranslations.fetchTranslations(localeCode as Locales[number], availableManualTranslations) + await AllTranslations.fetchTranslations( + localeCode as Locales[number], + availableManualTranslations, + ) if (translations.template.misc) { AllTranslations.misc(localeCode) @@ -166,7 +204,10 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} questConditions: AllQuests.parsedConditions, questRewardTypes: AllQuests.parsedRewardTypes, }) - AllTranslations.parseEvoQuests(localeCode, AllPokemon.evolutionQuests) + AllTranslations.parseEvoQuests( + localeCode, + AllPokemon.evolutionQuests, + ) } } }), @@ -202,12 +243,24 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} const localPokemon = localeCheck ? AllTranslations.masterfile.pokemon : AllPokemon.parsedPokeForms || AllPokemon.parsedPokemon - const localTypes = localeCheck ? AllTranslations.masterfile.types : AllTypes.parsedTypes - const localMoves = localeCheck ? AllTranslations.masterfile.moves : AllMoves.parsedMoves - const localForms = localeCheck ? AllTranslations.masterfile.forms : AllPokemon.parsedForms - const localItems = localeCheck ? AllTranslations.masterfile.items : AllItems.parsedItems - const localWeather = localeCheck ? AllTranslations.masterfile.weather : AllWeather.parsedWeather - const localEvolutionQuests = localeCheck ? AllTranslations.masterfile.evolutionQuests : AllPokemon.evolutionQuests + const localTypes = localeCheck + ? AllTranslations.masterfile.types + : AllTypes.parsedTypes + const localMoves = localeCheck + ? AllTranslations.masterfile.moves + : AllMoves.parsedMoves + const localForms = localeCheck + ? AllTranslations.masterfile.forms + : AllPokemon.parsedForms + const localItems = localeCheck + ? AllTranslations.masterfile.items + : AllItems.parsedItems + const localWeather = localeCheck + ? AllTranslations.masterfile.weather + : AllWeather.parsedWeather + const localEvolutionQuests = localeCheck + ? AllTranslations.masterfile.evolutionQuests + : AllPokemon.evolutionQuests if (pokemon.enabled) { final[pokemon.options.topLevelName || 'pokemon'] = raw @@ -242,7 +295,9 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} : AllPokemon.templater(AllPokemon.parsedCostumes, costumes) } if (items.enabled) { - final[items.options.topLevelName || 'items'] = raw ? localItems : AllItems.templater(localItems, items) + final[items.options.topLevelName || 'items'] = raw + ? localItems + : AllItems.templater(localItems, items) } if (moves.enabled) { final[moves.options.topLevelName || 'moves'] = raw @@ -277,7 +332,8 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} : AllWeather.templater(localWeather, weather, { types: localTypes }) } if (translations.enabled) { - final[translations.options.topLevelName || 'translations'] = AllTranslations.parsedTranslations + final[translations.options.topLevelName || 'translations'] = + AllTranslations.parsedTranslations } if (test && pokeApi === true) { final.AllPokeApi = AllPokeApi @@ -285,12 +341,19 @@ export async function generate({ template, url, raw, pokeApi, test }: Input = {} return final } -export async function invasions({ template }: InvasionsOnly = {}): Promise { +export async function invasions({ + template, +}: InvasionsOnly = {}): Promise { const finalTemplate = template || base.invasions const AllInvasions = new Invasions(finalTemplate.options) const invasionData: InvasionInfo = await AllInvasions.fetch( 'https://raw.githubusercontent.com/WatWowMap/event-info/main/grunts/classic.json', ) - AllInvasions.invasions(AllInvasions.mergeInvasions(invasionData, await AllInvasions.customInvasions(true))) + AllInvasions.invasions( + AllInvasions.mergeInvasions( + invasionData, + await AllInvasions.customInvasions(true), + ), + ) return AllInvasions.templater(AllInvasions.parsedInvasions, finalTemplate) } diff --git a/src/typings/inputs.ts b/src/typings/inputs.ts index 8987363..40afeff 100644 --- a/src/typings/inputs.ts +++ b/src/typings/inputs.ts @@ -325,7 +325,22 @@ export interface FullTemplate { } } -export type Locales = ['de', 'en', 'es', 'fr', 'hi', 'id', 'it', 'ja', 'ko', 'pt-br', 'ru', 'th', 'tr', 'zh-tw'] +export type Locales = [ + 'de', + 'en', + 'es', + 'fr', + 'hi', + 'id', + 'it', + 'ja', + 'ko', + 'pt-br', + 'ru', + 'th', + 'tr', + 'zh-tw', +] export interface InvasionsOnly { template?: { diff --git a/src/typings/protos.ts b/src/typings/protos.ts index bb42f22..c5e6a0a 100644 --- a/src/typings/protos.ts +++ b/src/typings/protos.ts @@ -1,6 +1,7 @@ import { Rpc } from 'pogo-protos' -export type WeatherProto = keyof typeof Rpc.GameplayWeatherProto.WeatherCondition +export type WeatherProto = + keyof typeof Rpc.GameplayWeatherProto.WeatherCondition export type CostumeProto = keyof typeof Rpc.PokemonDisplayProto.Costume @@ -24,6 +25,7 @@ export type QuestTypeProto = keyof typeof Rpc.QuestType export type QuestRewardProto = keyof typeof Rpc.QuestRewardProto.Type -export type QuestConditionProto = keyof typeof Rpc.QuestConditionProto.ConditionType +export type QuestConditionProto = + keyof typeof Rpc.QuestConditionProto.ConditionType export type ActivityProto = keyof typeof Rpc.HoloActivityType