From b68abaab9415ee97cfeef871c45c38cdb00faf85 Mon Sep 17 00:00:00 2001 From: ImperialSympathizer Date: Thu, 18 Jul 2024 16:01:47 -0400 Subject: [PATCH] cleanup and add jsdocs --- src/data/battle-anims.ts | 50 ++++++++++++------- .../encounters/safari-zone-encounter.ts | 14 +++--- .../slumbering-snorlax-encounter.ts | 40 ++++++++------- .../slumbering-snorlax-dialogue.ts | 41 +++++++-------- 4 files changed, 80 insertions(+), 65 deletions(-) diff --git a/src/data/battle-anims.ts b/src/data/battle-anims.ts index f832318fc4b..234e827b648 100644 --- a/src/data/battle-anims.ts +++ b/src/data/battle-anims.ts @@ -103,6 +103,11 @@ export enum CommonAnim { LOCK_ON = 2120 } +/** + * Animations used for Mystery Encounters + * These are custom animations that may or may not work in any other circumstance + * Use at your own risk + */ export enum EncounterAnim { MAGMA_BG, MAGMA_SPOUT @@ -520,23 +525,26 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise { }); } -export function initEncounterAnims(scene: BattleScene, anims: EncounterAnim | EncounterAnim[]): Promise { +/** + * Fetches animation configs to be used in a Mystery Encounter + * @param scene + * @param anims - one or more animations to fetch + */ +export async function initEncounterAnims(scene: BattleScene, anims: EncounterAnim | EncounterAnim[]): Promise { anims = anims instanceof Array ? anims : [anims]; - return new Promise(resolve => { - const encounterAnimNames = Utils.getEnumKeys(EncounterAnim); - const encounterAnimIds = Utils.getEnumValues(EncounterAnim); - const encounterAnimFetches = []; - for (const anim of anims) { - if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) { - continue; - } - const encounterAnimId = encounterAnimIds[anim]; - encounterAnimFetches.push(scene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`) - .then(response => response.json()) - .then(cas => encounterAnims.set(encounterAnimId, new AnimConfig(cas)))); + const encounterAnimNames = Utils.getEnumKeys(EncounterAnim); + const encounterAnimIds = Utils.getEnumValues(EncounterAnim); + const encounterAnimFetches = []; + for (const anim of anims) { + if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) { + continue; } - Promise.allSettled(encounterAnimFetches).then(() => resolve()); - }); + const encounterAnimId = encounterAnimIds[anim]; + encounterAnimFetches.push(scene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`) + .then(response => response.json()) + .then(cas => encounterAnims.set(encounterAnimId, new AnimConfig(cas)))); + } + await Promise.allSettled(encounterAnimFetches); } export function initMoveChargeAnim(scene: BattleScene, chargeAnim: ChargeAnim): Promise { @@ -593,10 +601,14 @@ export function loadCommonAnimAssets(scene: BattleScene, startLoad?: boolean): P }); } -export function loadEncounterAnimAssets(scene: BattleScene, startLoad?: boolean): Promise { - return new Promise(resolve => { - loadAnimAssets(scene, Array.from(encounterAnims.values()), startLoad).then(() => resolve()); - }); +/** + * Loads encounter animation assets to scene + * MUST be called after [initEncounterAnims()](./battle-anims.ts) to load all required animations properly + * @param scene + * @param startLoad + */ +export async function loadEncounterAnimAssets(scene: BattleScene, startLoad?: boolean): Promise { + await loadAnimAssets(scene, Array.from(encounterAnims.values()), startLoad); } export function loadMoveAnimAssets(scene: BattleScene, moveIds: Moves[], startLoad?: boolean): Promise { diff --git a/src/data/mystery-encounters/encounters/safari-zone-encounter.ts b/src/data/mystery-encounters/encounters/safari-zone-encounter.ts index ee0a161408a..164ac112596 100644 --- a/src/data/mystery-encounters/encounters/safari-zone-encounter.ts +++ b/src/data/mystery-encounters/encounters/safari-zone-encounter.ts @@ -19,6 +19,8 @@ import { getPokemonNameWithAffix } from "#app/messages"; /** the i18n namespace for the encounter */ const namespace = "mysteryEncounter:safariZone"; +const TRAINER_THROW_ANIMATION_TIMES = [512, 184, 768]; + /** * Safari Zone encounter. * @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/39 | GitHub Issue #39} @@ -314,14 +316,14 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(512, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { scene.playSound("pb_throw"); // Trainer throw frames scene.trainer.setFrame("2"); - scene.time.delayedCall(184, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { scene.trainer.setFrame("3"); - scene.time.delayedCall(768, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); }); }); @@ -380,14 +382,14 @@ async function throwMud(scene: BattleScene, pokemon: EnemyPokemon): Promise { scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(512, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { scene.playSound("pb_throw"); // Trainer throw frames scene.trainer.setFrame("2"); - scene.time.delayedCall(184, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { scene.trainer.setFrame("3"); - scene.time.delayedCall(768, () => { + scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); }); }); diff --git a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts index 0e60304d9dc..2efae68c9eb 100644 --- a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts +++ b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts @@ -16,16 +16,16 @@ import { getPokemonSpecies } from "#app/data/pokemon-species"; import { PartyHealPhase } from "#app/phases"; /** i18n namespace for the encounter */ -const namespace = "mysteryEncounter:sleeping_snorlax"; +const namespace = "mysteryEncounter:slumberingSnorlax"; /** * Sleeping Snorlax encounter. * @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/103 | GitHub Issue #103} * @see For biome requirements check [mysteryEncountersByBiome](../mystery-encounters.ts) */ -export const SleepingSnorlaxEncounter: IMysteryEncounter = +export const SlumberingSnorlaxEncounter: IMysteryEncounter = MysteryEncounterBuilder.withEncounterType( - MysteryEncounterType.SLEEPING_SNORLAX + MysteryEncounterType.SLUMBERING_SNORLAX ) .withEncounterTier(MysteryEncounterTier.GREAT) .withSceneWaveRangeRequirement(10, 180) // waves 10 to 180 @@ -44,7 +44,7 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter = ]) .withIntroDialogue([ { - text: `${namespace}_intro_message`, + text: `${namespace}:intro`, }, ]) .withOnInit((scene: BattleScene) => { @@ -70,16 +70,16 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter = return true; }) - .withTitle(`${namespace}_title`) - .withDescription(`${namespace}_description`) - .withQuery(`${namespace}_query`) + .withTitle(`${namespace}:title`) + .withDescription(`${namespace}:description`) + .withQuery(`${namespace}:query`) .withSimpleOption( { - buttonLabel: `${namespace}_option_1_label`, - buttonTooltip: `${namespace}_option_1_tooltip`, + buttonLabel: `${namespace}:option:1:label`, + buttonTooltip: `${namespace}:option:1:tooltip`, selected: [ { - text: `${namespace}_option_1_selected_message`, + text: `${namespace}:option:1:selected`, }, ], }, @@ -105,11 +105,11 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter = ) .withSimpleOption( { - buttonLabel: `${namespace}_option_2_label`, - buttonTooltip: `${namespace}_option_2_tooltip`, + buttonLabel: `${namespace}:option:2:label`, + buttonTooltip: `${namespace}:option:2:tooltip`, selected: [ { - text: `${namespace}_option_2_selected_message`, + text: `${namespace}:option:2:selected`, }, ], }, @@ -117,7 +117,7 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter = // Fall asleep waiting for Snorlax // Full heal party scene.unshiftPhase(new PartyHealPhase(scene, true)); - queueEncounterMessage(scene, `${namespace}_option_2_good_result`); + queueEncounterMessage(scene, `${namespace}:option:2:rest_result`); leaveEncounterWithoutBattle(scene); } ) @@ -126,15 +126,19 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter = .withOptionMode(EncounterOptionMode.DISABLED_OR_SPECIAL) .withPrimaryPokemonRequirement(new MoveRequirement(STEALING_MOVES)) .withDialogue({ - buttonLabel: `${namespace}_option_3_label`, - buttonTooltip: `${namespace}_option_3_tooltip`, - disabledButtonTooltip: `${namespace}_option_3_disabled_tooltip`, + buttonLabel: `${namespace}:option:3:label`, + buttonTooltip: `${namespace}:option:3:tooltip`, + disabledButtonTooltip: `${namespace}:option:3:disabled_tooltip`, + selected: [ + { + text: `${namespace}:option:3:selected` + } + ] }) .withOptionPhase(async (scene: BattleScene) => { // Steal the Snorlax's Leftovers const instance = scene.currentBattle.mysteryEncounter; setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: false }); - queueEncounterMessage(scene, `${namespace}_option_3_good_result`); // Snorlax exp to Pokemon that did the stealing setEncounterExp(scene, instance.primaryPokemon.id, getPokemonSpecies(Species.SNORLAX).baseExp); leaveEncounterWithoutBattle(scene); diff --git a/src/locales/en/mystery-encounters/slumbering-snorlax-dialogue.ts b/src/locales/en/mystery-encounters/slumbering-snorlax-dialogue.ts index bc2dc65e572..92244573c9b 100644 --- a/src/locales/en/mystery-encounters/slumbering-snorlax-dialogue.ts +++ b/src/locales/en/mystery-encounters/slumbering-snorlax-dialogue.ts @@ -1,31 +1,28 @@ -export const sleepingSnorlaxDialogue = { - intro: "Wandering aimlessly through the sea, you've effectively gotten nowhere.", - title: "Lost at Sea", - description: "The sea is turbulent in this area, and you're running out of energy.\nThis is bad. Is there a way out of the situation?", +export const slumberingSnorlaxDialogue = { + intro: `As you walk down a narrow pathway, you see a towering silhouette blocking your path. + $You get closer to see a Snorlax sleeping peacefully.\nIt seems like there's no way around it.`, + title: "Slumbering Snorlax", + description: "You could attack it to try and get it to move, or simply wait for it to wake up. Who knows how long that could take, though...", query: "What will you do?", option: { 1: { - label: "{{option1PrimaryName}} can help", - label_disabled: "Can't {{option1RequiredMove}}", - tooltip: "(+) {{option1PrimaryName}} saves you\n(+) {{option1PrimaryName}} gains some EXP", - tooltip_disabled: "You have no Pokémon to {{option1RequiredMove}} on", - selected: `{{option1PrimaryName}} swims ahead, guiding you back on track. - \${{option1PrimaryName}} seems to also have gotten stronger in this time of need!`, + label: "Battle it", + tooltip: "(-) Fight Sleeping Snorlax\n(+) Special Reward", + selected: "You approach the\nPokémon without fear.", }, 2: { - label: "{{option2PrimaryName}} can help", - label_disabled: "Can't {{option2RequiredMove}}", - tooltip: "(+) {{option2PrimaryName}} saves you\n(+) {{option2PrimaryName}} gains some EXP", - tooltip_disabled: "You have no Pokémon to {{option2RequiredMove}} with", - selected: `{{option2PrimaryName}} flies ahead of your boat, guiding you back on track. - \${{option2PrimaryName}} seems to also have gotten stronger in this time of need!`, + label: "Wait for it to move", + tooltip: "(-) Wait a Long Time\n(+) Recover Party", + selected: `.@d{32}.@d{32}.@d{32} + $You wait for a time, but the Snorlax's yawns make your party sleepy...`, + rest_result: "When you all awaken, the Snorlax is no where to be found -\nbut your Pokémon are all healed!", }, 3: { - label: "Wander aimlessly", - tooltip: "(-) Each of your Pokémon lose {{damagePercentage}}% of their total HP", - selected: `You float about in the boat, steering without direction until you finally spot a landmark you remember. - $You and your Pokémon are fatigued from the whole ordeal.`, + label: "Steal its item", + tooltip: "(+) {{option3PrimaryName}} uses {{option3PrimaryMove}}\n(+) Special Reward", + disabled_tooltip: "Your Pokémon need to know certain moves to choose this", + selected: `Your {{option3PrimaryName}} uses {{option3PrimaryMove}}! + $@s{item_fanfare}It steals Leftovers off the sleeping\nSnorlax and you make out like bandits!`, }, - }, - outro: "You are back on track." + } };