resolve some open strict-null bangs TODOs (#3530)

This commit is contained in:
flx-sta 2024-08-13 23:12:42 +02:00 committed by GitHub
parent 73372b424e
commit 5000a91348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 33 additions and 28 deletions

View File

@ -944,7 +944,7 @@ export default class BattleScene extends SceneBase {
} }
randBattleSeedInt(range: integer, min: integer = 0): integer { randBattleSeedInt(range: integer, min: integer = 0): integer {
return this.currentBattle.randSeedInt(this, range, min); return this.currentBattle?.randSeedInt(this, range, min);
} }
reset(clearScene: boolean = false, clearData: boolean = false, reloadI18n: boolean = false): void { reset(clearScene: boolean = false, clearData: boolean = false, reloadI18n: boolean = false): void {
@ -2397,7 +2397,7 @@ export default class BattleScene extends SceneBase {
} }
party.forEach((enemyPokemon: EnemyPokemon, i: integer) => { party.forEach((enemyPokemon: EnemyPokemon, i: integer) => {
const isBoss = enemyPokemon.isBoss() || (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer?.config.isBoss); const isBoss = enemyPokemon.isBoss() || (this.currentBattle.battleType === BattleType.TRAINER && !!this.currentBattle.trainer?.config.isBoss);
let upgradeChance = 32; let upgradeChance = 32;
if (isBoss) { if (isBoss) {
upgradeChance /= 2; upgradeChance /= 2;
@ -2405,7 +2405,7 @@ export default class BattleScene extends SceneBase {
if (isFinalBoss) { if (isFinalBoss) {
upgradeChance /= 8; upgradeChance /= 8;
} }
const modifierChance = this.gameMode.getEnemyModifierChance(isBoss!); // TODO: is this bang correct? const modifierChance = this.gameMode.getEnemyModifierChance(isBoss);
let pokemonModifierChance = modifierChance; let pokemonModifierChance = modifierChance;
if (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer) if (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer)
pokemonModifierChance = Math.ceil(pokemonModifierChance * this.currentBattle.trainer.getPartyMemberModifierChanceMultiplier(i)); // eslint-disable-line pokemonModifierChance = Math.ceil(pokemonModifierChance * this.currentBattle.trainer.getPartyMemberModifierChanceMultiplier(i)); // eslint-disable-line

View File

@ -74,14 +74,14 @@ export default class Battle {
this.gameMode = gameMode; this.gameMode = gameMode;
this.waveIndex = waveIndex; this.waveIndex = waveIndex;
this.battleType = battleType; this.battleType = battleType;
this.trainer = trainer!; //TODO: is this bang correct? this.trainer = trainer ?? null;
this.initBattleSpec(); this.initBattleSpec();
this.enemyLevels = battleType !== BattleType.TRAINER this.enemyLevels = battleType !== BattleType.TRAINER
? new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave()) ? new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave())
: trainer?.getPartyLevels(this.waveIndex); : trainer?.getPartyLevels(this.waveIndex);
this.enemyParty = []; this.enemyParty = [];
this.seenEnemyPartyMemberIds = new Set<integer>(); this.seenEnemyPartyMemberIds = new Set<integer>();
this.double = double!; //TODO: is this bang correct? this.double = !!double;
this.enemySwitchCounter = 0; this.enemySwitchCounter = 0;
this.turn = 0; this.turn = 0;
this.playerParticipantIds = new Set<integer>(); this.playerParticipantIds = new Set<integer>();
@ -208,9 +208,9 @@ export default class Battle {
return `encounter_${this.trainer?.getEncounterBgm()}`; return `encounter_${this.trainer?.getEncounterBgm()}`;
} }
if (scene.musicPreference === 0) { if (scene.musicPreference === 0) {
return this.trainer?.getBattleBgm()!; // TODO: is this bang correct? return this.trainer?.getBattleBgm() ?? null;
} else { } else {
return this.trainer?.getMixedBattleBgm()!; // TODO: is this bang correct? return this.trainer?.getMixedBattleBgm() ?? null;
} }
} else if (this.gameMode.isClassic && this.waveIndex > 195 && this.battleSpec !== BattleSpec.FINAL_BOSS) { } else if (this.gameMode.isClassic && this.waveIndex > 195 && this.battleSpec !== BattleSpec.FINAL_BOSS) {
return "end_summit"; return "end_summit";

View File

@ -325,7 +325,7 @@ export class TypeImmunityAbAttr extends PreDefendAbAttr {
super(); super();
this.immuneType = immuneType; this.immuneType = immuneType;
this.condition = condition!; // TODO: is this bang correct? this.condition = condition ?? null;
} }
/** /**
@ -1507,7 +1507,7 @@ export class BattleStatMultiplierAbAttr extends AbAttr {
this.battleStat = battleStat; this.battleStat = battleStat;
this.multiplier = multiplier; this.multiplier = multiplier;
this.condition = condition!; // TODO: is this bang correct? this.condition = condition ?? null;
} }
applyBattleStat(pokemon: Pokemon, passive: boolean, battleStat: BattleStat, statValue: Utils.NumberHolder, args: any[]): boolean | Promise<boolean> { applyBattleStat(pokemon: Pokemon, passive: boolean, battleStat: BattleStat, statValue: Utils.NumberHolder, args: any[]): boolean | Promise<boolean> {
@ -1560,7 +1560,7 @@ export class PostAttackStealHeldItemAbAttr extends PostAttackAbAttr {
constructor(stealCondition?: PokemonAttackCondition) { constructor(stealCondition?: PokemonAttackCondition) {
super(); super();
this.stealCondition = stealCondition!; // TODO: is this bang correct? this.stealCondition = stealCondition ?? null;
} }
applyPostAttackAfterMoveTypeCheck(pokemon: Pokemon, passive: boolean, defender: Pokemon, move: Move, hitResult: HitResult, args: any[]): Promise<boolean> { applyPostAttackAfterMoveTypeCheck(pokemon: Pokemon, passive: boolean, defender: Pokemon, move: Move, hitResult: HitResult, args: any[]): Promise<boolean> {
@ -1649,7 +1649,7 @@ export class PostDefendStealHeldItemAbAttr extends PostDefendAbAttr {
constructor(condition?: PokemonDefendCondition) { constructor(condition?: PokemonDefendCondition) {
super(); super();
this.condition = condition!; // TODO: is this bang correct? this.condition = condition ?? null;
} }
applyPostDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): Promise<boolean> { applyPostDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): Promise<boolean> {
@ -2400,11 +2400,11 @@ export class ProtectStatAbAttr extends PreStatChangeAbAttr {
constructor(protectedStat?: BattleStat) { constructor(protectedStat?: BattleStat) {
super(); super();
this.protectedStat = protectedStat!; // TODO: is this bang correct? this.protectedStat = protectedStat ?? null;
} }
applyPreStatChange(pokemon: Pokemon, passive: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean { applyPreStatChange(pokemon: Pokemon, passive: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean {
if (this.protectedStat === undefined || stat === this.protectedStat) { if (!this.protectedStat || stat === this.protectedStat) {
cancelled.value = true; cancelled.value = true;
return true; return true;
} }
@ -2746,7 +2746,7 @@ export class SuppressWeatherEffectAbAttr extends PreWeatherEffectAbAttr {
constructor(affectsImmutable?: boolean) { constructor(affectsImmutable?: boolean) {
super(); super();
this.affectsImmutable = affectsImmutable!; // TODO: is this bang correct? this.affectsImmutable = !!affectsImmutable;
} }
applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): boolean { applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): boolean {
@ -2810,11 +2810,11 @@ function getAnticipationCondition(): AbAttrCondition {
return true; return true;
} }
// move is a OHKO // move is a OHKO
if (move!.getMove().hasAttr(OneHitKOAttr)) { // TODO: is this bang correct? if (move?.getMove().hasAttr(OneHitKOAttr)) {
return true; return true;
} }
// edge case for hidden power, type is computed // edge case for hidden power, type is computed
if (move!.getMove().id === Moves.HIDDEN_POWER) { // TODO: is this bang correct? if (move?.getMove().id === Moves.HIDDEN_POWER) {
const iv_val = Math.floor(((opponent.ivs[Stat.HP] & 1) const iv_val = Math.floor(((opponent.ivs[Stat.HP] & 1)
+(opponent.ivs[Stat.ATK] & 1) * 2 +(opponent.ivs[Stat.ATK] & 1) * 2
+(opponent.ivs[Stat.DEF] & 1) * 4 +(opponent.ivs[Stat.DEF] & 1) * 4
@ -2862,13 +2862,13 @@ export class ForewarnAbAttr extends PostSummonAbAttr {
let movePower = 0; let movePower = 0;
for (const opponent of pokemon.getOpponents()) { for (const opponent of pokemon.getOpponents()) {
for (const move of opponent.moveset) { for (const move of opponent.moveset) {
if (move!.getMove() instanceof StatusMove) { // TODO: is this bang correct? if (move?.getMove() instanceof StatusMove) {
movePower = 1; movePower = 1;
} else if (move!.getMove().hasAttr(OneHitKOAttr)) { // TODO: is this bang correct? } else if (move?.getMove().hasAttr(OneHitKOAttr)) {
movePower = 150; movePower = 150;
} else if (move!.getMove().id === Moves.COUNTER || move!.getMove().id === Moves.MIRROR_COAT || move!.getMove().id === Moves.METAL_BURST) { // TODO: are those bangs correct? } else if (move?.getMove().id === Moves.COUNTER || move?.getMove().id === Moves.MIRROR_COAT || move?.getMove().id === Moves.METAL_BURST) {
movePower = 120; movePower = 120;
} else if (move!.getMove().power === -1) { // TODO: is this bang correct? } else if (move?.getMove().power === -1) {
movePower = 80; movePower = 80;
} else { } else {
movePower = move!.getMove().power; // TODO: is this bang correct? movePower = move!.getMove().power; // TODO: is this bang correct?

View File

@ -683,8 +683,8 @@ export abstract class BattleAnim {
private dstLine: number[]; private dstLine: number[];
constructor(user?: Pokemon, target?: Pokemon) { constructor(user?: Pokemon, target?: Pokemon) {
this.user = user!; // TODO: is this bang correct? this.user = user ?? null;
this.target = target!; // TODO: is this bang correct? this.target = target ?? null;
this.sprites = []; this.sprites = [];
} }

View File

@ -19,7 +19,7 @@ export function fetchDailyRunSeed(): Promise<string | null> {
return; return;
} }
return response.text(); return response.text();
}).then(seed => resolve(seed!)) // TODO: is this bang correct? }).then(seed => resolve(seed ?? null))
.catch(err => reject(err)); .catch(err => reject(err));
}); });
} }

View File

@ -343,7 +343,7 @@ export class InputsController {
// Sometimes, gamepads are undefined. For some reason. // Sometimes, gamepads are undefined. For some reason.
this.gamepads = this.scene.input.gamepad?.gamepads.filter(function (el) { this.gamepads = this.scene.input.gamepad?.gamepads.filter(function (el) {
return el !== null; return el !== null;
})!; // TODO: is this bang correct? }) ?? [];
for (const [index, thisGamepad] of this.gamepads.entries()) { for (const [index, thisGamepad] of this.gamepads.entries()) {
thisGamepad.index = index; // Overwrite the gamepad index, in case we had undefined gamepads earlier thisGamepad.index = index; // Overwrite the gamepad index, in case we had undefined gamepads earlier

View File

@ -10,7 +10,8 @@ import i18next from "i18next";
export function getPokemonNameWithAffix(pokemon: Pokemon | undefined): string { export function getPokemonNameWithAffix(pokemon: Pokemon | undefined): string {
if (!pokemon) { if (!pokemon) {
return "Missigno"; return "Missigno";
} // TODO: little easter-egg, lol }
switch (pokemon.scene.currentBattle.battleSpec) { switch (pokemon.scene.currentBattle.battleSpec) {
case BattleSpec.DEFAULT: case BattleSpec.DEFAULT:
return !pokemon.isPlayer() return !pokemon.isPlayer()

View File

@ -195,7 +195,7 @@ export class TitlePhase extends Phase {
this.scene.playBgm("title", true); this.scene.playBgm("title", true);
this.scene.gameData.getSession(loggedInUser!.lastSessionSlot).then(sessionData => { // TODO: is this bang correct? this.scene.gameData.getSession(loggedInUser?.lastSessionSlot ?? -1).then(sessionData => {
if (sessionData) { if (sessionData) {
this.lastSessionData = sessionData; this.lastSessionData = sessionData;
const biomeKey = getBiomeKey(sessionData.arena.biome); const biomeKey = getBiomeKey(sessionData.arena.biome);
@ -394,7 +394,11 @@ export class TitlePhase extends Phase {
// If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date. // If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date.
if (!Utils.isLocal) { if (!Utils.isLocal) {
fetchDailyRunSeed().then(seed => { fetchDailyRunSeed().then(seed => {
generateDaily(seed!); // TODO: is this bang correct? if (seed) {
generateDaily(seed);
} else {
throw new Error("Daily run seed is null!");
}
}).catch(err => { }).catch(err => {
console.error("Failed to load daily run:\n", err); console.error("Failed to load daily run:\n", err);
}); });
@ -468,7 +472,7 @@ export class ReloadSessionPhase extends Phase {
constructor(scene: BattleScene, systemDataStr?: string) { constructor(scene: BattleScene, systemDataStr?: string) {
super(scene); super(scene);
this.systemDataStr = systemDataStr!; // TODO: is this bang correct? this.systemDataStr = systemDataStr ?? null;
} }
start(): void { start(): void {