2021-07-19 17:05:23 +02:00
|
|
|
import { gameManager } from "../Game/GameManager";
|
|
|
|
import { Scene } from "phaser";
|
2021-08-15 08:51:35 +02:00
|
|
|
import { ErrorScene, ErrorSceneName } from "../Reconnecting/ErrorScene";
|
2021-07-19 17:05:23 +02:00
|
|
|
import { WAError } from "../Reconnecting/WAError";
|
|
|
|
import { waScaleManager } from "../Services/WaScaleManager";
|
2021-12-03 09:28:30 +01:00
|
|
|
import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene";
|
2022-01-21 17:06:03 +01:00
|
|
|
import LL from "../../i18n/i18n-svelte";
|
|
|
|
import { get } from "svelte/store";
|
|
|
|
import { localeDetector } from "../../i18n/locales";
|
|
|
|
|
|
|
|
const $LL = get(LL);
|
2020-10-12 18:59:49 +02:00
|
|
|
|
|
|
|
export const EntrySceneName = "EntryScene";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The EntryScene is not a real scene. It is the first scene loaded and is only used to initialize the gameManager
|
|
|
|
* and to route to the next correct scene.
|
|
|
|
*/
|
|
|
|
export class EntryScene extends Scene {
|
|
|
|
constructor() {
|
|
|
|
super({
|
2021-07-19 17:05:23 +02:00
|
|
|
key: EntrySceneName,
|
2020-10-12 18:59:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-03 09:28:30 +01:00
|
|
|
// From the very start, let's preload images used in the ReconnectingScene.
|
|
|
|
preload() {
|
|
|
|
this.load.image(ReconnectingTextures.icon, "static/images/favicons/favicon-32x32.png");
|
|
|
|
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
|
|
|
this.load.bitmapFont(ReconnectingTextures.mainFont, "resources/fonts/arcade.png", "resources/fonts/arcade.xml");
|
|
|
|
this.load.spritesheet("cat", "resources/characters/pipoya/Cat 01-1.png", { frameWidth: 32, frameHeight: 32 });
|
|
|
|
}
|
|
|
|
|
2020-10-12 18:59:49 +02:00
|
|
|
create() {
|
2022-01-21 17:06:03 +01:00
|
|
|
localeDetector()
|
|
|
|
.then(() => {
|
2021-12-08 01:34:50 +01:00
|
|
|
gameManager
|
|
|
|
.init(this.scene)
|
|
|
|
.then((nextSceneName) => {
|
|
|
|
// Let's rescale before starting the game
|
|
|
|
// We can do it at this stage.
|
|
|
|
waScaleManager.applyNewSize();
|
|
|
|
this.scene.start(nextSceneName);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.response && err.response.status == 404) {
|
|
|
|
ErrorScene.showError(
|
|
|
|
new WAError(
|
2022-01-21 17:06:03 +01:00
|
|
|
$LL.error.accessLink.title(),
|
|
|
|
$LL.error.accessLink.subTitle(),
|
|
|
|
$LL.error.accessLink.details()
|
2021-12-08 01:34:50 +01:00
|
|
|
),
|
|
|
|
this.scene
|
|
|
|
);
|
|
|
|
} else if (err.response && err.response.status == 403) {
|
|
|
|
ErrorScene.showError(
|
|
|
|
new WAError(
|
2022-01-21 17:06:03 +01:00
|
|
|
$LL.error.connectionRejected.title(),
|
|
|
|
$LL.error.connectionRejected.subTitle({
|
2021-12-19 16:01:51 +01:00
|
|
|
error: err.response.data ? ". \n\r \n\r" + `${err.response.data}` : "",
|
|
|
|
}),
|
2022-01-21 17:06:03 +01:00
|
|
|
$LL.error.connectionRejected.details()
|
2021-12-08 01:34:50 +01:00
|
|
|
),
|
|
|
|
this.scene
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ErrorScene.showError(err, this.scene);
|
|
|
|
}
|
|
|
|
});
|
2022-01-21 17:06:03 +01:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
throw new Error("Cannot load locale!");
|
2021-07-19 17:05:23 +02:00
|
|
|
});
|
2020-10-12 18:59:49 +02:00
|
|
|
}
|
|
|
|
}
|