FEAT: prototype game menu using html elements, better icon for text chat
This commit is contained in:
parent
855b55903b
commit
069f2f1cec
23 changed files with 520 additions and 226 deletions
|
@ -1,6 +1,11 @@
|
|||
import {GameScene} from "./GameScene";
|
||||
import {connectionManager} from "../../Connexion/ConnectionManager";
|
||||
import {Room} from "../../Connexion/Room";
|
||||
import {MenuSceneName} from "../Menu/MenuScene";
|
||||
import {LoginSceneName} from "../Login/LoginScene";
|
||||
import {SelectCharacterSceneName} from "../Login/SelectCharacterScene";
|
||||
import {EnableCameraSceneName} from "../Login/EnableCameraScene";
|
||||
import {localUserStore} from "../../Connexion/LocalUserStore";
|
||||
|
||||
export interface HasMovedEvent {
|
||||
direction: string;
|
||||
|
@ -9,29 +14,48 @@ export interface HasMovedEvent {
|
|||
y: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be responsible for any scene starting/stopping
|
||||
*/
|
||||
export class GameManager {
|
||||
private playerName!: string;
|
||||
private characterLayers!: string[];
|
||||
private playerName: string|null;
|
||||
private characterLayers: string[]|null;
|
||||
private startRoom!:Room;
|
||||
currentSceneName: string|null = null;
|
||||
|
||||
constructor() {
|
||||
this.playerName = localUserStore.getName();
|
||||
this.characterLayers = localUserStore.getCharacterLayers();
|
||||
}
|
||||
|
||||
public async init(scenePlugin: Phaser.Scenes.ScenePlugin) {
|
||||
public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise<string> {
|
||||
this.startRoom = await connectionManager.initGameConnexion();
|
||||
await this.loadMap(this.startRoom, scenePlugin);
|
||||
|
||||
if (!this.playerName) {
|
||||
return LoginSceneName;
|
||||
} else if (!this.characterLayers) {
|
||||
return SelectCharacterSceneName;
|
||||
} else {
|
||||
return EnableCameraSceneName;
|
||||
}
|
||||
}
|
||||
|
||||
public setPlayerName(name: string): void {
|
||||
this.playerName = name;
|
||||
localUserStore.setName(name);
|
||||
}
|
||||
|
||||
public setCharacterLayers(layers: string[]): void {
|
||||
this.characterLayers = layers;
|
||||
localUserStore.setCharacterLayers(layers);
|
||||
}
|
||||
|
||||
getPlayerName(): string {
|
||||
getPlayerName(): string|null {
|
||||
return this.playerName;
|
||||
}
|
||||
|
||||
getCharacterSelected(): string[] {
|
||||
getCharacterLayers(): string[]|null {
|
||||
return this.characterLayers;
|
||||
}
|
||||
|
||||
|
@ -48,7 +72,28 @@ export class GameManager {
|
|||
}
|
||||
|
||||
public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void {
|
||||
scenePlugin.start(this.startRoom.id);
|
||||
console.log('starting '+ (this.currentSceneName || this.startRoom.id))
|
||||
scenePlugin.start(this.currentSceneName || this.startRoom.id);
|
||||
//the menu scene launches faster than the gameScene, so we delay it to not have menu buttons on a black screen
|
||||
setTimeout(() => scenePlugin.launch(MenuSceneName), 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
leaveGame(scene: Phaser.Scene, targetSceneName: string): void {
|
||||
if (this.currentSceneName === null) throw 'No current scene id set!';
|
||||
const gameScene: GameScene = scene.scene.get(this.currentSceneName) as GameScene;
|
||||
gameScene.cleanupClosingScene();
|
||||
scene.scene.stop(this.currentSceneName);
|
||||
scene.scene.stop(MenuSceneName);
|
||||
scene.scene.run(targetSceneName);
|
||||
}
|
||||
|
||||
public getCurrentGameScene(scene: Phaser.Scene): GameScene {
|
||||
if (this.currentSceneName === null) throw 'No current scene id set!';
|
||||
return scene.scene.get(this.currentSceneName) as GameScene
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue