@safe-engine/pixi 8.4.1 → 8.4.3

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 (68) hide show
  1. package/dist/app.d.ts +3 -3
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +3 -2
  4. package/dist/base/gworld.d.ts +2 -1
  5. package/dist/base/gworld.d.ts.map +1 -1
  6. package/dist/base/index.d.ts +8 -0
  7. package/dist/base/index.d.ts.map +1 -1
  8. package/dist/base/utils.d.ts.map +1 -1
  9. package/dist/box2d-wasm/PhysicsSystem.d.ts +2 -1
  10. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  11. package/dist/box2d-wasm/PhysicsSystem.js +6 -5
  12. package/dist/box2d-wasm/debugDraw.d.ts +1 -1
  13. package/dist/box2d-wasm/debugDraw.d.ts.map +1 -1
  14. package/dist/box2d-wasm/debugDraw.js +7 -7
  15. package/dist/components/NodeComp.d.ts +10 -8
  16. package/dist/components/NodeComp.d.ts.map +1 -1
  17. package/dist/components/NodeComp.js +17 -11
  18. package/dist/core/Vec2.d.ts +30 -0
  19. package/dist/core/Vec2.d.ts.map +1 -0
  20. package/dist/core/Vec2.js +88 -0
  21. package/dist/core/index.d.ts +7 -0
  22. package/dist/core/index.d.ts.map +1 -0
  23. package/dist/core/index.js +7 -0
  24. package/dist/core/loader.d.ts +3 -0
  25. package/dist/core/loader.d.ts.map +1 -0
  26. package/dist/core/loader.js +21 -0
  27. package/dist/core/math.d.ts +1 -0
  28. package/dist/core/math.d.ts.map +1 -1
  29. package/dist/core/math.js +9 -0
  30. package/dist/gui/GUISystem.d.ts.map +1 -1
  31. package/dist/gui/GUISystem.js +4 -4
  32. package/dist/index.d.ts +2 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +2 -5
  35. package/dist/norender/NoRenderComponent.d.ts +2 -2
  36. package/dist/norender/NoRenderComponent.d.ts.map +1 -1
  37. package/dist/norender/NoRenderSystem.d.ts.map +1 -1
  38. package/dist/norender/NoRenderSystem.js +7 -6
  39. package/dist/norender/Touch.d.ts +32 -0
  40. package/dist/norender/Touch.d.ts.map +1 -0
  41. package/dist/norender/Touch.js +32 -0
  42. package/dist/render/RenderComponent.d.ts +3 -3
  43. package/dist/render/RenderComponent.d.ts.map +1 -1
  44. package/dist/render/RenderComponent.js +18 -28
  45. package/dist/render/RenderSystem.d.ts.map +1 -1
  46. package/dist/render/RenderSystem.js +3 -2
  47. package/package.json +2 -1
  48. package/src/app.ts +10 -4
  49. package/src/base/gworld.ts +2 -1
  50. package/src/base/index.ts +11 -0
  51. package/src/base/utils.ts +4 -4
  52. package/src/box2d-wasm/PhysicsSystem.ts +45 -48
  53. package/src/box2d-wasm/debugDraw.ts +80 -88
  54. package/src/components/NodeComp.ts +30 -30
  55. package/src/core/Vec2.ts +108 -0
  56. package/src/core/index.ts +7 -0
  57. package/src/core/loader.ts +12 -0
  58. package/src/core/math.ts +9 -0
  59. package/src/gui/GUISystem.ts +15 -9
  60. package/src/index.ts +3 -5
  61. package/src/norender/NoRenderComponent.ts +2 -2
  62. package/src/norender/NoRenderSystem.ts +12 -11
  63. package/src/norender/Touch.ts +37 -0
  64. package/src/render/RenderComponent.ts +35 -41
  65. package/src/render/RenderSystem.ts +5 -8
  66. package/dist/helper/html-text-parser.d.ts +0 -20
  67. package/dist/helper/html-text-parser.d.ts.map +0 -1
  68. package/dist/helper/html-text-parser.js +0 -64
@@ -1,4 +1,6 @@
1
- import { Color4B, Graphics } from "..";
1
+ import { Graphics } from 'pixi.js'
2
+
3
+ import { Color4B } from '..'
2
4
 
