Skip to content

Commit

Permalink
Fix double click
Browse files Browse the repository at this point in the history
  • Loading branch information
jankuss committed Jan 23, 2021
1 parent 41b34f2 commit fab78c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization {

this._disableTransitions = this._changeAnimationCount === 0;
this._changeAnimationCount++;

this.updateFrame(0);
}

updateAnimation(animation: string): void {
Expand Down
12 changes: 6 additions & 6 deletions src/objects/hitdetection/ClickHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
32 changes: 29 additions & 3 deletions storybook/stories/Furniture.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`,
Expand All @@ -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;
Expand All @@ -118,7 +144,7 @@ export function Animated() {
furniture.roomY = value.roomY;
furniture.roomZ = value.roomZ;
});
}
}*/

room.addRoomObject(furniture);
}
Expand Down

0 comments on commit fab78c6

Please sign in to comment.