-
-
Notifications
You must be signed in to change notification settings - Fork 254
/
action.ts
56 lines (49 loc) · 1.22 KB
/
action.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
import Scheduler from "./scheduler.js";
/**
* @class Action-based scheduler
* @augments ROT.Scheduler
*/
export default class Action<T = any> extends Scheduler<T> {
_defaultDuration: number;
_duration: number;
constructor() {
super();
this._defaultDuration = 1; /* for newly added */
this._duration = this._defaultDuration; /* for this._current */
}
/**
* @param {object} item
* @param {bool} repeat
* @param {number} [time=1]
* @see ROT.Scheduler#add
*/
add(item:T, repeat:boolean, time?: number) {
this._queue.add(item, time || this._defaultDuration);
return super.add(item, repeat);
}
clear() {
this._duration = this._defaultDuration;
return super.clear();
}
remove(item:T) {
if (item == this._current) { this._duration = this._defaultDuration; }
return super.remove(item);
}
/**
* @see ROT.Scheduler#next
*/
next() {
if (this._current !== null && this._repeat.indexOf(this._current) != -1) {
this._queue.add(this._current, this._duration || this._defaultDuration);
this._duration = this._defaultDuration;
}
return super.next();
}
/**
* Set duration for the active item
*/
setDuration(time: number) {
if (this._current) { this._duration = time; }
return this;
}
}