From 9c97e37c27e646bc738e0b82e1b6cebe84e2c16a Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 7 Jun 2024 23:50:07 -0400 Subject: [PATCH] initVouchers correctly (#1940) --- src/loading-scene.ts | 2 ++ src/system/voucher.ts | 68 +++++++++++++++++++--------------------- src/test/vitest.setup.ts | 2 ++ 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/loading-scene.ts b/src/loading-scene.ts index 8bb811e3d9b..22c013d9481 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -20,6 +20,7 @@ import {initAchievements} from "#app/system/achv"; import {initTrainerTypeDialogue} from "#app/data/dialogue"; import i18next from "i18next"; import { initStatsKeys } from "./ui/game-stats-ui-handler"; +import { initVouchers } from "./system/voucher"; export class LoadingScene extends SceneBase { constructor() { @@ -329,6 +330,7 @@ export class LoadingScene extends SceneBase { this.loadLoadingScreen(); + initVouchers(); initAchievements(); initStatsKeys(); initPokemonPrevolutions(); diff --git a/src/system/voucher.ts b/src/system/voucher.ts index c11410400b5..ba42b99d294 100644 --- a/src/system/voucher.ts +++ b/src/system/voucher.ts @@ -83,42 +83,40 @@ export const vouchers: Vouchers = {}; const voucherAchvs: Achv[] = [ achvs.CLASSIC_VICTORY ]; -{ - (function() { - import("../data/trainer-config").then(tc => { - const trainerConfigs = tc.trainerConfigs; +export function initVouchers() { + import("../data/trainer-config").then(tc => { + const trainerConfigs = tc.trainerConfigs; - for (const achv of voucherAchvs) { - const voucherType = achv.score >= 150 - ? VoucherType.GOLDEN - : achv.score >= 100 - ? VoucherType.PREMIUM - : achv.score >= 75 - ? VoucherType.PLUS - : VoucherType.REGULAR; - vouchers[achv.id] = new Voucher(voucherType, getAchievementDescription(achv.localizationKey)); - } + for (const achv of voucherAchvs) { + const voucherType = achv.score >= 150 + ? VoucherType.GOLDEN + : achv.score >= 100 + ? VoucherType.PREMIUM + : achv.score >= 75 + ? VoucherType.PLUS + : VoucherType.REGULAR; + vouchers[achv.id] = new Voucher(voucherType, getAchievementDescription(achv.localizationKey)); + } - const bossTrainerTypes = Object.keys(trainerConfigs) - .filter(tt => trainerConfigs[tt].isBoss && trainerConfigs[tt].getDerivedType() !== TrainerType.RIVAL); + const bossTrainerTypes = Object.keys(trainerConfigs) + .filter(tt => trainerConfigs[tt].isBoss && trainerConfigs[tt].getDerivedType() !== TrainerType.RIVAL); - for (const trainerType of bossTrainerTypes) { - const voucherType = trainerConfigs[trainerType].moneyMultiplier < 10 - ? VoucherType.PLUS - : VoucherType.PREMIUM; - const key = TrainerType[trainerType]; - const trainerName = trainerConfigs[trainerType].name; - const trainer = trainerConfigs[trainerType]; - const title = trainer.title ? ` (${trainer.title})` : ""; - vouchers[key] = new Voucher( - voucherType, - `${i18next.t("voucher:defeatTrainer", { trainerName })} ${title}`, - ); - } - const voucherKeys = Object.keys(vouchers); - for (const k of voucherKeys) { - vouchers[k].id = k; - } - }); - })(); + for (const trainerType of bossTrainerTypes) { + const voucherType = trainerConfigs[trainerType].moneyMultiplier < 10 + ? VoucherType.PLUS + : VoucherType.PREMIUM; + const key = TrainerType[trainerType]; + const trainerName = trainerConfigs[trainerType].name; + const trainer = trainerConfigs[trainerType]; + const title = trainer.title ? ` (${trainer.title})` : ""; + vouchers[key] = new Voucher( + voucherType, + `${i18next.t("voucher:defeatTrainer", { trainerName })} ${title}`, + ); + } + const voucherKeys = Object.keys(vouchers); + for (const k of voucherKeys) { + vouchers[k].id = k; + } + }); } diff --git a/src/test/vitest.setup.ts b/src/test/vitest.setup.ts index 8729e7796f0..7c1bbcbeabe 100644 --- a/src/test/vitest.setup.ts +++ b/src/test/vitest.setup.ts @@ -9,7 +9,9 @@ import {initSpecies} from "#app/data/pokemon-species"; import {initMoves} from "#app/data/move"; import {initAbilities} from "#app/data/ability"; import {initAchievements} from "#app/system/achv.js"; +import { initVouchers } from "#app/system/voucher.js"; +initVouchers(); initAchievements(); initStatsKeys(); initPokemonPrevolutions();