call activate() method on space key up

This commit is contained in:
Hanusiak Piotr 2022-01-26 13:16:52 +01:00
parent 3af6461c01
commit f42c7564b9
2 changed files with 7 additions and 2 deletions

View File

@ -1679,12 +1679,12 @@ ${escapedMessage}
private handleCurrentPlayerHasMovedEvent(event: HasPlayerMovedEvent): void {
//listen event to share position of user
this.pushPlayerPosition(event);
this.nearestActivatableObject = this.getNearestActivatableObject();
this.nearestActivatableObject = this.findNearestActivatableObject();
this.outlineItem(event);
this.gameMap.setPosition(event.x, event.y);
}
private getNearestActivatableObject(): ActivatableInterface | undefined {
private findNearestActivatableObject(): ActivatableInterface | undefined {
let shortestDistance: number = Infinity;
let closestObject: ActivatableInterface | undefined = undefined;
const currentPlayerPos = this.CurrentPlayer.getPosition();
@ -2225,4 +2225,8 @@ ${escapedMessage}
public getPathfindingManager(): PathfindingManager {
return this.pathfindingManager;
}
public getNearestActivatableObject(): ActivatableInterface | undefined {
return this.nearestActivatableObject
}
}

View File

@ -54,6 +54,7 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
public handleSpaceKeyUpEvent(event: Event): Event {
this.gameScene.activateOutlinedItem();
this.gameScene.getNearestActivatableObject()?.activate();
return event;
}
}