Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P3][Beta] Fix shiny Pokemon being displayed before shiny colours are loaded #4843

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
};
if (this.shiny) {
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]$/, "");
let config = variantData;
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride));
Expand All @@ -451,7 +451,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
if (variantSet && variantSet[this.variant] === 1) {
const cacheKey = this.getBattleSpriteKey(isBackSprite);
if (!variantColorCache.hasOwnProperty(cacheKey)) {
this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
await this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
}
}
resolve();
Expand Down Expand Up @@ -483,10 +483,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @param battleSpritePath the filename of the sprite
* @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);
if (useExpSprite) {
this.populateVariantColorCache(cacheKey, false, battleSpritePath);
await this.populateVariantColorCache(cacheKey, false, battleSpritePath);
}
}

Expand All @@ -497,18 +497,20 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @param useExpSprite should the experimental sprite be used
* @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`;
this.scene.cachedFetch(spritePath).then(res => {
return this.scene.cachedFetch(spritePath).then(res => {
// Prevent the JSON from processing if it failed to load
if (!res.ok) {
return this.fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
}
return res.json();
}).catch(error => {
this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
return this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
}).then(c => {
variantColorCache[cacheKey] = c;
if (!isNullOrUndefined(c)) {
variantColorCache[cacheKey] = c;
}
});
}

Expand Down
Loading