@safe-engine/pixi 8.4.7 → 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 (92) 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/helper/utils.d.ts +0 -6
  21. package/dist/helper/utils.d.ts.map +1 -1
  22. package/dist/helper/utils.js +0 -12
  23. package/package.json +6 -2
  24. package/.github/workflows/npm-publish.yml +0 -35
  25. package/dist/@types/safex.d.ts +0 -15
  26. package/src/@types/index.d.ts +0 -2
  27. package/src/app.ts +0 -91
  28. package/src/base/EnhancedComponent.ts +0 -38
  29. package/src/base/gworld.ts +0 -20
  30. package/src/base/index.ts +0 -14
  31. package/src/base/utils.ts +0 -23
  32. package/src/box2d-wasm/ContactListener.ts +0 -66
  33. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  34. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  35. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  36. package/src/box2d-wasm/debugDraw.ts +0 -249
  37. package/src/box2d-wasm/index.ts +0 -19
  38. package/src/collider/CollideComponent.ts +0 -257
  39. package/src/collider/CollideSystem.ts +0 -166
  40. package/src/collider/helper/Intersection.ts +0 -139
  41. package/src/collider/helper/utils.ts +0 -37
  42. package/src/collider/index.ts +0 -16
  43. package/src/components/BaseComponent.ts +0 -17
  44. package/src/components/NodeComp.ts +0 -442
  45. package/src/components/Scene.ts +0 -17
  46. package/src/core/Color.ts +0 -7
  47. package/src/core/LoadingBar.ts +0 -63
  48. package/src/core/NodePool.ts +0 -28
  49. package/src/core/Size.ts +0 -21
  50. package/src/core/Vec2.ts +0 -108
  51. package/src/core/director.ts +0 -11
  52. package/src/core/index.ts +0 -7
  53. package/src/core/loader.ts +0 -14
  54. package/src/core/math.ts +0 -22
  55. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  56. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  57. package/src/dragonbones/index.ts +0 -11
  58. package/src/gui/GUIComponent.ts +0 -155
  59. package/src/gui/GUISystem.ts +0 -125
  60. package/src/helper/utils.ts +0 -50
  61. package/src/index.ts +0 -21
  62. package/src/norender/NoRenderComponent.ts +0 -60
  63. package/src/norender/NoRenderSystem.ts +0 -67
  64. package/src/norender/Touch.ts +0 -37
  65. package/src/planck/PhysicsComponent.ts +0 -83
  66. package/src/planck/PhysicsSprite.ts +0 -43
  67. package/src/planck/PhysicsSystem.ts +0 -201
  68. package/src/planck/index.ts +0 -3
  69. package/src/render/RenderComponent.ts +0 -132
  70. package/src/render/RenderSystem.ts +0 -64
  71. package/src/richtext/RichTextComp.ts +0 -50
  72. package/src/richtext/RichTextSystem.ts +0 -26
  73. package/src/richtext/html-text-parser.ts +0 -87
  74. package/src/richtext/index.ts +0 -8
  75. package/src/spine/SpineComponent.ts +0 -18
  76. package/src/spine/SpineSystem.ts +0 -30
  77. package/src/spine/index.ts +0 -11
  78. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  79. package/src/spine/lib/Spine.ts +0 -894
  80. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  81. package/src/spine/lib/SpinePipe.ts +0 -203
  82. package/src/spine/lib/SpineTexture.ts +0 -143
  83. package/src/spine/lib/assets/atlasLoader.ts +0 -158
  84. package/src/spine/lib/assets/skeletonLoader.ts +0 -81
  85. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  86. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  87. package/src/spine/lib/darktint/DarkTintShader.ts +0 -74
  88. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  89. package/src/spine/lib/index.ts +0 -43
  90. package/src/spine/lib/require-shim.ts +0 -43
  91. package/tsconfig.json +0 -18
  92. /package/{dist/@types → @types}/index.d.ts +0 -0
