@safe-engine/pixi 8.4.7 → 8.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +17 -25
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +0 -23
  4. package/dist/box2d-wasm/ContactListener.d.ts +1 -1
  5. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
  6. package/dist/box2d-wasm/ContactListener.js +50 -18
  7. package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
  8. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  9. package/dist/box2d-wasm/PhysicsComponent.js +44 -11
  10. package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
  11. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  12. package/dist/box2d-wasm/PhysicsSprite.js +24 -3
  13. package/dist/box2d-wasm/PhysicsSystem.d.ts +5 -3
  14. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  15. package/dist/box2d-wasm/PhysicsSystem.js +135 -45
  16. package/dist/collider/CollideComponent.d.ts +27 -10
  17. package/dist/collider/CollideComponent.d.ts.map +1 -1
  18. package/dist/collider/CollideComponent.js +10 -12
  19. package/dist/collider/helper/Intersection.d.ts +6 -6
  20. package/dist/collider/helper/Intersection.d.ts.map +1 -1
  21. package/dist/collider/helper/Intersection.js +4 -4
  22. package/dist/collider/index.d.ts +1 -0
  23. package/dist/collider/index.d.ts.map +1 -1
  24. package/dist/collider/index.js +1 -0
  25. package/dist/components/NodeComp.d.ts +62 -36
  26. package/dist/components/NodeComp.d.ts.map +1 -1
  27. package/dist/components/NodeComp.js +18 -99
  28. package/dist/core/Color.d.ts.map +1 -1
  29. package/dist/dragonbones/DragonBonesComponent.d.ts +3 -2
  30. package/dist/dragonbones/DragonBonesComponent.d.ts.map +1 -1
  31. package/dist/dragonbones/DragonBonesComponent.js +1 -1
  32. package/dist/dragonbones/DragonBonesSystem.js +2 -2
  33. package/dist/gui/GUISystem.d.ts.map +1 -1
  34. package/dist/gui/GUISystem.js +5 -6
  35. package/dist/helper/utils.d.ts +0 -6
  36. package/dist/helper/utils.d.ts.map +1 -1
  37. package/dist/helper/utils.js +0 -12
  38. package/dist/index.d.ts +0 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +0 -5
  41. package/dist/norender/NoRenderComponent.d.ts +5 -1
  42. package/dist/norender/NoRenderComponent.d.ts.map +1 -1
  43. package/dist/norender/NoRenderSystem.d.ts.map +1 -1
  44. package/dist/norender/NoRenderSystem.js +8 -9
  45. package/dist/render/RenderComponent.d.ts +6 -17
  46. package/dist/render/RenderComponent.d.ts.map +1 -1
  47. package/dist/render/RenderComponent.js +26 -18
  48. package/dist/spine/lib/require-shim.d.ts.map +1 -1
  49. package/dist/spine/lib/require-shim.js +1 -1
  50. package/package.json +6 -7
  51. package/.github/workflows/npm-publish.yml +0 -35
  52. package/src/app.ts +0 -91
  53. package/src/base/EnhancedComponent.ts +0 -38
  54. package/src/base/gworld.ts +0 -20
  55. package/src/base/index.ts +0 -14
  56. package/src/base/utils.ts +0 -23
  57. package/src/box2d-wasm/ContactListener.ts +0 -66
  58. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  59. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  60. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  61. package/src/box2d-wasm/debugDraw.ts +0 -249
  62. package/src/box2d-wasm/index.ts +0 -19
  63. package/src/collider/CollideComponent.ts +0 -257
  64. package/src/collider/CollideSystem.ts +0 -166
  65. package/src/collider/helper/Intersection.ts +0 -139
  66. package/src/collider/helper/utils.ts +0 -37
  67. package/src/collider/index.ts +0 -16
  68. package/src/components/BaseComponent.ts +0 -17
  69. package/src/components/NodeComp.ts +0 -442
  70. package/src/components/Scene.ts +0 -17
  71. package/src/core/Color.ts +0 -7
  72. package/src/core/LoadingBar.ts +0 -63
  73. package/src/core/NodePool.ts +0 -28
  74. package/src/core/Size.ts +0 -21
  75. package/src/core/Vec2.ts +0 -108
  76. package/src/core/director.ts +0 -11
  77. package/src/core/index.ts +0 -7
  78. package/src/core/loader.ts +0 -14
  79. package/src/core/math.ts +0 -22
  80. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  81. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  82. package/src/dragonbones/index.ts +0 -11
  83. package/src/gui/GUIComponent.ts +0 -155
  84. package/src/gui/GUISystem.ts +0 -125
  85. package/src/helper/utils.ts +0 -50
  86. package/src/index.ts +0 -21
  87. package/src/norender/NoRenderComponent.ts +0 -60
  88. package/src/norender/NoRenderSystem.ts +0 -67
  89. package/src/norender/Touch.ts +0 -37
  90. package/src/planck/PhysicsComponent.ts +0 -83
  91. package/src/planck/PhysicsSprite.ts +0 -43
  92. package/src/planck/PhysicsSystem.ts +0 -201
  93. package/src/planck/index.ts +0 -3
  94. package/src/render/RenderComponent.ts +0 -132
  95. package/src/render/RenderSystem.ts +0 -64
  96. package/src/richtext/RichTextComp.ts +0 -50
  97. package/src/richtext/RichTextSystem.ts +0 -26
  98. package/src/richtext/html-text-parser.ts +0 -87
  99. package/src/richtext/index.ts +0 -8
  100. package/src/spine/SpineComponent.ts +0 -18
  101. package/src/spine/SpineSystem.ts +0 -30
  102. package/src/spine/index.ts +0 -11
  103. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  104. package/src/spine/lib/Spine.ts +0 -894
  105. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  106. package/src/spine/lib/SpinePipe.ts +0 -203
  107. package/src/spine/lib/SpineTexture.ts +0 -143
  108. package/src/spine/lib/assets/atlasLoader.ts +0 -158
  109. package/src/spine/lib/assets/skeletonLoader.ts +0 -81
  110. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  111. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  112. package/src/spine/lib/darktint/DarkTintShader.ts +0 -74
  113. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  114. package/src/spine/lib/index.ts +0 -43
  115. package/src/spine/lib/require-shim.ts +0 -43
  116. package/tsconfig.json +0 -18
  117. /package/{src/@types → @types}/index.d.ts +0 -0
