move variant.ts and update pokemon.loadAssets
This commit is contained in:
parent
7b98d1b78c
commit
767a2a39de
|
@ -106,8 +106,8 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container";
|
|||
import { biomeDepths, getBiomeName } from "#app/data/balance/biomes";
|
||||
import { SceneBase } from "#app/scene-base";
|
||||
import CandyBar from "#app/ui/candy-bar";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import { variantData, clearVariantData } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { variantData, clearVariantData } from "#app/sprites/variant";
|
||||
import type { Localizable } from "#app/interfaces/locales";
|
||||
import Overrides from "#app/overrides";
|
||||
import { InputsController } from "#app/inputs-controller";
|
||||
|
|
|
@ -58,7 +58,7 @@ import { BattleEndPhase } from "#app/phases/battle-end-phase";
|
|||
import { GameOverPhase } from "#app/phases/game-over-phase";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import { PartyExpPhase } from "#app/phases/party-exp-phase";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { StatusEffect } from "#enums/status-effect";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { getPokemonSpecies } from "#app/data/pokemon-species";
|
||||
|
|
|
@ -26,8 +26,8 @@ import {
|
|||
pokemonSpeciesLevelMoves,
|
||||
} from "#app/data/balance/pokemon-level-moves";
|
||||
import type { Stat } from "#enums/stat";
|
||||
import type { Variant, VariantSet } from "#app/data/variant";
|
||||
import { variantData } from "#app/data/variant";
|
||||
import type { Variant, VariantSet } from "#app/sprites/variant";
|
||||
import { variantData } from "#app/sprites/variant";
|
||||
import { speciesStarterCosts, POKERUS_STARTER_COUNT } from "#app/data/balance/starters";
|
||||
import { SpeciesFormKey } from "#enums/species-form-key";
|
||||
import { starterPassiveAbilities } from "#app/data/balance/passives";
|
||||
|
@ -589,18 +589,19 @@ export abstract class PokemonSpeciesForm {
|
|||
return true;
|
||||
}
|
||||
|
||||
loadAssets(
|
||||
async loadAssets(
|
||||
female: boolean,
|
||||
formIndex?: number,
|
||||
shiny?: boolean,
|
||||
shiny = false,
|
||||
variant?: Variant,
|
||||
startLoad?: boolean,
|
||||
back?: boolean,
|
||||
): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant, back);
|
||||
globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant, back));
|
||||
globalScene.load.audio(`${this.getCryKey(formIndex)}`, `audio/${this.getCryKey(formIndex)}.m4a`);
|
||||
startLoad = false,
|
||||
back = false,
|
||||
) {
|
||||
const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant, back);
|
||||
globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant, back));
|
||||
globalScene.load.audio(this.getCryKey(formIndex), `audio/${this.getCryKey(formIndex)}.m4a`);
|
||||
|
||||
return new Promise<void>(resolve => {
|
||||
globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => {
|
||||
const originalWarn = console.warn;
|
||||
// Ignore warnings for missing frames, because there will be a lot
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
import { VariantTier } from "#app/enums/variant-tier";
|
||||
|
||||
export type Variant = 0 | 1 | 2;
|
||||
|
||||
export type VariantSet = [Variant, Variant, Variant];
|
||||
|
||||
export const variantData: any = {};
|
||||
|
||||
export const variantColorCache = {};
|
||||
|
||||
export function getVariantTint(variant: Variant): number {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return 0xf8c020;
|
||||
case 1:
|
||||
return 0x20f8f0;
|
||||
case 2:
|
||||
return 0xe81048;
|
||||
}
|
||||
}
|
||||
|
||||
export function getVariantIcon(variant: Variant): number {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return VariantTier.STANDARD;
|
||||
case 1:
|
||||
return VariantTier.RARE;
|
||||
case 2:
|
||||
return VariantTier.EPIC;
|
||||
}
|
||||
}
|
||||
|
||||
/** Delete all of the keys in variantData */
|
||||
export function clearVariantData() {
|
||||
for (const key in variantData) {
|
||||
delete variantData[key];
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the variant data to use experiment sprite files for variants that have experimental sprites. */
|
||||
export async function mergeExperimentalData(mainData: any, expData: any) {
|
||||
if (!expData) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const key of Object.keys(expData)) {
|
||||
if (typeof expData[key] === "object" && !Array.isArray(expData[key])) {
|
||||
// If the value is an object, recursively merge.
|
||||
if (!mainData[key]) {
|
||||
mainData[key] = {};
|
||||
}
|
||||
this.mergeExperimentalData(mainData[key], expData[key]);
|
||||
} else {
|
||||
// Otherwise, replace the value
|
||||
mainData[key] = expData[key];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { globalScene } from "#app/global-scene";
|
||||
import { PokeballType } from "#enums/pokeball";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { getFrameMs, randGauss } from "#app/utils";
|
||||
|
||||
export function addPokeballOpenParticles(x: number, y: number, pokeballType: PokeballType): void {
|
||||
|
|
|
@ -4,7 +4,7 @@ import type MysteryEncounter from "#app/data/mystery-encounters/mystery-encounte
|
|||
import type { Species } from "#enums/species";
|
||||
import { isNullOrUndefined } from "#app/utils";
|
||||
import { getSpriteKeysFromSpecies } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { doShinySparkleAnim } from "#app/field/anims";
|
||||
import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig;
|
||||
import { loadPokemonVariantAssets } from "#app/sprites/pokemon-sprite";
|
||||
|
|
|
@ -2,9 +2,9 @@ import Phaser from "phaser";
|
|||
import type { AnySound } from "#app/battle-scene";
|
||||
import type BattleScene from "#app/battle-scene";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import type { Variant, VariantSet } from "#app/data/variant";
|
||||
import { variantColorCache } from "#app/data/variant";
|
||||
import { variantData } from "#app/data/variant";
|
||||
import type { Variant, VariantSet } from "#app/sprites/variant";
|
||||
import { populateVariantColors, variantColorCache } from "#app/sprites/variant";
|
||||
import { variantData } from "#app/sprites/variant";
|
||||
import BattleInfo, {
|
||||
PlayerBattleInfo,
|
||||
EnemyBattleInfo,
|
||||
|
@ -265,6 +265,7 @@ import { doShinySparkleAnim } from "#app/field/anims";
|
|||
import { MoveFlags } from "#enums/MoveFlags";
|
||||
import { hasExpSprite } from "#app/sprites/sprite-utilts";
|
||||
import { timedEventManager } from "#app/global-event-manager";
|
||||
import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader";
|
||||
import { ResetStatusPhase } from "#app/phases/reset-status-phase";
|
||||
|
||||
export enum LearnMoveSituation {
|
||||
|
@ -697,115 +698,79 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||
|
||||
abstract getBattlerIndex(): BattlerIndex;
|
||||
|
||||
loadAssets(ignoreOverride = true): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
const moveIds = this.getMoveset().map(m => m.getMove().id);
|
||||
Promise.allSettled(moveIds.map(m => initMoveAnim(m))).then(() => {
|
||||
loadMoveAnimAssets(moveIds);
|
||||
this.getSpeciesForm().loadAssets(
|
||||
this.getGender() === Gender.FEMALE,
|
||||
this.formIndex,
|
||||
this.shiny,
|
||||
this.variant,
|
||||
);
|
||||
if (this.isPlayer() || this.getFusionSpeciesForm()) {
|
||||
globalScene.loadPokemonAtlas(
|
||||
this.getBattleSpriteKey(true, ignoreOverride),
|
||||
this.getBattleSpriteAtlasPath(true, ignoreOverride),
|
||||
);
|
||||
}
|
||||
if (this.getFusionSpeciesForm()) {
|
||||
this.getFusionSpeciesForm().loadAssets(
|
||||
this.getFusionGender() === Gender.FEMALE,
|
||||
this.fusionFormIndex,
|
||||
this.fusionShiny,
|
||||
this.fusionVariant,
|
||||
);
|
||||
globalScene.loadPokemonAtlas(
|
||||
this.getFusionBattleSpriteKey(true, ignoreOverride),
|
||||
this.getFusionBattleSpriteAtlasPath(true, ignoreOverride),
|
||||
);
|
||||
}
|
||||
globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => {
|
||||
if (this.isPlayer()) {
|
||||
const originalWarn = console.warn;
|
||||
// Ignore warnings for missing frames, because there will be a lot
|
||||
console.warn = () => {};
|
||||
const battleFrameNames = globalScene.anims.generateFrameNames(
|
||||
this.getBattleSpriteKey(),
|
||||
{ zeroPad: 4, suffix: ".png", start: 1, end: 400 },
|
||||
);
|
||||
console.warn = originalWarn;
|
||||
if (!globalScene.anims.exists(this.getBattleSpriteKey())) {
|
||||
globalScene.anims.create({
|
||||
key: this.getBattleSpriteKey(),
|
||||
frames: battleFrameNames,
|
||||
frameRate: 10,
|
||||
repeat: -1,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.playAnim();
|
||||
const updateFusionPaletteAndResolve = () => {
|
||||
this.updateFusionPalette();
|
||||
if (this.summonData?.speciesForm) {
|
||||
this.updateFusionPalette(true);
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
if (this.shiny) {
|
||||
const populateVariantColors = (
|
||||
isBackSprite = false,
|
||||
): Promise<void> => {
|
||||
return new Promise(async resolve => {
|
||||
const battleSpritePath = this.getBattleSpriteAtlasPath(
|
||||
isBackSprite,
|
||||
ignoreOverride,
|
||||
)
|
||||
.replace("variant/", "")
|
||||
.replace(/_[1-3]$/, "");
|
||||
let config = variantData;
|
||||
const useExpSprite =
|
||||
globalScene.experimentalSprites &&
|
||||
hasExpSprite(
|
||||
this.getBattleSpriteKey(isBackSprite, ignoreOverride),
|
||||
);
|
||||
battleSpritePath
|
||||
.split("/")
|
||||
.map(p => (config ? (config = config[p]) : null));
|
||||
const variantSet: VariantSet = config as VariantSet;
|
||||
if (variantSet && variantSet[this.variant] === 1) {
|
||||
const cacheKey = this.getBattleSpriteKey(isBackSprite);
|
||||
if (!variantColorCache.hasOwnProperty(cacheKey)) {
|
||||
await this.populateVariantColorCache(
|
||||
cacheKey,
|
||||
useExpSprite,
|
||||
battleSpritePath,
|
||||
);
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
if (this.isPlayer()) {
|
||||
Promise.all([
|
||||
populateVariantColors(false),
|
||||
populateVariantColors(true),
|
||||
]).then(() => updateFusionPaletteAndResolve());
|
||||
} else {
|
||||
populateVariantColors(false).then(() =>
|
||||
updateFusionPaletteAndResolve(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
updateFusionPaletteAndResolve();
|
||||
}
|
||||
});
|
||||
if (!globalScene.load.isLoading()) {
|
||||
globalScene.load.start();
|
||||
}
|
||||
async loadAssets(ignoreOverride = true) {
|
||||
/** Promises that are loading assets and can be run concurrently. */
|
||||
const loadPromises: Promise<void>[] = [];
|
||||
// Assets for moves
|
||||
loadPromises.push(loadMoveAnimations(this.getMoveset().map(m => m.getMove().id)));
|
||||
|
||||
// Load the assets for the species form
|
||||
loadPromises.push(
|
||||
this.getSpeciesForm().loadAssets(this.getGender() === Gender.FEMALE, this.formIndex, this.shiny, this.variant),
|
||||
);
|
||||
|
||||
if (this.isPlayer() || this.getFusionSpeciesForm()) {
|
||||
globalScene.loadPokemonAtlas(
|
||||
this.getBattleSpriteKey(true, ignoreOverride),
|
||||
this.getBattleSpriteAtlasPath(true, ignoreOverride),
|
||||
);
|
||||
}
|
||||
if (this.getFusionSpeciesForm()) {
|
||||
loadPromises.push(this.getFusionSpeciesForm().loadAssets(
|
||||
this.getFusionGender() === Gender.FEMALE,
|
||||
this.fusionFormIndex,
|
||||
this.fusionShiny,
|
||||
this.fusionVariant,
|
||||
));
|
||||
globalScene.loadPokemonAtlas(
|
||||
this.getFusionBattleSpriteKey(true, ignoreOverride),
|
||||
this.getFusionBattleSpriteAtlasPath(true, ignoreOverride),
|
||||
);
|
||||
}
|
||||
|
||||
if (this.shiny) {
|
||||
loadPromises.push(populateVariantColors(this, false, ignoreOverride))
|
||||
if (this.isPlayer()) {
|
||||
loadPromises.push(populateVariantColors(this, true, ignoreOverride));
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.allSettled(loadPromises);
|
||||
|
||||
// Wait for the assets we queued to load to finish loading, then...
|
||||
if (!globalScene.load.isLoading()) {
|
||||
globalScene.load.start();
|
||||
}
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#creating_a_promise_around_an_old_callback_api
|
||||
await new Promise(resolve => globalScene.load.once(Phaser.Loader.Events.COMPLETE, resolve));
|
||||
|
||||
// With the sprites loaded, generate the animation frame information
|
||||
if (this.isPlayer()) {
|
||||
const originalWarn = console.warn;
|
||||
// Ignore warnings for missing frames, because there will be a lot
|
||||
console.warn = () => {};
|
||||
const battleFrameNames = globalScene.anims.generateFrameNames(this.getBattleSpriteKey(), {
|
||||
zeroPad: 4,
|
||||
suffix: ".png",
|
||||
start: 1,
|
||||
end: 400,
|
||||
});
|
||||
});
|
||||
console.warn = originalWarn;
|
||||
globalScene.anims.create({
|
||||
key: this.getBattleSpriteKey(),
|
||||
frames: battleFrameNames,
|
||||
frameRate: 10,
|
||||
repeat: -1,
|
||||
});
|
||||
}
|
||||
// With everything loaded, now begin playing the animation.
|
||||
this.playAnim();
|
||||
|
||||
// update the fusion palette
|
||||
this.updateFusionPalette();
|
||||
if (this.summonData?.speciesForm) {
|
||||
this.updateFusionPalette(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@ import { type PokeballCounts } from "#app/battle-scene";
|
|||
import { EvolutionItem } from "#app/data/balance/pokemon-evolutions";
|
||||
import { Gender } from "#app/data/gender";
|
||||
import { FormChangeItem } from "#app/data/pokemon-forms";
|
||||
import { Variant } from "#app/data/variant";
|
||||
import { Variant } from "#app/sprites/variant";
|
||||
import { type ModifierOverride } from "#app/modifier/modifier-type";
|
||||
import { Unlockables } from "#app/system/unlockables";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { variantColorCache } from "#app/data/variant";
|
||||
import { variantColorCache } from "#app/sprites/variant";
|
||||
import MysteryEncounterIntroVisuals from "#app/field/mystery-encounter-intro";
|
||||
import Pokemon from "#app/field/pokemon";
|
||||
import Trainer from "#app/field/trainer";
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { globalScene } from "#app/global-scene";
|
||||
import { isNullOrUndefined } from "#app/utils";
|
||||
import { variantColorCache, variantData } from "#app/data/variant";
|
||||
import { variantColorCache, variantData } from "#app/sprites/variant";
|
||||
import { Gender } from "#app/data/gender";
|
||||
import { hasExpSprite } from "./sprite-utilts";
|
||||
import type { Variant, VariantSet } from "#app/data/variant";
|
||||
import type { Variant, VariantSet } from "#app/sprites/variant";
|
||||
import type Pokemon from "#app/field/pokemon";
|
||||
import type BattleScene from "#app/battle-scene";
|
||||
|
||||
|
@ -12,57 +11,6 @@ import type BattleScene from "#app/battle-scene";
|
|||
/** Regex matching double underscores */
|
||||
const DUNDER_REGEX = /\_{2}/g;
|
||||
|
||||
/**
|
||||
* Gracefully handle errors loading a variant sprite. Log if it fails and attempt to fall back on
|
||||
* non-experimental sprites before giving up.
|
||||
*
|
||||
* @param cacheKey the cache key for the variant color sprite
|
||||
* @param attemptedSpritePath the sprite path that failed to load
|
||||
* @param useExpSprite was the attempted sprite experimental
|
||||
* @param battleSpritePath the filename of the sprite
|
||||
* @param optionalParams any additional params to log
|
||||
*/
|
||||
async function fallbackVariantColor(
|
||||
cacheKey: string,
|
||||
attemptedSpritePath: string,
|
||||
useExpSprite: boolean,
|
||||
battleSpritePath: string,
|
||||
...optionalParams: any[]
|
||||
) {
|
||||
console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams);
|
||||
if (useExpSprite) {
|
||||
await populateVariantColorCache(cacheKey, false, battleSpritePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to process variant sprite.
|
||||
*
|
||||
* @param cacheKey the cache key for the variant color sprite
|
||||
* @param useExpSprite should the experimental sprite be used
|
||||
* @param battleSpritePath the filename of the sprite
|
||||
*/
|
||||
export async function populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
|
||||
const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`;
|
||||
return globalScene
|
||||
.cachedFetch(spritePath)
|
||||
.then(res => {
|
||||
// Prevent the JSON from processing if it failed to load
|
||||
if (!res.ok) {
|
||||
return fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.catch(error => {
|
||||
return fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
|
||||
})
|
||||
.then(c => {
|
||||
if (!isNullOrUndefined(c)) {
|
||||
variantColorCache[cacheKey] = c;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the sprite ID from a pokemon form.
|
||||
*/
|
||||
|
@ -100,7 +48,7 @@ export function getSpriteAtlasPath(pokemon: Pokemon, ignoreOverride = false): st
|
|||
}
|
||||
|
||||
/**
|
||||
* Load the variant assets for the given sprite and stores them in {@linkcode variantColorCache}.
|
||||
* Load the variant assets for the given sprite and store it in {@linkcode variantColorCache}.
|
||||
* @param spriteKey the key of the sprite to load
|
||||
* @param fileRoot the root path of the sprite file
|
||||
* @param variant the variant to load
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
import { VariantTier } from "#app/enums/variant-tier";
|
||||
import { hasExpSprite } from "#app/sprites/sprite-utilts";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import type Pokemon from "#app/field/pokemon";
|
||||
import { isNullOrUndefined } from "#app/utils";
|
||||
|
||||
export type Variant = 0 | 1 | 2;
|
||||
|
||||
export type VariantSet = [Variant, Variant, Variant];
|
||||
|
||||
export const variantData: any = {};
|
||||
|
||||
/** Caches variant colors that have been generated */
|
||||
export const variantColorCache = {};
|
||||
|
||||
export function getVariantTint(variant: Variant): number {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return 0xf8c020;
|
||||
case 1:
|
||||
return 0x20f8f0;
|
||||
case 2:
|
||||
return 0xe81048;
|
||||
}
|
||||
}
|
||||
|
||||
export function getVariantIcon(variant: Variant): number {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return VariantTier.STANDARD;
|
||||
case 1:
|
||||
return VariantTier.RARE;
|
||||
case 2:
|
||||
return VariantTier.EPIC;
|
||||
}
|
||||
}
|
||||
|
||||
/** Delete all of the keys in variantData */
|
||||
export function clearVariantData() {
|
||||
for (const key in variantData) {
|
||||
delete variantData[key];
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the variant data to use experiment sprite files for variants that have experimental sprites. */
|
||||
export async function mergeExperimentalData(mainData: any, expData: any) {
|
||||
if (!expData) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const key of Object.keys(expData)) {
|
||||
if (typeof expData[key] === "object" && !Array.isArray(expData[key])) {
|
||||
// If the value is an object, recursively merge.
|
||||
if (!mainData[key]) {
|
||||
mainData[key] = {};
|
||||
}
|
||||
this.mergeExperimentalData(mainData[key], expData[key]);
|
||||
} else {
|
||||
// Otherwise, replace the value
|
||||
mainData[key] = expData[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Populate the variant color cache with the variant colors for this pokemon.
|
||||
*
|
||||
* The global scene must be initialized before this function is called.
|
||||
*/
|
||||
export async function populateVariantColors(
|
||||
pokemon: Pokemon,
|
||||
isBackSprite = false,
|
||||
ignoreOverride = true,
|
||||
): Promise<void> {
|
||||
const battleSpritePath = pokemon
|
||||
.getBattleSpriteAtlasPath(isBackSprite, ignoreOverride)
|
||||
.replace("variant/", "")
|
||||
.replace(/_[1-3]$/, "");
|
||||
let config = variantData;
|
||||
const useExpSprite =
|
||||
globalScene.experimentalSprites && hasExpSprite(pokemon.getBattleSpriteKey(isBackSprite, ignoreOverride));
|
||||
battleSpritePath.split("/").map(p => (config ? (config = config[p]) : null));
|
||||
const variantSet: VariantSet = config as VariantSet;
|
||||
if (!variantSet || variantSet[pokemon.variant] !== 1) {
|
||||
return;
|
||||
}
|
||||
const cacheKey = pokemon.getBattleSpriteKey(isBackSprite);
|
||||
if (!variantColorCache.hasOwnProperty(cacheKey)) {
|
||||
await populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gracefully handle errors loading a variant sprite. Log if it fails and attempt to fall back on
|
||||
* non-experimental sprites before giving up.
|
||||
*
|
||||
* @param cacheKey the cache key for the variant color sprite
|
||||
* @param attemptedSpritePath the sprite path that failed to load
|
||||
* @param useExpSprite was the attempted sprite experimental
|
||||
* @param battleSpritePath the filename of the sprite
|
||||
* @param optionalParams any additional params to log
|
||||
*/
|
||||
async function fallbackVariantColor(
|
||||
cacheKey: string,
|
||||
attemptedSpritePath: string,
|
||||
useExpSprite: boolean,
|
||||
battleSpritePath: string,
|
||||
...optionalParams: any[]
|
||||
) {
|
||||
console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams);
|
||||
if (useExpSprite) {
|
||||
await populateVariantColorCache(cacheKey, false, battleSpritePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a variant color sprite from the key and store it in the variant color cache.
|
||||
*
|
||||
* @param cacheKey the cache key for the variant color sprite
|
||||
* @param useExpSprite should the experimental sprite be used
|
||||
* @param battleSpritePath the filename of the sprite
|
||||
*/
|
||||
export async function populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
|
||||
const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`;
|
||||
return globalScene
|
||||
.cachedFetch(spritePath)
|
||||
.then(res => {
|
||||
// Prevent the JSON from processing if it failed to load
|
||||
if (!res.ok) {
|
||||
return fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.catch(error => {
|
||||
return fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
|
||||
})
|
||||
.then(c => {
|
||||
if (!isNullOrUndefined(c)) {
|
||||
variantColorCache[cacheKey] = c;
|
||||
}
|
||||
});
|
||||
}
|
|
@ -32,7 +32,7 @@ import { Tutorial } from "#app/tutorial";
|
|||
import { speciesEggMoves } from "#app/data/balance/egg-moves";
|
||||
import { allMoves } from "#app/data/moves/move";
|
||||
import { TrainerVariant } from "#app/field/trainer";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { setSettingGamepad, SettingGamepad, settingGamepadDefaults } from "#app/system/settings/settings-gamepad";
|
||||
import type { SettingKeyboard } from "#app/system/settings/settings-keyboard";
|
||||
import { setSettingKeyboard } from "#app/system/settings/settings-keyboard";
|
||||
|
|
|
@ -7,7 +7,7 @@ import { getPokemonSpecies, getPokemonSpeciesForm } from "../data/pokemon-specie
|
|||
import { Status } from "../data/status-effect";
|
||||
import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../field/pokemon";
|
||||
import { TrainerSlot } from "#enums/trainer-slot";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { loadBattlerTag } from "../data/battler-tags";
|
||||
import type { Biome } from "#enums/biome";
|
||||
import { Moves } from "#enums/moves";
|
||||
|
|
|
@ -7,7 +7,7 @@ import { StatusEffect } from "#enums/status-effect";
|
|||
import { globalScene } from "#app/global-scene";
|
||||
import { getTypeRgb } from "#app/data/type";
|
||||
import { PokemonType } from "#enums/pokemon-type";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import { Stat } from "#enums/stat";
|
||||
import BattleFlyout from "./battle-flyout";
|
||||
import { WindowVariant, addWindow } from "./ui-theme";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { EggHatchData } from "#app/data/egg-hatch-data";
|
||||
import { Gender } from "#app/data/gender";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import { DexAttr } from "#app/system/game-data";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import type PokemonSpecies from "#app/data/pokemon-species";
|
||||
|
|
|
@ -18,7 +18,7 @@ import PokemonIconAnimHandler, { PokemonIconAnimMode } from "#app/ui/pokemon-ico
|
|||
import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions";
|
||||
import { addWindow } from "#app/ui/ui-theme";
|
||||
import { SpeciesFormChangeItemTrigger, FormChangeItem } from "#app/data/pokemon-forms";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import { Button } from "#enums/buttons";
|
||||
import { applyChallenges, ChallengeType } from "#app/data/challenge";
|
||||
import MoveInfoOverlay from "#app/ui/move-info-overlay";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { isNullOrUndefined } from "#app/utils";
|
||||
import type PokemonSpecies from "../data/pokemon-species";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions";
|
||||
import { pokemonEvolutions, pokemonPrevolutions, pokemonStarters } from "#app/data/balance/pokemon-evolutions";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/sprites/variant";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
import { starterColors } from "#app/battle-scene";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { Variant } from "#app/data/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/sprites/variant";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
import { starterColors } from "#app/battle-scene";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getVariantTint } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import type BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { Gender, getGenderColor, getGenderSymbol } from "../data/gender";
|
||||
|
|
|
@ -18,7 +18,7 @@ import { getTypeRgb } from "#app/data/type";
|
|||
import { PokemonType } from "#enums/pokemon-type";
|
||||
import { TypeColor, TypeShadow } from "#app/enums/color";
|
||||
import { getNatureStatMultiplier, getNatureName } from "../data/nature";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import * as Modifier from "../modifier/modifier";
|
||||
import type { Species } from "#enums/species";
|
||||
import { PlayerGender } from "#enums/player-gender";
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import type { CandyUpgradeNotificationChangedEvent } from "#app/events/battle-scene";
|
||||
import { BattleSceneEventType } from "#app/events/battle-scene";
|
||||
import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { getVariantTint, getVariantIcon } from "#app/sprites/variant";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
import type BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
|
||||
|
|
|
@ -19,8 +19,8 @@ import { StatusEffect } from "#enums/status-effect";
|
|||
import { getBiomeName } from "#app/data/balance/biomes";
|
||||
import { getNatureName, getNatureStatMultiplier } from "#app/data/nature";
|
||||
import { loggedInUser } from "#app/account";
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { getVariantTint } from "#app/sprites/variant";
|
||||
import { Button } from "#enums/buttons";
|
||||
import type { Ability } from "#app/data/ability";
|
||||
import i18next from "i18next";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Variant } from "#app/data/variant";
|
||||
import type { Variant } from "#app/sprites/variant";
|
||||
import { Weather } from "#app/data/weather";
|
||||
import { Abilities } from "#app/enums/abilities";
|
||||
import type { ModifierOverride } from "#app/modifier/modifier-type";
|
||||
|
|
Loading…
Reference in New Issue