@safe-engine/pixi 8.4.6 → 8.5.1

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 (98) hide show
  1. package/README.md +14 -23
  2. package/dist/box2d-wasm/ContactListener.d.ts +1 -1
  3. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
  4. package/dist/box2d-wasm/ContactListener.js +50 -18
  5. package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
  6. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  7. package/dist/box2d-wasm/PhysicsComponent.js +44 -11
  8. package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
  9. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  10. package/dist/box2d-wasm/PhysicsSprite.js +24 -3
  11. package/dist/box2d-wasm/PhysicsSystem.d.ts +4 -2
  12. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  13. package/dist/box2d-wasm/PhysicsSystem.js +134 -44
  14. package/dist/collider/CollideComponent.d.ts +27 -10
  15. package/dist/collider/CollideComponent.d.ts.map +1 -1
  16. package/dist/collider/CollideComponent.js +10 -12
  17. package/dist/collider/helper/Intersection.d.ts +6 -6
  18. package/dist/collider/helper/Intersection.d.ts.map +1 -1
  19. package/dist/collider/helper/Intersection.js +4 -4
  20. package/dist/components/NodeComp.js +1 -1
  21. package/dist/helper/utils.d.ts +0 -6
  22. package/dist/helper/utils.d.ts.map +1 -1
  23. package/dist/helper/utils.js +0 -12
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -0
  27. package/{src/spine/lib/require-shim.ts → dist/spine/lib/assets/atlasLoader.d.ts} +5 -14
  28. package/dist/spine/lib/assets/atlasLoader.d.ts.map +1 -0
  29. package/dist/spine/lib/assets/atlasLoader.js +122 -0
  30. package/{src/spine/lib/darktint/DarkTintShader.ts → dist/spine/lib/assets/skeletonLoader.d.ts} +3 -47
  31. package/dist/spine/lib/assets/skeletonLoader.d.ts.map +1 -0
  32. package/dist/spine/lib/assets/skeletonLoader.js +70 -0
  33. package/package.json +6 -2
  34. package/.github/workflows/npm-publish.yml +0 -35
  35. package/dist/@types/safex.d.ts +0 -15
  36. package/src/@types/index.d.ts +0 -2
  37. package/src/app.ts +0 -91
  38. package/src/base/EnhancedComponent.ts +0 -38
  39. package/src/base/gworld.ts +0 -20
  40. package/src/base/index.ts +0 -14
  41. package/src/base/utils.ts +0 -23
  42. package/src/box2d-wasm/ContactListener.ts +0 -66
  43. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  44. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  45. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  46. package/src/box2d-wasm/debugDraw.ts +0 -249
  47. package/src/box2d-wasm/index.ts +0 -19
  48. package/src/collider/CollideComponent.ts +0 -257
  49. package/src/collider/CollideSystem.ts +0 -166
  50. package/src/collider/helper/Intersection.ts +0 -139
  51. package/src/collider/helper/utils.ts +0 -37
  52. package/src/collider/index.ts +0 -16
  53. package/src/components/BaseComponent.ts +0 -17
  54. package/src/components/NodeComp.ts +0 -442
  55. package/src/components/Scene.ts +0 -17
  56. package/src/core/Color.ts +0 -7
  57. package/src/core/LoadingBar.ts +0 -63
  58. package/src/core/NodePool.ts +0 -28
  59. package/src/core/Size.ts +0 -21
  60. package/src/core/Vec2.ts +0 -108
  61. package/src/core/director.ts +0 -11
  62. package/src/core/index.ts +0 -7
  63. package/src/core/loader.ts +0 -14
  64. package/src/core/math.ts +0 -22
  65. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  66. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  67. package/src/dragonbones/index.ts +0 -11
  68. package/src/gui/GUIComponent.ts +0 -155
  69. package/src/gui/GUISystem.ts +0 -125
  70. package/src/helper/utils.ts +0 -50
  71. package/src/index.ts +0 -19
  72. package/src/norender/NoRenderComponent.ts +0 -60
  73. package/src/norender/NoRenderSystem.ts +0 -67
  74. package/src/norender/Touch.ts +0 -37
  75. package/src/planck/PhysicsComponent.ts +0 -83
  76. package/src/planck/PhysicsSprite.ts +0 -43
  77. package/src/planck/PhysicsSystem.ts +0 -201
  78. package/src/planck/index.ts +0 -3
  79. package/src/render/RenderComponent.ts +0 -132
  80. package/src/render/RenderSystem.ts +0 -64
  81. package/src/richtext/RichTextComp.ts +0 -50
  82. package/src/richtext/RichTextSystem.ts +0 -26
  83. package/src/richtext/html-text-parser.ts +0 -87
  84. package/src/richtext/index.ts +0 -8
  85. package/src/spine/SpineComponent.ts +0 -18
  86. package/src/spine/SpineSystem.ts +0 -30
  87. package/src/spine/index.ts +0 -11
  88. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  89. package/src/spine/lib/Spine.ts +0 -894
  90. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  91. package/src/spine/lib/SpinePipe.ts +0 -203
  92. package/src/spine/lib/SpineTexture.ts +0 -143
  93. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  94. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  95. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  96. package/src/spine/lib/index.ts +0 -43
  97. package/tsconfig.json +0 -18
  98. /package/{dist/@types → @types}/index.d.ts +0 -0
