@safe-engine/pixi 8.3.7 → 8.4.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.
- package/.github/workflows/npm-publish.yml +35 -0
- package/README.md +70 -5
- package/dist/app.d.ts +2 -5
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +44 -27
- package/dist/base/gworld.d.ts +2 -0
- package/dist/base/gworld.d.ts.map +1 -1
- package/dist/box2d-wasm/ContactListener.d.ts +12 -0
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -0
- package/dist/box2d-wasm/ContactListener.js +64 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts +50 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsComponent.js +17 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts +11 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSprite.js +30 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts +17 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSystem.js +145 -0
- package/dist/box2d-wasm/debugDraw.d.ts +67 -0
- package/dist/box2d-wasm/debugDraw.d.ts.map +1 -0
- package/dist/box2d-wasm/debugDraw.js +224 -0
- package/dist/box2d-wasm/index.d.ts +6 -0
- package/dist/box2d-wasm/index.d.ts.map +1 -0
- package/dist/box2d-wasm/index.js +17 -0
- package/dist/collider/CollideComponent.d.ts.map +1 -1
- package/dist/collider/CollideComponent.js +12 -13
- package/dist/collider/CollideSystem.d.ts.map +1 -1
- package/dist/collider/CollideSystem.js +1 -2
- package/dist/collider/helper/utils.d.ts +2 -0
- package/dist/collider/helper/utils.d.ts.map +1 -1
- package/dist/collider/helper/utils.js +22 -0
- package/dist/collider/index.d.ts +1 -0
- package/dist/collider/index.d.ts.map +1 -1
- package/dist/collider/index.js +12 -0
- package/dist/components/NodeComp.d.ts +6 -4
- package/dist/components/NodeComp.d.ts.map +1 -1
- package/dist/components/NodeComp.js +13 -13
- package/dist/components/Scene.d.ts.map +1 -1
- package/dist/components/Scene.js +3 -4
- package/dist/core/director.d.ts.map +1 -1
- package/dist/core/director.js +4 -3
- package/dist/dragonbones/DragonBonesSystem.d.ts +2 -1
- package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesSystem.js +2 -0
- package/dist/dragonbones/index.d.ts +1 -0
- package/dist/dragonbones/index.d.ts.map +1 -1
- package/dist/dragonbones/index.js +7 -0
- package/dist/gui/GUIComponent.d.ts +0 -9
- package/dist/gui/GUIComponent.d.ts.map +1 -1
- package/dist/gui/GUIComponent.js +0 -37
- package/dist/gui/GUISystem.d.ts +1 -0
- package/dist/gui/GUISystem.d.ts.map +1 -1
- package/dist/gui/GUISystem.js +2 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/planck/PhysicsComponent.d.ts +7 -7
- package/dist/planck/PhysicsComponent.js +4 -4
- package/dist/planck/PhysicsSystem.js +12 -12
- package/dist/richtext/RichTextComp.d.ts +17 -0
- package/dist/richtext/RichTextComp.d.ts.map +1 -0
- package/dist/richtext/RichTextComp.js +38 -0
- package/dist/richtext/RichTextSystem.d.ts +7 -0
- package/dist/richtext/RichTextSystem.d.ts.map +1 -0
- package/dist/richtext/RichTextSystem.js +25 -0
- package/dist/richtext/html-text-parser.d.ts +20 -0
- package/dist/richtext/html-text-parser.d.ts.map +1 -0
- package/dist/richtext/html-text-parser.js +64 -0
- package/dist/richtext/index.d.ts +3 -0
- package/dist/richtext/index.d.ts.map +1 -0
- package/dist/richtext/index.js +7 -0
- package/dist/spine/index.d.ts +1 -0
- package/dist/spine/index.d.ts.map +1 -1
- package/dist/spine/index.js +7 -0
- package/package.json +9 -11
- package/src/@types/index.d.ts +2 -0
- package/src/@types/safex.d.ts +15 -0
- package/src/app.ts +85 -0
- package/src/base/EnhancedComponent.ts +37 -0
- package/src/base/gworld.ts +19 -0
- package/src/base/index.ts +3 -0
- package/src/base/utils.ts +23 -0
- package/src/box2d-wasm/ContactListener.ts +66 -0
- package/src/box2d-wasm/PhysicsComponent.ts +83 -0
- package/src/box2d-wasm/PhysicsSprite.ts +42 -0
- package/src/box2d-wasm/PhysicsSystem.ts +145 -0
- package/src/box2d-wasm/debugDraw.ts +257 -0
- package/src/box2d-wasm/index.ts +19 -0
- package/src/collider/CollideComponent.ts +257 -0
- package/src/collider/CollideSystem.ts +166 -0
- package/src/collider/helper/Intersection.ts +139 -0
- package/src/collider/helper/utils.ts +37 -0
- package/src/collider/index.ts +16 -0
- package/src/components/BaseComponent.ts +17 -0
- package/src/components/NodeComp.ts +434 -0
- package/src/components/Scene.ts +17 -0
- package/src/core/Color.ts +7 -0
- package/src/core/LoadingBar.ts +63 -0
- package/src/core/NodePool.ts +28 -0
- package/src/core/Size.ts +21 -0
- package/src/core/director.ts +11 -0
- package/src/core/math.ts +13 -0
- package/src/dragonbones/DragonBonesComponent.ts +32 -0
- package/src/dragonbones/DragonBonesSystem.ts +35 -0
- package/src/dragonbones/index.ts +11 -0
- package/src/gui/GUIComponent.ts +159 -0
- package/src/gui/GUISystem.ts +116 -0
- package/src/helper/utils.ts +50 -0
- package/src/index.ts +23 -0
- package/src/norender/NoRenderComponent.ts +60 -0
- package/src/norender/NoRenderSystem.ts +66 -0
- package/src/planck/PhysicsComponent.ts +83 -0
- package/src/planck/PhysicsSprite.ts +43 -0
- package/src/planck/PhysicsSystem.ts +201 -0
- package/src/planck/index.ts +3 -0
- package/src/render/RenderComponent.ts +138 -0
- package/src/render/RenderSystem.ts +67 -0
- package/src/richtext/RichTextComp.ts +46 -0
- package/src/richtext/RichTextSystem.ts +26 -0
- package/src/richtext/html-text-parser.ts +87 -0
- package/src/richtext/index.ts +8 -0
- package/src/spine/SpineComponent.ts +18 -0
- package/src/spine/SpineSystem.ts +30 -0
- package/src/spine/index.ts +11 -0
- package/src/spine/lib/BatchableSpineSlot.ts +138 -0
- package/src/spine/lib/Spine.ts +910 -0
- package/src/spine/lib/SpineDebugRenderer.ts +615 -0
- package/src/spine/lib/SpinePipe.ts +203 -0
- package/src/spine/lib/SpineTexture.ts +143 -0
- package/src/spine/lib/assets/atlasLoader.ts +158 -0
- package/src/spine/lib/assets/skeletonLoader.ts +81 -0
- package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +92 -0
- package/src/spine/lib/darktint/DarkTintBatcher.ts +186 -0
- package/src/spine/lib/darktint/DarkTintShader.ts +74 -0
- package/src/spine/lib/darktint/darkTintBit.ts +77 -0
- package/src/spine/lib/index.ts +43 -0
- package/src/spine/lib/require-shim.ts +43 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EventManager, EventTypes, System } from 'entityx-ts'
|
|
2
|
+
|
|
3
|
+
// import { Touch } from '../../polyfills'
|
|
4
|
+
import { Container } from 'pixi.js'
|
|
5
|
+
import { NodeComp } from '../components/NodeComp'
|
|
6
|
+
import { ExtraDataComp, TouchEventRegister } from './NoRenderComponent'
|
|
7
|
+
|
|
8
|
+
export class NoRenderSystem implements System {
|
|
9
|
+
configure(event_manager: EventManager) {
|
|
10
|
+
event_manager.subscribe(EventTypes.ComponentAdded, ExtraDataComp, ({ entity, component }) => {
|
|
11
|
+
const { key, value } = component.props
|
|
12
|
+
component.data[key] = value
|
|
13
|
+
})
|
|
14
|
+
event_manager.subscribe(EventTypes.ComponentAdded, TouchEventRegister, ({ entity, component }) => {
|
|
15
|
+
const ett = entity
|
|
16
|
+
const touchComp = component
|
|
17
|
+
const nodeComp = ett.getComponent(NodeComp)
|
|
18
|
+
touchComp.node = nodeComp
|
|
19
|
+
const container: Container = nodeComp.instance
|
|
20
|
+
if (touchComp.props.onTouchStart) {
|
|
21
|
+
container.on('pointerdown', (event) => {
|
|
22
|
+
touchComp.props.onTouchStart(event, nodeComp)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (touchComp.props.onTouchMove) {
|
|
26
|
+
container.on('pointermove', (event) => {
|
|
27
|
+
touchComp.props.onTouchMove(event, nodeComp)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (touchComp.props.onTouchEnd) {
|
|
31
|
+
container.on('pointerup', (event) => {
|
|
32
|
+
touchComp.props.onTouchEnd(event, nodeComp)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (touchComp.props.onTouchEnd) {
|
|
36
|
+
container.on('pointercancel', (event) => {
|
|
37
|
+
touchComp.props.onTouchEnd(event, nodeComp)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, TouchEventRegister, ({ entity, component }) => {
|
|
42
|
+
console.log('ComponentRemovedEvent TouchEventRegister', event)
|
|
43
|
+
// const ett = event.entity
|
|
44
|
+
// const nodeComp = ett.getComponent(NodeComp)
|
|
45
|
+
const touchComp = component as TouchEventRegister
|
|
46
|
+
const container: Container = touchComp.node.instance
|
|
47
|
+
if (touchComp.props.onTouchStart) {
|
|
48
|
+
container.removeListener('touchstart')
|
|
49
|
+
}
|
|
50
|
+
if (touchComp.props.onTouchMove) {
|
|
51
|
+
container.removeListener('touchmove')
|
|
52
|
+
}
|
|
53
|
+
if (touchComp.props.onTouchEnd) {
|
|
54
|
+
container.removeListener('touchend')
|
|
55
|
+
}
|
|
56
|
+
if (touchComp.props.onTouchEnd) {
|
|
57
|
+
container.removeListener('touchcancel')
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// update(entities: EntityManager, events: EventManager, dt: number)
|
|
63
|
+
// update() {
|
|
64
|
+
// throw new Error('Method not implemented.');
|
|
65
|
+
// }
|
|
66
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Graphics, Point, Sprite, Texture } from 'pixi.js'
|
|
2
|
+
|
|
3
|
+
import { 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 {
|
|
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 & { $ref?: SpriteRender }, 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 {
|
|
64
|
+
lineWidth?: number
|
|
65
|
+
strokeColor?: Color4B
|
|
66
|
+
fillColor?: Color4B
|
|
67
|
+
}
|
|
68
|
+
export class GraphicsRender extends ComponentX<GraphicsRenderProps & { $ref?: GraphicsRender }, Graphics> {
|
|
69
|
+
|
|
70
|
+
drawPoint(position: Vec2, pointSize: Float, color: Color4B, pointType = PointType.Rect) {
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
// drawPoints(points: Vec2[], color: Color4B) {
|
|
74
|
+
// }
|
|
75
|
+
drawLine(origin: Vec2, destination: Vec2, color: Color4B, thickness: Float) {
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
drawRect(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
79
|
+
const { x, y } = origin
|
|
80
|
+
const width = destination.x - x
|
|
81
|
+
const height = destination.y - y
|
|
82
|
+
this.node.instance.rect(x, y, width, height)
|
|
83
|
+
this.node.instance.fill(color)
|
|
84
|
+
}
|
|
85
|
+
drawSolidRect(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
drawCircle(center: Vec2, radius: Float, angle?: Float, segments?: Integer, drawLineToCenter?: boolean, scaleX?: Float, scaleY?: Float, color?: Color4B, thickness?: Float) {
|
|
89
|
+
const { x, y } = center
|
|
90
|
+
this.node.instance.circle(x, y, radius)
|
|
91
|
+
this.node.instance.fill(color)
|
|
92
|
+
}
|
|
93
|
+
drawSolidCircle(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
drawQuadBezier(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
drawCubicBezier(origin: Vec2, destination: Vec2, color: Color4B) {
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
drawCardinalSpline(points: Vec2[], color: Color4B) {
|
|
103
|
+
}
|
|
104
|
+
drawCatmullRom(points: Vec2[], color: Color4B) {
|
|
105
|
+
}
|
|
106
|
+
drawPoly(points: Vec2[], closedPolygon: boolean, color: Color4B, thickness?: Float) {
|
|
107
|
+
this.node.instance.poly(points, closedPolygon)
|
|
108
|
+
this.node.instance.fill(color)
|
|
109
|
+
}
|
|
110
|
+
drawSolidPoly(points: Vec2[], color: Color4B) {
|
|
111
|
+
}
|
|
112
|
+
drawDot(points: Vec2[], color: Color4B) {
|
|
113
|
+
}
|
|
114
|
+
drawSegment(from: Point, to: Point, color?: Color4B) {
|
|
115
|
+
this.node.instance.moveTo(from.x, from.y);
|
|
116
|
+
this.node.instance.lineTo(to.x, to.y);
|
|
117
|
+
this.node.instance.strokeStyle = {
|
|
118
|
+
cap: 'round', join: 'round',
|
|
119
|
+
width: this.props.lineWidth || 36,
|
|
120
|
+
color: color || this.props.strokeColor,
|
|
121
|
+
}
|
|
122
|
+
this.node.instance.stroke();
|
|
123
|
+
}
|
|
124
|
+
drawTriangle(p1: Vec2, p2: Vec2, p3: Vec2, color: Color4B) {
|
|
125
|
+
this.node.instance.poly([p1, p2, p3], true)
|
|
126
|
+
this.node.instance.fill(color)
|
|
127
|
+
}
|
|
128
|
+
clear() {
|
|
129
|
+
this.node.instance.clear()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface MaskRenderProps {
|
|
134
|
+
type?: number
|
|
135
|
+
segments?: number
|
|
136
|
+
inverted?: boolean
|
|
137
|
+
}
|
|
138
|
+
export class MaskRender extends ComponentX<MaskRenderProps> { }
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EventManager,
|
|
3
|
+
EventTypes,
|
|
4
|
+
System
|
|
5
|
+
} from 'entityx-ts'
|
|
6
|
+
import { Container, Graphics, Sprite } from 'pixi.js'
|
|
7
|
+
|
|
8
|
+
import { NodeComp } from '..'
|
|
9
|
+
import { GraphicsRender, MaskRender, NodeRender, SpriteRender } from './RenderComponent'
|
|
10
|
+
|
|
11
|
+
export enum SpriteTypes {
|
|
12
|
+
SIMPLE,
|
|
13
|
+
SLICED,
|
|
14
|
+
TILED,
|
|
15
|
+
FILLED,
|
|
16
|
+
MESH,
|
|
17
|
+
ANIMATION,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class RenderSystem implements System {
|
|
21
|
+
configure(event_manager: EventManager) {
|
|
22
|
+
event_manager.subscribe(EventTypes.ComponentAdded, NodeRender, ({ entity }) => {
|
|
23
|
+
const nodeRenderComp = entity.getComponent(NodeRender)
|
|
24
|
+
const node = new Container()
|
|
25
|
+
nodeRenderComp.node = entity.assign(new NodeComp(node, entity))
|
|
26
|
+
})
|
|
27
|
+
event_manager.subscribe(EventTypes.ComponentAdded, SpriteRender, ({ entity, component }) => {
|
|
28
|
+
const { spriteFrame } = component.props
|
|
29
|
+
// console.log('SpriteRender ComponentAdded', component)
|
|
30
|
+
const node = Sprite.from(spriteFrame)
|
|
31
|
+
// if (type === SpriteTypes.FILLED) {
|
|
32
|
+
// // console.log('fillType', fillType)
|
|
33
|
+
// const loadingBar = new LoadingBar(fillType, node)
|
|
34
|
+
// if (fillRange) loadingBar.progress = fillRange
|
|
35
|
+
// if (fillCenter) loadingBar.fillCenter = fillCenter
|
|
36
|
+
// component.loadingBar = loadingBar
|
|
37
|
+
// // node.setMidpoint(fillCenter)
|
|
38
|
+
// }
|
|
39
|
+
// node.texture.rotate = 8
|
|
40
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
41
|
+
// component.node.anchorX = 0.5
|
|
42
|
+
// component.node.anchorY = 0.5
|
|
43
|
+
})
|
|
44
|
+
event_manager.subscribe(EventTypes.ComponentAdded, MaskRender, ({ component }) => {
|
|
45
|
+
console.log('MaskRender', component);
|
|
46
|
+
// const { type, segments, inverted } = maskComp
|
|
47
|
+
// const node = new cc.ClippingNode()
|
|
48
|
+
// node.setInverted(inverted)
|
|
49
|
+
// maskComp.node = ett.assign(new NodeComp(node, ett))
|
|
50
|
+
})
|
|
51
|
+
event_manager.subscribe(EventTypes.ComponentAdded, GraphicsRender, ({ entity, component }) => {
|
|
52
|
+
// const { lineWidth, strokeColor, fillColor } = component
|
|
53
|
+
// console.log('GraphicsRender', component);
|
|
54
|
+
const node = new Graphics()
|
|
55
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
56
|
+
})
|
|
57
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, NodeComp, ({ component }) => {
|
|
58
|
+
if (component) {
|
|
59
|
+
component.instance.removeFromParent()
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// update() {
|
|
65
|
+
// throw new Error('Method not implemented.');
|
|
66
|
+
// }
|
|
67
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import TaggedText from 'pixi-tagged-text-plus'
|
|
2
|
+
import { ComponentX } from '../components/BaseComponent'
|
|
3
|
+
import { generateStringFromStyledElements, generateStylesFromStyledElements, parseFontString, transformToStyledElements } from './html-text-parser'
|
|
4
|
+
|
|
5
|
+
interface RichTextCompProps {
|
|
6
|
+
font?: string
|
|
7
|
+
string?: string
|
|
8
|
+
size?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class RichTextComp extends ComponentX<RichTextCompProps, TaggedText> {
|
|
12
|
+
|
|
13
|
+
get string() {
|
|
14
|
+
return this.props.string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
set string(val: string) {
|
|
19
|
+
this.props.string = val
|
|
20
|
+
if (!this.node) return
|
|
21
|
+
const jObj = parseFontString(val);
|
|
22
|
+
const styledOutput = transformToStyledElements(jObj);
|
|
23
|
+
const newText = generateStringFromStyledElements(styledOutput)
|
|
24
|
+
const styles = generateStylesFromStyledElements(styledOutput)
|
|
25
|
+
// console.log(styledOutput)
|
|
26
|
+
const wrapped = `<root>${newText}</root>`
|
|
27
|
+
this.node.instance.setText(wrapped)
|
|
28
|
+
this.node.instance.setTagStyles(styles)
|
|
29
|
+
}
|
|
30
|
+
get size() {
|
|
31
|
+
return this.props.size
|
|
32
|
+
}
|
|
33
|
+
set size(size: number) {
|
|
34
|
+
this.props.size = size
|
|
35
|
+
if (!this.node) return
|
|
36
|
+
this.node.instance.setStyleForTag('root', { fontSize: size, color: '#fff' })
|
|
37
|
+
}
|
|
38
|
+
get font() {
|
|
39
|
+
return this.props.font
|
|
40
|
+
}
|
|
41
|
+
set font(font: string) {
|
|
42
|
+
this.props.font = font
|
|
43
|
+
if (!this.node) return
|
|
44
|
+
this.node.instance.setStyleForTag('root', { color: '#fff', fontFamily: font })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EntityManager, EventManager, EventReceiveCallback, EventTypes, System } from 'entityx-ts'
|
|
2
|
+
|
|
3
|
+
import TaggedText from 'pixi-tagged-text-plus'
|
|
4
|
+
import { NodeComp } from '..'
|
|
5
|
+
import { RichTextComp } from './RichTextComp'
|
|
6
|
+
|
|
7
|
+
export class RichTextSystem implements System {
|
|
8
|
+
configure(event_manager: EventManager) {
|
|
9
|
+
event_manager.subscribe(EventTypes.ComponentAdded, RichTextComp, this.onAddRichTextComp)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private onAddRichTextComp: EventReceiveCallback<RichTextComp> = ({ entity, component }) => {
|
|
13
|
+
const { string = '', font = '', size = 64 } = component.props
|
|
14
|
+
const node = new TaggedText(string);
|
|
15
|
+
// node.defaultStyle = { }
|
|
16
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
17
|
+
component.string = (string)
|
|
18
|
+
if (font) component.font = (font)
|
|
19
|
+
if (size) component.size = (size)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
update(entities: EntityManager, events: EventManager, dt: number)
|
|
23
|
+
update() {
|
|
24
|
+
// throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
}
|