Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Create global scene variable #4766

Merged
merged 27 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7dc8f24
Replace various `scene` pass-arounds with global scene variable
DayKev Oct 31, 2024
55d1b14
Modify tests
DayKev Oct 31, 2024
db7ca95
Add scene back to `fade[in|out]()` calls
DayKev Nov 1, 2024
1d05582
Fix Bug Superfan ME test
DayKev Nov 4, 2024
510ffd4
Re-enable fixed test
DayKev Nov 4, 2024
e2cfb40
Rename `gScene` to `globalScene`
DayKev Nov 11, 2024
a76af6a
Merge branch 'beta' into global-scene
DayKev Nov 11, 2024
0e39947
Merge branch 'beta' into global-scene
DayKev Nov 11, 2024
a6cf3bf
Move `globalScene` to its own file to fix import/async issues
DayKev Nov 12, 2024
c01c623
Merge branch 'beta' into global-scene
DayKev Nov 14, 2024
810f472
Fix `SelectModifierPhase` tests
DayKev Nov 14, 2024
4dfedc2
Fix ME tests by removing `scene` from `expect()`s
DayKev Nov 14, 2024
f8e375e
Merge branch 'beta' into global-scene
DayKev Nov 14, 2024
15280c0
Merge branch 'beta' into global-scene
DayKev Dec 2, 2024
9d5a318
Resolve merge issues
DayKev Dec 2, 2024
b1be615
Merge branch 'beta' into global-scene
DayKev Dec 3, 2024
0208956
Merge branch 'beta' into global-scene
DayKev Dec 12, 2024
64f4a03
Remove tsdocs referencing `scene` params
DayKev Dec 18, 2024
dcb7f50
Merge branch 'beta' into global-scene
DayKev Dec 18, 2024
16ed662
Remove unnecessary `globalScene` usage in `loading-scene.ts`
DayKev Jan 10, 2025
a4d5d87
Merge branch 'beta' into global-scene
DayKev Jan 10, 2025
195932c
Fix merge conflicts
DayKev Jan 10, 2025
f5f5fcb
Attempt to fix circular import issue
DayKev Jan 10, 2025
a9653ae
Found the source of the import issue
DayKev Jan 10, 2025
32ab158
Merge branch 'beta' into global-scene
DayKev Jan 12, 2025
9fa5a91
Fix merge issues
DayKev Jan 12, 2025
39b2096
Merge branch 'beta' into global-scene
DayKev Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default [
"computed-property-spacing": ["error", "never" ], // Enforces consistent spacing inside computed property brackets
"space-infix-ops": ["error", { "int32Hint": false }], // Enforces spacing around infix operators
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], // Disallows multiple empty lines
"@typescript-eslint/consistent-type-imports": "error", // Enforces type-only imports wherever possible
}
}
]
4 changes: 1 addition & 3 deletions src/@types/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import BattleScene from "#app/battle-scene";

export type ConditionFn = (scene: BattleScene, args?: any[]) => boolean;
export type ConditionFn = (args?: any[]) => boolean;
2 changes: 1 addition & 1 deletion src/@types/i18next.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TOptions } from "i18next";
import type { TOptions } from "i18next";

// Module declared to make referencing keys in the localization files type-safe.
declare module "i18next" {
Expand Down
223 changes: 117 additions & 106 deletions src/battle-scene.ts

Large diffs are not rendered by default.

109 changes: 55 additions & 54 deletions src/battle.ts

Large diffs are not rendered by default.

353 changes: 176 additions & 177 deletions src/data/ability.ts

Large diffs are not rendered by default.

173 changes: 86 additions & 87 deletions src/data/arena-tag.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/data/balance/biomes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Type } from "#enums/type";
import * as Utils from "#app/utils";
import { pokemonEvolutions, SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions";
import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions";
import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions";
import i18next from "i18next";
import { Biome } from "#enums/biome";
import { Species } from "#enums/species";
Expand Down
123 changes: 62 additions & 61 deletions src/data/balance/pokemon-evolutions.ts

Large diffs are not rendered by default.

152 changes: 73 additions & 79 deletions src/data/battle-anims.ts

Large diffs are not rendered by default.

330 changes: 164 additions & 166 deletions src/data/battler-tags.ts

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/data/berry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getPokemonNameWithAffix } from "../messages";
import Pokemon, { HitResult } from "../field/pokemon";
import type Pokemon from "../field/pokemon";
import { HitResult } from "../field/pokemon";
import { getStatusEffectHealText } from "./status-effect";
import * as Utils from "../utils";
import { DoubleBerryEffectAbAttr, PostItemLostAbAttr, ReduceBerryUseThresholdAbAttr, applyAbAttrs, applyPostItemLostAbAttrs } from "./ability";
Expand All @@ -9,6 +10,7 @@ import { BerryType } from "#enums/berry-type";
import { Stat, type BattleStat } from "#app/enums/stat";
import { PokemonHealPhase } from "#app/phases/pokemon-heal-phase";
import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase";
import { globalScene } from "#app/global-scene";

