From fa3ffe4d7a0834b3f14bebdeecc746dd87a82638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Tue, 4 May 2021 14:28:30 +0200 Subject: [PATCH] Fix loader logo WA (#991) --- front/src/Phaser/Components/Loader.ts | 43 ++++++++++++------- front/src/Phaser/Game/GameScene.ts | 4 +- front/src/Phaser/Login/CustomizeScene.ts | 4 +- .../Login/SelectCharacterMobileScene.ts | 1 - .../src/Phaser/Login/SelectCharacterScene.ts | 4 +- .../src/Phaser/Login/SelectCompanionScene.ts | 6 +-- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/front/src/Phaser/Components/Loader.ts b/front/src/Phaser/Components/Loader.ts index 1ee18b32..1757883b 100644 --- a/front/src/Phaser/Components/Loader.ts +++ b/front/src/Phaser/Components/Loader.ts @@ -5,17 +5,18 @@ const TextName: string = 'Loading...'; const LogoResource: string = 'resources/logos/logo.png'; const LogoFrame: ImageFrameConfig = {frameWidth: 307, frameHeight: 59}; +let promiseLoadLogoTexture: Promise|null = null; +let loadingText: Phaser.GameObjects.Text|null = null; +let progressContainer: Phaser.GameObjects.Graphics|null = null; +let progress: Phaser.GameObjects.Graphics|null = null; + export const addLoader = (scene: Phaser.Scene): void => { - // If there is nothing to load, do not display the loader. - if (scene.load.list.entries.length === 0) { - return; - } - let loadingText: Phaser.GameObjects.Text|null = null; + const loadingBarWidth: number = Math.floor(scene.game.renderer.width / 3); const loadingBarHeight: number = 16; const padding: number = 5; - const promiseLoadLogoTexture = new Promise((res) => { + promiseLoadLogoTexture = new Promise((res) => { if(scene.load.textureManager.exists(LogoNameIndex)){ return res(scene.add.image(scene.game.renderer.width / 2, scene.game.renderer.height / 2 - 150, LogoNameIndex)); }else{ @@ -31,24 +32,36 @@ export const addLoader = (scene: Phaser.Scene): void => { }); }); - const progressContainer = scene.add.graphics(); - const progress = scene.add.graphics(); + progressContainer = scene.add.graphics(); + progress = scene.add.graphics(); progressContainer.fillStyle(0x444444, 0.8); progressContainer.fillRect((scene.game.renderer.width - loadingBarWidth) / 2 - padding, scene.game.renderer.height / 2 + 50 - padding, loadingBarWidth + padding * 2, loadingBarHeight + padding * 2); scene.load.on('progress', (value: number) => { - progress.clear(); - progress.fillStyle(0xBBBBBB, 1); - progress.fillRect((scene.game.renderer.width - loadingBarWidth) / 2, scene.game.renderer.height / 2 + 50, loadingBarWidth * value, loadingBarHeight); + if(progress){ + progress.clear(); + progress.fillStyle(0xBBBBBB, 1); + progress.fillRect((scene.game.renderer.width - loadingBarWidth) / 2, scene.game.renderer.height / 2 + 50, loadingBarWidth * value, loadingBarHeight); + } }); scene.load.on('complete', () => { - if(loadingText){ - loadingText.destroy(); - } + endLoader(scene); + }); +} + +export const endLoader = (scene: Phaser.Scene): void => { + if(loadingText){ + loadingText.destroy(); + } + if(promiseLoadLogoTexture){ promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => { resLoadingImage.destroy(); }); + } + if(progress){ progress.destroy(); + } + if(progressContainer){ progressContainer.destroy(); - }); + } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 149d7317..1f8f949d 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -71,7 +71,7 @@ import {ChatModeIcon} from "../Components/ChatModeIcon"; import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon"; import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene"; import {TextureError} from "../../Exception/TextureError"; -import {addLoader} from "../Components/Loader"; +import {addLoader, endLoader} from "../Components/Loader"; import {ErrorSceneName} from "../Reconnecting/ErrorScene"; import {localUserStore} from "../../Connexion/LocalUserStore"; import {iframeListener} from "../../Api/IframeListener"; @@ -497,6 +497,8 @@ export class GameScene extends ResizableScene implements CenterListener { if (!this.room.isDisconnected()) { this.connect(); } + + endLoader(this); } /** diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index 795ee475..20d20716 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -5,7 +5,7 @@ import Sprite = Phaser.GameObjects.Sprite; import Container = Phaser.GameObjects.Container; import {gameManager} from "../Game/GameManager"; import {localUserStore} from "../../Connexion/LocalUserStore"; -import {addLoader} from "../Components/Loader"; +import {addLoader, endLoader} from "../Components/Loader"; import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures"; import {AbstractCharacterScene} from "./AbstractCharacterScene"; import {areCharacterLayersValid} from "../../Connexion/LocalUser"; @@ -112,6 +112,8 @@ export class CustomizeScene extends AbstractCharacterScene { this.moveLayers(); this.updateSelectedLayer(); } + + endLoader(this); } private moveCursorHorizontally(index: number): void { diff --git a/front/src/Phaser/Login/SelectCharacterMobileScene.ts b/front/src/Phaser/Login/SelectCharacterMobileScene.ts index 5d874f46..e29ab798 100644 --- a/front/src/Phaser/Login/SelectCharacterMobileScene.ts +++ b/front/src/Phaser/Login/SelectCharacterMobileScene.ts @@ -6,7 +6,6 @@ import {EnableCameraSceneName} from "./EnableCameraScene"; import {CustomizeSceneName} from "./CustomizeScene"; import {localUserStore} from "../../Connexion/LocalUserStore"; import {loadAllDefaultModels} from "../Entity/PlayerTexturesLoadingManager"; -import {addLoader} from "../Components/Loader"; import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures"; import {AbstractCharacterScene} from "./AbstractCharacterScene"; import {areCharacterLayersValid} from "../../Connexion/LocalUser"; diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index c9f41e69..b8e339be 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -5,7 +5,7 @@ import {EnableCameraSceneName} from "./EnableCameraScene"; import {CustomizeSceneName} from "./CustomizeScene"; import {localUserStore} from "../../Connexion/LocalUserStore"; import {loadAllDefaultModels} from "../Entity/PlayerTexturesLoadingManager"; -import {addLoader} from "../Components/Loader"; +import {addLoader, endLoader} from "../Components/Loader"; import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures"; import {AbstractCharacterScene} from "./AbstractCharacterScene"; import {areCharacterLayersValid} from "../../Connexion/LocalUser"; @@ -47,7 +47,6 @@ export class SelectCharacterScene extends AbstractCharacterScene { }); }) this.playerModels = loadAllDefaultModels(this.load); - addLoader(this); } create() { @@ -98,6 +97,7 @@ export class SelectCharacterScene extends AbstractCharacterScene { this.input.keyboard.on('keydown-DOWN', () => { this.moveToDown(); }); + endLoader(this); } protected nextSceneToCameraScene(): void { diff --git a/front/src/Phaser/Login/SelectCompanionScene.ts b/front/src/Phaser/Login/SelectCompanionScene.ts index fe94cd90..1a739409 100644 --- a/front/src/Phaser/Login/SelectCompanionScene.ts +++ b/front/src/Phaser/Login/SelectCompanionScene.ts @@ -1,6 +1,6 @@ import Image = Phaser.GameObjects.Image; import Rectangle = Phaser.GameObjects.Rectangle; -import { addLoader } from "../Components/Loader"; +import { addLoader, endLoader } from "../Components/Loader"; import { gameManager} from "../Game/GameManager"; import { ResizableScene } from "./ResizableScene"; import { EnableCameraSceneName } from "./EnableCameraScene"; @@ -38,8 +38,6 @@ export class SelectCompanionScene extends ResizableScene { getAllCompanionResources(this.load).forEach(model => { this.companionModels.push(model); }); - - addLoader(this); } create() { @@ -85,6 +83,8 @@ export class SelectCompanionScene extends ResizableScene { this.createCurrentCompanion(); this.updateSelectedCompanion(); + + endLoader(this); } update(time: number, delta: number): void {