diff --git a/src/account.ts b/src/account.ts index 38895366e98..974c61788d9 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,5 +1,5 @@ import { bypassLogin } from "./battle-scene"; -import { api } from "./plugins/api/api"; +import { pokerogueApi } from "./plugins/api/pokerogue-api"; import * as Utils from "./utils"; export interface UserInfo { @@ -44,7 +44,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> { }); return resolve([ true, 200 ]); } - api.getAccountInfo().then((accountInfoOrStatus) => { + pokerogueApi.getAccountInfo().then((accountInfoOrStatus) => { if (typeof accountInfoOrStatus === "number") { resolve([ false, accountInfoOrStatus ]); return; diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 7d049f6d51c..f6fa3fce72b 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -6,7 +6,7 @@ import { 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 { speciesStarterCosts } from "#app/data/balance/starters"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; export interface DailyRunConfig { seed: integer; @@ -15,7 +15,7 @@ export interface DailyRunConfig { export function fetchDailyRunSeed(): Promise { return new Promise((resolve, reject) => { - api.getDailySeed().then(dailySeed => { + pokerogueApi.getDailySeed().then(dailySeed => { resolve(dailySeed); }).catch(err => reject(err)); // TODO: does this ever reject with the api class? }); diff --git a/src/phases/game-over-phase.ts b/src/phases/game-over-phase.ts index 0d6df7443d4..b5cf9b1c4b8 100644 --- a/src/phases/game-over-phase.ts +++ b/src/phases/game-over-phase.ts @@ -23,7 +23,7 @@ import * as Utils from "#app/utils"; import { PlayerGender } from "#enums/player-gender"; import { TrainerType } from "#enums/trainer-type"; import i18next from "i18next"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; export class GameOverPhase extends BattlePhase { private victory: boolean; @@ -178,7 +178,7 @@ export class GameOverPhase extends BattlePhase { If Offline, execute offlineNewClear(), a localStorage implementation of newClear daily run checks */ if (this.victory) { if (!Utils.isLocal || Utils.isLocalServerConnected) { - api.newclearSession(this.scene.sessionSlotId, clientSessionId) + pokerogueApi.newclearSession(this.scene.sessionSlotId, clientSessionId) .then((isNewClear) => doGameOver(!!isNewClear)); } else { this.scene.gameData.offlineNewClear(this.scene).then(result => { diff --git a/src/plugins/api/api.ts b/src/plugins/api/pokerogue-api.ts similarity index 98% rename from src/plugins/api/api.ts rename to src/plugins/api/pokerogue-api.ts index af883cec162..ad924f0a3cd 100644 --- a/src/plugins/api/api.ts +++ b/src/plugins/api/pokerogue-api.ts @@ -14,7 +14,7 @@ import type { VerifySavedataResponse } from "./models/VerifySavedata"; type DataType = "json" | "form-urlencoded"; -export class Api { +export class PokerogueApi { //#region Fields private readonly base: string; @@ -161,7 +161,7 @@ export class Api { * Verify if the session is valid. * If not the {@linkcode SystemSaveData} is returned. * @param sessionId The savedata session ID - * @returns A {@linkcode SystemSaveData} if NOT valid, otherwise `null`. + * @returns A {@linkcode SystemSaveData} if **NOT** valid, otherwise `null`. */ public async verifySystemSavedata(sessionId: string) { try { @@ -261,7 +261,7 @@ export class Api { if (response.ok) { if (loggedInUser) { - loggedInUser.lastSessionSlot = -1; // TODO: is the bang correct? + loggedInUser.lastSessionSlot = -1; } localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`); @@ -437,4 +437,4 @@ export class Api { //#endregion } -export const api = new Api(import.meta.env.VITE_SERVER_URL ?? "http://localhost:80001"); +export const pokerogueApi = new PokerogueApi(import.meta.env.VITE_SERVER_URL ?? "http://localhost:80001"); diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 73984d18682..5c20eaddd5b 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -49,7 +49,7 @@ import { RUN_HISTORY_LIMIT } from "#app/ui/run-history-ui-handler"; import { applySessionDataPatches, applySettingsDataPatches, applySystemDataPatches } from "#app/system/version-converter"; import { MysteryEncounterSaveData } from "#app/data/mystery-encounters/mystery-encounter-save-data"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; export const defaultStarterSpecies: Species[] = [ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, @@ -397,7 +397,7 @@ export class GameData { localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(systemData, bypassLogin)); if (!bypassLogin) { - api.updateSystemSavedata({clientSessionId}, systemData) + pokerogueApi.updateSystemSavedata({clientSessionId}, systemData) .then(error => { this.scene.ui.savingIcon.hide(); if (error) { @@ -430,7 +430,7 @@ export class GameData { } if (!bypassLogin) { - api.getSystemSavedata(clientSessionId) + pokerogueApi.getSystemSavedata(clientSessionId) .then(saveDataOrErr => { if (!saveDataOrErr || saveDataOrErr.length === 0 || saveDataOrErr[0] !== "{") { if (saveDataOrErr?.startsWith("sql: no rows in result set")) { @@ -705,7 +705,7 @@ export class GameData { return true; } - const systemData = api.verifySystemSavedata(clientSessionId); + const systemData = pokerogueApi.verifySystemSavedata(clientSessionId); if (systemData) { this.scene.clearPhaseQueue(); @@ -984,7 +984,7 @@ export class GameData { }; if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`)) { - api.getSessionSavedata(slotId, clientSessionId) + pokerogueApi.getSessionSavedata(slotId, clientSessionId) .then(async response => { if (!response && response?.length === 0 || response?.[0] !== "{") { console.error(response); @@ -1132,7 +1132,7 @@ export class GameData { if (success !== null && !success) { return resolve(false); } - api.deleteSessionSavedata(slotId, clientSessionId).then(error => { + pokerogueApi.deleteSessionSavedata(slotId, clientSessionId).then(error => { if (error) { if (error.startsWith("session out of date")) { this.scene.clearPhaseQueue(); @@ -1189,7 +1189,7 @@ export class GameData { result = [true, true]; } else { const sessionData = this.getSessionSaveData(scene); - const jsonResponse = await api.clearSessionSavedata(slotId, this.trainerId, clientSessionId, sessionData); + const jsonResponse = await pokerogueApi.clearSessionSavedata(slotId, this.trainerId, clientSessionId, sessionData); if (!jsonResponse?.error) { result = [true, jsonResponse?.success ?? false]; @@ -1309,7 +1309,7 @@ export class GameData { console.debug("Session data saved"); if (!bypassLogin && sync) { - api.updateAllSavedata(request) + pokerogueApi.updateAllSavedata(request) .then(error => { if (sync) { this.scene.lastSavePlayTime = 0; @@ -1359,9 +1359,9 @@ export class GameData { let promise: Promise = Promise.resolve(null); if (dataType === GameDataType.SYSTEM) { - promise = api.getSystemSavedata(clientSessionId); + promise = pokerogueApi.getSystemSavedata(clientSessionId); } else if (dataType === GameDataType.SESSION) { - promise = api.getSessionSavedata(slotId, clientSessionId); + promise = pokerogueApi.getSessionSavedata(slotId, clientSessionId); } promise @@ -1457,9 +1457,9 @@ export class GameData { const { trainerId, secretId } = this; let updatePromise: Promise; if (dataType === GameDataType.SESSION) { - updatePromise = api.updateSessionSavedata({slot: slotId, trainerId, secretId, clientSessionId}, dataStr); + updatePromise = pokerogueApi.updateSessionSavedata({slot: slotId, trainerId, secretId, clientSessionId}, dataStr); } else { - updatePromise = api.updateSystemSavedata({trainerId, secretId, clientSessionId}, dataStr); + updatePromise = pokerogueApi.updateSystemSavedata({trainerId, secretId, clientSessionId}, dataStr); } updatePromise .then(error => { diff --git a/src/ui/daily-run-scoreboard.ts b/src/ui/daily-run-scoreboard.ts index 5ac7ea37387..529655de420 100644 --- a/src/ui/daily-run-scoreboard.ts +++ b/src/ui/daily-run-scoreboard.ts @@ -3,7 +3,7 @@ import BattleScene from "../battle-scene"; import * as Utils from "../utils"; import { TextStyle, addTextObject } from "./text"; import { WindowVariant, addWindow } from "./ui-theme"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; export interface RankingEntry { rank: integer, @@ -192,9 +192,9 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { } Utils.executeIf(category !== this.category || this.pageCount === undefined, - () => api.getDailyRankingsPageCount(category).then(count => this.pageCount = count) + () => pokerogueApi.getDailyRankingsPageCount(category).then(count => this.pageCount = count) ).then(() => { - api.getDailyRankings(category, page) + pokerogueApi.getDailyRankings(category, page) .then(rankings => { this.page = page; this.category = category; diff --git a/src/ui/login-form-ui-handler.ts b/src/ui/login-form-ui-handler.ts index 84ae57cda7a..579328f029f 100644 --- a/src/ui/login-form-ui-handler.ts +++ b/src/ui/login-form-ui-handler.ts @@ -7,7 +7,7 @@ import BattleScene from "#app/battle-scene"; import { addTextObject, TextStyle } from "./text"; import { addWindow } from "./ui-theme"; import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; interface BuildInteractableImageOpts { scale?: number; @@ -136,7 +136,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { const [usernameInput, passwordInput] = this.inputs; - api.login(usernameInput.text, passwordInput.text).then(isSuccess => { + pokerogueApi.login(usernameInput.text, passwordInput.text).then(isSuccess => { if (isSuccess) { originalLoginAction && originalLoginAction(); } else { diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index a8100401c4b..19247d95f23 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -13,7 +13,7 @@ import { GameDataType } from "#enums/game-data-type"; import BgmBar from "#app/ui/bgm-bar"; import AwaitableUiHandler from "./awaitable-ui-handler"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; enum MenuOptions { GAME_SETTINGS, @@ -587,7 +587,7 @@ export default class MenuUiHandler extends MessageUiHandler { success = true; const doLogout = () => { ui.setMode(Mode.LOADING, { - buttonActions: [], fadeOut: () => api.logout().then(() => { + buttonActions: [], fadeOut: () => pokerogueApi.logout().then(() => { updateUserInfo().then(() => this.scene.reset(true, true)); }) }); diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index b650d9d9696..1f6aaa8380e 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -7,7 +7,7 @@ import { getSplashMessages } from "../data/splash-messages"; import i18next from "i18next"; import { TimedEventDisplay } from "#app/timed-event-manager"; import { version } from "../../package.json"; -import { api } from "#app/plugins/api/api"; +import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; export default class TitleUiHandler extends OptionSelectUiHandler { /** If the stats can not be retrieved, use this fallback value */ @@ -79,7 +79,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { } updateTitleStats(): void { - api.getGameTitleStats() + pokerogueApi.getGameTitleStats() .then(stats => { if (stats) { this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); diff --git a/src/utils.ts b/src/utils.ts index 1ea1407c3e8..132f9dd5393 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import { MoneyFormat } from "#enums/money-format"; import { Moves } from "#enums/moves"; import i18next from "i18next"; -import { api } from "./plugins/api/api"; +import { pokerogueApi } from "./plugins/api/pokerogue-api"; export type nil = null | undefined; @@ -326,7 +326,7 @@ export function getCookie(cName: string): string { */ export async function localPing() { if (isLocal) { - const titleStats = await api.getGameTitleStats(); + const titleStats = await pokerogueApi.getGameTitleStats(); isLocalServerConnected = !!titleStats; } }