Fix move animation defaults not working (fixes Tackle crash)

This commit is contained in:
Flashfyre 2024-04-04 09:45:25 -04:00
parent 6c59ed27ce
commit aa421b5d10
2 changed files with 8 additions and 8 deletions

View File

@ -429,10 +429,12 @@ export default class BattleScene extends SceneBase {
ui.setup();
const defaultMoves = [ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ];
Promise.all([
Promise.all(loadPokemonAssets),
initCommonAnims().then(() => loadCommonAnimAssets(this, true)),
initMoveAnim(Moves.STRUGGLE).then(() => loadMoveAnimAssets(this, [ Moves.STRUGGLE ], true))
Promise.all([ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ].map(m => initMoveAnim(m))).then(() => loadMoveAnimAssets(this, defaultMoves, true))
]).then(() => {
this.pushPhase(new LoginPhase(this));
this.pushPhase(new TitlePhase(this));

View File

@ -455,16 +455,14 @@ export function initMoveAnim(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) => {
fetch(`./battle-anims/${Moves[move].toLowerCase().replace(/\_/g, '-')}.json`)
fetch(`./battle-anims/${moveName}.json`)
.then(response => {
if (!response.ok) {
console.error(response.status, response.statusText);
if (move !== defaultMoveAnim)
fetchAnimAndResolve(defaultMoveAnim);
else
resolve();
return;
console.error(`Could not load animation file for move '${moveName}'`, response.status, response.statusText);
populateMoveAnim(move, moveAnims.get(defaultMoveAnim));
return resolve();
}
return response.json();
})