mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-31 13:17:21 +00:00
migrate clear session savedata to api
This commit is contained in:
parent
9f63360484
commit
ebf897822e
@ -1,5 +1,7 @@
|
|||||||
|
import type { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api";
|
||||||
import { loggedInUser } from "#app/account";
|
import { loggedInUser } from "#app/account";
|
||||||
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
||||||
|
import type { SessionSaveData } from "#app/system/game-data";
|
||||||
import type { RankingEntry, ScoreboardCategory } from "#app/ui/daily-run-scoreboard";
|
import type { RankingEntry, ScoreboardCategory } from "#app/ui/daily-run-scoreboard";
|
||||||
import { getCookie, removeCookie, setCookie } from "#app/utils";
|
import { getCookie, removeCookie, setCookie } from "#app/utils";
|
||||||
import type { AccountInfoResponse } from "./models/AccountInfo";
|
import type { AccountInfoResponse } from "./models/AccountInfo";
|
||||||
@ -251,6 +253,42 @@ export class Api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the session savedata of the given slot.
|
||||||
|
* @param slotId The slot ID
|
||||||
|
* @param trainerId The trainer ID
|
||||||
|
* @param sessionId The session ID
|
||||||
|
* @param sessionData The {@linkcode SessionSaveData} object
|
||||||
|
*/
|
||||||
|
public async clearSessionSavedata(
|
||||||
|
slotId: number,
|
||||||
|
trainerId: number,
|
||||||
|
sessionId: string,
|
||||||
|
sessionData: SessionSaveData
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.append("slot", String(slotId));
|
||||||
|
params.append("trainerId", String(trainerId));
|
||||||
|
params.append("clientSessionId", sessionId);
|
||||||
|
|
||||||
|
const response = await this.doPost<SessionSaveData>(`/savedata/session/clear?${params}`, sessionData);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
if (loggedInUser) {
|
||||||
|
loggedInUser!.lastSessionSlot = -1;
|
||||||
|
}
|
||||||
|
localStorage.removeItem(`sessionData${slotId > 0 ? slotId : ""}_${loggedInUser?.username}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (await response.json()) as PokerogueApiClearSessionData;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Could not clear session savedata!", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the daily rankings for a {@linkcode ScoreboardCategory}.
|
* Get the daily rankings for a {@linkcode ScoreboardCategory}.
|
||||||
* @param category The {@linkcode ScoreboardCategory} to fetch.
|
* @param category The {@linkcode ScoreboardCategory} to fetch.
|
||||||
|
@ -49,7 +49,6 @@ 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 { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api";
|
|
||||||
import { api } from "#app/plugins/api/api";
|
import { api } from "#app/plugins/api/api";
|
||||||
|
|
||||||
export const defaultStarterSpecies: Species[] = [
|
export const defaultStarterSpecies: Species[] = [
|
||||||
@ -1190,17 +1189,10 @@ export class GameData {
|
|||||||
result = [true, true];
|
result = [true, true];
|
||||||
} else {
|
} else {
|
||||||
const sessionData = this.getSessionSaveData(scene);
|
const sessionData = this.getSessionSaveData(scene);
|
||||||
const response = await Utils.apiPost(`savedata/session/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true);
|
const jsonResponse = await api.clearSessionSavedata(slotId, this.trainerId, clientSessionId, sessionData);
|
||||||
|
|
||||||
if (response.ok) {
|
if (!jsonResponse?.error) {
|
||||||
loggedInUser!.lastSessionSlot = -1; // TODO: is the bang correct?
|
result = [true, jsonResponse?.success ?? false];
|
||||||
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser?.username}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const jsonResponse: PokerogueApiClearSessionData = await response.json();
|
|
||||||
|
|
||||||
if (!jsonResponse.error) {
|
|
||||||
result = [true, jsonResponse.success ?? false];
|
|
||||||
} else {
|
} else {
|
||||||
if (jsonResponse && jsonResponse.error?.startsWith("session out of date")) {
|
if (jsonResponse && jsonResponse.error?.startsWith("session out of date")) {
|
||||||
this.scene.clearPhaseQueue();
|
this.scene.clearPhaseQueue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user