@safe-engine/pixi 8.4.7 → 8.5.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 (117) hide show
  1. package/README.md +17 -25
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +0 -23
  4. package/dist/box2d-wasm/ContactListener.d.ts +1 -1
  5. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
  6. package/dist/box2d-wasm/ContactListener.js +50 -18
  7. package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
  8. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  9. package/dist/box2d-wasm/PhysicsComponent.js +44 -11
  10. package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
  11. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  12. package/dist/box2d-wasm/PhysicsSprite.js +24 -3
  13. package/dist/box2d-wasm/PhysicsSystem.d.ts +5 -3
  14. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  15. package/dist/box2d-wasm/PhysicsSystem.js +135 -45
  16. package/dist/collider/CollideComponent.d.ts +27 -10
  17. package/dist/collider/CollideComponent.d.ts.map +1 -1
  18. package/dist/collider/CollideComponent.js +10 -12
  19. package/dist/collider/helper/Intersection.d.ts +6 -6
  20. package/dist/collider/helper/Intersection.d.ts.map +1 -1
  21. package/dist/collider/helper/Intersection.js +4 -4
  22. package/dist/collider/index.d.ts +1 -0
  23. package/dist/collider/index.d.ts.map +1 -1
  24. package/dist/collider/index.js +1 -0
  25. package/dist/components/NodeComp.d.ts +62 -36
  26. package/dist/components/NodeComp.d.ts.map +1 -1
  27. package/dist/components/NodeComp.js +18 -99
  28. package/dist/core/Color.d.ts.map +1 -1
  29. package/dist/dragonbones/DragonBonesComponent.d.ts +3 -2
  30. package/dist/dragonbones/DragonBonesComponent.d.ts.map +1 -1
  31. package/dist/dragonbones/DragonBonesComponent.js +1 -1
  32. package/dist/dragonbones/DragonBonesSystem.js +2 -2
  33. package/dist/gui/GUISystem.d.ts.map +1 -1
  34. package/dist/gui/GUISystem.js +5 -6
  35. package/dist/helper/utils.d.ts +0 -6
  36. package/dist/helper/utils.d.ts.map +1 -1
  37. package/dist/helper/utils.js +0 -12
  38. package/dist/index.d.ts +0 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +0 -5
  41. package/dist/norender/NoRenderComponent.d.ts +5 -1
  42. package/dist/norender/NoRenderComponent.d.ts.map +1 -1
  43. package/dist/norender/NoRenderSystem.d.ts.map +1 -1
  44. package/dist/norender/NoRenderSystem.js +8 -9
  45. package/dist/render/RenderComponent.d.ts +6 -17
  46. package/dist/render/RenderComponent.d.ts.map +1 -1
  47. package/dist/render/RenderComponent.js +26 -18
  48. package/dist/spine/lib/require-shim.d.ts.map +1 -1
  49. package/dist/spine/lib/require-shim.js +1 -1
  50. package/package.json +6 -7
  51. package/.github/workflows/npm-publish.yml +0 -35
  52. package/src/app.ts +0 -91
  53. package/src/base/EnhancedComponent.ts +0 -38
  54. package/src/base/gworld.ts +0 -20
  55. package/src/base/index.ts +0 -14
  56. package/src/base/utils.ts +0 -23
  57. package/src/box2d-wasm/ContactListener.ts +0 -66
  58. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  59. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  60. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  61. package/src/box2d-wasm/debugDraw.ts +0 -249
  62. package/src/box2d-wasm/index.ts +0 -19
  63. package/src/collider/CollideComponent.ts +0 -257
  64. package/src/collider/CollideSystem.ts +0 -166
  65. package/src/collider/helper/Intersection.ts +0 -139
  66. package/src/collider/helper/utils.ts +0 -37
  67. package/src/collider/index.ts +0 -16
  68. package/src/components/BaseComponent.ts +0 -17
  69. package/src/components/NodeComp.ts +0 -442
  70. package/src/components/Scene.ts +0 -17
  71. package/src/core/Color.ts +0 -7
  72. package/src/core/LoadingBar.ts +0 -63
  73. package/src/core/NodePool.ts +0 -28
  74. package/src/core/Size.ts +0 -21
  75. package/src/core/Vec2.ts +0 -108
  76. package/src/core/director.ts +0 -11
  77. package/src/core/index.ts +0 -7
  78. package/src/core/loader.ts +0 -14
  79. package/src/core/math.ts +0 -22
  80. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  81. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  82. package/src/dragonbones/index.ts +0 -11
  83. package/src/gui/GUIComponent.ts +0 -155
  84. package/src/gui/GUISystem.ts +0 -125
  85. package/src/helper/utils.ts +0 -50
  86. package/src/index.ts +0 -21
  87. package/src/norender/NoRenderComponent.ts +0 -60
  88. package/src/norender/NoRenderSystem.ts +0 -67
  89. package/src/norender/Touch.ts +0 -37
  90. package/src/planck/PhysicsComponent.ts +0 -83
  91. package/src/planck/PhysicsSprite.ts +0 -43
  92. package/src/planck/PhysicsSystem.ts +0 -201
  93. package/src/planck/index.ts +0 -3
  94. package/src/render/RenderComponent.ts +0 -132
  95. package/src/render/RenderSystem.ts +0 -64
  96. package/src/richtext/RichTextComp.ts +0 -50
  97. package/src/richtext/RichTextSystem.ts +0 -26
  98. package/src/richtext/html-text-parser.ts +0 -87
  99. package/src/richtext/index.ts +0 -8
  100. package/src/spine/SpineComponent.ts +0 -18
  101. package/src/spine/SpineSystem.ts +0 -30
  102. package/src/spine/index.ts +0 -11
  103. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  104. package/src/spine/lib/Spine.ts +0 -894
  105. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  106. package/src/spine/lib/SpinePipe.ts +0 -203
  107. package/src/spine/lib/SpineTexture.ts +0 -143
  108. package/src/spine/lib/assets/atlasLoader.ts +0 -158
  109. package/src/spine/lib/assets/skeletonLoader.ts +0 -81
  110. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  111. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  112. package/src/spine/lib/darktint/DarkTintShader.ts +0 -74
  113. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  114. package/src/spine/lib/index.ts +0 -43
  115. package/src/spine/lib/require-shim.ts +0 -43
  116. package/tsconfig.json +0 -18
  117. /package/{src/@types → @types}/index.d.ts +0 -0
