1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.superECS = {}));
|
5 | }(this, (function (exports) { 'use strict';
|
6 |
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var extendStatics = function(d, b) {
|
24 | extendStatics = Object.setPrototypeOf ||
|
25 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
26 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
27 | return extendStatics(d, b);
|
28 | };
|
29 |
|
30 | function __extends(d, b) {
|
31 | if (typeof b !== "function" && b !== null)
|
32 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
33 | extendStatics(d, b);
|
34 | function __() { this.constructor = d; }
|
35 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
36 | }
|
37 |
|
38 | function __awaiter(thisArg, _arguments, P, generator) {
|
39 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
40 | return new (P || (P = Promise))(function (resolve, reject) {
|
41 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
42 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
43 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
44 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
45 | });
|
46 | }
|
47 |
|
48 | function __generator(thisArg, body) {
|
49 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
50 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
51 | function verb(n) { return function (v) { return step([n, v]); }; }
|
52 | function step(op) {
|
53 | if (f) throw new TypeError("Generator is already executing.");
|
54 | while (_) try {
|
55 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
56 | if (y = 0, t) op = [op[0] & 2, t.value];
|
57 | switch (op[0]) {
|
58 | case 0: case 1: t = op; break;
|
59 | case 4: _.label++; return { value: op[1], done: false };
|
60 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
61 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
62 | default:
|
63 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
64 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
65 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
66 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
67 | if (t[2]) _.ops.pop();
|
68 | _.trys.pop(); continue;
|
69 | }
|
70 | op = body.call(thisArg, _);
|
71 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
72 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
73 | }
|
74 | }
|
75 |
|
76 | function __values(o) {
|
77 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
78 | if (m) return m.call(o);
|
79 | if (o && typeof o.length === "number") return {
|
80 | next: function () {
|
81 | if (o && i >= o.length) o = void 0;
|
82 | return { value: o && o[i++], done: !o };
|
83 | }
|
84 | };
|
85 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
86 | }
|
87 |
|
88 | function __read(o, n) {
|
89 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
90 | if (!m) return o;
|
91 | var i = m.call(o), r, ar = [], e;
|
92 | try {
|
93 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
94 | }
|
95 | catch (error) { e = { error: error }; }
|
96 | finally {
|
97 | try {
|
98 | if (r && !r.done && (m = i["return"])) m.call(i);
|
99 | }
|
100 | finally { if (e) throw e.error; }
|
101 | }
|
102 | return ar;
|
103 | }
|
104 |
|
105 | function __spreadArray(to, from) {
|
106 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
107 | to[j] = from[i];
|
108 | return to;
|
109 | }
|
110 |
|
111 | function __await(v) {
|
112 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
113 | }
|
114 |
|
115 | function __asyncGenerator(thisArg, _arguments, generator) {
|
116 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
117 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
118 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
119 | function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
120 | function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
121 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
122 | function fulfill(value) { resume("next", value); }
|
123 | function reject(value) { resume("throw", value); }
|
124 | function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
125 | }
|
126 |
|
127 | function __asyncValues(o) {
|
128 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
129 | var m = o[Symbol.asyncIterator], i;
|
130 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
131 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
132 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
133 | }
|
134 |
|
135 | function isFunction(value) {
|
136 | return typeof value === 'function';
|
137 | }
|
138 |
|
139 | function createErrorClass(createImpl) {
|
140 | var _super = function (instance) {
|
141 | Error.call(instance);
|
142 | instance.stack = new Error().stack;
|
143 | };
|
144 | var ctorFunc = createImpl(_super);
|
145 | ctorFunc.prototype = Object.create(Error.prototype);
|
146 | ctorFunc.prototype.constructor = ctorFunc;
|
147 | return ctorFunc;
|
148 | }
|
149 |
|
150 | var UnsubscriptionError = createErrorClass(function (_super) {
|
151 | return function UnsubscriptionErrorImpl(errors) {
|
152 | _super(this);
|
153 | this.message = errors
|
154 | ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
155 | : '';
|
156 | this.name = 'UnsubscriptionError';
|
157 | this.errors = errors;
|
158 | };
|
159 | });
|
160 |
|
161 | function arrRemove(arr, item) {
|
162 | if (arr) {
|
163 | var index = arr.indexOf(item);
|
164 | 0 <= index && arr.splice(index, 1);
|
165 | }
|
166 | }
|
167 |
|
168 | var Subscription = (function () {
|
169 | function Subscription(initialTeardown) {
|
170 | this.initialTeardown = initialTeardown;
|
171 | this.closed = false;
|
172 | this._parentage = null;
|
173 | this._teardowns = null;
|
174 | }
|
175 | Subscription.prototype.unsubscribe = function () {
|
176 | var e_1, _a, e_2, _b;
|
177 | var errors;
|
178 | if (!this.closed) {
|
179 | this.closed = true;
|
180 | var _parentage = this._parentage;
|
181 | if (_parentage) {
|
182 | this._parentage = null;
|
183 | if (Array.isArray(_parentage)) {
|
184 | try {
|
185 | for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
186 | var parent_1 = _parentage_1_1.value;
|
187 | parent_1.remove(this);
|
188 | }
|
189 | }
|
190 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
191 | finally {
|
192 | try {
|
193 | if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
194 | }
|
195 | finally { if (e_1) throw e_1.error; }
|
196 | }
|
197 | }
|
198 | else {
|
199 | _parentage.remove(this);
|
200 | }
|
201 | }
|
202 | var initialTeardown = this.initialTeardown;
|
203 | if (isFunction(initialTeardown)) {
|
204 | try {
|
205 | initialTeardown();
|
206 | }
|
207 | catch (e) {
|
208 | errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
209 | }
|
210 | }
|
211 | var _teardowns = this._teardowns;
|
212 | if (_teardowns) {
|
213 | this._teardowns = null;
|
214 | try {
|
215 | for (var _teardowns_1 = __values(_teardowns), _teardowns_1_1 = _teardowns_1.next(); !_teardowns_1_1.done; _teardowns_1_1 = _teardowns_1.next()) {
|
216 | var teardown_1 = _teardowns_1_1.value;
|
217 | try {
|
218 | execTeardown(teardown_1);
|
219 | }
|
220 | catch (err) {
|
221 | errors = errors !== null && errors !== void 0 ? errors : [];
|
222 | if (err instanceof UnsubscriptionError) {
|
223 | errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
224 | }
|
225 | else {
|
226 | errors.push(err);
|
227 | }
|
228 | }
|
229 | }
|
230 | }
|
231 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
232 | finally {
|
233 | try {
|
234 | if (_teardowns_1_1 && !_teardowns_1_1.done && (_b = _teardowns_1.return)) _b.call(_teardowns_1);
|
235 | }
|
236 | finally { if (e_2) throw e_2.error; }
|
237 | }
|
238 | }
|
239 | if (errors) {
|
240 | throw new UnsubscriptionError(errors);
|
241 | }
|
242 | }
|
243 | };
|
244 | Subscription.prototype.add = function (teardown) {
|
245 | var _a;
|
246 | if (teardown && teardown !== this) {
|
247 | if (this.closed) {
|
248 | execTeardown(teardown);
|
249 | }
|
250 | else {
|
251 | if (teardown instanceof Subscription) {
|
252 | if (teardown.closed || teardown._hasParent(this)) {
|
253 | return;
|
254 | }
|
255 | teardown._addParent(this);
|
256 | }
|
257 | (this._teardowns = (_a = this._teardowns) !== null && _a !== void 0 ? _a : []).push(teardown);
|
258 | }
|
259 | }
|
260 | };
|
261 | Subscription.prototype._hasParent = function (parent) {
|
262 | var _parentage = this._parentage;
|
263 | return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
264 | };
|
265 | Subscription.prototype._addParent = function (parent) {
|
266 | var _parentage = this._parentage;
|
267 | this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
268 | };
|
269 | Subscription.prototype._removeParent = function (parent) {
|
270 | var _parentage = this._parentage;
|
271 | if (_parentage === parent) {
|
272 | this._parentage = null;
|
273 | }
|
274 | else if (Array.isArray(_parentage)) {
|
275 | arrRemove(_parentage, parent);
|
276 | }
|
277 | };
|
278 | Subscription.prototype.remove = function (teardown) {
|
279 | var _teardowns = this._teardowns;
|
280 | _teardowns && arrRemove(_teardowns, teardown);
|
281 | if (teardown instanceof Subscription) {
|
282 | teardown._removeParent(this);
|
283 | }
|
284 | };
|
285 | Subscription.EMPTY = (function () {
|
286 | var empty = new Subscription();
|
287 | empty.closed = true;
|
288 | return empty;
|
289 | })();
|
290 | return Subscription;
|
291 | }());
|
292 | var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
293 | function isSubscription(value) {
|
294 | return (value instanceof Subscription ||
|
295 | (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
296 | }
|
297 | function execTeardown(teardown) {
|
298 | if (isFunction(teardown)) {
|
299 | teardown();
|
300 | }
|
301 | else {
|
302 | teardown.unsubscribe();
|
303 | }
|
304 | }
|
305 |
|
306 | var config = {
|
307 | onUnhandledError: null,
|
308 | onStoppedNotification: null,
|
309 | Promise: undefined,
|
310 | useDeprecatedSynchronousErrorHandling: false,
|
311 | useDeprecatedNextContext: false,
|
312 | };
|
313 |
|
314 | var timeoutProvider = {
|
315 | setTimeout: function () {
|
316 | var args = [];
|
317 | for (var _i = 0; _i < arguments.length; _i++) {
|
318 | args[_i] = arguments[_i];
|
319 | }
|
320 | return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
|
321 | },
|
322 | clearTimeout: function (handle) {
|
323 | return (clearTimeout)(handle);
|
324 | },
|
325 | delegate: undefined,
|
326 | };
|
327 |
|
328 | function reportUnhandledError(err) {
|
329 | timeoutProvider.setTimeout(function () {
|
330 | {
|
331 | throw err;
|
332 | }
|
333 | });
|
334 | }
|
335 |
|
336 | function noop() { }
|
337 |
|
338 | function errorContext(cb) {
|
339 | {
|
340 | cb();
|
341 | }
|
342 | }
|
343 |
|
344 | var Subscriber = (function (_super) {
|
345 | __extends(Subscriber, _super);
|
346 | function Subscriber(destination) {
|
347 | var _this = _super.call(this) || this;
|
348 | _this.isStopped = false;
|
349 | if (destination) {
|
350 | _this.destination = destination;
|
351 | if (isSubscription(destination)) {
|
352 | destination.add(_this);
|
353 | }
|
354 | }
|
355 | else {
|
356 | _this.destination = EMPTY_OBSERVER;
|
357 | }
|
358 | return _this;
|
359 | }
|
360 | Subscriber.create = function (next, error, complete) {
|
361 | return new SafeSubscriber(next, error, complete);
|
362 | };
|
363 | Subscriber.prototype.next = function (value) {
|
364 | if (this.isStopped) ;
|
365 | else {
|
366 | this._next(value);
|
367 | }
|
368 | };
|
369 | Subscriber.prototype.error = function (err) {
|
370 | if (this.isStopped) ;
|
371 | else {
|
372 | this.isStopped = true;
|
373 | this._error(err);
|
374 | }
|
375 | };
|
376 | Subscriber.prototype.complete = function () {
|
377 | if (this.isStopped) ;
|
378 | else {
|
379 | this.isStopped = true;
|
380 | this._complete();
|
381 | }
|
382 | };
|
383 | Subscriber.prototype.unsubscribe = function () {
|
384 | if (!this.closed) {
|
385 | this.isStopped = true;
|
386 | _super.prototype.unsubscribe.call(this);
|
387 | this.destination = null;
|
388 | }
|
389 | };
|
390 | Subscriber.prototype._next = function (value) {
|
391 | this.destination.next(value);
|
392 | };
|
393 | Subscriber.prototype._error = function (err) {
|
394 | try {
|
395 | this.destination.error(err);
|
396 | }
|
397 | finally {
|
398 | this.unsubscribe();
|
399 | }
|
400 | };
|
401 | Subscriber.prototype._complete = function () {
|
402 | try {
|
403 | this.destination.complete();
|
404 | }
|
405 | finally {
|
406 | this.unsubscribe();
|
407 | }
|
408 | };
|
409 | return Subscriber;
|
410 | }(Subscription));
|
411 | var _bind = Function.prototype.bind;
|
412 | function bind(fn, thisArg) {
|
413 | return _bind.call(fn, thisArg);
|
414 | }
|
415 | var ConsumerObserver = (function () {
|
416 | function ConsumerObserver(partialObserver) {
|
417 | this.partialObserver = partialObserver;
|
418 | }
|
419 | ConsumerObserver.prototype.next = function (value) {
|
420 | var partialObserver = this.partialObserver;
|
421 | if (partialObserver.next) {
|
422 | try {
|
423 | partialObserver.next(value);
|
424 | }
|
425 | catch (error) {
|
426 | handleUnhandledError(error);
|
427 | }
|
428 | }
|
429 | };
|
430 | ConsumerObserver.prototype.error = function (err) {
|
431 | var partialObserver = this.partialObserver;
|
432 | if (partialObserver.error) {
|
433 | try {
|
434 | partialObserver.error(err);
|
435 | }
|
436 | catch (error) {
|
437 | handleUnhandledError(error);
|
438 | }
|
439 | }
|
440 | else {
|
441 | handleUnhandledError(err);
|
442 | }
|
443 | };
|
444 | ConsumerObserver.prototype.complete = function () {
|
445 | var partialObserver = this.partialObserver;
|
446 | if (partialObserver.complete) {
|
447 | try {
|
448 | partialObserver.complete();
|
449 | }
|
450 | catch (error) {
|
451 | handleUnhandledError(error);
|
452 | }
|
453 | }
|
454 | };
|
455 | return ConsumerObserver;
|
456 | }());
|
457 | var SafeSubscriber = (function (_super) {
|
458 | __extends(SafeSubscriber, _super);
|
459 | function SafeSubscriber(observerOrNext, error, complete) {
|
460 | var _this = _super.call(this) || this;
|
461 | var partialObserver;
|
462 | if (isFunction(observerOrNext) || !observerOrNext) {
|
463 | partialObserver = {
|
464 | next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
|
465 | error: error !== null && error !== void 0 ? error : undefined,
|
466 | complete: complete !== null && complete !== void 0 ? complete : undefined,
|
467 | };
|
468 | }
|
469 | else {
|
470 | var context_1;
|
471 | if (_this && config.useDeprecatedNextContext) {
|
472 | context_1 = Object.create(observerOrNext);
|
473 | context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
474 | partialObserver = {
|
475 | next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
476 | error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
477 | complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
478 | };
|
479 | }
|
480 | else {
|
481 | partialObserver = observerOrNext;
|
482 | }
|
483 | }
|
484 | _this.destination = new ConsumerObserver(partialObserver);
|
485 | return _this;
|
486 | }
|
487 | return SafeSubscriber;
|
488 | }(Subscriber));
|
489 | function handleUnhandledError(error) {
|
490 | {
|
491 | reportUnhandledError(error);
|
492 | }
|
493 | }
|
494 | function defaultErrorHandler(err) {
|
495 | throw err;
|
496 | }
|
497 | var EMPTY_OBSERVER = {
|
498 | closed: true,
|
499 | next: noop,
|
500 | error: defaultErrorHandler,
|
501 | complete: noop,
|
502 | };
|
503 |
|
504 | var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
505 |
|
506 | function identity(x) {
|
507 | return x;
|
508 | }
|
509 |
|
510 | function pipeFromArray(fns) {
|
511 | if (fns.length === 0) {
|
512 | return identity;
|
513 | }
|
514 | if (fns.length === 1) {
|
515 | return fns[0];
|
516 | }
|
517 | return function piped(input) {
|
518 | return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
519 | };
|
520 | }
|
521 |
|
522 | var Observable = (function () {
|
523 | function Observable(subscribe) {
|
524 | if (subscribe) {
|
525 | this._subscribe = subscribe;
|
526 | }
|
527 | }
|
528 | Observable.prototype.lift = function (operator) {
|
529 | var observable = new Observable();
|
530 | observable.source = this;
|
531 | observable.operator = operator;
|
532 | return observable;
|
533 | };
|
534 | Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
535 | var _this = this;
|
536 | var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
537 | errorContext(function () {
|
538 | var _a = _this, operator = _a.operator, source = _a.source;
|
539 | subscriber.add(operator
|
540 | ?
|
541 | operator.call(subscriber, source)
|
542 | : source
|
543 | ?
|
544 | _this._subscribe(subscriber)
|
545 | :
|
546 | _this._trySubscribe(subscriber));
|
547 | });
|
548 | return subscriber;
|
549 | };
|
550 | Observable.prototype._trySubscribe = function (sink) {
|
551 | try {
|
552 | return this._subscribe(sink);
|
553 | }
|
554 | catch (err) {
|
555 | sink.error(err);
|
556 | }
|
557 | };
|
558 | Observable.prototype.forEach = function (next, promiseCtor) {
|
559 | var _this = this;
|
560 | promiseCtor = getPromiseCtor(promiseCtor);
|
561 | return new promiseCtor(function (resolve, reject) {
|
562 | var subscriber = new SafeSubscriber({
|
563 | next: function (value) {
|
564 | try {
|
565 | next(value);
|
566 | }
|
567 | catch (err) {
|
568 | reject(err);
|
569 | subscriber.unsubscribe();
|
570 | }
|
571 | },
|
572 | error: reject,
|
573 | complete: resolve,
|
574 | });
|
575 | _this.subscribe(subscriber);
|
576 | });
|
577 | };
|
578 | Observable.prototype._subscribe = function (subscriber) {
|
579 | var _a;
|
580 | return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
581 | };
|
582 | Observable.prototype[observable] = function () {
|
583 | return this;
|
584 | };
|
585 | Observable.prototype.pipe = function () {
|
586 | var operations = [];
|
587 | for (var _i = 0; _i < arguments.length; _i++) {
|
588 | operations[_i] = arguments[_i];
|
589 | }
|
590 | return pipeFromArray(operations)(this);
|
591 | };
|
592 | Observable.prototype.toPromise = function (promiseCtor) {
|
593 | var _this = this;
|
594 | promiseCtor = getPromiseCtor(promiseCtor);
|
595 | return new promiseCtor(function (resolve, reject) {
|
596 | var value;
|
597 | _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
598 | });
|
599 | };
|
600 | Observable.create = function (subscribe) {
|
601 | return new Observable(subscribe);
|
602 | };
|
603 | return Observable;
|
604 | }());
|
605 | function getPromiseCtor(promiseCtor) {
|
606 | var _a;
|
607 | return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
608 | }
|
609 | function isObserver(value) {
|
610 | return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
611 | }
|
612 | function isSubscriber(value) {
|
613 | return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
614 | }
|
615 |
|
616 | function hasLift(source) {
|
617 | return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
618 | }
|
619 | function operate(init) {
|
620 | return function (source) {
|
621 | if (hasLift(source)) {
|
622 | return source.lift(function (liftedSource) {
|
623 | try {
|
624 | return init(liftedSource, this);
|
625 | }
|
626 | catch (err) {
|
627 | this.error(err);
|
628 | }
|
629 | });
|
630 | }
|
631 | throw new TypeError('Unable to lift unknown Observable type');
|
632 | };
|
633 | }
|
634 |
|
635 | function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
636 | return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
637 | }
|
638 | var OperatorSubscriber = (function (_super) {
|
639 | __extends(OperatorSubscriber, _super);
|
640 | function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
641 | var _this = _super.call(this, destination) || this;
|
642 | _this.onFinalize = onFinalize;
|
643 | _this.shouldUnsubscribe = shouldUnsubscribe;
|
644 | _this._next = onNext
|
645 | ? function (value) {
|
646 | try {
|
647 | onNext(value);
|
648 | }
|
649 | catch (err) {
|
650 | destination.error(err);
|
651 | }
|
652 | }
|
653 | : _super.prototype._next;
|
654 | _this._error = onError
|
655 | ? function (err) {
|
656 | try {
|
657 | onError(err);
|
658 | }
|
659 | catch (err) {
|
660 | destination.error(err);
|
661 | }
|
662 | finally {
|
663 | this.unsubscribe();
|
664 | }
|
665 | }
|
666 | : _super.prototype._error;
|
667 | _this._complete = onComplete
|
668 | ? function () {
|
669 | try {
|
670 | onComplete();
|
671 | }
|
672 | catch (err) {
|
673 | destination.error(err);
|
674 | }
|
675 | finally {
|
676 | this.unsubscribe();
|
677 | }
|
678 | }
|
679 | : _super.prototype._complete;
|
680 | return _this;
|
681 | }
|
682 | OperatorSubscriber.prototype.unsubscribe = function () {
|
683 | var _a;
|
684 | if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
685 | var closed_1 = this.closed;
|
686 | _super.prototype.unsubscribe.call(this);
|
687 | !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
688 | }
|
689 | };
|
690 | return OperatorSubscriber;
|
691 | }(Subscriber));
|
692 |
|
693 | var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
694 | return function ObjectUnsubscribedErrorImpl() {
|
695 | _super(this);
|
696 | this.name = 'ObjectUnsubscribedError';
|
697 | this.message = 'object unsubscribed';
|
698 | };
|
699 | });
|
700 |
|
701 | var Subject = (function (_super) {
|
702 | __extends(Subject, _super);
|
703 | function Subject() {
|
704 | var _this = _super.call(this) || this;
|
705 | _this.closed = false;
|
706 | _this.observers = [];
|
707 | _this.isStopped = false;
|
708 | _this.hasError = false;
|
709 | _this.thrownError = null;
|
710 | return _this;
|
711 | }
|
712 | Subject.prototype.lift = function (operator) {
|
713 | var subject = new AnonymousSubject(this, this);
|
714 | subject.operator = operator;
|
715 | return subject;
|
716 | };
|
717 | Subject.prototype._throwIfClosed = function () {
|
718 | if (this.closed) {
|
719 | throw new ObjectUnsubscribedError();
|
720 | }
|
721 | };
|
722 | Subject.prototype.next = function (value) {
|
723 | var _this = this;
|
724 | errorContext(function () {
|
725 | var e_1, _a;
|
726 | _this._throwIfClosed();
|
727 | if (!_this.isStopped) {
|
728 | var copy = _this.observers.slice();
|
729 | try {
|
730 | for (var copy_1 = __values(copy), copy_1_1 = copy_1.next(); !copy_1_1.done; copy_1_1 = copy_1.next()) {
|
731 | var observer = copy_1_1.value;
|
732 | observer.next(value);
|
733 | }
|
734 | }
|
735 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
736 | finally {
|
737 | try {
|
738 | if (copy_1_1 && !copy_1_1.done && (_a = copy_1.return)) _a.call(copy_1);
|
739 | }
|
740 | finally { if (e_1) throw e_1.error; }
|
741 | }
|
742 | }
|
743 | });
|
744 | };
|
745 | Subject.prototype.error = function (err) {
|
746 | var _this = this;
|
747 | errorContext(function () {
|
748 | _this._throwIfClosed();
|
749 | if (!_this.isStopped) {
|
750 | _this.hasError = _this.isStopped = true;
|
751 | _this.thrownError = err;
|
752 | var observers = _this.observers;
|
753 | while (observers.length) {
|
754 | observers.shift().error(err);
|
755 | }
|
756 | }
|
757 | });
|
758 | };
|
759 | Subject.prototype.complete = function () {
|
760 | var _this = this;
|
761 | errorContext(function () {
|
762 | _this._throwIfClosed();
|
763 | if (!_this.isStopped) {
|
764 | _this.isStopped = true;
|
765 | var observers = _this.observers;
|
766 | while (observers.length) {
|
767 | observers.shift().complete();
|
768 | }
|
769 | }
|
770 | });
|
771 | };
|
772 | Subject.prototype.unsubscribe = function () {
|
773 | this.isStopped = this.closed = true;
|
774 | this.observers = null;
|
775 | };
|
776 | Object.defineProperty(Subject.prototype, "observed", {
|
777 | get: function () {
|
778 | var _a;
|
779 | return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
780 | },
|
781 | enumerable: false,
|
782 | configurable: true
|
783 | });
|
784 | Subject.prototype._trySubscribe = function (subscriber) {
|
785 | this._throwIfClosed();
|
786 | return _super.prototype._trySubscribe.call(this, subscriber);
|
787 | };
|
788 | Subject.prototype._subscribe = function (subscriber) {
|
789 | this._throwIfClosed();
|
790 | this._checkFinalizedStatuses(subscriber);
|
791 | return this._innerSubscribe(subscriber);
|
792 | };
|
793 | Subject.prototype._innerSubscribe = function (subscriber) {
|
794 | var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
795 | return hasError || isStopped
|
796 | ? EMPTY_SUBSCRIPTION
|
797 | : (observers.push(subscriber), new Subscription(function () { return arrRemove(observers, subscriber); }));
|
798 | };
|
799 | Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
800 | var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
801 | if (hasError) {
|
802 | subscriber.error(thrownError);
|
803 | }
|
804 | else if (isStopped) {
|
805 | subscriber.complete();
|
806 | }
|
807 | };
|
808 | Subject.prototype.asObservable = function () {
|
809 | var observable = new Observable();
|
810 | observable.source = this;
|
811 | return observable;
|
812 | };
|
813 | Subject.create = function (destination, source) {
|
814 | return new AnonymousSubject(destination, source);
|
815 | };
|
816 | return Subject;
|
817 | }(Observable));
|
818 | var AnonymousSubject = (function (_super) {
|
819 | __extends(AnonymousSubject, _super);
|
820 | function AnonymousSubject(destination, source) {
|
821 | var _this = _super.call(this) || this;
|
822 | _this.destination = destination;
|
823 | _this.source = source;
|
824 | return _this;
|
825 | }
|
826 | AnonymousSubject.prototype.next = function (value) {
|
827 | var _a, _b;
|
828 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
829 | };
|
830 | AnonymousSubject.prototype.error = function (err) {
|
831 | var _a, _b;
|
832 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
833 | };
|
834 | AnonymousSubject.prototype.complete = function () {
|
835 | var _a, _b;
|
836 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
837 | };
|
838 | AnonymousSubject.prototype._subscribe = function (subscriber) {
|
839 | var _a, _b;
|
840 | return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
841 | };
|
842 | return AnonymousSubject;
|
843 | }(Subject));
|
844 |
|
845 | var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
846 |
|
847 | function isPromise(value) {
|
848 | return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
849 | }
|
850 |
|
851 | function isInteropObservable(input) {
|
852 | return isFunction(input[observable]);
|
853 | }
|
854 |
|
855 | function isAsyncIterable(obj) {
|
856 | return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
857 | }
|
858 |
|
859 | function createInvalidObservableTypeError(input) {
|
860 | return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
861 | }
|
862 |
|
863 | function getSymbolIterator() {
|
864 | if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
865 | return '@@iterator';
|
866 | }
|
867 | return Symbol.iterator;
|
868 | }
|
869 | var iterator = getSymbolIterator();
|
870 |
|
871 | function isIterable(input) {
|
872 | return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
873 | }
|
874 |
|
875 | function readableStreamLikeToAsyncGenerator(readableStream) {
|
876 | return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
877 | var reader, _a, value, done;
|
878 | return __generator(this, function (_b) {
|
879 | switch (_b.label) {
|
880 | case 0:
|
881 | reader = readableStream.getReader();
|
882 | _b.label = 1;
|
883 | case 1:
|
884 | _b.trys.push([1, , 9, 10]);
|
885 | _b.label = 2;
|
886 | case 2:
|
887 | return [4, __await(reader.read())];
|
888 | case 3:
|
889 | _a = _b.sent(), value = _a.value, done = _a.done;
|
890 | if (!done) return [3, 5];
|
891 | return [4, __await(void 0)];
|
892 | case 4: return [2, _b.sent()];
|
893 | case 5: return [4, __await(value)];
|
894 | case 6: return [4, _b.sent()];
|
895 | case 7:
|
896 | _b.sent();
|
897 | return [3, 2];
|
898 | case 8: return [3, 10];
|
899 | case 9:
|
900 | reader.releaseLock();
|
901 | return [7];
|
902 | case 10: return [2];
|
903 | }
|
904 | });
|
905 | });
|
906 | }
|
907 | function isReadableStreamLike(obj) {
|
908 | return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
909 | }
|
910 |
|
911 | function innerFrom(input) {
|
912 | if (input instanceof Observable) {
|
913 | return input;
|
914 | }
|
915 | if (input != null) {
|
916 | if (isInteropObservable(input)) {
|
917 | return fromInteropObservable(input);
|
918 | }
|
919 | if (isArrayLike(input)) {
|
920 | return fromArrayLike(input);
|
921 | }
|
922 | if (isPromise(input)) {
|
923 | return fromPromise(input);
|
924 | }
|
925 | if (isAsyncIterable(input)) {
|
926 | return fromAsyncIterable(input);
|
927 | }
|
928 | if (isIterable(input)) {
|
929 | return fromIterable(input);
|
930 | }
|
931 | if (isReadableStreamLike(input)) {
|
932 | return fromReadableStreamLike(input);
|
933 | }
|
934 | }
|
935 | throw createInvalidObservableTypeError(input);
|
936 | }
|
937 | function fromInteropObservable(obj) {
|
938 | return new Observable(function (subscriber) {
|
939 | var obs = obj[observable]();
|
940 | if (isFunction(obs.subscribe)) {
|
941 | return obs.subscribe(subscriber);
|
942 | }
|
943 | throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
944 | });
|
945 | }
|
946 | function fromArrayLike(array) {
|
947 | return new Observable(function (subscriber) {
|
948 | for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
949 | subscriber.next(array[i]);
|
950 | }
|
951 | subscriber.complete();
|
952 | });
|
953 | }
|
954 | function fromPromise(promise) {
|
955 | return new Observable(function (subscriber) {
|
956 | promise
|
957 | .then(function (value) {
|
958 | if (!subscriber.closed) {
|
959 | subscriber.next(value);
|
960 | subscriber.complete();
|
961 | }
|
962 | }, function (err) { return subscriber.error(err); })
|
963 | .then(null, reportUnhandledError);
|
964 | });
|
965 | }
|
966 | function fromIterable(iterable) {
|
967 | return new Observable(function (subscriber) {
|
968 | var e_1, _a;
|
969 | try {
|
970 | for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
971 | var value = iterable_1_1.value;
|
972 | subscriber.next(value);
|
973 | if (subscriber.closed) {
|
974 | return;
|
975 | }
|
976 | }
|
977 | }
|
978 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
979 | finally {
|
980 | try {
|
981 | if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
982 | }
|
983 | finally { if (e_1) throw e_1.error; }
|
984 | }
|
985 | subscriber.complete();
|
986 | });
|
987 | }
|
988 | function fromAsyncIterable(asyncIterable) {
|
989 | return new Observable(function (subscriber) {
|
990 | process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
991 | });
|
992 | }
|
993 | function fromReadableStreamLike(readableStream) {
|
994 | return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
995 | }
|
996 | function process(asyncIterable, subscriber) {
|
997 | var asyncIterable_1, asyncIterable_1_1;
|
998 | var e_2, _a;
|
999 | return __awaiter(this, void 0, void 0, function () {
|
1000 | var value, e_2_1;
|
1001 | return __generator(this, function (_b) {
|
1002 | switch (_b.label) {
|
1003 | case 0:
|
1004 | _b.trys.push([0, 5, 6, 11]);
|
1005 | asyncIterable_1 = __asyncValues(asyncIterable);
|
1006 | _b.label = 1;
|
1007 | case 1: return [4, asyncIterable_1.next()];
|
1008 | case 2:
|
1009 | if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
1010 | value = asyncIterable_1_1.value;
|
1011 | subscriber.next(value);
|
1012 | if (subscriber.closed) {
|
1013 | return [2];
|
1014 | }
|
1015 | _b.label = 3;
|
1016 | case 3: return [3, 1];
|
1017 | case 4: return [3, 11];
|
1018 | case 5:
|
1019 | e_2_1 = _b.sent();
|
1020 | e_2 = { error: e_2_1 };
|
1021 | return [3, 11];
|
1022 | case 6:
|
1023 | _b.trys.push([6, , 9, 10]);
|
1024 | if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
1025 | return [4, _a.call(asyncIterable_1)];
|
1026 | case 7:
|
1027 | _b.sent();
|
1028 | _b.label = 8;
|
1029 | case 8: return [3, 10];
|
1030 | case 9:
|
1031 | if (e_2) throw e_2.error;
|
1032 | return [7];
|
1033 | case 10: return [7];
|
1034 | case 11:
|
1035 | subscriber.complete();
|
1036 | return [2];
|
1037 | }
|
1038 | });
|
1039 | });
|
1040 | }
|
1041 |
|
1042 | function takeUntil(notifier) {
|
1043 | return operate(function (source, subscriber) {
|
1044 | innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function () { return subscriber.complete(); }, noop));
|
1045 | !subscriber.closed && source.subscribe(subscriber);
|
1046 | });
|
1047 | }
|
1048 |
|
1049 | var entityId = 0;
|
1050 | |
1051 |
|
1052 |
|
1053 | var Entity = (function () {
|
1054 | function Entity() {
|
1055 | this._componentAddedSubject$ = new Subject();
|
1056 | this._componentRemovedSubject$ = new Subject();
|
1057 | this._componentMap = new Map();
|
1058 | this.id = entityId++;
|
1059 | }
|
1060 | |
1061 |
|
1062 |
|
1063 |
|
1064 | Entity.prototype.hasComponent = function (componentName) {
|
1065 | return this._componentMap.has(componentName);
|
1066 | };
|
1067 | |
1068 |
|
1069 |
|
1070 |
|
1071 | Entity.prototype.getComponent = function (componentName) {
|
1072 | var component = this._componentMap.get(componentName);
|
1073 | if (typeof component !== 'undefined') {
|
1074 | return component;
|
1075 | }
|
1076 | return undefined;
|
1077 | };
|
1078 | |
1079 |
|
1080 |
|
1081 |
|
1082 | Entity.prototype.addComponent = function (component) {
|
1083 | this._componentMap.set(component.name, component);
|
1084 | this._componentAddedSubject$.next(component);
|
1085 | return this;
|
1086 | };
|
1087 | |
1088 |
|
1089 |
|
1090 |
|
1091 | Entity.prototype.removeComponent = function (componentName) {
|
1092 | var component = this._componentMap.get(componentName);
|
1093 | if (typeof component !== 'undefined') {
|
1094 | this._componentMap.delete(componentName);
|
1095 | this._componentRemovedSubject$.next(component);
|
1096 | }
|
1097 | return this;
|
1098 | };
|
1099 | Object.defineProperty(Entity.prototype, "componentAdded$", {
|
1100 | |
1101 |
|
1102 |
|
1103 |
|
1104 | get: function () {
|
1105 | return this._componentAddedSubject$.asObservable();
|
1106 | },
|
1107 | enumerable: false,
|
1108 | configurable: true
|
1109 | });
|
1110 | Object.defineProperty(Entity.prototype, "componentRemoved$", {
|
1111 | |
1112 |
|
1113 |
|
1114 |
|
1115 | get: function () {
|
1116 | return this._componentRemovedSubject$.asObservable();
|
1117 | },
|
1118 | enumerable: false,
|
1119 | configurable: true
|
1120 | });
|
1121 | return Entity;
|
1122 | }());
|
1123 |
|
1124 | |
1125 |
|
1126 |
|
1127 | var System = (function () {
|
1128 | function System() {
|
1129 | }
|
1130 | |
1131 |
|
1132 |
|
1133 |
|
1134 | System.prototype.addedToWorld = function (world) {
|
1135 | this._world = world;
|
1136 | };
|
1137 | |
1138 |
|
1139 |
|
1140 |
|
1141 | System.prototype.removedFromWorld = function (world) {
|
1142 | this._world = undefined;
|
1143 | };
|
1144 | |
1145 |
|
1146 |
|
1147 |
|
1148 | System.prototype.update = function (tickerData) {
|
1149 |
|
1150 | };
|
1151 | Object.defineProperty(System.prototype, "world", {
|
1152 | |
1153 |
|
1154 |
|
1155 | get: function () {
|
1156 | if (!this._world) {
|
1157 | throw Error('wait till the system is added to the world');
|
1158 | }
|
1159 | return this._world;
|
1160 | },
|
1161 | enumerable: false,
|
1162 | configurable: true
|
1163 | });
|
1164 | return System;
|
1165 | }());
|
1166 |
|
1167 | var EntityNode = (function () {
|
1168 | function EntityNode(entity) {
|
1169 | this.prev = null;
|
1170 | this.next = null;
|
1171 | this.entity = entity;
|
1172 | }
|
1173 | return EntityNode;
|
1174 | }());
|
1175 |
|
1176 | |
1177 |
|
1178 |
|
1179 |
|
1180 | var EntityList = (function () {
|
1181 | function EntityList() {
|
1182 | this.length = 0;
|
1183 | this.head = null;
|
1184 | this.tail = null;
|
1185 | this._entityMap = new Map();
|
1186 |
|
1187 | }
|
1188 | |
1189 |
|
1190 |
|
1191 |
|
1192 | EntityList.prototype.add = function (entity) {
|
1193 | var node = new EntityNode(entity);
|
1194 | if (this.head === null) {
|
1195 | this.head = this.tail = node;
|
1196 | }
|
1197 | else {
|
1198 | node.prev = this.tail;
|
1199 | if (this.tail) {
|
1200 | this.tail.next = node;
|
1201 | }
|
1202 | this.tail = node;
|
1203 | }
|
1204 | this.length += 1;
|
1205 | this._entityMap.set(entity.id, node);
|
1206 | };
|
1207 | |
1208 |
|
1209 |
|
1210 |
|
1211 | EntityList.prototype.remove = function (entity) {
|
1212 | var entityId = entity.id;
|
1213 | var node = this._entityMap.get(entityId);
|
1214 | if (typeof node === 'undefined') {
|
1215 | return;
|
1216 | }
|
1217 | if (node.prev === null) {
|
1218 | this.head = node.next;
|
1219 | }
|
1220 | else {
|
1221 | node.prev.next = node.next;
|
1222 | }
|
1223 | if (node.next === null) {
|
1224 | this.tail = node.prev;
|
1225 | }
|
1226 | else {
|
1227 | node.next.prev = node.prev;
|
1228 | }
|
1229 | this.length -= 1;
|
1230 | this._entityMap.delete(entityId);
|
1231 | };
|
1232 | |
1233 |
|
1234 |
|
1235 |
|
1236 | EntityList.prototype.has = function (entity) {
|
1237 | return this._entityMap.has(entity.id);
|
1238 | };
|
1239 | |
1240 |
|
1241 |
|
1242 | EntityList.prototype.clear = function () {
|
1243 | this.head = this.tail = null;
|
1244 | this.length = 0;
|
1245 | this._entityMap.clear();
|
1246 | };
|
1247 | |
1248 |
|
1249 |
|
1250 | EntityList.prototype.toArray = function () {
|
1251 | var array = [], node;
|
1252 | for (node = this.head; node; node = node.next) {
|
1253 | array.push(node.entity);
|
1254 | }
|
1255 | return array;
|
1256 | };
|
1257 | return EntityList;
|
1258 | }());
|
1259 |
|
1260 | var Family = (function () {
|
1261 | function Family(componentNames) {
|
1262 | this._entityAddedSubject$ = new Subject();
|
1263 | this._entityRemovedSubject$ = new Subject();
|
1264 | this._entities = new EntityList();
|
1265 | this._componentNames = componentNames;
|
1266 | }
|
1267 | |
1268 |
|
1269 |
|
1270 | Family.prototype.getEntities = function () {
|
1271 | return this._entities.toArray();
|
1272 | };
|
1273 | |
1274 |
|
1275 |
|
1276 |
|
1277 | Family.prototype.addEntityIfMatch = function (entity) {
|
1278 | if (!this._entities.has(entity) && this.matchEntity(entity)) {
|
1279 | this._entities.add(entity);
|
1280 | this._entityAddedSubject$.next(entity);
|
1281 | }
|
1282 | };
|
1283 | |
1284 |
|
1285 |
|
1286 |
|
1287 | Family.prototype.removeEntity = function (entity) {
|
1288 | if (this._entities.has(entity)) {
|
1289 | this._entities.remove(entity);
|
1290 | this._entityRemovedSubject$.next(entity);
|
1291 | }
|
1292 | };
|
1293 | Family.prototype.onComponentAdded = function (entity, component) {
|
1294 | this.addEntityIfMatch(entity);
|
1295 | };
|
1296 | Family.prototype.onComponentRemoved = function (entity, component) {
|
1297 |
|
1298 | if (!this._entities.has(entity)) {
|
1299 | return;
|
1300 | }
|
1301 |
|
1302 | var names = this._componentNames;
|
1303 | var len = names.length;
|
1304 | for (var i = 0; i < len; ++i) {
|
1305 | if (names[i] === component.name) {
|
1306 | this._entities.remove(entity);
|
1307 | this._entityRemovedSubject$.next(entity);
|
1308 | }
|
1309 | }
|
1310 | };
|
1311 | Object.defineProperty(Family.prototype, "entityAdded$", {
|
1312 | |
1313 |
|
1314 |
|
1315 | get: function () {
|
1316 | return this._entityAddedSubject$.asObservable();
|
1317 | },
|
1318 | enumerable: false,
|
1319 | configurable: true
|
1320 | });
|
1321 | Object.defineProperty(Family.prototype, "entityRemoved$", {
|
1322 | |
1323 |
|
1324 |
|
1325 | get: function () {
|
1326 | return this._entityRemovedSubject$.asObservable();
|
1327 | },
|
1328 | enumerable: false,
|
1329 | configurable: true
|
1330 | });
|
1331 | Family.prototype.matchEntity = function (entity) {
|
1332 | var componentNames = this._componentNames;
|
1333 | var len = componentNames.length;
|
1334 | for (var i = 0; i < len; ++i) {
|
1335 | if (!entity.hasComponent(componentNames[i])) {
|
1336 | return false;
|
1337 | }
|
1338 | }
|
1339 | return true;
|
1340 | };
|
1341 | return Family;
|
1342 | }());
|
1343 |
|
1344 | var World = (function () {
|
1345 | function World() {
|
1346 | this._systems = [];
|
1347 | this._entities = new EntityList();
|
1348 | this._families = new Map();
|
1349 | this._disposeEntityMap = new Map();
|
1350 |
|
1351 | }
|
1352 | |
1353 |
|
1354 |
|
1355 |
|
1356 | World.prototype.addSystem = function (system) {
|
1357 | this._systems.push(system);
|
1358 | system.addedToWorld(this);
|
1359 | return this;
|
1360 | };
|
1361 | |
1362 |
|
1363 |
|
1364 |
|
1365 | World.prototype.removeSystem = function (system) {
|
1366 | var systems = this._systems;
|
1367 | var len = systems.length;
|
1368 | for (var i = 0; i < len; ++i) {
|
1369 | if (systems[i] === system) {
|
1370 | systems.splice(i, 1);
|
1371 | system.removedFromWorld(this);
|
1372 | }
|
1373 | }
|
1374 | return this;
|
1375 | };
|
1376 | |
1377 |
|
1378 |
|
1379 | World.prototype.removeAllSystems = function () {
|
1380 | var _this = this;
|
1381 | this._systems.forEach(function (system) { return system.removedFromWorld(_this); });
|
1382 | this._systems.length = 0;
|
1383 | return this;
|
1384 | };
|
1385 | |
1386 |
|
1387 |
|
1388 |
|
1389 | World.prototype.addEntity = function (entity) {
|
1390 | var _this = this;
|
1391 |
|
1392 | this._families.forEach(function (family) { return family.addEntityIfMatch(entity); });
|
1393 | var dispose$ = new Subject();
|
1394 | this._disposeEntityMap.set(entity, dispose$);
|
1395 |
|
1396 |
|
1397 | var componentAdded$ = entity.componentAdded$, componentRemoved$ = entity.componentRemoved$;
|
1398 | componentAdded$.pipe(takeUntil(dispose$)).subscribe(function (component) { return _this.onComponentAdded(entity, component); });
|
1399 | componentRemoved$.pipe(takeUntil(dispose$)).subscribe(function (component) { return _this.onComponentRemoved(entity, component); });
|
1400 | this._entities.add(entity);
|
1401 | return this;
|
1402 | };
|
1403 | |
1404 |
|
1405 |
|
1406 |
|
1407 | World.prototype.removeEntity = function (entity) {
|
1408 | this._families.forEach(function (family) { return family.removeEntity(entity); });
|
1409 | this._entities.remove(entity);
|
1410 | var dispose$ = this._disposeEntityMap.get(entity);
|
1411 | if (typeof dispose$ !== 'undefined') {
|
1412 | dispose$.next();
|
1413 | this._disposeEntityMap.delete(entity);
|
1414 | }
|
1415 | return this;
|
1416 | };
|
1417 | |
1418 |
|
1419 |
|
1420 | World.prototype.removeAllEntities = function () {
|
1421 | var _this = this;
|
1422 | this._entities.toArray().forEach(function (entity) { return _this.removeEntity(entity); });
|
1423 | return this;
|
1424 | };
|
1425 | |
1426 |
|
1427 |
|
1428 |
|
1429 | World.prototype.getEntities = function (componentNames) {
|
1430 | var familyId = this.generateFamilyId(componentNames);
|
1431 | this.ensureFamilyExists(componentNames, familyId);
|
1432 | var family = this._families.get(familyId);
|
1433 | if (typeof family !== 'undefined') {
|
1434 | return family.getEntities();
|
1435 | }
|
1436 | throw Error("unable to getEntities, " + componentNames);
|
1437 | };
|
1438 | |
1439 |
|
1440 |
|
1441 |
|
1442 | World.prototype.update = function (tickerData) {
|
1443 | var systems = this._systems;
|
1444 | var len = systems.length;
|
1445 | for (var i = 0; i < len; ++i) {
|
1446 | systems[i].update(tickerData);
|
1447 | }
|
1448 | };
|
1449 | |
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 | World.prototype.entityAdded$ = function (componentNames) {
|
1457 | var familyId = this.generateFamilyId(componentNames);
|
1458 | this.ensureFamilyExists(componentNames, familyId);
|
1459 | var family = this._families.get(familyId);
|
1460 | if (typeof family !== 'undefined') {
|
1461 | return family.entityAdded$;
|
1462 | }
|
1463 | throw Error("unable to perform entityAdded, " + componentNames);
|
1464 | };
|
1465 | |
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 | World.prototype.entityRemoved$ = function (componentNames) {
|
1473 | var familyId = this.generateFamilyId(componentNames);
|
1474 | this.ensureFamilyExists(componentNames, familyId);
|
1475 | var family = this._families.get(familyId);
|
1476 | if (typeof family !== 'undefined') {
|
1477 | return family.entityRemoved$;
|
1478 | }
|
1479 | throw Error("unable to perform entityRemoved, " + componentNames);
|
1480 | };
|
1481 | World.prototype.generateFamilyId = function (componentNames) {
|
1482 | var keys = componentNames.map(function (data) { return data.toString(); });
|
1483 | return "$-" + keys.join(',');
|
1484 | };
|
1485 | World.prototype.ensureFamilyExists = function (componentNames, familyId) {
|
1486 | var families = this._families;
|
1487 | if (families.has(familyId)) {
|
1488 | return;
|
1489 | }
|
1490 | var family = new Family(__spreadArray([], componentNames));
|
1491 | families.set(familyId, family);
|
1492 | for (var node = this._entities.head; node; node = node.next) {
|
1493 | var family_1 = families.get(familyId);
|
1494 | if (typeof family_1 !== 'undefined') {
|
1495 | family_1.addEntityIfMatch(node.entity);
|
1496 | }
|
1497 | }
|
1498 | };
|
1499 | World.prototype.onComponentAdded = function (entity, component) {
|
1500 | this._families.forEach(function (family) { return family.onComponentAdded(entity, component); });
|
1501 | };
|
1502 | World.prototype.onComponentRemoved = function (entity, component) {
|
1503 | this._families.forEach(function (family) { return family.onComponentRemoved(entity, component); });
|
1504 | };
|
1505 | return World;
|
1506 | }());
|
1507 |
|
1508 | exports.Entity = Entity;
|
1509 | exports.System = System;
|
1510 | exports.World = World;
|
1511 |
|
1512 | Object.defineProperty(exports, '__esModule', { value: true });
|
1513 |
|
1514 | })));
|
1515 |
|