/
spinner.ts
44 lines (35 loc) · 985 Bytes
/
spinner.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
import * as alt from 'alt-client';
import * as native from 'natives';
import { SYSTEM_EVENTS } from '@AthenaShared/enums/system';
import ISpinner from '@AthenaShared/interfaces/iSpinner';
let timeout: number;
/**
* Used to clear the last set spinner.
*
*/
export function clear() {
if (timeout) {
alt.clearTimeout(timeout);
timeout = null;
}
native.busyspinnerOff();
}
/**
* Create a spinner to show in the bottom-right corner.
*
* @param {ISpinner} spinner
*/
export function create(data: ISpinner) {
clear();
if (!data.type) {
data.type = 0;
}
native.beginTextCommandBusyspinnerOn('STRING');
native.addTextComponentSubstringPlayerName(data.text);
native.endTextCommandBusyspinnerOn(data.type);
if (data.duration >= 0) {
timeout = alt.setTimeout(clear, data.duration);
}
}
alt.onServer(SYSTEM_EVENTS.PLAYER_EMIT_SPINNER, create);
alt.onServer(SYSTEM_EVENTS.PLAYER_EMIT_SPINNER_CLEAR, clear);