This commit is contained in:
kharhamel 2021-07-13 12:00:09 +02:00
parent 50f3af81e4
commit 1ce801cced
10 changed files with 49 additions and 49 deletions

View file

@ -70,7 +70,7 @@
{#if $menuIconVisible} {#if $menuIconVisible}
<div> <div>
<MenuIcon game ={game}></MenuIcon> <MenuIcon></MenuIcon>
</div> </div>
{/if} {/if}
{#if $menuVisible} {#if $menuVisible}

View file

@ -4,7 +4,6 @@
import {gameManager} from "../../Phaser/Game/GameManager"; import {gameManager} from "../../Phaser/Game/GameManager";
import type {Game} from "../../Phaser/Game/Game"; import type {Game} from "../../Phaser/Game/Game";
export let game: Game;
let inputSendTextActive = true; let inputSendTextActive = true;
let uploadMusicActive = false; let uploadMusicActive = false;
@ -33,10 +32,10 @@
</div> </div>
<div class="main-input"> <div class="main-input">
{#if inputSendTextActive} {#if inputSendTextActive}
<InputTextGlobalMessage game={game} gameManager={gameManager}></InputTextGlobalMessage> <InputTextGlobalMessage gameManager={gameManager}></InputTextGlobalMessage>
{/if} {/if}
{#if uploadMusicActive} {#if uploadMusicActive}
<UploadAudioGlobalMessage game={game} gameManager={gameManager}></UploadAudioGlobalMessage> <UploadAudioGlobalMessage gameManager={gameManager}></UploadAudioGlobalMessage>
{/if} {/if}
</div> </div>
</div> </div>

View file

@ -1,12 +1,10 @@
<script lang="ts"> <script lang="ts">
import {consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; import {consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
import {onMount} from "svelte"; import {onMount} from "svelte";
import type {Game} from "../../Phaser/Game/Game";
import type {GameManager} from "../../Phaser/Game/GameManager"; import type {GameManager} from "../../Phaser/Game/GameManager";
import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels"; import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels";
import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService"; import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService";
import type {Quill} from "quill"; import type {Quill} from "quill";
import {LoginSceneName} from "../../Phaser/Login/LoginScene";
//toolbar //toolbar
export const toolbarOptions = [ export const toolbarOptions = [
@ -32,10 +30,9 @@
// remove formatting button // remove formatting button
]; ];
export let game: Game;
export let gameManager: GameManager; export let gameManager: GameManager;
let gameScene = gameManager.getCurrentGameScene(game.scene.getScene(LoginSceneName)); let gameScene = gameManager.getCurrentGameScene();
let quill: Quill; let quill: Quill;
let INPUT_CONSOLE_MESSAGE: HTMLDivElement; let INPUT_CONSOLE_MESSAGE: HTMLDivElement;

View file

@ -1,21 +1,18 @@
<script lang="ts"> <script lang="ts">
import {HtmlUtils} from "../../WebRtc/HtmlUtils"; import {HtmlUtils} from "../../WebRtc/HtmlUtils";
import type {Game} from "../../Phaser/Game/Game";
import type {GameManager} from "../../Phaser/Game/GameManager"; import type {GameManager} from "../../Phaser/Game/GameManager";
import {consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore} from "../../Stores/ConsoleGlobalMessageManagerStore"; import {consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore} from "../../Stores/ConsoleGlobalMessageManagerStore";
import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService"; import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService";
import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels"; import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels";
import uploadFile from "../images/music-file.svg"; import uploadFile from "../images/music-file.svg";
import {LoginSceneName} from "../../Phaser/Login/LoginScene";
interface EventTargetFiles extends EventTarget { interface EventTargetFiles extends EventTarget {
files: Array<File>; files: Array<File>;
} }
export let game: Game;
export let gameManager: GameManager; export let gameManager: GameManager;
let gameScene = gameManager.getCurrentGameScene(game.scene.getScene(LoginSceneName)); let gameScene = gameManager.getCurrentGameScene();
let fileinput: HTMLInputElement; let fileinput: HTMLInputElement;
let filename: string; let filename: string;
let filesize: string; let filesize: string;

View file

@ -3,7 +3,7 @@
import EditProfileMenu from "./EditProfileMenu.svelte"; import EditProfileMenu from "./EditProfileMenu.svelte";
enum SubMenus { enum SubMenus {
gameQuality = 1, settings = 1,
editProfile, editProfile,
shareUrl, shareUrl,
} }
@ -13,6 +13,13 @@
function switchMenu(menu: SubMenus) { function switchMenu(menu: SubMenus) {
activeSubMenu = menu; activeSubMenu = menu;
} }
function gotToCreateMapPage() {
//const sparkHost = 'https://'+window.location.host.replace('play.', '')+'/choose-map.html';
//TODO fix me: this button can to send us on WorkAdventure BO.
const sparkHost = "https://workadventu.re/getting-started";
window.open(sparkHost, "_blank");
}
</script> </script>
@ -20,17 +27,17 @@
<section class="menuNav"> <section class="menuNav">
<nav> <nav>
<ul> <ul>
<li class:active={activeSubMenu === SubMenus.gameQuality } on:click={switchMenu(SubMenus.gameQuality)}>GameQuality</li> <li class:active={activeSubMenu === SubMenus.settings } on:click={() => switchMenu(SubMenus.settings)}>Settings</li>
<li class:active={activeSubMenu === SubMenus.editProfile } on:click={switchMenu(SubMenus.editProfile)}>Edit Profile</li> <li class:active={activeSubMenu === SubMenus.shareUrl } on:click={() => switchMenu(SubMenus.shareUrl)}>Share Url</li>
<li class:active={activeSubMenu === 3 } on:click={switchMenu(3)}>Share Url </li> <li class:active={activeSubMenu === SubMenus.editProfile } on:click={() => switchMenu(SubMenus.editProfile)}>Edit Profile</li>
<li class:active={activeSubMenu === 3 } on:click={switchMenu(3)}>Create Map</li> <li on:click={() => gotToCreateMapPage()}>Create Map</li>
<li class:active={activeSubMenu === 3 } on:click={switchMenu(3)}>Go to Menu</li> <li>Go to Menu</li>
</ul> </ul>
</nav> </nav>
</section> </section>
<section class="subMenuContainer"> <section class="subMenuContainer">
{#if activeSubMenu === SubMenus.gameQuality} {#if activeSubMenu === SubMenus.settings}
<GameQualityMenu></GameQualityMenu> <GameQualityMenu></GameQualityMenu>
{:else if activeSubMenu === SubMenus.editProfile} {:else if activeSubMenu === SubMenus.editProfile}
<EditProfileMenu></EditProfileMenu> <EditProfileMenu></EditProfileMenu>

View file

@ -1,8 +1,6 @@
<script lang="typescript"> <script lang="typescript">
import { Game } from "../../Phaser/Game/Game";
import {menuVisible} from "../../Stores/MenuStore"; import {menuVisible} from "../../Stores/MenuStore";
export let game: Game;
let isOpen : Boolean = false; let isOpen : Boolean = false;
function openMenu(){ function openMenu(){
@ -15,7 +13,7 @@
<main class="menuIcon"> <main class="menuIcon">
<section> <section>
<button on:click|preventDefault={openMenu}> <button on:click|preventDefault={openMenu}>
<img src="/static/images/logo-WA-min.png"> <img src="/static/images/logo-WA-min.png" alt="open menu">
</button> </button>
</section> </section>
</main> </main>

View file

@ -20,6 +20,8 @@ export class GameManager {
private companion: string | null; private companion: string | null;
private startRoom!: Room; private startRoom!: Room;
currentGameSceneName: string | null = null; currentGameSceneName: string | null = null;
// Note: this scenePlugin is the scenePlugin of the EntryScene. We should always provide a key in methods called on this scenePlugin.
private scenePlugin!: Phaser.Scenes.ScenePlugin;
constructor() { constructor() {
this.playerName = localUserStore.getName(); this.playerName = localUserStore.getName();
@ -28,8 +30,9 @@ export class GameManager {
} }
public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise<string> { public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise<string> {
this.scenePlugin = scenePlugin;
this.startRoom = await connectionManager.initGameConnexion(); this.startRoom = await connectionManager.initGameConnexion();
await this.loadMap(this.startRoom, scenePlugin); await this.loadMap(this.startRoom);
if (!this.playerName) { if (!this.playerName) {
return LoginSceneName; return LoginSceneName;
@ -69,21 +72,20 @@ export class GameManager {
return this.companion; return this.companion;
} }
public async loadMap(room: Room, scenePlugin: Phaser.Scenes.ScenePlugin): Promise<void> { public async loadMap(room: Room): Promise<void> {
const roomID = room.id; const roomID = room.id;
const mapDetail = await room.getMapDetail(); const mapDetail = await room.getMapDetail();
const gameIndex = scenePlugin.getIndex(roomID); const gameIndex = this.scenePlugin.getIndex(roomID);
if (gameIndex === -1) { if (gameIndex === -1) {
const game: Phaser.Scene = new GameScene(room, mapDetail.mapUrl); const game: Phaser.Scene = new GameScene(room, mapDetail.mapUrl);
scenePlugin.add(roomID, game, false); this.scenePlugin.add(roomID, game, false);
} }
} }
public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void { public goToStartingMap(): void {
console.log("starting " + (this.currentGameSceneName || this.startRoom.id)); this.scenePlugin.start(this.currentGameSceneName || this.startRoom.id);
scenePlugin.start(this.currentGameSceneName || this.startRoom.id); this.scenePlugin.launch(MenuSceneName);
scenePlugin.launch(MenuSceneName);
if ( if (
!localUserStore.getHelpCameraSettingsShown() && !localUserStore.getHelpCameraSettingsShown() &&
@ -105,33 +107,33 @@ export class GameManager {
* Temporary leave a gameScene to go back to the loginScene for example. * Temporary leave a gameScene to go back to the loginScene for example.
* This will close the socket connections and stop the gameScene, but won't remove it. * This will close the socket connections and stop the gameScene, but won't remove it.
*/ */
leaveGame(scene: Phaser.Scene, targetSceneName: string, sceneClass: Phaser.Scene): void { leaveGame(targetSceneName: string, sceneClass: Phaser.Scene): void {
if (this.currentGameSceneName === null) throw "No current scene id set!"; if (this.currentGameSceneName === null) throw "No current scene id set!";
const gameScene: GameScene = scene.scene.get(this.currentGameSceneName) as GameScene; const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene;
gameScene.cleanupClosingScene(); gameScene.cleanupClosingScene();
scene.scene.stop(this.currentGameSceneName); this.scenePlugin.stop(this.currentGameSceneName);
scene.scene.sleep(MenuSceneName); this.scenePlugin.sleep(MenuSceneName);
if (!scene.scene.get(targetSceneName)) { if (!this.scenePlugin.get(targetSceneName)) {
scene.scene.add(targetSceneName, sceneClass, false); this.scenePlugin.add(targetSceneName, sceneClass, false);
} }
scene.scene.run(targetSceneName); this.scenePlugin.run(targetSceneName);
} }
/** /**
* follow up to leaveGame() * follow up to leaveGame()
*/ */
tryResumingGame(scene: Phaser.Scene, fallbackSceneName: string) { tryResumingGame(fallbackSceneName: string) {
if (this.currentGameSceneName) { if (this.currentGameSceneName) {
scene.scene.start(this.currentGameSceneName); this.scenePlugin.start(this.currentGameSceneName);
scene.scene.wake(MenuSceneName); this.scenePlugin.wake(MenuSceneName);
} else { } else {
scene.scene.run(fallbackSceneName); this.scenePlugin.run(fallbackSceneName);
} }
} }
public getCurrentGameScene(scene: Phaser.Scene): GameScene { public getCurrentGameScene(): GameScene {
if (this.currentGameSceneName === null) throw "No current scene id set!"; if (this.currentGameSceneName === null) throw "No current scene id set!";
return scene.scene.get(this.currentGameSceneName) as GameScene; return this.scenePlugin.get(this.currentGameSceneName) as GameScene;
} }
} }

View file

@ -1248,7 +1248,7 @@ ${escapedMessage}
private loadNextGame(exitSceneIdentifier: string): Promise<void> { private loadNextGame(exitSceneIdentifier: string): Promise<void> {
const { roomId, hash } = Room.getIdFromIdentifier(exitSceneIdentifier, this.MapUrlFile, this.instance); const { roomId, hash } = Room.getIdFromIdentifier(exitSceneIdentifier, this.MapUrlFile, this.instance);
const room = new Room(roomId); const room = new Room(roomId);
return gameManager.loadMap(room, this.scene).catch(() => {}); return gameManager.loadMap(room).catch(() => {});
} }
//todo: in a dedicated class/function? //todo: in a dedicated class/function?
@ -1306,7 +1306,7 @@ ${escapedMessage}
}); });
} catch (err) { } catch (err) {
if (err instanceof TextureError) { if (err instanceof TextureError) {
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene());
} }
throw err; throw err;
} }

View file

@ -38,6 +38,6 @@ export class EnableCameraScene extends ResizableScene {
enableCameraSceneVisibilityStore.hideEnableCameraScene(); enableCameraSceneVisibilityStore.hideEnableCameraScene();
this.scene.sleep(EnableCameraSceneName); this.scene.sleep(EnableCameraSceneName);
gameManager.goToStartingMap(this.scene); gameManager.goToStartingMap();
} }
} }

View file

@ -330,18 +330,18 @@ export class MenuScene extends Phaser.Scene {
switch ((event?.target as HTMLInputElement).id) { switch ((event?.target as HTMLInputElement).id) {
case "changeNameButton": case "changeNameButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, LoginSceneName, new LoginScene()); gameManager.leaveGame(LoginSceneName, new LoginScene());
break; break;
case "sparkButton": case "sparkButton":
this.gotToCreateMapPage(); this.gotToCreateMapPage();
break; break;
case "changeSkinButton": case "changeSkinButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene());
break; break;
case "changeCompanionButton": case "changeCompanionButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, SelectCompanionSceneName, new SelectCompanionScene()); gameManager.leaveGame(SelectCompanionSceneName, new SelectCompanionScene());
break; break;
case "closeButton": case "closeButton":
this.closeSideMenu(); this.closeSideMenu();