package/README.md CHANGED
@@ -13,11 +13,12 @@ Safex is an open-source game engine written in TypeScript, combining the power o
13
13
  - All components must be extends from `ComponentX` or `NoRenderComponentX`
14
14
  - `NoRenderComponentX` will append to component of parent node have `ComponentX`, `ComponentX` will be `addChild` to parent node
15
15
  - `node` property represent node, and can pass properties to assign
16
- - Example `<SpriteRender node={{ x: 5, y: 9 }} />`
16
+ - Example `<SpriteRender node={{ xy: [5, 9] }} />`
17
17
  - `$ref` bind component with current class property as string
18
18
  - `$push` push component to list
19
- - `Array(2).map(i)` iteration repeat component 2 times
20
- - `Loading.listItems.map(item, i = 1)` iteration in static property
19
+ - `$refNode` and `$pushNode` for `NodeComp` component from any component.
20
+ - `Array(2).map(_, i)` iteration repeat component 2 times
21
+ - `Loading.listItems.map(item, i = 1)` iteration in class static property
21
22
  - `listItems.map(item, i)` iteration in const variable
22
23
 
23
24
  ## Benefits
@@ -32,7 +33,7 @@ Safex is an open-source game engine written in TypeScript, combining the power o
32
33
  npm install @safe-engine/pixi
33
34
  ```
34
35
 
35
- # Quick start
36
+ # Show case
36
37
 
37
38
  ```sh
38
39
  git clone https://github.com/Safe-engine/pixi-safe-engine-demo
@@ -40,18 +41,8 @@ npm install @safe-engine/pixi
40
41
 
41
42
  ## Basic Example
42
43
 
43
- ```tsx game.ts
44
- import { addGameCanvasTo, loadScene, startGameSystems } from 'safex'
45
- async function start() {
46
- await addGameCanvasTo('canvasId')
47
- startGameSystems()
48
- loadScene(GameScene)
49
- }
50
- start()
51
- ```
52
-
53
44
  ```tsx GameScene.tsx
54
- import { SceneComponent, LabelComp, ButtonComp, SpriteRender, instantiate } from 'safex'
45
+ import { SceneComponent, LabelComp, ButtonComp, SpriteRender, instantiate } from '@safe-engine/pixi'
55
46
  import ColliderSprite from './ColliderSprite'
56
47
 
57
48
  export class GameScene extends ComponentX {
@@ -79,8 +70,8 @@ export class GameScene extends ComponentX {
79
70
  // onTouchEnd={this.onTouchEnd}
80
71
  onTouchMove={this.onTouchMove}
81
72
  />
82
- <LabelComp $ref={this.label} node={{ x: 106, y: 240 }} string="Hello safex" font={defaultFont} />
83
- <SpriteRender $ref={this.sprite} node={{ x: 500, y: 600 }} spriteFrame={'path/to/sprite.png'}>
73
+ <LabelComp $ref={this.label} node={{ xy: [106, 240] }} string="Hello safex" font={defaultFont} />
74
+ <SpriteRender $ref={this.sprite} node={{ xy: [500, 600] }} spriteFrame={'path/to/sprite.png'}>
84
75
  <ButtonComp onPress={this.onPress} />
85
76
  </SpriteRender>
86
77
  </SceneComponent>
@@ -92,17 +83,17 @@ export class GameScene extends ComponentX {
92
83
  ## Collider Events
93
84
 
94
85
  ```tsx
95
- import { BoxCollider, Collider, ComponentX, SpriteRender } from 'safex'
86
+ import { BoxCollider, Collider, ComponentX, SpriteRender } from '@safe-engine/pixi'
96
87
  import { sf_crash } from '../assets'
97
88
 
98
89
  export class ColliderSprite extends ComponentX {
99
90
  onCollisionEnter(other: Collider) {
100
- console.log(other.tag)
91
+ console.log(other.props.tag)
101
92
  }
102
93
 
103
94
  render() {
104
95
  return (
105
- <SpriteRender node={{ x: 640, y: 360 }} spriteFrame={sf_crash}>
96
+ <SpriteRender node={{ xy: [640, 360] }} spriteFrame={sf_crash}>
106
97
  <BoxCollider height={100} width={100}></BoxCollider>
107
98
  </SpriteRender>
108
99
  )
@@ -113,18 +104,19 @@ export class ColliderSprite extends ComponentX {
113
104
  ## Physics Events
114
105
 
115
106
  ```tsx
116
- import { PhysicsBoxCollider, PhysicsCollider, RigidBody, ComponentX, SpriteRender } from 'safex'
107
+ import { ComponentX, SpriteRender } from '@safe-engine/pixi'
108
+ import { DynamicBody, PhysicsBoxCollider, RigidBody } from '@safe-engine/pixi/dist/box2d-wasm'
117
109
  import { sf_crash } from '../assets'
118
110
 
119
111
  export class PhysicsCollider extends ComponentX {
120
- onCollisionEnter(col: PhysicsCollider) {
121
- console.log('onCollisionEnter', col)
112
+ onBeginContact(other: RigidBody) {
113
+ console.log('onBeginContact', other)
122
114
  }
123
115
 
124
116
  render() {
125
117
  return (
126
- <SpriteRender node={{ x: 640, y: 360 }} spriteFrame={sf_crash}>
127
- <RigidBody type="static"></RigidBody>
118
+ <SpriteRender node={{ xy: [640, 360] }} spriteFrame={sf_crash}>
119
+ <RigidBody type={DynamicBody} onBeginContact={this.onBeginContact}></RigidBody>
128
120
  <PhysicsBoxCollider height={100} width={100}></PhysicsBoxCollider>
129
121
  </SpriteRender>
130
122
  )
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQ5D,wBAAsB,SAAS,CAC7B,WAAW,KAAA,EACX,kBAAkB;;;CAA+B,EACjD,YAAY,EAAE,WAAW,EACzB,EAAE,SAAe,GAChB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CA8BhC"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAO5D,wBAAsB,SAAS,CAC7B,WAAW,KAAA,EACX,kBAAkB;;;CAA+B,EACjD,YAAY,EAAE,WAAW,EACzB,EAAE,SAAe,GAChB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CA6BhC"}
package/dist/app.js CHANGED
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { actionManager } from 'pixi-action-ease';
11
11
  import { Application } from 'pixi.js';
12
12
  import { GameWorld } from './base';
13
- import { CollideSystem } from './collider';
14
13
  import { GUISystem } from './gui/GUISystem';
15
14
  import { NoRenderSystem } from './norender/NoRenderSystem';
16
15
  import { RenderSystem } from './render/RenderSystem';
@@ -30,7 +29,6 @@ export function startGame(defaultFont_1) {
30
29
  },
31
30
  canvas: document.getElementById(id),
32
31
  });
33
- // GameWorld.Instance.setup(NodeComp, app.stage)
34
32
  Object.assign(app.canvas.style, {
35
33
  width: `${window.innerWidth}px`,
36
34
  height: `${window.innerHeight}px`,
@@ -56,37 +54,16 @@ function startGameLoop(world) {
56
54
  });
57
55
  // app.ticker.speed = 0.5
58
56
  }
59
- // const systemsList = [RenderSystem, GUISystem, SpineSystem, DragonBonesSystem, CollideSystem, NoRenderSystem]
60
- // export function startGameSystems(list = []) {
61
- // const world = GameWorld.Instance
62
- // systemsList.forEach(system => {
63
- // world.systems.add(system)
64
- // world.systems.configureOnce(system)
65
- // })
66
- // world.listUpdate.push(CollideSystem)
67
- // // world.listUpdate.push(PhysicsSystem)
68
- // list.forEach(system => {
69
- // world.systems.add(system)
70
- // world.systems.configureOnce(system)
71
- // world.listUpdate.push(system)
72
- // })
73
- // startGameLoop(world)
74
- // // console.log('startGameLoop', world.listUpdate)
75
- // }
76
57
  function initWorld(defaultFont) {
77
58
  const world = GameWorld.Instance;
78
59
  world.systems.add(RenderSystem);
79
- world.systems.add(CollideSystem);
80
60
  world.systems.add(GUISystem);
81
61
  world.systems.add(NoRenderSystem);
82
- world.listUpdate.push(CollideSystem);
83
62
  world.systems.configureOnce(RenderSystem);
84
- world.systems.configureOnce(CollideSystem);
85
63
  world.systems.configureOnce(GUISystem);
86
64
  world.systems.configureOnce(NoRenderSystem);
87
65
  if (defaultFont) {
88
66
  const guiSystem = world.systems.get(GUISystem);
89
67
  guiSystem.defaultFont = defaultFont;
90
68
  }
91
- // startGameLoop(world, app)
92
69
  }
@@ -1,4 +1,4 @@
1
- import { NodeComp } from "..";
1
+ import { NodeComp } from '..';
2
2
  type Meta = {
3
3
  [key: number]: NodeComp;
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ContactListener.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/ContactListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B,KAAK,IAAI,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AACvC,eAAO,MAAM,mBAAmB,GAAI,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,OAAO,OAAO,KAAK;0BAWnE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;wBAwBjC,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;sBAmBjC,KAAK,CAAC,SAAS,GAAG,MAAM,eAAe,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI;uBAGtE,KAAK,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,CAAC,gBAAgB,GAAG,MAAM,GAAG,IAAI;CAK/F,CAAA"}
1
+ {"version":3,"file":"ContactListener.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/ContactListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAG7B,KAAK,IAAI,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AACvC,eAAO,MAAM,mBAAmB,GAAI,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,OAAO,OAAO,KAAK;0BAWnE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;wBAwBjC,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;sBAmBjC,KAAK,CAAC,SAAS,GAAG,MAAM,eAAe,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI;uBAmBtE,KAAK,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,CAAC,gBAAgB,GAAG,MAAM,GAAG,IAAI;CAqB/F,CAAA"}
@@ -1,10 +1,10 @@
1
- import { ColliderPhysics } from "./PhysicsComponent";
1
+ import { RigidBody } from './PhysicsComponent';
2
2
  export const makeContactListener = (world, metadata, box2D) => {
3
3
  const { JSContactListener, getPointer, NULL } = box2D;
4
4
  function getContactById(contact) {
5
5
  for (let contactList = world.GetContactList(); getPointer(contactList) !== getPointer(NULL); contactList = contactList.GetNext()) {
6
6
  if (getPointer(contactList) === contact) {
7
- console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL));
7
+ // console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL))
8
8
  return contactList;
9
9
  }
10
10
  }
@@ -17,20 +17,20 @@ export const makeContactListener = (world, metadata, box2D) => {
17
17
  const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
18
18
  const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
19
19
  // world.addPostStepCallback(() => {
20
- // // log('addPostStepCallback');
21
20
  // listRemoveShape.forEach((s) => world.removeShape(s))
22
21
  // listRemoveBody.forEach((b) => world.removeBody(b))
23
22
  // listRemoveBody = []
24
23
  // listRemoveShape = []
25
24
  // })
26
- const phys1 = ett1.getComponent(ColliderPhysics);
27
- const phys2 = ett2.getComponent(ColliderPhysics);
25
+ const phys1 = ett1.getComponent(RigidBody);
26
+ const phys2 = ett2.getComponent(RigidBody);
27
+ // console.log('addPostStepCallback', ett1, phys1.props.onBeginContact, phys2.props)
28
28
  if (phys1 && phys2) {
29
- if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionEnter')) {
30
- phys1.props.onCollisionEnter(phys2);
29
+ if (Object.prototype.hasOwnProperty.call(phys1.props, 'onBeginContact')) {
30
+ phys1.props.onBeginContact(phys2);
31
31
  }
32
- if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionEnter')) {
33
- phys2.props.onCollisionEnter(phys1);
32
+ if (Object.prototype.hasOwnProperty.call(phys2.props, 'onBeginContact')) {
33
+ phys2.props.onBeginContact(phys1);
34
34
  }
35
35
  }
36
36
  },
@@ -41,24 +41,56 @@ export const makeContactListener = (world, metadata, box2D) => {
41
41
  const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
42
42
  const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
43
43
  // const event1 = ett1.getComponent(NodeComp)
44
- const phys1 = ett1.getComponent(ColliderPhysics);
45
- const phys2 = ett2.getComponent(ColliderPhysics);
44
+ const phys1 = ett1.getComponent(RigidBody);
45
+ const phys2 = ett2.getComponent(RigidBody);
46
46
  // const event2 = ett2.getComponent(NodeComp)
47
47
  if (phys1 && phys2) {
48
- if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionExit')) {
49
- phys1.props.onCollisionExit(phys2);
48
+ if (Object.prototype.hasOwnProperty.call(phys1.props, 'onEndContact')) {
49
+ phys1.props.onEndContact(phys2);
50
50
  }
51
- if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionExit')) {
52
- phys2.props.onCollisionExit(phys1);
51
+ if (Object.prototype.hasOwnProperty.call(phys2.props, 'onEndContact')) {
52
+ phys2.props.onEndContact(phys1);
53
53
  }
54
54
  }
55
55
  },
56
56
  PreSolve(contact, oldManifold) {
57
- console.log('collisionSeparate');
57
+ if (typeof contact === 'number') {
58
+ contact = getContactById(contact);
59
+ }
60
+ const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
61
+ const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
62
+ // const event1 = ett1.getComponent(NodeComp)
63
+ const phys1 = ett1.getComponent(RigidBody);
64
+ const phys2 = ett2.getComponent(RigidBody);
65
+ // const event2 = ett2.getComponent(NodeComp)
66
+ if (phys1 && phys2) {
67
+ if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
68
+ phys1.props.onPostSolve(phys2, oldManifold);
69
+ }
70
+ if (Object.prototype.hasOwnProperty.call(phys2.props, 'onPostSolve')) {
71
+ phys2.props.onPostSolve(phys1, oldManifold);
72
+ }
73
+ }
58
74
  },
59
75
  PostSolve(contact, impulse) {
60
- console.log('collisionPost');
61
- }
76
+ if (typeof contact === 'number') {
77
+ contact = getContactById(contact);
78
+ }
79
+ const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
80
+ const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
81
+ // const event1 = ett1.getComponent(NodeComp)
82
+ const phys1 = ett1.getComponent(RigidBody);
83
+ const phys2 = ett2.getComponent(RigidBody);
84
+ // const event2 = ett2.getComponent(NodeComp)
85
+ if (phys1 && phys2) {
86
+ if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
87
+ phys1.props.onPostSolve(phys2, impulse);
88
+ }
89
+ if (Object.prototype.hasOwnProperty.call(phys2.props, 'onPostSolve')) {
90
+ phys2.props.onPostSolve(phys1, impulse);
91
+ }
92
+ }
93
+ },
62
94
  });
63
95
  return listener;
64
96
  };
@@ -1,50 +1,47 @@
1
- import { BodyType, Vec2 } from 'planck';
2
- import { NoRenderComponentX } from '..';
1
+ import { BaseComponentProps, Vec2 } from '..';
2
+ import { NoRenderComponentX } from '../components/BaseComponent';
3
3
  import { PhysicsSprite } from './PhysicsSprite';
4
4
  interface RigidBodyProps {
5
- type?: BodyType;
5
+ type?: 0 | 1 | 2;
6
6
  density?: Float;
7
7
  restitution?: Float;
8
8
  friction?: Float;
9
9
  gravityScale?: Float;
10
+ isSensor?: boolean;
11
+ tag?: number;
12
+ onBeginContact?: (other: RigidBody) => void;
13
+ onEndContact?: (other: RigidBody) => void;
14
+ onPreSolve?: (other: RigidBody, impulse?: any) => void;
15
+ onPostSolve?: (other: RigidBody, oldManifold?: any) => void;
10
16
  }
11
17
  export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
12
18
  body: Box2D.b2Body;
13
- }
14
- interface PhysicsMaterialProps {
15
- friction?: number;
16
- restitution?: number;
17
- density?: number;
18
- }
19
- export declare class PhysicsMaterial extends NoRenderComponentX<PhysicsMaterialProps> {
20
- }
21
- interface ColliderPhysicsProps {
22
- tag?: number;
23
- group?: number;
24
- offset?: Vec2;
25
- onCollisionEnter?: (other: ColliderPhysics) => void;
26
- onCollisionExit?: (other: ColliderPhysics) => void;
27
- onCollisionStay?: (other: ColliderPhysics) => void;
28
- }
29
- export declare class ColliderPhysics<T extends ColliderPhysicsProps = ColliderPhysicsProps> extends NoRenderComponentX<T, PhysicsSprite['node']> {
30
- enabled: boolean;
31
- instance: PhysicsSprite;
32
- }
33
- interface BoxColliderPhysicsProps extends ColliderPhysicsProps {
19
+ physicSprite: PhysicsSprite;
20
+ set linearVelocity(vel: Vec2);
21
+ get linearVelocity(): Vec2;
22
+ applyForceToCenter(vel: Vec2): void;
23
+ applyLinearImpulseToCenter(vel: Vec2): void;
24
+ set position(pos: Vec2);
25
+ get position(): Vec2;
26
+ }
27
+ interface BoxColliderPhysicsProps {
34
28
  width: number;
35
29
  height: number;
30
+ offset?: [number, number];
36
31
  }
37
- export declare class BoxColliderPhysics extends ColliderPhysics<BoxColliderPhysicsProps> {
32
+ export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<PhysicsBoxCollider>> {
38
33
  }
39
- interface CircleColliderPhysicsProps extends ColliderPhysicsProps {
34
+ interface CircleColliderPhysicsProps {
40
35
  radius: number;
36
+ offset?: [number, number];
41
37
  }
42
- export declare class CircleColliderPhysics extends ColliderPhysics<CircleColliderPhysicsProps> {
38
+ export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<PhysicsCircleCollider>> {
43
39
  }
44
- interface PolygonColliderPhysicsProps extends ColliderPhysicsProps {
45
- points: Array<Vec2>;
40
+ interface PolygonColliderPhysicsProps {
41
+ points: Array<Vec2> | [number, number][];
42
+ offset?: [number, number];
46
43
  }
47
- export declare class PolygonColliderPhysics extends ColliderPhysics<PolygonColliderPhysicsProps> {
44
+ export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<PhysicsPolygonCollider>> {
48
45
  }
49
46
  export {};
50
47
  //# sourceMappingURL=PhysicsComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAA;CACrB;AAED,qBAAa,SAAU,SAAQ,kBAAkB,CAAC,cAAc,CAAC;IAC/D,IAAI,EAAE,KAAK,CAAC,MAAM,CAAA;CAmBnB;AAED,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AACD,qBAAa,eAAgB,SAAQ,kBAAkB,CAAC,oBAAoB,CAAC;CAE5E;AAED,UAAU,oBAAoB;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IACnD,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IAClD,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CACnD;AAED,qBAAa,eAAe,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SA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sBAAuB,SAAQ,kBAAkB,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;CAAI"}
@@ -1,17 +1,50 @@
1
- import { NoRenderComponentX } from '..';
1
+ import { Vec2 } from '..';
2
+ import { NoRenderComponentX } from '../components/BaseComponent';
3
+ import { box2D } from './PhysicsSystem';
2
4
  export class RigidBody extends NoRenderComponentX {
3
- }
4
- export class PhysicsMaterial extends NoRenderComponentX {
5
- }
6
- export class ColliderPhysics extends NoRenderComponentX {
7
- constructor() {
8
- super(...arguments);
9
- this.enabled = true;
5
+ set linearVelocity(vel) {
6
+ if (!this.node) {
7
+ return;
8
+ }
9
+ this.body.SetLinearVelocity(new box2D.b2Vec2(vel.x, vel.y));
10
+ }
11
+ get linearVelocity() {
12
+ if (!this.node) {
13
+ return Vec2.ZERO;
14
+ }
15
+ const vel = this.body.GetLinearVelocity();
16
+ return Vec2(vel);
17
+ }
18
+ applyForceToCenter(vel) {
19
+ if (!this.node) {
20
+ return;
21
+ }
22
+ this.body.ApplyForceToCenter(new box2D.b2Vec2(vel.x, vel.y), true);
23
+ }
24
+ applyLinearImpulseToCenter(vel) {
25
+ if (!this.node) {
26
+ return;
27
+ }
28
+ // console.log('applyLinearImpulseToCenter', new box2D.b2Vec2(vel.x, vel.y))
29
+ this.body.ApplyLinearImpulseToCenter(new box2D.b2Vec2(vel.x, vel.y), true);
30
+ }
31
+ set position(pos) {
32
+ this.physicSprite.node.position = Vec2(pos.x, pos.y);
33
+ const physicsPos = new box2D.b2Vec2(pos.x, pos.y);
34
+ // console.log('SetTransform', pos, physicsPos)
35
+ const body = this.body;
36
+ body.SetLinearVelocity(new box2D.b2Vec2(0, 0));
37
+ body.SetAngularVelocity(0);
38
+ body.SetAwake(true);
39
+ body.SetTransform(physicsPos, this.node.rotation);
40
+ }
41
+ get position() {
42
+ return Vec2(this.physicSprite.getBody().GetPosition());
10
43
  }
11
44
  }
12
- export class BoxColliderPhysics extends ColliderPhysics {
45
+ export class PhysicsBoxCollider extends NoRenderComponentX {
13
46
  }
14
- export class CircleColliderPhysics extends ColliderPhysics {
47
+ export class PhysicsCircleCollider extends NoRenderComponentX {
15
48
  }
16
- export class PolygonColliderPhysics extends ColliderPhysics {
49
+ export class PhysicsPolygonCollider extends NoRenderComponentX {
17
50
  }
@@ -3,6 +3,9 @@ export declare class PhysicsSprite {
3
3
  node: Container;
4
4
  physicsBody: Box2D.b2Body;
5
5
  constructor(node: Container, body: Box2D.b2Body);
6
+ update(dt: number): void;
7
+ getBody(): Box2D.b2Body;
8
+ set position(val: Box2D.b2Vec2);
6
9
  get x(): number;
7
10
  get y(): number;
8
11
  get angle(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,qBAAa,aAAa;IACxB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,EAAE,KAAK,CAAC,MAAM,CAAA;gBAEb,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM;IAgB/C,IAAI,CAAC,WAEJ;IAED,IAAI,CAAC,WAEJ;IAMD,IAAI,KAAK,WAER;IAED,QAAQ,CAAC,KAAK,EAAE,SAAS;CAG1B"}
1
+ {"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGnC,qBAAa,aAAa;IACxB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,EAAE,KAAK,CAAC,MAAM,CAAA;gBAEb,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM;IAK/C,MAAM,CAAC,EAAE,EAAE,MAAM;IAkBjB,OAAO;IAIP,IAAI,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,EAE7B;IASD,IAAI,CAAC,WAEJ;IAED,IAAI,CAAC,WAEJ;IAMD,IAAI,KAAK,WAER;IAED,QAAQ,CAAC,KAAK,EAAE,SAAS;CAG1B"}
@@ -1,11 +1,29 @@
1
+ import { Vec2, radiansToDegrees } from '..';
1
2
  export class PhysicsSprite {
2
3
  constructor(node, body) {
3
4
  this.node = node;
4
5
  this.physicsBody = body;
5
6
  }
6
- // set position(val: Box2D.b2Vec2) {
7
- // this.physicsBody.setPosition(val)
8
- // }
7
+ update(dt) {
8
+ if (!this.physicsBody) {
9
+ return;
10
+ }
11
+ // const pos = this.physicsBody.GetPosition()
12
+ // use lerp to smooth the position update
13
+ const pos = Vec2(lerp(this.node.x, this.physicsBody.GetPosition().x, dt * 10), lerp(this.node.y, this.physicsBody.GetPosition().y, dt * 10));
14
+ this.node.position = Vec2(pos.x, pos.y);
15
+ // lerp the rotation
16
+ this.node.rotation = lerp(this.node.rotation, radiansToDegrees(-this.physicsBody.GetAngle()), dt * 10);
17
+ // this.node.setRotation(radiansToDegrees(this.physicsBody.GetAngle()))
18
+ // this.node.setScale(1 / pixelsPerMeter)
19
+ // this.node.setScale(1 / this.physicsBody.GetFixtureList().GetShape().GetRadius())
20
+ }
21
+ getBody() {
22
+ return this.physicsBody;
23
+ }
24
+ set position(val) {
25
+ this.physicsBody.SetTransform(val, this.node.rotation);
26
+ }
9
27
  // set x(val) {
10
28
  // this.physicsBody.setPosition(Vec2(val, this.y))
11
29
  // }
@@ -28,3 +46,6 @@ export class PhysicsSprite {
28
46
  this.node.addChild(child);
29
47
  }
30
48
  }
49
+ function lerp(a, b, t) {
50
+ return a + (b - a) * t;
51
+ }
@@ -1,18 +1,20 @@
1
1
  import { EntityManager, EventManager, System } from 'entityx-ts';
2
2
  import { Graphics } from 'pixi.js';
3
3
  import { Vec2 } from '..';
4
+ export declare const DynamicBody = 2;
5
+ export declare const KinematicBody = 1;
6
+ export declare const StaticBody = 0;
4
7
  export declare let box2D: typeof Box2D;
5
8
  export declare function initBox2d(): Promise<void>;
6
9
  export declare function setColliderMatrix(colliderMatrix?: boolean[][]): void;
7
10
  export declare class PhysicsSystem implements System {
8
11
  world: Box2D.b2World;
9
- listRemoveBody: Body[];
10
- listRemoveShape: Box2D.b2Shape[];
12
+ listRemoveBody: Box2D.b2Body[];
11
13
  colliderMatrix: boolean[][];
12
14
  graphics: Graphics;
13
15
  addDebug(): void;
14
16
  configure(event_manager: EventManager): void;
15
- update(entities: EntityManager, events: EventManager, dt: number): void;
17
+ update(entities: EntityManager, _events: EventManager, dt: number): void;
16
18
  set gravity(val: Vec2);
17
19
  }
18
20
  //# sourceMappingURL=PhysicsSystem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAoC,IAAI,EAAE,MAAM,IAAI,CAAA;AAmB3D,eAAO,IAAI,KAAK,EAAE,OAAO,KAAK,CAAA;AAC9B,wBAAsB,SAAS,kBAE9B;AAED,wBAAgB,iBAAiB,CAAC,cAAc,cAAW,QAG1D;AAOD,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,KAAK,CAAC,OAAO,CAAA;IACpB,cAAc,EAAE,IAAI,EAAE,CAAK;IAC3B,eAAe,EAAE,KAAK,CAAC,OAAO,EAAE,CAAK;IACrC,cAAc,cAAW;IACzB,QAAQ,EAAE,QAAQ,CAAA;IAElB,QAAQ;IAKR,SAAS,CAAC,aAAa,EAAE,YAAY;IA0ErC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IAYhE,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAIpB;C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