3
5
  /**
4
6
  * Forked from Box2D.js
@@ -22,16 +24,15 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
22
24
  b2Transform,
23
25
  b2Vec2,
24
26
  JSDraw,
25
- wrapPointer
26
- } = box2D;
27
+ wrapPointer,
28
+ } = box2D
27
29
 
28
30
  /**
29
31
  * to replace original C++ operator =
30
32
  * @param {Box2D.b2Vec2} vec
31
33
  * @returns {Box2D.b2Vec2}
32
34
  */
33
- const copyVec2 = (vec: Box2D.b2Vec2) =>
34
- new b2Vec2(vec.get_x(), vec.get_y());
35
+ const copyVec2 = (vec: Box2D.b2Vec2) => new b2Vec2(vec.get_x(), vec.get_y())
35
36
 
36
37
  /**
37
38
  * to replace original C++ operator *= (float)
@@ -39,28 +40,27 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
39
40
  * @param {number} scale
40
41
  * @returns {Box2D.b2Vec2}
41
42
  */
42
- const scaledVec2 = (vec: Box2D.b2Vec2, scale: number) =>
43
- new b2Vec2(scale * vec.get_x(), scale * vec.get_y());
43
+ const scaledVec2 = (vec: Box2D.b2Vec2, scale: number) => new b2Vec2(scale * vec.get_x(), scale * vec.get_y())
44
44
 
45
45
  /**
46
46
  * @param {Box2D.b2Color} color
47
47
  * @returns {string}
48
48
  */
49
49
  const getRgbStr = (color: Box2D.b2Color) => {
50
- const red = (color.get_r() * 255) | 0;
51
- const green = (color.get_g() * 255) | 0;
52
- const blue = (color.get_b() * 255) | 0;
53
- return Color4B(red, green, blue, 0.1);
54
- };
50
+ const red = (color.get_r() * 255) | 0
51
+ const green = (color.get_g() * 255) | 0
52
+ const blue = (color.get_b() * 255) | 0
53
+ return Color4B(red, green, blue, 0.1)
54
+ }
55
55
 
56
56
  /**
57
57
  * @param {string} rgbStr
58
58
  * @returns {void}
59
59
  */
60
60
  const setCtxColor = (rgbStr: Color4B) => {
61
- graphics.fillStyle = rgbStr;
62
- graphics.strokeStyle = { color: rgbStr };
63
- };
61
+ graphics.fillStyle = rgbStr
62
+ graphics.strokeStyle = { color: rgbStr }
63
+ }
64
64
 
65
65
  /**
66
66
  * @param {Box2D.b2Vec2[]} vertices
@@ -70,13 +70,12 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
70
70
  const drawPolygon = (vertices, fill) => {
71
71
  // console.log("drawPolygon", vertices[0].y, fill);
72
72
  // graphics.poly(vertices, fill)
73
- graphics.moveTo(vertices[vertices.length - 1].x * pixelsPerMeter,
74
- vertices[vertices.length - 1].y * pixelsPerMeter);
73
+ graphics.moveTo(vertices[vertices.length - 1].x * pixelsPerMeter, vertices[vertices.length - 1].y * pixelsPerMeter)
75
74
  vertices.forEach((v) => {
76
- graphics.lineTo(v.x * pixelsPerMeter, v.y * pixelsPerMeter);
75
+ graphics.lineTo(v.x * pixelsPerMeter, v.y * pixelsPerMeter)
77
76
  })
78
77
  graphics.fill()
79
- };
78
+ }
80
79
 
81
80
  /**
82
81
  * @param {Box2D.b2Vec2} center
@@ -87,22 +86,22 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
87
86
  */
