mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-30 20:57:13 +00:00
dont make api calls when no server is connected in local (#1847)
* dont make api calls in local without a server connected and fix fusionLuck not set by default
This commit is contained in:
parent
6d35399c31
commit
c5689dfc96
@ -211,8 +211,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||
this.generateFusionSpecies();
|
||||
}
|
||||
}
|
||||
|
||||
this.luck = (this.shiny ? this.variant + 1 : 0) + (this.fusionShiny ? this.fusionVariant + 1 : 0);
|
||||
this.fusionLuck = this.luck;
|
||||
}
|
||||
|
||||
this.generateName();
|
||||
|
@ -29,6 +29,7 @@ export class LoadingScene extends SceneBase {
|
||||
}
|
||||
|
||||
preload() {
|
||||
Utils.localPing();
|
||||
this.load["manifest"] = this.game["manifest"];
|
||||
|
||||
if (!isMobile()) {
|
||||
|
24
src/utils.ts
24
src/utils.ts
@ -263,6 +263,8 @@ export const isLocal = (
|
||||
// Set the server URL based on whether it's local or not
|
||||
export const serverUrl = isLocal ? `${window.location.hostname}:${window.location.port}` : "";
|
||||
export const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net";
|
||||
// used to disable api calls when isLocal is true and a server is not found
|
||||
export let isLocalServerConnected = false;
|
||||
|
||||
export function setCookie(cName: string, cValue: string): void {
|
||||
const expiration = new Date();
|
||||
@ -285,8 +287,22 @@ export function getCookie(cName: string): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* When locally running the game, "pings" the local server
|
||||
* with a GET request to verify if a server is running,
|
||||
* sets isLocalServerConnected based on results
|
||||
*/
|
||||
export function localPing() {
|
||||
if (isLocal) {
|
||||
apiFetch("game/titlestats")
|
||||
.then(resolved => isLocalServerConnected = true,
|
||||
rejected => isLocalServerConnected = false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function apiFetch(path: string, authed: boolean = false): Promise<Response> {
|
||||
return new Promise((resolve, reject) => {
|
||||
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||
const request = {};
|
||||
if (authed) {
|
||||
const sId = getCookie(sessionIdKey);
|
||||
@ -297,11 +313,11 @@ export function apiFetch(path: string, authed: boolean = false): Promise<Respons
|
||||
fetch(`${apiUrl}/${path}`, request)
|
||||
.then(response => resolve(response))
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
}) : new Promise(() => {});
|
||||
}
|
||||
|
||||
export function apiPost(path: string, data?: any, contentType: string = "application/json", authed: boolean = false): Promise<Response> {
|
||||
return new Promise((resolve, reject) => {
|
||||
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||
const headers = {
|
||||
"Accept": contentType,
|
||||
"Content-Type": contentType,
|
||||
@ -315,7 +331,7 @@ export function apiPost(path: string, data?: any, contentType: string = "applica
|
||||
fetch(`${apiUrl}/${path}`, { method: "POST", headers: headers, body: data })
|
||||
.then(response => resolve(response))
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
}) : new Promise(() => {});
|
||||
}
|
||||
|
||||
export class BooleanHolder {
|
||||
|
Loading…
x
Reference in New Issue
Block a user