@safe-engine/cocos 2.3.10 → 2.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.
Files changed (67) hide show
  1. package/dist/chipmunk/PhysicsComponent.d.ts +49 -0
  2. package/dist/chipmunk/PhysicsComponent.d.ts.map +1 -0
  3. package/dist/chipmunk/PhysicsComponent.js +69 -0
  4. package/dist/chipmunk/PhysicsSprite.d.ts +16 -0
  5. package/dist/chipmunk/PhysicsSprite.d.ts.map +1 -0
  6. package/dist/chipmunk/PhysicsSprite.js +49 -0
  7. package/dist/chipmunk/PhysicsSystem.d.ts +20 -0
  8. package/dist/chipmunk/PhysicsSystem.d.ts.map +1 -0
  9. package/dist/chipmunk/PhysicsSystem.js +259 -0
  10. package/dist/chipmunk/index.d.ts +24 -0
  11. package/dist/chipmunk/index.d.ts.map +1 -0
  12. package/dist/chipmunk/index.js +13 -0
  13. package/dist/core/Scene.d.ts.map +1 -1
  14. package/dist/core/Scene.js +4 -1
  15. package/dist/norender/NoRenderSystem.js +1 -1
  16. package/dist/render/RenderSystem.d.ts +1 -2
  17. package/dist/render/RenderSystem.d.ts.map +1 -1
  18. package/dist/render/RenderSystem.js +0 -3
  19. package/package.json +2 -2
  20. package/dist/core/index.d.ts +0 -6
  21. package/dist/core/index.d.ts.map +0 -1
  22. package/dist/core/index.js +0 -5
  23. package/dist/dragonbones/PixiDragonBonesSprite.d.ts +0 -19
  24. package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +0 -1
  25. package/dist/dragonbones/PixiDragonBonesSprite.js +0 -75
  26. package/dist/gworld/EnhancedComponent.d.ts +0 -22
  27. package/dist/gworld/EnhancedComponent.d.ts.map +0 -1
  28. package/dist/gworld/EnhancedComponent.js +0 -44
  29. package/dist/gworld/NodeComp.d.ts +0 -153
  30. package/dist/gworld/NodeComp.d.ts.map +0 -1
  31. package/dist/gworld/NodeComp.js +0 -337
  32. package/dist/gworld/NodePool.d.ts +0 -9
  33. package/dist/gworld/NodePool.d.ts.map +0 -1
  34. package/dist/gworld/NodePool.js +0 -23
  35. package/dist/gworld/Scene.d.ts +0 -5
  36. package/dist/gworld/Scene.d.ts.map +0 -1
  37. package/dist/gworld/Scene.js +0 -14
  38. package/dist/gworld/decorator.d.ts +0 -8
  39. package/dist/gworld/decorator.d.ts.map +0 -1
  40. package/dist/gworld/decorator.js +0 -12
  41. package/dist/gworld/index.d.ts +0 -8
  42. package/dist/gworld/index.d.ts.map +0 -1
  43. package/dist/gworld/index.js +0 -14
  44. package/dist/render/TiledSprite.d.ts +0 -13
  45. package/dist/render/TiledSprite.d.ts.map +0 -1
  46. package/dist/render/TiledSprite.js +0 -69
  47. package/dist/safex.d.ts +0 -10
  48. package/dist/safex.d.ts.map +0 -1
  49. package/dist/safex.js +0 -1
  50. package/dist/spine/CCSkeleton.d.ts +0 -189
  51. package/dist/spine/CCSkeleton.d.ts.map +0 -1
  52. package/dist/spine/CCSkeleton.js +0 -320
  53. package/dist/spine/CCSkeletonAnimation.d.ts +0 -146
  54. package/dist/spine/CCSkeletonAnimation.d.ts.map +0 -1
  55. package/dist/spine/CCSkeletonAnimation.js +0 -311
  56. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +0 -2
  57. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +0 -1
  58. package/dist/spine/CCSkeletonCanvasRenderCmd.js +0 -228
  59. package/dist/spine/CCSkeletonTexture.d.ts +0 -25
  60. package/dist/spine/CCSkeletonTexture.d.ts.map +0 -1
  61. package/dist/spine/CCSkeletonTexture.js +0 -60
  62. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +0 -28
  63. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +0 -1
  64. package/dist/spine/CCSkeletonWebGLRenderCmd.js +0 -277
  65. package/dist/spine/PixiSpineSprite.d.ts +0 -19
  66. package/dist/spine/PixiSpineSprite.d.ts.map +0 -1
  67. package/dist/spine/PixiSpineSprite.js +0 -72