88
87
  const drawCircle = (center, radius, axis, fill) => {
89
88
  // graphics.circle(center.x, center.y, radius)
90
- let angle = 0;
91
- const angleStep = 32;
92
- const n = 360 / angleStep;
93
- let x = radius * Math.cos(angle * Math.PI / 180);
94
- let y = radius * Math.sin(angle * Math.PI / 180);
95
- graphics.moveTo(center.x + x, center.y + y);
96
- angle += angleStep;
89
+ let angle = 0
90
+ const angleStep = 32
91
+ const n = 360 / angleStep
92
+ let x = radius * Math.cos((angle * Math.PI) / 180)
93
+ let y = radius * Math.sin((angle * Math.PI) / 180)
94
+ graphics.moveTo(center.x + x, center.y + y)
95
+ angle += angleStep
97
96
 
98
97
  for (let i = 0; i < n; i++) {
99
- x = radius * Math.cos(angle * Math.PI / 180);
100
- y = radius * Math.sin(angle * Math.PI / 180);
101
- graphics.lineTo(center.x + x, center.y + y);
102
- angle += angleStep;
98
+ x = radius * Math.cos((angle * Math.PI) / 180)
99
+ y = radius * Math.sin((angle * Math.PI) / 180)
100
+ graphics.lineTo(center.x + x, center.y + y)
101
+ angle += angleStep
103
102
  }
104
103
  graphics.fill()
105
- };
104
+ }
106
105
 
107
106
  /**
108
107
  * @param {Box2D.b2Vec2} vert1
@@ -111,10 +110,10 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
111
110
  */
112
111
  const drawSegment = (vert1, vert2) => {
113
112
  // console.log("drawSegment", vert1, vert2)
114
- graphics.moveTo(vert1.get_x(), vert1.get_y());
115
- graphics.lineTo(vert2.get_x(), vert2.get_y());
116
- graphics.stroke();
117
- };
113
+ graphics.moveTo(vert1.get_x(), vert1.get_y())
114
+ graphics.lineTo(vert2.get_x(), vert2.get_y())
115
+ graphics.stroke()
116
+ }
118
117
 
119
118
  /**
120
119
  * @param {Box2D.b2Vec2} vertex
@@ -122,14 +121,9 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
122
121
  * @returns {void}
123
122
  */
124
123
  const drawPoint = (vertex, sizeMetres) => {
125
- const sizePixels = sizeMetres / pixelsPerMeter;
126
- graphics.rect(
127
- vertex.get_x() - sizePixels / 2,
128
- vertex.get_y() - sizePixels / 2,
129
- sizePixels,
130
- sizePixels
131
- );
132
- };
124
+ const sizePixels = sizeMetres / pixelsPerMeter
125
+ graphics.rect(vertex.get_x() - sizePixels / 2, vertex.get_y() - sizePixels / 2, sizePixels, sizePixels)
126
+ }
133
127
 
134
128
  /**
135
129
  * @param {Box2D.b2Transform} transform
@@ -137,19 +131,19 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
137
131
  * @returns {void}
138
132
  */
139
133
  const drawTransform = (transform: Box2D.b2Transform) => {
140
- const pos = transform.get_p();
141
- const rot = transform.get_q();
134
+ const pos = transform.get_p()
135
+ const rot = transform.get_q()
142
136
 
143
- graphics.save();
144
- graphics.translateTransform(pos.get_x(), pos.get_y());
145
- graphics.scaleTransform(0.5, 0.5);
146
- graphics.rotateTransform(rot.GetAngle());
137
+ graphics.save()
138
+ graphics.translateTransform(pos.get_x(), pos.get_y())
139
+ graphics.scaleTransform(0.5, 0.5)
140
+ graphics.rotateTransform(rot.GetAngle())
147
141
  // graphics.lineWidth *= 2;
148
- graphics.restore();
142
+ graphics.restore()
149
143
  }
150
144
 
151
145
  /** {@link Box2D.b2Vec2} is a struct of `float x, y` */
152
- const sizeOfB2Vec = Float32Array.BYTES_PER_ELEMENT * 2;
146
+ const sizeOfB2Vec = Float32Array.BYTES_PER_ELEMENT * 2
153
147
 
154
148
  /**
155
149
  * @param {number} array_p pointer to {@link Box2D.b2Vec2}
@@ -161,9 +155,7 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
161
155
  const reifyArray = (array_p, numElements, sizeOfElement, ctor) =>
162
156
  Array(numElements)
163
157
  .fill(undefined)
164
- .map((_, index) =>
165
- wrapPointer(array_p + index * sizeOfElement, ctor)
166
- );
158
+ .map((_, index) => wrapPointer(array_p + index * sizeOfElement, ctor))
167
159
 
168
160
  const debugDraw = Object.assign(new JSDraw(), {
169
161
  /**
@@ -173,11 +165,11 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
173
165
  * @returns {void}
174
166
  */
