mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-27 02:32:21 +02:00
Using default animation for errors that occur.
This commit is contained in:
parent
72439ffff7
commit
96aada282f
@ -488,14 +488,13 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise<void> {
|
||||
} else {
|
||||
moveAnims.set(move, null);
|
||||
const defaultMoveAnim = allMoves[move] instanceof AttackMove ? Moves.TACKLE : allMoves[move] instanceof SelfStatusMove ? Moves.FOCUS_ENERGY : Moves.TAIL_WHIP;
|
||||
const moveName = Moves[move].toLowerCase().replace(/\_/g, "-");
|
||||
|
||||
const fetchAnimAndResolve = (move: Moves) => {
|
||||
scene.cachedFetch(`./battle-anims/${moveName}.json`)
|
||||
scene.cachedFetch(`./battle-anims/${Utils.animationFileName(move)}.json`)
|
||||
.then(response => {
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (!response.ok || contentType?.indexOf("application/json") === -1) {
|
||||
console.error(`Could not load animation file for move '${moveName}'`, response.status, response.statusText);
|
||||
populateMoveAnim(move, moveAnims.get(defaultMoveAnim));
|
||||
useDefaultAnim(move, defaultMoveAnim, response.status, response.statusText);
|
||||
return resolve();
|
||||
}
|
||||
return response.json();
|
||||
@ -515,6 +514,10 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise<void> {
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
useDefaultAnim(move, defaultMoveAnim, error);
|
||||
return resolve();
|
||||
});
|
||||
};
|
||||
fetchAnimAndResolve(move);
|
||||
@ -522,6 +525,19 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the default animation for the given move.
|
||||
*
|
||||
* @param move the move to populate an animation for
|
||||
* @param defaultMoveAnim the default move to use as the default animation
|
||||
* @param optionalParams parameters to add to the error logging
|
||||
*/
|
||||
function useDefaultAnim(move: Moves, defaultMoveAnim: Moves, ...optionalParams: any[]) {
|
||||
const moveName = Utils.animationFileName(move);
|
||||
console.error(`Could not load animation file for move '${moveName}'`, ...optionalParams);
|
||||
populateMoveAnim(move, moveAnims.get(defaultMoveAnim));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches animation configs to be used in a Mystery Encounter
|
||||
* @param scene
|
||||
|
10
src/utils.ts
10
src/utils.ts
@ -1,4 +1,5 @@
|
||||
import { MoneyFormat } from "#enums/money-format";
|
||||
import { Moves } from "#enums/moves";
|
||||
import i18next from "i18next";
|
||||
|
||||
export const MissingTextureKey = "__MISSING";
|
||||
@ -628,3 +629,12 @@ export function getLocalizedSpriteKey(baseKey: string) {
|
||||
export function isBetween(num: number, min: number, max: number): boolean {
|
||||
return num >= min && num <= max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return the animation filename for a given move
|
||||
*
|
||||
* @param move the move for which the animation filename is needed
|
||||
*/
|
||||
export function animationFileName(move: Moves): string {
|
||||
return Moves[move].toLowerCase().replace(/\_/g, "-");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user