Player return a the same position when after editing his profile (same as reconnection)
This commit is contained in:
parent
0c796dff90
commit
c2b3d23ec0
2 changed files with 26 additions and 36 deletions
|
@ -17,7 +17,6 @@ export class GameManager {
|
||||||
private playerName: string | null;
|
private playerName: string | null;
|
||||||
private characterLayers: string[] | null;
|
private characterLayers: string[] | null;
|
||||||
private companion: string | null;
|
private companion: string | null;
|
||||||
private positionBeforeSleep: { scene: string; x: number; y: number } | undefined;
|
|
||||||
private startRoom!: Room;
|
private startRoom!: Room;
|
||||||
private scenePlugin!: Phaser.Scenes.ScenePlugin;
|
private scenePlugin!: Phaser.Scenes.ScenePlugin;
|
||||||
currentGameSceneName: string | null = null;
|
currentGameSceneName: string | null = null;
|
||||||
|
@ -71,10 +70,6 @@ export class GameManager {
|
||||||
return this.companion;
|
return this.companion;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPositionBeforeSleep(): { scene: string; x: number; y: number } | undefined {
|
|
||||||
return this.positionBeforeSleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
public loadMap(room: Room) {
|
public loadMap(room: Room) {
|
||||||
const roomID = room.key;
|
const roomID = room.key;
|
||||||
|
|
||||||
|
@ -113,12 +108,7 @@ export class GameManager {
|
||||||
if (this.currentGameSceneName === null) throw "No current scene id set!";
|
if (this.currentGameSceneName === null) throw "No current scene id set!";
|
||||||
const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene;
|
const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene;
|
||||||
gameScene.cleanupClosingScene();
|
gameScene.cleanupClosingScene();
|
||||||
this.positionBeforeSleep = {
|
gameScene.createSuccessorGameScene(false, false);
|
||||||
scene: gameScene.roomUrl,
|
|
||||||
x: gameScene.CurrentPlayer.x,
|
|
||||||
y: gameScene.CurrentPlayer.y,
|
|
||||||
};
|
|
||||||
this.scenePlugin.stop(this.currentGameSceneName);
|
|
||||||
this.scenePlugin.sleep(MenuSceneName);
|
this.scenePlugin.sleep(MenuSceneName);
|
||||||
if (!this.scenePlugin.get(targetSceneName)) {
|
if (!this.scenePlugin.get(targetSceneName)) {
|
||||||
this.scenePlugin.add(targetSceneName, sceneClass, false);
|
this.scenePlugin.add(targetSceneName, sceneClass, false);
|
||||||
|
|
|
@ -538,15 +538,7 @@ export class GameScene extends DirtyScene {
|
||||||
}
|
}
|
||||||
|
|
||||||
//notify game manager can to create currentUser in map
|
//notify game manager can to create currentUser in map
|
||||||
const positionBeforeSleep = gameManager.getPositionBeforeSleep();
|
this.createCurrentPlayer();
|
||||||
if (positionBeforeSleep && positionBeforeSleep.scene === this.room.key) {
|
|
||||||
this.createCurrentPlayer(positionBeforeSleep.x, positionBeforeSleep.y);
|
|
||||||
} else {
|
|
||||||
this.createCurrentPlayer(
|
|
||||||
this.startPositionCalculator.startPosition.x,
|
|
||||||
this.startPositionCalculator.startPosition.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted
|
this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted
|
||||||
|
|
||||||
this.initCamera();
|
this.initCamera();
|
||||||
|
@ -692,19 +684,7 @@ export class GameScene extends DirtyScene {
|
||||||
this.connection.onServerDisconnected(() => {
|
this.connection.onServerDisconnected(() => {
|
||||||
console.log("Player disconnected from server. Reloading scene.");
|
console.log("Player disconnected from server. Reloading scene.");
|
||||||
this.cleanupClosingScene();
|
this.cleanupClosingScene();
|
||||||
|
this.createSuccessorGameScene(true, true);
|
||||||
const gameSceneKey = "somekey" + Math.round(Math.random() * 10000);
|
|
||||||
const game: Phaser.Scene = new GameScene(this.room, this.MapUrlFile, gameSceneKey);
|
|
||||||
this.scene.add(gameSceneKey, game, true, {
|
|
||||||
initPosition: {
|
|
||||||
x: this.CurrentPlayer.x,
|
|
||||||
y: this.CurrentPlayer.y,
|
|
||||||
},
|
|
||||||
reconnecting: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.scene.stop(this.scene.key);
|
|
||||||
this.scene.remove(this.scene.key);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.connection.onActionableEvent((message) => {
|
this.connection.onActionableEvent((message) => {
|
||||||
|
@ -1491,14 +1471,14 @@ ${escapedMessage}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createCurrentPlayer(x: number, y: number) {
|
createCurrentPlayer() {
|
||||||
//TODO create animation moving between exit and start
|
//TODO create animation moving between exit and start
|
||||||
const texturesPromise = lazyLoadPlayerCharacterTextures(this.load, this.characterLayers);
|
const texturesPromise = lazyLoadPlayerCharacterTextures(this.load, this.characterLayers);
|
||||||
try {
|
try {
|
||||||
this.CurrentPlayer = new Player(
|
this.CurrentPlayer = new Player(
|
||||||
this,
|
this,
|
||||||
x,
|
this.startPositionCalculator.startPosition.x,
|
||||||
y,
|
this.startPositionCalculator.startPosition.y,
|
||||||
this.playerName,
|
this.playerName,
|
||||||
texturesPromise,
|
texturesPromise,
|
||||||
PlayerAnimationDirections.Down,
|
PlayerAnimationDirections.Down,
|
||||||
|
@ -1936,4 +1916,24 @@ ${escapedMessage}
|
||||||
waScaleManager.zoomModifier *= zoomFactor;
|
waScaleManager.zoomModifier *= zoomFactor;
|
||||||
biggestAvailableAreaStore.recompute();
|
biggestAvailableAreaStore.recompute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createSuccessorGameScene(autostart: boolean, reconnecting: boolean) {
|
||||||
|
const gameSceneKey = "somekey" + Math.round(Math.random() * 10000);
|
||||||
|
const game = new GameScene(this.room, this.MapUrlFile, gameSceneKey);
|
||||||
|
this.scene.add(gameSceneKey, game, autostart, {
|
||||||
|
initPosition: {
|
||||||
|
x: this.CurrentPlayer.x,
|
||||||
|
y: this.CurrentPlayer.y,
|
||||||
|
},
|
||||||
|
reconnecting: reconnecting,
|
||||||
|
});
|
||||||
|
|
||||||
|
//If new gameScene doesn't start automatically then we change the gameScene in gameManager so that it can start the new gameScene
|
||||||
|
if (!autostart) {
|
||||||
|
gameManager.gameSceneIsCreated(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scene.stop(this.scene.key);
|
||||||
|
this.scene.remove(this.scene.key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue