@safe-engine/pixi 7.0.3 → 8.0.4

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 (46) hide show
  1. package/README.md +4 -4
  2. package/dist/app.d.ts +2 -2
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +20 -17
  5. package/dist/components/GUIComponent.d.ts +6 -4
  6. package/dist/components/GUIComponent.d.ts.map +1 -1
  7. package/dist/components/GUIComponent.js +1 -2
  8. package/dist/components/NodeComp.js +1 -1
  9. package/dist/components/RenderComponent.d.ts +1 -1
  10. package/dist/core/LoadingBar.js +8 -8
  11. package/dist/systems/GUISystem.d.ts.map +1 -1
  12. package/dist/systems/GUISystem.js +2 -7
  13. package/dist/systems/RenderSystem.d.ts.map +1 -1
  14. package/dist/systems/RenderSystem.js +3 -2
  15. package/package.json +5 -5
  16. package/.github/workflows/npm-publish.yml +0 -35
  17. package/dist/components/EnhancedComponent.d.ts +0 -22
  18. package/dist/components/EnhancedComponent.d.ts.map +0 -1
  19. package/dist/components/EnhancedComponent.js +0 -62
  20. package/dist/core/Scene.d.ts +0 -6
  21. package/dist/core/Scene.d.ts.map +0 -1
  22. package/dist/core/Scene.js +0 -39
  23. package/dist/core/Vec2.d.ts +0 -20
  24. package/dist/core/Vec2.d.ts.map +0 -1
  25. package/dist/core/Vec2.js +0 -70
  26. package/dist/core/decorator.d.ts +0 -9
  27. package/dist/core/decorator.d.ts.map +0 -1
  28. package/dist/core/decorator.js +0 -46
  29. package/dist/gworld.d.ts +0 -8
  30. package/dist/gworld.d.ts.map +0 -1
  31. package/dist/gworld.js +0 -43
  32. package/dist/helper/utils.d.ts +0 -11
  33. package/dist/helper/utils.d.ts.map +0 -1
  34. package/dist/helper/utils.js +0 -40
  35. package/src/app.ts +0 -53
  36. package/src/components/GUIComponent.ts +0 -141
  37. package/src/components/NodeComp.ts +0 -416
  38. package/src/components/RenderComponent.ts +0 -66
  39. package/src/core/Color.ts +0 -3
  40. package/src/core/LoadingBar.ts +0 -63
  41. package/src/core/Size.ts +0 -21
  42. package/src/helper/html-text-parser.ts +0 -364
  43. package/src/index.ts +0 -7
  44. package/src/systems/GUISystem.ts +0 -80
  45. package/src/systems/RenderSystem.ts +0 -70
  46. package/tsconfig.json +0 -24