175
167
  DrawSegment(vert1_p, vert2_p, color_p) {
176
- const color = wrapPointer(color_p, b2Color);
177
- setCtxColor(getRgbStr(color));
178
- const vert1 = wrapPointer(vert1_p, b2Vec2);
179
- const vert2 = wrapPointer(vert2_p, b2Vec2);
180
- drawSegment(vert1, vert2);
168
+ const color = wrapPointer(color_p, b2Color)
169
+ setCtxColor(getRgbStr(color))
170
+ const vert1 = wrapPointer(vert1_p, b2Vec2)
171
+ const vert2 = wrapPointer(vert2_p, b2Vec2)
172
+ drawSegment(vert1, vert2)
181
173
  },
182
174
  /**
183
175
  * @param {number} vertices_p pointer to Array<{@link Box2D.b2Vec2}>
@@ -186,10 +178,10 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
186
178
  * @returns {void}
187
179
  */
188
180
  DrawPolygon(vertices_p, vertexCount, color_p) {
189
- const color = wrapPointer(color_p, b2Color);
190
- setCtxColor(getRgbStr(color));
191
- const vertices = reifyArray(vertices_p, vertexCount, sizeOfB2Vec, b2Vec2);
192
- drawPolygon(vertices, false);
181
+ const color = wrapPointer(color_p, b2Color)
182
+ setCtxColor(getRgbStr(color))
183
+ const vertices = reifyArray(vertices_p, vertexCount, sizeOfB2Vec, b2Vec2)
184
+ drawPolygon(vertices, false)
193
185
  // console.log(`DrawPolygon`, getRgbStr(color).green, vertices[0].y)
194
186
  },
195
187
  /**
@@ -199,10 +191,10 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
199
191
  * @returns {void}
200
192
  */
201
193
  DrawSolidPolygon(vertices_p, vertexCount, color_p) {
202
- const color = wrapPointer(color_p, b2Color);
203
- setCtxColor(getRgbStr(color));
204
- const vertices = reifyArray(vertices_p, vertexCount, sizeOfB2Vec, b2Vec2);
205
- drawPolygon(vertices, true);
194
+ const color = wrapPointer(color_p, b2Color)
195
+ setCtxColor(getRgbStr(color))
196
+ const vertices = reifyArray(vertices_p, vertexCount, sizeOfB2Vec, b2Vec2)
197
+ drawPolygon(vertices, true)
206
198
  },
207
199
  /**
208
200
  * @param {number} center_p pointer to {@link Box2D.b2Vec2}
@@ -211,11 +203,11 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
211
203
  * @returns {void}
212
204
  */
213
205
  DrawCircle(center_p, radius, color_p) {
214
- const color = wrapPointer(color_p, b2Color);
215
- setCtxColor(getRgbStr(color));
216
- const center = wrapPointer(center_p, b2Vec2);
217
- const dummyAxis = new b2Vec2(0, 0);
218
- drawCircle(center, radius, dummyAxis, false);
206
+ const color = wrapPointer(color_p, b2Color)
207
+ setCtxColor(getRgbStr(color))
208
+ const center = wrapPointer(center_p, b2Vec2)
209
+ const dummyAxis = new b2Vec2(0, 0)
210
+ drawCircle(center, radius, dummyAxis, false)
219
211
  },
220
212
  /**
221
213
  * @param {number} center_p pointer to {@link Box2D.b2Vec2}
@@ -225,19 +217,19 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
225
217
  * @returns {void}
226
218
  */
227
219
  DrawSolidCircle(center_p, radius, axis_p, color_p) {
228
- const color = wrapPointer(color_p, b2Color);
229
- setCtxColor(getRgbStr(color));
230
- const center = wrapPointer(center_p, b2Vec2);
231
- const axis = wrapPointer(axis_p, b2Vec2);
232
- drawCircle(center, radius, axis, true);
220
+ const color = wrapPointer(color_p, b2Color)
221
+ setCtxColor(getRgbStr(color))
222
+ const center = wrapPointer(center_p, b2Vec2)
223
+ const axis = wrapPointer(axis_p, b2Vec2)
224
+ drawCircle(center, radius, axis, true)
233
225
  },
234
226
  /**
235
227
  * @param {number} transform_p pointer to {@link Box2D.b2Transform}
236
228
  * @returns {void}
237
229
  */
