From e938ff608d9ae8f08b2b61a55ab23fcf019476c6 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:12:37 -0500 Subject: [PATCH] Make more arrays readonly --- src/data/abilities/ability.ts | 2 +- src/data/balance/pokemon-species.ts | 2 +- src/data/data-lists.ts | 6 +- src/data/moves/move.ts | 2 +- .../encounters/bug-type-superfan-encounter.ts | 69 +++++++------------ src/data/pokemon-forms.ts | 2 +- src/data/trainers/trainer-config.ts | 2 +- src/field/arena.ts | 2 +- src/utils/common.ts | 16 ++--- 9 files changed, 41 insertions(+), 62 deletions(-) diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index d602cfb9651..339a6cb7f79 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -6699,7 +6699,7 @@ function getPokemonWithWeatherBasedForms() { // biome-ignore format: prevent biome from removing the newlines (e.g. prevent `new Ability(...).attr(...)`) export function initAbilities() { - allAbilities.push( + (allAbilities as Ability[]).push( new Ability(AbilityId.NONE, 3), new Ability(AbilityId.STENCH, 3) .attr(PostAttackApplyBattlerTagAbAttr, false, (user, target, move) => !move.hasAttr("FlinchAttr") && !move.hitsSubstitute(user, target) ? 10 : 0, BattlerTagType.FLINCHED), diff --git a/src/data/balance/pokemon-species.ts b/src/data/balance/pokemon-species.ts index c6c17986257..1d89b77e98c 100644 --- a/src/data/balance/pokemon-species.ts +++ b/src/data/balance/pokemon-species.ts @@ -8,7 +8,7 @@ import { SpeciesId } from "#enums/species-id"; // biome-ignore format: manually formatted export function initSpecies() { - allSpecies.push( + (allSpecies as PokemonSpecies[]).push( new PokemonSpecies(SpeciesId.BULBASAUR, 1, false, false, false, "Seed Pokémon", PokemonType.GRASS, PokemonType.POISON, 0.7, 6.9, AbilityId.OVERGROW, AbilityId.NONE, AbilityId.CHLOROPHYLL, 318, 45, 49, 49, 65, 65, 45, 45, 50, 64, GrowthRate.MEDIUM_SLOW, 87.5, false), new PokemonSpecies(SpeciesId.IVYSAUR, 1, false, false, false, "Seed Pokémon", PokemonType.GRASS, PokemonType.POISON, 1, 13, AbilityId.OVERGROW, AbilityId.NONE, AbilityId.CHLOROPHYLL, 405, 60, 62, 63, 80, 80, 60, 45, 50, 142, GrowthRate.MEDIUM_SLOW, 87.5, false), new PokemonSpecies(SpeciesId.VENUSAUR, 1, false, false, false, "Seed Pokémon", PokemonType.GRASS, PokemonType.POISON, 2, 100, AbilityId.OVERGROW, AbilityId.NONE, AbilityId.CHLOROPHYLL, 525, 80, 82, 83, 100, 100, 80, 45, 50, 263, GrowthRate.MEDIUM_SLOW, 87.5, true, true, diff --git a/src/data/data-lists.ts b/src/data/data-lists.ts index ae3d0acc77f..7c9a9520735 100644 --- a/src/data/data-lists.ts +++ b/src/data/data-lists.ts @@ -3,9 +3,9 @@ import type { PokemonSpecies } from "#data/pokemon-species"; import type { ModifierTypes } from "#modifiers/modifier-type"; import type { Move } from "#moves/move"; -export const allAbilities: Ability[] = []; -export const allMoves: Move[] = []; -export const allSpecies: PokemonSpecies[] = []; +export const allAbilities: readonly Ability[] = []; +export const allMoves: readonly Move[] = []; +export const allSpecies: readonly PokemonSpecies[] = []; // TODO: Figure out what this is used for and provide an appropriate tsdoc comment export const modifierTypes = {} as ModifierTypes; diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 03d4efd65db..252bd5d6b4b 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -8394,7 +8394,7 @@ const MoveAttrs = Object.freeze({ export type MoveAttrConstructorMap = typeof MoveAttrs; export function initMoves() { - allMoves.push( + (allMoves as Move[]).push( new SelfStatusMove(MoveId.NONE, PokemonType.NORMAL, MoveCategory.STATUS, -1, -1, 0, 1), new AttackMove(MoveId.POUND, PokemonType.NORMAL, MoveCategory.PHYSICAL, 40, 100, 35, -1, 0, 1), new AttackMove(MoveId.KARATE_CHOP, PokemonType.FIGHTING, MoveCategory.PHYSICAL, 50, 100, 25, -1, 0, 1) diff --git a/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts b/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts index 00e98048ada..6ab029a7ff9 100644 --- a/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts +++ b/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts @@ -78,7 +78,7 @@ const POOL_1_POKEMON = [ SpeciesId.RIBOMBEE, SpeciesId.SPIDOPS, SpeciesId.LOKIX, -]; +] as const; const POOL_2_POKEMON = [ SpeciesId.SCYTHER, @@ -104,41 +104,20 @@ const POOL_2_POKEMON = [ SpeciesId.CENTISKORCH, SpeciesId.FROSMOTH, SpeciesId.KLEAVOR, -]; +] as const; -const POOL_3_POKEMON: { species: SpeciesId; formIndex?: number }[] = [ - { - species: SpeciesId.PINSIR, - formIndex: 1, - }, - { - species: SpeciesId.SCIZOR, - formIndex: 1, - }, - { - species: SpeciesId.HERACROSS, - formIndex: 1, - }, - { - species: SpeciesId.ORBEETLE, - formIndex: 1, - }, - { - species: SpeciesId.CENTISKORCH, - formIndex: 1, - }, - { - species: SpeciesId.DURANT, - }, - { - species: SpeciesId.VOLCARONA, - }, - { - species: SpeciesId.GOLISOPOD, - }, -]; +const POOL_3_POKEMON = [ + { species: SpeciesId.PINSIR, formIndex: 1 }, + { species: SpeciesId.SCIZOR, formIndex: 1 }, + { species: SpeciesId.HERACROSS, formIndex: 1 }, + { species: SpeciesId.ORBEETLE, formIndex: 1 }, + { species: SpeciesId.CENTISKORCH, formIndex: 1 }, + { species: SpeciesId.DURANT } as { species: SpeciesId.DURANT; formIndex: undefined }, + { species: SpeciesId.VOLCARONA } as { species: SpeciesId.VOLCARONA; formIndex: undefined }, + { species: SpeciesId.GOLISOPOD } as { species: SpeciesId.GOLISOPOD; formIndex: undefined }, +] as const; -const POOL_4_POKEMON = [SpeciesId.GENESECT, SpeciesId.SLITHER_WING, SpeciesId.BUZZWOLE, SpeciesId.PHEROMOSA]; +const POOL_4_POKEMON = [SpeciesId.GENESECT, SpeciesId.SLITHER_WING, SpeciesId.BUZZWOLE, SpeciesId.PHEROMOSA] as const; const PHYSICAL_TUTOR_MOVES = [ MoveId.MEGAHORN, @@ -146,7 +125,7 @@ const PHYSICAL_TUTOR_MOVES = [ MoveId.BUG_BITE, MoveId.FIRST_IMPRESSION, MoveId.LUNGE, -]; +] as const; const SPECIAL_TUTOR_MOVES = [ MoveId.SILVER_WIND, @@ -154,7 +133,7 @@ const SPECIAL_TUTOR_MOVES = [ MoveId.BUG_BUZZ, MoveId.POLLEN_PUFF, MoveId.STRUGGLE_BUG, -]; +] as const; const STATUS_TUTOR_MOVES = [ MoveId.STRING_SHOT, @@ -162,14 +141,20 @@ const STATUS_TUTOR_MOVES = [ MoveId.RAGE_POWDER, MoveId.STICKY_WEB, MoveId.SILK_TRAP, -]; +] as const; -const MISC_TUTOR_MOVES = [MoveId.LEECH_LIFE, MoveId.U_TURN, MoveId.HEAL_ORDER, MoveId.QUIVER_DANCE, MoveId.INFESTATION]; +const MISC_TUTOR_MOVES = [ + MoveId.LEECH_LIFE, + MoveId.U_TURN, + MoveId.HEAL_ORDER, + MoveId.QUIVER_DANCE, + MoveId.INFESTATION, +] as const; /** * Wave breakpoints that determine how strong to make the Bug-Type Superfan's team */ -const WAVE_LEVEL_BREAKPOINTS = [30, 50, 70, 100, 120, 140, 160]; +const WAVE_LEVEL_BREAKPOINTS = [30, 50, 70, 100, 120, 140, 160] as const; /** * Bug Type Superfan encounter. @@ -517,8 +502,8 @@ function getTrainerConfigForWave(waveIndex: number) { const config = trainerConfigs[TrainerType.BUG_TYPE_SUPERFAN].clone(); config.name = i18next.t("trainerNames:bugTypeSuperfan"); - let pool3Copy = POOL_3_POKEMON.slice(0); - pool3Copy = randSeedShuffle(pool3Copy); + const pool3Copy = randSeedShuffle(POOL_3_POKEMON.slice()); + // Bang is fine here, as we know pool3Copy has at least 1 entry const pool3Mon = pool3Copy.pop()!; if (waveIndex < WAVE_LEVEL_BREAKPOINTS[0]) { @@ -579,7 +564,6 @@ function getTrainerConfigForWave(waveIndex: number) { }), ); } else if (waveIndex < WAVE_LEVEL_BREAKPOINTS[5]) { - pool3Copy = randSeedShuffle(pool3Copy); const pool3Mon2 = pool3Copy.pop()!; config .setPartyTemplates(new TrainerPartyTemplate(5, PartyMemberStrength.AVERAGE)) @@ -657,7 +641,6 @@ function getTrainerConfigForWave(waveIndex: number) { ) .setPartyMemberFunc(4, getRandomPartyMemberFunc(POOL_4_POKEMON, TrainerSlot.TRAINER, true)); } else { - pool3Copy = randSeedShuffle(pool3Copy); const pool3Mon2 = pool3Copy.pop()!; config .setPartyTemplates( diff --git a/src/data/pokemon-forms.ts b/src/data/pokemon-forms.ts index 0517459aaa1..909967b84fa 100644 --- a/src/data/pokemon-forms.ts +++ b/src/data/pokemon-forms.ts @@ -35,7 +35,7 @@ export class SpeciesFormChange { public formKey: string; public trigger: SpeciesFormChangeTrigger; public quiet: boolean; - public readonly conditions: SpeciesFormChangeCondition[]; + public readonly conditions: readonly SpeciesFormChangeCondition[]; constructor( speciesId: SpeciesId, diff --git a/src/data/trainers/trainer-config.ts b/src/data/trainers/trainer-config.ts index 982ef989971..1e6e06abd10 100644 --- a/src/data/trainers/trainer-config.ts +++ b/src/data/trainers/trainer-config.ts @@ -1000,7 +1000,7 @@ let t = 0; * @param postProcess */ export function getRandomPartyMemberFunc( - speciesPool: SpeciesId[], + speciesPool: readonly SpeciesId[], trainerSlot: TrainerSlot = TrainerSlot.TRAINER, ignoreEvolution = false, postProcess?: (enemyPokemon: EnemyPokemon) => void, diff --git a/src/field/arena.ts b/src/field/arena.ts index d307ce9d0e8..4cd814ab907 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -588,7 +588,7 @@ export class Arena { overrideTint(): [number, number, number] { switch (Overrides.ARENA_TINT_OVERRIDE) { case TimeOfDay.DUSK: - return [98, 48, 73].map(c => Math.round((c + 128) / 2)) as [number, number, number]; + return [113, 88, 101]; case TimeOfDay.NIGHT: return [64, 64, 64]; case TimeOfDay.DAWN: diff --git a/src/utils/common.ts b/src/utils/common.ts index ae586b60455..61ce2177a1e 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -132,20 +132,16 @@ export function randSeedItem(items: ArrayLike): T { } /** - * Shuffle a list using the seeded rng. Utilises the Fisher-Yates algorithm. + * Shuffle a list in place using the seeded rng and the Fisher-Yates algorithm. * @param items An array of items. - * @returns A new shuffled array of items. + * @returns `items` shuffled in place. */ export function randSeedShuffle(items: T[]): T[] { - if (items.length <= 1) { - return items; - } - const newArray = items.slice(0); for (let i = items.length - 1; i > 0; i--) { const j = Phaser.Math.RND.integerInRange(0, i); - [newArray[i], newArray[j]] = [newArray[j], newArray[i]]; + [items[i], items[j]] = [items[j], items[i]]; } - return newArray; + return items; } export function getFrameMs(frameCount: number): number { @@ -338,7 +334,7 @@ export function rgbToHsv(r: number, g: number, b: number) { * @param rgb1 First RGB color in array * @param rgb2 Second RGB color in array */ -export function deltaRgb(rgb1: number[], rgb2: number[]): number { +export function deltaRgb(rgb1: readonly number[], rgb2: readonly number[]): number { const [r1, g1, b1] = rgb1; const [r2, g2, b2] = rgb2; const drp2 = Math.pow(r1 - r2, 2); @@ -362,7 +358,7 @@ export function rgbHexToRgba(hex: string) { }; } -export function rgbaToInt(rgba: number[]): number { +export function rgbaToInt(rgba: readonly number[]): number { return (rgba[0] << 24) + (rgba[1] << 16) + (rgba[2] << 8) + rgba[3]; }