diff --git a/src/battle-scene.ts b/src/battle-scene.ts index e9d5a97ab8d0..9b578c1e9779 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -363,28 +363,30 @@ export default class BattleScene extends SceneBase { /** * Load the variant assets for the given sprite and stores them in {@linkcode variantColorCache} */ - loadPokemonVariantAssets(spriteKey: string, fileRoot: string, variant?: Variant) { + public async loadPokemonVariantAssets(spriteKey: string, fileRoot: string, variant?: Variant): Promise { const useExpSprite = this.experimentalSprites && this.hasExpSprite(spriteKey); if (useExpSprite) { fileRoot = `exp/${fileRoot}`; } let variantConfig = variantData; - fileRoot.split("/").map(p => variantConfig ? variantConfig = variantConfig[p] : null); + fileRoot.split("/").map((p) => (variantConfig ? (variantConfig = variantConfig[p]) : null)); const variantSet = variantConfig as VariantSet; - if (variantSet && (variant !== undefined && variantSet[variant] === 1)) { - const populateVariantColors = (key: string): Promise => { - return new Promise(resolve => { - if (variantColorCache.hasOwnProperty(key)) { - return resolve(); - } - this.cachedFetch(`./images/pokemon/variant/${fileRoot}.json`).then(res => res.json()).then(c => { - variantColorCache[key] = c; + + return new Promise((resolve) => { + if (variantSet && variant !== undefined && variantSet[variant] === 1) { + if (variantColorCache.hasOwnProperty(spriteKey)) { + return resolve(); + } + this.cachedFetch(`./images/pokemon/variant/${fileRoot}.json`) + .then((res) => res.json()) + .then((c) => { + variantColorCache[spriteKey] = c; resolve(); }); - }); - }; - populateVariantColors(spriteKey); - } + } else { + resolve(); + } + }); } async preload() { diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 285c2a702369..574c2a67f65b 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -516,8 +516,7 @@ export abstract class PokemonSpeciesForm { globalScene.anims.get(spriteKey).frameRate = 10; } const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant).replace("variant/", "").replace(/_[1-3]$/, ""); - globalScene.loadPokemonVariantAssets(spriteKey, spritePath, variant); - resolve(); + globalScene.loadPokemonVariantAssets(spriteKey, spritePath, variant).then(() => resolve()); }); if (startLoad) { if (!globalScene.load.isLoading()) { diff --git a/src/field/mystery-encounter-intro.ts b/src/field/mystery-encounter-intro.ts index 4fce9b1dfc9b..0110dabc7a9a 100644 --- a/src/field/mystery-encounter-intro.ts +++ b/src/field/mystery-encounter-intro.ts @@ -215,11 +215,12 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con resolve(); } + const shinyPromises: Promise[] = []; this.spriteConfigs.forEach((config) => { if (config.isPokemon) { globalScene.loadPokemonAtlas(config.spriteKey, config.fileRoot); if (config.isShiny) { - globalScene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant); + shinyPromises.push(globalScene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant)); } } else if (config.isItem) { globalScene.loadAtlas("items", ""); @@ -254,7 +255,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con return true; }); - resolve(); + Promise.all(shinyPromises).then(() => resolve()); }); if (!globalScene.load.isLoading()) {