Skip to content

Commit

Permalink
Convert overly long import lines to multi-line imports
Browse files Browse the repository at this point in the history
This should hopefully prevent most merge conflicts with imports

- Replace `* as Utils` with `{ ... }`

- Add `#phases`, `#mystery-encounters`, `#balance` import mappings

- Replace many instances of relative with absolute imports
  • Loading branch information
DayKev committed Oct 22, 2024
1 parent c2eb9de commit 852a083
Show file tree
Hide file tree
Showing 433 changed files with 3,509 additions and 2,742 deletions.
6 changes: 3 additions & 3 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bypassLogin } from "./battle-scene";
import * as Utils from "./utils";
import { randomString, apiFetch } from "#app/utils";

export interface UserInfo {
username: string;
Expand All @@ -11,7 +11,7 @@ export interface UserInfo {

export let loggedInUser: UserInfo | null = null;
// This is a random string that is used to identify the client session - unique per session (tab or window) so that the game will only save on the one that the server is expecting
export const clientSessionId = Utils.randomString(32);
export const clientSessionId = randomString(32);

export function initLoggedInUser(): void {
loggedInUser = { username: "Guest", lastSessionSlot: -1, discordId: "", googleId: "", hasAdminRole: false };
Expand Down Expand Up @@ -43,7 +43,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
});
return resolve([ true, 200 ]);
}
Utils.apiFetch("account/info", true).then(response => {
apiFetch("account/info", true).then(response => {
if (!response.ok) {
resolve([ false, response.status ]);
return;
Expand Down
226 changes: 150 additions & 76 deletions src/battle-scene.ts

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions src/battle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import BattleScene from "./battle-scene";
import { Command } from "./ui/command-ui-handler";
import * as Utils from "./utils";
import { Command } from "#app/ui/command-ui-handler";
import {
randomString,
getEnumValues,
IntegerHolder,
randSeedInt,
shiftCharCodes,
randSeedItem,
randInt,
} from "#app/utils";
import Trainer, { TrainerVariant } from "./field/trainer";
import { GameMode } from "./game-mode";
import { MoneyMultiplierModifier, PokemonHeldItemModifier } from "./modifier/modifier";
import { PokeballType } from "./data/pokeball";
import { GameMode } from "#app/game-mode";
import { MoneyMultiplierModifier, PokemonHeldItemModifier } from "#app/modifier/modifier";
import { PokeballType } from "#app/data/pokeball";
import { trainerConfigs } from "#app/data/trainer-config";
import Pokemon, { EnemyPokemon, PlayerPokemon, QueuedMove } from "#app/field/pokemon";
import { ArenaTagType } from "#enums/arena-tag-type";
Expand All @@ -14,7 +22,7 @@ import { PlayerGender } from "#enums/player-gender";
import { Species } from "#enums/species";
import { TrainerType } from "#enums/trainer-type";
import i18next from "#app/plugins/i18n";
import MysteryEncounter from "#app/data/mystery-encounters/mystery-encounter";
import MysteryEncounter from "#mystery-encounters/mystery-encounter";
import { MysteryEncounterMode } from "#enums/mystery-encounter-mode";
import { CustomModifierSettings } from "#app/modifier/modifier-type";
import { ModifierTier } from "#app/modifier/modifier-tier";
Expand Down Expand Up @@ -78,7 +86,7 @@ export default class Battle {
public postBattleLoot: PokemonHeldItemModifier[] = [];
public escapeAttempts: number = 0;
public lastMove: Moves;
public battleSeed: string = Utils.randomString(16, true);
public battleSeed: string = randomString(16, true);
private battleSeedState: string | null = null;
public moneyScattered: number = 0;
public lastUsedPokeball: PokeballType | null = null;
Expand Down Expand Up @@ -154,7 +162,7 @@ export default class Battle {

incrementTurn(scene: BattleScene): void {
this.turn++;
this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
this.turnCommands = Object.fromEntries(getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
this.battleSeedState = null;
}

Expand All @@ -176,7 +184,7 @@ export default class Battle {
}

pickUpScatteredMoney(scene: BattleScene): void {
const moneyAmount = new Utils.IntegerHolder(scene.currentBattle.moneyScattered);
const moneyAmount = new IntegerHolder(scene.currentBattle.moneyScattered);
scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount);

if (scene.arena.getTag(ArenaTagType.HAPPY_HOUR)) {
Expand Down Expand Up @@ -382,7 +390,7 @@ export default class Battle {
}

/**
* Generates a random number using the current battle's seed. Calls {@linkcode Utils.randSeedInt}
* Generates a random number using the current battle's seed. Calls {@linkcode randSeedInt}
* @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min}
* @param min The minimum integer to pick, default `0`
* @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1)
Expand All @@ -397,12 +405,12 @@ export default class Battle {
if (this.battleSeedState) {
Phaser.Math.RND.state(this.battleSeedState);
} else {
Phaser.Math.RND.sow([ Utils.shiftCharCodes(this.battleSeed, this.turn << 6) ]);
Phaser.Math.RND.sow([ shiftCharCodes(this.battleSeed, this.turn << 6) ]);
console.log("Battle Seed:", this.battleSeed);
}
scene.rngCounter = this.rngCounter++;
scene.rngSeedOverride = this.battleSeed;
const ret = Utils.randSeedInt(range, min);
const ret = randSeedInt(range, min);
this.battleSeedState = Phaser.Math.RND.state();
Phaser.Math.RND.state(state);
scene.rngCounter = tempRngCounter;
Expand Down Expand Up @@ -479,29 +487,29 @@ export class FixedBattleConfig {
*/
function getRandomTrainerFunc(trainerPool: (TrainerType | TrainerType[])[], randomGender: boolean = false, seedOffset: number = 0): GetTrainerFunc {
return (scene: BattleScene) => {
const rand = Utils.randSeedInt(trainerPool.length);
const rand = randSeedInt(trainerPool.length);
const trainerTypes: TrainerType[] = [];

scene.executeWithSeedOffset(() => {
for (const trainerPoolEntry of trainerPool) {
const trainerType = Array.isArray(trainerPoolEntry)
? Utils.randSeedItem(trainerPoolEntry)
? randSeedItem(trainerPoolEntry)
: trainerPoolEntry;
trainerTypes.push(trainerType);
}
}, seedOffset);

let trainerGender = TrainerVariant.DEFAULT;
if (randomGender) {
trainerGender = (Utils.randInt(2) === 0) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT;
trainerGender = (randInt(2) === 0) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT;
}

/* 1/3 chance for evil team grunts to be double battles */
const evilTeamGrunts = [ TrainerType.ROCKET_GRUNT, TrainerType.MAGMA_GRUNT, TrainerType.AQUA_GRUNT, TrainerType.GALACTIC_GRUNT, TrainerType.PLASMA_GRUNT, TrainerType.FLARE_GRUNT, TrainerType.AETHER_GRUNT, TrainerType.SKULL_GRUNT, TrainerType.MACRO_GRUNT, TrainerType.STAR_GRUNT ];
const isEvilTeamGrunt = evilTeamGrunts.includes(trainerTypes[rand]);

if (trainerConfigs[trainerTypes[rand]].hasDouble && isEvilTeamGrunt) {
return new Trainer(scene, trainerTypes[rand], (Utils.randInt(3) === 0) ? TrainerVariant.DOUBLE : trainerGender);
return new Trainer(scene, trainerTypes[rand], (randInt(3) === 0) ? TrainerVariant.DOUBLE : trainerGender);
}

return new Trainer(scene, trainerTypes[rand], trainerGender);
Expand All @@ -522,7 +530,7 @@ export interface FixedBattleConfigs {
*/
export const classicFixedBattles: FixedBattleConfigs = {
[5]: new FixedBattleConfig().setBattleType(BattleType.TRAINER)
.setGetTrainerFunc(scene => new Trainer(scene, TrainerType.YOUNGSTER, Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)),
.setGetTrainerFunc(scene => new Trainer(scene, TrainerType.YOUNGSTER, randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)),
[8]: new FixedBattleConfig().setBattleType(BattleType.TRAINER)
.setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)),
[25]: new FixedBattleConfig().setBattleType(BattleType.TRAINER)
Expand Down
Loading

0 comments on commit 852a083

Please sign in to comment.