-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEventManager.js
87 lines (87 loc) · 2.65 KB
/
EventManager.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Created by knutandersstokke on 16.10.2016.
*
*/
/** Manager for events stored in queue. Manager is also responsible for executing events automatically */
var eventManager = /** @class */ (function () {
function eventManager() {
this.delayTime = 1000; // Original value
this.nextEvents = [];
this.previousEvents = [];
this.paused = true;
}
// Executing the next event in the queue, adding it to 'previous'
eventManager.prototype.next = function () {
if (this.nextEvents.length == 0) {
return;
}
var event = this.nextEvents.shift();
event.next();
this.previousEvents.push(event);
if (event.duration == 0)
this.next();
};
// Executing the previous event
eventManager.prototype.previous = function () {
this.pause();
if (this.previousEvents.length == 0)
return;
var event = this.previousEvents.pop();
event.previous();
this.nextEvents.unshift(event);
};
eventManager.prototype.addEvent = function (event) {
this.nextEvents.push(event);
};
eventManager.prototype.start = function () {
var manager = this; // Anonymous functions cannot access this...
this.paused = false;
this.eventThread = setInterval(function () {
manager.next();
}, manager.delayTime);
};
eventManager.prototype.pause = function () {
this.paused = true;
clearInterval(this.eventThread);
};
eventManager.prototype.unpause = function () {
var manager = this;
this.paused = false;
this.eventThread = setInterval(function () {
manager.next();
}, manager.delayTime);
};
eventManager.prototype.clear = function () {
clearInterval(this.eventThread);
this.nextEvents = [];
this.previousEvents = [];
};
eventManager.prototype.slow = function () {
this.delayTime = 1500;
this.helpSetInterval();
};
eventManager.prototype.medium = function () {
this.delayTime = 1000;
this.helpSetInterval();
};
eventManager.prototype.fast = function () {
this.delayTime = 500;
this.helpSetInterval();
};
eventManager.prototype.helpSetInterval = function () {
if (!this.paused) {
this.pause();
this.start();
}
};
return eventManager;
}());
var FrontendEvent = /** @class */ (function () {
function FrontendEvent(n, p, d) {
this.next = n;
this.previous = p;
this.duration = d;
}
return FrontendEvent;
}());
var manager = new eventManager();