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 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var SideralObject_1 = require("./../SideralObject");
|
14 |
|
15 |
|
16 |
|
17 | var SkillManager = (function (_super) {
|
18 | __extends(SkillManager, _super);
|
19 | function SkillManager() {
|
20 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
21 | |
22 |
|
23 |
|
24 | _this.skills = {};
|
25 | |
26 |
|
27 |
|
28 | _this.currentSkill = null;
|
29 | |
30 |
|
31 |
|
32 | _this.lastSkill = null;
|
33 | return _this;
|
34 | }
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | SkillManager.prototype.addSkill = function (name, skill) {
|
43 | skill.name = name;
|
44 | skill.owner = this.parent;
|
45 | skill.signals.skillComplete.add(this._onSkillComplete.bind(this));
|
46 | return this.skills[name] = this.add(skill);
|
47 | };
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | SkillManager.prototype.get = function (name) {
|
54 | return this.skills[name];
|
55 | };
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | SkillManager.prototype.isRunning = function (name) {
|
62 | return this.currentSkill && this.currentSkill[name] === this.skills[name] && this.currentSkill.active;
|
63 | };
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | SkillManager.prototype.run = function (name, props) {
|
71 | var skill = this.get(name);
|
72 | if (!skill || (skill && !skill.ready) || (this.currentSkill && this.currentSkill.unstoppable)) {
|
73 | return false;
|
74 | }
|
75 | if (this.currentSkill) {
|
76 | this.currentSkill.stop();
|
77 | }
|
78 | this.currentSkill = skill;
|
79 | this.currentSkill.run(props);
|
80 | return true;
|
81 | };
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | SkillManager.prototype.remove = function (name) {
|
88 | delete this.skills[name];
|
89 | };
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | SkillManager.prototype._onSkillComplete = function (skill) {
|
98 | if (this.currentSkill.name === skill.name) {
|
99 | this.currentSkill = null;
|
100 | }
|
101 | this.lastSkill = skill;
|
102 | };
|
103 | return SkillManager;
|
104 | }(SideralObject_1.SideralObject));
|
105 | exports.SkillManager = SkillManager;
|