[Enhancement] Remove unnecessary loading of trainer sprites in loading scene (#4397)

* Remove unnecessary loading of trainer sprites in loading scene

* load trainer assets on demand for run history UI

---------

Co-authored-by: ImperialSympathizer <imperialsympathizer@gmail.com>
This commit is contained in:
ImperialSympathizer 2024-09-23 17:34:47 -04:00 committed by GitHub
parent eb264cffee
commit 23f006bc43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 29 deletions

View File

@ -1,5 +1,4 @@
import { GachaType } from "./enums/gacha-types"; import { GachaType } from "./enums/gacha-types";
import { trainerConfigs } from "./data/trainer-config";
import { getBiomeHasProps } from "./field/arena"; import { getBiomeHasProps } from "./field/arena";
import CacheBustedLoaderPlugin from "./plugins/cache-busted-loader-plugin"; import CacheBustedLoaderPlugin from "./plugins/cache-busted-loader-plugin";
import { SceneBase } from "./scene-base"; import { SceneBase } from "./scene-base";
@ -21,7 +20,6 @@ import i18next from "i18next";
import { initStatsKeys } from "./ui/game-stats-ui-handler"; import { initStatsKeys } from "./ui/game-stats-ui-handler";
import { initVouchers } from "./system/voucher"; import { initVouchers } from "./system/voucher";
import { Biome } from "#enums/biome"; import { Biome } from "#enums/biome";
import { TrainerType } from "#enums/trainer-type";
import {initMysteryEncounters} from "#app/data/mystery-encounters/mystery-encounters"; import {initMysteryEncounters} from "#app/data/mystery-encounters/mystery-encounters";
export class LoadingScene extends SceneBase { export class LoadingScene extends SceneBase {
@ -208,14 +206,6 @@ export class LoadingScene extends SceneBase {
this.loadAtlas("trainer_f_back", "trainer"); this.loadAtlas("trainer_f_back", "trainer");
this.loadAtlas("trainer_f_back_pb", "trainer"); this.loadAtlas("trainer_f_back_pb", "trainer");
Utils.getEnumValues(TrainerType).map(tt => {
const config = trainerConfigs[tt];
this.loadAtlas(config.getSpriteKey(), "trainer");
if (config.doubleOnly || config.hasDouble) {
this.loadAtlas(config.getSpriteKey(true), "trainer");
}
});
// Load character sprites // Load character sprites
this.loadAtlas("c_rival_m", "character", "rival_m"); this.loadAtlas("c_rival_m", "character", "rival_m");
this.loadAtlas("c_rival_f", "character", "rival_f"); this.loadAtlas("c_rival_f", "character", "rival_f");

View File

@ -288,25 +288,29 @@ export default class RunInfoUiHandler extends UiHandler {
private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) { private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) {
// Creating the trainer sprite and adding it to enemyContainer // Creating the trainer sprite and adding it to enemyContainer
const tObj = this.runInfo.trainer.toTrainer(this.scene); const tObj = this.runInfo.trainer.toTrainer(this.scene);
const tObjSpriteKey = tObj.config.getSpriteKey(this.runInfo.trainer.variant === TrainerVariant.FEMALE, false);
const tObjSprite = this.scene.add.sprite(0, 5, tObjSpriteKey); // Loads trainer assets on demand, as they are not loaded by default in the scene
if (this.runInfo.trainer.variant === TrainerVariant.DOUBLE) { tObj.config.loadAssets(this.scene, this.runInfo.trainer.variant).then(() => {
const doubleContainer = this.scene.add.container(5, 8); const tObjSpriteKey = tObj.config.getSpriteKey(this.runInfo.trainer.variant === TrainerVariant.FEMALE, false);
tObjSprite.setPosition(-3, -3); const tObjSprite = this.scene.add.sprite(0, 5, tObjSpriteKey);
const tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true); if (this.runInfo.trainer.variant === TrainerVariant.DOUBLE) {
const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey); const doubleContainer = this.scene.add.container(5, 8);
// Double Trainers have smaller sprites than Single Trainers tObjSprite.setPosition(-3, -3);
tObjPartnerSprite.setScale(0.20); const tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true);
tObjSprite.setScale(0.20); const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey);
doubleContainer.add(tObjSprite); // Double Trainers have smaller sprites than Single Trainers
doubleContainer.add(tObjPartnerSprite); tObjPartnerSprite.setScale(0.20);
doubleContainer.setPosition(12, 38); tObjSprite.setScale(0.20);
enemyContainer.add(doubleContainer); doubleContainer.add(tObjSprite);
} else { doubleContainer.add(tObjPartnerSprite);
tObjSprite.setScale(0.35, 0.35); doubleContainer.setPosition(12, 38);
tObjSprite.setPosition(12, 28); enemyContainer.add(doubleContainer);
enemyContainer.add(tObjSprite); } else {
} tObjSprite.setScale(0.35, 0.35);
tObjSprite.setPosition(12, 28);
enemyContainer.add(tObjSprite);
}
});
// Determining which Terastallize Modifier belongs to which Pokemon // Determining which Terastallize Modifier belongs to which Pokemon
// Creates a dictionary {PokemonId: TeraShardType} // Creates a dictionary {PokemonId: TeraShardType}