@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.
- package/README.md +14 -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 +4 -2
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +134 -44
- 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/helper/utils.d.ts +0 -6
- package/dist/helper/utils.d.ts.map +1 -1
- package/dist/helper/utils.js +0 -12
- package/package.json +6 -2
- package/.github/workflows/npm-publish.yml +0 -35
- package/dist/@types/safex.d.ts +0 -15
- package/src/@types/index.d.ts +0 -2
- 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/{dist/@types → @types}/index.d.ts +0 -0
|
@@ -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> { }
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { EventManager, EventTypes, System } from 'entityx-ts'
|
|
2
|
-
import { Container, Graphics, Sprite } from 'pixi.js'
|
|
3
|
-
|
|
4
|
-
import { NodeComp } from '..'
|
|
5
|
-
import { GraphicsRender, MaskRender, NodeRender, SpriteRender } from './RenderComponent'
|
|
6
|
-
|
|
7
|
-
export enum SpriteTypes {
|
|
8
|
-
SIMPLE,
|
|
9
|
-
SLICED,
|
|
10
|
-
TILED,
|
|
11
|
-
FILLED,
|
|
12
|
-
MESH,
|
|
13
|
-
ANIMATION,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class RenderSystem implements System {
|
|
17
|
-
configure(event_manager: EventManager) {
|
|
18
|
-
event_manager.subscribe(EventTypes.ComponentAdded, NodeRender, ({ entity }) => {
|
|
19
|
-
const nodeRenderComp = entity.getComponent(NodeRender)
|
|
20
|
-
const node = new Container()
|
|
21
|
-
nodeRenderComp.node = entity.assign(new NodeComp(node, entity))
|
|
22
|
-
})
|
|
23
|
-
event_manager.subscribe(EventTypes.ComponentAdded, SpriteRender, ({ entity, component }) => {
|
|
24
|
-
const { spriteFrame } = component.props
|
|
25
|
-
// const texture = GameWorld.Instance.assetManager.get<Texture>(spriteFrame)
|
|
26
|
-
// console.log('SpriteRender ComponentAdded', component, texture)
|
|
27
|
-
const node = Sprite.from(spriteFrame)
|
|
28
|
-
// if (type === SpriteTypes.FILLED) {
|
|
29
|
-
// // console.log('fillType', fillType)
|
|
30
|
-
// const loadingBar = new LoadingBar(fillType, node)
|
|
31
|
-
// if (fillRange) loadingBar.progress = fillRange
|
|
32
|
-
// if (fillCenter) loadingBar.fillCenter = fillCenter
|
|
33
|
-
// component.loadingBar = loadingBar
|
|
34
|
-
// // node.setMidpoint(fillCenter)
|
|
35
|
-
// }
|
|
36
|
-
// node.texture.rotate = 8
|
|
37
|
-
component.node = entity.assign(new NodeComp(node, entity))
|
|
38
|
-
// component.node.anchorX = 0.5
|
|
39
|
-
// component.node.anchorY = 0.5
|
|
40
|
-
})
|
|
41
|
-
event_manager.subscribe(EventTypes.ComponentAdded, MaskRender, ({ component }) => {
|
|
42
|
-
console.log('MaskRender', component)
|
|
43
|
-
// const { type, segments, inverted } = maskComp
|
|
44
|
-
// const node = new cc.ClippingNode()
|
|
45
|
-
// node.setInverted(inverted)
|
|
46
|
-
// maskComp.node = ett.assign(new NodeComp(node, ett))
|
|
47
|
-
})
|
|
48
|
-
event_manager.subscribe(EventTypes.ComponentAdded, GraphicsRender, ({ entity, component }) => {
|
|
49
|
-
// const { lineWidth, strokeColor, fillColor } = component.props
|
|
50
|
-
// console.log('GraphicsRender', component);
|
|
51
|
-
const node = new Graphics()
|
|
52
|
-
component.node = entity.assign(new NodeComp(node, entity))
|
|
53
|
-
})
|
|
54
|
-
event_manager.subscribe(EventTypes.ComponentRemoved, NodeComp, ({ component }) => {
|
|
55
|
-
if (component) {
|
|
56
|
-
component.instance.removeFromParent()
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// update() {
|
|
62
|
-
// throw new Error('Method not implemented.');
|
|
63
|
-
// }
|
|
64
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import TaggedText from 'pixi-tagged-text-plus'
|
|
2
|
-
import { BaseComponentProps } from '..'
|
|
3
|
-
import { ComponentX } from '../components/BaseComponent'
|
|
4
|
-
import {
|
|
5
|
-
generateStringFromStyledElements,
|
|
6
|
-
generateStylesFromStyledElements,
|
|
7
|
-
parseFontString,
|
|
8
|
-
transformToStyledElements,
|
|
9
|
-
} from './html-text-parser'
|
|
10
|
-
|
|
11
|
-
interface RichTextCompProps extends BaseComponentProps<RichTextComp> {
|
|
12
|
-
font?: string
|
|
13
|
-
string?: string
|
|
14
|
-
size?: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class RichTextComp extends ComponentX<RichTextCompProps, TaggedText> {
|
|
18
|
-
get string() {
|
|
19
|
-
return this.props.string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set string(val: string) {
|
|
23
|
-
this.props.string = val
|
|
24
|
-
if (!this.node) return
|
|
25
|
-
const jObj = parseFontString(val)
|
|
26
|
-
const styledOutput = transformToStyledElements(jObj)
|
|
27
|
-
const newText = generateStringFromStyledElements(styledOutput)
|
|
28
|
-
const styles = generateStylesFromStyledElements(styledOutput)
|
|
29
|
-
// console.log(styledOutput)
|
|
30
|
-
const wrapped = `<root>${newText}</root>`
|
|
31
|
-
this.node.instance.setText(wrapped)
|
|
32
|
-
this.node.instance.setTagStyles(styles)
|
|
33
|
-
}
|
|
34
|
-
get size() {
|
|
35
|
-
return this.props.size
|
|
36
|
-
}
|
|
37
|
-
set size(size: number) {
|
|
38
|
-
this.props.size = size
|
|
39
|
-
if (!this.node) return
|
|
40
|
-
this.node.instance.setStyleForTag('root', { fontSize: size, color: '#fff' })
|
|
41
|
-
}
|
|
42
|
-
get font() {
|
|
43
|
-
return this.props.font
|
|
44
|
-
}
|
|
45
|
-
set font(font: string) {
|
|
46
|
-
this.props.font = font
|
|
47
|
-
if (!this.node) return
|
|
48
|
-
this.node.instance.setStyleForTag('root', { color: '#fff', fontFamily: font })
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
interface FontTag {
|
|
2
|
-
color?: string;
|
|
3
|
-
size?: number;
|
|
4
|
-
text: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type ParsedResult = FontTag[];
|
|
8
|
-
|
|
9
|
-
type StyledElement = {
|
|
10
|
-
tag?: string;
|
|
11
|
-
style?: { color?: string; size?: number };
|
|
12
|
-
text: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function parseFontString(input: string): ParsedResult {
|
|
16
|
-
const regex = /<font\s+color=['"](#?[0-9a-fA-F]{6})['"](?:\s+size=(\d+))?>(.*?)<\/font>/gi;
|
|
17
|
-
const results: ParsedResult = [];
|
|
18
|
-
let lastIndex = 0;
|
|
19
|
-
|
|
20
|
-
let match: RegExpExecArray | null;
|
|
21
|
-
while ((match = regex.exec(input)) !== null) {
|
|
22
|
-
// Add plain text before the match if it exists
|
|
23
|
-
if (match.index > lastIndex) {
|
|
24
|
-
const plainText = input.slice(lastIndex, match.index)
|
|
25
|
-
if (plainText) {
|
|
26
|
-
results.push({ text: plainText });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const color = match[1];
|
|
31
|
-
const size = match[2] ? parseInt(match[2], 10) : undefined;
|
|
32
|
-
const text = match[3];
|
|
33
|
-
|
|
34
|
-
results.push({ color, size, text });
|
|
35
|
-
|
|
36
|
-
lastIndex = regex.lastIndex;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Add remaining plain text after the last match
|
|
40
|
-
if (lastIndex < input.length) {
|
|
41
|
-
const plainText = input.slice(lastIndex);
|
|
42
|
-
if (plainText) {
|
|
43
|
-
results.push({ text: plainText });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return results;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function transformToStyledElements(parsed: ParsedResult): StyledElement[] {
|
|
51
|
-
return parsed.map((item, index) => {
|
|
52
|
-
if (item.color || item.size) {
|
|
53
|
-
return {
|
|
54
|
-
tag: `b${index + 1}`,
|
|
55
|
-
style: { color: item.color, size: item.size },
|
|
56
|
-
text: item.text,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
text: item.text,
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function generateStringFromStyledElements(elements: StyledElement[]): string {
|
|
66
|
-
return elements
|
|
67
|
-
.map((element) => {
|
|
68
|
-
if (!element.tag) {
|
|
69
|
-
return element.text;
|
|
70
|
-
}
|
|
71
|
-
return `<${element.tag}>${element.text}</${element.tag}>`;
|
|
72
|
-
})
|
|
73
|
-
.join('');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function generateStylesFromStyledElements(elements: StyledElement[]) {
|
|
77
|
-
const styles = {};
|
|
78
|
-
elements
|
|
79
|
-
.forEach((element) => {
|
|
80
|
-
const { tag, style } = element
|
|
81
|
-
if (!tag) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
styles[element.tag] = style
|
|
85
|
-
})
|
|
86
|
-
return styles
|
|
87
|
-
}
|