238
230
  DrawTransform(transform_p) {
239
- const transform = wrapPointer(transform_p, b2Transform);
240
- drawTransform(transform);
231
+ const transform = wrapPointer(transform_p, b2Transform)
232
+ drawTransform(transform)
241
233
  },
242
234
  /**
243
235
  * @param {number} vertex_p pointer to {@link Box2D.b2Vec2}
@@ -246,12 +238,12 @@ export const makeDebugDraw = (graphics: Graphics, pixelsPerMeter, box2D: typeof
246
238
  * @returns {void}
247
239
  */
248
240
  DrawPoint(vertex_p, sizeMetres, color_p) {
249
- const color = wrapPointer(color_p, b2Color);
250
- setCtxColor(getRgbStr(color));
251
- const vertex = wrapPointer(vertex_p, b2Vec2);
252
- drawPoint(vertex, sizeMetres);
253
- }
254
- });
255
- debugDraw.SetFlags(e_shapeBit);
256
- return debugDraw;
257
- };
241
+ const color = wrapPointer(color_p, b2Color)
242
+ setCtxColor(getRgbStr(color))
243
+ const vertex = wrapPointer(vertex_p, b2Vec2)
244
+ drawPoint(vertex, sizeMetres)
245
+ },
246
+ })
247
+ debugDraw.SetFlags(e_shapeBit)
248
+ return debugDraw
249
+ }
@@ -1,8 +1,9 @@
1
1
  import { Constructor, Entity } from 'entityx-ts'
2
2
  import { Action, actionManager, Animation } from 'pixi-action-ease'
3
3
  import { Color, ColorSource, Container, Point, Sprite, Text } from 'pixi.js'
4
- import { ComponentType, EnhancedComponent, instantiate } from '../base'
5
4
 
5
+ import { ComponentType, EnhancedComponent, instantiate } from '../base'
6
+ import { updatePoint, Vec2 } from '../core'
6
7
  import { Size } from '../core/Size'
7
8
  import { ProgressBarComp } from '../gui/GUIComponent'
8
9
  import { ExtraDataComp } from '../norender/NoRenderComponent'
@@ -12,7 +13,7 @@ export interface EventMap {
12
13
  [key: string]: [EventCallbackType]
13
14
  }
14
15
 
15
- type TouchEventCallback = (target: { location: Point }) => void
16
+ type TouchEventCallback = (target: { location: Vec2 }) => void
16
17
 
