Merge branch 'develop' of github.com:thecodingmachine/workadventure
This commit is contained in:
@@ -88,6 +88,11 @@ export abstract class Character extends Container {
|
||||
fontSize: "8px",
|
||||
strokeThickness: 2,
|
||||
stroke: "gray",
|
||||
metrics: {
|
||||
ascent: 20,
|
||||
descent: 10,
|
||||
fontSize: 35,
|
||||
},
|
||||
});
|
||||
this.playerName.setOrigin(0.5).setDepth(DEPTH_INGAME_TEXT_INDEX);
|
||||
this.add(this.playerName);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { GameScene } from "./GameScene";
|
||||
import { get } from "svelte/store";
|
||||
import { connectionManager } from "../../Connexion/ConnectionManager";
|
||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||
import type { Room } from "../../Connexion/Room";
|
||||
import { helpCameraSettingsVisibleStore } from "../../Stores/HelpCameraSettingsStore";
|
||||
import { requestedCameraState, requestedMicrophoneState } from "../../Stores/MediaStore";
|
||||
import { menuIconVisiblilityStore } from "../../Stores/MenuStore";
|
||||
import { EnableCameraSceneName } from "../Login/EnableCameraScene";
|
||||
import { LoginSceneName } from "../Login/LoginScene";
|
||||
import { SelectCharacterSceneName } from "../Login/SelectCharacterScene";
|
||||
import { EnableCameraSceneName } from "../Login/EnableCameraScene";
|
||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||
import { get } from "svelte/store";
|
||||
import { requestedCameraState, requestedMicrophoneState } from "../../Stores/MediaStore";
|
||||
import { helpCameraSettingsVisibleStore } from "../../Stores/HelpCameraSettingsStore";
|
||||
import { menuIconVisiblilityStore } from "../../Stores/MenuStore";
|
||||
import { GameScene } from "./GameScene";
|
||||
|
||||
/**
|
||||
* This class should be responsible for any scene starting/stopping
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import type { ITiledMap, ITiledMapLayer, ITiledMapObject, ITiledMapProperty } from "../Map/ITiledMap";
|
||||
import type {
|
||||
ITiledMap,
|
||||
ITiledMapLayer,
|
||||
ITiledMapObject,
|
||||
ITiledMapProperty,
|
||||
ITiledMapTileLayer,
|
||||
} from "../Map/ITiledMap";
|
||||
import { flattenGroupLayersMap } from "../Map/LayersFlattener";
|
||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer;
|
||||
import { DEPTH_OVERLAY_INDEX } from "./DepthIndexes";
|
||||
@@ -307,6 +313,31 @@ export class GameMap {
|
||||
}
|
||||
}
|
||||
|
||||
public getRandomPositionFromLayer(layerName: string): { x: number; y: number } {
|
||||
const layer = this.findLayer(layerName) as ITiledMapTileLayer;
|
||||
if (!layer) {
|
||||
throw new Error(`No layer "${layerName}" was found`);
|
||||
}
|
||||
const tiles = layer.data;
|
||||
if (!tiles) {
|
||||
throw new Error(`No tiles in "${layerName}" were found`);
|
||||
}
|
||||
if (typeof tiles === "string") {
|
||||
throw new Error("The content of a JSON map must be filled as a JSON array, not as a string");
|
||||
}
|
||||
const possiblePositions: { x: number; y: number }[] = [];
|
||||
tiles.forEach((objectKey: number, key: number) => {
|
||||
if (objectKey === 0) {
|
||||
return;
|
||||
}
|
||||
possiblePositions.push({ x: key % layer.width, y: Math.floor(key / layer.width) });
|
||||
});
|
||||
if (possiblePositions.length > 0) {
|
||||
return MathUtils.randomFromArray(possiblePositions);
|
||||
}
|
||||
throw new Error("No possible position found");
|
||||
}
|
||||
|
||||
private getLayersByKey(key: number): Array<ITiledMapLayer> {
|
||||
return this.flatLayers.filter((flatLayer) => flatLayer.type === "tilelayer" && flatLayer.data[key] !== 0);
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ import { MapStore } from "../../Stores/Utils/MapStore";
|
||||
import { followUsersColorStore } from "../../Stores/FollowStore";
|
||||
import Camera = Phaser.Cameras.Scene2D.Camera;
|
||||
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
||||
import { locale } from "../../i18n/i18n-svelte";
|
||||
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null;
|
||||
@@ -576,6 +577,12 @@ export class GameScene extends DirtyScene {
|
||||
.catch((e) => console.error(e));
|
||||
}
|
||||
|
||||
this.pathfindingManager = new PathfindingManager(
|
||||
this,
|
||||
this.gameMap.getCollisionsGrid(),
|
||||
this.gameMap.getTileDimensions()
|
||||
);
|
||||
|
||||
//notify game manager can to create currentUser in map
|
||||
this.createCurrentPlayer();
|
||||
this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted
|
||||
@@ -586,11 +593,6 @@ export class GameScene extends DirtyScene {
|
||||
waScaleManager
|
||||
);
|
||||
|
||||
this.pathfindingManager = new PathfindingManager(
|
||||
this,
|
||||
this.gameMap.getCollisionsGrid(),
|
||||
this.gameMap.getTileDimensions()
|
||||
);
|
||||
biggestAvailableAreaStore.recompute();
|
||||
this.cameraManager.startFollowPlayer(this.CurrentPlayer);
|
||||
|
||||
@@ -1351,6 +1353,7 @@ export class GameScene extends DirtyScene {
|
||||
startLayerName: this.startPositionCalculator.startLayerName,
|
||||
uuid: localUserStore.getLocalUser()?.uuid,
|
||||
nickname: this.playerName,
|
||||
language: get(locale),
|
||||
roomId: this.roomUrl,
|
||||
tags: this.connection ? this.connection.getAllTags() : [],
|
||||
variables: this.sharedVariablesManager.variables,
|
||||
@@ -1757,6 +1760,22 @@ export class GameScene extends DirtyScene {
|
||||
this.connection?.emitEmoteEvent(emoteKey);
|
||||
analyticsClient.launchEmote(emoteKey);
|
||||
});
|
||||
const moveToParam = urlManager.getHashParameter("moveTo");
|
||||
if (moveToParam) {
|
||||
try {
|
||||
const endPos = this.gameMap.getRandomPositionFromLayer(moveToParam);
|
||||
this.pathfindingManager
|
||||
.findPath(this.gameMap.getTileIndexAt(this.CurrentPlayer.x, this.CurrentPlayer.y), endPos)
|
||||
.then((path) => {
|
||||
if (path && path.length > 0) {
|
||||
this.CurrentPlayer.setPathToFollow(path).catch((reason) => console.warn(reason));
|
||||
}
|
||||
})
|
||||
.catch((reason) => console.warn(reason));
|
||||
} catch (err) {
|
||||
console.warn(`Cannot proceed with moveTo command:\n\t-> ${err}`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof TextureError) {
|
||||
gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene());
|
||||
|
||||
@@ -4,6 +4,11 @@ import { ErrorScene, ErrorSceneName } from "../Reconnecting/ErrorScene";
|
||||
import { WAError } from "../Reconnecting/WAError";
|
||||
import { waScaleManager } from "../Services/WaScaleManager";
|
||||
import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene";
|
||||
import LL from "../../i18n/i18n-svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { localeDetector } from "../../i18n/locales";
|
||||
|
||||
const $LL = get(LL);
|
||||
|
||||
export const EntrySceneName = "EntryScene";
|
||||
|
||||
@@ -27,37 +32,44 @@ export class EntryScene extends Scene {
|
||||
}
|
||||
|
||||
create() {
|
||||
gameManager
|
||||
.init(this.scene)
|
||||
.then((nextSceneName) => {
|
||||
// Let's rescale before starting the game
|
||||
// We can do it at this stage.
|
||||
waScaleManager.applyNewSize();
|
||||
this.scene.start(nextSceneName);
|
||||
localeDetector()
|
||||
.then(() => {
|
||||
gameManager
|
||||
.init(this.scene)
|
||||
.then((nextSceneName) => {
|
||||
// Let's rescale before starting the game
|
||||
// We can do it at this stage.
|
||||
waScaleManager.applyNewSize();
|
||||
this.scene.start(nextSceneName);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status == 404) {
|
||||
ErrorScene.showError(
|
||||
new WAError(
|
||||
$LL.error.accessLink.title(),
|
||||
$LL.error.accessLink.subTitle(),
|
||||
$LL.error.accessLink.details()
|
||||
),
|
||||
this.scene
|
||||
);
|
||||
} else if (err.response && err.response.status == 403) {
|
||||
ErrorScene.showError(
|
||||
new WAError(
|
||||
$LL.error.connectionRejected.title(),
|
||||
$LL.error.connectionRejected.subTitle({
|
||||
error: err.response.data ? ". \n\r \n\r" + `${err.response.data}` : "",
|
||||
}),
|
||||
$LL.error.connectionRejected.details()
|
||||
),
|
||||
this.scene
|
||||
);
|
||||
} else {
|
||||
ErrorScene.showError(err, this.scene);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status == 404) {
|
||||
ErrorScene.showError(
|
||||
new WAError(
|
||||
"Access link incorrect",
|
||||
"Could not find map. Please check your access link.",
|
||||
"If you want more information, you may contact administrator or contact us at: partey@bstly.de"
|
||||
),
|
||||
this.scene
|
||||
);
|
||||
} else if (err.response && err.response.status == 403) {
|
||||
ErrorScene.showError(
|
||||
new WAError(
|
||||
"Connection rejected",
|
||||
(err.response.data ? ". \n\r \n\r" + `${err.response.data}` : "") +
|
||||
".",
|
||||
"If you want more information, you may contact administrator or contact us at: partey@bstly.de"
|
||||
),
|
||||
this.scene
|
||||
);
|
||||
} else {
|
||||
ErrorScene.showError(err, this.scene);
|
||||
}
|
||||
.catch(() => {
|
||||
throw new Error("Cannot load locale!");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { TextField } from "../Components/TextField";
|
||||
import Image = Phaser.GameObjects.Image;
|
||||
import Sprite = Phaser.GameObjects.Sprite;
|
||||
import LL from "../../i18n/i18n-svelte";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
export const ReconnectingSceneName = "ReconnectingScene";
|
||||
export enum ReconnectingTextures {
|
||||
@@ -38,7 +40,7 @@ export class ReconnectingScene extends Phaser.Scene {
|
||||
this,
|
||||
this.game.renderer.width / 2,
|
||||
this.game.renderer.height / 2,
|
||||
"Connection lost. Reconnecting..."
|
||||
get(LL).warning.connectionLost()
|
||||
);
|
||||
|
||||
const cat = this.add.sprite(this.game.renderer.width / 2, this.game.renderer.height / 2 - 32, "cat");
|
||||
|
||||
Reference in New Issue
Block a user