@@ -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.x = 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>
@@ -1,63 +0,0 @@
1
- import { Container, Graphics, Point, Sprite, Texture } from 'pixi.js'
2
-
3
- export enum LoadingBarMode {
4
- BAR,
5
- RADIAL,
6
- }
7
-
8
- export class LoadingBar extends Graphics {
9
- spriteComp: Sprite
10
- mode: LoadingBarMode
11
- fillCenter = new Point(0.5, 0.5)
12
- constructor(mode: LoadingBarMode, spriteComp: Sprite) {
13
- super()
14
- this.spriteComp = spriteComp
15
- this.mode = mode || LoadingBarMode.BAR
16
- this.fill(0xffffff)
17
- this.rect(0, 0, spriteComp.width, spriteComp.height)
18
- spriteComp.mask = this
19
- spriteComp.addChild(this)
20
- }
21
-
22
- set progress(val: number) {
23
- this.clear()
24
- this.fill(0xffffff)
25
- if (this.mode === LoadingBarMode.BAR) {
26
- const spriteComp = this.spriteComp
27
- this.rect(0, 0, spriteComp.width * val, spriteComp.height)
28
- // console.log('new length', spriteComp.width)
29
- this.x = -spriteComp.width * 0.5
30
- this.y = -spriteComp.height * 0.5
31
- }
32
- }
33
- }
34
-
35
- export class ProgressTimer extends Container {
36
- graphics: Graphics
37
- spriteComp: Sprite
38
- mode: LoadingBarMode
39
- fillCenter = new Point(0.5, 0.5)
40
- constructor(mode: LoadingBarMode, spriteFrame: string) {
41
- super()
42
- const texture = Texture.from(spriteFrame)
43
- this.spriteComp = Sprite.from(texture)
44
- this.graphics = new Graphics()
45
- this.mode = mode || LoadingBarMode.BAR
46
- this.graphics.fill(0xffffff)
47
- this.graphics.rect(0, 0, this.spriteComp.width, this.spriteComp.height)
48
- this.spriteComp.mask = this.graphics
49
- this.addChild(this.graphics)
50
- this.addChild(this.spriteComp)
51
- // this.graphics.x = -this.spriteComp.width * this.fillCenter.x
52
- // this.graphics.y = -this.spriteComp.height * this.fillCenter.y
53
- }
54
-
55
- set progress(val: number) {
56
- this.graphics.clear()
57
- if (this.mode === LoadingBarMode.BAR) {
58
- this.graphics.rect(0, 0, this.spriteComp.width * val, this.spriteComp.height)
59
- // console.log('new length', this.width)
60
- this.graphics.fill(0xffffff)
61
- }
62
- }
63
- }
@@ -1,28 +0,0 @@
1
- import { NodeComp } from "../components/NodeComp"
2
-
3
- export class NodePool {
4
- items: NodeComp[] = []
5
-
6
- put(node: NodeComp) {
7
- if (node) {
8
- node.active = false
9
- node.removeFromParent()
10
- this.items.push(node)
11
- }
12
- }
13
-
14
- get(): NodeComp {
15
- const node = this.items.pop()
16
- node.active = true
17
- return node
18
- }
19
-
20
- size() {
21
- return this.items.length
22
- }
23
-
24
- clear() {
25
- this.items.forEach((node) => node.destroy())
26
- this.items.length = 0
27
- }
28
- }
package/src/core/Size.ts DELETED
@@ -1,21 +0,0 @@
1
- class _Size {
2
- width: number
3
- height: number
4
- static ZERO
5
- constructor(width = 0, height = 0) {
6
- if (!(this instanceof _Size)) {
7
- return new _Size(width, height)
8
- }
9
- if (height === undefined) {
10
- this.width = (width as any).width
11
- this.height = (width as any).height
12
- }
13
- this.width = width
14
- this.height = height
15
- }
16
- }
17
-
18
- export type Size = _Size
19
- export function Size(x?: number, y?: number): Size {
20
- return new _Size(x, y)
21
- }
package/src/core/Vec2.ts DELETED
@@ -1,108 +0,0 @@
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))
@@ -1,11 +0,0 @@
1
- // import { app } from "../app"
2
-
3
- import { GameWorld } from ".."
4
-
5
- export function pauseAll() {
6
- GameWorld.Instance.app.ticker.stop()
7
- }
8
-
9
- export function resumeAll() {
10
- GameWorld.Instance.app.ticker.start()
11
- }
package/src/core/index.ts DELETED
@@ -1,7 +0,0 @@
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'