export function getBerryName(berryType: BerryType): string {
return i18next.t(`berry:${BerryType[berryType]}.name`);
Expand Down Expand Up @@ -73,7 +75,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
}
const hpHealed = new Utils.NumberHolder(Utils.toDmgValue(pokemon.getMaxHp() / 4));
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, hpHealed);
pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(),
globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(),
hpHealed.value, i18next.t("battle:hpHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), berryName: getBerryName(berryType) }), true));
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
Expand All @@ -83,7 +85,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
pokemon.battleData.berriesEaten.push(berryType);
}
if (pokemon.status) {
pokemon.scene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)));
globalScene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)));
}
pokemon.resetStatus(true, true);
pokemon.updateInfo();
Expand All @@ -102,7 +104,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
const stat: BattleStat = berryType - BerryType.ENIGMA;
const statStages = new Utils.NumberHolder(1);
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, statStages);
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ stat ], statStages.value));
globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ stat ], statStages.value));
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LANSAT:
Expand All @@ -121,7 +123,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
const randStat = Utils.randSeedInt(Stat.SPD, Stat.ATK);
const stages = new Utils.NumberHolder(2);
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, stages);
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ randStat ], stages.value));
globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ randStat ], stages.value));
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LEPPA:
Expand All @@ -132,7 +134,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
const ppRestoreMove = pokemon.getMoveset().find(m => !m?.getPpRatio()) ? pokemon.getMoveset().find(m => !m?.getPpRatio()) : pokemon.getMoveset().find(m => m!.getPpRatio() < 1); // TODO: is this bang correct?
if (ppRestoreMove !== undefined) {
ppRestoreMove!.ppUsed = Math.max(ppRestoreMove!.ppUsed - 10, 0);
pokemon.scene.queueMessage(i18next.t("battle:ppHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: ppRestoreMove!.getName(), berryName: getBerryName(berryType) }));
globalScene.queueMessage(i18next.t("battle:ppHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: ppRestoreMove!.getName(), berryName: getBerryName(berryType) }));
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
}
};
Expand Down
18 changes: 11 additions & 7 deletions src/data/challenge.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as Utils from "#app/utils";
import i18next from "i18next";
import { defaultStarterSpecies, DexAttrProps, GameData } from "#app/system/game-data";
import PokemonSpecies, { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import type { DexAttrProps, GameData } from "#app/system/game-data";
import { defaultStarterSpecies } from "#app/system/game-data";
import type PokemonSpecies from "#app/data/pokemon-species";
import { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import { speciesStarterCosts } from "#app/data/balance/starters";
import Pokemon, { PokemonMove } from "#app/field/pokemon";
import { BattleType, FixedBattleConfig } from "#app/battle";
import type Pokemon from "#app/field/pokemon";
import { PokemonMove } from "#app/field/pokemon";
import type { FixedBattleConfig } from "#app/battle";
import { BattleType } from "#app/battle";
import Trainer, { TrainerVariant } from "#app/field/trainer";
import { GameMode } from "#app/game-mode";
import type { GameMode } from "#app/game-mode";
import { Type } from "#enums/type";
import { Challenges } from "#enums/challenges";
import { Species } from "#enums/species";
import { TrainerType } from "#enums/trainer-type";
import { Nature } from "#enums/nature";
import { Moves } from "#enums/moves";
import type { Moves } from "#enums/moves";
import { TypeColor, TypeShadow } from "#enums/color";
import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions";
import { pokemonFormChanges } from "#app/data/pokemon-forms";
Expand Down Expand Up @@ -467,7 +471,7 @@ export class SingleGenerationChallenge extends Challenge {
if (trainerTypes.length === 0) {
return false;
} else {
battleConfig.setBattleType(BattleType.TRAINER).setGetTrainerFunc(scene => new Trainer(scene, trainerTypes[this.value - 1], TrainerVariant.DEFAULT));
battleConfig.setBattleType(BattleType.TRAINER).setGetTrainerFunc(() => new Trainer(trainerTypes[this.value - 1], TrainerVariant.DEFAULT));
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/data/custom-pokemon-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Abilities } from "#enums/abilities";
import { Type } from "#enums/type";
import type { Abilities } from "#enums/abilities";
import type { Type } from "#enums/type";
import { isNullOrUndefined } from "#app/utils";
import { Nature } from "#enums/nature";
import type { Nature } from "#enums/nature";

/**
* Data that can customize a Pokemon in non-standard ways from its Species
Expand Down
23 changes: 12 additions & 11 deletions src/data/daily-run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PartyMemberStrength } from "#enums/party-member-strength";
import { Species } from "#enums/species";
import BattleScene from "#app/battle-scene";
import type { Species } from "#enums/species";
import { globalScene } from "#app/global-scene";
import { PlayerPokemon } from "#app/field/pokemon";
import { Starter } from "#app/ui/starter-select-ui-handler";
import type { Starter } from "#app/ui/starter-select-ui-handler";
import * as Utils from "#app/utils";
import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import type { PokemonSpeciesForm } from "#app/data/pokemon-species";
import PokemonSpecies, { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import { speciesStarterCosts } from "#app/data/balance/starters";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";

Expand All @@ -21,17 +22,17 @@ export function fetchDailyRunSeed(): Promise<string | null> {
});
}

export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
export function getDailyRunStarters(seed: string): Starter[] {
const starters: Starter[] = [];

scene.executeWithSeedOffset(() => {
const startingLevel = scene.gameMode.getStartingLevel();
globalScene.executeWithSeedOffset(() => {
const startingLevel = globalScene.gameMode.getStartingLevel();

if (/\d{18}$/.test(seed)) {
for (let s = 0; s < 3; s++) {
const offset = 6 + s * 6;
const starterSpeciesForm = getPokemonSpeciesForm(parseInt(seed.slice(offset, offset + 4)) as Species, parseInt(seed.slice(offset + 4, offset + 6)));
starters.push(getDailyRunStarter(scene, starterSpeciesForm, startingLevel));
starters.push(getDailyRunStarter(starterSpeciesForm, startingLevel));
}
return;
}
Expand All @@ -48,17 +49,17 @@ export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[]
.filter(s => speciesStarterCosts[s] === cost);
const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies));
const starterSpecies = getPokemonSpecies(randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel));
starters.push(getDailyRunStarter(starterSpecies, startingLevel));
}
}, 0, seed);

return starters;
}

function getDailyRunStarter(scene: BattleScene, starterSpeciesForm: PokemonSpeciesForm, startingLevel: integer): Starter {
function getDailyRunStarter(starterSpeciesForm: PokemonSpeciesForm, startingLevel: integer): Starter {
const starterSpecies = starterSpeciesForm instanceof PokemonSpecies ? starterSpeciesForm : getPokemonSpecies(starterSpeciesForm.speciesId);
const formIndex = starterSpeciesForm instanceof PokemonSpecies ? undefined : starterSpeciesForm.formIndex;
const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined, undefined);
const pokemon = new PlayerPokemon(starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined, undefined);
const starter: Starter = {
species: starterSpecies,
dexAttr: pokemon.getDexAttr(),
Expand Down
21 changes: 9 additions & 12 deletions src/data/egg-hatch-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BattleScene from "#app/battle-scene";
import { PlayerPokemon } from "#app/field/pokemon";
import { DexEntry, StarterDataEntry } from "#app/system/game-data";
import { globalScene } from "#app/global-scene";
import type { PlayerPokemon } from "#app/field/pokemon";
import type { DexEntry, StarterDataEntry } from "#app/system/game-data";

/**
* Stores data associated with a specific egg and the hatched pokemon
Expand All @@ -17,11 +17,8 @@ export class EggHatchData {
public dexEntryBeforeUpdate: DexEntry;
/** stored copy of the hatched pokemon's starter entry before it was updated due to hatch */
public starterDataEntryBeforeUpdate: StarterDataEntry;
/** reference to the battle scene to get gamedata and update dex */
private scene: BattleScene;

constructor(scene: BattleScene, pokemon: PlayerPokemon, eggMoveIndex: number) {
this.scene = scene;
constructor(pokemon: PlayerPokemon, eggMoveIndex: number) {
this.pokemon = pokemon;
this.eggMoveIndex = eggMoveIndex;
}
Expand All @@ -39,8 +36,8 @@ export class EggHatchData {
* Used before updating the dex, so comparing the pokemon to these entries will show the new attributes
*/
setDex() {
const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId];
const currStarterDataEntry = this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()];
const currDexEntry = globalScene.gameData.dexData[this.pokemon.species.speciesId];
const currStarterDataEntry = globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId()];
this.dexEntryBeforeUpdate = {
seenAttr: currDexEntry.seenAttr,
caughtAttr: currDexEntry.caughtAttr,
Expand Down Expand Up @@ -86,9 +83,9 @@ export class EggHatchData {
*/
updatePokemon(showMessage : boolean = false) {
return new Promise<void>(resolve => {
this.scene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => {
this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs);
this.scene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => {
globalScene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => {
globalScene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs);
globalScene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => {
this.setEggMoveUnlocked(value);
resolve();
});
Expand Down
Loading
Loading