2020-05-19 19:11:12 +02:00
|
|
|
import {GameScene} from "./GameScene";
|
2020-05-08 00:35:36 +02:00
|
|
|
import {
|
2020-06-22 11:58:07 +02:00
|
|
|
Connection,
|
2020-05-08 00:35:36 +02:00
|
|
|
GroupCreatedUpdatedMessageInterface,
|
2020-05-23 15:43:26 +02:00
|
|
|
ListMessageUserPositionInterface,
|
|
|
|
MessageUserJoined,
|
|
|
|
MessageUserMovedInterface,
|
|
|
|
MessageUserPositionInterface,
|
|
|
|
Point,
|
2020-06-22 11:58:07 +02:00
|
|
|
PointInterface, StartMapInterface
|
2020-05-24 23:14:12 +02:00
|
|
|
} from "../../Connection";
|
2020-06-03 22:32:43 +02:00
|
|
|
import {SimplePeer} from "../../WebRtc/SimplePeer";
|
2020-05-19 19:11:12 +02:00
|
|
|
import {AddPlayerInterface} from "./AddPlayerInterface";
|
2020-06-10 15:43:22 +02:00
|
|
|
import {ReconnectingScene, ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
|
|
|
|
import ScenePlugin = Phaser.Scenes.ScenePlugin;
|
|
|
|
import {Scene} from "phaser";
|
2020-06-22 11:58:07 +02:00
|
|
|
import Axios from "axios";
|
|
|
|
import {API_URL} from "../../Enum/EnvironmentVariable";
|
2020-04-10 12:54:05 +02:00
|
|
|
|
2020-05-02 16:54:52 +02:00
|
|
|
export interface HasMovedEvent {
|
|
|
|
direction: string;
|
2020-05-22 22:59:43 +02:00
|
|
|
moving: boolean;
|
2020-05-02 16:54:52 +02:00
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}
|
2020-04-07 20:41:35 +02:00
|
|
|
|
2020-05-09 21:28:50 +02:00
|
|
|
export interface MapObject {
|
|
|
|
key: string,
|
|
|
|
url: string
|
|
|
|
}
|
|
|
|
|
2020-04-27 15:03:05 +02:00
|
|
|
export class GameManager {
|
2020-05-03 15:29:40 +02:00
|
|
|
private playerName: string;
|
2020-05-08 15:18:22 +02:00
|
|
|
private characterUserSelected: string;
|
2020-04-07 20:41:35 +02:00
|
|
|
|
2020-06-22 16:10:34 +02:00
|
|
|
public storePlayerDetails(name: string, characterUserSelected : string): void {
|
2020-05-03 15:29:40 +02:00
|
|
|
this.playerName = name;
|
2020-05-08 15:18:22 +02:00
|
|
|
this.characterUserSelected = characterUserSelected;
|
2020-04-10 12:54:05 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 11:58:07 +02:00
|
|
|
loadStartMap() : Promise<StartMapInterface> {
|
|
|
|
return Axios.get(`${API_URL}/start-map`)
|
|
|
|
.then((res) => {
|
|
|
|
return res.data;
|
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
throw err;
|
|
|
|
});
|
2020-05-09 19:41:21 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 15:29:40 +02:00
|
|
|
getPlayerName(): string {
|
|
|
|
return this.playerName;
|
|
|
|
}
|
2020-05-03 15:51:16 +02:00
|
|
|
|
2020-05-08 15:18:22 +02:00
|
|
|
getCharacterSelected(): string {
|
|
|
|
return this.characterUserSelected;
|
2020-05-06 01:50:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 17:27:49 +02:00
|
|
|
loadMap(mapUrl: string, scene: Phaser.Scenes.ScenePlugin, instance: string): string {
|
2020-06-09 23:13:26 +02:00
|
|
|
const sceneKey = GameScene.getMapKeyByUrl(mapUrl);
|
2020-05-11 23:26:40 +02:00
|
|
|
|
2020-06-09 23:13:26 +02:00
|
|
|
const gameIndex = scene.getIndex(sceneKey);
|
2020-05-11 23:26:40 +02:00
|
|
|
if(gameIndex === -1){
|
2020-06-09 23:13:26 +02:00
|
|
|
const game : Phaser.Scene = GameScene.createFromUrl(mapUrl, instance);
|
2020-05-11 23:26:40 +02:00
|
|
|
scene.add(sceneKey, game, false);
|
|
|
|
}
|
|
|
|
return sceneKey;
|
|
|
|
}
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 15:29:40 +02:00
|
|
|
export const gameManager = new GameManager();
|