-
Notifications
You must be signed in to change notification settings - Fork 16
/
scoreboard.ts
66 lines (62 loc) · 1.37 KB
/
scoreboard.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { TimeboxEvoRequest } from "../requests";
import { int2hexlittle } from "../helpers/utils";
/**
* Options for the [[ScoreBoardChannel]]
*/
interface ScoreBoardOptions {
red?: number;
blue?: number;
}
export class ScoreBoardChannel extends TimeboxEvoRequest {
private _opts: ScoreBoardOptions = {
red: 0,
blue: 0
};
private _PACKAGE_PREFIX = "450600";
/**
* Generates the appropriate message to display the scoreboard
* @param opts The options for the channel
*/
constructor(opts?: ScoreBoardOptions) {
super();
this.red = opts && opts.red ? opts.red : 0;
this.blue = opts && opts.blue ? opts.blue : 0;
}
/**
* Updates the message queue based on the parameters used
*/
private _updateMessage() {
this.clear();
this.push(
this._PACKAGE_PREFIX +
int2hexlittle(this._opts.red) +
int2hexlittle(this._opts.blue)
);
}
/**
* Sets the red player score
*/
set red(int: number) {
this._opts.red = Math.min(999, Math.max(0, int));
this._updateMessage();
}
/**
* Gets the red player score
*/
get red() {
return this._opts.red;
}
/**
* Sets the blue player score
*/
set blue(int: number) {
this._opts.blue = Math.min(999, Math.max(0, int));
this._updateMessage();
}
/**
* Gets the blue player score
*/
get blue() {
return this._opts.blue;
}
}