refactor executed code while importing and initializing all of these in loading-scene (#1125)

This commit is contained in:
Greenlamp2 2024-05-24 19:46:30 +02:00 committed by GitHub
parent a9af2bd6ff
commit c1a7df913a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 257 additions and 129 deletions

View File

@ -2,7 +2,7 @@ import Phaser from "phaser";
import UI from "./ui/ui";
import { NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, TurnInitPhase, ReturnPhase, LevelCapPhase, ShowTrainerPhase, LoginPhase, MovePhase, TitlePhase, SwitchPhase } from "./phases";
import Pokemon, { PlayerPokemon, EnemyPokemon } from "./field/pokemon";
import PokemonSpecies, { PokemonSpeciesFilter, allSpecies, getPokemonSpecies, initSpecies } from "./data/pokemon-species";
import PokemonSpecies, { PokemonSpeciesFilter, allSpecies, getPokemonSpecies } from "./data/pokemon-species";
import * as Utils from "./utils";
import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier, PokemonHeldItemModifier, ModifierPredicate, DoubleBattleChanceBoosterModifier, FusePokemonModifier, PokemonFormChangeItemModifier, TerastallizeModifier, overrideModifiers, overrideHeldItems } from "./modifier/modifier";
import { PokeballType } from "./data/pokeball";
@ -15,10 +15,9 @@ import { GameData, PlayerGender } from "./system/game-data";
import { TextStyle, addTextObject } from "./ui/text";
import { Moves } from "./data/enums/moves";
import { allMoves } from "./data/move";
import { initMoves } from "./data/move";
import { ModifierPoolType, getDefaultModifierTypeForTier, getEnemyModifierTypesForWave, getLuckString, getLuckTextTint, getModifierPoolForType, getPartyLuckValue } from "./modifier/modifier-type";
import AbilityBar from "./ui/ability-bar";
import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, IncrementMovePriorityAbAttr, applyAbAttrs, initAbilities } from "./data/ability";
import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, IncrementMovePriorityAbAttr, applyAbAttrs } from "./data/ability";
import { allAbilities } from "./data/ability";
import Battle, { BattleType, FixedBattleConfig, fixedBattles } from "./battle";
import { GameMode, GameModes, gameModes } from "./game-mode";
@ -187,11 +186,6 @@ export default class BattleScene extends SceneBase {
constructor() {
super("battle");
initSpecies();
initMoves();
initAbilities();
this.phaseQueue = [];
this.phaseQueuePrepend = [];
this.phaseQueuePrependSpliceIndex = -1;

View File

@ -5,7 +5,7 @@ import beautify from "json-beautify";
import { TrainerType } from "./enums/trainer-type";
import { TimeOfDay } from "./enums/time-of-day";
import { Biome } from "./enums/biome";
import { SpeciesFormEvolution } from "./pokemon-evolutions";
import {pokemonEvolutions, SpeciesFormEvolution} from "./pokemon-evolutions";
export function getBiomeName(biome: Biome | -1) {
if (biome === -1) {
@ -2012,7 +2012,7 @@ export const biomeTrainerPools: BiomeTrainerPools = {
}
};
{
export function initBiomes() {
const pokemonBiomes = [
[ Species.BULBASAUR, Type.GRASS, Type.POISON, [
[ Biome.GRASS, BiomePoolTier.RARE ]
@ -7677,8 +7677,6 @@ export const biomeTrainerPools: BiomeTrainerPools = {
traverseBiome(Biome.TOWN, 0);
biomeDepths[Biome.END] = [ Object.values(biomeDepths).map(d => d[0]).reduce((max: integer, value: integer) => Math.max(max, value), 0) + 1, 1 ];
import("./pokemon-evolutions").then(pe => {
const pokemonEvolutions = pe.pokemonEvolutions;
for (const biome of Utils.getEnumValues(Biome)) {
biomePokemonPools[biome] = {};
biomeTrainerPools[biome] = {};
@ -7799,8 +7797,6 @@ export const biomeTrainerPools: BiomeTrainerPools = {
}
}
//outputPools();
});
// used in a commented code
// eslint-disable-next-line @typescript-eslint/no-unused-vars

View File

@ -608,9 +608,11 @@ function parseEggMoves(content: string): void {
console.log(output);
}
const eggMovesStr = "";
if (eggMovesStr) {
export function initEggMoves() {
const eggMovesStr = "";
if (eggMovesStr) {
setTimeout(() => {
parseEggMoves(eggMovesStr);
}, 1000);
}
}

View File

@ -1619,7 +1619,7 @@ interface PokemonPrevolutions {
export const pokemonPrevolutions: PokemonPrevolutions = {};
{
export function initPokemonPrevolutions(): void {
const megaFormKeys = [ SpeciesFormKey.MEGA, "", SpeciesFormKey.MEGA_X, "", SpeciesFormKey.MEGA_Y ].map(sfk => sfk as string);
const prevolutionKeys = Object.keys(pokemonEvolutions);
prevolutionKeys.forEach(pk => {

View File

@ -729,7 +729,7 @@ export const pokemonFormChanges: PokemonFormChanges = {
]
};
{
export function initPokemonForms() {
const formChangeKeys = Object.keys(pokemonFormChanges);
formChangeKeys.forEach(pk => {
const formChanges = pokemonFormChanges[pk];

View File

@ -1051,6 +1051,6 @@ export const trainerConfigs: TrainerConfigs = {
}),
};
(function () {
export function initTrainerTypeDialogue() {
initTrainerTypeDialogue();
})();
}

View File

@ -9,6 +9,14 @@ import { WindowVariant, getWindowVariantSuffix } from "./ui/ui-theme";
import { isMobile } from "./touch-controls";
import * as Utils from "./utils";
import { initI18n } from "./plugins/i18n";
import {initStatsKeys} from "#app/ui/game-stats-ui-handler";
import {initPokemonPrevolutions} from "#app/data/pokemon-evolutions";
import {initBiomes} from "#app/data/biomes";
import {initEggMoves} from "#app/data/egg-moves";
import {initPokemonForms} from "#app/data/pokemon-forms";
import {initSpecies} from "#app/data/pokemon-species";
import {initMoves} from "#app/data/move";
import {initAbilities} from "#app/data/ability";
export class LoadingScene extends SceneBase {
constructor() {
@ -284,6 +292,15 @@ export class LoadingScene extends SceneBase {
this.load.plugin("rextexteditplugin", "https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rextexteditplugin.min.js", true);
this.loadLoadingScreen();
initStatsKeys();
initPokemonPrevolutions();
initBiomes();
initEggMoves();
initPokemonForms();
initSpecies();
initMoves();
initAbilities();
}
loadLoadingScreen() {

View File

@ -0,0 +1,9 @@
import {describe, expect, it} from "vitest";
import {MoneyAchv} from "#app/system/achv";
describe("check some Achievement related stuff", () => {
it ("should check Achievement creation", () => {
const ach = new MoneyAchv("Achievement", 1000, null, 100);
expect(ach.name).toBe("Achievement");
});
});

View File

@ -0,0 +1,35 @@
import { describe, expect, it} from "vitest";
import {initStatsKeys} from "#app/ui/game-stats-ui-handler";
async function importModule() {
try {
initStatsKeys();
const { PokemonMove } = await import("#app/field/pokemon");
const { Species } = await import("#app/data/enums/species");
return {
PokemonMove,
Species,
};
// Dynamically import the module
} catch (error) {
// Log the error stack trace
console.error("Error during import:", error.stack);
// Rethrow the error to ensure the test fails
throw error;
}
}
describe("tests to debug the import, with trace", () => {
it("import PokemonMove module", async () => {
const module = await importModule();
// Example assertion
expect(module.PokemonMove).toBeDefined();
});
it("import Species module", async () => {
const module = await importModule();
// Example assertion
expect(module.Species).toBeDefined();
});
});

57
src/test/pokemon.test.ts Normal file
View File

@ -0,0 +1,57 @@
import {describe, expect, it} from "vitest";
import {getPokemonSpecies} from "#app/data/pokemon-species";
import {PokemonMove} from "#app/field/pokemon";
import {Species} from "#app/data/enums/species";
import {Moves} from "#app/data/enums/moves";
import PokemonData from "#app/system/pokemon-data";
describe("some tests related to PokemonData and Species", () => {
it("should create a species", () => {
const species = getPokemonSpecies(Species.MEW);
expect(species).not.toBeNull();
});
it("should create a pokemon", () => {
const pokemon = new PokemonData({
species: Species.MEW,
level: 1,
});
expect(pokemon).not.toBeNull();
expect(pokemon.level).toEqual(1);
expect(pokemon.species).toEqual(Species.MEW);
});
it("should generate a moveset", () => {
const pokemon = new PokemonData({
species: Species.MEW,
level: 1,
});
expect(pokemon.moveset[0].moveId).toBe(Moves.TACKLE);
expect(pokemon.moveset[1].moveId).toBe(Moves.GROWL);
});
it("should create an ennemypokemon", () => {
const ennemyPokemon = new PokemonData({
species: Species.MEWTWO,
level: 100,
});
expect(ennemyPokemon).not.toBeNull();
expect(ennemyPokemon.level).toEqual(100);
expect(ennemyPokemon.species).toEqual(Species.MEWTWO);
});
it("should create an ennemypokemon with specified moveset", () => {
const ennemyPokemon = new PokemonData({
species: Species.MEWTWO,
level: 100,
moveset: [
new PokemonMove(Moves.ACID),
new PokemonMove(Moves.ACROBATICS),
new PokemonMove(Moves.FOCUS_ENERGY),
]
});
expect(ennemyPokemon.moveset[0].moveId).toBe(Moves.ACID);
expect(ennemyPokemon.moveset[1].moveId).toBe(Moves.ACROBATICS);
expect(ennemyPokemon.moveset[2].moveId).toBe(Moves.FOCUS_ENERGY);
});
});

View File

@ -1,2 +1,19 @@
import "vitest-canvas-mock";
import "#app/test/phaser.setup";
import {initStatsKeys} from "#app/ui/game-stats-ui-handler";
import {initPokemonPrevolutions} from "#app/data/pokemon-evolutions";
import {initBiomes} from "#app/data/biomes";
import {initEggMoves} from "#app/data/egg-moves";
import {initPokemonForms} from "#app/data/pokemon-forms";
import {initSpecies} from "#app/data/pokemon-species";
import {initMoves} from "#app/data/move";
import {initAbilities} from "#app/data/ability";
initStatsKeys();
initPokemonPrevolutions();
initBiomes();
initEggMoves();
initPokemonForms();
initSpecies();
initMoves();
initAbilities();

View File

@ -230,7 +230,7 @@ export default class GameStatsUiHandler extends UiHandler {
}
}
(function () {
export function initStatsKeys() {
const statKeys = Object.keys(displayStats);
for (const key of statKeys) {
@ -256,4 +256,4 @@ export default class GameStatsUiHandler extends UiHandler {
(displayStats[key] as DisplayStat).label = Utils.toReadableString(`${splittableKey[0].toUpperCase()}${splittableKey.slice(1)}`);
}
}
})();
}

View File

@ -14,6 +14,7 @@ export default defineConfig(({ mode }) => {
}
},
threads: false,
trace: true,
environmentOptions: {
jsdom: {
resources: 'usable',