17
18
  export class NodeComp<C extends Container = Container> {
18
19
  entity: Entity
@@ -36,7 +37,7 @@ export class NodeComp<C extends Container = Container> {
36
37
  this.onTouchStart = cb
37
38
  this.instance.on('touchstart', (event) => {
38
39
  const { global } = event
39
- this.onTouchStart({ location: global })
40
+ this.onTouchStart({ location: updatePoint(global) })
40
41
  })
41
42
  }
42
43
 
@@ -44,7 +45,7 @@ export class NodeComp<C extends Container = Container> {
44
45
  this.onTouchMove = cb
45
46
  this.instance.on('touchmove', (event) => {
46
47
  const { global } = event
47
- this.onTouchMove({ location: global })
48
+ this.onTouchMove({ location: updatePoint(global) })
48
49
  })
49
50
  }
50
51
 
@@ -52,7 +53,7 @@ export class NodeComp<C extends Container = Container> {
52
53
  this.onTouchEnd = cb
53
54
  this.instance.on('touchend', (event) => {
54
55
  const { global } = event
55
- this.onTouchEnd({ location: global })
56
+ this.onTouchEnd({ location: updatePoint(global) })
56
57
  })
57
58
  }
58
59
 
@@ -60,7 +61,7 @@ export class NodeComp<C extends Container = Container> {
60
61
  this.onTouchCancel = cb
61
62
  this.instance.on('touchcancel', (event) => {
62
63
  const { global } = event
63
- this.onTouchCancel({ location: global })
64
+ this.onTouchCancel({ location: updatePoint(global) })
64
65
  })
65
66
  }
66
67
 
@@ -74,11 +75,11 @@ export class NodeComp<C extends Container = Container> {
74
75
  return this.entity.id
75
76
  }
76
77
 
77
- get position(): Point {
78
+ get position(): Vec2 {
78
79
  return this.getPosition()
79
80
  }
80
81
 
81
- set position(val: Point) {
82
+ set position(val: Vec2) {
82
83
  this.setPosition(val.x, val.y)
83
84
  }
84
85
 
@@ -127,25 +128,21 @@ export class NodeComp<C extends Container = Container> {
127
128
  }
128
129
 
129
130
  get anchorX() {
130
- if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
131
- return this.instance.anchor.x
131
+ if (this.instance instanceof Sprite || this.instance instanceof Text) return this.instance.anchor.x
132
132
  return 0
133
133
  }
134
134
 
135
135
  set anchorX(val: number) {
136
- if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
137
- this.instance.anchor.x = val
136
+ if (this.instance instanceof Sprite || this.instance instanceof Text) this.instance.anchor.x = val
138
137
  }
139
138
 
140
139
  get anchorY() {
141
- if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
142
- return this.instance.anchor.y
140
+ if (this.instance instanceof Sprite || this.instance instanceof Text) return this.instance.anchor.y
143
141
  return 0
144
142
  }
145
143
 
146
144
  set anchorY(val: number) {
147
- if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
148
- this.instance.anchor.y = val
145
+ if (this.instance instanceof Sprite || this.instance instanceof Text) this.instance.anchor.y = val
149
146
  }
150
147
 
151
148
  /** rotation is in radians */
@@ -167,10 +164,8 @@ export class NodeComp<C extends Container = Container> {
167
164
  }
168
165
 
169
166
  get color() {
170
- if (this.instance instanceof Sprite)
171
- return this.instance.tint
172
- if (this.instance instanceof Text)
173
- return this.instance.style.fill as ColorSource
167
+ if (this.instance instanceof Sprite) return this.instance.tint
168
+ if (this.instance instanceof Text) return this.instance.style.fill as ColorSource
174
169
  return 0xffffff
175
170
  }
176
171
 
@@ -253,27 +248,27 @@ export class NodeComp<C extends Container = Container> {
253
248
  return this.getComponentsInChildren(component)[0]
254
249
  }
255
250
 
256
- convertToNodeSpace(point: Point) {
251
+ convertToNodeSpace(point: Vec2) {
257
252
  return this.instance.toLocal(point)
258
253
  }
259
254
 
260
- convertToNodeSpaceAR(point: Point) {
255
+ convertToNodeSpaceAR(point: Vec2) {
261
256
  return this.instance.toLocal(point)
262
257
  }
263
258
 
264
- convertToWorldSpaceAR(point: Point) {
259
+ convertToWorldSpaceAR(point: Vec2) {
265
260
  return this.instance.toGlobal(point)
266
261
  }
267
262
 
268
- getPosition(): Point {
269
- return this.instance.position
263
+ getPosition(): Vec2 {
264
+ return updatePoint(this.instance.position)
270
265
  }
271
266
 
272
267
  setPosition(x: number | Point, y?: number) {
273
268
  if (typeof x !== 'number') {
274
- this.instance.position = new Point(x.x, x.y)
269
+ this.instance.position = Vec2(x.x, x.y)
275
270
  } else {
276
- this.instance.position = new Point(x, y)
271
+ this.instance.position = Vec2(x, y)
277
272
  }
278
273
  }
279
274
 
@@ -319,8 +314,7 @@ export class NodeComp<C extends Container = Container> {
319
314
  // }
320
315
 
321
316
  setColor(color: Color) {
322
- if (this.instance instanceof Sprite)
323
- (this.instance as Sprite).tint = color
317
+ if (this.instance instanceof Sprite) (this.instance as Sprite).tint = color
324
318
  }
325
319
 
326
320
  setScale(scaleX: number, scaleY?: number) {
@@ -385,6 +379,12 @@ export class NodeComp<C extends Container = Container> {
385
379
  })
386
380
  }
387
381
 
382
+ removeAllChildren() {
383
+ this.children.forEach((child) => {
384
+ child.removeFromParent()
385
+ })
386
+ }
387
+
388
388
  on(name: string, callback: EventCallbackType, target?: any) {
389
389
  const bound = target ? callback.bind(target) : callback
390
390
  if (this.events[name]) {
@@ -404,7 +404,7 @@ export class NodeComp<C extends Container = Container> {
404
404
  }
405
405
  }
406
406
 
407
- resolveComponent(component: EnhancedComponent<{}, NodeComp>) {
407
+ resolveComponent(component: EnhancedComponent<object, NodeComp>) {
408
408
  // console.log(component.constructor.name, (component.constructor as any).hasRender)
409
409
  if ((component.constructor as any).hasRender) {
410
410
  this.addChild(component.node)
@@ -0,0 +1,108 @@
1
+ import { Point } from 'pixi.js'
2
+
3
+ import { clampf } from './math'
4
+
5
+ export function updatePoint(p) {
6
+ const { x, y } = p
7
+ return Vec2(x, y)
8
+ }
9
+
10
+ class _Vec2 {
11
+ x: number
12
+ y: number
13
+ static ZERO
14
+ constructor(x: number | object = 0, y = 0) {
15
+ if (!(this instanceof _Vec2)) {
16
+ return new _Vec2(x, y)
17
+ }
18
+ if (typeof x === 'object') {
19
+ this.x = (x as any).x
20
+ this.y = (x as any).y
21
+ return
22
+ }
23
+ this.x = x
24
+ this.y = y
25
+ }
26
+
27
+ equals(other: _Vec2) {
28
+ return this.x === other.x && this.y === other.y
29
+ }
30
+
31
+ add(value: Point | Vec2): _Vec2 {
32
+ return updatePoint(new Point(this.x, this.y).add(value))
33
+ }
34
+
35
+ addSelf(value: Point | Vec2): _Vec2 {
36
+ const nor = updatePoint(new Point(this.x, this.y).add(value))
37
+ this.x = nor.x
38
+ this.y = nor.y
39
+ return nor
40
+ }
41
+
42
+ sub(value: Point | Vec2): _Vec2 {
43
+ return updatePoint(new Point(this.x, this.y).subtract(value))
44
+ }
45
+
46
+ mul(multiply: number): _Vec2 {
47
+ return updatePoint(new Point(this.x, this.y).multiply(new Point(multiply, multiply)))
48
+ }
49
+
50
+ mulSelf(multiply: number): _Vec2 {
51
+ const nor = updatePoint(new Point(this.x, this.y).multiply(new Point(multiply, multiply)))
52
+ this.x = nor.x
53
+ this.y = nor.y
54
+ return nor
55
+ }
56
+
57
+ mag(): number {
58
+ return new Point(this.x, this.y).magnitude()
59
+ }
60
+
61
+ normalizeSelf(): _Vec2 {
62
+ const nor = updatePoint(new Point(this.x, this.y).normalize())
63
+ this.x = nor.x
64
+ this.y = nor.y
65
+ return nor
66
+ }
67
+
68
+ normalize(): _Vec2 {
69
+ return updatePoint(new Point(this.x, this.y).normalize())
70
+ }
71
+
72
+ public cross(other: Vec2) {
73
+ return this.x * other.y - this.y * other.x
74
+ }
75
+ public signAngle(other: Vec2) {
76
+ const angle = this.angle(other)
77
+ return this.cross(other) < 0 ? -angle : angle
78
+ }
79
+ public lengthSqr() {
80
+ return this.x * this.x + this.y * this.y
81
+ }
82
+ public dot(other: Vec2) {
83
+ return this.x * other.x + this.y * other.y
84
+ }
85
+ public angle(other: Vec2) {
86
+ const magSqr1 = this.lengthSqr()
87
+ const magSqr2 = other.lengthSqr()
88
+
89
+ if (magSqr1 === 0 || magSqr2 === 0) {
90
+ console.warn('Cant get angle between zero vector')
91
+ return 0.0
92
+ }
93
+
94
+ const dot = this.dot(other)
95
+ let theta = dot / Math.sqrt(magSqr1 * magSqr2)
96
+ theta = clampf(theta, -1.0, 1.0)
97
+ return Math.acos(theta)
98
+ }
99
+ public distance(other: _Vec2) {
100
+ return this.sub(other).mag()
101
+ }
102
+ }
103
+ export type Vec2 = _Vec2
104
+ export function Vec2(x?: number | object, y?: number): Vec2 {
105
+ return new _Vec2(x, y)
106
+ }
107
+
108
+ Vec2.ZERO = Object.freeze(Vec2(0, 0))
@@ -0,0 +1,7 @@
1
+ export * from './Color'
2
+ export * from './director'
3
+ export * from './loader'
4
+ export * from './math'
5
+ export * from './NodePool'
6
+ // export * from './Size'
7
+ export * from './Vec2'
@@ -0,0 +1,12 @@
1
+ import { Assets } from 'pixi.js'
2
+
3
+ const jsonCache = {}
4
+ export async function loadJsonAsync<T>(filePath: string): Promise<T> {
5
+ const json = await Assets.load(filePath)
6
+ jsonCache[filePath] = json
7
+ return json
8
+ }
9
+
10
+ export function loadJsonFromCache<T>(filePath: string): T {
11
+ return jsonCache[filePath]
12
+ }
package/src/core/math.ts CHANGED
@@ -11,3 +11,12 @@ export function degreesToRadians(deg: Float) {
11
11
  export function radiansToDegrees(rad: Float) {
12
12
  return RAD_TO_DEG * rad
13
13
  }
14
+
15
+ export function clampf(theta: number, arg1: number, arg2: number): number {
16
+ if (theta < arg1) {
17
+ return arg1
18
+ } else if (theta > arg2) {
19
+ return arg2
20
+ }
21
+ return theta
22
+ }
@@ -1,16 +1,22 @@
1
1
  import { Button, CheckBox, List, RadioGroup, ScrollBox } from '@pixi/ui'
2
- import {
3
- EventManager,
4
- EventTypes,
5
- System
6
- } from 'entityx-ts'
2
+ import { EventManager, EventTypes, System } from 'entityx-ts'
7
3
  import { callFunc, easeBackIn, scaleTo, sequence } from 'pixi-action-ease'
8
4
  import { Text } from 'pixi.js'
9
5
 
10
6
  import { NodeComp } from '..'
11
7
  import { GameWorld } from '../base'
12
8
  import { LoadingBarMode, ProgressTimer } from '../core/LoadingBar'
13
- import { ButtonComp, CheckBoxComp, LabelComp, LabelOutlineComp, LabelShadowComp, ListComp, ProgressTimerComp, RadioGroupComp, ScrollView } from './GUIComponent'
9
+ import {
10
+ ButtonComp,
11
+ CheckBoxComp,
12
+ LabelComp,
13
+ LabelOutlineComp,
14
+ LabelShadowComp,
15
+ ListComp,
16
+ ProgressTimerComp,
17
+ RadioGroupComp,
18
+ ScrollView,
19
+ } from './GUIComponent'
14
20
 
15
21
  export class GUISystem implements System {
16
22
  defaultFont: string
@@ -89,9 +95,9 @@ export class GUISystem implements System {
89
95
  node.style.fill = '#fff'
90
96
  component.node = entity.assign(new NodeComp(node, entity))
91
97
  const { string = '', font = this.defaultFont, size = 64 } = component.props
92
- if (font) component.font = (font)
93
- component.size = (size)
94
- component.string = (string)
98
+ if (font) component.font = font
99
+ component.size = size
100
+ component.string = string
95
101
  })
96
102
  event_manager.subscribe(EventTypes.ComponentAdded, LabelOutlineComp, ({ entity, component }) => {
97
103
  const { color, width } = component.props
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from 'pixi-action-ease'
2
2
  export * from 'pixi.js'
3
- export { Vec2 } from 'planck'
4
3
  export * from './app'
5
4
  export * from './base'
6
5
  export * from './collider'
@@ -8,16 +7,15 @@ export * from './collider/helper/Intersection'
8
7
  export * from './components/BaseComponent'
9
8
  export * from './components/NodeComp'
10
9
  export * from './components/Scene'
11
- export * from './core/Color'
12
- export * from './core/director'
13
- export * from './core/math'
14
- export * from './core/NodePool'
10
+ export * from './core'
15
11
  export * from './dragonbones'
16
12
  export * from './gui/GUIComponent'
17
13
  export * from './gui/GUISystem'
18
14
  export * from './helper/utils'
19
15
  export * from './norender/NoRenderComponent'
16
+ export * from './norender/Touch'
20
17
  export * from './render/RenderComponent'
21
18
  export * from './render/RenderSystem'
22
19
  export * from './richtext'
23
20
  export * from './spine'
21
+