summaryrefslogtreecommitdiff
path: root/src/engine/components/Highlight.ts
blob: 587505777d67ea3c18f162e79f6a65218a8422ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Component, ComponentNames } from ".";

export class Highlight extends Component {
  public isHighlighted: boolean;
  private onHighlight: Function;
  private onUnhighlight: Function;

  constructor(
    onHighlight: Function,
    onUnhighlight: Function,
    isHighlighted: boolean = false,
  ) {
    super(ComponentNames.Highlight);

    this.isHighlighted = isHighlighted;
    this.onHighlight = onHighlight;
    this.onUnhighlight = onUnhighlight;
  }

  public highlight() {
    if (!this.isHighlighted) {
      this.isHighlighted = true;
      this.onHighlight();
    }
  }

  public unhighlight() {
    if (this.isHighlighted) {
      this.isHighlighted = false;
      this.onUnhighlight();
    }
  }
}