rename api to pokerogue-api

This commit is contained in:
flx-sta 2024-10-04 09:58:37 -07:00
parent 9df8a616d4
commit 70f78d1060
10 changed files with 33 additions and 33 deletions

View File

@ -1,5 +1,5 @@
import { bypassLogin } from "./battle-scene"; import { bypassLogin } from "./battle-scene";
import { api } from "./plugins/api/api"; import { pokerogueApi } from "./plugins/api/pokerogue-api";
import * as Utils from "./utils"; import * as Utils from "./utils";
export interface UserInfo { export interface UserInfo {
@ -44,7 +44,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
}); });
return resolve([ true, 200 ]); return resolve([ true, 200 ]);
} }
api.getAccountInfo().then((accountInfoOrStatus) => { pokerogueApi.getAccountInfo().then((accountInfoOrStatus) => {
if (typeof accountInfoOrStatus === "number") { if (typeof accountInfoOrStatus === "number") {
resolve([ false, accountInfoOrStatus ]); resolve([ false, accountInfoOrStatus ]);
return; return;

View File

@ -6,7 +6,7 @@ import { Starter } from "#app/ui/starter-select-ui-handler";
import * as Utils from "#app/utils"; import * as Utils from "#app/utils";
import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import { speciesStarterCosts } from "#app/data/balance/starters"; 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 { export interface DailyRunConfig {
seed: integer; seed: integer;
@ -15,7 +15,7 @@ export interface DailyRunConfig {
export function fetchDailyRunSeed(): Promise<string | null> { export function fetchDailyRunSeed(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => { return new Promise<string | null>((resolve, reject) => {
api.getDailySeed().then(dailySeed => { pokerogueApi.getDailySeed().then(dailySeed => {
resolve(dailySeed); resolve(dailySeed);
}).catch(err => reject(err)); // TODO: does this ever reject with the api class? }).catch(err => reject(err)); // TODO: does this ever reject with the api class?
}); });

View File

@ -23,7 +23,7 @@ import * as Utils from "#app/utils";
import { PlayerGender } from "#enums/player-gender"; import { PlayerGender } from "#enums/player-gender";
import { TrainerType } from "#enums/trainer-type"; import { TrainerType } from "#enums/trainer-type";
import i18next from "i18next"; import i18next from "i18next";
import { api } from "#app/plugins/api/api"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
export class GameOverPhase extends BattlePhase { export class GameOverPhase extends BattlePhase {
private victory: boolean; 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 Offline, execute offlineNewClear(), a localStorage implementation of newClear daily run checks */
if (this.victory) { if (this.victory) {
if (!Utils.isLocal || Utils.isLocalServerConnected) { if (!Utils.isLocal || Utils.isLocalServerConnected) {
api.newclearSession(this.scene.sessionSlotId, clientSessionId) pokerogueApi.newclearSession(this.scene.sessionSlotId, clientSessionId)
.then((isNewClear) => doGameOver(!!isNewClear)); .then((isNewClear) => doGameOver(!!isNewClear));
} else { } else {
this.scene.gameData.offlineNewClear(this.scene).then(result => { this.scene.gameData.offlineNewClear(this.scene).then(result => {

View File

@ -14,7 +14,7 @@ import type { VerifySavedataResponse } from "./models/VerifySavedata";
type DataType = "json" | "form-urlencoded"; type DataType = "json" | "form-urlencoded";
export class Api { export class PokerogueApi {
//#region Fields //#region Fields
private readonly base: string; private readonly base: string;
@ -161,7 +161,7 @@ export class Api {
* Verify if the session is valid. * Verify if the session is valid.
* If not the {@linkcode SystemSaveData} is returned. * If not the {@linkcode SystemSaveData} is returned.
* @param sessionId The savedata session ID * @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) { public async verifySystemSavedata(sessionId: string) {
try { try {
@ -261,7 +261,7 @@ export class Api {
if (response.ok) { if (response.ok) {
if (loggedInUser) { if (loggedInUser) {
loggedInUser.lastSessionSlot = -1; // TODO: is the bang correct? loggedInUser.lastSessionSlot = -1;
} }
localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`); localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`);
@ -437,4 +437,4 @@ export class Api {
//#endregion //#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");

View File

@ -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 { applySessionDataPatches, applySettingsDataPatches, applySystemDataPatches } from "#app/system/version-converter";
import { MysteryEncounterSaveData } from "#app/data/mystery-encounters/mystery-encounter-save-data"; import { MysteryEncounterSaveData } from "#app/data/mystery-encounters/mystery-encounter-save-data";
import { MysteryEncounterType } from "#enums/mystery-encounter-type"; 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[] = [ export const defaultStarterSpecies: Species[] = [
Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE,
@ -397,7 +397,7 @@ export class GameData {
localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(systemData, bypassLogin)); localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(systemData, bypassLogin));
if (!bypassLogin) { if (!bypassLogin) {
api.updateSystemSavedata({clientSessionId}, systemData) pokerogueApi.updateSystemSavedata({clientSessionId}, systemData)
.then(error => { .then(error => {
this.scene.ui.savingIcon.hide(); this.scene.ui.savingIcon.hide();
if (error) { if (error) {
@ -430,7 +430,7 @@ export class GameData {
} }
if (!bypassLogin) { if (!bypassLogin) {
api.getSystemSavedata(clientSessionId) pokerogueApi.getSystemSavedata(clientSessionId)
.then(saveDataOrErr => { .then(saveDataOrErr => {
if (!saveDataOrErr || saveDataOrErr.length === 0 || saveDataOrErr[0] !== "{") { if (!saveDataOrErr || saveDataOrErr.length === 0 || saveDataOrErr[0] !== "{") {
if (saveDataOrErr?.startsWith("sql: no rows in result set")) { if (saveDataOrErr?.startsWith("sql: no rows in result set")) {
@ -705,7 +705,7 @@ export class GameData {
return true; return true;
} }
const systemData = api.verifySystemSavedata(clientSessionId); const systemData = pokerogueApi.verifySystemSavedata(clientSessionId);
if (systemData) { if (systemData) {
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
@ -984,7 +984,7 @@ export class GameData {
}; };
if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`)) { if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`)) {
api.getSessionSavedata(slotId, clientSessionId) pokerogueApi.getSessionSavedata(slotId, clientSessionId)
.then(async response => { .then(async response => {
if (!response && response?.length === 0 || response?.[0] !== "{") { if (!response && response?.length === 0 || response?.[0] !== "{") {
console.error(response); console.error(response);
@ -1132,7 +1132,7 @@ export class GameData {
if (success !== null && !success) { if (success !== null && !success) {
return resolve(false); return resolve(false);
} }
api.deleteSessionSavedata(slotId, clientSessionId).then(error => { pokerogueApi.deleteSessionSavedata(slotId, clientSessionId).then(error => {
if (error) { if (error) {
if (error.startsWith("session out of date")) { if (error.startsWith("session out of date")) {
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
@ -1189,7 +1189,7 @@ export class GameData {
result = [true, true]; result = [true, true];
} else { } else {
const sessionData = this.getSessionSaveData(scene); 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) { if (!jsonResponse?.error) {
result = [true, jsonResponse?.success ?? false]; result = [true, jsonResponse?.success ?? false];
@ -1309,7 +1309,7 @@ export class GameData {
console.debug("Session data saved"); console.debug("Session data saved");
if (!bypassLogin && sync) { if (!bypassLogin && sync) {
api.updateAllSavedata(request) pokerogueApi.updateAllSavedata(request)
.then(error => { .then(error => {
if (sync) { if (sync) {
this.scene.lastSavePlayTime = 0; this.scene.lastSavePlayTime = 0;
@ -1359,9 +1359,9 @@ export class GameData {
let promise: Promise<any> = Promise.resolve(null); let promise: Promise<any> = Promise.resolve(null);
if (dataType === GameDataType.SYSTEM) { if (dataType === GameDataType.SYSTEM) {
promise = api.getSystemSavedata(clientSessionId); promise = pokerogueApi.getSystemSavedata(clientSessionId);
} else if (dataType === GameDataType.SESSION) { } else if (dataType === GameDataType.SESSION) {
promise = api.getSessionSavedata(slotId, clientSessionId); promise = pokerogueApi.getSessionSavedata(slotId, clientSessionId);
} }
promise promise
@ -1457,9 +1457,9 @@ export class GameData {
const { trainerId, secretId } = this; const { trainerId, secretId } = this;
let updatePromise: Promise<string | null>; let updatePromise: Promise<string | null>;
if (dataType === GameDataType.SESSION) { if (dataType === GameDataType.SESSION) {
updatePromise = api.updateSessionSavedata({slot: slotId, trainerId, secretId, clientSessionId}, dataStr); updatePromise = pokerogueApi.updateSessionSavedata({slot: slotId, trainerId, secretId, clientSessionId}, dataStr);
} else { } else {
updatePromise = api.updateSystemSavedata({trainerId, secretId, clientSessionId}, dataStr); updatePromise = pokerogueApi.updateSystemSavedata({trainerId, secretId, clientSessionId}, dataStr);
} }
updatePromise updatePromise
.then(error => { .then(error => {

View File

@ -3,7 +3,7 @@ import BattleScene from "../battle-scene";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { TextStyle, addTextObject } from "./text"; import { TextStyle, addTextObject } from "./text";
import { WindowVariant, addWindow } from "./ui-theme"; import { WindowVariant, addWindow } from "./ui-theme";
import { api } from "#app/plugins/api/api"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
export interface RankingEntry { export interface RankingEntry {
rank: integer, rank: integer,
@ -192,9 +192,9 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container {
} }
Utils.executeIf(category !== this.category || this.pageCount === undefined, 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(() => { ).then(() => {
api.getDailyRankings(category, page) pokerogueApi.getDailyRankings(category, page)
.then(rankings => { .then(rankings => {
this.page = page; this.page = page;
this.category = category; this.category = category;

View File

@ -7,7 +7,7 @@ import BattleScene from "#app/battle-scene";
import { addTextObject, TextStyle } from "./text"; import { addTextObject, TextStyle } from "./text";
import { addWindow } from "./ui-theme"; import { addWindow } from "./ui-theme";
import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; 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 { interface BuildInteractableImageOpts {
scale?: number; scale?: number;
@ -136,7 +136,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler {
const [usernameInput, passwordInput] = this.inputs; const [usernameInput, passwordInput] = this.inputs;
api.login(usernameInput.text, passwordInput.text).then(isSuccess => { pokerogueApi.login(usernameInput.text, passwordInput.text).then(isSuccess => {
if (isSuccess) { if (isSuccess) {
originalLoginAction && originalLoginAction(); originalLoginAction && originalLoginAction();
} else { } else {

View File

@ -13,7 +13,7 @@ import { GameDataType } from "#enums/game-data-type";
import BgmBar from "#app/ui/bgm-bar"; import BgmBar from "#app/ui/bgm-bar";
import AwaitableUiHandler from "./awaitable-ui-handler"; import AwaitableUiHandler from "./awaitable-ui-handler";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; 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 { enum MenuOptions {
GAME_SETTINGS, GAME_SETTINGS,
@ -587,7 +587,7 @@ export default class MenuUiHandler extends MessageUiHandler {
success = true; success = true;
const doLogout = () => { const doLogout = () => {
ui.setMode(Mode.LOADING, { ui.setMode(Mode.LOADING, {
buttonActions: [], fadeOut: () => api.logout().then(() => { buttonActions: [], fadeOut: () => pokerogueApi.logout().then(() => {
updateUserInfo().then(() => this.scene.reset(true, true)); updateUserInfo().then(() => this.scene.reset(true, true));
}) })
}); });

View File

@ -7,7 +7,7 @@ import { getSplashMessages } from "../data/splash-messages";
import i18next from "i18next"; import i18next from "i18next";
import { TimedEventDisplay } from "#app/timed-event-manager"; import { TimedEventDisplay } from "#app/timed-event-manager";
import { version } from "../../package.json"; 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 { export default class TitleUiHandler extends OptionSelectUiHandler {
/** If the stats can not be retrieved, use this fallback value */ /** If the stats can not be retrieved, use this fallback value */
@ -79,7 +79,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
} }
updateTitleStats(): void { updateTitleStats(): void {
api.getGameTitleStats() pokerogueApi.getGameTitleStats()
.then(stats => { .then(stats => {
if (stats) { if (stats) {
this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`);

View File

@ -1,7 +1,7 @@
import { MoneyFormat } from "#enums/money-format"; import { MoneyFormat } from "#enums/money-format";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import i18next from "i18next"; import i18next from "i18next";
import { api } from "./plugins/api/api"; import { pokerogueApi } from "./plugins/api/pokerogue-api";
export type nil = null | undefined; export type nil = null | undefined;
@ -326,7 +326,7 @@ export function getCookie(cName: string): string {
*/ */
export async function localPing() { export async function localPing() {
if (isLocal) { if (isLocal) {
const titleStats = await api.getGameTitleStats(); const titleStats = await pokerogueApi.getGameTitleStats();
isLocalServerConnected = !!titleStats; isLocalServerConnected = !!titleStats;
} }
} }