@safe-engine/pixi 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.github/workflows/npm-publish.yml +35 -0
  2. package/README.md +4 -0
  3. package/dist/app.d.ts +9 -0
  4. package/dist/app.d.ts.map +1 -0
  5. package/dist/app.js +102 -0
  6. package/dist/components/EnhancedComponent.d.ts +22 -0
  7. package/dist/components/EnhancedComponent.d.ts.map +1 -0
  8. package/dist/components/EnhancedComponent.js +62 -0
  9. package/dist/components/GUIComponent.d.ts +72 -0
  10. package/dist/components/GUIComponent.d.ts.map +1 -0
  11. package/dist/components/GUIComponent.js +178 -0
  12. package/dist/components/NodeComp.d.ts +104 -0
  13. package/dist/components/NodeComp.d.ts.map +1 -0
  14. package/dist/components/NodeComp.js +420 -0
  15. package/dist/components/RenderComponent.d.ts +29 -0
  16. package/dist/components/RenderComponent.d.ts.map +1 -0
  17. package/dist/components/RenderComponent.js +89 -0
  18. package/dist/core/Color.d.ts +7 -0
  19. package/dist/core/Color.d.ts.map +1 -0
  20. package/dist/core/Color.js +6 -0
  21. package/dist/core/LoadingBar.d.ts +13 -0
  22. package/dist/core/LoadingBar.d.ts.map +1 -0
  23. package/dist/core/LoadingBar.js +55 -0
  24. package/dist/core/Scene.d.ts +6 -0
  25. package/dist/core/Scene.d.ts.map +1 -0
  26. package/dist/core/Scene.js +39 -0
  27. package/dist/core/Size.d.ts +10 -0
  28. package/dist/core/Size.d.ts.map +1 -0
  29. package/dist/core/Size.js +22 -0
  30. package/dist/core/Vec2.d.ts +20 -0
  31. package/dist/core/Vec2.d.ts.map +1 -0
  32. package/dist/core/Vec2.js +70 -0
  33. package/dist/core/decorator.d.ts +9 -0
  34. package/dist/core/decorator.d.ts.map +1 -0
  35. package/dist/core/decorator.js +46 -0
  36. package/dist/gworld.d.ts +8 -0
  37. package/dist/gworld.d.ts.map +1 -0
  38. package/dist/gworld.js +43 -0
  39. package/dist/helper/html-text-parser.d.ts +30 -0
  40. package/dist/helper/html-text-parser.d.ts.map +1 -0
  41. package/dist/helper/html-text-parser.js +353 -0
  42. package/dist/helper/utils.d.ts +17 -0
  43. package/dist/helper/utils.d.ts.map +1 -0
  44. package/dist/helper/utils.js +64 -0
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +39 -0
  48. package/dist/systems/GUISystem.d.ts +7 -0
  49. package/dist/systems/GUISystem.d.ts.map +1 -0
  50. package/dist/systems/GUISystem.js +94 -0
  51. package/dist/systems/RenderSystem.d.ts +15 -0
  52. package/dist/systems/RenderSystem.d.ts.map +1 -0
  53. package/dist/systems/RenderSystem.js +100 -0
  54. package/package.json +30 -0
  55. package/src/app.ts +51 -0
  56. package/src/components/EnhancedComponent.ts +57 -0
  57. package/src/components/GUIComponent.ts +147 -0
  58. package/src/components/NodeComp.ts +409 -0
  59. package/src/components/RenderComponent.ts +65 -0
  60. package/src/core/Color.ts +3 -0
  61. package/src/core/LoadingBar.ts +33 -0
  62. package/src/core/Scene.ts +17 -0
  63. package/src/core/Size.ts +21 -0
  64. package/src/core/Vec2.ts +52 -0
  65. package/src/core/decorator.ts +18 -0
  66. package/src/gworld.ts +17 -0
  67. package/src/helper/html-text-parser.ts +364 -0
  68. package/src/helper/utils.ts +64 -0
  69. package/src/index.ts +10 -0
  70. package/src/systems/GUISystem.ts +95 -0
  71. package/src/systems/RenderSystem.ts +100 -0
  72. package/tsconfig.json +24 -0
