From 41ac51f2918b743da445a2ba3b89bd8f66e08e06 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Thu, 29 Jul 2021 18:02:36 +0200 Subject: [PATCH 1/2] FEATURE: improved the room capacity warning visuals --- back/src/Services/SocketManager.ts | 2 +- .../dist/resources/html/warningContainer.html | 18 ------------- front/src/Components/App.svelte | 5 ++++ .../WarningContainer/WarningContainer.svelte | 26 ++++++++++++++++++ front/src/Connexion/RoomConnection.ts | 27 ++++++++++++++----- front/src/Connexion/WorldFullWarningStream.ts | 14 ---------- .../src/Phaser/Components/WarningContainer.ts | 14 ---------- front/src/Phaser/Menu/MenuScene.ts | 20 -------------- front/src/Stores/MenuStore.ts | 22 ++++++++++++++- 9 files changed, 74 insertions(+), 74 deletions(-) delete mode 100644 front/dist/resources/html/warningContainer.html create mode 100644 front/src/Components/WarningContainer/WarningContainer.svelte delete mode 100644 front/src/Connexion/WorldFullWarningStream.ts delete mode 100644 front/src/Phaser/Components/WarningContainer.ts diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 178eacc0..9fec90f3 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -790,7 +790,7 @@ export class SocketManager { if (!room) { //todo: this should cause the http call to return a 500 console.error( - "In sendAdminRoomMessage, could not find room with id '" + + "In dispatchWorldFullWarning, could not find room with id '" + roomId + "'. Maybe the room was closed a few milliseconds ago and there was a race condition?" ); diff --git a/front/dist/resources/html/warningContainer.html b/front/dist/resources/html/warningContainer.html deleted file mode 100644 index 832ac4da..00000000 --- a/front/dist/resources/html/warningContainer.html +++ /dev/null @@ -1,18 +0,0 @@ - - -
-

Warning!

-

This world is close to its limit!

-
\ No newline at end of file diff --git a/front/src/Components/App.svelte b/front/src/Components/App.svelte index 0f808074..1e846185 100644 --- a/front/src/Components/App.svelte +++ b/front/src/Components/App.svelte @@ -27,6 +27,8 @@ import {gameOverlayVisibilityStore} from "../Stores/GameOverlayStoreVisibility"; import {consoleGlobalMessageManagerVisibleStore} from "../Stores/ConsoleGlobalMessageManagerStore"; import ConsoleGlobalMessageManager from "./ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte"; + import {warningContainerStore} from "../Stores/MenuStore"; + import WarningContainer from "./WarningContainer/WarningContainer.svelte"; export let game: Game; @@ -91,4 +93,7 @@ {#if $chatVisibilityStore} {/if} + {#if $warningContainerStore} + + {/if} diff --git a/front/src/Components/WarningContainer/WarningContainer.svelte b/front/src/Components/WarningContainer/WarningContainer.svelte new file mode 100644 index 00000000..26961357 --- /dev/null +++ b/front/src/Components/WarningContainer/WarningContainer.svelte @@ -0,0 +1,26 @@ + + +
+

Warning!

+

This world is close to its limit!

+
+ + \ No newline at end of file diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 521a8473..f37c59d2 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -32,7 +32,8 @@ import { EmotePromptMessage, SendUserMessage, BanUserMessage, - VariableMessage, ErrorMessage, + VariableMessage, + ErrorMessage, } from "../Messages/generated/messages_pb"; import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer"; @@ -54,9 +55,9 @@ import { import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures"; import { adminMessagesService } from "./AdminMessagesService"; import { worldFullMessageStream } from "./WorldFullMessageStream"; -import { worldFullWarningStream } from "./WorldFullWarningStream"; import { connectionManager } from "./ConnectionManager"; import { emoteEventStream } from "./EmoteEventStream"; +import { warningContainerStore } from "../Stores/MenuStore"; const manualPingDelay = 20000; @@ -167,7 +168,7 @@ export class RoomConnection implements RoomConnection { emoteEventStream.fire(emoteMessage.getActoruserid(), emoteMessage.getEmote()); } else if (subMessage.hasErrormessage()) { const errorMessage = subMessage.getErrormessage() as ErrorMessage; - console.error('An error occurred server side: '+errorMessage.getMessage()); + console.error("An error occurred server side: " + errorMessage.getMessage()); } else if (subMessage.hasVariablemessage()) { event = EventMessage.SET_VARIABLE; payload = subMessage.getVariablemessage(); @@ -192,7 +193,14 @@ export class RoomConnection implements RoomConnection { try { variables.set(variable.getName(), JSON.parse(variable.getValue())); } catch (e) { - console.error('Unable to unserialize value received from server for variable "'+variable.getName()+'". Value received: "'+variable.getValue()+'". Error: ', e); + console.error( + 'Unable to unserialize value received from server for variable "' + + variable.getName() + + '". Value received: "' + + variable.getValue() + + '". Error: ', + e + ); } } @@ -236,7 +244,7 @@ export class RoomConnection implements RoomConnection { } else if (message.hasBanusermessage()) { adminMessagesService.onSendusermessage(message.getBanusermessage() as BanUserMessage); } else if (message.hasWorldfullwarningmessage()) { - worldFullWarningStream.onMessage(); + warningContainerStore.activateWarningContainer(); } else if (message.hasRefreshroommessage()) { //todo: implement a way to notify the user the room was refreshed. } else { @@ -659,7 +667,14 @@ export class RoomConnection implements RoomConnection { try { value = JSON.parse(serializedValue); } catch (e) { - console.error('Unable to unserialize value received from server for variable "'+name+'". Value received: "'+serializedValue+'". Error: ', e); + console.error( + 'Unable to unserialize value received from server for variable "' + + name + + '". Value received: "' + + serializedValue + + '". Error: ', + e + ); } } callback(name, value); diff --git a/front/src/Connexion/WorldFullWarningStream.ts b/front/src/Connexion/WorldFullWarningStream.ts deleted file mode 100644 index 5e552830..00000000 --- a/front/src/Connexion/WorldFullWarningStream.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {Subject} from "rxjs"; - -class WorldFullWarningStream { - - private _stream:Subject = new Subject(); - public stream = this._stream.asObservable(); - - - onMessage() { - this._stream.next(); - } -} - -export const worldFullWarningStream = new WorldFullWarningStream(); \ No newline at end of file diff --git a/front/src/Phaser/Components/WarningContainer.ts b/front/src/Phaser/Components/WarningContainer.ts deleted file mode 100644 index 97e97660..00000000 --- a/front/src/Phaser/Components/WarningContainer.ts +++ /dev/null @@ -1,14 +0,0 @@ - -export const warningContainerKey = 'warningContainer'; -export const warningContainerHtml = 'resources/html/warningContainer.html'; - -export class WarningContainer extends Phaser.GameObjects.DOMElement { - - constructor(scene: Phaser.Scene) { - super(scene, 100, 0); - this.setOrigin(0, 0); - this.createFromCache(warningContainerKey); - this.scene.add.existing(this); - } - -} \ No newline at end of file diff --git a/front/src/Phaser/Menu/MenuScene.ts b/front/src/Phaser/Menu/MenuScene.ts index 4e9297b6..5c8949a7 100644 --- a/front/src/Phaser/Menu/MenuScene.ts +++ b/front/src/Phaser/Menu/MenuScene.ts @@ -6,8 +6,6 @@ import { localUserStore } from "../../Connexion/LocalUserStore"; import { gameReportKey, gameReportRessource, ReportMenu } from "./ReportMenu"; import { connectionManager } from "../../Connexion/ConnectionManager"; import { GameConnexionTypes } from "../../Url/UrlManager"; -import { WarningContainer, warningContainerHtml, warningContainerKey } from "../Components/WarningContainer"; -import { worldFullWarningStream } from "../../Connexion/WorldFullWarningStream"; import { menuIconVisible } from "../../Stores/MenuStore"; import { videoConstraintStore } from "../../Stores/MediaStore"; import { showReportScreenStore } from "../../Stores/ShowReportScreenStore"; @@ -45,8 +43,6 @@ export class MenuScene extends Phaser.Scene { private gameQualityValue: number; private videoQualityValue: number; private menuButton!: Phaser.GameObjects.DOMElement; - private warningContainer: WarningContainer | null = null; - private warningContainerTimeout: NodeJS.Timeout | null = null; private subscriptions = new Subscription(); constructor() { super({ key: MenuSceneName }); @@ -91,7 +87,6 @@ export class MenuScene extends Phaser.Scene { this.load.html(gameSettingsMenuKey, "resources/html/gameQualityMenu.html"); this.load.html(gameShare, "resources/html/gameShare.html"); this.load.html(gameReportKey, gameReportRessource); - this.load.html(warningContainerKey, warningContainerHtml); } create() { @@ -147,7 +142,6 @@ export class MenuScene extends Phaser.Scene { this.menuElement.addListener("click"); this.menuElement.on("click", this.onMenuClick.bind(this)); - worldFullWarningStream.stream.subscribe(() => this.showWorldCapacityWarning()); chatVisibilityStore.subscribe((v) => { this.menuButton.setVisible(!v); }); @@ -194,20 +188,6 @@ export class MenuScene extends Phaser.Scene { }); } - private showWorldCapacityWarning() { - if (!this.warningContainer) { - this.warningContainer = new WarningContainer(this); - } - if (this.warningContainerTimeout) { - clearTimeout(this.warningContainerTimeout); - } - this.warningContainerTimeout = setTimeout(() => { - this.warningContainer?.destroy(); - this.warningContainer = null; - this.warningContainerTimeout = null; - }, 120000); - } - private closeSideMenu(): void { if (!this.sideMenuOpened) return; this.sideMenuOpened = false; diff --git a/front/src/Stores/MenuStore.ts b/front/src/Stores/MenuStore.ts index c7c02130..084e8ce8 100644 --- a/front/src/Stores/MenuStore.ts +++ b/front/src/Stores/MenuStore.ts @@ -1,3 +1,23 @@ -import { derived, writable, Writable } from "svelte/store"; +import { writable } from "svelte/store"; +import Timeout = NodeJS.Timeout; export const menuIconVisible = writable(false); + +let warningContainerTimeout: Timeout | null = null; +function createWarningContainerStore() { + const { subscribe, set } = writable(false); + + return { + subscribe, + activateWarningContainer() { + set(true); + if (warningContainerTimeout) clearTimeout(warningContainerTimeout); + warningContainerTimeout = setTimeout(() => { + set(false); + warningContainerTimeout = null; + }, 120000); + }, + }; +} + +export const warningContainerStore = createWarningContainerStore(); From ebdcf8804d7ab72a51bac10eeb476467caa16f43 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Fri, 30 Jul 2021 14:08:27 +0200 Subject: [PATCH 2/2] added admin link to the warning container --- .github/workflows/continuous_integration.yml | 1 + .github/workflows/push-to-npm.yml | 1 + .../WarningContainer/WarningContainer.svelte | 13 ++++++++- front/src/Enum/EnvironmentVariable.ts | 28 ++++++++++--------- front/src/Phaser/Game/GameScene.ts | 3 ++ front/src/Phaser/Menu/MenuScene.ts | 3 +- front/src/Stores/GameStore.ts | 4 ++- front/webpack.config.ts | 2 +- 8 files changed, 38 insertions(+), 17 deletions(-) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index faf50c7a..ecd7ffef 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -50,6 +50,7 @@ jobs: run: yarn run build env: PUSHER_URL: "//localhost:8080" + ADMIN_URL: "//localhost:80" working-directory: "front" - name: "Svelte check" diff --git a/.github/workflows/push-to-npm.yml b/.github/workflows/push-to-npm.yml index fd247b11..1208e0c0 100644 --- a/.github/workflows/push-to-npm.yml +++ b/.github/workflows/push-to-npm.yml @@ -47,6 +47,7 @@ jobs: run: yarn run build-typings env: PUSHER_URL: "//localhost:8080" + ADMIN_URL: "//localhost:80" working-directory: "front" # We build the front to generate the typings of iframe_api, then we copy those typings in a separate package. diff --git a/front/src/Components/WarningContainer/WarningContainer.svelte b/front/src/Components/WarningContainer/WarningContainer.svelte index 26961357..57b956e2 100644 --- a/front/src/Components/WarningContainer/WarningContainer.svelte +++ b/front/src/Components/WarningContainer/WarningContainer.svelte @@ -1,14 +1,25 @@

Warning!

-

This world is close to its limit!

+ {#if $userIsAdminStore} +

This world is close to its limit!. You can upgrade its capacity here

+ {:else} +

This world is close to its limit!

+ {/if} +