[Sprite] Fix game not waiting for variant data to finish loading (#5130)
Co-authored-by: Moka <millennium.stitcher@gmail.com> Co-authored-by: damocleas <damocleas25@gmail.com>
This commit is contained in:
parent
c3641a370f
commit
188664f389
|
@ -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<void> {
|
||||
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<void> => {
|
||||
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<void>((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() {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -215,11 +215,12 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con
|
|||
resolve();
|
||||
}
|
||||
|
||||
const shinyPromises: Promise<void>[] = [];
|
||||
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()) {
|
||||
|
|
Loading…
Reference in New Issue