mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-20 06:19:29 +02:00
make loading variant assets cleaner
This commit is contained in:
parent
9fe58c52e2
commit
4bc3e6e49c
@ -47,7 +47,7 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container";
|
|||||||
import { biomeDepths, getBiomeName } from "#app/data/balance/biomes";
|
import { biomeDepths, getBiomeName } from "#app/data/balance/biomes";
|
||||||
import { SceneBase } from "#app/scene-base";
|
import { SceneBase } from "#app/scene-base";
|
||||||
import CandyBar from "#app/ui/candy-bar";
|
import CandyBar from "#app/ui/candy-bar";
|
||||||
import { Variant, variantData } from "#app/data/variant";
|
import { Variant, variantColorCache, variantData, VariantSet } from "#app/data/variant";
|
||||||
import { Localizable } from "#app/interfaces/locales";
|
import { Localizable } from "#app/interfaces/locales";
|
||||||
import Overrides from "#app/overrides";
|
import Overrides from "#app/overrides";
|
||||||
import { InputsController } from "#app/inputs-controller";
|
import { InputsController } from "#app/inputs-controller";
|
||||||
@ -345,6 +345,33 @@ export default class BattleScene extends SceneBase {
|
|||||||
this.load.atlas(key, `images/pokemon/${variant ? "variant/" : ""}${experimental ? "exp/" : ""}${atlasPath}.png`, `images/pokemon/${variant ? "variant/" : ""}${experimental ? "exp/" : ""}${atlasPath}.json`);
|
this.load.atlas(key, `images/pokemon/${variant ? "variant/" : ""}${experimental ? "exp/" : ""}${atlasPath}.png`, `images/pokemon/${variant ? "variant/" : ""}${experimental ? "exp/" : ""}${atlasPath}.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the variant assets for the given sprite and stores them in {@linkcode variantColorCache}
|
||||||
|
*/
|
||||||
|
loadPokemonVariantAssets(spriteKey: string, fileRoot: string, variant?: Variant) {
|
||||||
|
const useExpSprite = this.experimentalSprites && this.hasExpSprite(spriteKey);
|
||||||
|
if (useExpSprite) {
|
||||||
|
fileRoot = `exp/${fileRoot}`;
|
||||||
|
}
|
||||||
|
let variantConfig = variantData;
|
||||||
|
fileRoot.split("/").map(p => variantConfig ? variantConfig = variantConfig[p] : null);
|
||||||
|
const variantSet = variantConfig as VariantSet;
|
||||||
|
if (variantSet && (variant !== undefined && variantSet[variant] === 1)) {
|
||||||
|
const populateVariantColors = (key: string): Promise<void> => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (variantColorCache.hasOwnProperty(key)) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
this.cachedFetch(`./images/pokemon/variant/${fileRoot}.json`).then(res => res.json()).then(c => {
|
||||||
|
variantColorCache[key] = c;
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
populateVariantColors(spriteKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async preload() {
|
async preload() {
|
||||||
if (DEBUG_RNG) {
|
if (DEBUG_RNG) {
|
||||||
const scene = this;
|
const scene = this;
|
||||||
|
@ -15,7 +15,7 @@ import { EvolutionLevel, SpeciesWildEvolutionDelay, pokemonEvolutions, pokemonPr
|
|||||||
import { Type } from "#enums/type";
|
import { Type } from "#enums/type";
|
||||||
import { LevelMoves, pokemonFormLevelMoves, pokemonFormLevelMoves as pokemonSpeciesFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves";
|
import { LevelMoves, pokemonFormLevelMoves, pokemonFormLevelMoves as pokemonSpeciesFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves";
|
||||||
import { Stat } from "#enums/stat";
|
import { Stat } from "#enums/stat";
|
||||||
import { Variant, VariantSet, variantColorCache, variantData } from "#app/data/variant";
|
import { Variant, VariantSet, variantData } from "#app/data/variant";
|
||||||
import { speciesStarterCosts, POKERUS_STARTER_COUNT } from "#app/data/balance/starters";
|
import { speciesStarterCosts, POKERUS_STARTER_COUNT } from "#app/data/balance/starters";
|
||||||
import { SpeciesFormKey } from "#enums/species-form-key";
|
import { SpeciesFormKey } from "#enums/species-form-key";
|
||||||
|
|
||||||
@ -505,29 +505,8 @@ export abstract class PokemonSpeciesForm {
|
|||||||
} else {
|
} else {
|
||||||
scene.anims.get(spriteKey).frameRate = 12;
|
scene.anims.get(spriteKey).frameRate = 12;
|
||||||
}
|
}
|
||||||
let spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant).replace("variant/", "").replace(/_[1-3]$/, "");
|
const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant).replace("variant/", "").replace(/_[1-3]$/, "");
|
||||||
const useExpSprite = scene.experimentalSprites && scene.hasExpSprite(spriteKey);
|
scene.loadPokemonVariantAssets(spriteKey, spritePath, variant);
|
||||||
if (useExpSprite) {
|
|
||||||
spritePath = `exp/${spritePath}`;
|
|
||||||
}
|
|
||||||
let config = variantData;
|
|
||||||
spritePath.split("/").map(p => config ? config = config[p] : null);
|
|
||||||
const variantSet = config as VariantSet;
|
|
||||||
if (variantSet && (variant !== undefined && variantSet[variant] === 1)) {
|
|
||||||
const populateVariantColors = (key: string): Promise<void> => {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (variantColorCache.hasOwnProperty(key)) {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
scene.cachedFetch(`./images/pokemon/variant/${spritePath}.json`).then(res => res.json()).then(c => {
|
|
||||||
variantColorCache[key] = c;
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
populateVariantColors(spriteKey).then(() => resolve());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
if (startLoad) {
|
if (startLoad) {
|
||||||
|
@ -5,7 +5,7 @@ import { Species } from "#enums/species";
|
|||||||
import { isNullOrUndefined } from "#app/utils";
|
import { isNullOrUndefined } from "#app/utils";
|
||||||
import { getSpriteKeysFromSpecies } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils";
|
import { getSpriteKeysFromSpecies } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils";
|
||||||
import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig;
|
import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig;
|
||||||
import { Variant, variantColorCache, variantData, VariantSet } from "#app/data/variant";
|
import { Variant } from "#app/data/variant";
|
||||||
import { doShinySparkleAnim } from "#app/field/anims";
|
import { doShinySparkleAnim } from "#app/field/anims";
|
||||||
|
|
||||||
type KnownFileRoot =
|
type KnownFileRoot =
|
||||||
@ -61,8 +61,9 @@ export class MysteryEncounterSpriteConfig {
|
|||||||
scale?: number;
|
scale?: number;
|
||||||
/** If you are using a Pokemon sprite, set to `true`. This will ensure variant, form, gender, shiny sprites are loaded properly */
|
/** If you are using a Pokemon sprite, set to `true`. This will ensure variant, form, gender, shiny sprites are loaded properly */
|
||||||
isPokemon?: boolean;
|
isPokemon?: boolean;
|
||||||
//TODO
|
/** If using a Pokemon shiny sprite, needs to be set to ensure the correct variant assets get loaded and displayed */
|
||||||
isShiny?: boolean;
|
isShiny?: boolean;
|
||||||
|
/** If using a Pokemon shiny sprite, needs to be set to ensure the correct variant assets get loaded and displayed */
|
||||||
variant?: Variant;
|
variant?: Variant;
|
||||||
/** If you are using an item sprite, set to `true` */
|
/** If you are using an item sprite, set to `true` */
|
||||||
isItem?: boolean;
|
isItem?: boolean;
|
||||||
@ -219,29 +220,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con
|
|||||||
if (config.isPokemon) {
|
if (config.isPokemon) {
|
||||||
this.scene.loadPokemonAtlas(config.spriteKey, config.fileRoot);
|
this.scene.loadPokemonAtlas(config.spriteKey, config.fileRoot);
|
||||||
if (config.isShiny) {
|
if (config.isShiny) {
|
||||||
// Load variant assets
|
this.scene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant);
|
||||||
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(config.spriteKey);
|
|
||||||
if (useExpSprite) {
|
|
||||||
config.fileRoot = `exp/${config.fileRoot}`;
|
|
||||||
}
|
|
||||||
let variantConfig = variantData;
|
|
||||||
config.fileRoot.split("/").map(p => variantConfig ? variantConfig = variantConfig[p] : null);
|
|
||||||
const variantSet = variantConfig as VariantSet;
|
|
||||||
if (variantSet && (config.variant !== undefined && variantSet[config.variant] === 1)) {
|
|
||||||
const populateVariantColors = (key: string): Promise<void> => {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (variantColorCache.hasOwnProperty(key)) {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
this.scene.cachedFetch(`./images/pokemon/variant/${config.fileRoot}.json`).then(res => res.json()).then(c => {
|
|
||||||
variantColorCache[key] = c;
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
populateVariantColors(config.spriteKey);
|
|
||||||
}
|
|
||||||
// TODO load shiny sparkle?
|
|
||||||
}
|
}
|
||||||
} else if (config.isItem) {
|
} else if (config.isItem) {
|
||||||
this.scene.loadAtlas("items", "");
|
this.scene.loadAtlas("items", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user