mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-11 10:52:17 +02:00
[Refactor] Replace .fill().map
"loops" with real for
loops (#6071)
This commit is contained in:
parent
2fbaca7b5e
commit
9b0f0b7a0f
@ -15,7 +15,7 @@ import type { PokemonHeldItemModifier } from "#app/modifier/modifier";
|
||||
import { AbilityAttr } from "#enums/ability-attr";
|
||||
import PokemonData from "#app/system/pokemon-data";
|
||||
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 { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
@ -30,7 +30,7 @@ import i18next from "i18next";
|
||||
import { getStatKey } from "#enums/stat";
|
||||
import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants";
|
||||
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 */
|
||||
const namespace = "mysteryEncounters/trainingSession";
|
||||
@ -184,10 +184,9 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
|
||||
.withPreOptionPhase(async (): Promise<boolean> => {
|
||||
// Open menu for selecting pokemon and Nature
|
||||
const encounter = globalScene.currentBattle.mysteryEncounter!;
|
||||
const natures = new Array(25).fill(null).map((_val, i) => i as Nature);
|
||||
const onPokemonSelected = (pokemon: PlayerPokemon) => {
|
||||
// Return the options for nature selection
|
||||
return natures.map((nature: Nature) => {
|
||||
return getEnumValues(Nature).map((nature: Nature) => {
|
||||
const option: OptionSelectItem = {
|
||||
label: getNatureName(nature, true, true, true, globalScene.uiTheme),
|
||||
handler: () => {
|
||||
|
@ -150,7 +150,7 @@ function doFanOutParticle(
|
||||
}
|
||||
|
||||
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");
|
||||
particle.setOrigin(pokeball.originX, pokeball.originY);
|
||||
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 {
|
||||
|
@ -981,14 +981,15 @@ export class ArenaBase extends Phaser.GameObjects.Container {
|
||||
this.base = globalScene.addFieldSprite(0, 0, "plains_a", undefined, 1);
|
||||
this.base.setOrigin(0, 0);
|
||||
|
||||
this.props = !player
|
||||
? new Array(3).fill(null).map(() => {
|
||||
const ret = globalScene.addFieldSprite(0, 0, "plains_b", undefined, 1);
|
||||
ret.setOrigin(0, 0);
|
||||
ret.setVisible(false);
|
||||
return ret;
|
||||
})
|
||||
: [];
|
||||
this.props = [];
|
||||
if (!player) {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const ret = globalScene.addFieldSprite(0, 0, "plains_b", undefined, 1);
|
||||
ret.setOrigin(0, 0);
|
||||
ret.setVisible(false);
|
||||
this.props.push(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setBiome(biome: BiomeId, propValue?: number): void {
|
||||
|
@ -2457,12 +2457,31 @@ export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: Mod
|
||||
}
|
||||
|
||||
export interface CustomModifierSettings {
|
||||
/** If specified, will override the next X items to be the specified tier. These can upgrade with luck. */
|
||||
guaranteedModifierTiers?: ModifierTier[];
|
||||
/** If specified, will override the first X items to be specific modifier options (these should be pre-genned). */
|
||||
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[];
|
||||
/**
|
||||
* 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;
|
||||
/** 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;
|
||||
/**
|
||||
* If `false`, will prevent set item tiers from upgrading via luck.
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
allowLuckUpgrades?: boolean;
|
||||
}
|
||||
|
||||
@ -2472,19 +2491,10 @@ export function getModifierTypeFuncById(id: string): ModifierTypeFunc {
|
||||
|
||||
/**
|
||||
* Generates modifier options for a {@linkcode SelectModifierPhase}
|
||||
* @param count Determines the number of items to generate
|
||||
* @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 customModifierSettings (Optional) If specified, can customize the item shop rewards further.
|
||||
* - `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
|
||||
* @param count - Determines the number of items to generate
|
||||
* @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 customModifierSettings - See {@linkcode CustomModifierSettings}
|
||||
*/
|
||||
export function getPlayerModifierTypeOptions(
|
||||
count: number,
|
||||
@ -2495,16 +2505,10 @@ export function getPlayerModifierTypeOptions(
|
||||
const options: ModifierTypeOption[] = [];
|
||||
const retryCount = Math.min(count * 5, 50);
|
||||
if (!customModifierSettings) {
|
||||
new Array(count).fill(0).map((_, i) => {
|
||||
options.push(
|
||||
getModifierTypeOptionWithRetry(
|
||||
options,
|
||||
retryCount,
|
||||
party,
|
||||
modifierTiers && modifierTiers.length > i ? modifierTiers[i] : undefined,
|
||||
),
|
||||
);
|
||||
});
|
||||
for (let i = 0; i < count; i++) {
|
||||
const tier = modifierTiers && modifierTiers.length > i ? modifierTiers[i] : undefined;
|
||||
options.push(getModifierTypeOptionWithRetry(options, retryCount, party, tier));
|
||||
}
|
||||
} else {
|
||||
// Guaranteed mod options first
|
||||
if (
|
||||
|
@ -11,25 +11,22 @@ import { PlayerGender } from "#enums/player-gender";
|
||||
import { ShopCursorTarget } from "#enums/shop-cursor-target";
|
||||
import { isLocal } from "#app/utils/common";
|
||||
|
||||
const VOLUME_OPTIONS: SettingOption[] = new Array(11).fill(null).map((_, i) =>
|
||||
i
|
||||
? {
|
||||
value: (i * 10).toString(),
|
||||
label: (i * 10).toString(),
|
||||
}
|
||||
: {
|
||||
value: "Mute",
|
||||
label: i18next.t("settings:mute"),
|
||||
},
|
||||
);
|
||||
const VOLUME_OPTIONS: SettingOption[] = [
|
||||
{
|
||||
value: "Mute",
|
||||
label: i18next.t("settings:mute"),
|
||||
},
|
||||
];
|
||||
for (let i = 1; i < 11; i++) {
|
||||
const value = (i * 10).toString();
|
||||
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();
|
||||
return {
|
||||
value,
|
||||
label: value,
|
||||
};
|
||||
});
|
||||
SHOP_OVERLAY_OPACITY_OPTIONS.push({ value, label: value });
|
||||
}
|
||||
|
||||
const OFF_ON: SettingOption[] = [
|
||||
{
|
||||
@ -183,6 +180,12 @@ export enum MusicPreference {
|
||||
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
|
||||
*/
|
||||
@ -432,13 +435,7 @@ export const Setting: Array<Setting> = [
|
||||
{
|
||||
key: SettingKeys.Window_Type,
|
||||
label: i18next.t("settings:windowType"),
|
||||
options: new Array(5).fill(null).map((_, i) => {
|
||||
const windowType = (i + 1).toString();
|
||||
return {
|
||||
value: windowType,
|
||||
label: windowType,
|
||||
};
|
||||
}),
|
||||
options: windowTypeOptions,
|
||||
default: 0,
|
||||
type: SettingType.DISPLAY,
|
||||
},
|
||||
|
@ -299,8 +299,8 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
|
||||
this.eggGachaContainer.add(this.eggGachaOptionsContainer);
|
||||
|
||||
new Array(getEnumKeys(VoucherType).length).fill(null).map((_, i) => {
|
||||
const container = globalScene.add.container(globalScene.game.canvas.width / 6 - 56 * i, 0);
|
||||
for (const voucher of getEnumValues(VoucherType)) {
|
||||
const container = globalScene.add.container(globalScene.game.canvas.width / 6 - 56 * voucher, 0);
|
||||
|
||||
const bg = addWindow(0, 0, 56, 22);
|
||||
bg.setOrigin(1, 0);
|
||||
@ -312,7 +312,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
|
||||
this.voucherCountLabels.push(countLabel);
|
||||
|
||||
const iconImage = getVoucherTypeIcon(i as VoucherType);
|
||||
const iconImage = getVoucherTypeIcon(voucher);
|
||||
|
||||
const icon = globalScene.add.sprite(-19, 2, "items", iconImage);
|
||||
icon.setOrigin(0, 0);
|
||||
@ -320,7 +320,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
container.add(icon);
|
||||
|
||||
this.eggGachaContainer.add(container);
|
||||
});
|
||||
}
|
||||
|
||||
this.eggGachaOverlay = globalScene.add.rectangle(0, 0, bg.displayWidth, bg.displayHeight, 0x000000);
|
||||
this.eggGachaOverlay.setOrigin(0, 0);
|
||||
|
@ -267,10 +267,10 @@ export default class GameStatsUiHandler extends UiHandler {
|
||||
|
||||
this.statsContainer = globalScene.add.container(0, 0);
|
||||
|
||||
new Array(18).fill(null).map((_, s) => {
|
||||
for (let i = 0; i < 18; i++) {
|
||||
const statLabel = addTextObject(
|
||||
8 + (s % 2 === 1 ? statsBgWidth : 0),
|
||||
28 + Math.floor(s / 2) * 16,
|
||||
8 + (i % 2 === 1 ? statsBgWidth : 0),
|
||||
28 + Math.floor(i / 2) * 16,
|
||||
"",
|
||||
TextStyle.STATS_LABEL,
|
||||
);
|
||||
@ -278,11 +278,11 @@ export default class GameStatsUiHandler extends UiHandler {
|
||||
this.statsContainer.add(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);
|
||||
this.statsContainer.add(statValue);
|
||||
this.statValues.push(statValue);
|
||||
});
|
||||
}
|
||||
|
||||
this.gameStatsContainer.add(headerBg);
|
||||
this.gameStatsContainer.add(headerText);
|
||||
|
@ -483,13 +483,14 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
|
||||
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");
|
||||
cursorObj.setVisible(false);
|
||||
cursorObj.setOrigin(0, 0);
|
||||
starterBoxContainer.add(cursorObj);
|
||||
return cursorObj;
|
||||
});
|
||||
this.pokerusCursorObjs.push(cursorObj);
|
||||
}
|
||||
|
||||
this.cursorObj = globalScene.add.image(0, 0, "select_cursor");
|
||||
this.cursorObj.setOrigin(0, 0);
|
||||
|
@ -800,21 +800,23 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
|
||||
|
||||
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");
|
||||
cursorObj.setVisible(false);
|
||||
cursorObj.setOrigin(0, 0);
|
||||
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");
|
||||
cursorObj.setVisible(false);
|
||||
cursorObj.setOrigin(0, 0);
|
||||
starterBoxContainer.add(cursorObj);
|
||||
return cursorObj;
|
||||
});
|
||||
this.starterCursorObjs.push(cursorObj);
|
||||
}
|
||||
|
||||
this.cursorObj = globalScene.add.image(0, 0, "select_cursor");
|
||||
this.cursorObj.setOrigin(0, 0);
|
||||
@ -843,15 +845,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
|
||||
|
||||
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");
|
||||
icon.setScale(0.5);
|
||||
icon.setOrigin(0, 0);
|
||||
icon.setFrame("unknown");
|
||||
this.starterSelectContainer.add(icon);
|
||||
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.PASSIVE);
|
||||
return icon;
|
||||
});
|
||||
this.starterIcons.push(icon);
|
||||
}
|
||||
|
||||
this.type1Icon = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types"));
|
||||
this.type1Icon.setScale(0.5);
|
||||
|
@ -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 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 {
|
||||
private showDiff: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user