diff --git a/.env.app b/.env.app new file mode 100644 index 00000000000..91c228d6761 --- /dev/null +++ b/.env.app @@ -0,0 +1,8 @@ +VITE_BYPASS_LOGIN=1 +VITE_BYPASS_TUTORIAL=0 +VITE_SERVER_URL=http://localhost:8001 +# IDs for discord/google auth go unused due to VITE_BYPASS_LOGIN +VITE_DISCORD_CLIENT_ID=1234567890 +VITE_GOOGLE_CLIENT_ID=1234567890 +VITE_I18N_DEBUG=0 +VITE_PORT=8000 diff --git a/package.json b/package.json index d6d37b768c2..6bc858ec2d6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "build": "vite build && node scripts/sync-dist-assets.js", "build:beta": "vite build --mode beta && node scripts/sync-dist-assets.js", "build:dev": "vite build --mode development && node scripts/sync-dist-assets.js", + "build:app": "vite build --mode app && node scripts/sync-dist-assets.js", "preview": "vite preview", "test": "vitest run --no-isolate", "test:cov": "vitest run --coverage --no-isolate", diff --git a/src/account.ts b/src/account.ts index c97721889ae..5a35c31a57a 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,5 +1,5 @@ import { pokerogueApi } from "#api/pokerogue-api"; -import { bypassLogin } from "#app/global-vars/bypass-login"; +import { bypassLogin } from "#constants/app-constants"; import type { UserInfo } from "#types/user-info"; import { randomString } from "#utils/common"; diff --git a/src/ai/ai-moveset-gen.ts b/src/ai/ai-moveset-gen.ts index b8ff504d844..f4b0f57d2f7 100644 --- a/src/ai/ai-moveset-gen.ts +++ b/src/ai/ai-moveset-gen.ts @@ -21,6 +21,7 @@ import { ULTRA_TM_MOVESET_WEIGHT, } from "#balance/moveset-generation"; import { speciesTmMoves, tmPoolTiers } from "#balance/tms"; +import { isBeta, isDev } from "#constants/app-constants"; import { allMoves } from "#data/data-lists"; import { ModifierTier } from "#enums/modifier-tier"; import { MoveCategory } from "#enums/move-category"; @@ -632,7 +633,7 @@ function fillInRemainingMovesetSlots( * @param note - Short note to include in the log for context */ function debugMoveWeights(pokemon: Pokemon, pool: Map, note: string): void { - if (import.meta.env.DEV && import.meta.env.NODE_ENV !== "test") { + if ((isBeta || isDev) && import.meta.env.NODE_ENV !== "test") { const moveNameToWeightMap = new Map(); const sortedByValue = Array.from(pool.entries()).sort((a, b) => b[1] - a[1]); for (const [moveId, weight] of sortedByValue) { diff --git a/src/ai/rival-team-gen.ts b/src/ai/rival-team-gen.ts index aec00920420..536a8ba794a 100644 --- a/src/ai/rival-team-gen.ts +++ b/src/ai/rival-team-gen.ts @@ -1,4 +1,5 @@ import { globalScene } from "#app/global-scene"; +import { isBeta, isDev } from "#constants/app-constants"; import type { PokemonSpecies } from "#data/pokemon-species"; import { getTypeDamageMultiplier } from "#data/type"; import { AbilityId } from "#enums/ability-id"; @@ -278,7 +279,7 @@ export function getRandomRivalPartyMemberFunc( ): (level: number, strength: PartyMemberStrength) => EnemyPokemon { // Protect against out of range slots. // Only care about this in dev to be caught during development; it will be excluded in production builds. - if (import.meta.env.DEV && slot > config.length) { + if ((isBeta || isDev) && slot > config.length) { throw new Error(`Slot ${slot} is out of range for the provided config of length ${config.length}`); } return (level: number, _strength: PartyMemberStrength) => { diff --git a/src/constants/app-constants.ts b/src/constants/app-constants.ts new file mode 100644 index 00000000000..c42d9c4a1dd --- /dev/null +++ b/src/constants/app-constants.ts @@ -0,0 +1,18 @@ +/** + * `true` if running in "development" mode which happens when: + * - The build mode is "development" (`pnpm build:dev` which runs `vite build --mode development`) or + * - The Vite server is started via `pnpm start:dev` (which runs `vite --mode development`) + */ +export const isDev = import.meta.env.MODE === "development"; + +/** + * `true` if running in "beta" mode which happens when: + * - The build mode is "beta" (`pnpm build:beta` which runs `vite build --mode beta`) or + * - The Vite server is started via `pnpm start:beta` (which runs `vite --mode beta`) + */ +export const isBeta = import.meta.env.MODE === "beta"; + +/** `true` if running via "app" mode (`pnpm build:app` which runs `vite build --mode app`) */ +export const isApp = import.meta.env.MODE === "app"; + +export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; diff --git a/src/global-vars/bypass-login.ts b/src/global-vars/bypass-login.ts deleted file mode 100644 index 3595a076101..00000000000 --- a/src/global-vars/bypass-login.ts +++ /dev/null @@ -1 +0,0 @@ -export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; diff --git a/src/main.ts b/src/main.ts index 5d181690cd2..9903a257af6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import "#app/polyfills"; import { InvertPostFX } from "#app/pipelines/invert"; import { initI18n } from "#app/plugins/i18n"; +import { isBeta, isDev } from "#constants/app-constants"; import { version } from "#package.json"; import Phaser from "phaser"; import BBCodeTextPlugin from "phaser3-rex-plugins/plugins/bbcodetext-plugin"; @@ -10,7 +11,7 @@ import InputTextPlugin from "phaser3-rex-plugins/plugins/inputtext-plugin"; import TransitionImagePackPlugin from "phaser3-rex-plugins/templates/transitionimagepack/transitionimagepack-plugin"; import UIPlugin from "phaser3-rex-plugins/templates/ui/ui-plugin"; -if (import.meta.env.DEV) { +if (isBeta || isDev) { document.title += " (Beta)"; } @@ -59,9 +60,9 @@ Phaser.GameObjects.Text.prototype.setPositionRelative = setPositionRelative; Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative; document.fonts.load("16px emerald").then(() => document.fonts.load("10px pkmnems")); -// biome-ignore lint/suspicious/noImplicitAnyLet: TODO +// biome-ignore lint: TODO let game; -// biome-ignore lint/suspicious/noImplicitAnyLet: TODO +// biome-ignore lint: TODO let manifest; const startGame = async () => { diff --git a/src/phases/game-over-phase.ts b/src/phases/game-over-phase.ts index f229f872958..a8afa8bfb47 100644 --- a/src/phases/game-over-phase.ts +++ b/src/phases/game-over-phase.ts @@ -2,6 +2,7 @@ import { pokerogueApi } from "#api/pokerogue-api"; import { clientSessionId } from "#app/account"; import { globalScene } from "#app/global-scene"; import { pokemonEvolutions } from "#balance/pokemon-evolutions"; +import { bypassLogin } from "#constants/app-constants"; import { modifierTypes } from "#data/data-lists"; import { getCharVariantFromDialogue } from "#data/dialogue"; import type { PokemonSpecies } from "#data/pokemon-species"; @@ -24,7 +25,7 @@ import { TrainerData } from "#system/trainer-data"; import { trainerConfigs } from "#trainers/trainer-config"; import type { SessionSaveData } from "#types/save-data"; import { checkSpeciesValidForChallenge, isNuzlockeChallenge } from "#utils/challenge-utils"; -import { isLocal, isLocalServerConnected } from "#utils/common"; +import { isLocalServerConnected } from "#utils/common"; import { getPokemonSpecies } from "#utils/pokemon-utils"; import i18next from "i18next"; @@ -247,10 +248,9 @@ export class GameOverPhase extends BattlePhase { }); }; - /* Added a local check to see if the game is running offline - If Online, execute apiFetch as intended - If Offline, execute offlineNewClear() only for victory, a localStorage implementation of newClear daily run checks */ - if (!isLocal || isLocalServerConnected) { + // If Online, execute apiFetch as intended + // If Offline, execute offlineNewClear() only for victory, a localStorage implementation of newClear daily run checks + if (!bypassLogin || isLocalServerConnected) { pokerogueApi.savedata.session .newclear({ slot: globalScene.sessionSlotId, diff --git a/src/phases/login-phase.ts b/src/phases/login-phase.ts index d81b9b614f2..0aaf97e234b 100644 --- a/src/phases/login-phase.ts +++ b/src/phases/login-phase.ts @@ -1,8 +1,8 @@ import { updateUserInfo } from "#app/account"; import { globalScene } from "#app/global-scene"; -import { bypassLogin } from "#app/global-vars/bypass-login"; import { Phase } from "#app/phase"; import { handleTutorial, Tutorial } from "#app/tutorial"; +import { bypassLogin } from "#constants/app-constants"; import { UiMode } from "#enums/ui-mode"; import { executeIf, sessionIdKey } from "#utils/common"; import { getCookie, removeCookie } from "#utils/cookies"; diff --git a/src/phases/title-phase.ts b/src/phases/title-phase.ts index 9535ea1c8e9..f69ebc4bf4e 100644 --- a/src/phases/title-phase.ts +++ b/src/phases/title-phase.ts @@ -3,6 +3,7 @@ import { GameMode, getGameMode } from "#app/game-mode"; import { globalScene } from "#app/global-scene"; import Overrides from "#app/overrides"; import { Phase } from "#app/phase"; +import { bypassLogin } from "#constants/app-constants"; import { fetchDailyRunSeed, getDailyRunStarters } from "#data/daily-run"; import { modifierTypes } from "#data/data-lists"; import { Gender } from "#data/gender"; @@ -18,7 +19,7 @@ import { vouchers } from "#system/voucher"; import type { SessionSaveData } from "#types/save-data"; import type { OptionSelectConfig, OptionSelectItem } from "#ui/abstract-option-select-ui-handler"; import { SaveSlotUiMode } from "#ui/save-slot-select-ui-handler"; -import { isLocal, isLocalServerConnected } from "#utils/common"; +import { isLocalServerConnected } from "#utils/common"; import { getPokemonSpecies } from "#utils/pokemon-utils"; import i18next from "i18next"; @@ -271,7 +272,7 @@ export class TitlePhase extends Phase { }; // If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date. - if (!isLocal || isLocalServerConnected) { + if (!bypassLogin || isLocalServerConnected) { fetchDailyRunSeed() .then(seed => { if (seed) { diff --git a/src/system/game-data.ts b/src/system/game-data.ts index d824d9ca2a9..0135c198680 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -3,12 +3,12 @@ import { clientSessionId, loggedInUser, updateUserInfo } from "#app/account"; import { defaultStarterSpecies, saveKey } from "#app/constants"; import { getGameMode } from "#app/game-mode"; import { globalScene } from "#app/global-scene"; -import { bypassLogin } from "#app/global-vars/bypass-login"; import Overrides from "#app/overrides"; import { Tutorial } from "#app/tutorial"; import { speciesEggMoves } from "#balance/egg-moves"; import { pokemonPrevolutions } from "#balance/pokemon-evolutions"; import { speciesStarterCosts } from "#balance/starters"; +import { bypassLogin, isBeta, isDev } from "#constants/app-constants"; import { EntryHazardTag } from "#data/arena-tag"; import { allMoves, allSpecies } from "#data/data-lists"; import type { Egg } from "#data/egg"; @@ -74,7 +74,7 @@ import type { } from "#types/save-data"; import { RUN_HISTORY_LIMIT } from "#ui/run-history-ui-handler"; import { applyChallenges } from "#utils/challenge-utils"; -import { executeIf, fixedInt, isLocal, NumberHolder, randInt, randSeedItem } from "#utils/common"; +import { executeIf, fixedInt, NumberHolder, randInt, randSeedItem } from "#utils/common"; import { decrypt, encrypt } from "#utils/data"; import { getEnumKeys } from "#utils/enums"; import { getPokemonSpecies } from "#utils/pokemon-utils"; @@ -413,7 +413,7 @@ export class GameData { } } - if (import.meta.env.DEV) { + if (isBeta || isDev) { try { console.debug( GameData.parseSystemData( @@ -446,36 +446,8 @@ export class GameData { * Retrieves current run history data, organized by time stamp. * At the moment, only retrievable from locale cache */ + // TODO: save run history data to server? async getRunHistoryData(): Promise { - if (!isLocal) { - /** - * Networking Code DO NOT DELETE! - * Note: Might have to be migrated to `pokerogue-api.ts` - * - const response = await Utils.apiFetch("savedata/runHistory", true); - const data = await response.json(); - */ - const lsItemKey = `runHistoryData_${loggedInUser?.username}`; - const lsItem = localStorage.getItem(lsItemKey); - if (lsItem) { - const cachedResponse = lsItem; - if (cachedResponse) { - const runHistory = JSON.parse(decrypt(cachedResponse, bypassLogin)); - return runHistory; - } - return {}; - // check to see whether cachedData or serverData is more up-to-date - /** - * Networking Code DO NOT DELETE! - * - if ( Object.keys(cachedRHData).length >= Object.keys(data).length ) { - return cachedRHData; - } - */ - } - localStorage.setItem(`runHistoryData_${loggedInUser?.username}`, ""); - return {}; - } const lsItemKey = `runHistoryData_${loggedInUser?.username}`; const lsItem = localStorage.getItem(lsItemKey); if (lsItem) { @@ -496,6 +468,7 @@ export class GameData { * @param isVictory: result of the run * Arbitrary limit of 25 runs per player - Will delete runs, starting with the oldest one, if needed */ + // TODO: save run history data to server? async saveRunHistory(runEntry: SessionSaveData, isVictory: boolean): Promise { const runHistoryData = await this.getRunHistoryData(); // runHistoryData should always return run history or {} empty object @@ -518,20 +491,6 @@ export class GameData { `runHistoryData_${loggedInUser?.username}`, encrypt(JSON.stringify(runHistoryData), bypassLogin), ); - /** - * Networking Code DO NOT DELETE - * - if (!Utils.isLocal) { - try { - await Utils.apiPost("savedata/runHistory", JSON.stringify(runHistoryData), undefined, true); - return true; - } catch (err) { - console.log("savedata/runHistory POST failed : ", err); - return false; - } - } - NOTE: should be adopted to `pokerogue-api.ts` - */ return true; } @@ -954,7 +913,7 @@ export class GameData { const { promise, resolve, reject } = Promise.withResolvers(); try { const initSessionFromData = (fromSession: SessionSaveData) => { - if (import.meta.env.DEV) { + if (isBeta || isDev) { try { console.debug( this.parseSessionData( diff --git a/src/system/settings/settings.ts b/src/system/settings/settings.ts index 78b6044b0fc..4580b36ac19 100644 --- a/src/system/settings/settings.ts +++ b/src/system/settings/settings.ts @@ -1,5 +1,6 @@ import { globalScene } from "#app/global-scene"; import { hasTouchscreen } from "#app/touch-controls"; +import { isDev } from "#constants/app-constants"; import { EaseType } from "#enums/ease-type"; import { MoneyFormat } from "#enums/money-format"; import { PlayerGender } from "#enums/player-gender"; @@ -7,7 +8,6 @@ import { ShopCursorTarget } from "#enums/shop-cursor-target"; import { UiMode } from "#enums/ui-mode"; import { CandyUpgradeNotificationChangedEvent } from "#events/battle-scene"; import { updateWindowType } from "#ui/ui-theme"; -import { isLocal } from "#utils/common"; import i18next from "i18next"; import { languageOptions } from "./settings-language"; @@ -716,7 +716,7 @@ export const Setting: Array = [ }, ]; -if (isLocal) { +if (isDev) { Setting.push({ key: SettingKeys.Dex_For_Devs, label: i18next.t("settings:dexForDevs"), diff --git a/src/ui/handlers/admin-ui-handler.ts b/src/ui/handlers/admin-ui-handler.ts index 8ae8c04500d..988c1cd5a7a 100644 --- a/src/ui/handlers/admin-ui-handler.ts +++ b/src/ui/handlers/admin-ui-handler.ts @@ -1,6 +1,6 @@ import { pokerogueApi } from "#api/pokerogue-api"; import { globalScene } from "#app/global-scene"; -import { bypassLogin } from "#app/global-vars/bypass-login"; +import { bypassLogin } from "#constants/app-constants"; import { AdminMode } from "#enums/admin-mode"; import { Button } from "#enums/buttons"; import { TextStyle } from "#enums/text-style"; diff --git a/src/ui/handlers/menu-ui-handler.ts b/src/ui/handlers/menu-ui-handler.ts index 8a910f91df3..62e475aec16 100644 --- a/src/ui/handlers/menu-ui-handler.ts +++ b/src/ui/handlers/menu-ui-handler.ts @@ -1,8 +1,8 @@ import { pokerogueApi } from "#api/pokerogue-api"; import { loggedInUser, updateUserInfo } from "#app/account"; import { globalScene } from "#app/global-scene"; -import { bypassLogin } from "#app/global-vars/bypass-login"; import { handleTutorial, Tutorial } from "#app/tutorial"; +import { bypassLogin, isApp, isBeta, isDev } from "#constants/app-constants"; import { AdminMode, getAdminModeName } from "#enums/admin-mode"; import { Button } from "#enums/buttons"; import { GameDataType } from "#enums/game-data-type"; @@ -237,7 +237,7 @@ export class MenuUiHandler extends MessageUiHandler { }); }; - if (import.meta.env.DEV) { + if (isBeta || isDev || isApp) { manageDataOptions.push({ label: i18next.t("menuUiHandler:importSession"), handler: () => { @@ -291,7 +291,7 @@ export class MenuUiHandler extends MessageUiHandler { }, keepOpen: true, }); - if (import.meta.env.DEV) { + if (isBeta || isDev || isApp) { manageDataOptions.push({ label: i18next.t("menuUiHandler:importData"), handler: () => { @@ -338,8 +338,7 @@ export class MenuUiHandler extends MessageUiHandler { keepOpen: true, }, ); - if (import.meta.env.DEV) { - // this should make sure we don't have this option in live + if (isBeta || isDev) { manageDataOptions.push({ label: "Test Dialogue", handler: () => { diff --git a/src/ui/handlers/save-slot-select-ui-handler.ts b/src/ui/handlers/save-slot-select-ui-handler.ts index 194971a005f..90bb6b1febf 100644 --- a/src/ui/handlers/save-slot-select-ui-handler.ts +++ b/src/ui/handlers/save-slot-select-ui-handler.ts @@ -1,5 +1,6 @@ import { GameMode } from "#app/game-mode"; import { globalScene } from "#app/global-scene"; +import { isBeta, isDev } from "#constants/app-constants"; import { Button } from "#enums/buttons"; import { GameModes } from "#enums/game-modes"; import { TextStyle } from "#enums/text-style"; @@ -202,7 +203,7 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler { false, 0, 19, - import.meta.env.DEV ? 300 : 2000, + isBeta || isDev ? 300 : 2000, ); }); return true; @@ -251,7 +252,7 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler { false, 0, 19, - import.meta.env.DEV ? 300 : 2000, + isBeta || isDev ? 300 : 2000, ); }); } else if (this.sessionSlots[cursor].hasData === false) { diff --git a/src/ui/handlers/title-ui-handler.ts b/src/ui/handlers/title-ui-handler.ts index 28165a33db7..a681dbc2a40 100644 --- a/src/ui/handlers/title-ui-handler.ts +++ b/src/ui/handlers/title-ui-handler.ts @@ -3,6 +3,7 @@ import { FAKE_TITLE_LOGO_CHANCE } from "#app/constants"; import { timedEventManager } from "#app/global-event-manager"; import { globalScene } from "#app/global-scene"; import { TimedEventDisplay } from "#app/timed-event-manager"; +import { isBeta, isDev } from "#constants/app-constants"; import { getSplashMessages } from "#data/splash-messages"; import { PlayerGender } from "#enums/player-gender"; import type { SpeciesId } from "#enums/species-id"; @@ -141,7 +142,7 @@ export class TitleUiHandler extends OptionSelectUiHandler { }), ); - const betaText = import.meta.env.DEV ? " (Beta)" : ""; + const betaText = isBeta || isDev ? " (Beta)" : ""; this.appVersionText.setText("v" + version + betaText); const ui = this.getUi(); diff --git a/src/utils/common.ts b/src/utils/common.ts index dd8044bfb6d..58deccb4d80 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,5 @@ import { pokerogueApi } from "#api/pokerogue-api"; +import { bypassLogin, isDev } from "#constants/app-constants"; import { BiomeId } from "#enums/biome-id"; import { MoneyFormat } from "#enums/money-format"; import type { Variant } from "#sprites/variant"; @@ -269,11 +270,8 @@ export function executeIf(condition: boolean, promiseFunc: () => Promise): export const sessionIdKey = "pokerogue_sessionId"; -/** `true` when run via `pnpm start:dev` (which runs `vite --mode development`) */ -export const isLocal = import.meta.env.MODE === "development"; - -/** Used to disable api calls when isLocal is true and a server is not found */ -export let isLocalServerConnected = true; +/** Used to disable api calls when `isDev` is true and a server is not found */ +export let isLocalServerConnected = !bypassLogin; /** * When locally running the game, "pings" the local server @@ -281,7 +279,7 @@ export let isLocalServerConnected = true; * sets isLocalServerConnected based on results */ export async function localPing(): Promise { - if (isLocal) { + if (isDev) { const titleStats = await pokerogueApi.getGameTitleStats(); isLocalServerConnected = !!titleStats; console.log("isLocalServerConnected:", isLocalServerConnected); diff --git a/src/utils/cookies.ts b/src/utils/cookies.ts index 407bd75da14..c95c777243a 100644 --- a/src/utils/cookies.ts +++ b/src/utils/cookies.ts @@ -1,4 +1,4 @@ -import { isBeta } from "#utils/utility-vars"; +import { isBeta } from "#constants/app-constants"; export function setCookie(cName: string, cValue: string): void { const expiration = new Date(); diff --git a/src/utils/utility-vars.ts b/src/utils/utility-vars.ts deleted file mode 100644 index 1f8eca00650..00000000000 --- a/src/utils/utility-vars.ts +++ /dev/null @@ -1,4 +0,0 @@ -// TODO: move this (and other global constants) to `src/constants/*-constants.ts` - -/** `true` if running on `beta.pokerogue.net` or via `pnpm start:beta` (which runs `vite --mode beta`) */ -export const isBeta = import.meta.env.MODE === "beta"; diff --git a/test/account.test.ts b/test/account.test.ts index 52d52778dad..b17b863445c 100644 --- a/test/account.test.ts +++ b/test/account.test.ts @@ -1,6 +1,6 @@ import { pokerogueApi } from "#api/pokerogue-api"; import { initLoggedInUser, loggedInUser, updateUserInfo } from "#app/account"; -import * as bypassLogin from "#app/global-vars/bypass-login"; +import * as appConstants from "#constants/app-constants"; import { describe, expect, it, vi } from "vitest"; describe("account", () => { @@ -15,7 +15,7 @@ describe("account", () => { describe("updateUserInfo", () => { it("should set loggedInUser! to Guest if bypassLogin is true", async () => { - vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(true); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(true); const [success, status] = await updateUserInfo(); @@ -26,7 +26,7 @@ describe("account", () => { }); it("should fetch user info from the API if bypassLogin is false", async () => { - vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([ { username: "test", @@ -47,7 +47,7 @@ describe("account", () => { }); it("should handle resolved API errors", async () => { - vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 401]); const [success, status] = await updateUserInfo(); @@ -57,7 +57,7 @@ describe("account", () => { }); it("should handle 500 API errors", async () => { - vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 500]); const [success, status] = await updateUserInfo(); diff --git a/test/system/game-data.test.ts b/test/system/game-data.test.ts index 42a3ac339ce..a2c06c80d66 100644 --- a/test/system/game-data.test.ts +++ b/test/system/game-data.test.ts @@ -1,6 +1,6 @@ import { pokerogueApi } from "#api/pokerogue-api"; import * as account from "#app/account"; -import * as bypassLoginModule from "#app/global-vars/bypass-login"; +import * as appConstants from "#constants/app-constants"; import { AbilityId } from "#enums/ability-id"; import { MoveId } from "#enums/move-id"; import { GameManager } from "#test/test-utils/game-manager"; @@ -33,13 +33,13 @@ describe("System - Game Data", () => { describe("tryClearSession", () => { beforeEach(() => { - vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(game.scene.gameData, "getSessionSaveData").mockReturnValue({} as SessionSaveData); vi.spyOn(account, "updateUserInfo").mockImplementation(async () => [true, 1]); }); it("should return [true, true] if bypassLogin is true", async () => { - vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(true); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(true); const result = await game.scene.gameData.tryClearSession(0); diff --git a/test/system/rename-run.test.ts b/test/system/rename-run.test.ts index 038303c3254..60e41ac0488 100644 --- a/test/system/rename-run.test.ts +++ b/test/system/rename-run.test.ts @@ -1,6 +1,6 @@ import * as account from "#app/account"; -import * as bypassLoginModule from "#app/global-vars/bypass-login"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; +import * as appConstants from "#constants/app-constants"; import { AbilityId } from "#enums/ability-id"; import { MoveId } from "#enums/move-id"; import { GameManager } from "#test/test-utils/game-manager"; @@ -33,7 +33,7 @@ describe("System - Rename Run", () => { describe("renameSession", () => { beforeEach(() => { - vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(account, "updateUserInfo").mockImplementation(async () => [true, 1]); }); @@ -52,7 +52,7 @@ describe("System - Rename Run", () => { }); it("should return true if bypassLogin is true", async () => { - vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(true); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(true); vi.spyOn(game.scene.gameData, "getSession").mockResolvedValue({} as SessionSaveData); const result = await game.scene.gameData.renameSession(0, "Named Run"); diff --git a/test/test-utils/game-wrapper.ts b/test/test-utils/game-wrapper.ts index 6c9cf53e455..20b29362927 100644 --- a/test/test-utils/game-wrapper.ts +++ b/test/test-utils/game-wrapper.ts @@ -2,7 +2,7 @@ import { BattleScene } from "#app/battle-scene"; // biome-ignore lint/performance/noNamespaceImport: Necessary in order to mock the var -import * as bypassLoginModule from "#app/global-vars/bypass-login"; +import * as appConstants from "#constants/app-constants"; import { MoveAnim } from "#data/battle-anims"; import { Pokemon } from "#field/pokemon"; import { version } from "#package.json"; @@ -32,7 +32,7 @@ export class GameWrapper { Phaser.Math.RND.sow(["test"]); // vi.spyOn(Utils, "apiFetch", "get").mockReturnValue(fetch); if (bypassLogin) { - vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(true); + vi.spyOn(appConstants, "bypassLogin", "get").mockReturnValue(true); } this.game = phaserGame; MoveAnim.prototype.getAnim = () => ({ diff --git a/tsconfig.json b/tsconfig.json index a008fdb3aa5..6b06c8c78b9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,6 +32,7 @@ "#abilities/*": ["./src/data/abilities/*.ts"], "#api/*": ["./src/plugins/api/*.ts"], "#balance/*": ["./src/data/balance/*.ts"], + "#constants/*": ["./src/constants/*.ts"], "#enums/*": ["./src/enums/*.ts"], "#events/*": ["./src/events/*.ts"], "#field/*": ["./src/field/*.ts"],