mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-21 20:45:52 +02:00
* Replace various `scene` pass-arounds with global scene variable * Modify tests * Add scene back to `fade[in|out]()` calls Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Fix Bug Superfan ME test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Re-enable fixed test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Rename `gScene` to `globalScene` * Move `globalScene` to its own file to fix import/async issues * Fix `SelectModifierPhase` tests * Fix ME tests by removing `scene` from `expect()`s * Resolve merge issues * Remove tsdocs referencing `scene` params Remove missed instances of `.scene` * Remove unnecessary `globalScene` usage in `loading-scene.ts` * Fix merge conflicts * Attempt to fix circular import issue * Found the source of the import issue * Fix merge issues --------- Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import type { ModalConfig } from "./modal-ui-handler";
|
|
import { ModalUiHandler } from "./modal-ui-handler";
|
|
import { addTextObject, TextStyle } from "./text";
|
|
import type { Mode } from "./ui";
|
|
import { updateUserInfo } from "#app/account";
|
|
import * as Utils from "#app/utils";
|
|
import i18next from "i18next";
|
|
import { globalScene } from "#app/global-scene";
|
|
|
|
export default class UnavailableModalUiHandler extends ModalUiHandler {
|
|
private reconnectTimer: NodeJS.Timeout | null;
|
|
private reconnectDuration: number;
|
|
private reconnectCallback: () => void;
|
|
|
|
private readonly minTime = 1000 * 5;
|
|
private readonly maxTime = 1000 * 60 * 5;
|
|
|
|
private readonly randVarianceTime = 1000 * 10;
|
|
|
|
constructor(mode: Mode | null = null) {
|
|
super(mode);
|
|
this.reconnectDuration = this.minTime;
|
|
}
|
|
|
|
getModalTitle(): string {
|
|
return "";
|
|
}
|
|
|
|
getWidth(): number {
|
|
return 160;
|
|
}
|
|
|
|
getHeight(): number {
|
|
return 64;
|
|
}
|
|
|
|
getMargin(): [number, number, number, number] {
|
|
return [ 0, 0, 48, 0 ];
|
|
}
|
|
|
|
getButtonLabels(): string[] {
|
|
return [ ];
|
|
}
|
|
|
|
setup(): void {
|
|
super.setup();
|
|
|
|
const label = addTextObject(this.getWidth() / 2, this.getHeight() / 2, i18next.t("menu:errorServerDown"), TextStyle.WINDOW, { fontSize: "48px", align: "center" });
|
|
label.setOrigin(0.5, 0.5);
|
|
|
|
this.modalContainer.add(label);
|
|
}
|
|
|
|
tryReconnect(): void {
|
|
updateUserInfo().then(response => {
|
|
if (response[0] || [ 200, 400 ].includes(response[1])) {
|
|
this.reconnectTimer = null;
|
|
this.reconnectDuration = this.minTime;
|
|
globalScene.playSound("se/pb_bounce_1");
|
|
this.reconnectCallback();
|
|
} else if (response[1] === 401) {
|
|
Utils.removeCookie(Utils.sessionIdKey);
|
|
globalScene.reset(true, true);
|
|
} else {
|
|
this.reconnectDuration = Math.min(this.reconnectDuration * 2, this.maxTime); // Set a max delay so it isn't infinite
|
|
this.reconnectTimer =
|
|
setTimeout(
|
|
() => this.tryReconnect(),
|
|
// Adds a random factor to avoid pendulum effect during long total breakdown
|
|
this.reconnectDuration + (Math.random() * this.randVarianceTime));
|
|
}
|
|
});
|
|
}
|
|
|
|
show(args: any[]): boolean {
|
|
if (args.length >= 1 && args[0] instanceof Function) {
|
|
const config: ModalConfig = {
|
|
buttonActions: []
|
|
};
|
|
|
|
this.reconnectCallback = args[0];
|
|
this.reconnectDuration = this.minTime;
|
|
this.reconnectTimer = setTimeout(() => this.tryReconnect(), this.reconnectDuration);
|
|
|
|
return super.show([ config ]);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|