@@ -0,0 +1,10 @@
1
+ declare class _Size {
2
+ width: number;
3
+ height: number;
4
+ static ZERO: any;
5
+ constructor(width?: number, height?: number);
6
+ }
7
+ export type Size = _Size;
8
+ export declare function Size(x?: number, y?: number): Size;
9
+ export {};
10
+ //# sourceMappingURL=Size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Size.d.ts","sourceRoot":"","sources":["../../src/core/Size.ts"],"names":[],"mappings":"AAAA,cAAM,KAAK;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,IAAI,MAAA;gBACC,KAAK,SAAI,EAAE,MAAM,SAAI;CAWlC;AAED,MAAM,MAAM,IAAI,GAAG,KAAK,CAAA;AACxB,wBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAEjD"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Size = Size;
4
+ var _Size = /** @class */ (function () {
5
+ function _Size(width, height) {
6
+ if (width === void 0) { width = 0; }
7
+ if (height === void 0) { height = 0; }
8
+ if (!(this instanceof _Size)) {
9
+ return new _Size(width, height);
10
+ }
11
+ if (height === undefined) {
12
+ this.width = width.width;
13
+ this.height = width.height;
14
+ }
15
+ this.width = width;
16
+ this.height = height;
17
+ }
18
+ return _Size;
19
+ }());
20
+ function Size(x, y) {
21
+ return new _Size(x, y);
22
+ }
@@ -0,0 +1,20 @@
1
+ import { Point } from 'pixi.js';
2
+ declare class _Vec2 extends Point {
3
+ x: number;
4
+ y: number;
5
+ static ZERO: any;
6
+ equals(other: Point): boolean;
7
+ addSelf(value: Point): Point;
8
+ cross(other: Vec2): number;
9
+ signAngle(other: Vec2): number;
10
+ lengthSqr(): number;
11
+ dot(other: Vec2): number;
12
+ angle(other: Vec2): number;
13
+ }
14
+ export type Vec2 = _Vec2;
15
+ export declare function Vec2(x?: number, y?: number): Vec2;
16
+ export declare namespace Vec2 {
17
+ var ZERO: Readonly<_Vec2>;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=Vec2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vec2.d.ts","sourceRoot":"","sources":["../../src/core/Vec2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,cAAM,KAAM,SAAQ,KAAK;IACvB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,CAAC,IAAI,MAAA;IAEX,MAAM,CAAC,KAAK,EAAE,KAAK;IAInB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAOrB,KAAK,CAAC,KAAK,EAAE,IAAI;IAGjB,SAAS,CAAC,KAAK,EAAE,IAAI;IAIrB,SAAS;IAGT,GAAG,CAAC,KAAK,EAAE,IAAI;IAGf,KAAK,CAAC,KAAK,EAAE,IAAI;CAczB;AACD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAA;AACxB,wBAAgB,IAAI,CAAC,CAAC,SAAI,EAAE,CAAC,SAAI,GAAG,IAAI,CAEvC;yBAFe,IAAI"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Vec2 = Vec2;
22
+ var clamp_1 = __importDefault(require("lodash/clamp"));
23
+ var pixi_js_1 = require("pixi.js");
24
+ var _Vec2 = /** @class */ (function (_super) {
25
+ __extends(_Vec2, _super);
26
+ function _Vec2() {
27
+ return _super !== null && _super.apply(this, arguments) || this;
28
+ }
29
+ _Vec2.prototype.equals = function (other) {
30
+ return this.x === other.x && this.y === other.y;
31
+ };
32
+ _Vec2.prototype.addSelf = function (value) {
33
+ var nor = value.add(new pixi_js_1.Point(this.x, this.y));
34
+ this.x = nor.x;
35
+ this.y = nor.y;
36
+ return nor;
37
+ };
38
+ _Vec2.prototype.cross = function (other) {
39
+ return this.x * other.y - this.y * other.x;
40
+ };
41
+ _Vec2.prototype.signAngle = function (other) {
42
+ var angle = this.angle(other);
43
+ return this.cross(other) < 0 ? -angle : angle;
44
+ };
45
+ _Vec2.prototype.lengthSqr = function () {
46
+ return this.x * this.x + this.y * this.y;
47
+ };
48
+ _Vec2.prototype.dot = function (other) {
49
+ return this.x * other.x + this.y * other.y;
50
+ };
51
+ _Vec2.prototype.angle = function (other) {
52
+ var magSqr1 = this.lengthSqr();
53
+ var magSqr2 = other.lengthSqr();
54
+ if (magSqr1 === 0 || magSqr2 === 0) {
55
+ console.warn('Cant get angle between zero vector');
56
+ return 0.0;
57
+ }
58
+ var dot = this.dot(other);
59
+ var theta = dot / Math.sqrt(magSqr1 * magSqr2);
60
+ theta = (0, clamp_1.default)(theta, -1.0, 1.0);
61
+ return Math.acos(theta);
62
+ };
63
+ return _Vec2;
64
+ }(pixi_js_1.Point));
65
+ function Vec2(x, y) {
66
+ if (x === void 0) { x = 0; }
67
+ if (y === void 0) { y = 0; }
68
+ return new _Vec2(x, y);
69
+ }
70
+ Vec2.ZERO = Object.freeze(Vec2(0, 0));
@@ -0,0 +1,9 @@
1
+ import { EnhancedComponent } from '../components/EnhancedComponent';
2
+ export declare class NoRenderComponentX extends EnhancedComponent {
3
+ static hasRender: boolean;
4
+ static create(data?: any): NoRenderComponentX;
5
+ }
6
+ export declare class ComponentX extends EnhancedComponent {
7
+ static create(data?: any): ComponentX;
8
+ }
9
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/core/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE,qBAAa,kBAAmB,SAAQ,iBAAiB;IACvD,MAAM,CAAC,SAAS,UAAQ;IACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG;CAGzB;AAED,qBAAa,UAAW,SAAQ,iBAAiB;IAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG;CAMzB"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ComponentX = exports.NoRenderComponentX = void 0;
19
+ var EnhancedComponent_1 = require("../components/EnhancedComponent");
20
+ var gworld_1 = require("../gworld");
21
+ var NoRenderComponentX = /** @class */ (function (_super) {
22
+ __extends(NoRenderComponentX, _super);
23
+ function NoRenderComponentX() {
24
+ return _super !== null && _super.apply(this, arguments) || this;
25
+ }
26
+ NoRenderComponentX.create = function (data) {
27
+ return new this(data);
28
+ };
29
+ NoRenderComponentX.hasRender = false;
30
+ return NoRenderComponentX;
31
+ }(EnhancedComponent_1.EnhancedComponent));
32
+ exports.NoRenderComponentX = NoRenderComponentX;
33
+ var ComponentX = /** @class */ (function (_super) {
34
+ __extends(ComponentX, _super);
35
+ function ComponentX() {
36
+ return _super !== null && _super.apply(this, arguments) || this;
37
+ }
38
+ ComponentX.create = function (data) {
39
+ var world = gworld_1.GameWorld.Instance;
40
+ var root = world.entities.create();
41
+ var comp = root.assign(new this(data));
42
+ return comp;
43
+ };
44
+ return ComponentX;
45
+ }(EnhancedComponent_1.EnhancedComponent));
46
+ exports.ComponentX = ComponentX;
@@ -0,0 +1,8 @@
1
+ import { Constructor, System, World } from 'entityx-ts';
2
+ export declare class GameWorld extends World {
3
+ listUpdate: (System | Constructor<System>)[];
4
+ update(dt: number): void;
5
+ private static _instance;
6
+ static get Instance(): GameWorld;
7
+ }
8
+ //# sourceMappingURL=gworld.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gworld.d.ts","sourceRoot":"","sources":["../src/gworld.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvD,qBAAa,SAAU,SAAQ,KAAK;IAClC,UAAU,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAK;IACjD,MAAM,CAAC,EAAE,EAAE,MAAM;IAMjB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAW;IAEnC,WAAkB,QAAQ,cAGzB;CACF"}
package/dist/gworld.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.GameWorld = void 0;
19
+ var entityx_ts_1 = require("entityx-ts");
20
+ var GameWorld = /** @class */ (function (_super) {
21
+ __extends(GameWorld, _super);
22
+ function GameWorld() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.listUpdate = [];
25
+ return _this;
26
+ }
27
+ GameWorld.prototype.update = function (dt) {
28
+ var _this = this;
29
+ this.listUpdate.forEach(function (system) {
30
+ _this.systems.update(system, dt);
31
+ });
32
+ };
33
+ Object.defineProperty(GameWorld, "Instance", {
34
+ get: function () {
35
+ // Do you need arguments? Make it a regular static method instead.
36
+ return this._instance || (this._instance = new this());
37
+ },
38
+ enumerable: false,
39
+ configurable: true
40
+ });
41
+ return GameWorld;
42
+ }(entityx_ts_1.World));
43
+ exports.GameWorld = GameWorld;
@@ -0,0 +1,30 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2013-2016 Chukong Technologies Inc.
3
+ Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4
+
5
+ https://www.cocos.com/
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated engine source code (the "Software"), a limited,
9
+ worldwide, royalty-free, non-assignable, revocable and non-exclusive license
10
+ to use Cocos Creator solely to develop games on your target platforms. You shall
11
+ not use Cocos Creator software for developing other software or tools that's
12
+ used for developing games. You are not granted to publish, distribute,
13
+ sublicense, and/or sell copies of Cocos Creator.
14
+
15
+ The software or tools in this License Agreement are licensed, not sold.
16
+ Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+ ****************************************************************************/
26
+ /**
27
+ * A utils class for parsing HTML texts. The parsed results will be an object array.
28
+ */
29
+ export declare const HtmlTextParser: () => void;
30
+ //# sourceMappingURL=html-text-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-text-parser.d.ts","sourceRoot":"","sources":["../../src/helper/html-text-parser.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;8EAwB8E;AAK9E;;GAEG;AACH,eAAO,MAAM,cAAc,YAS1B,CAAA"}
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ /* eslint-disable no-var */
3
+ /* eslint-disable quotes */
4
+ /* eslint-disable no-useless-escape */
5
+ /****************************************************************************
6
+ Copyright (c) 2013-2016 Chukong Technologies Inc.
7
+ Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
8
+
9
+ https://www.cocos.com/
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated engine source code (the "Software"), a limited,
13
+ worldwide, royalty-free, non-assignable, revocable and non-exclusive license
14
+ to use Cocos Creator solely to develop games on your target platforms. You shall
15
+ not use Cocos Creator software for developing other software or tools that's
16
+ used for developing games. You are not granted to publish, distribute,
17
+ sublicense, and/or sell copies of Cocos Creator.
18
+
19
+ The software or tools in this License Agreement are licensed, not sold.
20
+ Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ THE SOFTWARE.
29
+ ****************************************************************************/
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.HtmlTextParser = void 0;
32
+ var eventRegx = /^(click)(\s)*=|(param)(\s)*=/;
33
+ var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*align(\s)*=|(\s)*offset(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/;
34
+ /**
35
+ * A utils class for parsing HTML texts. The parsed results will be an object array.
36
+ */
37
+ var HtmlTextParser = function () {
38
+ this._parsedObject = {};
39
+ this._specialSymbolArray = [];
40
+ this._specialSymbolArray.push([/&lt;/g, '<']);
41
+ this._specialSymbolArray.push([/&gt;/g, '>']);
42
+ this._specialSymbolArray.push([/&amp;/g, '&']);
43
+ this._specialSymbolArray.push([/&quot;/g, '"']);
44
+ this._specialSymbolArray.push([/&apos;/g, "'"]);
45
+ this._specialSymbolArray.push([/&nbsp;/g, ' ']);
46
+ };
47
+ exports.HtmlTextParser = HtmlTextParser;
48
+ exports.HtmlTextParser.prototype = {
49
+ constructor: exports.HtmlTextParser,
50
+ parse: function (htmlString) {
51
+ this._resultObjectArray = [];
52
+ if (!htmlString) {
53
+ return this._resultObjectArray;
54
+ }
55
+ this._stack = [];
56
+ var startIndex = 0;
57
+ var length = htmlString.length;
58
+ while (startIndex < length) {
59
+ var tagEndIndex = htmlString.indexOf('>', startIndex);
60
+ var tagBeginIndex = -1;
61
+ if (tagEndIndex >= 0) {
62
+ tagBeginIndex = htmlString.lastIndexOf('<', tagEndIndex);
63
+ var noTagBegin = tagBeginIndex < startIndex - 1;
64
+ if (noTagBegin) {
65
+ tagBeginIndex = htmlString.indexOf('<', tagEndIndex + 1);
66
+ tagEndIndex = htmlString.indexOf('>', tagBeginIndex + 1);
67
+ }
68
+ }
69
+ if (tagBeginIndex < 0) {
70
+ this._stack.pop();
71
+ this._processResult(htmlString.substring(startIndex));
72
+ startIndex = length;
73
+ }
74
+ else {
75
+ var newStr = htmlString.substring(startIndex, tagBeginIndex);
76
+ var tagStr = htmlString.substring(tagBeginIndex + 1, tagEndIndex);
77
+ if (tagStr === '')
78
+ newStr = htmlString.substring(startIndex, tagEndIndex + 1);
79
+ this._processResult(newStr);
80
+ if (tagEndIndex === -1) {
81
+ // cc.error('The HTML tag is invalid!');
82
+ tagEndIndex = tagBeginIndex;
83
+ }
84
+ else if (htmlString.charAt(tagBeginIndex + 1) === '/') {
85
+ this._stack.pop();
86
+ }
87
+ else {
88
+ this._addToStack(tagStr);
89
+ }
90
+ startIndex = tagEndIndex + 1;
91
+ }
92
+ }
93
+ return this._resultObjectArray;
94
+ },
95
+ _attributeToObject: function (attribute) {
96
+ attribute = attribute.trim();
97
+ var obj = {};
98
+ var header = attribute.match(/^(color|size)(\s)*=/);
99
+ var tagName;
100
+ var nextSpace;
101
+ var eventObj;
102
+ var eventHanlderString;
103
+ if (header) {
104
+ tagName = header[0];
105
+ attribute = attribute.substring(tagName.length).trim();
106
+ if (attribute === '')
107
+ return obj;
108
+ //parse color
109
+ nextSpace = attribute.indexOf(' ');
110
+ switch (tagName[0]) {
111
+ case 'c':
112
+ if (nextSpace > -1) {
113
+ obj.color = attribute.substring(0, nextSpace).trim();
114
+ }
115
+ else {
116
+ obj.color = attribute;
117
+ }
118
+ break;
119
+ case 's':
120
+ obj.size = parseInt(attribute);
121
+ break;
122
+ }
123
+ //tag has event arguments
124
+ if (nextSpace > -1) {
125
+ eventHanlderString = attribute.substring(nextSpace + 1).trim();
126
+ eventObj = this._processEventHandler(eventHanlderString);
127
+ obj.event = eventObj;
128
+ }
129
+ return obj;
130
+ }
131
+ header = attribute.match(/^(br(\s)*\/)/);
132
+ if (header && header[0].length > 0) {
133
+ tagName = header[0].trim();
134
+ if (tagName.startsWith('br') && tagName[tagName.length - 1] === '/') {
135
+ obj.isNewLine = true;
136
+ this._resultObjectArray.push({ text: '', style: { newline: true } });
137
+ return obj;
138
+ }
139
+ }
140
+ header = attribute.match(/^(img(\s)*src(\s)*=[^>]+\/)/);
141
+ if (header && header[0].length > 0) {
142
+ tagName = header[0].trim();
143
+ if (tagName.startsWith('img') && tagName[tagName.length - 1] === '/') {
144
+ header = attribute.match(imageAttrReg);
145
+ var tagValue;
146
+ var remainingArgument;
147
+ var isValidImageTag = false;
148
+ while (header) {
149
+ //skip the invalid tags at first
150
+ attribute = attribute.substring(attribute.indexOf(header[0]));
151
+ tagName = attribute.substr(0, header[0].length);
152
+ //remove space and = character
153
+ remainingArgument = attribute.substring(tagName.length).trim();
154
+ nextSpace = remainingArgument.indexOf(' ');
155
+ tagValue = nextSpace > -1 ? remainingArgument.substr(0, nextSpace) : remainingArgument;
156
+ tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
157
+ tagName = tagName.toLocaleLowerCase();
158
+ attribute = remainingArgument.substring(nextSpace).trim();
159
+ if (tagValue.endsWith('/'))
160
+ tagValue = tagValue.slice(0, -1);
161
+ if (tagName === 'src') {
162
+ switch (tagValue.charCodeAt(0)) {
163
+ case 34: // "
164
+ case 39: // '
165
+ isValidImageTag = true;
166
+ tagValue = tagValue.slice(1, -1);
167
+ break;
168
+ }
169
+ obj.isImage = true;
170
+ obj.src = tagValue;
171
+ }
172
+ else if (tagName === 'height') {
173
+ obj.imageHeight = parseInt(tagValue);
174
+ }
175
+ else if (tagName === 'width') {
176
+ obj.imageWidth = parseInt(tagValue);
177
+ }
178
+ else if (tagName === 'align') {
179
+ switch (tagValue.charCodeAt(0)) {
180
+ case 34: // "
181
+ case 39: // '
182
+ tagValue = tagValue.slice(1, -1);
183
+ break;
184
+ }
185
+ obj.imageAlign = tagValue.toLocaleLowerCase();
186
+ }
187
+ else if (tagName === 'offset') {
188
+ obj.imageOffset = tagValue;
189
+ }
190
+ else if (tagName === 'click') {
191
+ obj.event = this._processEventHandler("".concat(tagName, "=").concat(tagValue));
192
+ }
193
+ if (obj.event && tagName === 'param') {
194
+ obj.event.param = tagValue.replace(/^\"|\"$/g, '');
195
+ }
196
+ header = attribute.match(imageAttrReg);
197
+ }
198
+ if (isValidImageTag && obj.isImage) {
199
+ this._resultObjectArray.push({ text: '', style: obj });
200
+ }
201
+ return {};
202
+ }
203
+ }
204
+ header = attribute.match(/^(outline(\s)*[^>]*)/);
205
+ if (header) {
206
+ attribute = header[0].substring('outline'.length).trim();
207
+ var defaultOutlineObject = { color: '#ffffff', width: 1 };
208
+ if (attribute) {
209
+ var outlineAttrReg = /(\s)*color(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/;
210
+ header = attribute.match(outlineAttrReg);
211
+ var tagValue;
212
+ while (header) {
213
+ //skip the invalid tags at first
214
+ attribute = attribute.substring(attribute.indexOf(header[0]));
215
+ tagName = attribute.substr(0, header[0].length);
216
+ //remove space and = character
217
+ remainingArgument = attribute.substring(tagName.length).trim();
218
+ nextSpace = remainingArgument.indexOf(' ');
219
+ if (nextSpace > -1) {
220
+ tagValue = remainingArgument.substr(0, nextSpace);
221
+ }
222
+ else {
223
+ tagValue = remainingArgument;
224
+ }
225
+ tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
226
+ tagName = tagName.toLocaleLowerCase();
227
+ attribute = remainingArgument.substring(nextSpace).trim();
228
+ if (tagName === 'click') {
229
+ obj.event = this._processEventHandler("".concat(tagName, "=").concat(tagValue));
230
+ }
231
+ else if (tagName === 'color') {
232
+ defaultOutlineObject.color = tagValue;
233
+ }
234
+ else if (tagName === 'width') {
235
+ defaultOutlineObject.width = parseInt(tagValue);
236
+ }
237
+ if (obj.event && tagName === 'param') {
238
+ obj.event.param = tagValue.replace(/^\"|\"$/g, '');
239
+ }
240
+ header = attribute.match(outlineAttrReg);
241
+ }
242
+ }
243
+ obj.outline = defaultOutlineObject;
244
+ }
245
+ header = attribute.match(/^(on|u|b|i)(\s)*/);
246
+ if (header && header[0].length > 0) {
247
+ tagName = header[0];
248
+ attribute = attribute.substring(tagName.length).trim();
249
+ switch (tagName[0]) {
250
+ case 'u':
251
+ obj.underline = true;
252
+ break;
253
+ case 'i':
254
+ obj.italic = true;
255
+ break;
256
+ case 'b':
257
+ obj.bold = true;
258
+ break;
259
+ }
260
+ if (attribute === '') {
261
+ return obj;
262
+ }
263
+ eventObj = this._processEventHandler(attribute);
264
+ obj.event = eventObj;
265
+ }
266
+ return obj;
267
+ },
268
+ _processEventHandler: function (eventString) {
269
+ var index = 0;
270
+ var obj = {};
271
+ var eventNames = eventString.match(eventRegx);
272
+ var isValidTag = false;
273
+ while (eventNames) {
274
+ var eventName = eventNames[0];
275
+ var eventValue = '';
276
+ isValidTag = false;
277
+ eventString = eventString.substring(eventName.length).trim();
278
+ if (eventString.charAt(0) === '"') {
279
+ index = eventString.indexOf('"', 1);
280
+ if (index > -1) {
281
+ eventValue = eventString.substring(1, index).trim();
282
+ isValidTag = true;
283
+ }
284
+ index++;
285
+ }
286
+ else if (eventString.charAt(0) === '\'') {
287
+ index = eventString.indexOf('\'', 1);
288
+ if (index > -1) {
289
+ eventValue = eventString.substring(1, index).trim();
290
+ isValidTag = true;
291
+ }
292
+ index++;
293
+ }
294
+ else {
295
+ //skip the invalid attribute value
296
+ var match = eventString.match(/(\S)+/);
297
+ if (match) {
298
+ eventValue = match[0];
299
+ }
300
+ else {
301
+ eventValue = '';
302
+ }
303
+ index = eventValue.length;
304
+ }
305
+ if (isValidTag) {
306
+ eventName = eventName.substring(0, eventName.length - 1).trim();
307
+ obj[eventName] = eventValue;
308
+ }
309
+ eventString = eventString.substring(index).trim();
310
+ eventNames = eventString.match(eventRegx);
311
+ }
312
+ return obj;
313
+ },
314
+ _addToStack: function (attribute) {
315
+ var obj = this._attributeToObject(attribute);
316
+ if (this._stack.length === 0) {
317
+ this._stack.push(obj);
318
+ }
319
+ else {
320
+ if (obj.isNewLine || obj.isImage) {
321
+ return;
322
+ }
323
+ //for nested tags
324
+ var previousTagObj = this._stack[this._stack.length - 1];
325
+ for (var key in previousTagObj) {
326
+ if (!obj[key]) {
327
+ obj[key] = previousTagObj[key];
328
+ }
329
+ }
330
+ this._stack.push(obj);
331
+ }
332
+ },
333
+ _processResult: function (value) {
334
+ if (value === '') {
335
+ return;
336
+ }
337
+ value = this._escapeSpecialSymbol(value);
338
+ if (this._stack.length > 0) {
339
+ this._resultObjectArray.push({ text: value, style: this._stack[this._stack.length - 1] });
340
+ }
341
+ else {
342
+ this._resultObjectArray.push({ text: value });
343
+ }
344
+ },
345
+ _escapeSpecialSymbol: function (str) {
346
+ for (var i = 0; i < this._specialSymbolArray.length; ++i) {
347
+ var key = this._specialSymbolArray[i][0];
348
+ var value = this._specialSymbolArray[i][1];
349
+ str = str.replace(key, value);
350
+ }
351
+ return str;
352
+ },
353
+ };
@@ -0,0 +1,17 @@
1
+ import { Constructor, EntityManager, EventManager, EventReceive } from 'entityx-ts';
2
+ import { ComponentX } from '..';
3
+ export declare function registerSystem<T extends ComponentX>(component: Constructor<T>): {
4
+ new (): {
5
+ configure(event_manager: EventManager): void;
6
+ receive(type: string, event: EventReceive): void;
7
+ update(entities: EntityManager, events: EventManager, dt: number): void;
8
+ };
9
+ };
10
+ export declare function instantiate<T>(ComponentType: Constructor<T>, data?: any): T;
11
+ export declare class Size {
12
+ constructor(width: any, height: any);
13
+ width: number;
14
+ height: number;
15
+ }
16
+ export declare function size(width: number, height: number): Size;
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/helper/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAEvD,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAG,UAAU,EAAY,MAAM,IAAI,CAAA;AAG1C,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;;iCAKjD,YAAY;sBAKvB,MAAM,SAAS,YAAY;yBAYxB,aAAa,UAAU,YAAY,MAAM,MAAM;;EAenE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAE3E;AAED,qBAAa,IAAI;gBACH,KAAK,KAAA,EAAE,MAAM,KAAA;IAIzB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAEjD"}