mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-25 16:26:25 +00:00
fix circular dependencies with api
This commit is contained in:
parent
d927ed8e6c
commit
e66bceded3
@ -1,4 +1,4 @@
|
||||
import type { UserInfo } from "#app/account";
|
||||
import type { UserInfo } from "#app/@types/UserInfo";
|
||||
|
||||
export interface AccountInfoResponse extends UserInfo {}
|
||||
|
||||
|
7
src/@types/UserInfo.ts
Normal file
7
src/@types/UserInfo.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface UserInfo {
|
||||
username: string;
|
||||
lastSessionSlot: number;
|
||||
discordId: string;
|
||||
googleId: string;
|
||||
hasAdminRole: boolean;
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -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();
|
||||
|
@ -328,6 +328,7 @@ export async function localPing() {
|
||||
if (isLocal) {
|
||||
const titleStats = await pokerogueApi.getGameTitleStats();
|
||||
isLocalServerConnected = !!titleStats;
|
||||
console.log("isLocalServerConnected:", isLocalServerConnected);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user