From fab78c6301fa5a6214785830c08092cc5a46c4ac Mon Sep 17 00:00:00 2001 From: jankuss Date: Sat, 23 Jan 2021 08:41:14 -0800 Subject: [PATCH] Fix double click --- .../AnimatedFurnitureVisualization.ts | 2 -- src/objects/hitdetection/ClickHandler.ts | 12 +++---- storybook/stories/Furniture.stories.ts | 32 +++++++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts b/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts index 58a26d78..ccf66463 100644 --- a/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts +++ b/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts @@ -63,8 +63,6 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization { this._disableTransitions = this._changeAnimationCount === 0; this._changeAnimationCount++; - - this.updateFrame(0); } updateAnimation(animation: string): void { diff --git a/src/objects/hitdetection/ClickHandler.ts b/src/objects/hitdetection/ClickHandler.ts index db1a60f3..3973628e 100644 --- a/src/objects/hitdetection/ClickHandler.ts +++ b/src/objects/hitdetection/ClickHandler.ts @@ -51,19 +51,19 @@ export class ClickHandler { } handleClick(event: HitEvent) { - if (this._doubleClickInfo == null) { - if (this._canHandleEvent(ClickHandler.CLICK)) { - this._beginEvent(ClickHandler.CLICK); + if (this._canHandleEvent(ClickHandler.CLICK)) { + this._beginEvent(ClickHandler.CLICK); + if (this._doubleClickInfo == null) { this.onClick && this.onClick(event); if (this.onDoubleClick != null) { this._startDoubleClick(event); } + } else { + event.stopPropagation(); + this._performDoubleClick(event); } - } else { - event.stopPropagation(); - this._performDoubleClick(event); } } diff --git a/storybook/stories/Furniture.stories.ts b/storybook/stories/Furniture.stories.ts index 16b4a4d7..c9b94296 100644 --- a/storybook/stories/Furniture.stories.ts +++ b/storybook/stories/Furniture.stories.ts @@ -53,7 +53,32 @@ export function Default() { room.addRoomObject(furniture); } + const test1 = new FloorFurniture({ + roomX: 3, + roomY: 3, + roomZ: 0, + id: 1626, + direction: 2, + }); + + const test2 = new FloorFurniture({ + roomX: 3, + roomY: 3, + roomZ: 0, + id: 285, + direction: 2, + }); + + test1.onClick = () => { + console.log("Clicked"); + }; + test1.onDoubleClick = () => { + console.log("Double Clicked"); + }; + room.onTileClick = (position) => console.log(position); + room.addRoomObject(test1); + room.addRoomObject(test2); const dice = new FloorFurniture({ roomX: 1, @@ -93,7 +118,7 @@ export function Animated() { const animation = i % 2 === 0 ? "0" : "1"; const furniture = new FloorFurniture({ - roomX: 1 + i * 3, + roomX: 1, roomY: 1, roomZ: 0, type: `rare_dragonlamp*${i}`, @@ -103,13 +128,14 @@ export function Animated() { furniture.onClick = action(`Furniture ${i} clicked`); furniture.onDoubleClick = () => { + action(`Furniture ${i} double clicked`)(); if (furniture.animation === "0") { furniture.animation = "1"; } else { furniture.animation = "0"; } }; - + /* if (i === 0) { room.onActiveTileChange.subscribe((value) => { if (value == null) return; @@ -118,7 +144,7 @@ export function Animated() { furniture.roomY = value.roomY; furniture.roomZ = value.roomZ; }); - } + }*/ room.addRoomObject(furniture); }