Fix crash with certain animated variant sprites

This commit is contained in:
Flashfyre 2024-04-26 02:00:58 -04:00
parent b863ab88a7
commit ef552c7ffd
5 changed files with 212 additions and 6 deletions

View File

@ -1069,6 +1069,8 @@
"971", "971",
"972", "972",
"972", "972",
"973",
"973",
"974", "974",
"974", "974",
"975", "975",
@ -2201,6 +2203,8 @@
"971b", "971b",
"972b", "972b",
"972b", "972b",
"973b",
"973b",
"974b", "974b",
"974b", "974b",
"975b", "975b",
@ -3331,6 +3335,8 @@
"971sb", "971sb",
"972sb", "972sb",
"972sb", "972sb",
"973sb",
"973sb",
"974sb", "974sb",
"974sb", "974sb",
"975sb", "975sb",
@ -4468,6 +4474,8 @@
"971s", "971s",
"972s", "972s",
"972s", "972s",
"973s",
"973s",
"974s", "974s",
"974s", "974s",
"975s", "975s",
@ -4527,5 +4535,184 @@
"999s-roaming", "999s-roaming",
"999s-roaming", "999s-roaming",
"999s", "999s",
"999s" "999s",
"1000",
"1001",
"1004",
"181-mega",
"212-mega",
"282-mega_2",
"282-mega_2",
"282-mega_3",
"282-mega_3",
"303-mega",
"334-mega",
"334-mega_2",
"334-mega_2",
"376-mega",
"384-mega",
"384-mega_2",
"384-mega_2",
"4263",
"4264",
"428-mega",
"445-mega",
"448-mega",
"475-mega_2",
"475-mega_2",
"475-mega_3",
"475-mega_3",
"6549",
"6570",
"6571",
"6705",
"6706_2",
"6706_2",
"6706_3",
"6706_3",
"700",
"704",
"705_2",
"705_2",
"705_3",
"705_3",
"706",
"708",
"709",
"710",
"711",
"720-unbound",
"720",
"755",
"756",
"789",
"791_1",
"791_1",
"802",
"856",
"857_2",
"857_2",
"857_3",
"857_3",
"858",
"872",
"873",
"877-hangry",
"877",
"885",
"886",
"887",
"890_2",
"890_2",
"890_3",
"890_3",
"900",
"919",
"920",
"924",
"925-four",
"925-four_2",
"925-four_2",
"925-four_3",
"925-four_3",
"925-three",
"925-three_2",
"925-three_2",
"925-three_3",
"925-three_3",
"94-mega_1",
"94-mega_1",
"94-mega_2",
"94-mega_2",
"94-mega_3",
"94-mega_3",
"962",
"967",
"973",
"987",
"988",
"988_3",
"988_3",
"999",
"999_1",
"999_1",
"1000b",
"1001b",
"1004b",
"181b-mega",
"212b-mega",
"282b-mega",
"303b-mega",
"334b-mega",
"376b-mega",
"384b-mega",
"4263b",
"4264b",
"428b-mega",
"445b-mega",
"448b-mega",
"475b-mega_2",
"475b-mega_2",
"475b-mega_3",
"475b-mega_3",
"6549b",
"6570b",
"6571b",
"6705b",
"6706_2b",
"6706_2b",
"6706_3b",
"6706_3b",
"700b",
"704b",
"705b",
"706b",
"708b",
"709b",
"710b",
"711b",
"720b-unbound",
"720b",
"755b",
"756b",
"789b",
"791b",
"802b",
"856b",
"857_2b",
"857_2b",
"857_3b",
"857_3b",
"858b",
"872b",
"873b",
"877b-hangry",
"877b",
"885b",
"886b",
"887b",
"890b",
"900b",
"919b",
"920b",
"924b",
"925b-four",
"925b-four_2",
"925b-four_2",
"925b-four_3",
"925b-four_3",
"925b-three",
"925b-three_2",
"925b-three_2",
"925b-three_3",
"925b-three_3",
"94b-mega",
"962b",
"962_3b",
"962_3b",
"967b",
"973b",
"987b",
"988b",
"999b"
] ]

View File

