Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/objects/events/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class EventManager {
private _bush = new RBush<EventManagerNode>();
private _currentOverElements: Set<EventManagerNode> = new Set();
private _pointerDownElements: Set<EventManagerNode> = new Set();
private _onBackgroundClick: ((event: InteractionEvent) => void) | undefined = undefined;

public set onBackgroundClick(value: ((event: InteractionEvent) => void) | undefined) {
this._onBackgroundClick = value;
}

click(event: InteractionEvent, x: number, y: number) {
const elements = this._performHitTest(x, y);
Expand Down Expand Up @@ -48,6 +53,10 @@ export class EventManager {
}
});

if (elements.activeNodes.length === 0 && clickedNodes.size === 0 && this._onBackgroundClick) {
this._onBackgroundClick(event);
}

new Propagation(event, elements.activeNodes, (target, event) =>
target.triggerPointerUp(event)
);
Expand Down
5 changes: 5 additions & 0 deletions src/objects/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RoomModelVisualization } from "./RoomModelVisualization";
import { ParsedTileMap } from "./ParsedTileMap";
import { getTileColors, getWallColors } from "./util/getTileColors";
import { EventManager } from "../events/EventManager";
import { InteractionEvent } from "pixi.js";

export interface Dependencies {
animationTicker: IAnimationTicker;
Expand Down Expand Up @@ -330,6 +331,10 @@ export class Room
this._visualization.destroy();
}

public set onBackgroundClick(value: ((event: InteractionEvent) => void) | undefined) {
this._eventManager.onBackgroundClick = value;
}

private _getObjectPositionWithOffset(roomX: number, roomY: number) {
return {
x: roomX,
Expand Down