From e5fe0c6e3a4116827bb8b0f10d8279fe8e7f8d16 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Fri, 24 Nov 2023 15:12:26 -0500 Subject: [PATCH] Add transform support to fusion palette swaps --- src/data/ability.ts | 3 ++ src/data/move.ts | 4 ++- src/evolution-phase.ts | 16 ++++++--- src/pipelines/sprite.ts | 5 +-- src/pokemon.ts | 70 ++++++++++++++++++++++-------------- src/ui/summary-ui-handler.ts | 9 +++-- 6 files changed, 72 insertions(+), 35 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index bcf2ff66a..69c703b93 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -530,13 +530,16 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { target = targets[0]; pokemon.summonData.speciesForm = target.getSpeciesForm(); + pokemon.summonData.fusionSpeciesForm = target.getFusionSpeciesForm(); pokemon.summonData.gender = target.getGender(); + pokemon.summonData.fusionGender = target.getFusionGender(); pokemon.summonData.stats = [ pokemon.stats[Stat.HP] ].concat(target.stats.slice(1)); pokemon.summonData.battleStats = target.summonData.battleStats.slice(0); pokemon.summonData.moveset = target.getMoveset().map(m => new PokemonMove(m.moveId, m.ppUsed, m.ppUp)); pokemon.summonData.types = target.getTypes(); pokemon.scene.playSound('PRSFX- Transform'); + pokemon.loadAssets().then(() => pokemon.playAnim()); pokemon.scene.queueMessage(getPokemonMessage(pokemon, ` transformed\ninto ${target.name}!`)); diff --git a/src/data/move.ts b/src/data/move.ts index 76d4f56c7..d1a1b82cb 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -2276,14 +2276,16 @@ export class TransformAttr extends MoveEffectAttr { return resolve(false); user.summonData.speciesForm = target.getSpeciesForm(); + user.summonData.fusionSpeciesForm = target.getFusionSpeciesForm(); user.summonData.gender = target.getGender(); + user.summonData.fusionGender = target.getFusionGender(); user.summonData.stats = [ user.stats[Stat.HP] ].concat(target.stats.slice(1)); user.summonData.battleStats = target.summonData.battleStats.slice(0); user.summonData.moveset = target.getMoveset().map(m => new PokemonMove(m.moveId, m.ppUsed, m.ppUp)); user.summonData.types = target.getTypes(); user.scene.queueMessage(getPokemonMessage(user, ` transformed\ninto ${target.name}!`)); - + user.loadAssets().then(() => { user.playAnim(); resolve(true); diff --git a/src/evolution-phase.ts b/src/evolution-phase.ts index 746f9c2a7..8ed7e1819 100644 --- a/src/evolution-phase.ts +++ b/src/evolution-phase.ts @@ -81,9 +81,13 @@ export class EvolutionPhase extends BattlePhase { const preName = pokemon.name; [ this.pokemonSprite, this.pokemonTintSprite, this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => { - sprite.play(pokemon.getSpriteKey()); + sprite.play(pokemon.getSpriteKey(true)); sprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false }); - [ 'spriteColors', 'fusionSpriteColors' ].map(k => sprite.pipelineData[k] = pokemon.getSprite().pipelineData[k]); + [ 'spriteColors', 'fusionSpriteColors' ].map(k => { + if (pokemon.summonData?.speciesForm) + k += 'Base'; + sprite.pipelineData[k] = pokemon.getSprite().pipelineData[k]; + }); }); this.scene.ui.showText(`What?\n${preName} is evolving!`, null, () => { @@ -91,8 +95,12 @@ export class EvolutionPhase extends BattlePhase { pokemon.evolve(this.evolution).then(() => { [ this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => { - sprite.play(pokemon.getSpriteKey()); - [ 'spriteColors', 'fusionSpriteColors' ].map(k => sprite.pipelineData[k] = pokemon.getSprite().pipelineData[k]); + sprite.play(pokemon.getSpriteKey(true)); + [ 'spriteColors', 'fusionSpriteColors' ].map(k => { + if (pokemon.summonData?.speciesForm) + k += 'Base'; + sprite.pipelineData[k] = pokemon.getSprite().pipelineData[k]; + }); }); }); diff --git a/src/pipelines/sprite.ts b/src/pipelines/sprite.ts index 965c4af03..f70a4da2e 100644 --- a/src/pipelines/sprite.ts +++ b/src/pipelines/sprite.ts @@ -162,8 +162,9 @@ export default class SpritePipeline extends Phaser.Renderer.WebGL.Pipelines.Mult const data = sprite.pipelineData; const tone = data['tone'] as number[]; const hasShadow = data['hasShadow'] as boolean; - let spriteColors = data['spriteColors'] || [] as number[][]; - const fusionSpriteColors = data['fusionSpriteColors'] || [] as number[][]; + const ignoreOverride = data['ignoreOverride'] as boolean; + const spriteColors = (ignoreOverride && data['spriteColorsBase']) || data['spriteColors'] || [] as number[][]; + const fusionSpriteColors = (ignoreOverride && data['fusionSpriteColorsBase']) || data['fusionSpriteColors'] || [] as number[][]; const position = sprite.parentContainer instanceof Pokemon || sprite.parentContainer instanceof Trainer ? [ sprite.parentContainer.x, sprite.parentContainer.y ] diff --git a/src/pokemon.ts b/src/pokemon.ts index 68466001b..b96648add 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -247,10 +247,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { .then(() => { loadMoveAnimAssets(this.scene, moveIds); this.getSpeciesForm().loadAssets(this.scene, this.getGender() === Gender.FEMALE, this.formIndex, this.shiny); - if (this.isPlayer() || this.fusionSpecies) + if (this.isPlayer() || this.getFusionSpeciesForm()) this.scene.loadAtlas(this.getBattleSpriteKey(true), 'pokemon', this.getBattleSpriteAtlasPath(true)); - if (this.fusionSpecies) { - this.getFusionSpeciesForm().loadAssets(this.scene, this.fusionGender === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny); + if (this.getFusionSpeciesForm()) { + this.getFusionSpeciesForm().loadAssets(this.scene, this.getFusionGender() === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny); this.scene.loadAtlas(this.getFusionBattleSpriteKey(true), 'pokemon', this.getFusionBattleSpriteAtlasPath(true)); } this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => { @@ -268,8 +268,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); } this.playAnim(); - if (this.fusionSpecies) - this.updateFusionPalette(); + this.updateFusionPalette(); + if (this.summonData?.speciesForm) + this.updateFusionPalette(true); resolve(); }); if (!this.scene.load.isLoading()) @@ -304,22 +305,22 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return `pkmn__${this.getBattleSpriteId(back, ignoreOverride)}`; } - getFusionSpriteId(): string { - return this.getFusionSpeciesForm().getSpriteId(this.fusionGender === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny); + getFusionSpriteId(ignoreOverride?: boolean): string { + return this.getFusionSpeciesForm(ignoreOverride).getSpriteId(this.getFusionGender(ignoreOverride) === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny); } - getFusionBattleSpriteId(back?: boolean): string { + getFusionBattleSpriteId(back?: boolean, ignoreOverride?: boolean): string { if (back === undefined) back = this.isPlayer(); - return `${back ? 'back__' : ''}${this.getFusionSpriteId()}`; + return `${back ? 'back__' : ''}${this.getFusionSpriteId(ignoreOverride)}`; } - getFusionBattleSpriteKey(back?: boolean): string { - return `pkmn__${this.getFusionBattleSpriteId(back)}`; + getFusionBattleSpriteKey(back?: boolean, ignoreOverride?: boolean): string { + return `pkmn__${this.getFusionBattleSpriteId(back, ignoreOverride)}`; } - getFusionBattleSpriteAtlasPath(back?: boolean): string { - return this.getFusionBattleSpriteId(back).replace(/\_{2}/g, '/'); + getFusionBattleSpriteAtlasPath(back?: boolean, ignoreOverride?: boolean): string { + return this.getFusionBattleSpriteId(back, ignoreOverride).replace(/\_{2}/g, '/'); } getIconAtlasKey(ignoreOverride?: boolean): string { @@ -342,10 +343,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.species.forms[this.formIndex]; } - getFusionSpeciesForm(): PokemonSpeciesForm { - if (!this.fusionSpecies.forms?.length || this.fusionFormIndex >= this.fusionSpecies.forms.length) + getFusionSpeciesForm(ignoreOverride?: boolean): PokemonSpeciesForm { + if (!ignoreOverride && this.summonData?.speciesForm) + return this.summonData.fusionSpeciesForm; + if (!this.fusionSpecies?.forms?.length || this.fusionFormIndex >= this.fusionSpecies?.forms.length) return this.fusionSpecies; - return this.fusionSpecies.forms[this.fusionFormIndex]; + return this.fusionSpecies?.forms[this.fusionFormIndex]; } getSprite(): Phaser.GameObjects.Sprite { @@ -485,6 +488,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.gender; } + getFusionGender(ignoreOverride?: boolean): Gender { + if (!ignoreOverride && this.summonData?.fusionGender !== undefined) + return this.summonData.fusionGender; + return this.fusionGender; + } + isShiny(): boolean { return this.shiny || (this.fusionSpecies && this.fusionShiny); } @@ -1288,6 +1297,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } resetSummonData(): void { + if (this.summonData?.speciesForm) { + this.summonData.speciesForm = null; + this.updateFusionPalette(); + } this.summonData = new PokemonSummonData(); this.resetBattleSummonData(); } @@ -1378,19 +1391,22 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - updateFusionPalette(): void { - if (!this.fusionSpecies) { + updateFusionPalette(ignoreOveride?: boolean): void { + if (!this.getFusionSpeciesForm(ignoreOveride)) { [ this.getSprite(), this.getTintSprite() ].map(s => { - s.pipelineData['spriteColors'] = []; - s.pipelineData['fusionSpriteColors'] = []; + s.pipelineData[`spriteColors${ignoreOveride && this.summonData?.speciesForm ? 'Base' : ''}`] = []; + s.pipelineData[`fusionSpriteColors${ignoreOveride && this.summonData?.speciesForm ? 'Base' : ''}`] = []; }); return; } - const sourceTexture = this.scene.textures.get(this.getSpeciesForm().getSpriteKey(this.gender === Gender.FEMALE, this.formIndex, this.shiny)); - const sourceBackTexture = this.scene.textures.get(this.getSpeciesForm().getSpriteKey(this.gender === Gender.FEMALE, this.formIndex, this.shiny).replace('pkmn__', 'pkmn__back__')); - const fusionTexture = this.scene.textures.get(this.getFusionSpeciesForm().getSpriteKey(this.fusionGender === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny)); - const fusionBackTexture = this.scene.textures.get(this.getFusionSpeciesForm().getSpriteKey(this.fusionGender === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny).replace('pkmn__', 'pkmn__back__')); + const speciesForm = this.getSpeciesForm(ignoreOveride); + const fusionSpeciesForm = this.getFusionSpeciesForm(ignoreOveride); + + const sourceTexture = this.scene.textures.get(speciesForm.getSpriteKey(this.getGender(ignoreOveride) === Gender.FEMALE, speciesForm.formIndex, this.shiny)); + const sourceBackTexture = this.scene.textures.get(speciesForm.getSpriteKey(this.getGender(ignoreOveride) === Gender.FEMALE, speciesForm.formIndex, this.shiny).replace('pkmn__', 'pkmn__back__')); + const fusionTexture = this.scene.textures.get(fusionSpeciesForm.getSpriteKey(this.getFusionGender(ignoreOveride) === Gender.FEMALE, fusionSpeciesForm.formIndex, this.fusionShiny)); + const fusionBackTexture = this.scene.textures.get(fusionSpeciesForm.getSpriteKey(this.getFusionGender(ignoreOveride) === Gender.FEMALE, fusionSpeciesForm.formIndex, this.fusionShiny).replace('pkmn__', 'pkmn__back__')); const [ sourceFrame, sourceBackFrame, fusionFrame, fusionBackFrame ] = [ sourceTexture, sourceBackTexture, fusionTexture, fusionBackTexture ].map(texture => texture.frames[texture.firstFrame]); const [ sourceImage, sourceBackImage, fusionImage, fusionBackImage ] = [ sourceTexture, sourceBackTexture, fusionTexture, fusionBackTexture ].map(i => i.getSourceImage() as HTMLImageElement); @@ -1555,8 +1571,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } [ this.getSprite(), this.getTintSprite() ].map(s => { - s.pipelineData['spriteColors'] = spriteColors; - s.pipelineData['fusionSpriteColors'] = fusionSpriteColors; + s.pipelineData[`spriteColors${ignoreOveride && this.summonData?.speciesForm ? 'Base' : ''}`] = spriteColors; + s.pipelineData[`fusionSpriteColors${ignoreOveride && this.summonData?.speciesForm ? 'Base' : ''}`] = fusionSpriteColors; }); canvas.remove(); @@ -1954,7 +1970,9 @@ export class PokemonSummonData { public tags: BattlerTag[] = []; public speciesForm: PokemonSpeciesForm; + public fusionSpeciesForm: PokemonSpeciesForm; public gender: Gender; + public fusionGender: Gender; public stats: integer[]; public moveset: PokemonMove[]; public types: Type[]; diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index eb98fc485..0615bfaab 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -98,7 +98,7 @@ export default class SummaryUiHandler extends UiHandler { this.summaryContainer.add(this.numberText); this.pokemonSprite = this.scene.add.sprite(56, -106, `pkmn__sub`); - this.pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false }); + this.pokemonSprite.setPipeline(this.scene.spritePipeline, { ignoreOverride: true, tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false }); this.summaryContainer.add(this.pokemonSprite); this.nameText = addTextObject(this.scene, 6, -54, '', TextStyle.SUMMARY); @@ -198,7 +198,12 @@ export default class SummaryUiHandler extends UiHandler { this.numberText.setShadowColor(getTextColor(!this.pokemon.isShiny() ? TextStyle.SUMMARY : TextStyle.SUMMARY_GOLD, true)); this.pokemonSprite.play(this.pokemon.getSpriteKey(true)); - [ 'spriteColors', 'fusionSpriteColors' ].map(k => this.pokemonSprite.pipelineData[k] = this.pokemon.getSprite().pipelineData[k]); + [ 'spriteColors', 'fusionSpriteColors' ].map(k => { + delete this.pokemonSprite.pipelineData[`${k}Base`]; + if (this.pokemon.summonData?.speciesForm) + k += 'Base'; + this.pokemonSprite.pipelineData[k] = this.pokemon.getSprite().pipelineData[k]; + }); this.pokemon.cry(); let nameLabel = this.pokemon.name;