diff --git a/src/@types/PokerogueAccountApi.ts b/src/@types/PokerogueAccountApi.ts index 765628c2358..68d0a5e7730 100644 --- a/src/@types/PokerogueAccountApi.ts +++ b/src/@types/PokerogueAccountApi.ts @@ -1,4 +1,4 @@ -import type { UserInfo } from "#app/account"; +import type { UserInfo } from "#app/@types/UserInfo"; export interface AccountInfoResponse extends UserInfo {} diff --git a/src/@types/UserInfo.ts b/src/@types/UserInfo.ts new file mode 100644 index 00000000000..c8a0c6ecb26 --- /dev/null +++ b/src/@types/UserInfo.ts @@ -0,0 +1,7 @@ +export interface UserInfo { + username: string; + lastSessionSlot: number; + discordId: string; + googleId: string; + hasAdminRole: boolean; +} diff --git a/src/account.ts b/src/account.ts index 4c91b61dd67..ea5891a2454 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,15 +1,8 @@ -import { bypassLogin } from "./battle-scene"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; +import type { UserInfo } from "#app/@types/UserInfo"; +import { bypassLogin } from "./battle-scene"; import * as Utils from "./utils"; -export interface UserInfo { - username: string; - lastSessionSlot: number; - discordId: string; - googleId: string; - hasAdminRole: boolean; -} - export let loggedInUser: UserInfo | null = null; // This is a random string that is used to identify the client session - unique per session (tab or window) so that the game will only save on the one that the server is expecting export const clientSessionId = Utils.randomString(32); diff --git a/src/plugins/api/pokerogue-session-savedata-api.ts b/src/plugins/api/pokerogue-session-savedata-api.ts index 7ac4b06fef0..756506918e8 100644 --- a/src/plugins/api/pokerogue-session-savedata-api.ts +++ b/src/plugins/api/pokerogue-session-savedata-api.ts @@ -6,7 +6,6 @@ import type { NewClearSessionSavedataRequest, UpdateSessionSavedataRequest, } from "#app/@types/PokerogueSessionSavedataApi"; -import { loggedInUser } from "#app/account"; import { ApiBase } from "#app/plugins/api/api-base"; import type { SessionSaveData } from "#app/system/game-data"; @@ -74,7 +73,7 @@ export class PokerogueSessionSavedataApi extends ApiBase { /** * Delete a session savedata slot. * @param params The {@linkcode DeleteSessionSavedataRequest} to send - * @returns The session as `string` + * @returns An error message if something went wrong */ public async delete(params: DeleteSessionSavedataRequest) { try { @@ -82,11 +81,7 @@ export class PokerogueSessionSavedataApi extends ApiBase { const response = await this.doGet(`/savedata/session/delete?${urlSearchParams}`); if (response.ok) { - if (loggedInUser) { - loggedInUser.lastSessionSlot = -1; - } - - localStorage.removeItem(`sessionData${params.slot > 0 ? params.slot : ""}_${loggedInUser?.username}`); + return null; } else { return await response.text(); } @@ -107,18 +102,14 @@ export class PokerogueSessionSavedataApi extends ApiBase { const urlSearchParams = this.toUrlSearchParams(params); const response = await this.doPost(`/savedata/session/clear?${urlSearchParams}`, sessionData); - if (response.ok) { - if (loggedInUser) { - loggedInUser!.lastSessionSlot = -1; - } - localStorage.removeItem(`sessionData${params.slot > 0 ? params.slot : ""}_${loggedInUser?.username}`); - } - return (await response.json()) as ClearSessionSavedataResponse; } catch (err) { console.warn("Could not clear session savedata!", err); } - return null; + return { + error: "Unknown error", + success: false, + } as ClearSessionSavedataResponse; } } diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 9ccff14fdb0..21c65a01594 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -1142,8 +1142,15 @@ export class GameData { } console.error(error); resolve(false); + } else { + if (loggedInUser) { + loggedInUser.lastSessionSlot = -1; + } + + localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`); + resolve(true); + } - resolve(true); }); }); }); @@ -1196,6 +1203,10 @@ export class GameData { if (!jsonResponse?.error) { result = [true, jsonResponse?.success ?? false]; + if (loggedInUser) { + loggedInUser!.lastSessionSlot = -1; + } + localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`); } else { if (jsonResponse && jsonResponse.error?.startsWith("session out of date")) { this.scene.clearPhaseQueue(); diff --git a/src/utils.ts b/src/utils.ts index 9014519b7a9..8057a878f56 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -328,6 +328,7 @@ export async function localPing() { if (isLocal) { const titleStats = await pokerogueApi.getGameTitleStats(); isLocalServerConnected = !!titleStats; + console.log("isLocalServerConnected:", isLocalServerConnected); } }