@ -272,7 +272,7 @@ export default class BattleScene extends SceneBase {
populateAnims(); populateAnims();
await this.cachedFetch('./images/pokemon/variant/_masterlist.json').then(res => res.json()).then(v => Object.keys(v).forEach(k => variantData[k] = v[k])); await this.initVariantData();
} }
create() { create() {
@ -513,6 +513,21 @@ export default class BattleScene extends SceneBase {
}); });
} }
async initVariantData(): Promise<void> {
Object.keys(variantData).forEach(key => delete variantData[key]);
await this.cachedFetch('./images/pokemon/variant/_masterlist.json').then(res => res.json())
.then(v => {
Object.keys(v).forEach(k => variantData[k] = v[k]);
if (this.experimentalSprites) {
const expTree = variantData['exp'];
Object.keys(expTree).forEach(ek => {
variantData[ek] = expTree[ek];
});
}
Promise.resolve();
});
}
cachedFetch(url: string, init?: RequestInit): Promise<Response> { cachedFetch(url: string, init?: RequestInit): Promise<Response> {
const manifest = this.game['manifest']; const manifest = this.game['manifest'];
if (manifest) { if (manifest) {
@ -817,6 +832,9 @@ export default class BattleScene extends SceneBase {
} }
if (clearScene) { if (clearScene) {
// Reload variant data in case sprite set has changed
this.initVariantData();
this.fadeOutBgm(250, false); this.fadeOutBgm(250, false);
this.tweens.add({ this.tweens.add({
targets: [ this.uiContainer ], targets: [ this.uiContainer ],

View File

@ -312,12 +312,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
const battleSpritePath = this.getBattleSpriteAtlasPath(back, ignoreOverride).replace('variant/', '').replace(/_[1-3]$/, ''); const battleSpritePath = this.getBattleSpriteAtlasPath(back, ignoreOverride).replace('variant/', '').replace(/_[1-3]$/, '');
let variantSet: VariantSet; let variantSet: VariantSet;
let config = variantData; let config = variantData;
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(back, ignoreOverride));
battleSpritePath.split('/').map(p => config ? config = config[p] : null); battleSpritePath.split('/').map(p => config ? config = config[p] : null);
variantSet = config as VariantSet; variantSet = config as VariantSet;
if (variantSet && variantSet[this.variant] === 1) { if (variantSet && variantSet[this.variant] === 1) {
if (variantColorCache.hasOwnProperty(key)) if (variantColorCache.hasOwnProperty(key))
return resolve(); return resolve();
this.scene.cachedFetch(`./images/pokemon/variant/${battleSpritePath}.json`).then(res => res.json()).then(c => { this.scene.cachedFetch(`./images/pokemon/variant/${useExpSprite ? 'exp/' : ''}${battleSpritePath}.json`).then(res => res.json()).then(c => {
variantColorCache[key] = c; variantColorCache[key] = c;
resolve(); resolve();
}); });

View File

@ -48,7 +48,7 @@ export const settingOptions: SettingOptions = {
[Setting.Window_Type]: new Array(5).fill(null).map((_, i) => (i + 1).toString()), [Setting.Window_Type]: new Array(5).fill(null).map((_, i) => (i + 1).toString()),
[Setting.Tutorials]: [ 'Off', 'On' ], [Setting.Tutorials]: [ 'Off', 'On' ],
[Setting.Enable_Retries]: [ 'Off', 'On' ], [Setting.Enable_Retries]: [ 'Off', 'On' ],
[Setting.Sprite_Set]: [ 'Consistent', 'Prioritize Animation' ], [Setting.Sprite_Set]: [ 'Consistent', 'Mixed Animated' ],
[Setting.Move_Animations]: [ 'Off', 'On' ], [Setting.Move_Animations]: [ 'Off', 'On' ],
[Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ], [Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ],
[Setting.EXP_Gains_Speed]: [ 'Normal', 'Fast', 'Faster', 'Skip' ], [Setting.EXP_Gains_Speed]: [ 'Normal', 'Fast', 'Faster', 'Skip' ],
@ -83,7 +83,7 @@ export const settingDefaults: SettingDefaults = {
[Setting.Vibration]: 0 [Setting.Vibration]: 0
}; };
export const reloadSettings: Setting[] = [ Setting.UI_Theme, Setting.Language ]; export const reloadSettings: Setting[] = [ Setting.UI_Theme, Setting.Language, Setting.Sprite_Set ];
export function setSetting(scene: BattleScene, setting: Setting, value: integer): boolean { export function setSetting(scene: BattleScene, setting: Setting, value: integer): boolean {
switch (setting) { switch (setting) {

View File

@ -21,4 +21,4 @@ Get-ChildItem -Path '.\public\images\pokemon' -Recurse -Directory | Where-Object
} }
} }
$keys | ConvertTo-Json | Out-File -encoding ASCII .\public\exp_sprites.json $keys | ConvertTo-Json | Out-File -encoding ASCII .\public\exp-sprites.json