Added button to show back sprites

This commit is contained in:
Wlowscha 2025-01-29 01:01:14 +01:00
parent df1cdd265d
commit dabc275bdf
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
2 changed files with 44 additions and 14 deletions

View File

@ -298,8 +298,8 @@ export abstract class PokemonSpeciesForm {
return ret;
}
getSpriteAtlasPath(female: boolean, formIndex?: number, shiny?: boolean, variant?: number): string {
const spriteId = this.getSpriteId(female, formIndex, shiny, variant).replace(/\_{2}/g, "/");
getSpriteAtlasPath(female: boolean, formIndex?: number, shiny?: boolean, variant?: number, back?: boolean): string {
const spriteId = this.getSpriteId(female, formIndex, shiny, variant, back).replace(/\_{2}/g, "/");
return `${/_[1-3]$/.test(spriteId) ? "variant/" : ""}${spriteId}`;
}
@ -320,8 +320,8 @@ export abstract class PokemonSpeciesForm {
return `${back ? "back__" : ""}${shiny && (!variantSet || (!variant && !variantSet[variant || 0])) ? "shiny__" : ""}${baseSpriteKey}${shiny && variantSet && variantSet[variant] === 2 ? `_${variant + 1}` : ""}`;
}
getSpriteKey(female: boolean, formIndex?: number, shiny?: boolean, variant?: number): string {
return `pkmn__${this.getSpriteId(female, formIndex, shiny, variant)}`;
getSpriteKey(female: boolean, formIndex?: number, shiny?: boolean, variant?: number, back?: boolean): string {
return `pkmn__${this.getSpriteId(female, formIndex, shiny, variant, back)}`;
}
abstract getFormSpriteKey(formIndex?: number): string;
@ -494,10 +494,10 @@ export abstract class PokemonSpeciesForm {
return true;
}
loadAssets(female: boolean, formIndex?: number, shiny?: boolean, variant?: Variant, startLoad?: boolean): Promise<void> {
loadAssets(female: boolean, formIndex?: number, shiny?: boolean, variant?: Variant, startLoad?: boolean, back?: boolean): Promise<void> {
return new Promise(resolve => {
const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant);
globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant));
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`);
globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => {
const originalWarn = console.warn;
@ -507,7 +507,7 @@ export abstract class PokemonSpeciesForm {
console.warn = originalWarn;
if (!(globalScene.anims.exists(spriteKey))) {
globalScene.anims.create({
key: this.getSpriteKey(female, formIndex, shiny, variant),
key: this.getSpriteKey(female, formIndex, shiny, variant, back),
frames: frameNames,
frameRate: 10,
repeat: -1
@ -515,7 +515,7 @@ export abstract class PokemonSpeciesForm {
} else {
globalScene.anims.get(spriteKey).frameRate = 10;
}
const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant).replace("variant/", "").replace(/_[1-3]$/, "");
const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant, back).replace("variant/", "").replace(/_[1-3]$/, "");
globalScene.loadPokemonVariantAssets(spriteKey, spritePath, variant).then(() => resolve());
});
if (startLoad) {

View File

@ -185,6 +185,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
private variantLabel: Phaser.GameObjects.Text;
private candyUpgradeIconElement: Phaser.GameObjects.Sprite;
private candyUpgradeLabel: Phaser.GameObjects.Text;
private showBackSpriteIconElement: Phaser.GameObjects.Sprite;
private showBackSpriteLabel: Phaser.GameObjects.Text;
private starterSelectMessageBox: Phaser.GameObjects.NineSlice;
private starterSelectMessageBoxContainer: Phaser.GameObjects.Container;
@ -239,6 +241,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
protected blockInput: boolean = false;
protected blockInputOverlay: boolean = false;
private showBackSprite: boolean = false;
// Menu
private menuContainer: Phaser.GameObjects.Container;
private menuBg: Phaser.GameObjects.NineSlice;
@ -441,6 +445,15 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.variantLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.variantLabel.setName("text-variant-label");
this.showBackSpriteIconElement = new Phaser.GameObjects.Sprite(globalScene, 50, 7, "keyboard", "E.png");
this.showBackSpriteIconElement.setName("show-backSprite-icon-element");
this.showBackSpriteIconElement.setScale(0.675);
this.showBackSpriteIconElement.setOrigin(0.0, 0.0);
this.showBackSpriteLabel = addTextObject(60, 7, i18next.t("pokedexUiHandler:showBackSprite"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.showBackSpriteLabel.setName("show-backSprite-label");
this.starterSelectContainer.add(this.showBackSpriteIconElement);
this.starterSelectContainer.add(this.showBackSpriteLabel);
this.hideInstructions();
this.filterInstructionsContainer = globalScene.add.container(50, 5);
@ -1720,6 +1733,16 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
}
}
break;
case Button.CYCLE_ABILITY:
this.showBackSprite = !this.showBackSprite;
if (this.showBackSprite) {
this.showBackSpriteLabel.setText(i18next.t("pokedexUiHandler:showFrontSprite"));
} else {
this.showBackSpriteLabel.setText(i18next.t("pokedexUiHandler:showBackSprite"));
}
this.setSpeciesDetails(this.species, {}, true);
success = true;
break;
case Button.UP:
if (this.cursor) {
success = this.setCursor(this.cursor - 1);
@ -1798,6 +1821,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
case SettingKeyboard.Button_Cycle_Variant:
iconPath = "V.png";
break;
case SettingKeyboard.Button_Cycle_Ability:
iconPath = "E.png";
break;
default:
break;
}
@ -2087,7 +2113,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
}
}
setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}): void {
setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}, forceUpdate?: boolean): void {
let { shiny, formIndex, female, variant } = options;
const forSeen: boolean = options.forSeen ?? false;
const oldProps = species ? this.starterAttributes : null;
@ -2095,7 +2121,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
// We will only update the sprite if there is a change to form, shiny/variant
// or gender for species with gender sprite differences
const shouldUpdateSprite = (species?.genderDiffs && !isNullOrUndefined(female))
|| !isNullOrUndefined(formIndex) || !isNullOrUndefined(shiny) || !isNullOrUndefined(variant);
|| !isNullOrUndefined(formIndex) || !isNullOrUndefined(shiny) || !isNullOrUndefined(variant) || forceUpdate;
if (this.activeTooltip === "CANDY") {
if (this.species && this.pokemonCandyContainer.visible) {
@ -2170,16 +2196,17 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.assetLoadCancelled = assetLoadCancelled;
if (shouldUpdateSprite) {
species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => { // TODO: is this bang correct?
const back = this.showBackSprite ? true : false;
species.loadAssets(female!, formIndex, shiny, variant as Variant, true, back).then(() => { // TODO: is this bang correct?
if (assetLoadCancelled.value) {
return;
}
this.assetLoadCancelled = null;
this.speciesLoaded.set(species.speciesId, true);
this.pokemonSprite.play(species.getSpriteKey(female!, formIndex, shiny, variant)); // TODO: is this bang correct?
this.pokemonSprite.play(species.getSpriteKey(female!, formIndex, shiny, variant, back)); // TODO: is this bang correct?
this.pokemonSprite.setPipelineData("shiny", shiny);
this.pokemonSprite.setPipelineData("variant", variant);
this.pokemonSprite.setPipelineData("spriteKey", species.getSpriteKey(female!, formIndex, shiny, variant)); // TODO: is this bang correct?
this.pokemonSprite.setPipelineData("spriteKey", species.getSpriteKey(female!, formIndex, shiny, variant, back)); // TODO: is this bang correct?
this.pokemonSprite.setVisible(!this.statsMode);
});
} else {
@ -2374,6 +2401,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.starterSelectContainer.setVisible(false);
this.blockInput = false;
this.showBackSprite = false;
this.showBackSpriteLabel.setText(i18next.t("pokedexUiHandler:showBackSprite"));
if (this.statsMode) {
this.toggleStatsMode(false);
}