package/dist/gworld.js DELETED
@@ -1,43 +0,0 @@
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;
@@ -1,11 +0,0 @@
1
- import { ComponentX } from '@safe-engine/core';
2
- import { Constructor, EntityManager, EventManager, EventReceive } from 'entityx-ts';
3
- export declare function registerSystem<T extends ComponentX>(component: Constructor<T>): {
4
- new (): {
5
- configure(event_manager: EventManager): void;
6
- receiveComponentAddedEvent(event: EventReceive<T>): 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
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/helper/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,mBAAmB,CAAA;AACzD,OAAO,EACL,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAGvD,MAAM,YAAY,CAAA;AAInB,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;;iCAKjD,YAAY;0CAKH,YAAY,CAAC,CAAC,CAAC;yBAMhC,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"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerSystem = registerSystem;
4
- exports.instantiate = instantiate;
5
- const core_1 = require("@safe-engine/core");
6
- const entityx_ts_1 = require("entityx-ts");
7
- const __1 = require("..");
8
- function registerSystem(component) {
9
- if (core_1.GameWorld.Instance.systems.isRegistered(`${component.name}System`)) {
10
- return;
11
- }
12
- class NewSystem {
13
- configure(event_manager) {
14
- console.log('configure registerSystem', component.name);
15
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, component, this.receiveComponentAddedEvent.bind(this));
16
- }
17
- receiveComponentAddedEvent(event) {
18
- const ett = event.entity;
19
- const newComp = ett.getComponent(component);
20
- newComp.node = ett.getComponent(__1.NodeComp);
21
- }
22
- update(entities, events, dt) {
23
- for (const entt of entities.entities_with_components(component)) {
24
- const comp = entt.getComponent(component);
25
- // console.log('comp', comp.constructor.name, typeof comp['update'] === 'function')
26
- if (comp.node.active && typeof comp['update'] === 'function') {
27
- comp['update'](dt);
28
- }
29
- }
30
- }
31
- }
32
- Object.defineProperty(NewSystem, 'name', { value: `${component.name}System` });
33
- core_1.GameWorld.Instance.systems.add(NewSystem);
34
- core_1.GameWorld.Instance.systems.configureOnce(NewSystem);
35
- core_1.GameWorld.Instance.listUpdate.push(NewSystem);
36
- return NewSystem;
37
- }
38
- function instantiate(ComponentType, data) {
39
- return ComponentType.create(data);
40
- }
package/src/app.ts DELETED
@@ -1,53 +0,0 @@
1
- import { GameWorld } from '@safe-engine/core'
2
- import { Constructor, System } from 'entityx-ts'
3
- import { Application } from 'pixi.js'
4
- import { actionManager } from 'pixi-action-ease'
5
-
6
- import { NodeComp } from './components/NodeComp'
7
-
8
- export const app = new Application({
9
- width: 1080,
10
- height: 1920,
11
- antialias: true,
12
- resolution: window.devicePixelRatio,
13
- })
14
-
15
- export function setupResolution(designedResolution = { width: 720, height: 1280 }) {
16
- const { width, height } = designedResolution
17
- app.renderer.resize(width, height)
18
- }
19
-
20
- export async function addGameCanvasTo(id = 'game') {
21
- Object.assign(app.view.style, {
22
- width: `${window.innerWidth}px`,
23
- // height: `${window.innerHeight}px`,
24
- overflow: 'hidden',
25
- })
26
-
27
- const gameDiv = document.getElementById(id)
28
- gameDiv.appendChild(app.view as never)
29
- GameWorld.Instance.setup(NodeComp, app.stage)
30
- }
31
-
32
- function startGameLoop(world: GameWorld) {
33
- // Listen for frame updates
34
- app.ticker.add(() => {
35
- const dt = app.ticker.deltaMS * 0.001
36
- actionManager.update(dt)
37
- world.update(dt)
38
- })
39
- // app.ticker.speed = 0.5
40
- }
41
-
42
- export function startGameWithSystems(systemsList: Constructor<System>[]) {
43
- const world = GameWorld.Instance
44
- systemsList.forEach(system => {
45
- world.systems.add(system)
46
- const sys = world.systemsMap[system.name]
47
- if (sys.update) {
48
- world.listUpdate.push(system)
49
- }
50
- })
51
- world.systems.configure()
52
- startGameLoop(world)
53
- }
@@ -1,141 +0,0 @@
1
- import { ComponentX, NoRenderComponentX } from '@safe-engine/core'
2
- import { Assets, Container, Point, Text } from 'pixi.js'
3
-
4
- import { Color4B } from '../core/Color'
5
- import { LoadingBar, LoadingBarMode, ProgressTimer } from '../core/LoadingBar'
6
- import { NodeComp } from './NodeComp'
7
-
8
- // const _htmlTextParser = new HtmlTextParser()
9
- export const FillType = {
10
- HORIZONTAL: 0,
11
- VERTICAL: 1,
12
- RADIAL: 2,
13
- }
14
- type Keys = keyof typeof FillType
15
- type Values = (typeof FillType)[Keys]
16
-
17
- export class ButtonComp extends NoRenderComponentX<NodeComp> {
18
- normalImage: string
19
- selectedImage: string
20
- disableImage: string
21
- zoomScale: number
22
- onPress: (target: ButtonComp) => void
23
-
24
- setOnPress(cb: (target: ButtonComp) => void) {
25
- this.onPress = cb
26
- }
27
-
28
- set enabled(val) {
29
- this.node.instance.interactive = val
30
- }
31
- }
32
-
33
- export class ProgressBarComp extends NoRenderComponentX<NodeComp<LoadingBar>> {
34
- mode = LoadingBarMode.BAR
35
- private _progress: number
36
- isReverse: boolean
37
-
38
- get progress() {
39
- return this._progress
40
- }
41
-
42
- set progress(val: number) {
43
- this._progress = val
44
- this.node.instance.progress = val
45
- }
46
- }
47
-
48
- export class LabelComp extends ComponentX<NodeComp<Text>> {
49
- font: string
50
- string: string
51
- size = 64
52
-
53
- getString() {
54
- if (this.node.instance instanceof Text) {
55
- return this.node.instance.text
56
- }
57
- }
58
-
59
- setString(val: string) {
60
- if (this.node.instance instanceof Text) {
61
- this.node.instance.text = val
62
- }
63
- }
64
-
65
- getSize() {
66
- if (this.node.instance instanceof Text) {
67
- return this.node.instance.style.fontSize
68
- }
69
- }
70
- setSize(val) {
71
- if (this.node.instance instanceof Text) {
72
- this.node.instance.style.fontSize = val
73
- }
74
- }
75
-
76
- getFont() {
77
- if (this.node.instance instanceof Text) {
78
- return this.node.instance.style.fontFamily as string
79
- }
80
- }
81
-
82
- setFont(val: string) {
83
- // console.log('set font', val, Assets.get(val))
84
- if (this.node.instance instanceof Text) {
85
- if (Assets.get(val)) this.node.instance.style.fontFamily = Assets.get(val).family
86
- }
87
- }
88
- }
89
-
90
- export class ScrollView extends ComponentX<NodeComp<Container>> {
91
- width: number
92
- height: number
93
- }
94
-
95
- export class BlockInputEventsComp extends NoRenderComponentX<NodeComp<Container>> { }
96
-
97
- export class ProgressTimerComp extends ComponentX<NodeComp<ProgressTimer>> {
98
- spriteFrame: string
99
- fillType: Values
100
- fillRange: number
101
- fillCenter: Point
102
- isReverse: boolean
103
-
104
- getFillRange() {
105
- return this.node.instance.progress
106
- }
107
-
108
- setFillStart(val: number) {
109
- this.node.instance.fillCenter.x = val
110
- }
111
-
112
- setFillRange(val: number) {
113
- // console.log('setFillRange', this.node.instance);
114
- this.node.instance.progress = val
115
- }
116
- }
117
-
118
- export class RichTextComp extends ComponentX<NodeComp<Text>> {
119
- protected font: string
120
- protected string: string
121
- protected size: number
122
-
123
- getString() {
124
- return this.string
125
- }
126
-
127
- setString(val: string) {
128
- this.string = val
129
- }
130
- }
131
-
132
- export class LabelOutlineComp extends NoRenderComponentX<NodeComp> {
133
- color: typeof Color4B
134
- width: number
135
- }
136
-
137
- export class LabelShadowComp extends NoRenderComponentX<NodeComp> {
138
- color: typeof Color4B
139
- blur: number
140
- offset: Point
141
- }
@@ -1,416 +0,0 @@
1
- import { BaseNode, ComponentType, EnhancedComponent } from '@safe-engine/core'
2
- import { Constructor, Entity } from 'entityx-ts'
3
- import remove from 'lodash/remove'
4
- import { Color, ColorSource, Container, Point, Sprite } from 'pixi.js'
5
- import { Action, actionManager, Animation } from 'pixi-action-ease'
6
-
7
- import { Size } from '../core/Size'
8
- import { ProgressBarComp } from './GUIComponent'
9
-
10
- export type EventCallbackType = (...args) => void
11
- export interface EventMap {
12
- [key: string]: [EventCallbackType]
13
- }
14
-
15
- type TouchEVentCallback = (target: { location: Point }) => void
16
-
17
- export class NodeComp<C extends Container = Container> implements BaseNode<C> {
18
- entity: Entity
19
- instance: C
20
- events: EventMap = {}
21
- data: { [key: string]: any } = {}
22
- parent: NodeComp
23
- children: NodeComp[] = []
24
- actionsList: Animation[] = []
25
- // offset: cc.Point = cc.v2(0, 0);
26
- name: string
27
- private lastMove: { x: number; y: number }
28
- private _group = 0
29
-
30
- onTouchStart?: TouchEVentCallback
31
- onTouchMove?: TouchEVentCallback
32
- onTouchEnd?: TouchEVentCallback
33
- onTouchCancel?: TouchEVentCallback
34
-
35
- setOnTouchStart(cb: TouchEVentCallback) {
36
- this.onTouchStart = cb
37
- this.instance.on('touchstart', (event) => {
38
- const { global } = event
39
- this.onTouchStart({ location: global })
40
- })
41
- }
42
-
43
- setOnTouchMove(cb: TouchEVentCallback) {
44
- this.onTouchMove = cb
45
- this.instance.on('touchmove', (event) => {
46
- const { global } = event
47
- this.onTouchMove({ location: global })
48
- })
49
- }
50
-
51
- setOnTouchEnd(cb: TouchEVentCallback) {
52
- this.onTouchEnd = cb
53
- this.instance.on('touchend', (event) => {
54
- const { global } = event
55
- this.onTouchEnd({ location: global })
56
- })
57
- }
58
-
59
- setOnTouchCancel(cb: TouchEVentCallback) {
60
- this.onTouchCancel = cb
61
- this.instance.on('touchcancel', (event) => {
62
- const { global } = event
63
- this.onTouchCancel({ location: global })
64
- })
65
- }
66
-
67
- constructor(instance: C, entity: Entity) {
68
- this.entity = entity
69
- this.instance = instance
70
- this.instance.eventMode = 'static'
71
- }
72
-
73
- get uuid() {
74
- return this.entity.id
75
- }
76
-
77
- get position(): Point {
78
- return this.getPosition()
79
- }
80
-
81
- set position(val: Point) {
82
- this.setPosition(val.x, val.y)
83
- }
84
-
85
- get x() {
86
- return this.instance.x
87
- }
88
-
89
- set x(val: number) {
90
- this.instance.x = val
91
- }
92
-
93
- get y() {
94
- return this.instance.y
95
- }
96
-
97
- set y(val: number) {
98
- this.instance.y = val
99
- }
100
-
101
- // get scale() {
102
- // return this.instance.scale
103
- // }
104
-
105
- set scale(val: number) {
106
- this.instance.scale = new Point(val, val)
107
- }
108
-
109
- get scaleX() {
110
- return this.instance.scale.x
111
- }
112
-
113
- set scaleX(val: number) {
114
- this.instance.scale.x = val
115
- }
116
-
117
- get scaleY() {
118
- return this.instance.y
119
- }
120
-
121
- set scaleY(val: number) {
122
- this.instance.y = val
123
- }
124
-
125
- get anchorX() {
126
- if (this.instance instanceof Sprite)
127
- return (this.instance as Sprite).anchor.x
128
- return 0
129
- }
130
-
131
- set anchorX(val: number) {
132
- if (this.instance instanceof Sprite) this.instance.anchor.x = val
133
- }
134
-
135
- get anchorY() {
136
- if (this.instance instanceof Sprite)
137
- return (this.instance as Sprite).anchor.y
138
- return 0
139
- } ß
140
-
141
- set anchorY(val: number) {
142
- if (this.instance instanceof Sprite) this.instance.anchor.y = val
143
- }
144
-
145
- /** rotation is in radians */
146
- get rotation() {
147
- return this.instance.rotation
148
- }
149
- /** rotation is in radians */
150
- set rotation(val: number) {
151
- this.instance.rotation = val
152
- }
153
-
154
- /** angle is in degrees. */
155
- get angle() {
156
- return this.instance.angle
157
- }
158
- /** angle is in degrees. */
159
- set angle(val: number) {
160
- this.instance.angle = val
161
- }
162
-
163
- get color() {
164
- if (this.instance instanceof Sprite)
165
- return (this.instance as Sprite).tint
166
- return 0xffffff
167
- }
168
-
169
- set color(val: ColorSource) {
170
- if (this.instance instanceof Sprite) this.instance.tint = val
171
- }
172
-
173
- get opacity() {
174
- return this.instance.alpha
175
- }
176
-
177
- set opacity(val: number) {
178
- this.instance.alpha = val
179
- }
180
-
181
- get active() {
182
- return this.instance.visible && !this.instance.destroyed
183
- }
184
-
185
- set active(val: boolean) {
186
- this.instance.visible = val
187
- }
188
-
189
- get group() {
190
- return this._group
191
- }
192
-
193
- set group(val: number) {
194
- this._group = val
195
- }
196
-
197
- get width() {
198
- return this.instance.width
199
- }
200
-
201
- set width(val) {
202
- this.instance.width = val
203
- }
204
-
205
- get height() {
206
- return this.instance.height
207
- }
208
-
209
- set height(val) {
210
- this.instance.height = val
211
- }
212
-
213
- get zIndex() {
214
- return this.instance.zIndex
215
- }
216
-
217
- set zIndex(val) {
218
- this.instance.zIndex = val
219
- }
220
-
221
- get childrenCount() {
222
- return this.children.length
223
- }
224
-
225
- addComponent<T extends ComponentType>(instance): T {
226
- return this.entity.assign(instance)
227
- }
228
-
229
- getComponent<T extends ComponentType>(component: Constructor<T>): T {
230
- return this.entity.getComponent(component)
231
- }
232
-
233
- getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
234
- if (!this.children.length) {
235
- return []
236
- }
237
- const listHave = this.children.filter((child) => {
238
- return child.getComponent(component)
239
- })
240
- return listHave.map((node) => node.getComponent(component))
241
- }
242
-
243
- getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
244
- return this.getComponentsInChildren(component)[0]
245
- }
246
-
247
- convertToNodeSpace(point: Point) {
248
- return this.instance.toLocal(point)
249
- }
250
-
251
- convertToNodeSpaceAR(point: Point) {
252
- return this.instance.toLocal(point)
253
- }
254
-
255
- convertToWorldSpaceAR(point: Point) {
256
- return this.instance.toGlobal(point)
257
- }
258
-
259
- getPosition(): Point {
260
- return this.instance.position
261
- }
262
-
263
- setPosition(x: number | Point, y?: number) {
264
- if (typeof x !== 'number') {
265
- this.x = x.x
266
- this.y = x.y
267
- } else {
268
- this.x = x
269
- this.y = y
270
- }
271
- }
272
-
273
- setRotation(deg: number) {
274
- this.instance.rotation = deg
275
- }
276
-
277
- getRotation() {
278
- return this.instance.rotation
279
- }
280
-
281
- // setAnchorPoint(point: number | cc.Point, y?: number) {
282
- // this.instance.setAnchorPoint(point, y)
283
- // }
284
-
285
- // getAnchorPoint() {
286
- // return this.instance.getAnchorPoint()
287
- // }
288
-
289
- // getBoundingBox() {
290
- // const box = this.instance.getBoundingBox()
291
- // box.contains = function (point) {
292
- // return this.x <= point.x && this.x + this.width >= point.x && this.y <= point.y && this.y + this.height >= point.y
293
- // }
294
- // return box
295
- // }
296
-
297
- getContentSize(): Size {
298
- return this.instance.getBounds()
299
- }
300
-
301
- // setContentSize(size: cc.Size | number, height?: number) {
302
- // this.instance.setContentSize(size, height)
303
- // if (this.instance instanceof cc.ClippingNode) {
304
- // const hw = ((size as any).width || size) * 0.5
305
- // const hh = ((size as any).height || height) * 0.5
306
- // const stencil = new cc.DrawNode()
307
- // const rectangle = [cc.p(-hw, -hh), cc.p(hw, -hh), cc.p(hw, hh), cc.p(-hw, hh)]
308
- // stencil.drawPoly(rectangle, cc.Color.WHITE, 0, cc.Color.WHITE)
309
- // // stencil.drawDot(cc.p(-height * 0.5, -height * 0.5), height, cc.Color.WHITE);
310
- // this.instance.stencil = stencil
311
- // }
312
- // }
313
-
314
- setColor(color: Color) {
315
- if (this.instance instanceof Sprite)
316
- (this.instance as Sprite).tint = color
317
- }
318
-
319
- setScale(scaleX: number, scaleY?: number) {
320
- this.instance.scale.x = scaleX
321
- this.instance.scale.x = scaleY || scaleX
322
- }
323
-
324
- runAction(act: Action) {
325
- const animation = actionManager.runAction(this.instance as any, act)
326
- this.actionsList.push(animation)
327
- }
328
-
329
- stopAllActions() {
330
- this.actionsList.forEach((act) => {
331
- actionManager.cancelAction(act)
332
- })
333
- this.actionsList = []
334
- }
335
-
336
- pauseAllActions() {
337
- this.actionsList.forEach((anim: Animation) => {
338
- anim.isPause = true
339
- })
340
- }
341
-
342
- resumeAllActions() {
343
- this.actionsList.forEach((anim: Animation) => {
344
- anim.isPause = false
345
- })
346
- }
347
-
348
- destroy() {
349
- if (this.parent) {
350
- remove(this.parent.children, ({ entity }) => entity.id === this.entity.id)
351
- }
352
- this.children.forEach((child) => {
353
- child.destroy()
354
- })
355
- this.parent = null
356
- this.entity.destroy()
357
- this.stopAllActions()
358
- this.instance.destroy()
359
- }
360
-
361
- removeFromParent() {
362
- this.active = false
363
- this.stopAllActions()
364
- this.instance.removeFromParent()
365
- }
366
-
367
- addChild(child: NodeComp, zOrder?: number) {
368
- child.parent = this
369
- child.active = true
370
- this.children.push(child)
371
- this.instance.addChild(child.instance)
372
- if (zOrder) child.zIndex = zOrder
373
- }
374
-
375
- destroyAllChildren() {
376
- this.children.forEach((child) => {
377
- child.destroy()
378
- })
379
- }
380
-
381
- on(name: string, callback: EventCallbackType, target?: any) {
382
- const bound = target ? callback.bind(target) : callback
383
- if (this.events[name]) {
384
- this.events[name].push(bound)
385
- } else {
386
- this.events[name] = [bound]
387
- }
388
- }
389
-
390
- off(name: string) {
391
- this.events[name] = undefined
392
- }
393
-
394
- emit(name: string, ...params: any) {
395
- if (this.events[name]) {
396
- this.events[name].forEach((fc) => fc(...params))
397
- }
398
- }
399
-
400
- resolveComponent(component: EnhancedComponent<NodeComp>) {
401
- if ((component.constructor as any).hasRender) {
402
- this.addChild(component.node)
403
- } else {
404
- this.addComponent(component)
405
- if (component instanceof ProgressBarComp) {
406
- this.addChild(component.node)
407
- }
408
- }
409
- }
410
- getData<T>(key: string): T {
411
- return this.data[key]
412
- }
413
- setData<T>(key: string, val: T) {
414
- this.data[key] = val
415
- }
416
- }