@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.
- package/README.md +17 -25
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +0 -23
- package/dist/box2d-wasm/ContactListener.d.ts +1 -1
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
- package/dist/box2d-wasm/ContactListener.js +50 -18
- package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +44 -11
- package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSprite.js +24 -3
- package/dist/box2d-wasm/PhysicsSystem.d.ts +5 -3
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +135 -45
- package/dist/collider/CollideComponent.d.ts +27 -10
- package/dist/collider/CollideComponent.d.ts.map +1 -1
- package/dist/collider/CollideComponent.js +10 -12
- package/dist/collider/helper/Intersection.d.ts +6 -6
- package/dist/collider/helper/Intersection.d.ts.map +1 -1
- package/dist/collider/helper/Intersection.js +4 -4
- package/dist/collider/index.d.ts +1 -0
- package/dist/collider/index.d.ts.map +1 -1
- package/dist/collider/index.js +1 -0
- package/dist/components/NodeComp.d.ts +62 -36
- package/dist/components/NodeComp.d.ts.map +1 -1
- package/dist/components/NodeComp.js +18 -99
- package/dist/core/Color.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComponent.d.ts +3 -2
- package/dist/dragonbones/DragonBonesComponent.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComponent.js +1 -1
- package/dist/dragonbones/DragonBonesSystem.js +2 -2
- package/dist/gui/GUISystem.d.ts.map +1 -1
- package/dist/gui/GUISystem.js +5 -6
- package/dist/helper/utils.d.ts +0 -6
- package/dist/helper/utils.d.ts.map +1 -1
- package/dist/helper/utils.js +0 -12
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -5
- package/dist/norender/NoRenderComponent.d.ts +5 -1
- package/dist/norender/NoRenderComponent.d.ts.map +1 -1
- package/dist/norender/NoRenderSystem.d.ts.map +1 -1
- package/dist/norender/NoRenderSystem.js +8 -9
- package/dist/render/RenderComponent.d.ts +6 -17
- package/dist/render/RenderComponent.d.ts.map +1 -1
- package/dist/render/RenderComponent.js +26 -18
- package/dist/spine/lib/require-shim.d.ts.map +1 -1
- package/dist/spine/lib/require-shim.js +1 -1
- package/package.json +6 -7
- package/.github/workflows/npm-publish.yml +0 -35
- package/src/app.ts +0 -91
- package/src/base/EnhancedComponent.ts +0 -38
- package/src/base/gworld.ts +0 -20
- package/src/base/index.ts +0 -14
- package/src/base/utils.ts +0 -23
- package/src/box2d-wasm/ContactListener.ts +0 -66
- package/src/box2d-wasm/PhysicsComponent.ts +0 -83
- package/src/box2d-wasm/PhysicsSprite.ts +0 -42
- package/src/box2d-wasm/PhysicsSystem.ts +0 -142
- package/src/box2d-wasm/debugDraw.ts +0 -249
- package/src/box2d-wasm/index.ts +0 -19
- package/src/collider/CollideComponent.ts +0 -257
- package/src/collider/CollideSystem.ts +0 -166
- package/src/collider/helper/Intersection.ts +0 -139
- package/src/collider/helper/utils.ts +0 -37
- package/src/collider/index.ts +0 -16
- package/src/components/BaseComponent.ts +0 -17
- package/src/components/NodeComp.ts +0 -442
- package/src/components/Scene.ts +0 -17
- package/src/core/Color.ts +0 -7
- package/src/core/LoadingBar.ts +0 -63
- package/src/core/NodePool.ts +0 -28
- package/src/core/Size.ts +0 -21
- package/src/core/Vec2.ts +0 -108
- package/src/core/director.ts +0 -11
- package/src/core/index.ts +0 -7
- package/src/core/loader.ts +0 -14
- package/src/core/math.ts +0 -22
- package/src/dragonbones/DragonBonesComponent.ts +0 -32
- package/src/dragonbones/DragonBonesSystem.ts +0 -35
- package/src/dragonbones/index.ts +0 -11
- package/src/gui/GUIComponent.ts +0 -155
- package/src/gui/GUISystem.ts +0 -125
- package/src/helper/utils.ts +0 -50
- package/src/index.ts +0 -21
- package/src/norender/NoRenderComponent.ts +0 -60
- package/src/norender/NoRenderSystem.ts +0 -67
- package/src/norender/Touch.ts +0 -37
- package/src/planck/PhysicsComponent.ts +0 -83
- package/src/planck/PhysicsSprite.ts +0 -43
- package/src/planck/PhysicsSystem.ts +0 -201
- package/src/planck/index.ts +0 -3
- package/src/render/RenderComponent.ts +0 -132
- package/src/render/RenderSystem.ts +0 -64
- package/src/richtext/RichTextComp.ts +0 -50
- package/src/richtext/RichTextSystem.ts +0 -26
- package/src/richtext/html-text-parser.ts +0 -87
- package/src/richtext/index.ts +0 -8
- package/src/spine/SpineComponent.ts +0 -18
- package/src/spine/SpineSystem.ts +0 -30
- package/src/spine/index.ts +0 -11
- package/src/spine/lib/BatchableSpineSlot.ts +0 -138
- package/src/spine/lib/Spine.ts +0 -894
- package/src/spine/lib/SpineDebugRenderer.ts +0 -615
- package/src/spine/lib/SpinePipe.ts +0 -203
- package/src/spine/lib/SpineTexture.ts +0 -143
- package/src/spine/lib/assets/atlasLoader.ts +0 -158
- package/src/spine/lib/assets/skeletonLoader.ts +0 -81
- package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
- package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
- package/src/spine/lib/darktint/DarkTintShader.ts +0 -74
- package/src/spine/lib/darktint/darkTintBit.ts +0 -77
- package/src/spine/lib/index.ts +0 -43
- package/src/spine/lib/require-shim.ts +0 -43
- package/tsconfig.json +0 -18
- /package/{src/@types → @types}/index.d.ts +0 -0
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export * from 'pixi-action-ease'
|
|
2
|
-
export * from 'pixi.js'
|
|
3
|
-
export * from './app'
|
|
4
|
-
export * from './base'
|
|
5
|
-
export * from './collider'
|
|
6
|
-
export * from './collider/helper/Intersection'
|
|
7
|
-
export * from './components/BaseComponent'
|
|
8
|
-
export * from './components/NodeComp'
|
|
9
|
-
export * from './components/Scene'
|
|
10
|
-
export * from './core'
|
|
11
|
-
export * from './dragonbones'
|
|
12
|
-
export * from './gui/GUIComponent'
|
|
13
|
-
export * from './gui/GUISystem'
|
|
14
|
-
export * from './helper/utils'
|
|
15
|
-
export * from './norender/NoRenderComponent'
|
|
16
|
-
export * from './norender/Touch'
|
|
17
|
-
export * from './render/RenderComponent'
|
|
18
|
-
export * from './render/RenderSystem'
|
|
19
|
-
export * from './richtext'
|
|
20
|
-
export * from './spine'
|
|
21
|
-
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { NoRenderComponentX } from '../components/BaseComponent'
|
|
2
|
-
import { EventCallbackType, EventMap, NodeComp } from '../components/NodeComp'
|
|
3
|
-
import { Touch } from './Touch'
|
|
4
|
-
|
|
5
|
-
// export class Touch extends FederatedPointerEvent {
|
|
6
|
-
// declare getLocation: () => Vec2
|
|
7
|
-
// declare getDelta: () => Vec2
|
|
8
|
-
// }
|
|
9
|
-
|
|
10
|
-
export type TouchEventCallback = (touch?: Touch, node?: NodeComp) => void
|
|
11
|
-
|
|
12
|
-
export class EventRegister extends NoRenderComponentX {
|
|
13
|
-
events: EventMap = {}
|
|
14
|
-
|
|
15
|
-
on(name: string, callback: EventCallbackType, target?: any) {
|
|
16
|
-
const bound = target ? callback.bind(target) : callback
|
|
17
|
-
if (this.events[name]) {
|
|
18
|
-
this.events[name].push(bound)
|
|
19
|
-
} else {
|
|
20
|
-
this.events[name] = [bound]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
off(name: string, callback?: EventCallbackType, target?: any)
|
|
25
|
-
off(name: string) {
|
|
26
|
-
this.events[name] = undefined
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
emit(name: string, ...params: any) {
|
|
30
|
-
if (this.events[name]) {
|
|
31
|
-
this.events[name].forEach((fc) => fc(...params))
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface TouchEventProps {
|
|
37
|
-
onTouchStart?: TouchEventCallback
|
|
38
|
-
onTouchMove?: TouchEventCallback
|
|
39
|
-
onTouchEnd?: TouchEventCallback
|
|
40
|
-
onTouchCancel?: TouchEventCallback
|
|
41
|
-
}
|
|
42
|
-
export class TouchEventRegister extends NoRenderComponentX<TouchEventProps> {
|
|
43
|
-
listener: EventListener
|
|
44
|
-
touch: Touch
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface ExtraDataProps {
|
|
48
|
-
key: string
|
|
49
|
-
value: any
|
|
50
|
-
}
|
|
51
|
-
export class ExtraDataComp extends NoRenderComponentX<ExtraDataProps> {
|
|
52
|
-
data: { [key: string]: any } = {}
|
|
53
|
-
|
|
54
|
-
getData<T>(key: string): T {
|
|
55
|
-
return this.data[key]
|
|
56
|
-
}
|
|
57
|
-
setData<T>(key: string, val: T) {
|
|
58
|
-
this.data[key] = val
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { EventManager, EventTypes, System } from 'entityx-ts'
|
|
2
|
-
// import { Touch } from '../../polyfills'
|
|
3
|
-
import { Container } from 'pixi.js'
|
|
4
|
-
|
|
5
|
-
import { NodeComp } from '../components/NodeComp'
|
|
6
|
-
import { ExtraDataComp, TouchEventRegister } from './NoRenderComponent'
|
|
7
|
-
import { Touch } from './Touch'
|
|
8
|
-
|
|
9
|
-
export class NoRenderSystem implements System {
|
|
10
|
-
configure(event_manager: EventManager) {
|
|
11
|
-
event_manager.subscribe(EventTypes.ComponentAdded, ExtraDataComp, ({ component }) => {
|
|
12
|
-
const { key, value } = component.props
|
|
13
|
-
component.data[key] = value
|
|
14
|
-
})
|
|
15
|
-
event_manager.subscribe(EventTypes.ComponentAdded, TouchEventRegister, ({ entity, component }) => {
|
|
16
|
-
const ett = entity
|
|
17
|
-
const touchComp = component
|
|
18
|
-
const nodeComp = ett.getComponent(NodeComp)
|
|
19
|
-
touchComp.node = nodeComp
|
|
20
|
-
const container: Container = nodeComp.instance
|
|
21
|
-
if (touchComp.props.onTouchStart) {
|
|
22
|
-
container.on('pointerdown', (event) => {
|
|
23
|
-
touchComp.props.onTouchStart(new Touch(event), nodeComp)
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
if (touchComp.props.onTouchMove) {
|
|
27
|
-
container.on('pointermove', (event) => {
|
|
28
|
-
touchComp.props.onTouchMove(new Touch(event), nodeComp)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
if (touchComp.props.onTouchEnd) {
|
|
32
|
-
container.on('pointerup', (event) => {
|
|
33
|
-
touchComp.props.onTouchEnd(new Touch(event), nodeComp)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
if (touchComp.props.onTouchEnd) {
|
|
37
|
-
container.on('pointercancel', (event) => {
|
|
38
|
-
touchComp.props.onTouchEnd(new Touch(event), nodeComp)
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
event_manager.subscribe(EventTypes.ComponentRemoved, TouchEventRegister, ({ component }) => {
|
|
43
|
-
console.log('ComponentRemovedEvent TouchEventRegister', event)
|
|
44
|
-
// const ett = event.entity
|
|
45
|
-
// const nodeComp = ett.getComponent(NodeComp)
|
|
46
|
-
const touchComp = component as TouchEventRegister
|
|
47
|
-
const container: Container = touchComp.node.instance
|
|
48
|
-
if (touchComp.props.onTouchStart) {
|
|
49
|
-
container.removeListener('touchstart')
|
|
50
|
-
}
|
|
51
|
-
if (touchComp.props.onTouchMove) {
|
|
52
|
-
container.removeListener('touchmove')
|
|
53
|
-
}
|
|
54
|
-
if (touchComp.props.onTouchEnd) {
|
|
55
|
-
container.removeListener('touchend')
|
|
56
|
-
}
|
|
57
|
-
if (touchComp.props.onTouchEnd) {
|
|
58
|
-
container.removeListener('touchcancel')
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// update(entities: EntityManager, events: EventManager, dt: number)
|
|
64
|
-
// update() {
|
|
65
|
-
// throw new Error('Method not implemented.');
|
|
66
|
-
// }
|
|
67
|
-
}
|
package/src/norender/Touch.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { FederatedPointerEvent } from 'pixi.js'
|
|
2
|
-
|
|
3
|
-
import { Vec2 } from '..'
|
|
4
|
-
|
|
5
|
-
export class Touch {
|
|
6
|
-
private event: FederatedPointerEvent
|
|
7
|
-
constructor(event) {
|
|
8
|
-
this.event = event
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
getLocation(): ReturnType<typeof Vec2> {
|
|
12
|
-
return Vec2(this.event.global)
|
|
13
|
-
}
|
|
14
|
-
getLocationX() {
|
|
15
|
-
return this.event.globalX
|
|
16
|
-
}
|
|
17
|
-
getLocationY() {
|
|
18
|
-
return this.event.globalY
|
|
19
|
-
}
|
|
20
|
-
getDelta(): ReturnType<typeof Vec2> {
|
|
21
|
-
return Vec2(this.event.movementX, this.event.movementY)
|
|
22
|
-
}
|
|
23
|
-
getDeltaX() {
|
|
24
|
-
return this.event.movementX
|
|
25
|
-
}
|
|
26
|
-
getDeltaY() {
|
|
27
|
-
return this.event.movementY
|
|
28
|
-
}
|
|
29
|
-
getLocationInView(view: any) {
|
|
30
|
-
const { x, y } = this.event.global
|
|
31
|
-
return view.toLocal({ x, y })
|
|
32
|
-
}
|
|
33
|
-
getLocationInNode(node: any) {
|
|
34
|
-
const { x, y } = this.event.global
|
|
35
|
-
return node.toLocal({ x, y })
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Body, BodyType, Vec2 } from 'planck'
|
|
2
|
-
|
|
3
|
-
import { NoRenderComponentX } from '../components/BaseComponent'
|
|
4
|
-
import { PhysicsSprite } from './PhysicsSprite'
|
|
5
|
-
|
|
6
|
-
interface RigidBodyProps {
|
|
7
|
-
type?: BodyType
|
|
8
|
-
density?: Float
|
|
9
|
-
restitution?: Float
|
|
10
|
-
friction?: Float
|
|
11
|
-
gravityScale?: Float
|
|
12
|
-
}
|
|
13
|
-
export class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
14
|
-
body: Body
|
|
15
|
-
// set linearVelocity(vel: Vec2) {
|
|
16
|
-
// if (!this.node) {
|
|
17
|
-
// return
|
|
18
|
-
// }
|
|
19
|
-
// const physics = this.node.instance
|
|
20
|
-
// if (physics instanceof Sprite) {
|
|
21
|
-
// physics.getBody().setVel(vel)
|
|
22
|
-
// }
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
// get linearVelocity() {
|
|
26
|
-
// if (!this.node) {
|
|
27
|
-
// return Vec2.ZERO
|
|
28
|
-
// }
|
|
29
|
-
// const physics = this.node.instance
|
|
30
|
-
// const vel = (physics as Sprite).getBody().getVel()
|
|
31
|
-
// return v2(vel)
|
|
32
|
-
// }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface PhysicsMaterialProps {
|
|
36
|
-
friction?: number
|
|
37
|
-
restitution?: number
|
|
38
|
-
density?: number
|
|
39
|
-
}
|
|
40
|
-
export class PhysicsMaterial extends NoRenderComponentX<PhysicsMaterialProps> {
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface ColliderPhysicsProps {
|
|
45
|
-
tag?: number
|
|
46
|
-
group?: number
|
|
47
|
-
offset?: Vec2
|
|
48
|
-
onCollisionEnter?: (other: PhysicsCollider) => void
|
|
49
|
-
onCollisionExit?: (other: PhysicsCollider) => void
|
|
50
|
-
onCollisionStay?: (other: PhysicsCollider) => void
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class PhysicsCollider<T extends ColliderPhysicsProps = ColliderPhysicsProps> extends NoRenderComponentX<T, PhysicsSprite['node']> {
|
|
54
|
-
enabled = true
|
|
55
|
-
instance: PhysicsSprite
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface BoxColliderPhysicsProps extends ColliderPhysicsProps {
|
|
59
|
-
width: number
|
|
60
|
-
height: number
|
|
61
|
-
}
|
|
62
|
-
export class PhysicsBoxCollider extends PhysicsCollider<BoxColliderPhysicsProps> {
|
|
63
|
-
|
|
64
|
-
// set onCollisionEnter(val) {
|
|
65
|
-
// const phys1 = this.getComponent(PhysicsCollider)
|
|
66
|
-
// phys1._onCollisionEnter = val
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
|
-
// get onCollisionEnter() {
|
|
70
|
-
// const phys1 = this.getComponent(PhysicsCollider)
|
|
71
|
-
// return phys1._onCollisionEnter
|
|
72
|
-
// }
|
|
73
|
-
}
|
|
74
|
-
interface CircleColliderPhysicsProps extends ColliderPhysicsProps {
|
|
75
|
-
radius: number
|
|
76
|
-
}
|
|
77
|
-
export class PhysicsCircleCollider extends PhysicsCollider<CircleColliderPhysicsProps> {
|
|
78
|
-
}
|
|
79
|
-
interface PolygonColliderPhysicsProps extends ColliderPhysicsProps {
|
|
80
|
-
points: Array<Vec2>
|
|
81
|
-
}
|
|
82
|
-
export class PhysicsPolygonCollider extends PhysicsCollider<PolygonColliderPhysicsProps> {
|
|
83
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Container } from 'pixi.js'
|
|
2
|
-
import { Body, Vec2 } from 'planck'
|
|
3
|
-
|
|
4
|
-
export class PhysicsSprite {
|
|
5
|
-
node: Container
|
|
6
|
-
physicsBody: Body
|
|
7
|
-
|
|
8
|
-
constructor(node: Container, body: Body) {
|
|
9
|
-
this.node = node
|
|
10
|
-
this.physicsBody = body
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
set position(val: Vec2) {
|
|
14
|
-
this.physicsBody.setPosition(val)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set x(val) {
|
|
18
|
-
this.physicsBody.setPosition(Vec2(val, this.y))
|
|
19
|
-
}
|
|
20
|
-
set y(val) {
|
|
21
|
-
this.physicsBody.setPosition(Vec2(this.x, val))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get x() {
|
|
25
|
-
return this.physicsBody.getPosition().x
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get y() {
|
|
29
|
-
return this.physicsBody.getPosition().x
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set angle(val: number) {
|
|
33
|
-
this.physicsBody.setAngle(val)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get angle() {
|
|
37
|
-
return this.physicsBody.getAngle()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
addChild(child: Container) {
|
|
41
|
-
this.node.addChild(child)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Entity,
|
|
3
|
-
EntityManager,
|
|
4
|
-
EventManager,
|
|
5
|
-
EventTypes,
|
|
6
|
-
System
|
|
7
|
-
} from 'entityx-ts'
|
|
8
|
-
import { Body, Box, Contact, Fixture, Manifold, Shape, Vec2, World } from 'planck'
|
|
9
|
-
|
|
10
|
-
import { Graphics } from 'pixi.js'
|
|
11
|
-
import { GameWorld, instantiate } from '../base'
|
|
12
|
-
import { NodeComp } from '../components/NodeComp'
|
|
13
|
-
import {
|
|
14
|
-
PhysicsBoxCollider,
|
|
15
|
-
PhysicsCircleCollider,
|
|
16
|
-
PhysicsCollider,
|
|
17
|
-
PhysicsPolygonCollider,
|
|
18
|
-
RigidBody,
|
|
19
|
-
} from './PhysicsComponent'
|
|
20
|
-
import { PhysicsSprite } from './PhysicsSprite'
|
|
21
|
-
|
|
22
|
-
Fixture.prototype.shouldCollide = function (other) {
|
|
23
|
-
const nodeThis: NodeComp = this.getBody().getUserData()
|
|
24
|
-
const nodeOther = other.getBody().getUserData() as NodeComp
|
|
25
|
-
const { colliderMatrix } = GameWorld.Instance.systems.get(PhysicsSystem)
|
|
26
|
-
return colliderMatrix[nodeOther.group][nodeThis.group]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function setColliderMatrix(colliderMatrix = [[true]]) {
|
|
30
|
-
const physicsSystem = GameWorld.Instance.systems.get(PhysicsSystem)
|
|
31
|
-
physicsSystem.colliderMatrix = colliderMatrix
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class PhysicsSystem implements System {
|
|
35
|
-
world: World
|
|
36
|
-
listRemoveBody: Body[] = []
|
|
37
|
-
listRemoveShape: Shape[] = []
|
|
38
|
-
colliderMatrix = [[true]]
|
|
39
|
-
|
|
40
|
-
configure(event_manager: EventManager) {
|
|
41
|
-
this.world = new World({
|
|
42
|
-
gravity: Vec2(0, 98.0),
|
|
43
|
-
})
|
|
44
|
-
// event_manager.world.physicsManager = this
|
|
45
|
-
// event_manager.subscribe(ComponentAddedEvent(RigidBody), this);
|
|
46
|
-
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsBoxCollider, ({ entity, component }) => {
|
|
47
|
-
console.log('ComponentAddedEvent PhysicsBoxCollider', component)
|
|
48
|
-
let rigidBody = entity.getComponent(RigidBody)
|
|
49
|
-
if (!rigidBody) {
|
|
50
|
-
rigidBody = instantiate(RigidBody)
|
|
51
|
-
entity.assign(rigidBody)
|
|
52
|
-
}
|
|
53
|
-
const { type = 'dynamic', gravityScale = 1 } = rigidBody.props
|
|
54
|
-
// const physicsMaterial = entity.getComponent(PhysicsMaterial)
|
|
55
|
-
const box = component
|
|
56
|
-
const node = entity.getComponent(NodeComp)
|
|
57
|
-
const { width, height, ...colliderProps } = box.props
|
|
58
|
-
// ett.assign(instantiate(PhysicsCollider, { tag, offset }))
|
|
59
|
-
// const { density, restitution, friction } = physicsMaterial
|
|
60
|
-
const { x = 0, y = 0 } = colliderProps.offset || {}
|
|
61
|
-
const body = this.world.createBody({
|
|
62
|
-
position: { x: node.position.x + x, y: node.position.y + y }, // the body's origin position.
|
|
63
|
-
angle: 0.25 * Math.PI, // the body's angle in radians.
|
|
64
|
-
userData: node,
|
|
65
|
-
type,
|
|
66
|
-
gravityScale,
|
|
67
|
-
})
|
|
68
|
-
rigidBody.body = body
|
|
69
|
-
// console.log('body', body);
|
|
70
|
-
// body.setMassData({ mass: 1 } as any)
|
|
71
|
-
const physicsNode = new PhysicsSprite(node.instance, body)
|
|
72
|
-
const shape = new Box(width, height)
|
|
73
|
-
body.createFixture({
|
|
74
|
-
shape,
|
|
75
|
-
density: 1,
|
|
76
|
-
isSensor: true,
|
|
77
|
-
})
|
|
78
|
-
const debugBox = new Graphics()
|
|
79
|
-
debugBox.rect(x, y, width, height)
|
|
80
|
-
debugBox.fill({ color: 0xff0000, alpha: 0.3 })
|
|
81
|
-
node.instance.addChild(debugBox)
|
|
82
|
-
const physicsCollide = entity.assign(instantiate(PhysicsCollider, colliderProps))
|
|
83
|
-
physicsCollide.instance = physicsNode
|
|
84
|
-
physicsCollide.node = node
|
|
85
|
-
box.node = node
|
|
86
|
-
})
|
|
87
|
-
event_manager.subscribe(EventTypes.ComponentAdded, (PhysicsCircleCollider), () => { })
|
|
88
|
-
event_manager.subscribe(EventTypes.ComponentAdded, (PhysicsPolygonCollider), () => { })
|
|
89
|
-
event_manager.subscribe(EventTypes.ComponentRemoved, (NodeComp), () => {
|
|
90
|
-
// log('ComponentRemovedEvent NodeComp', event);
|
|
91
|
-
// const node = event.entity.getComponent(NodeComp)
|
|
92
|
-
// if (node.instance instanceof Sprite) {
|
|
93
|
-
// const body = node.instance.getBody()
|
|
94
|
-
// this.listRemoveShape.push(...body.shapeList)
|
|
95
|
-
// this.listRemoveBody.push(body)
|
|
96
|
-
// }
|
|
97
|
-
})
|
|
98
|
-
this.world.on('begin-contact', this.contactBegin.bind(this))
|
|
99
|
-
this.world.on('end-contact', this.contactEnd.bind(this))
|
|
100
|
-
this.world.on('pre-solve', this.preSolve.bind(this))
|
|
101
|
-
this.world.on('post-solve', this.postSolve.bind(this))
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
update(entities: EntityManager, events: EventManager, dt: number) {
|
|
105
|
-
if (this.world) {
|
|
106
|
-
this.world.step(dt)
|
|
107
|
-
|
|
108
|
-
// Iterate over bodies
|
|
109
|
-
for (let body = this.world.getBodyList(); body; body = body.getNext()) {
|
|
110
|
-
this.renderBody(body)
|
|
111
|
-
// ... and fixtures
|
|
112
|
-
for (let fixture = body.getFixtureList(); fixture; fixture = fixture.getNext()) {
|
|
113
|
-
this.renderFixture(fixture)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Iterate over joints
|
|
118
|
-
for (let joint = this.world.getJointList(); joint; joint = joint.getNext()) {
|
|
119
|
-
this.renderJoint(joint)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
renderBody(body: Body) {
|
|
125
|
-
// Render or update body rendering
|
|
126
|
-
const ett = body.getUserData() as NodeComp
|
|
127
|
-
const collider = ett.getComponent(PhysicsCollider)
|
|
128
|
-
if (collider) {
|
|
129
|
-
collider.instance.node.position = body.getPosition()
|
|
130
|
-
collider.instance.angle = body.getAngle()
|
|
131
|
-
// console.log('renderBody body', body.getPosition())
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
renderFixture(fixture: Fixture) {
|
|
136
|
-
// Render or update fixture rendering
|
|
137
|
-
// const shape = fixture.getShape()
|
|
138
|
-
// console.log('renderFixture shape', shape.m_type)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
renderJoint(joint) {
|
|
142
|
-
// Render or update joint rendering
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
contactBegin(contact: Contact) {
|
|
146
|
-
console.log('contactBegin');
|
|
147
|
-
const ett1: NodeComp = contact.getFixtureA().getBody().getUserData() as NodeComp
|
|
148
|
-
const ett2: NodeComp = contact.getFixtureB().getBody().getUserData() as NodeComp
|
|
149
|
-
// this.world.addPostStepCallback(() => {
|
|
150
|
-
// // log('addPostStepCallback');
|
|
151
|
-
// this.listRemoveShape.forEach((s) => this.world.removeShape(s))
|
|
152
|
-
// this.listRemoveBody.forEach((b) => this.world.removeBody(b))
|
|
153
|
-
// this.listRemoveBody = []
|
|
154
|
-
// this.listRemoveShape = []
|
|
155
|
-
// })
|
|
156
|
-
const phys1 = ett1.getComponent(PhysicsCollider)
|
|
157
|
-
const phys2 = ett2.getComponent(PhysicsCollider)
|
|
158
|
-
if (phys1 && phys2) {
|
|
159
|
-
if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionEnter')) {
|
|
160
|
-
phys1.props.onCollisionEnter(phys2)
|
|
161
|
-
}
|
|
162
|
-
if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionEnter')) {
|
|
163
|
-
phys2.props.onCollisionEnter(phys1)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
preSolve(contact: Contact, oldManifold: Manifold) {
|
|
169
|
-
console.log('preSolve');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
postSolve(contact: Contact, contactImpulse) {
|
|
173
|
-
console.log('collisionPost');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
contactEnd(contact: Contact) {
|
|
177
|
-
console.log('collisionSeparate');
|
|
178
|
-
const ett1: Entity = contact.getFixtureA().getBody().getUserData() as Entity
|
|
179
|
-
const ett2: Entity = contact.getFixtureB().getBody().getUserData() as Entity
|
|
180
|
-
// const event1 = ett1.getComponent(NodeComp)
|
|
181
|
-
const phys1 = ett1.getComponent(PhysicsCollider)
|
|
182
|
-
const phys2 = ett2.getComponent(PhysicsCollider)
|
|
183
|
-
// const event2 = ett2.getComponent(NodeComp)
|
|
184
|
-
if (phys1 && phys2) {
|
|
185
|
-
if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionExit')) {
|
|
186
|
-
phys1.props.onCollisionExit(phys2)
|
|
187
|
-
}
|
|
188
|
-
if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionExit')) {
|
|
189
|
-
phys2.props.onCollisionExit(phys1)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
set enabled(val) {
|
|
195
|
-
if (val) {
|
|
196
|
-
this.world.setGravity(Vec2(0, 98))
|
|
197
|
-
// this.world.iterations = 60
|
|
198
|
-
// this.world.collisionSlop = 0.5
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
package/src/planck/index.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Graphics, Sprite, Texture } from 'pixi.js'
|
|
2
|
-
|
|
3
|
-
import { BaseComponentProps, Color4B, Vec2 } from '..'
|
|
4
|
-
import { ComponentX } from '../components/BaseComponent'
|
|
5
|
-
import { LoadingBarMode } from '../core/LoadingBar'
|
|
6
|
-
import { SpriteTypes } from './RenderSystem'
|
|
7
|
-
|
|
8
|
-
export class NodeRender extends ComponentX {
|
|
9
|
-
nodeName?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface SpriteRenderProps extends BaseComponentProps<SpriteRender> {
|
|
13
|
-
spriteFrame: string
|
|
14
|
-
type?: SpriteTypes
|
|
15
|
-
fillType?: LoadingBarMode
|
|
16
|
-
// fillRange = 1
|
|
17
|
-
// fillCenter: Point
|
|
18
|
-
// loadingBar: LoadingBar
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class SpriteRender extends ComponentX<SpriteRenderProps, Sprite> {
|
|
22
|
-
// protected _spriteFrame: string
|
|
23
|
-
// set fillStart(val: number) {
|
|
24
|
-
// if (this.node.instance instanceof cc.ProgressTimer) {
|
|
25
|
-
// this.node.instance.setMidpoint(cc.v2(val, val));
|
|
26
|
-
// }
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// setFillRange(val: number) {
|
|
30
|
-
// if (this.loadingBar) {
|
|
31
|
-
// this.loadingBar.progress = val
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
get spriteFrame() {
|
|
36
|
-
return this.props.spriteFrame
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
set spriteFrame(frame) {
|
|
40
|
-
this.props.spriteFrame = frame
|
|
41
|
-
if (!this.node) return
|
|
42
|
-
const sprite = this.node.instance as Sprite
|
|
43
|
-
// if (this.node.instance instanceof cc.Sprite) {
|
|
44
|
-
sprite.texture = Texture.from(frame)
|
|
45
|
-
// sprite.texture.rotate = 8
|
|
46
|
-
// } else if (this.node.instance instanceof ccui.ImageView) {
|
|
47
|
-
// if (this.texType) {
|
|
48
|
-
// this.node.instance.loadTexture(frame, this.texType);
|
|
49
|
-
// } else {
|
|
50
|
-
// this.node.instance.loadTexture(frame);
|
|
51
|
-
// }
|
|
52
|
-
// const sprite = new cc.Sprite(frame);
|
|
53
|
-
// this.node.setContentSize(sprite.getContentSize());
|
|
54
|
-
// } else if (this.node.instance instanceof ccui.Button) {
|
|
55
|
-
// this.node.instance.loadTextureNormal(frame);
|
|
56
|
-
// }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
enum PointType {
|
|
60
|
-
Circle,
|
|
61
|
-
Rect,
|
|
62
|
-
}
|
|
63
|
-
interface GraphicsRenderProps extends BaseComponentProps<GraphicsRender> {
|
|
64
|
-
lineWidth?: number
|
|
65
|
-
strokeColor?: Color4B
|
|
66
|
-
fillColor?: Color4B
|
|
67
|
-
}
|
|
68
|
-
export class GraphicsRender extends ComponentX<GraphicsRenderProps, Graphics> {
|
|
69
|
-
drawPoint(position: Vec2, pointSize: Float, color: Color4B, pointType = PointType.Rect) { }
|
|
70
|
-
// drawPoints(points: Vec2[], color: Color4B) {
|
|
71
|
-
// }
|
|
72
|
-
drawLine(origin: Vec2, destination: Vec2, color: Color4B, thickness: Float) { }
|
|
73
|
-
drawRect(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
74
|
-
const { x, y } = origin
|
|
75
|
-
const width = destination.x - x
|
|
76
|
-
const height = destination.y - y
|
|
77
|
-
this.node.instance.rect(x, y, width, height)
|
|
78
|
-
this.node.instance.fill(color)
|
|
79
|
-
}
|
|
80
|
-
drawSolidRect(origin: Vec2, destination: Vec2, color: Color4B) { }
|
|
81
|
-
drawCircle(
|
|
82
|
-
center: Vec2,
|
|
83
|
-
radius: Float,
|
|
84
|
-
angle?: Float,
|
|
85
|
-
segments?: Integer,
|
|
86
|
-
drawLineToCenter?: boolean,
|
|
87
|
-
scaleX?: Float,
|
|
88
|
-
scaleY?: Float,
|
|
89
|
-
color?: Color4B,
|
|
90
|
-
thickness?: Float,
|
|
91
|
-
) {
|
|
92
|
-
const { x, y } = center
|
|
93
|
-
this.node.instance.circle(x, y, radius)
|
|
94
|
-
this.node.instance.fill(color)
|
|
95
|
-
}
|
|
96
|
-
drawSolidCircle(origin: Vec2, destination: Vec2, color: Color4B) { }
|
|
97
|
-
drawQuadBezier(origin: Vec2, destination: Vec2, color: Color4B) { }
|
|
98
|
-
drawCubicBezier(origin: Vec2, destination: Vec2, color: Color4B) { }
|
|
99
|
-
drawCardinalSpline(points: Vec2[], color: Color4B) { }
|
|
100
|
-
drawCatmullRom(points: Vec2[], color: Color4B) { }
|
|
101
|
-
drawPoly(points: Vec2[], color?: Color4B, thickness?: Float) {
|
|
102
|
-
this.node.instance.poly(points, true)
|
|
103
|
-
this.node.instance.fill(color || this.props.fillColor)
|
|
104
|
-
}
|
|
105
|
-
drawSolidPoly(points: Vec2[], color: Color4B) { }
|
|
106
|
-
drawDot(points: Vec2[], color: Color4B) { }
|
|
107
|
-
drawSegment(from: Vec2, to: Vec2, thickness?: Float, color?: Color4B) {
|
|
108
|
-
this.node.instance.moveTo(from.x, from.y)
|
|
109
|
-
this.node.instance.lineTo(to.x, to.y)
|
|
110
|
-
this.node.instance.strokeStyle = {
|
|
111
|
-
cap: 'round',
|
|
112
|
-
join: 'round',
|
|
113
|
-
width: thickness || this.props.lineWidth || 36,
|
|
114
|
-
color: color || this.props.strokeColor,
|
|
115
|
-
}
|
|
116
|
-
this.node.instance.stroke()
|
|
117
|
-
}
|
|
118
|
-
drawTriangle(p1: Vec2, p2: Vec2, p3: Vec2, color: Color4B) {
|
|
119
|
-
this.node.instance.poly([p1, p2, p3], true)
|
|
120
|
-
this.node.instance.fill(color)
|
|
121
|
-
}
|
|
122
|
-
clear() {
|
|
123
|
-
this.node.instance.clear()
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
interface MaskRenderProps extends BaseComponentProps<MaskRender>{
|
|
128
|
-
type?: number
|
|
129
|
-
segments?: number
|
|
130
|
-
inverted?: boolean
|
|
131
|
-
}
|
|
132
|
-
export class MaskRender extends ComponentX<MaskRenderProps> { }
|