@@ -0,0 +1,49 @@
1
+ import { BaseComponentProps } from '..';
2
+ import { ComponentX } from '../core/decorator';
3
+ import { Vec2 } from '../polyfills';
4
+ import { PhysicsSprite } from './PhysicsSprite';
5
+ interface RigidBodyProps {
6
+ type?: 0 | 1 | 2;
7
+ density?: Float;
8
+ restitution?: Float;
9
+ friction?: Float;
10
+ isSensor?: boolean;
11
+ isLockRotate?: boolean;
12
+ tag?: number;
13
+ onBeginContact?: (other: RigidBody) => void;
14
+ onEndContact?: (other: RigidBody) => void;
15
+ onPreSolve?: (other: RigidBody, impulse?: any) => void;
16
+ onPostSolve?: (other: RigidBody, oldManifold?: any) => void;
17
+ }
18
+ export declare class RigidBody extends ComponentX<RigidBodyProps> {
19
+ body: cp.Body;
20
+ physicSprite: PhysicsSprite;
21
+ set linearVelocity(vel: Vec2);
22
+ get linearVelocity(): Vec2;
23
+ applyForceTo(vel: Vec2, pos?: Vec2): void;
24
+ applyLinearImpulse(vel: Vec2, pos?: Vec2): void;
25
+ applyTorque(torque: Float): void;
26
+ set position(pos: Vec2);
27
+ get position(): Vec2;
28
+ }
29
+ interface BoxColliderPhysicsProps {
30
+ width: number;
31
+ height: number;
32
+ offset?: [number, number];
33
+ }
34
+ export declare class PhysicsBoxCollider extends ComponentX<BoxColliderPhysicsProps & BaseComponentProps<PhysicsBoxCollider>> {
35
+ }
36
+ interface CircleColliderPhysicsProps {
37
+ radius: number;
38
+ offset?: [number, number];
39
+ }
40
+ export declare class PhysicsCircleCollider extends ComponentX<CircleColliderPhysicsProps & BaseComponentProps<PhysicsCircleCollider>> {
41
+ }
42
+ interface PolygonColliderPhysicsProps {
43
+ points: Array<Vec2> | [number, number][];
44
+ offset?: [number, number];
45
+ }
46
+ export declare class PhysicsPolygonCollider extends ComponentX<PolygonColliderPhysicsProps & BaseComponentProps<PhysicsPolygonCollider>> {
47
+ }
48
+ export {};
49
+ //# sourceMappingURL=PhysicsComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/chipmunk/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAEhB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IAC3C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IACzC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,KAAA,KAAK,IAAI,CAAA;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,KAAA,KAAK,IAAI,CAAA;CACvD;AAED,qBAAa,SAAU,SAAQ,UAAU,CAAC,cAAc,CAAC;IACvD,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;IACb,YAAY,EAAE,aAAa,CAAA;IAC3B,IAAI,cAAc,CAAC,GAAG,EAAE,IAAI,EAM3B;IAED,IAAI,cAAc,IARM,IAAI,CAc3B;IAED,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI;IAWlC,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI;IAaxC,WAAW,CAAC,MAAM,EAAE,KAAK;IAOzB,IAAI,QAAQ,CAAC,GAAG,EAAE,IAAI,EASrB;IAED,IAAI,QAAQ,IAXM,IAAI,CAarB;CACF;AAED,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,kBAAmB,SAAQ,UAAU,CAAC,uBAAuB,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;CASnH;AACD,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,qBAAsB,SAAQ,UAAU,CAAC,0BAA0B,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CAAG;AAChI,UAAU,2BAA2B;IACnC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;IACxC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,sBAAuB,SAAQ,UAAU,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;CAAG"}
@@ -0,0 +1,69 @@
1
+ import { ComponentX } from '../core/decorator';
2
+ import { Vec2 } from '../polyfills';
3
+ export class RigidBody extends ComponentX {
4
+ body;
5
+ physicSprite;
6
+ set linearVelocity(vel) {
7
+ // console.log('set linearVelocity(', vel)
8
+ if (!this.node) {
9
+ return;
10
+ }
11
+ this.body.setVel(new cp.Vect(vel.x, vel.y));
12
+ }
13
+ get linearVelocity() {
14
+ if (!this.node) {
15
+ return Vec2.ZERO;
16
+ }
17
+ const vel = this.body.getVel();
18
+ return Vec2(vel);
19
+ }
20
+ applyForceTo(vel, pos) {
21
+ if (!this.node) {
22
+ return;
23
+ }
24
+ if (pos) {
25
+ this.body.applyForce(new cp.Vect(vel.x, vel.y), new cp.Vect(pos.x, pos.y));
26
+ }
27
+ else {
28
+ this.body.applyForce(new cp.Vect(vel.x, vel.y), new cp.Vect(0, 0));
29
+ }
30
+ }
31
+ applyLinearImpulse(vel, pos) {
32
+ if (!this.node) {
33
+ return;
34
+ }
35
+ // console.log('applyLinearImpulse', vel, pos)
36
+ // this.body.activate()
37
+ if (pos) {
38
+ this.body.applyImpulse(new cp.Vect(vel.x, vel.y), new cp.Vect(pos.x, pos.y));
39
+ }
40
+ else {
41
+ this.body.applyImpulse(new cp.Vect(vel.x, vel.y), new cp.Vect(0, 0));
42
+ }
43
+ }
44
+ applyTorque(torque) {
45
+ if (!this.node) {
46
+ return;
47
+ }
48
+ this.body.setAngVel(torque);
49
+ }
50
+ set position(pos) {
51
+ this.physicSprite.node.setPosition(pos.x, pos.y);
52
+ const physicsPos = new cp.Vect(pos.x, pos.y);
53
+ // console.log('SetTransform', pos, physicsPos)
54
+ const body = this.body;
55
+ body.setVel(new cp.Vect(0, 0));
56
+ body.setAngVel(0);
57
+ // body.SetAwake(true)
58
+ body.setPos(physicsPos);
59
+ }
60
+ get position() {
61
+ return Vec2(this.physicSprite.getBody().getPos());
62
+ }
63
+ }
64
+ export class PhysicsBoxCollider extends ComponentX {
65
+ }
66
+ export class PhysicsCircleCollider extends ComponentX {
67
+ }
68
+ export class PhysicsPolygonCollider extends ComponentX {
69
+ }
@@ -0,0 +1,16 @@
1
+ export declare class PhysicsSprite {
2
+ node: cc.Node;
3
+ physicsBody: cp.Body;
4
+ constructor(node: cc.Node, body: cp.Body);
5
+ update(dt: number): void;
6
+ getBody(): cp.Body;
7
+ set position(val: cp.Vect);
8
+ set x(val: number);
9
+ set y(val: number);
10
+ get x(): number;
11
+ get y(): number;
12
+ set rotation(val: number);
13
+ get rotation(): number;
14
+ addChild(child: cc.Node): void;
15
+ }
16
+ //# sourceMappingURL=PhysicsSprite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/chipmunk/PhysicsSprite.ts"],"names":[],"mappings":"AAEA,qBAAa,aAAa;IACxB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;IACb,WAAW,EAAE,EAAE,CAAC,IAAI,CAAA;gBAER,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;IAKxC,MAAM,CAAC,EAAE,EAAE,MAAM;IAcjB,OAAO;IAIP,IAAI,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,EAExB;IAED,IAAI,CAAC,CAAC,GAAG,QAAA,EAER;IACD,IAAI,CAAC,CAAC,GAAG,QAAA,EAER;IAED,IAAI,CAAC,WAEJ;IAED,IAAI,CAAC,WAEJ;IAED,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,EAEvB;IAED,IAAI,QAAQ,IAJM,MAAM,CAMvB;IAED,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI;CAGxB"}
@@ -0,0 +1,49 @@
1
+ import { Vec2 } from '../polyfills';
2
+ export class PhysicsSprite {
3
+ node;
4
+ physicsBody;
5
+ constructor(node, body) {
6
+ this.node = node;
7
+ this.physicsBody = body;
8
+ }
9
+ update(dt) {
10
+ if (!this.physicsBody) {
11
+ return;
12
+ }
13
+ const { x, y } = this.physicsBody.getPos();
14
+ // use cc.lerp to smooth the position update
15
+ // const pos = Vec2(cc.lerp(this.node.x, x, dt * 10), cc.lerp(this.node.y, y, dt * 10))
16
+ this.node.setPosition(x, y);
17
+ // lerp the rotation
18
+ // this.node.setRotation(cc.lerp(this.node.rotation, -cc.radiansToDegrees(this.physicsBody.a), dt * 10))
19
+ this.node.setRotation(-cc.radiansToDegrees(this.physicsBody.a));
20
+ // this.node.setScale(1 / this.physicsBody.GetFixtureList().GetShape().GetRadius())
21
+ }
22
+ getBody() {
23
+ return this.physicsBody;
24
+ }
25
+ set position(val) {
26
+ this.physicsBody.setPos(val);
27
+ }
28
+ set x(val) {
29
+ this.physicsBody.setPos(Vec2(val, this.y));
30
+ }
31
+ set y(val) {
32
+ this.physicsBody.setPos(Vec2(this.x, val));
33
+ }
34
+ get x() {
35
+ return this.physicsBody.getPos().x;
36
+ }
37
+ get y() {
38
+ return this.physicsBody.getPos().y;
39
+ }
40
+ set rotation(val) {
41
+ this.physicsBody.setAngle(-cc.degreesToRadians(val));
42
+ }
43
+ get rotation() {
44
+ return -cc.radiansToDegrees(this.physicsBody.a);
45
+ }
46
+ addChild(child) {
47
+ this.node.addChild(child);
48
+ }
49
+ }
@@ -0,0 +1,20 @@
1
+ import { EntityManager, EventManager, System } from 'entityx-ts';
2
+ export declare const DynamicBody = 2;
3
+ export declare const KinematicBody = 1;
4
+ export declare const StaticBody = 0;
5
+ export declare function setColliderMatrix(colliderMatrix?: boolean[][]): void;
6
+ export declare class PhysicsSystem implements System {
7
+ space: cp.Space;
8
+ _debugNode: cc.PhysicsDebugNode;
9
+ listRemoveBody: cp.Body[];
10
+ listRemoveShape: cp.Shape[];
11
+ colliderMatrix: boolean[][];
12
+ configure(event_manager: EventManager): void;
13
+ update(entities: EntityManager, events: EventManager, dt: number): void;
14
+ collisionBegin(arbiter: cp.Arbiter, space: cp.Space): boolean;
15
+ collisionPre(arbiter: cp.Arbiter, space: cp.Space): boolean;
16
+ collisionPost(arbiter: cp.Arbiter, space: cp.Space): boolean;
17
+ collisionSeparate(arbiter: cp.Arbiter, space: cp.Space): boolean;
18
+ addDebug(): void;
19
+ }
20
+ //# sourceMappingURL=PhysicsSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/chipmunk/PhysicsSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAO5E,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,UAAU,IAAI,CAAA;AAE3B,wBAAgB,iBAAiB,CAAC,cAAc,cAAW,QAG1D;AAED,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,EAAE,CAAC,KAAK,CAAA;IACf,UAAU,EAAE,EAAE,CAAC,gBAAgB,CAAA;IAC/B,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,CAAK;IAC9B,eAAe,EAAE,EAAE,CAAC,KAAK,EAAE,CAAK;IAChC,cAAc,cAAW;IAEzB,SAAS,CAAC,aAAa,EAAE,YAAY;IAuKrC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IA2BhE,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK;IA2BnD,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK;IAKjD,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK;IAKlD,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK;IAkBtD,QAAQ;CAMT"}
@@ -0,0 +1,259 @@
1
+ import { EventTypes } from 'entityx-ts';
2
+ import { NodeComp } from '../core/NodeComp';
3
+ import { GameWorld } from '../gworld';
4
+ import { instantiate } from '../helper';
5
+ import { PhysicsBoxCollider, PhysicsCircleCollider, PhysicsPolygonCollider, RigidBody } from './PhysicsComponent';
6
+ import { PhysicsSprite } from './PhysicsSprite';
7
+ export const DynamicBody = 2;
8
+ export const KinematicBody = 1;
9
+ export const StaticBody = 0;
10
+ export function setColliderMatrix(colliderMatrix = [[true]]) {
11
+ const physicsSystem = GameWorld.Instance.systems.get(PhysicsSystem);
12
+ physicsSystem.colliderMatrix = colliderMatrix;
13
+ }
14
+ export class PhysicsSystem {
15
+ space;
16
+ _debugNode;
17
+ listRemoveBody = [];
18
+ listRemoveShape = [];
19
+ colliderMatrix = [[true]];
20
+ configure(event_manager) {
21
+ this.space = new cp.Space();
22
+ this.space.gravity = cp.v(0, -98);
23
+ this.space.iterations = 60;
24
+ this.space.collisionSlop = 0.5;
25
+ this.space.setDefaultCollisionHandler(this.collisionBegin.bind(this), this.collisionPre.bind(this), this.collisionPost.bind(this), this.collisionSeparate.bind(this));
26
+ event_manager.subscribe(EventTypes.ComponentAdded, PhysicsBoxCollider, ({ entity, component: box }) => {
27
+ // console.log('ComponentAddedEvent PhysicsBoxCollider', box)
28
+ let rigidBody = entity.getComponent(RigidBody);
29
+ if (!rigidBody) {
30
+ rigidBody = instantiate(RigidBody);
31
+ entity.assign(rigidBody);
32
+ }
33
+ const { type = DynamicBody, density = 1, friction = 0.5, restitution = 0.3, isSensor, isLockRotate, tag = 0 } = rigidBody.props;
34
+ const { width, height, offset = [] } = box.props;
35
+ const [x = 0, y = 0] = offset;
36
+ const node = entity.getComponent(NodeComp);
37
+ const hw = width * 0.5;
38
+ const hh = height * 0.5;
39
+ let shape;
40
+ let body;
41
+ if (type === DynamicBody) {
42
+ body = new cp.Body(density, isLockRotate ? Infinity : cp.momentForBox(density, width, height));
43
+ shape = new cp.BoxShape2(body, new cp.BB(-hw + x, -hh + y, hw + x, hh + y));
44
+ body.setPos(node.position);
45
+ this.space.addShape(shape);
46
+ this.space.addBody(body);
47
+ }
48
+ else {
49
+ body = new cp.Body(Infinity, Infinity);
50
+ body.nodeIdleTime = Infinity;
51
+ shape = new cp.BoxShape2(body, new cp.BB(-hw + x, -hh + y, hw + x, hh + y));
52
+ this.space.addStaticShape(shape);
53
+ body.setPos(node.position);
54
+ this.space.reindexStatic();
55
+ }
56
+ shape.setElasticity(restitution);
57
+ shape.setFriction(friction);
58
+ shape.setSensor(isSensor);
59
+ const physicsNode = new PhysicsSprite(node.instance, body);
60
+ rigidBody.physicSprite = physicsNode;
61
+ rigidBody.node = node;
62
+ rigidBody.body = body;
63
+ body.data = node;
64
+ shape.group = tag;
65
+ box.node = node;
66
+ });
67
+ event_manager.subscribe(EventTypes.ComponentAdded, PhysicsCircleCollider, ({ entity, component }) => {
68
+ // console.log('ComponentAddedEvent PhysicsCircleCollider', component)
69
+ let rigidBody = entity.getComponent(RigidBody);
70
+ if (!rigidBody) {
71
+ rigidBody = instantiate(RigidBody);
72
+ entity.assign(rigidBody);
73
+ }
74
+ const { type = DynamicBody, isLockRotate, density = 1, friction = 0.5, restitution = 0.3, isSensor = false, tag = 0, } = rigidBody.props;
75
+ const node = entity.getComponent(NodeComp);
76
+ const { radius, offset = [] } = component.props;
77
+ const [x = 0, y = 0] = offset;
78
+ const { width, height } = node.contentSize;
79
+ const { scaleX, scaleY, anchorX, anchorY } = node;
80
+ const offVect = new cp.Vect(x - width * anchorX * scaleX, y - height * scaleY * anchorY);
81
+ let shape;
82
+ let body;
83
+ if (type === DynamicBody) {
84
+ body = new cp.Body(density, isLockRotate ? Infinity : cp.momentForCircle(density, radius, radius, offVect));
85
+ shape = new cp.CircleShape(body, radius, offVect);
86
+ body.setPos(node.position);
87
+ this.space.addShape(shape);
88
+ this.space.addBody(body);
89
+ }
90
+ else {
91
+ body = new cp.Body(Infinity, Infinity);
92
+ body.nodeIdleTime = Infinity;
93
+ shape = new cp.CircleShape(body, radius, offVect);
94
+ this.space.addStaticShape(shape);
95
+ body.setPos(node.position);
96
+ this.space.reindexStatic();
97
+ }
98
+ shape.setElasticity(restitution);
99
+ shape.setFriction(friction);
100
+ shape.setSensor(isSensor);
101
+ const physicsNode = new PhysicsSprite(node.instance, body);
102
+ // console.log(position instanceof b2Vec2, zero instanceof b2Vec2)
103
+ rigidBody.physicSprite = physicsNode;
104
+ rigidBody.node = node;
105
+ rigidBody.body = body;
106
+ body.data = node;
107
+ shape.group = tag;
108
+ component.node = node;
109
+ });
110
+ event_manager.subscribe(EventTypes.ComponentAdded, PhysicsPolygonCollider, ({ entity, component }) => {
111
+ // console.log('ComponentAddedEvent PhysicsPolygonCollider', component)
112
+ let rigidBody = entity.getComponent(RigidBody);
113
+ if (!rigidBody) {
114
+ rigidBody = instantiate(RigidBody);
115
+ entity.assign(rigidBody);
116
+ }
117
+ const { type = DynamicBody, isLockRotate, density = 1, friction = 0.5, restitution = 0.3, isSensor, tag = 0 } = rigidBody.props;
118
+ const node = entity.getComponent(NodeComp);
119
+ const { points, offset = [] } = component.props;
120
+ const [x = 0, y = 0] = offset;
121
+ const { width, height } = node.contentSize;
122
+ const { scaleX, scaleY, anchorX, anchorY } = node;
123
+ const offVect = new cp.Vect(x - width * anchorX * scaleX, y - height * scaleY * anchorY);
124
+ const fixedPoints = [];
125
+ points.forEach((p) => {
126
+ const px = p.x || p[0];
127
+ const py = p.y || p[1];
128
+ fixedPoints.push(px);
129
+ fixedPoints.push(py);
130
+ });
131
+ let shape;
132
+ let body;
133
+ if (type === DynamicBody) {
134
+ body = new cp.Body(density, isLockRotate ? Infinity : cp.momentForPoly(density, fixedPoints, offVect));
135
+ shape = new cp.PolyShape(body, fixedPoints, offVect);
136
+ body.setPos(node.position);
137
+ this.space.addShape(shape);
138
+ this.space.addBody(body);
139
+ }
140
+ else {
141
+ body = new cp.Body(Infinity, Infinity);
142
+ body.nodeIdleTime = Infinity;
143
+ shape = new cp.PolyShape(body, fixedPoints, offVect);
144
+ this.space.addStaticShape(shape);
145
+ body.setPos(node.position);
146
+ this.space.reindexStatic();
147
+ }
148
+ shape.setElasticity(restitution);
149
+ shape.setFriction(friction);
150
+ shape.setSensor(isSensor);
151
+ const physicsNode = new PhysicsSprite(node.instance, body);
152
+ rigidBody.physicSprite = physicsNode;
153
+ rigidBody.node = node;
154
+ rigidBody.body = body;
155
+ body.data = node;
156
+ shape.group = tag;
157
+ component.node = node;
158
+ });
159
+ event_manager.subscribe(EventTypes.ComponentRemoved, RigidBody, ({ component }) => {
160
+ // console.log('ComponentRemovedEvent RigidBody', component)
161
+ if (component.enabled && component.physicSprite instanceof PhysicsSprite) {
162
+ const body = component.physicSprite.getBody();
163
+ if (body && this.space.containsBody(body)) {
164
+ body.shapeList.forEach((shape) => {
165
+ if (shape && this.space.containsShape(shape)) {
166
+ if (!this.listRemoveShape.includes(shape)) {
167
+ this.listRemoveShape.push(shape);
168
+ }
169
+ }
170
+ });
171
+ this.listRemoveBody.push(body);
172
+ }
173
+ }
174
+ });
175
+ }
176
+ update(entities, events, dt) {
177
+ if (this.space) {
178
+ this.space.step(dt);
179
+ }
180
+ // this.space.addPostStepCallback(() => {
181
+ // cc.log('addPostStepCallback');
182
+ this.listRemoveShape.forEach((shape) => {
183
+ if (shape && this.space.containsShape(shape)) {
184
+ this.space.removeShape(shape);
185
+ }
186
+ });
187
+ this.listRemoveBody.forEach((body) => {
188
+ if (body && this.space.containsBody(body)) {
189
+ this.space.removeBody(body);
190
+ }
191
+ });
192
+ this.listRemoveBody = [];
193
+ this.listRemoveShape = [];
194
+ // })
195
+ for (const entt of entities.entities_with_components(RigidBody)) {
196
+ const comp = entt.getComponent(RigidBody);
197
+ if (comp.node && comp.node.active && comp.enabled) {
198
+ comp.physicSprite.update(dt);
199
+ }
200
+ }
201
+ }
202
+ collisionBegin(arbiter, space) {
203
+ const shapes = arbiter.getShapes();
204
+ // cc.log(arbiter);
205
+ const node1 = arbiter.body_a.data;
206
+ const node2 = arbiter.body_b.data;
207
+ const groupA = shapes[0].group;
208
+ const groupB = shapes[1].group;
209
+ // cc.log(groupA, groupB, this.colliderMatrix[groupA][groupB])
210
+ if (!this.colliderMatrix[groupA][groupB]) {
211
+ return false;
212
+ }
213
+ const phys1 = node1.getComponent(RigidBody);
214
+ const phys2 = node2.getComponent(RigidBody);
215
+ if (node1 && node1.active) {
216
+ if (phys1 && phys2 && phys1.props.onBeginContact) {
217
+ phys1.props.onBeginContact(phys2);
218
+ }
219
+ }
220
+ if (node2 && node2.active) {
221
+ if (phys1 && phys2 && phys2.props.onBeginContact) {
222
+ phys2.props.onBeginContact(phys1);
223
+ }
224
+ }
225
+ return true;
226
+ }
227
+ collisionPre(arbiter, space) {
228
+ // cc.log('collisionPre');
229
+ return true;
230
+ }
231
+ collisionPost(arbiter, space) {
232
+ // cc.log('collisionPost');
233
+ return true;
234
+ }
235
+ collisionSeparate(arbiter, space) {
236
+ // cc.log('collisionSeparate');
237
+ const node1 = arbiter.body_a.data;
238
+ const node2 = arbiter.body_b.data;
239
+ const phys1 = node1.getComponent(RigidBody);
240
+ const phys2 = node2.getComponent(RigidBody);
241
+ if (node1 && node1.active) {
242
+ if (phys1 && phys2 && phys1.props.onEndContact) {
243
+ phys1.props.onEndContact(phys2);
244
+ }
245
+ }
246
+ if (node2 && node2.active) {
247
+ if (phys1 && phys2 && phys2.props.onEndContact) {
248
+ phys2.props.onEndContact(phys1);
249
+ }
250
+ }
251
+ return true;
252
+ }
253
+ addDebug() {
254
+ const currentScene = cc.director.getRunningScene();
255
+ this._debugNode = new cc.PhysicsDebugNode(this.space);
256
+ this._debugNode.visible = true;
257
+ currentScene.addChild(this._debugNode, 100);
258
+ }
259
+ }
@@ -0,0 +1,24 @@
1
+ import { Vec2 } from '..';
2
+ export * from './PhysicsComponent';
3
+ export * from './PhysicsSprite';
4
+ export * from './PhysicsSystem';
5
+ export declare function setupPhysics(colliderMatrix?: boolean[][], isDebugDraw?: boolean, gravity?: {
6
+ x: number;
7
+ y: number;
8
+ equals(other: /*elided*/ any): boolean;
9
+ add(value: cc.Point | Vec2): /*elided*/ any;
10
+ addSelf(value: cc.Point | Vec2): /*elided*/ any;
11
+ sub(value: cc.Point | Vec2): /*elided*/ any;
12
+ mul(multiply: number): /*elided*/ any;
13
+ mulSelf(multiply: number): /*elided*/ any;
14
+ mag(): number;
15
+ normalizeSelf(): /*elided*/ any;
16
+ normalize(): /*elided*/ any;
17
+ cross(other: Vec2): number;
18
+ signAngle(other: Vec2): number;
19
+ lengthSqr(): number;
20
+ dot(other: Vec2): number;
21
+ angle(other: Vec2): number;
22
+ distance(other: /*elided*/ any): number;
23
+ }): void;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chipmunk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,IAAI,EAAE,MAAM,IAAI,CAAA;AAGpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,cAAc,cAAW,EAAE,WAAW,UAAQ,EAAE,OAAO;;;;;;;;;;;;;;;;;;CAAe,QAOlG"}
@@ -0,0 +1,13 @@
1
+ import { GameWorld, Vec2 } from '..';
2
+ import { PhysicsSystem } from './PhysicsSystem';
3
+ export * from './PhysicsComponent';
4
+ export * from './PhysicsSprite';
5
+ export * from './PhysicsSystem';
6
+ export function setupPhysics(colliderMatrix = [[true]], isDebugDraw = false, gravity = Vec2(0, -98)) {
7
+ const physicsSystem = GameWorld.Instance.addSystemAndUpdate(PhysicsSystem);
8
+ if (isDebugDraw) {
9
+ physicsSystem.addDebug();
10
+ }
11
+ physicsSystem.colliderMatrix = colliderMatrix;
12
+ physicsSystem.space.gravity = gravity;
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"Scene.d.ts","sourceRoot":"","sources":["../../src/core/Scene.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,qBAAa,cAAe,SAAQ,iBAAiB;IACnD,MAAM;CASP"}
1
+ {"version":3,"file":"Scene.d.ts","sourceRoot":"","sources":["../../src/core/Scene.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,qBAAa,cAAe,SAAQ,iBAAiB;IACnD,MAAM;CAYP"}
@@ -6,7 +6,10 @@ export class SceneComponent extends EnhancedComponent {
6
6
  const world = GameWorld.Instance;
7
7
  world.entities.reset();
8
8
  const root = world.entities.create();
9
- const node = root.assign(new NodeComp(cc.director.getRunningScene(), root));
9
+ const scene = cc.director.getRunningScene();
10
+ scene.unscheduleAllCallbacks();
11
+ scene.stopAllActions();
12
+ const node = root.assign(new NodeComp(scene, root));
10
13
  const sceneComponent = root.assign(this);
11
14
  sceneComponent.node = node;
12
15
  return sceneComponent;
@@ -15,7 +15,7 @@ export class NoRenderSystem {
15
15
  swallowTouches: true,
16
16
  onTouchBegan: function (touch) {
17
17
  const { onTouchStart } = touchComp.props;
18
- if (!nodeComp.active)
18
+ if (!nodeComp.active || !touchComp.enabled)
19
19
  return false;
20
20
  // console.log('onTouchBegan', onTouchStart)
21
21
  if (!nodeComp.parent) {
@@ -1,4 +1,4 @@
1
- import { EntityManager, EventManager, System } from 'entityx-ts';
1
+ import { EventManager, System } from 'entityx-ts';
2
2
  export declare enum SpriteTypes {
3
3
  SIMPLE = 0,
4
4
  SLICED = 1,
@@ -17,6 +17,5 @@ export declare class RenderSystem implements System {
17
17
  private onAddTiledMap;
18
18
  private onAddMotionStreak;
19
19
  private onRemovedNodeComp;
20
- update(entities: EntityManager, events: EventManager, dt: number): any;
21
20
  }
22
21
  //# sourceMappingURL=RenderSystem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAKlG,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AA4CD,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAgBxB;IAED,OAAO,CAAC,eAAe,CAatB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAUxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
1
+ {"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAKnF,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AA4CD,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAgBxB;IAED,OAAO,CAAC,eAAe,CAatB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAUxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;CAKF"}
@@ -131,7 +131,4 @@ export class RenderSystem {
131
131
  node.instance.removeFromParent(true);
132
132
  }
133
133
  };
134
- update() {
135
- // throw new Error('Method not implemented.');
136
- }
137
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/cocos",
3
- "version": "2.3.10",
3
+ "version": "2.4.1",
4
4
  "description": "safe-engine with cocos renderer support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "@cocos/dragonbones-js": "^1.0.2",
25
25
  "@esotericsoftware/spine-core": "^4.2.93",
26
26
  "box2d-wasm": "^7.0.0",
27
- "cocos-html5-ts": "^2.0.3",
27
+ "cocos-html5-ts": "^2.1.2",
28
28
  "entityx-ts": "^2.3.1"
29
29
  },
30
30
  "author": "",
@@ -1,6 +0,0 @@
1
- export * from './decorator';
2
- export * from './EnhancedComponent';
3
- export * from './NodeComp';
4
- export * from './NodePool';
5
- export * from './Scene';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
@@ -1,5 +0,0 @@
1
- export * from './decorator';
2
- export * from './EnhancedComponent';
3
- export * from './NodeComp';
4
- export * from './NodePool';
5
- export * from './Scene';
@@ -1,19 +0,0 @@
1
- import { PixiArmatureDisplay } from 'dragonbones-pixijs';
2
- import { Application } from 'pixi.js';
3
- export declare function loadDragonBonesAssets({ skeleton, atlas, texture }: {
4
- skeleton: any;
5
- atlas: any;
6
- texture: any;
7
- }): Promise<any>;
8
- export declare class PixiDragonBonesSprite extends cc.Sprite {
9
- _canvas: any;
10
- _pixiApp: Application;
11
- _texture: cc.Texture2D;
12
- _config: any;
13
- _armatureDisplay: PixiArmatureDisplay;
14
- constructor(config: any);
15
- _setupArmature(): void;
16
- updateTexture(): void;
17
- onExit(): void;
18
- }
19
- //# sourceMappingURL=PixiDragonBonesSprite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PixiDragonBonesSprite.d.ts","sourceRoot":"","sources":["../../src/dragonbones/PixiDragonBonesSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAe,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,WAAW,EAAU,MAAM,SAAS,CAAA;AAE7C,wBAAgB,qBAAqB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE;;;;CAAA,gBAGjE;AAED,qBAAa,qBAAsB,SAAQ,EAAE,CAAC,MAAM;IAClD,OAAO,EAAE,GAAG,CAAA;IACZ,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;IACtB,OAAO,MAAA;IACP,gBAAgB,EAAE,mBAAmB,CAAA;gBACzB,MAAM,KAAA;IA+BlB,cAAc;IAuBd,aAAa;IASb,MAAM;CAQP"}