summaryrefslogtreecommitdiff
path: root/src/engine/components/Highlight.ts
blob: 66ec74b3e792cad5a4d56759804483f4ec46904e (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
34
import { Component, ComponentNames } from ".";
import { Direction } from "../interfaces";

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

  constructor(
    onHighlight: (direction: Direction) => void,
    onUnhighlight: () => void,
    isHighlighted: boolean = false,
  ) {
    super(ComponentNames.Highlight);

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

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

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