parse x and y position from moveTo param
This commit is contained in:
parent
fe570c9117
commit
b565080312
@ -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)
|
||||
|
12
front/src/Utils/StringUtils.ts
Normal file
12
front/src/Utils/StringUtils.ts
Normal file
@ -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] };
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user