Skip to content

Commit

Permalink
start migrating Utils.apiFetch to api class
Browse files Browse the repository at this point in the history
  • Loading branch information
flx-sta committed Oct 3, 2024
1 parent c58b5e9 commit c879a73
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_BYPASS_LOGIN=1
VITE_BYPASS_LOGIN=0
VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://localhost:8001
VITE_DISCORD_CLIENT_ID=1234567890
Expand Down
16 changes: 8 additions & 8 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { bypassLogin } from "./battle-scene";
import { api } from "./plugins/api/api";
import * as Utils from "./utils";

export interface UserInfo {
username: string;
lastSessionSlot: integer;
lastSessionSlot: number;
discordId: string;
googleId: string;
hasAdminRole: boolean;
Expand Down Expand Up @@ -43,15 +44,14 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
});
return resolve([ true, 200 ]);
}
Utils.apiFetch("account/info", true).then(response => {
if (!response.ok) {
resolve([ false, response.status ]);
api.getAccountInfo().then((accountInfoOrStatus) => {
if (typeof accountInfoOrStatus === "number") {
resolve([ false, accountInfoOrStatus ]);
return;
} else {
loggedInUser = accountInfoOrStatus;
resolve([ true, 200 ]);
}
return response.json();
}).then(jsonResponse => {
loggedInUser = jsonResponse;
resolve([ true, 200 ]);
}).catch(err => {
console.error(err);
resolve([ false, 500 ]);
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export const PLAYER_PARTY_MAX_SIZE: number = 6;

/** Whether to use seasonal splash messages in general */
export const USE_SEASONAL_SPLASH_MESSAGES: boolean = false;

/** Name of the session ID cookie */
export const SESSION_ID_COOKIE_NAME: string = "pokerogue_sessionId";
12 changes: 4 additions & 8 deletions src/data/daily-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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";

export interface DailyRunConfig {
seed: integer;
Expand All @@ -14,14 +15,9 @@ export interface DailyRunConfig {

export function fetchDailyRunSeed(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => {
Utils.apiFetch("daily/seed").then(response => {
if (!response.ok) {
resolve(null);
return;
}
return response.text();
}).then(seed => resolve(seed ?? null))
.catch(err => reject(err));
api.getDailySeed().then(dailySeed => {
resolve(dailySeed);
}).catch(err => reject(err)); // TODO: does this ever reject with the api class?
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
* }
* ```
*/
const overrides = {} satisfies Partial<InstanceType<typeof DefaultOverrides>>;
const overrides = {
STARTING_WAVE_OVERRIDE: 199,
STARTING_BIOME_OVERRIDE: Biome.END,
OPP_LEVEL_OVERRIDE: 1,
STARTING_LEVEL_OVERRIDE: 999,
} satisfies Partial<InstanceType<typeof DefaultOverrides>>;

/**
* If you need to add Overrides values for local testing do that inside {@linkcode overrides}
Expand Down
8 changes: 4 additions & 4 deletions src/phases/game-over-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +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";

export class GameOverPhase extends BattlePhase {
private victory: boolean;
Expand Down Expand Up @@ -176,10 +177,9 @@ export class GameOverPhase extends BattlePhase {
If Online, execute apiFetch as intended
If Offline, execute offlineNewClear(), a localStorage implementation of newClear daily run checks */
if (this.victory) {
if (!Utils.isLocal) {
Utils.apiFetch(`savedata/session/newclear?slot=${this.scene.sessionSlotId}&clientSessionId=${clientSessionId}`, true)
.then(response => response.json())
.then(newClear => doGameOver(newClear));
if (!Utils.isLocal || Utils.isLocalServerConnected) {
api.newclearSession(this.scene.sessionSlotId, clientSessionId)
.then((isNewClear) => doGameOver(!!isNewClear));
} else {
this.scene.gameData.offlineNewClear(this.scene).then(result => {
doGameOver(result);
Expand Down
2 changes: 1 addition & 1 deletion src/phases/title-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class TitlePhase extends Phase {
};

// If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date.
if (!Utils.isLocal) {
if (!Utils.isLocal || Utils.isLocalServerConnected) {
fetchDailyRunSeed().then(seed => {
if (seed) {
generateDaily(seed);
Expand Down
Loading

0 comments on commit c879a73

Please sign in to comment.