[Refactor] Replace .fill().map "loops" with real for loops (#6071)

This commit is contained in:
NightKev 2025-07-08 00:53:36 -07:00 committed by GitHub
parent 2fbaca7b5e
commit 9b0f0b7a0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 91 additions and 84 deletions

View File

@ -15,7 +15,7 @@ import type { PokemonHeldItemModifier } from "#app/modifier/modifier";
import { AbilityAttr } from "#enums/ability-attr"; import { AbilityAttr } from "#enums/ability-attr";
import PokemonData from "#app/system/pokemon-data"; import PokemonData from "#app/system/pokemon-data";
import type { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import type { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler";
import { isNullOrUndefined, randSeedShuffle } from "#app/utils/common"; import { getEnumValues, isNullOrUndefined, randSeedShuffle } from "#app/utils/common";
import { BattlerTagType } from "#enums/battler-tag-type"; import { BattlerTagType } from "#enums/battler-tag-type";
import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import { globalScene } from "#app/global-scene"; import { globalScene } from "#app/global-scene";
@ -30,7 +30,7 @@ import i18next from "i18next";
import { getStatKey } from "#enums/stat"; import { getStatKey } from "#enums/stat";
import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants";
import { isPokemonValidForEncounterOptionSelection } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; import { isPokemonValidForEncounterOptionSelection } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils";
import type { Nature } from "#enums/nature"; import { Nature } from "#enums/nature";
/** The i18n namespace for the encounter */ /** The i18n namespace for the encounter */
const namespace = "mysteryEncounters/trainingSession"; const namespace = "mysteryEncounters/trainingSession";
@ -184,10 +184,9 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
.withPreOptionPhase(async (): Promise<boolean> => { .withPreOptionPhase(async (): Promise<boolean> => {
// Open menu for selecting pokemon and Nature // Open menu for selecting pokemon and Nature
const encounter = globalScene.currentBattle.mysteryEncounter!; const encounter = globalScene.currentBattle.mysteryEncounter!;
const natures = new Array(25).fill(null).map((_val, i) => i as Nature);
const onPokemonSelected = (pokemon: PlayerPokemon) => { const onPokemonSelected = (pokemon: PlayerPokemon) => {
// Return the options for nature selection // Return the options for nature selection
return natures.map((nature: Nature) => { return getEnumValues(Nature).map((nature: Nature) => {
const option: OptionSelectItem = { const option: OptionSelectItem = {
label: getNatureName(nature, true, true, true, globalScene.uiTheme), label: getNatureName(nature, true, true, true, globalScene.uiTheme),
handler: () => { handler: () => {

View File

@ -150,7 +150,7 @@ function doFanOutParticle(
} }
export function addPokeballCaptureStars(pokeball: Phaser.GameObjects.Sprite): void { export function addPokeballCaptureStars(pokeball: Phaser.GameObjects.Sprite): void {
const addParticle = () => { const addParticle = (): void => {
const particle = globalScene.add.sprite(pokeball.x, pokeball.y, "pb_particles", "4.png"); const particle = globalScene.add.sprite(pokeball.x, pokeball.y, "pb_particles", "4.png");
particle.setOrigin(pokeball.originX, pokeball.originY); particle.setOrigin(pokeball.originX, pokeball.originY);
particle.setAlpha(0.5); particle.setAlpha(0.5);
@ -188,7 +188,9 @@ export function addPokeballCaptureStars(pokeball: Phaser.GameObjects.Sprite): vo
}); });
}; };
new Array(3).fill(null).map(() => addParticle()); for (let i = 0; i < 3; i++) {
addParticle();
}
} }
export function sin(index: number, amplitude: number): number { export function sin(index: number, amplitude: number): number {

View File

@ -981,14 +981,15 @@ export class ArenaBase extends Phaser.GameObjects.Container {
this.base = globalScene.addFieldSprite(0, 0, "plains_a", undefined, 1); this.base = globalScene.addFieldSprite(0, 0, "plains_a", undefined, 1);
this.base.setOrigin(0, 0); this.base.setOrigin(0, 0);
this.props = !player this.props = [];
? new Array(3).fill(null).map(() => { if (!player) {
const ret = globalScene.addFieldSprite(0, 0, "plains_b", undefined, 1); for (let i = 0; i < 3; i++) {
ret.setOrigin(0, 0); const ret = globalScene.addFieldSprite(0, 0, "plains_b", undefined, 1);
ret.setVisible(false); ret.setOrigin(0, 0);
return ret; ret.setVisible(false);
}) this.props.push(ret);
: []; }
}
} }
setBiome(biome: BiomeId, propValue?: number): void { setBiome(biome: BiomeId, propValue?: number): void {

View File

@ -2457,12 +2457,31 @@ export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: Mod
} }
export interface CustomModifierSettings { export interface CustomModifierSettings {
/** If specified, will override the next X items to be the specified tier. These can upgrade with luck. */
guaranteedModifierTiers?: ModifierTier[]; guaranteedModifierTiers?: ModifierTier[];
/** If specified, will override the first X items to be specific modifier options (these should be pre-genned). */
guaranteedModifierTypeOptions?: ModifierTypeOption[]; guaranteedModifierTypeOptions?: ModifierTypeOption[];
/** If specified, will override the next X items to be auto-generated from specific modifier functions (these don't have to be pre-genned). */
guaranteedModifierTypeFuncs?: ModifierTypeFunc[]; guaranteedModifierTypeFuncs?: ModifierTypeFunc[];
/**
* If set to `true`, will fill the remainder of shop items that were not overridden by the 3 options above, up to the `count` param value.
* @example
* ```ts
* count = 4;
* customModifierSettings = { guaranteedModifierTiers: [ModifierTier.GREAT], fillRemaining: true };
* ```
* The first item in the shop will be `GREAT` tier, and the remaining `3` items will be generated normally.
*
* If `fillRemaining: false` in the same scenario, only 1 `GREAT` tier item will appear in the shop (regardless of the value of `count`).
* @defaultValue `false`
*/
fillRemaining?: boolean; fillRemaining?: boolean;
/** Set to negative value to disable rerolls completely in shop */ /** If specified, can adjust the amount of money required for a shop reroll. If set to a negative value, the shop will not allow rerolls at all. */
rerollMultiplier?: number; rerollMultiplier?: number;
/**
* If `false`, will prevent set item tiers from upgrading via luck.
* @defaultValue `true`
*/
allowLuckUpgrades?: boolean; allowLuckUpgrades?: boolean;
} }
@ -2472,19 +2491,10 @@ export function getModifierTypeFuncById(id: string): ModifierTypeFunc {
/** /**
* Generates modifier options for a {@linkcode SelectModifierPhase} * Generates modifier options for a {@linkcode SelectModifierPhase}
* @param count Determines the number of items to generate * @param count - Determines the number of items to generate
* @param party Party is required for generating proper modifier pools * @param party - Party is required for generating proper modifier pools
* @param modifierTiers (Optional) If specified, rolls items in the specified tiers. Commonly used for tier-locking with Lock Capsule. * @param modifierTiers - (Optional) If specified, rolls items in the specified tiers. Commonly used for tier-locking with Lock Capsule.
* @param customModifierSettings (Optional) If specified, can customize the item shop rewards further. * @param customModifierSettings - See {@linkcode CustomModifierSettings}
* - `guaranteedModifierTypeOptions?: ModifierTypeOption[]` If specified, will override the first X items to be specific modifier options (these should be pre-genned).
* - `guaranteedModifierTypeFuncs?: ModifierTypeFunc[]` If specified, will override the next X items to be auto-generated from specific modifier functions (these don't have to be pre-genned).
* - `guaranteedModifierTiers?: ModifierTier[]` If specified, will override the next X items to be the specified tier. These can upgrade with luck.
* - `fillRemaining?: boolean` Default 'false'. If set to true, will fill the remainder of shop items that were not overridden by the 3 options above, up to the 'count' param value.
* - Example: `count = 4`, `customModifierSettings = { guaranteedModifierTiers: [ModifierTier.GREAT], fillRemaining: true }`,
* - The first item in the shop will be `GREAT` tier, and the remaining 3 items will be generated normally.
* - If `fillRemaining = false` in the same scenario, only 1 `GREAT` tier item will appear in the shop (regardless of `count` value).
* - `rerollMultiplier?: number` If specified, can adjust the amount of money required for a shop reroll. If set to a negative value, the shop will not allow rerolls at all.
* - `allowLuckUpgrades?: boolean` Default `true`, if `false` will prevent set item tiers from upgrading via luck
*/ */
export function getPlayerModifierTypeOptions( export function getPlayerModifierTypeOptions(
count: number, count: number,
@ -2495,16 +2505,10 @@ export function getPlayerModifierTypeOptions(
const options: ModifierTypeOption[] = []; const options: ModifierTypeOption[] = [];
const retryCount = Math.min(count * 5, 50); const retryCount = Math.min(count * 5, 50);
if (!customModifierSettings) { if (!customModifierSettings) {
new Array(count).fill(0).map((_, i) => { for (let i = 0; i < count; i++) {
options.push( const tier = modifierTiers && modifierTiers.length > i ? modifierTiers[i] : undefined;
getModifierTypeOptionWithRetry( options.push(getModifierTypeOptionWithRetry(options, retryCount, party, tier));
options, }
retryCount,
party,
modifierTiers && modifierTiers.length > i ? modifierTiers[i] : undefined,
),
);
});
} else { } else {
// Guaranteed mod options first // Guaranteed mod options first
if ( if (

View File

@ -11,25 +11,22 @@ import { PlayerGender } from "#enums/player-gender";
import { ShopCursorTarget } from "#enums/shop-cursor-target"; import { ShopCursorTarget } from "#enums/shop-cursor-target";
import { isLocal } from "#app/utils/common"; import { isLocal } from "#app/utils/common";
const VOLUME_OPTIONS: SettingOption[] = new Array(11).fill(null).map((_, i) => const VOLUME_OPTIONS: SettingOption[] = [
i {
? { value: "Mute",
value: (i * 10).toString(), label: i18next.t("settings:mute"),
label: (i * 10).toString(), },
} ];
: { for (let i = 1; i < 11; i++) {
value: "Mute", const value = (i * 10).toString();
label: i18next.t("settings:mute"), VOLUME_OPTIONS.push({ value, label: value });
}, }
);
const SHOP_OVERLAY_OPACITY_OPTIONS: SettingOption[] = new Array(9).fill(null).map((_, i) => { const SHOP_OVERLAY_OPACITY_OPTIONS: SettingOption[] = [];
for (let i = 0; i < 9; i++) {
const value = ((i + 1) * 10).toString(); const value = ((i + 1) * 10).toString();
return { SHOP_OVERLAY_OPACITY_OPTIONS.push({ value, label: value });
value, }
label: value,
};
});
const OFF_ON: SettingOption[] = [ const OFF_ON: SettingOption[] = [
{ {
@ -183,6 +180,12 @@ export enum MusicPreference {
ALLGENS, ALLGENS,
} }
const windowTypeOptions: SettingOption[] = [];
for (let i = 0; i < 5; i++) {
const value = (i + 1).toString();
windowTypeOptions.push({ value, label: value });
}
/** /**
* All Settings not related to controls * All Settings not related to controls
*/ */
@ -432,13 +435,7 @@ export const Setting: Array<Setting> = [
{ {
key: SettingKeys.Window_Type, key: SettingKeys.Window_Type,
label: i18next.t("settings:windowType"), label: i18next.t("settings:windowType"),
options: new Array(5).fill(null).map((_, i) => { options: windowTypeOptions,
const windowType = (i + 1).toString();
return {
value: windowType,
label: windowType,
};
}),
default: 0, default: 0,
type: SettingType.DISPLAY, type: SettingType.DISPLAY,
}, },

View File

@ -299,8 +299,8 @@ export default class EggGachaUiHandler extends MessageUiHandler {
this.eggGachaContainer.add(this.eggGachaOptionsContainer); this.eggGachaContainer.add(this.eggGachaOptionsContainer);
new Array(getEnumKeys(VoucherType).length).fill(null).map((_, i) => { for (const voucher of getEnumValues(VoucherType)) {
const container = globalScene.add.container(globalScene.game.canvas.width / 6 - 56 * i, 0); const container = globalScene.add.container(globalScene.game.canvas.width / 6 - 56 * voucher, 0);
const bg = addWindow(0, 0, 56, 22); const bg = addWindow(0, 0, 56, 22);
bg.setOrigin(1, 0); bg.setOrigin(1, 0);
@ -312,7 +312,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
this.voucherCountLabels.push(countLabel); this.voucherCountLabels.push(countLabel);
const iconImage = getVoucherTypeIcon(i as VoucherType); const iconImage = getVoucherTypeIcon(voucher);
const icon = globalScene.add.sprite(-19, 2, "items", iconImage); const icon = globalScene.add.sprite(-19, 2, "items", iconImage);
icon.setOrigin(0, 0); icon.setOrigin(0, 0);
@ -320,7 +320,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
container.add(icon); container.add(icon);
this.eggGachaContainer.add(container); this.eggGachaContainer.add(container);
}); }
this.eggGachaOverlay = globalScene.add.rectangle(0, 0, bg.displayWidth, bg.displayHeight, 0x000000); this.eggGachaOverlay = globalScene.add.rectangle(0, 0, bg.displayWidth, bg.displayHeight, 0x000000);
this.eggGachaOverlay.setOrigin(0, 0); this.eggGachaOverlay.setOrigin(0, 0);

View File

@ -267,10 +267,10 @@ export default class GameStatsUiHandler extends UiHandler {
this.statsContainer = globalScene.add.container(0, 0); this.statsContainer = globalScene.add.container(0, 0);
new Array(18).fill(null).map((_, s) => { for (let i = 0; i < 18; i++) {
const statLabel = addTextObject( const statLabel = addTextObject(
8 + (s % 2 === 1 ? statsBgWidth : 0), 8 + (i % 2 === 1 ? statsBgWidth : 0),
28 + Math.floor(s / 2) * 16, 28 + Math.floor(i / 2) * 16,
"", "",
TextStyle.STATS_LABEL, TextStyle.STATS_LABEL,
); );
@ -278,11 +278,11 @@ export default class GameStatsUiHandler extends UiHandler {
this.statsContainer.add(statLabel); this.statsContainer.add(statLabel);
this.statLabels.push(statLabel); this.statLabels.push(statLabel);
const statValue = addTextObject(statsBgWidth * ((s % 2) + 1) - 8, statLabel.y, "", TextStyle.STATS_VALUE); const statValue = addTextObject(statsBgWidth * ((i % 2) + 1) - 8, statLabel.y, "", TextStyle.STATS_VALUE);
statValue.setOrigin(1, 0); statValue.setOrigin(1, 0);
this.statsContainer.add(statValue); this.statsContainer.add(statValue);
this.statValues.push(statValue); this.statValues.push(statValue);
}); }
this.gameStatsContainer.add(headerBg); this.gameStatsContainer.add(headerBg);
this.gameStatsContainer.add(headerText); this.gameStatsContainer.add(headerText);

View File

@ -483,13 +483,14 @@ export default class PokedexUiHandler extends MessageUiHandler {
starterBoxContainer.add(this.starterSelectScrollBar); starterBoxContainer.add(this.starterSelectScrollBar);
this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { this.pokerusCursorObjs = [];
for (let i = 0; i < POKERUS_STARTER_COUNT; i++) {
const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus");
cursorObj.setVisible(false); cursorObj.setVisible(false);
cursorObj.setOrigin(0, 0); cursorObj.setOrigin(0, 0);
starterBoxContainer.add(cursorObj); starterBoxContainer.add(cursorObj);
return cursorObj; this.pokerusCursorObjs.push(cursorObj);
}); }
this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj = globalScene.add.image(0, 0, "select_cursor");
this.cursorObj.setOrigin(0, 0); this.cursorObj.setOrigin(0, 0);

View File

@ -800,21 +800,23 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
starterBoxContainer.add(this.starterSelectScrollBar); starterBoxContainer.add(this.starterSelectScrollBar);
this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { this.pokerusCursorObjs = [];
for (let i = 0; i < POKERUS_STARTER_COUNT; i++) {
const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus");
cursorObj.setVisible(false); cursorObj.setVisible(false);
cursorObj.setOrigin(0, 0); cursorObj.setOrigin(0, 0);
starterBoxContainer.add(cursorObj); starterBoxContainer.add(cursorObj);
return cursorObj; this.pokerusCursorObjs.push(cursorObj);
}); }
this.starterCursorObjs = new Array(6).fill(null).map(() => { this.starterCursorObjs = [];
for (let i = 0; i < 6; i++) {
const cursorObj = globalScene.add.image(0, 0, "select_cursor_highlight"); const cursorObj = globalScene.add.image(0, 0, "select_cursor_highlight");
cursorObj.setVisible(false); cursorObj.setVisible(false);
cursorObj.setOrigin(0, 0); cursorObj.setOrigin(0, 0);
starterBoxContainer.add(cursorObj); starterBoxContainer.add(cursorObj);
return cursorObj; this.starterCursorObjs.push(cursorObj);
}); }
this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj = globalScene.add.image(0, 0, "select_cursor");
this.cursorObj.setOrigin(0, 0); this.cursorObj.setOrigin(0, 0);
@ -843,15 +845,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.starterSelectContainer.add(starterBoxContainer); this.starterSelectContainer.add(starterBoxContainer);
this.starterIcons = new Array(6).fill(null).map((_, i) => { this.starterIcons = [];
for (let i = 0; i < 6; i++) {
const icon = globalScene.add.sprite(teamWindowX + 7, calcStarterIconY(i), "pokemon_icons_0"); const icon = globalScene.add.sprite(teamWindowX + 7, calcStarterIconY(i), "pokemon_icons_0");
icon.setScale(0.5); icon.setScale(0.5);
icon.setOrigin(0, 0); icon.setOrigin(0, 0);
icon.setFrame("unknown"); icon.setFrame("unknown");
this.starterSelectContainer.add(icon); this.starterSelectContainer.add(icon);
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.PASSIVE); this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.PASSIVE);
return icon; this.starterIcons.push(icon);
}); }
this.type1Icon = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types")); this.type1Icon = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types"));
this.type1Icon.setScale(0.5); this.type1Icon.setScale(0.5);

View File

@ -19,7 +19,7 @@ const ivLabelOffset = [0, sideLabelOffset, -sideLabelOffset, sideLabelOffset, -s
const ivChartLabelyOffset = [0, 5, 0, 5, 0, 0]; // doing this so attack does not overlap with (+N) const ivChartLabelyOffset = [0, 5, 0, 5, 0, 0]; // doing this so attack does not overlap with (+N)
const ivChartStatIndexes = [0, 1, 2, 5, 4, 3]; // swap special attack and speed const ivChartStatIndexes = [0, 1, 2, 5, 4, 3]; // swap special attack and speed
const defaultIvChartData = new Array(12).fill(null).map(() => 0); const defaultIvChartData: number[] = new Array(12).fill(0);
export class StatsContainer extends Phaser.GameObjects.Container { export class StatsContainer extends Phaser.GameObjects.Container {
private showDiff: boolean; private showDiff: boolean;