@@ -1,139 +0,0 @@
1
- import { Point } from 'pixi.js'
2
- import { getDistance, v2 } from '../../helper/utils'
3
-
4
- export function pointInPolygon(pos: Point, polygon: Point[]) {
5
- let inside = false
6
- const x = pos.x
7
- const y = pos.y
8
-
9
- // use some raycasting to test hits
10
- // https://github.com/substack/point-in-polygon/blob/master/index.js
11
- const length = polygon.length
12
-
13
- let intersect = false
14
- for (let i = 0, j = length - 1; i < length; j = i++) {
15
- const xi = polygon[i].x,
16
- yi = polygon[i].y,
17
- xj = polygon[j].x,
18
- yj = polygon[j].y
19
- intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi
20
-
21
- if (intersect) {
22
- inside = !inside
23
- }
24
- }
25
-
26
- return inside
27
- }
28
-
29
- function lineLine(a1: Point, a2: Point, b1: Point, b2: Point): boolean {
30
- // jshint camel case:false
31
-
32
- const ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x)
33
- const ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x)
34
- const u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y)
35
-
36
- if (u_b !== 0) {
37
- const ua = ua_t / u_b
38
- const ub = ub_t / u_b
39
-
40
- if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
41
- return true
42
- }
43
- }
44
-
45
- return false
46
- }
47
-
48
- function linePolygon(A: Point, B: Point, polygon: Point[]) {
49
- const length = polygon.length
50
- for (let i = 0; i < length; ++i) {
51
- const C = polygon[i]
52
- const D = polygon[(i + 1) % length]
53
-
54
- if (lineLine(A, B, C, D)) {
55
- return true
56
- }
57
- }
58
-
59
- return false
60
- }
61
-
62
- export function pointLineDistance(point: Point, start: Point, end: Point, isSegment) {
63
- let dx = end.x - start.x
64
- let dy = end.y - start.y
65
- const d = dx * dx + dy * dy
66
- const t = ((point.x - start.x) * dx + (point.y - start.y) * dy) / d
67
- let p
68
-
69
- if (!isSegment) {
70
- p = v2(start.x + t * dx, start.y + t * dy)
71
- } else if (d) {
72
- if (t < 0) {
73
- p = start
74
- } else if (t > 1) {
75
- p = end
76
- } else {
77
- p = v2(start.x + t * dx, start.y + t * dy)
78
- }
79
- } else {
80
- p = start
81
- }
82
-
83
- dx = point.x - p.x
84
- dy = point.y - p.y
85
- return Math.sqrt(dx * dx + dy * dy)
86
- }
87
-
88
- export function polygonPolygon(pts1: Point[], pts2: Point[]) {
89
- let i = 0,
90
- l = 0
91
-
92
- // check if p1 pts1 intersects pts2
93
- for (l = pts1.length; i < l; ++i) {
94
- const a1 = pts1[i]
95
- const a2 = pts1[(i + 1) % l]
96
-
97
- if (linePolygon(a1, a2, pts2)) {
98
- return true
99
- }
100
- }
101
-
102
- // check if pts1 contains pts2
103
- for (i = 0, l = pts2.length; i < l; ++i) {
104
- if (pointInPolygon(pts2[i], pts1)) {
105
- return true
106
- }
107
- }
108
-
109
- // check if pts2 contains pts1
110
- for (i = 0, l = pts1.length; i < l; ++i) {
111
- if (pointInPolygon(pts1[i], pts2)) {
112
- return true
113
- }
114
- }
115
-
116
- return false
117
- }
118
-
119
- export function circleCircle(p1: Point, r1: number, p2: Point, r2: number) {
120
- const d = getDistance(p1, p2)
121
- return d < r1 + r2
122
- }
123
-
124
- export function polygonCircle(pts1: Point[], p2: Point, r2: number) {
125
- if (pointInPolygon(p2, pts1)) {
126
- return true
127
- }
128
-
129
- for (let i = 0, l = pts1.length; i < l; i++) {
130
- const start = i === 0 ? pts1[l - 1] : pts1[i - 1]
131
- const end = pts1[i]
132
-
133
- if (pointLineDistance(p2, start, end, true) < r2) {
134
- return true
135
- }
136
- }
137
-
138
- return false
139
- }
@@ -1,37 +0,0 @@
1
- import { GameWorld } from '../../base'
2
- import { Collider } from '../CollideComponent'
3
- import { CollideSystem } from '../CollideSystem'
4
-
5
- export function shouldCollider(colA: Collider, colB: Collider) {
6
- const groupA = colA.node.group
7
- const groupB = colB.node.group
8
- if (groupA === undefined || groupB === undefined) {
9
- return true
10
- }
11
- const { colliderMatrix } = GameWorld.Instance.systems.get(CollideSystem)
12
- return colliderMatrix[groupA][groupB]
13
- }
14
-
15
- export function getMin(arr: number[]): number | null {
16
- if (arr.length === 0) return null;
17
-
18
- let min = arr[0];
19
- for (let i = 1; i < arr.length; i++) {
20
- if (arr[i] < min) {
21
- min = arr[i];
22
- }
23
- }
24
- return min;
25
- }
26
-
27
- export function getMax(arr: number[]): number | null {
28
- if (arr.length === 0) return null;
29
-
30
- let max = arr[0];
31
- for (let i = 1; i < arr.length; i++) {
32
- if (arr[i] > max) {
33
- max = arr[i];
34
- }
35
- }
36
- return max;
37
- }
@@ -1,16 +0,0 @@
1
- import { GameWorld } from '..'
2
- import { CollideSystem, enabledDebugDraw } from './CollideSystem'
3
-
4
- export * from './CollideComponent'
5
- export * from './CollideSystem'
6
-
7
- export function setupCollider(colliderMatrix?, debug = false) {
8
- GameWorld.Instance.systems.add(CollideSystem)
9
- GameWorld.Instance.listUpdate.push(CollideSystem)
10
- GameWorld.Instance.systems.configureOnce(CollideSystem)
11
- const collideSystem = GameWorld.Instance.systems.get(CollideSystem)
12
- if (colliderMatrix) {
13
- collideSystem.colliderMatrix = colliderMatrix
14
- }
15
- enabledDebugDraw(debug)
16
- }
@@ -1,17 +0,0 @@
1
- import { Container } from 'pixi.js'
2
- import { EnhancedComponent, GameWorld } from '../base'
3
-
4
- import { NodeComp } from './NodeComp'
5
-
6
- export class NoRenderComponentX<Props = {}, C extends Container = Container> extends EnhancedComponent<Props, NodeComp<C>> {
7
- }
8
-
9
- export class ComponentX<Props = {}, C extends Container = Container> extends EnhancedComponent<Props, NodeComp<C>> {
10
- static hasRender = true
11
- render?(): this {
12
- const world = GameWorld.Instance
13
- const root = world.entities.create()
14
- const comp = root.assign(this)
15
- return comp
16
- }
17
- }
@@ -1,442 +0,0 @@
1
- import { Constructor, Entity } from 'entityx-ts'
2
- import { Action, actionManager, Animation } from 'pixi-action-ease'
3
- import { Color, ColorSource, Container, Point, Sprite, Text } from 'pixi.js'
4
-
5
- import { ComponentType, EnhancedComponent, instantiate } from '../base'
6
- import { updatePoint, Vec2 } from '../core'
7
- import { Size } from '../core/Size'
8
- import { ProgressBarComp } from '../gui/GUIComponent'
9
- import { ExtraDataComp } from '../norender/NoRenderComponent'
10
-
11
- export type EventCallbackType = (...args) => void
12
- export interface EventMap {
13
- [key: string]: [EventCallbackType]
14
- }
15
-
16
- type TouchEventCallback = (target: { location: Vec2 }) => void
17
-
18
- export class NodeComp<C extends Container = Container> {
19
- entity: Entity
20
- instance: C
21
- events: EventMap = {}
22
- data: { [key: string]: any } = {}
23
- parent: NodeComp
24
- children: NodeComp[] = []
25
- actionsList: Animation[] = []
26
- // offset: cc.Point = cc.v2(0, 0);
27
- name: string
28
- // private lastMove: { x: number; y: number }
29
- private _group = 0
30
- private _active = true
31
-
32
- onTouchStart?: TouchEventCallback
33
- onTouchMove?: TouchEventCallback
34
- onTouchEnd?: TouchEventCallback
35
- onTouchCancel?: TouchEventCallback
36
-
37
- setOnTouchStart(cb: TouchEventCallback) {
38
- this.onTouchStart = cb
39
- this.instance.on('touchstart', (event) => {
40
- const { global } = event
41
- this.onTouchStart({ location: updatePoint(global) })
42
- })
43
- }
44
-
45
- setOnTouchMove(cb: TouchEventCallback) {
46
- this.onTouchMove = cb
47
- this.instance.on('touchmove', (event) => {
48
- const { global } = event
49
- this.onTouchMove({ location: updatePoint(global) })
50
- })
51
- }
52
-
53
- setOnTouchEnd(cb: TouchEventCallback) {
54
- this.onTouchEnd = cb
55
- this.instance.on('touchend', (event) => {
56
- const { global } = event
57
- this.onTouchEnd({ location: updatePoint(global) })
58
- })
59
- }
60
-
61
- setOnTouchCancel(cb: TouchEventCallback) {
62
- this.onTouchCancel = cb
63
- this.instance.on('touchcancel', (event) => {
64
- const { global } = event
65
- this.onTouchCancel({ location: updatePoint(global) })
66
- })
67
- }
68
-
69
- constructor(instance: C, entity: Entity) {
70
- this.entity = entity
71
- this.instance = instance
72
- this.instance.eventMode = 'static'
73
- }
74
-
75
- get uuid() {
76
- return this.entity.id
77
- }
78
-
79
- get position(): Vec2 {
80
- return this.getPosition()
81
- }
82
-
83
- set position(val: Vec2) {
84
- this.setPosition(val.x, val.y)
85
- }
86
-
87
- get posX() {
88
- return this.instance.x
89
- }
90
-
91
- set posX(val: number) {
92
- this.instance.x = val
93
- }
94
-
95
- get posY() {
96
- return this.instance.y
97
- }
98
-
99
- set posY(val: number) {
100
- this.instance.y = val
101
- }
102
-
103
- set xy(val: [number, number]) {
104
- this.setPosition(val[0], val[1])
105
- }
106
-
107
- get scale() {
108
- return this.instance.scale.x
109
- }
110
-
111
- set scale(val: number) {
112
- this.instance.scale = new Point(val, val)
113
- }
114
-
115
- get scaleX() {
116
- return this.instance.scale.x
117
- }
118
-
119
- set scaleX(val: number) {
120
- this.instance.scale.x = val
121
- }
122
-
123
- get scaleY() {
124
- return this.instance.scale.y
125
- }
126
-
127
- set scaleY(val: number) {
128
- this.instance.scale.y = val
129
- }
130
-
131
- get anchorX() {
132
- if (this.instance instanceof Sprite || this.instance instanceof Text) return this.instance.anchor.x
133
- return 0
134
- }
135
-
136
- set anchorX(val: number) {
137
- if (this.instance instanceof Sprite || this.instance instanceof Text) this.instance.anchor.x = val
138
- }
139
-
140
- get anchorY() {
141
- if (this.instance instanceof Sprite || this.instance instanceof Text) return this.instance.anchor.y
142
- return 0
143
- }
144
-
145
- set anchorY(val: number) {
146
- if (this.instance instanceof Sprite || this.instance instanceof Text) this.instance.anchor.y = val
147
- }
148
-
149
- /** rotation is in radians */
150
- get rotation() {
151
- return this.instance.rotation
152
- }
153
- /** rotation is in radians */
154
- set rotation(val: number) {
155
- this.instance.rotation = val
156
- }
157
-
158
- /** angle is in degrees. */
159
- get angle() {
160
- return this.instance.angle
161
- }
162
- /** angle is in degrees. */
163
- set angle(val: number) {
164
- this.instance.angle = val
165
- }
166
-
167
- get color() {
168
- if (this.instance instanceof Sprite) return this.instance.tint
169
- if (this.instance instanceof Text) return this.instance.style.fill as ColorSource
170
- return 0xffffff
171
- }
172
-
173
- set color(val: ColorSource) {
174
- if (this.instance instanceof Sprite) this.instance.tint = val
175
- if (this.instance instanceof Text) this.instance.style.fill = val
176
- }
177
-
178
- get opacity() {
179
- return this.instance.alpha
180
- }
181
-
182
- set opacity(val: number) {
183
- this.instance.alpha = val
184
- }
185
-
186
- get active() {
187
- if (!this._active) return false
188
- let p = this.parent
189
- while (p) {
190
- if (!p.active) return false
191
- p = p.parent
192
- }
193
- return this.instance.visible && !this.instance.destroyed
194
- }
195
-
196
- set active(val: boolean) {
197
- this._active = val
198
- this.instance.visible = val
199
- }
200
-
201
- get group() {
202
- return this._group
203
- }
204
-
205
- set group(val: number) {
206
- this._group = val
207
- }
208
-
209
- get width() {
210
- return this.instance.width
211
- }
212
-
213
- set width(val) {
214
- this.instance.width = val
215
- }
216
-
217
- get height() {
218
- return this.instance.height
219
- }
220
-
221
- set height(val) {
222
- this.instance.height = val
223
- }
224
-
225
- get zIndex() {
226
- return this.instance.zIndex
227
- }
228
-
229
- set zIndex(val) {
230
- this.instance.zIndex = val
231
- }
232
-
233
- get childrenCount() {
234
- return this.children.length
235
- }
236
-
237
- addComponent<T extends ComponentType>(instance): T {
238
- return this.entity.assign(instance)
239
- }
240
-
241
- getComponent<T extends Constructor<ComponentType>>(component: T): InstanceType<T> {
242
- return this.entity.getComponent(component) as any
243
- }
244
-
245
- getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
246
- if (!this.children.length) {
247
- return []
248
- }
249
- const listHave = this.children.filter((child) => {
250
- return child.getComponent(component)
251
- })
252
- return listHave.map((node) => node.getComponent(component))
253
- }
254
-
255
- getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
256
- return this.getComponentsInChildren(component)[0]
257
- }
258
-
259
- convertToNodeSpace(point: Vec2) {
260
- return this.instance.toLocal(point)
261
- }
262
-
263
- convertToNodeSpaceAR(point: Vec2) {
264
- return this.instance.toLocal(point)
265
- }
266
-
267
- convertToWorldSpaceAR(point: Vec2) {
268
- return this.instance.toGlobal(point)
269
- }
270
-
271
- getPosition(): Vec2 {
272
- return updatePoint(this.instance.position)
273
- }
274
-
275
- setPosition(x: number | Point, y?: number) {
276
- if (typeof x !== 'number') {
277
- this.instance.position = Vec2(x.x, x.y)
278
- } else {
279
- this.instance.position = Vec2(x, y)
280
- }
281
- }
282
-
283
- setRotation(deg: number) {
284
- this.instance.rotation = deg
285
- }
286
-
287
- getRotation() {
288
- return this.instance.rotation
289
- }
290
-
291
- // setAnchorPoint(point: number | cc.Point, y?: number) {
292
- // this.instance.setAnchorPoint(point, y)
293
- // }
294
-
295
- // getAnchorPoint() {
296
- // return this.instance.getAnchorPoint()
297
- // }
298
-
299
- // getBoundingBox() {
300
- // const box = this.instance.getBoundingBox()
301
- // box.contains = function (point) {
302
- // return this.x <= point.x && this.x + this.width >= point.x && this.y <= point.y && this.y + this.height >= point.y
303
- // }
304
- // return box
305
- // }
306
-
307
- getContentSize(): Size {
308
- return this.instance.boundsArea
309
- }
310
-
311
- // setContentSize(size: cc.Size | number, height?: number) {
312
- // this.instance.setContentSize(size, height)
313
- // if (this.instance instanceof cc.ClippingNode) {
314
- // const hw = ((size as any).width || size) * 0.5
315
- // const hh = ((size as any).height || height) * 0.5
316
- // const stencil = new cc.DrawNode()
317
- // const rectangle = [cc.p(-hw, -hh), cc.p(hw, -hh), cc.p(hw, hh), cc.p(-hw, hh)]
318
- // stencil.drawPoly(rectangle, cc.Color.WHITE, 0, cc.Color.WHITE)
319
- // // stencil.drawDot(cc.p(-height * 0.5, -height * 0.5), height, cc.Color.WHITE);
320
- // this.instance.stencil = stencil
321
- // }
322
- // }
323
-
324
- setColor(color: Color) {
325
- if (this.instance instanceof Sprite) (this.instance as Sprite).tint = color
326
- }
327
-
328
- setScale(scaleX: number, scaleY?: number) {
329
- this.instance.scale.x = scaleX
330
- this.instance.scale.y = scaleY || scaleX
331
- }
332
-
333
- runAction(act: Action) {
334
- const animation = actionManager.runAction(this.instance as any, act)
335
- this.actionsList.push(animation)
336
- }
337
-
338
- stopAllActions() {
339
- this.actionsList.forEach((act) => {
340
- actionManager.cancelAction(act)
341
- })
342
- this.actionsList = []
343
- }
344
-
345
- pauseAllActions() {
346
- this.actionsList.forEach((anim: Animation) => {
347
- anim.isPause = true
348
- })
349
- }
350
-
351
- resumeAllActions() {
352
- this.actionsList.forEach((anim: Animation) => {
353
- anim.isPause = false
354
- })
355
- }
356
-
357
- destroy() {
358
- if (this.parent) {
359
- this.parent.children = this.parent.children.filter(({ entity }) => entity.id !== this.entity.id)
360
- }
361
- this.children.forEach((child) => {
362
- child.destroy()
363
- })
364
- this.parent = null
365
- this.entity.destroy()
366
- this.stopAllActions()
367
- this.instance.destroy()
368
- }
369
-
370
- removeFromParent() {
371
- this.active = false
372
- this.stopAllActions()
373
- this.instance.removeFromParent()
374
- }
375
-
376
- addChild(child: NodeComp, zOrder?: number) {
377
- child.parent = this
378
- child.active = true
379
- this.children.push(child)
380
- this.instance.addChild(child.instance)
381
- if (zOrder) child.zIndex = zOrder
382
- }
383
-
384
- destroyAllChildren() {
385
- this.children.forEach((child) => {
386
- child.destroy()
387
- })
388
- }
389
-
390
- removeAllChildren() {
391
- this.children.forEach((child) => {
392
- child.removeFromParent()
393
- })
394
- }
395
-
396
- on(name: string, callback: EventCallbackType, target?: any) {
397
- const bound = target ? callback.bind(target) : callback
398
- if (this.events[name]) {
399
- this.events[name].push(bound)
400
- } else {
401
- this.events[name] = [bound]
402
- }
403
- }
404
-
405
- off(name: string) {
406
- this.events[name] = undefined
407
- }
408
-
409
- emit(name: string, ...params: any) {
410
- if (this.events[name]) {
411
- this.events[name].forEach((fc) => fc(...params))
412
- }
413
- }
414
-
415
- resolveComponent(component: EnhancedComponent<object, NodeComp>) {
416
- // console.log(component.constructor.name, (component.constructor as any).hasRender)
417
- if ((component.constructor as any).hasRender) {
418
- this.addChild(component.node)
419
- } else {
420
- this.addComponent(component)
421
- if (component instanceof ProgressBarComp) {
422
- this.addChild(component.node)
423
- }
424
- }
425
- }
426
-
427
- getData<T>(key: string): T {
428
- const data = this.getComponent(ExtraDataComp)
429
- if (!data) return console.warn('need add ExtraDataComp to Node') as T
430
- return data.getData(key)
431
- }
432
-
433
- setData<T>(key: string, value: T) {
434
- const data = this.getComponent(ExtraDataComp)
435
- // console.log('setData', key, value, data)
436
- if (!data) {
437
- this.addComponent(instantiate(ExtraDataComp, { key, value }))
438
- } else {
439
- data.setData(key, value)
440
- }
441
- }
442
- }
@@ -1,17 +0,0 @@
1
- import { EnhancedComponent, GameWorld } from '../base'
2
-
3
- import { NodeComp } from './NodeComp'
4
-
5
- export class SceneComponent extends EnhancedComponent<{}, NodeComp> {
6
- render() {
7
- const world = GameWorld.Instance
8
- world.entities.reset()
9
- const root = world.entities.create()
10
- const node = root.assign(new NodeComp(GameWorld.Instance.app.stage, root))
11
- GameWorld.Instance.app.stage.eventMode = 'static';
12
- GameWorld.Instance.app.stage.hitArea = GameWorld.Instance.app.screen;
13
- const sceneComponent = root.assign(this)
14
- sceneComponent.node = node
15
- return sceneComponent
16
- }
17
- }
package/src/core/Color.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Color } from 'pixi.js';
2
-
3
- export function Color4B(r: number, g: number, b: number, a: number) {
4
- return new Color({ r, g, b, a })
5
- }
6
-
7
- export type Color4B = ReturnType<typeof Color4B>