mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-25 16:26:25 +00:00
rename api
to pokerogue-api
This commit is contained in:
parent
9df8a616d4
commit
70f78d1060
@ -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;
|
||||
|
@ -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<string | null> {
|
||||
return new Promise<string | null>((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?
|
||||
});
|
||||
|
@ -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 => {
|
||||
|
@ -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");
|
@ -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<any> = 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<string | null>;
|
||||
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 => {
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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));
|
||||
})
|
||||
});
|
||||
|
@ -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")}`);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user