Update name map

- Change name in game scene and login scene
This commit is contained in:
gparant 2020-05-09 16:47:55 +02:00
parent b983fff076
commit 4157a12f5d
2 changed files with 30 additions and 13 deletions

View File

@ -11,17 +11,23 @@ import Graphics = Phaser.GameObjects.Graphics;
import Texture = Phaser.Textures.Texture; import Texture = Phaser.Textures.Texture;
import Sprite = Phaser.GameObjects.Sprite; import Sprite = Phaser.GameObjects.Sprite;
import CanvasTexture = Phaser.Textures.CanvasTexture; import CanvasTexture = Phaser.Textures.CanvasTexture;
import {Floor1Name} from "./GameSceneFloor1";
export const GameSceneName = "GameScene";
export enum Textures { export enum Textures {
Player = 'male1', Player = "male1",
Map = 'map' Map = 'floor0',
MapUrl = 'maps/floor0.json'
} }
export const Floor0Name = "Floor0";
export interface GameSceneInterface extends Phaser.Scene { export interface GameSceneInterface extends Phaser.Scene {
Map: Phaser.Tilemaps.Tilemap; Map: Phaser.Tilemaps.Tilemap;
createCurrentPlayer(UserId : string) : void; createCurrentPlayer(UserId : string) : void;
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void; shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface): void;
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>): void;
deleteGroup(groupId: string): void;
} }
export class GameScene extends Phaser.Scene implements GameSceneInterface{ export class GameScene extends Phaser.Scene implements GameSceneInterface{
GameManager : GameManager; GameManager : GameManager;
@ -39,7 +45,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
constructor() { constructor() {
super({ super({
key: GameSceneName key: Floor0Name
}); });
this.GameManager = gameManager; this.GameManager = gameManager;
this.Terrains = []; this.Terrains = [];
@ -49,7 +55,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
//hook preload scene //hook preload scene
preload(): void { preload(): void {
this.GameManager.setCurrentGameScene(this); this.GameManager.setCurrentGameScene(this);
let mapUrl = 'maps/map.json';
this.load.on('filecomplete-tilemapJSON-'+Textures.Map, (key: string, type: string, data: any) => { this.load.on('filecomplete-tilemapJSON-'+Textures.Map, (key: string, type: string, data: any) => {
// Triggered when the map is loaded // Triggered when the map is loaded
// Load tiles attached to the map recursively // Load tiles attached to the map recursively
@ -59,11 +64,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
console.warn("Don't know how to handle tileset ", tileset) console.warn("Don't know how to handle tileset ", tileset)
return; return;
} }
let path = mapUrl.substr(0, mapUrl.lastIndexOf('/')); let path = Textures.MapUrl.substr(0, Textures.MapUrl.lastIndexOf('/'));
this.load.image(tileset.name, path + '/' + tileset.image); this.load.image(tileset.name, path + '/' + tileset.image);
}) })
}); });
this.load.tilemapTiledJSON(Textures.Map, mapUrl); this.load.tilemapTiledJSON(Textures.Map, Textures.MapUrl);
//add player png //add player png
PLAYER_RESOURCES.forEach((playerResource: any) => { PLAYER_RESOURCES.forEach((playerResource: any) => {
@ -78,13 +83,12 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
} }
//hook initialisation //hook initialisation
init() { init() {}
}
//hook create scene //hook create scene
create(): void { create(): void {
//initalise map //initalise map
this.Map = this.add.tilemap("map"); this.Map = this.add.tilemap(Textures.Map);
this.map.tilesets.forEach((tileset: ITiledTileSet) => { this.map.tilesets.forEach((tileset: ITiledTileSet) => {
this.Terrains.push(this.Map.addTilesetImage(tileset.name, tileset.name)); this.Terrains.push(this.Map.addTilesetImage(tileset.name, tileset.name));
}); });
@ -274,7 +278,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
* Create new player * Create new player
* @param MessageUserPosition * @param MessageUserPosition
*/ */
addPlayer(MessageUserPosition : MessageUserPositionInterface){ addPlayer(MessageUserPosition : MessageUserPositionInterface) : void{
//initialise player //initialise player
let player = new Player( let player = new Player(
MessageUserPosition.userId, MessageUserPosition.userId,

View File

@ -2,13 +2,14 @@ import {gameManager} from "../Game/GameManager";
import {TextField} from "../Components/TextField"; import {TextField} from "../Components/TextField";
import {TextInput} from "../Components/TextInput"; import {TextInput} from "../Components/TextInput";
import {ClickButton} from "../Components/ClickButton"; import {ClickButton} from "../Components/ClickButton";
import {GameSceneInterface, GameSceneName, Textures} from "../Game/GameScene"; import {GameSceneInterface, Floor0Name, Textures} from "../Game/GameScene";
import Image = Phaser.GameObjects.Image; import Image = Phaser.GameObjects.Image;
import {Player} from "../Player/Player"; import {Player} from "../Player/Player";
import {getPlayerAnimations, PlayerAnimationNames} from "../Player/Animation"; import {getPlayerAnimations, PlayerAnimationNames} from "../Player/Animation";
import Rectangle = Phaser.GameObjects.Rectangle; import Rectangle = Phaser.GameObjects.Rectangle;
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter"; import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {cypressAsserter} from "../../Cypress/CypressAsserter";
import {GroupCreatedUpdatedMessageInterface, MessageUserPositionInterface} from "../../Connexion";
//todo: put this constants in a dedicated file //todo: put this constants in a dedicated file
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
@ -94,7 +95,7 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
private async login(name: string) { private async login(name: string) {
gameManager.connect(name, this.selectedPlayer.texture.key).then(() => { gameManager.connect(name, this.selectedPlayer.texture.key).then(() => {
this.scene.start(GameSceneName); this.scene.start(Floor0Name);
}); });
} }
@ -132,4 +133,16 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
shareUserPosition(UsersPosition: import("../../Connexion").MessageUserPositionInterface[]): void { shareUserPosition(UsersPosition: import("../../Connexion").MessageUserPositionInterface[]): void {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
deleteGroup(groupId: string): void {
throw new Error("Method not implemented.");
}
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface): void {
throw new Error("Method not implemented.");
}
updateOrCreateMapPlayer(UsersPosition: Array<MessageUserPositionInterface>): void {
throw new Error("Method not implemented.");
}
} }