Add transform support to fusion palette swaps

pull/7/head
Flashfyre 2023-11-24 15:12:26 -05:00
parent 5fc5f5b499
commit e5fe0c6e3a
6 changed files with 72 additions and 35 deletions

View File

@ -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}!`));

View File

@ -2276,7 +2276,9 @@ 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));

View File

@ -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];
});
});
});

View File

@ -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 ]

View File

@ -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[];

View File

@ -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;