1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | var __assign = (this && this.__assign) || Object.assign || function(t) {
|
13 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
14 | s = arguments[i];
|
15 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
16 | t[p] = s[p];
|
17 | }
|
18 | return t;
|
19 | };
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | var SideralObject_1 = require("./../SideralObject");
|
22 | var Tool_1 = require("./../Tool");
|
23 | var Timer_1 = require("./Timer");
|
24 |
|
25 |
|
26 |
|
27 | var TimerManager = (function (_super) {
|
28 | __extends(TimerManager, _super);
|
29 | function TimerManager() {
|
30 |
|
31 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
32 | |
33 |
|
34 |
|
35 | _this.timers = {};
|
36 | return _this;
|
37 | }
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | TimerManager.prototype.addTimer = function (name, duration, onComplete, options) {
|
48 | if (options === void 0) { options = {}; }
|
49 | var timer = this.add(new Timer_1.Timer(), __assign({ duration: duration, complete: onComplete }, options));
|
50 | timer.name = name;
|
51 | var oldTimer = this.timers[name];
|
52 | if (oldTimer) {
|
53 | oldTimer.kill();
|
54 | }
|
55 | return this.timers[name] = timer;
|
56 | };
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 | TimerManager.prototype.getTimer = function (name) {
|
63 | return this.timers[name];
|
64 | };
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | TimerManager.prototype.getDuration = function (duration, type, animation) {
|
73 | var ms = duration;
|
74 | switch (type) {
|
75 | case Tool_1.Enum.DURATION_TYPE.ANIMATION_LOOP:
|
76 | if (!animation) {
|
77 | throw new Error("Timers.getDuration: You must provide an 'animation' object when you use Enum.DURATION_TYPE.ANIMATION_LOOP");
|
78 | }
|
79 | ms = animation.duration * duration * animation.frames.length;
|
80 | break;
|
81 | case Tool_1.Enum.DURATION_TYPE.FRAME:
|
82 | ms = Timer_1.Timer.frameToMs(duration, this.context.game.fps);
|
83 | break;
|
84 | }
|
85 | return ms;
|
86 | };
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 | TimerManager.prototype.removeTimer = function (name) {
|
93 | var timer = this.timers[name];
|
94 | if (timer) {
|
95 | timer.kill();
|
96 | }
|
97 | delete this.timers[name];
|
98 | return this;
|
99 | };
|
100 | |
101 |
|
102 |
|
103 | TimerManager.prototype.removeAllTimer = function () {
|
104 | var _this = this;
|
105 | Object.keys(this.timers).forEach(function (key) { return _this.timers[key] && _this.timers[key].kill(); });
|
106 | this.timers = {};
|
107 | return this;
|
108 | };
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | TimerManager.prototype.isFinished = function (name) {
|
116 | var timer = this.timers[name];
|
117 | return timer ? timer.finished : true;
|
118 | };
|
119 | return TimerManager;
|
120 | }(SideralObject_1.SideralObject));
|
121 | exports.TimerManager = TimerManager;
|