parse x and y position from moveTo param
This commit is contained in:
parent
fe570c9117
commit
b565080312
2 changed files with 22 additions and 4 deletions
|
@ -92,6 +92,7 @@ import { MapStore } from "../../Stores/Utils/MapStore";
|
||||||
import { followUsersColorStore } from "../../Stores/FollowStore";
|
import { followUsersColorStore } from "../../Stores/FollowStore";
|
||||||
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
||||||
import { locale } from "../../i18n/i18n-svelte";
|
import { locale } from "../../i18n/i18n-svelte";
|
||||||
|
import { StringUtils } from "../../Utils/StringUtils";
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface | null;
|
initPosition: PointInterface | null;
|
||||||
reconnecting: boolean;
|
reconnecting: boolean;
|
||||||
|
@ -1632,12 +1633,17 @@ ${escapedMessage}
|
||||||
const moveToParam = urlManager.getHashParameter("moveTo");
|
const moveToParam = urlManager.getHashParameter("moveTo");
|
||||||
if (moveToParam) {
|
if (moveToParam) {
|
||||||
try {
|
try {
|
||||||
const destinationObject = this.gameMap.getObjectWithName(moveToParam);
|
|
||||||
let endPos;
|
let endPos;
|
||||||
if (destinationObject) {
|
const posFromParam = StringUtils.parsePointFromParam(moveToParam);
|
||||||
endPos = this.gameMap.getTileIndexAt(destinationObject.x, destinationObject.y);
|
if (posFromParam) {
|
||||||
|
endPos = this.gameMap.getTileIndexAt(posFromParam.x, posFromParam.y);
|
||||||
} else {
|
} 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
|
this.pathfindingManager
|
||||||
.findPath(this.gameMap.getTileIndexAt(this.CurrentPlayer.x, this.CurrentPlayer.y), endPos)
|
.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…
Add table
Add a link
Reference in a new issue