Skip to content

Commit

Permalink
Fix ignoreMouse property
Browse files Browse the repository at this point in the history
  • Loading branch information
jankuss committed Jan 23, 2021
1 parent 5aec70d commit 9ac6bc4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
23 changes: 12 additions & 11 deletions src/objects/furniture/BaseFurniture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,20 @@ export class BaseFurniture implements IFurnitureEventHandlers {
group: this,
});

if (layer?.ignoreMouse !== true) {
sprite.addEventListener("click", (event) =>
this._clickHandler.handleClick(event)
);
const ignoreMouse = layer?.ignoreMouse != null && layer.ignoreMouse;
sprite.ignoreMouse = ignoreMouse;

sprite.addEventListener("pointerup", (event) => {
this._clickHandler.handlePointerUp(event);
});
sprite.addEventListener("click", (event) => {
this._clickHandler.handleClick(event);
});

sprite.addEventListener("pointerdown", (event) => {
this._clickHandler.handlePointerDown(event);
});
}
sprite.addEventListener("pointerup", (event) => {
this._clickHandler.handlePointerUp(event);
});

sprite.addEventListener("pointerdown", (event) => {
this._clickHandler.handlePointerDown(event);
});

sprite.hitTexture = texture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization {
this._disableTransitions = this._changeAnimationCount === 0;
this._changeAnimationCount++;

if (!this.isAnimated(newAnimation.toString())) {
this.updateFrame(0);
}
this._update();
}

updateAnimation(animation: string): void {
Expand Down
1 change: 0 additions & 1 deletion src/objects/hitdetection/ClickHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class ClickHandler {

private _performDoubleClick(event: HitEvent) {
if (this._doubleClickInfo == null) return;
if (event.target !== this._doubleClickInfo.initialEvent.target) return;

this.onDoubleClick &&
this.onDoubleClick(this._doubleClickInfo.initialEvent);
Expand Down
30 changes: 22 additions & 8 deletions src/objects/hitdetection/HitSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export class HitSprite extends PIXI.Sprite implements HitDetectionElement {
private _mirrored: boolean;
private _mirrorNotVisually: boolean;
private _ignore = false;
private _ignoreMouse = false;

private _getHitmap:
| (() => (
x: number,
y: number,
transform: { x: number; y: number }
) => boolean)
| undefined;

constructor({
hitDetection,
Expand Down Expand Up @@ -51,6 +60,14 @@ export class HitSprite extends PIXI.Sprite implements HitDetectionElement {
this.mirrored = this._mirrored;
}

public get ignoreMouse() {
return this._ignoreMouse;
}

public set ignoreMouse(value) {
this._ignoreMouse = value;
}

public get group() {
return this._group;
}
Expand All @@ -72,14 +89,6 @@ export class HitSprite extends PIXI.Sprite implements HitDetectionElement {
this.scale.x = this._mirrored ? -1 : 1;
}

private _getHitmap:
| (() => (
x: number,
y: number,
transform: { x: number; y: number }
) => boolean)
| undefined;

public get hitTexture() {
return this._hitTexture;
}
Expand Down Expand Up @@ -110,6 +119,10 @@ export class HitSprite extends PIXI.Sprite implements HitDetectionElement {
handlers?.forEach((handler) => handler(event));
}

removeAllEventListeners() {
this._handlers = new Map();
}

addEventListener(type: HitEventType, handler: HitEventHandler) {
const existingHandlers = this._handlers.get(type) ?? new Set();
existingHandlers.add(handler);
Expand Down Expand Up @@ -151,6 +164,7 @@ export class HitSprite extends PIXI.Sprite implements HitDetectionElement {
hits(x: number, y: number): boolean {
if (this._getHitmap == null) return false;
if (this.ignore) return false;
if (this.ignoreMouse) return false;

const hitBox = this.getHitBox();

Expand Down
1 change: 1 addition & 0 deletions storybook/stories/Furniture.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export function GldGate() {

floorFurniture3.onClick = () => {
b = !b;
console.log("CHANGE");

if (b) {
floorFurniture3.animation = "1";
Expand Down

0 comments on commit 9ac6bc4

Please sign in to comment.