diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 44992d85..8d13cb7b 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -92,6 +92,7 @@ import { MapStore } from "../../Stores/Utils/MapStore"; import { followUsersColorStore } from "../../Stores/FollowStore"; import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler"; import { locale } from "../../i18n/i18n-svelte"; +import { StringUtils } from "../../Utils/StringUtils"; export interface GameSceneInitInterface { initPosition: PointInterface | null; reconnecting: boolean; @@ -1632,12 +1633,17 @@ ${escapedMessage} const moveToParam = urlManager.getHashParameter("moveTo"); if (moveToParam) { try { - const destinationObject = this.gameMap.getObjectWithName(moveToParam); let endPos; - if (destinationObject) { - endPos = this.gameMap.getTileIndexAt(destinationObject.x, destinationObject.y); + const posFromParam = StringUtils.parsePointFromParam(moveToParam); + if (posFromParam) { + endPos = this.gameMap.getTileIndexAt(posFromParam.x, posFromParam.y); } else { - endPos = this.gameMap.getRandomPositionFromLayer(moveToParam); + const destinationObject = this.gameMap.getObjectWithName(moveToParam); + if (destinationObject) { + endPos = this.gameMap.getTileIndexAt(destinationObject.x, destinationObject.y); + } else { + endPos = this.gameMap.getRandomPositionFromLayer(moveToParam); + } } this.pathfindingManager .findPath(this.gameMap.getTileIndexAt(this.CurrentPlayer.x, this.CurrentPlayer.y), endPos) diff --git a/front/src/Utils/StringUtils.ts b/front/src/Utils/StringUtils.ts new file mode 100644 index 00000000..1f168c15 --- /dev/null +++ b/front/src/Utils/StringUtils.ts @@ -0,0 +1,12 @@ +export class StringUtils { + public static parsePointFromParam(param: string, separator: string = ","): { x: number; y: number } | undefined { + const values = param.split(separator).map((val) => parseInt(val)); + if (values.length !== 2) { + return; + } + if (isNaN(values[0]) || isNaN(values[1])) { + return; + } + return { x: values[0], y: values[1] }; + } +}