[Beta][P3] Fix shiny Pokemon being displayed before shiny colours are loaded (#4843)
This commit is contained in:
parent
f2a2281ff1
commit
efa9f119a0
|
@ -442,7 +442,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
};
|
};
|
||||||
if (this.shiny) {
|
if (this.shiny) {
|
||||||
const populateVariantColors = (isBackSprite: boolean = false): Promise<void> => {
|
const populateVariantColors = (isBackSprite: boolean = false): Promise<void> => {
|
||||||
return new Promise(resolve => {
|
return new Promise(async resolve => {
|
||||||
const battleSpritePath = this.getBattleSpriteAtlasPath(isBackSprite, ignoreOverride).replace("variant/", "").replace(/_[1-3]$/, "");
|
const battleSpritePath = this.getBattleSpriteAtlasPath(isBackSprite, ignoreOverride).replace("variant/", "").replace(/_[1-3]$/, "");
|
||||||
let config = variantData;
|
let config = variantData;
|
||||||
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride));
|
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride));
|
||||||
|
@ -451,7 +451,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
if (variantSet && variantSet[this.variant] === 1) {
|
if (variantSet && variantSet[this.variant] === 1) {
|
||||||
const cacheKey = this.getBattleSpriteKey(isBackSprite);
|
const cacheKey = this.getBattleSpriteKey(isBackSprite);
|
||||||
if (!variantColorCache.hasOwnProperty(cacheKey)) {
|
if (!variantColorCache.hasOwnProperty(cacheKey)) {
|
||||||
this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
|
await this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -483,10 +483,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
* @param battleSpritePath the filename of the sprite
|
* @param battleSpritePath the filename of the sprite
|
||||||
* @param optionalParams any additional params to log
|
* @param optionalParams any additional params to log
|
||||||
*/
|
*/
|
||||||
fallbackVariantColor(cacheKey: string, attemptedSpritePath: string, useExpSprite: boolean, battleSpritePath: string, ...optionalParams: any[]) {
|
async fallbackVariantColor(cacheKey: string, attemptedSpritePath: string, useExpSprite: boolean, battleSpritePath: string, ...optionalParams: any[]) {
|
||||||
console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams);
|
console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams);
|
||||||
if (useExpSprite) {
|
if (useExpSprite) {
|
||||||
this.populateVariantColorCache(cacheKey, false, battleSpritePath);
|
await this.populateVariantColorCache(cacheKey, false, battleSpritePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,18 +497,20 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
* @param useExpSprite should the experimental sprite be used
|
* @param useExpSprite should the experimental sprite be used
|
||||||
* @param battleSpritePath the filename of the sprite
|
* @param battleSpritePath the filename of the sprite
|
||||||
*/
|
*/
|
||||||
populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
|
async populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
|
||||||
const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`;
|
const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`;
|
||||||
this.scene.cachedFetch(spritePath).then(res => {
|
return this.scene.cachedFetch(spritePath).then(res => {
|
||||||
// Prevent the JSON from processing if it failed to load
|
// Prevent the JSON from processing if it failed to load
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return this.fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
|
return this.fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
|
||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
|
return this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
|
||||||
}).then(c => {
|
}).then(c => {
|
||||||
|
if (!isNullOrUndefined(c)) {
|
||||||
variantColorCache[cacheKey] = c;
|
variantColorCache[cacheKey] = c;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue