diff --git a/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts b/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts index 19bb02bb..34454413 100644 --- a/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts +++ b/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts @@ -4,6 +4,10 @@ import type { GameScene } from "../Game/GameScene"; export class GameSceneUserInputHandler implements UserInputHandlerInterface { private gameScene: GameScene; + private lastTime: number = 0; + private lastX: number = 0; + private lastY: number = 0; + constructor(gameScene: GameScene) { this.gameScene = gameScene; } @@ -22,27 +26,34 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface { if (pointer.rightButtonReleased() || pointer.getDuration() > 250) { return; } - const camera = this.gameScene.getCameraManager().getCamera(); - const index = this.gameScene - .getGameMap() - .getTileIndexAt(pointer.x + camera.scrollX, pointer.y + camera.scrollY); - const startTile = this.gameScene - .getGameMap() - .getTileIndexAt(this.gameScene.CurrentPlayer.x, this.gameScene.CurrentPlayer.y); - this.gameScene - .getPathfindingManager() - .findPath(startTile, index, true, true) - .then((path) => { - // Remove first step as it is for the tile we are currently standing on - path.shift(); - this.gameScene.CurrentPlayer.setPathToFollow(path).catch((reason) => {}); - }) - .catch((reason) => { - console.warn(reason); - }); + + if (this.lastTime > 0 && pointer.time - this.lastTime < 500 && this.lastX == pointer.x && this.lastY == pointer.y) { + const camera = this.gameScene.getCameraManager().getCamera(); + const index = this.gameScene + .getGameMap() + .getTileIndexAt(pointer.x + camera.scrollX, pointer.y + camera.scrollY); + const startTile = this.gameScene + .getGameMap() + .getTileIndexAt(this.gameScene.CurrentPlayer.x, this.gameScene.CurrentPlayer.y); + this.gameScene + .getPathfindingManager() + .findPath(startTile, index, true, true) + .then((path) => { + // Remove first step as it is for the tile we are currently standing on + path.shift(); + this.gameScene.CurrentPlayer.setPathToFollow(path).catch((reason) => { }); + }) + .catch((reason) => { + console.warn(reason); + }); + } + + this.lastTime = pointer.time; + this.lastX = pointer.x; + this.lastY = pointer.y; } - public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {} + public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void { } public handleSpaceKeyUpEvent(event: Event): Event { this.gameScene.activateOutlinedItem();