@@ -1,19 +0,0 @@
1
- import { GameWorld, Vec2 } from '..'
2
- import { PhysicsSystem } from './PhysicsSystem'
3
-
4
- export * from './PhysicsComponent'
5
- export * from './PhysicsSprite'
6
- export * from './PhysicsSystem'
7
-
8
- export function setupPhysics(world = GameWorld.Instance, isDebugDraw?: boolean, gravity?: Vec2) {
9
- console.log('app world', world.app)
10
- world.systems.add(PhysicsSystem)
11
- world.systems.configureOnce(PhysicsSystem)
12
- world.listUpdate.push(PhysicsSystem)
13
- if (isDebugDraw) {
14
- world.systems.get(PhysicsSystem).addDebug()
15
- }
16
- if (gravity) {
17
- world.systems.get(PhysicsSystem).gravity = gravity
18
- }
19
- }
@@ -1,257 +0,0 @@
1
- import { Graphics, Point, Rectangle, Size } from 'pixi.js'
2
-
3
- import { GameWorld } from '..'
4
- import { NoRenderComponentX } from '../components/BaseComponent'
5
- import { NodeComp } from '../components/NodeComp'
6
- import { v2 } from '../helper/utils'
7
- import { circleCircle, polygonCircle, polygonPolygon } from './helper/Intersection'
8
- import { getMax, getMin } from './helper/utils'
9
-
10
- function getNodeToWorldTransformAR(node: NodeComp) {
11
- const t = node.instance.worldTransform
12
- const x = node.instance.pivot.x * node.instance.width
13
- const y = node.instance.pivot.y * node.instance.height
14
- const transform = t.translate(x, y)
15
- return transform
16
- }
17
-
18
- function cloneRect(origin: Rectangle) {
19
- return new Rectangle(origin.x, origin.y, origin.width, origin.height)
20
- }
21
- interface ColliderProps {
22
- offset?: Point
23
- tag?: number
24
- enabled?: boolean
25
- onCollisionEnter?: (other: Collider) => void
26
- onCollisionExit?: (other: Collider) => void
27
- onCollisionStay?: (other: Collider) => void
28
- }
29
-
30
- export class Collider<T = ColliderProps> extends NoRenderComponentX<T> {
31
- _worldPoints: Point[] = []
32
- _worldPosition: Point
33
- _worldRadius
34
- _AABB: Rectangle = new Rectangle(0, 0, 0, 0)
35
- _preAabb: Rectangle = new Rectangle(0, 0, 0, 0)
36
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
- update(dt: number, draw?: Graphics) { }
38
- getAABB() {
39
- return this._AABB
40
- }
41
- get world() {
42
- return {
43
- points: this._worldPoints,
44
- preAabb: this._preAabb,
45
- }
46
- }
47
- }
48
-
49
- interface BoxColliderProps extends ColliderProps {
50
- width: number
51
- height: number
52
- }
53
- export class BoxCollider extends Collider<BoxColliderProps> {
54
-
55
- get size(): Size {
56
- return this.props
57
- }
58
-
59
- set size(s: Size) {
60
- this.props.width = s.width
61
- this.props.height = s.height
62
- }
63
-
64
- update(dt, draw: Graphics) {
65
- if (!this.node) {
66
- return
67
- }
68
- const { x, y } = this.props.offset || v2()
69
- // const hw = this.width * 0.5
70
- // const hh = this.height * 0.5
71
- const transform = getNodeToWorldTransformAR(this.node)
72
- // const dx = x - hw
73
- // const dy = y - hh
74
- const collider = this.getComponent(Collider)
75
- collider._worldPoints = [
76
- v2(x, y),
77
- v2(x, y + this.props.height),
78
- v2(x + this.props.width, y + this.props.height),
79
- v2(x + this.props.width, y)
80
- ].map(p => transform.apply(p))
81
- // console.log("_worldPoints", collider._worldPoints, rectTrs)
82
- // collider._worldPoints = collider._worldPoints.map(p => transform.apply(p))
83
- const listX = collider._worldPoints.map(({ x }) => x)
84
- const listY = collider._worldPoints.map(({ y }) => y)
85
- collider._preAabb = cloneRect(collider._AABB)
86
- collider._AABB.x = getMin(listX)
87
- collider._AABB.y = getMin(listY)
88
- collider._AABB.width = getMax(listX) - collider._AABB.x
89
- collider._AABB.height = getMax(listY) - collider._AABB.y
90
- if (draw) {
91
- // console.log("drawing", JSON.stringify(collider._worldPoints))
92
- const drawList = collider._worldPoints
93
- // draw.clear()
94
- draw.poly(drawList)
95
- // draw.fill({ color: '#fff', alpha: 0.3 })
96
- }
97
- }
98
- }
99
-
100
- interface CircleColliderProps extends ColliderProps {
101
- radius: number
102
- }
103
-
104
- export class CircleCollider extends Collider<CircleColliderProps> {
105
-
106
- update(dt, draw: Graphics) {
107
- if (!this.node) {
108
- return
109
- }
110
- const transform = getNodeToWorldTransformAR(this.node)
111
- const collider = this.getComponent(Collider)
112
- collider._worldRadius = this.props.radius * this.node.scaleX
113
- collider._worldPosition = transform.apply(this.props.offset)
114
- if (draw) {
115
- const { x } = collider._worldPosition
116
- const y = GameWorld.Instance.app.screen.height - collider._worldPosition.y
117
- draw.rect(x, y, 2, 2)
118
- draw.circle(x, y, collider._worldRadius)
119
- }
120
- collider._preAabb = cloneRect(collider._AABB)
121
- collider._AABB.x = collider._worldPosition.x - collider._worldRadius
122
- collider._AABB.y = collider._worldPosition.y - collider._worldRadius
123
- collider._AABB.width = collider._worldRadius * 2
124
- collider._AABB.height = collider._AABB.width
125
- // draw.drawRect(p(this._AABB.x, this._AABB.y),
126
- // p(this._worldPosition.x + this._worldRadius, this._worldPosition.y + this._worldRadius),
127
- // Color.WHITE, 3, Color.DEBUG_BORDER_COLOR);
128
- }
129
- }
130
-
131
-
132
- interface PolygonColliderProps extends ColliderProps {
133
- points: Array<Point>
134
- }
135
- export class PolygonCollider extends Collider<PolygonColliderProps> {
136
-
137
- get points(): Point[] {
138
- const { x, y } = this.props.offset
139
- const pointsList = this.props.points.map((p) => v2(p.x + x, p.y + y))
140
- return pointsList
141
- }
142
-
143
- set points(points: Point[]) {
144
- this.props.points = points
145
- }
146
-
147
- update(dt, draw: Graphics) {
148
- if (!this.node) {
149
- return
150
- }
151
- const transform = getNodeToWorldTransformAR(this.node)
152
- const collider = this.getComponent(Collider)
153
- collider._worldPoints = this.points.map((p) => transform.apply(p))
154
- // log(polyPoints);
155
- if (draw) {
156
- const drawList = collider._worldPoints.map(({ x, y }) => v2(x, GameWorld.Instance.app.screen.height - y))
157
- draw.poly(drawList)
158
- }
159
- const listX = collider._worldPoints.map(({ x }) => x)
160
- const listY = collider._worldPoints.map(({ y }) => y)
161
- collider._preAabb = cloneRect(collider._AABB)
162
- collider._AABB.x = getMin(listX)
163
- collider._AABB.y = getMin(listY)
164
- collider._AABB.width = getMax(listX) - collider._AABB.x
165
- collider._AABB.height = getMax(listY) - collider._AABB.y
166
- // draw.drawRect(p(this._AABB.x, this._AABB.y), p(max(listX), max(listY)),
167
- // Color.WHITE, 3, Color.DEBUG_BORDER_COLOR);
168
- }
169
- }
170
-
171
- export enum CollisionType {
172
- NONE,
173
- ENTER,
174
- STAY,
175
- EXIT,
176
- }
177
-
178
- function isPolygonCollider(col: Collider) {
179
- return col.getComponent(PolygonCollider) || col.getComponent(BoxCollider)
180
- }
181
- function isCircleCollider(col: Collider) {
182
- return col.getComponent(CircleCollider)
183
- }
184
-
185
- export class Contract {
186
- _collider1: Collider
187
- _collider2: Collider
188
- _touching: boolean
189
- _isPolygonPolygon: boolean
190
- _isCircleCircle: boolean
191
- _isPolygonCircle: boolean
192
-
193
- constructor(collider1: Collider, collider2: Collider) {
194
- this._collider1 = collider1
195
- this._collider2 = collider2
196
- const isCollider1Polygon = isPolygonCollider(collider1)
197
- const isCollider2Polygon = isPolygonCollider(collider2)
198
- const isCollider1Circle = isCircleCollider(collider1)
199
- const isCollider2Circle = isCircleCollider(collider2)
200
-
201
- if (isCollider1Polygon && isCollider2Polygon) {
202
- this._isPolygonPolygon = true
203
- } else if (isCollider1Circle && isCollider2Circle) {
204
- this._isCircleCircle = true
205
- } else if (isCollider1Polygon && isCollider2Circle) {
206
- this._isPolygonCircle = true
207
- } else if (isCollider1Circle && isCollider2Polygon) {
208
- this._isPolygonCircle = true
209
- this._collider1 = collider2
210
- this._collider2 = collider1
211
- }
212
- // log(this._isPolygonPolygon);
213
- }
214
-
215
- updateState() {
216
- const result = this.test()
217
-
218
- let type = CollisionType.NONE
219
- if (result && !this._touching) {
220
- this._touching = true
221
- type = CollisionType.ENTER
222
- } else if (result && this._touching) {
223
- type = CollisionType.STAY
224
- } else if (!result && this._touching) {
225
- this._touching = false
226
- type = CollisionType.EXIT
227
- }
228
- // console.log('updateState', result, this._touching, type)
229
- return type
230
- }
231
-
232
- test() {
233
- // if (!shouldCollider(this._collider1, this._collider2)) {
234
- // return false
235
- // }
236
- // log(this._collider1.getAABB(), this._collider2.getAABB());
237
- if (!this._collider1.getAABB().intersects(this._collider2.getAABB())) {
238
- return false
239
- }
240
-
241
- if (this._isPolygonPolygon) {
242
- return polygonPolygon(this._collider1._worldPoints, this._collider2._worldPoints)
243
- }
244
- if (this._isCircleCircle) {
245
- const p1 = this._collider1
246
- const p2 = this._collider2
247
- return circleCircle(p1._worldPosition, p1._worldRadius, p2._worldPosition, p2._worldRadius)
248
- }
249
-
250
- if (this._isPolygonCircle) {
251
- const p2 = this._collider2
252
- return polygonCircle(this._collider1._worldPoints, p2._worldPosition, p2._worldRadius)
253
- }
254
-
255
- return false
256
- }
257
- }
@@ -1,166 +0,0 @@
1
- import { EntityManager, EventManager, EventTypes, System } from 'entityx-ts'
2
- import { Color, Graphics } from 'pixi.js'
3
-
4
- import { GameWorld } from '../base'
5
- import { NodeComp } from '../components/NodeComp'
6
- import { BoxCollider, CircleCollider, Collider, CollisionType, Contract, PolygonCollider } from './CollideComponent'
7
-
8
- export function enabledDebugDraw(enable = true) {
9
- const collideSystem = GameWorld.Instance.systems.get(CollideSystem)
10
- collideSystem.enabledDebugDraw = enable
11
- }
12
-
13
- export class CollideSystem implements System {
14
- listColliders: Collider[] = []
15
- _contracts: Contract[] = []
16
- removeColliders: Collider[] = []
17
- debugGraphics: Graphics
18
- enabledDebugDraw = true
19
- enabled = true
20
- colliderMatrix = [[true]]
21
-
22
- configure(event_manager: EventManager) {
23
- event_manager.subscribe(EventTypes.ComponentAdded, BoxCollider, this.onAddCollider.bind(this))
24
- event_manager.subscribe(EventTypes.ComponentAdded, CircleCollider, this.onAddCollider.bind(this))
25
- event_manager.subscribe(EventTypes.ComponentAdded, PolygonCollider, this.onAddCollider.bind(this))
26
- event_manager.subscribe(EventTypes.ComponentRemoved, BoxCollider, this.onRemoveCollider.bind(this))
27
- event_manager.subscribe(EventTypes.ComponentRemoved, CircleCollider, this.onRemoveCollider.bind(this))
28
- event_manager.subscribe(EventTypes.ComponentRemoved, PolygonCollider, this.onRemoveCollider.bind(this))
29
- if (this.enabledDebugDraw) {
30
- this.debugGraphics = new Graphics()
31
- this.debugGraphics.setFillStyle({ color: new Color('white') })
32
- this.debugGraphics.width = 4
33
- this.debugGraphics.zIndex = 40
34
- }
35
- GameWorld.Instance.app.stage.addChild(this.debugGraphics)
36
- }
37
-
38
- update(entities: EntityManager, events: EventManager, dt: number) {
39
- if (!this.enabled) {
40
- return
41
- }
42
- this.listColliders.forEach((collider) => {
43
- if (!collider.node.active) {
44
- this.removeColliders.push(collider)
45
- }
46
- })
47
- // this.removeColliders.forEach((comp) => {
48
- // this.listColliders = this.listColliders.filter((col) => !col.isEqual(comp) && col.node.active)
49
- // this._contracts = this._contracts.filter((contract) => {
50
- // const col1 = contract._collider1
51
- // const col2 = contract._collider2
52
- // if (col1.isEqual(comp) || !col1.node.active) {
53
- // if (contract._touching) {
54
- // // contract._touching = false
55
- // if (col2.onCollisionExit) {
56
- // col2.onCollisionExit(col1)
57
- // }
58
- // }
59
- // return false
60
- // }
61
- // if (col2.isEqual(comp) || !col2.node.active) {
62
- // if (contract._touching) {
63
- // // contract._touching = false
64
- // if (col1.onCollisionExit) col1.onCollisionExit(col2)
65
- // }
66
- // return false
67
- // }
68
- // return true
69
- // })
70
- // })
71
- this.removeColliders = []
72
- const draw = this.enabledDebugDraw ? this.debugGraphics : undefined
73
- if (this.enabledDebugDraw) {
74
- draw.clear()
75
- }
76
- for (const entt of entities.entities_with_components(BoxCollider)) {
77
- const comp = entt.getComponent(BoxCollider)
78
- comp.update(dt, draw)
79
- }
80
- for (const entt of entities.entities_with_components(CircleCollider)) {
81
- const comp = entt.getComponent(CircleCollider)
82
- comp.update(dt, draw)
83
- }
84
- for (const entt of entities.entities_with_components(PolygonCollider)) {
85
- const comp = entt.getComponent(PolygonCollider)
86
- comp.update(dt, draw)
87
- }
88
- if (this.enabledDebugDraw) {
89
- // draw.clear()
90
- // draw.removeFromParent()
91
- // app.stage.addChild(draw)
92
- // console.log('enabledDebugDraw', this.debugGraphics)
93
- // this.debugGraphics.width = 4
94
- // this.debugGraphics.circle(500, 600, 450)
95
- this.debugGraphics.fill({ color: new Color('white'), alpha: 0.3 })
96
- }
97
- // console.log(this._contracts.length)
98
- this._contracts.forEach((contract) => {
99
- const col1 = contract._collider1
100
- const col2 = contract._collider2
101
- if (!col1.node || !col2.node || !col1.node.active || !col2.node.active) {
102
- return
103
- }
104
- const type = contract.updateState()
105
- if (!col1 || !col2) {
106
- return
107
- }
108
-
109
- switch (type) {
110
- case CollisionType.ENTER: {
111
- if (col1.props.onCollisionEnter) {
112
- col1.props.onCollisionEnter(col2)
113
- }
114
- if (col2.props.onCollisionEnter) {
115
- col2.props.onCollisionEnter(col1)
116
- }
117
- break
118
- }
119
- case CollisionType.STAY:
120
- if (col1.props.onCollisionStay) {
121
- col1.props.onCollisionStay(col2)
122
- }
123
- if (col2.props.onCollisionStay) {
124
- col2.props.onCollisionStay(col1)
125
- }
126
- break
127
- case CollisionType.EXIT:
128
- if (col1.props.onCollisionExit) {
129
- col1.props.onCollisionExit(col2)
130
- }
131
- if (col2.props.onCollisionExit) {
132
- col2.props.onCollisionExit(col1)
133
- }
134
- break
135
-
136
- default:
137
- break
138
- }
139
- })
140
- }
141
-
142
- addCollider(colliderPhysics: Collider) {
143
- this.listColliders.forEach((col) => {
144
- // if (shouldCollider(col, colliderPhysics)) {
145
- this._contracts.push(new Contract(col, colliderPhysics))
146
- // }
147
- })
148
- this.listColliders.push(colliderPhysics)
149
- }
150
-
151
- removeCollider(colliderPhysics: Collider) {
152
- this.removeColliders.push(colliderPhysics)
153
- }
154
- onAddCollider({ entity, component }) {
155
- console.log('ComponentAddedEvent', component)
156
- const collider = entity.assign(new Collider(component))
157
- collider.node = entity.getComponent(NodeComp)
158
- component.node = entity.getComponent(NodeComp)
159
- this.addCollider(collider)
160
- }
161
- onRemoveCollider({ entity, component }) {
162
- console.log('ComponentRemovedEvent', component)
163
- const collider = entity.getComponent(Collider)
164
- this.removeCollider(collider)
165
- }
166
- }
@@ -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
- }