From 73f7a340a2bc604c6e0391888d7fed1c95097313 Mon Sep 17 00:00:00 2001 From: innerthunder Date: Fri, 9 Aug 2024 00:16:33 -0700 Subject: [PATCH] Fix some strict-null issues --- src/data/move.ts | 2 +- src/field/pokemon.ts | 2 +- src/test/moves/substitute.test.ts | 62 +++++++++++++++---------------- src/test/moves/tidy_up.test.ts | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index efd0af7973c..621c9c73cd4 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -572,7 +572,7 @@ export default class Move implements Localizable { * example: @see {@linkcode Moves.WHIRLWIND} * @returns The {@linkcode Move} that called this function */ - ignoresSubstitute(ignoresSubstitute?: boolean): this { + ignoresSubstitute(ignoresSubstitute: boolean = true): this { this.setFlag(MoveFlags.IGNORE_SUBSTITUTE, ignoresSubstitute); return this; } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5d95b4a8c2c..48bc11b43a8 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2924,7 +2924,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // If this Pokemon has a Substitute when loading in, play an animation to add its sprite if (!!this.getTag(SubstituteTag)) { this.scene.triggerPokemonBattleAnim(this, PokemonAnimType.SUBSTITUTE_ADD); - this.getTag(SubstituteTag).sourceInFocus = false; + this.getTag(SubstituteTag)!.sourceInFocus = false; } this.summonDataPrimer = null; } diff --git a/src/test/moves/substitute.test.ts b/src/test/moves/substitute.test.ts index 7eba4cfc18e..51ad68274b7 100644 --- a/src/test/moves/substitute.test.ts +++ b/src/test/moves/substitute.test.ts @@ -48,7 +48,7 @@ describe("Moves - Substitute", () => { async () => { await game.startBattle([Species.MAGIKARP]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -65,7 +65,7 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.SKARMORY]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -91,7 +91,7 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.MAGIKARP]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -115,7 +115,7 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.MAGIKARP]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -133,7 +133,7 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -157,7 +157,7 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -178,7 +178,7 @@ describe("Moves - Substitute", () => { async () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; game.doAttack(getMovePosition(game.scene, 0, Moves.SUBSTITUTE)); @@ -201,10 +201,10 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); - const enemyPokemon = game.scene.getEnemyPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; + const enemyPokemon = game.scene.getEnemyPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.TACKLE)); @@ -222,9 +222,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); @@ -242,9 +242,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); @@ -261,9 +261,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); @@ -282,9 +282,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); @@ -302,9 +302,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const enemyPokemon = game.scene.getEnemyPokemon(); + const enemyPokemon = game.scene.getEnemyPokemon()!; - enemyPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, enemyPokemon.id); + enemyPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, enemyPokemon.id); const enemyNumItems = enemyPokemon.getHeldItems().length; game.doAttack(getMovePosition(game.scene, 0, Moves.KNOCK_OFF)); @@ -323,10 +323,10 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); - const enemyPokemon = game.scene.getEnemyPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; + const enemyPokemon = game.scene.getEnemyPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.TACKLE)); @@ -347,9 +347,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SWORDS_DANCE)); @@ -367,9 +367,9 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doAttack(getMovePosition(game.scene, 0, Moves.SWORDS_DANCE)); @@ -387,16 +387,16 @@ describe("Moves - Substitute", () => { await game.startBattle([Species.BLASTOISE, Species.CHARIZARD]); - const leadPokemon = game.scene.getPlayerPokemon(); + const leadPokemon = game.scene.getPlayerPokemon()!; - leadPokemon.addTag(BattlerTagType.SUBSTITUTE, null, null, leadPokemon.id); + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); game.doSwitchPokemon(1, true); await game.phaseInterceptor.to(MovePhase, false); - const switchedPokemon = game.scene.getPlayerPokemon(); - const subTag = switchedPokemon.getTag(SubstituteTag); + const switchedPokemon = game.scene.getPlayerPokemon()!; + const subTag = switchedPokemon.getTag(SubstituteTag)!; expect(subTag).toBeDefined(); expect(subTag.hp).toBe(Math.floor(leadPokemon.getMaxHp() * 1/4)); }, TIMEOUT diff --git a/src/test/moves/tidy_up.test.ts b/src/test/moves/tidy_up.test.ts index f46ffba6e7a..b4895d08081 100644 --- a/src/test/moves/tidy_up.test.ts +++ b/src/test/moves/tidy_up.test.ts @@ -105,7 +105,7 @@ describe("Moves - Tidy Up", () => { const pokemon = [ game.scene.getPlayerPokemon(), game.scene.getEnemyPokemon() ]; pokemon.forEach(p => { expect(p).toBeDefined(); - expect(p.getTag(SubstituteTag)).toBeUndefined(); + expect(p!.getTag(SubstituteTag)).toBeUndefined(); }); }, 20000);