Fix clear ignoring errors from server

This commit is contained in:
Sirz Benjie 2025-04-26 23:20:14 -05:00
parent 89a9d55d3c
commit ce0a488738
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
2 changed files with 19 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import ChallengeData from "#app/system/challenge-data";
import TrainerData from "#app/system/trainer-data";
import ArenaData from "#app/system/arena-data";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { MessagePhase } from "./message-phase";
export class GameOverPhase extends BattlePhase {
private isVictory: boolean;
@ -122,7 +123,7 @@ export class GameOverPhase extends BattlePhase {
globalScene.disableMenu = true;
globalScene.time.delayedCall(1000, () => {
let firstClear = false;
if (this.isVictory && newClear) {
if (this.isVictory) {
if (globalScene.gameMode.isClassic) {
firstClear = globalScene.validateAchv(achvs.CLASSIC_VICTORY);
globalScene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY);
@ -226,7 +227,17 @@ export class GameOverPhase extends BattlePhase {
isVictory: this.isVictory,
clientSessionId: clientSessionId,
})
.then(success => doGameOver(!!success));
.then(success => doGameOver(!globalScene.gameMode.isDaily || !!success))
.catch(_err => {
globalScene.clearPhaseQueue();
globalScene.clearPhaseQueueSplice();
globalScene.unshiftPhase(new MessagePhase(i18next.t("menu:serverCommunicationFailed"), 2500));
// force the game to reload after 2 seconds.
setTimeout(() => {
window.location.reload();
}, 2000);
this.end();
});
} else if (this.isVictory) {
globalScene.gameData.offlineNewClear().then(result => {
doGameOver(result);

View File

@ -20,17 +20,20 @@ export class PokerogueSessionSavedataApi extends ApiBase {
* *This is **NOT** the same as {@linkcode clear | clear()}.*
* @param params The {@linkcode NewClearSessionSavedataRequest} to send
* @returns The raw savedata as `string`.
* @throws Error if the request fails
*/
public async newclear(params: NewClearSessionSavedataRequest) {
try {
const urlSearchParams = this.toUrlSearchParams(params);
const response = await this.doGet(`/savedata/session/newclear?${urlSearchParams}`);
const json = await response.json();
return Boolean(json);
if (response.ok) {
return Boolean(json);
}
throw new Error("Could not newclear session!");
} catch (err) {
console.warn("Could not newclear session!", err);
return false;
throw new Error("Could not newclear session!");
}
}