@combos-fun/plugin-matterjs 0.0.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 ADDED
@@ -0,0 +1,3 @@
1
+ # @combos-fun/plugin-matterjs
2
+
3
+ Internal workspace package (Combos Fun monorepo).
@@ -0,0 +1,399 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var engine = require('@combos-fun/engine');
5
+ var Matter = require('matter-js');
6
+ var pixi_js = require('pixi.js');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var Matter__default = /*#__PURE__*/_interopDefault(Matter);
11
+
12
+ exports.PhysicsType = void 0;
13
+ (function (PhysicsType) {
14
+ PhysicsType["RECTANGLE"] = "rectangle";
15
+ PhysicsType["CIRCLE"] = "circle";
16
+ PhysicsType["POLYGON"] = "polygon";
17
+ })(exports.PhysicsType || (exports.PhysicsType = {}));
18
+ class Physics extends engine.Component {
19
+ static { this.componentName = 'Physics'; }
20
+ init(params) {
21
+ this.bodyParams = params;
22
+ }
23
+ update() {
24
+ if (this.body && this.gameObject) {
25
+ this.gameObject.transform.anchor.x = 0;
26
+ this.gameObject.transform.anchor.y = 0;
27
+ this.gameObject.transform.position.x = this.body.position.x;
28
+ this.gameObject.transform.position.y = this.body.position.y;
29
+ if (!this.bodyParams.stopRotation) {
30
+ this.gameObject.transform.rotation = this.body.angle;
31
+ }
32
+ }
33
+ }
34
+ onDestroy() {
35
+ Matter__default.default.World.remove(this.PhysicsEngine.world, this.body, true);
36
+ }
37
+ }
38
+
39
+ class BodiesFactory {
40
+ constructor() {
41
+ this.Bodies = Matter__default.default.Bodies;
42
+ }
43
+ create(component) {
44
+ let body = null;
45
+ const { gameObject, bodyParams } = component;
46
+ const coordinate = this.getCoordinate(gameObject);
47
+ const x = bodyParams.position ? bodyParams.position.x : coordinate.x;
48
+ const y = bodyParams.position ? bodyParams.position.y : coordinate.y;
49
+ const halfW = (gameObject.transform.size.width * gameObject.transform.scale.x) / 2;
50
+ const halfH = (gameObject.transform.size.height * gameObject.transform.scale.y) / 2;
51
+ /** Matter.circle approximates with a polygon; NaN/0 radius breaks vertices. */
52
+ const defaultRadius = Math.max(1, Math.min(halfW, halfH));
53
+ switch (bodyParams.type) {
54
+ case exports.PhysicsType.RECTANGLE: {
55
+ const width = gameObject.transform.size.width * gameObject.transform.scale.x;
56
+ const height = gameObject.transform.size.height * gameObject.transform.scale.y;
57
+ body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);
58
+ break;
59
+ }
60
+ case exports.PhysicsType.CIRCLE: {
61
+ const radius = bodyParams.radius ?? defaultRadius;
62
+ body = this.Bodies.circle(x, y, radius, bodyParams.bodyOptions);
63
+ break;
64
+ }
65
+ case exports.PhysicsType.POLYGON: {
66
+ const sides = Math.max(3, bodyParams.sides ?? 6);
67
+ const radius = bodyParams.radius ?? defaultRadius;
68
+ body = this.Bodies.polygon(x, y, sides, radius, bodyParams.bodyOptions);
69
+ break;
70
+ }
71
+ }
72
+ return body;
73
+ }
74
+ getCoordinate(gameObject) {
75
+ const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;
76
+ const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;
77
+ return {
78
+ x,
79
+ y,
80
+ };
81
+ }
82
+ }
83
+
84
+ /** WebGL wireframe overlay for Matter bodies in test mode. */
85
+ class MatterPixiDebugRenderer {
86
+ constructor(opts) {
87
+ this.app = null;
88
+ this.graphics = null;
89
+ this.opts = opts;
90
+ this.engine = opts.engine;
91
+ this.onAfterUpdate = () => this.redraw();
92
+ }
93
+ async init() {
94
+ const { canvas, width, height, resolution = 1 } = this.opts;
95
+ const app = new pixi_js.Application();
96
+ await app.init({
97
+ canvas,
98
+ width,
99
+ height,
100
+ resolution,
101
+ autoDensity: true,
102
+ antialias: true,
103
+ backgroundAlpha: 0.12,
104
+ preference: 'webgl',
105
+ });
106
+ this.app = app;
107
+ this.graphics = new pixi_js.Graphics();
108
+ app.stage.addChild(this.graphics);
109
+ Matter__default.default.Events.on(this.engine, 'afterUpdate', this.onAfterUpdate);
110
+ }
111
+ redraw() {
112
+ const g = this.graphics;
113
+ if (!g) {
114
+ return;
115
+ }
116
+ g.clear();
117
+ const bodies = Matter__default.default.Composite.allBodies(this.engine.world);
118
+ for (let b = 0; b < bodies.length; b++) {
119
+ const body = bodies[b];
120
+ if (body.render?.visible === false) {
121
+ continue;
122
+ }
123
+ const verts = body.vertices;
124
+ if (!verts?.length) {
125
+ continue;
126
+ }
127
+ const v0 = verts[0];
128
+ g.moveTo(v0.x, v0.y);
129
+ for (let i = 1; i < verts.length; i++) {
130
+ g.lineTo(verts[i].x, verts[i].y);
131
+ }
132
+ g.closePath();
133
+ g.stroke({ width: 1, color: 0x00e676, alpha: 0.9 });
134
+ }
135
+ }
136
+ destroy() {
137
+ Matter__default.default.Events.off(this.engine, 'afterUpdate', this.onAfterUpdate);
138
+ if (this.app) {
139
+ this.app.destroy(true, { children: true, texture: true });
140
+ this.app = null;
141
+ }
142
+ this.graphics = null;
143
+ }
144
+ }
145
+
146
+ class PhysicsEngine {
147
+ constructor(game, options) {
148
+ this.debugRenderer = null;
149
+ this.enabled = false;
150
+ this.Engine = Matter__default.default.Engine;
151
+ this.World = Matter__default.default.World;
152
+ this.bodiesFatoty = new BodiesFactory();
153
+ this.Runner = Matter__default.default.Runner;
154
+ this.Constraint = Matter__default.default.Constraint;
155
+ this.game = game;
156
+ this.collisionEvents = ['collisionStart', 'collisionActive', 'collisionEnd'];
157
+ this.bodyEvents = ['tick', 'beforeUpdate', 'afterUpdate', 'beforeRender', 'afterRender', 'afterTick'];
158
+ this.options = options;
159
+ this.runner = this.Runner.create({
160
+ delta: 1000 / (this.options.fps || 60),
161
+ frameDeltaSmoothing: (this.options.deltaSampleSize ?? 1) > 1,
162
+ });
163
+ }
164
+ start() {
165
+ this.engine = this.Engine.create();
166
+ const world = this.World.create(this.options.world);
167
+ this.engine.world = world;
168
+ if (this.options.isTest) {
169
+ const ownCanvas = !this.options.canvas;
170
+ const canvas = this.options.canvas ?? document.createElement('canvas');
171
+ if (ownCanvas && this.options.element) {
172
+ this.options.element.appendChild(canvas);
173
+ }
174
+ const resolution = this.options.resolution || 1;
175
+ this.debugRenderer = new MatterPixiDebugRenderer({
176
+ engine: this.engine,
177
+ canvas,
178
+ width: this.game.canvas.width / resolution,
179
+ height: this.game.canvas.height / resolution,
180
+ resolution,
181
+ });
182
+ void this.debugRenderer.init().catch(err => {
183
+ console.error('[plugin-matterjs] MatterPixiDebugRenderer init failed', err);
184
+ });
185
+ this.Runner.run(this.runner, this.engine);
186
+ }
187
+ this.enabled = true;
188
+ this.initMouse();
189
+ this.initCollisionEvents();
190
+ this.initBodyEvents();
191
+ }
192
+ update(e) {
193
+ if (!this.engine) {
194
+ return;
195
+ }
196
+ if (!this.options.isTest) {
197
+ this.Runner.tick(this.runner, this.engine, e.currentTime);
198
+ }
199
+ }
200
+ stop() {
201
+ this.enabled = false;
202
+ this.runner.enabled = false;
203
+ }
204
+ destroy() {
205
+ this.debugRenderer?.destroy();
206
+ this.debugRenderer = null;
207
+ if (this.engine) {
208
+ Matter__default.default.Runner.stop(this.runner);
209
+ Matter__default.default.Engine.clear(this.engine);
210
+ }
211
+ }
212
+ awake() {
213
+ this.enabled = true;
214
+ this.runner.enabled = true;
215
+ }
216
+ add(component) {
217
+ const body = this.createBodies(component);
218
+ this.World.add(this.engine.world, [body]);
219
+ component.body = body;
220
+ component.Body = Matter__default.default.Body;
221
+ component.PhysicsEngine = this.engine;
222
+ component.Constraint = this.Constraint;
223
+ component.mouseConstraint = this.mouseConstraint;
224
+ component.World = this.World;
225
+ body.component = component;
226
+ }
227
+ change(component) {
228
+ const newBody = this.createBodies(component);
229
+ this.World.remove(this.engine.world, component.body, true);
230
+ this.World.add(this.engine.world, [newBody]);
231
+ component.body = newBody;
232
+ }
233
+ remove(component) {
234
+ this.World.remove(this.engine.world, component.body, true);
235
+ component.body = undefined;
236
+ }
237
+ createBodies(params) {
238
+ const body = this.bodiesFatoty.create(params);
239
+ return body;
240
+ }
241
+ initCollisionEvents() {
242
+ this.collisionEvents.forEach(eventName => {
243
+ Matter__default.default.Events.on(this.engine, eventName, (event) => {
244
+ const pairs = event.pairs ?? [];
245
+ for (let i = 0; i < pairs.length; i++) {
246
+ const pair = pairs[i];
247
+ const { bodyA, bodyB } = pair;
248
+ const componentA = bodyA.component;
249
+ const componentB = bodyB.component;
250
+ componentA.emit(eventName, componentB.gameObject, componentA.gameObject);
251
+ componentB.emit(eventName, componentA.gameObject, componentB.gameObject);
252
+ }
253
+ });
254
+ });
255
+ }
256
+ initMouse() {
257
+ if (this.options.mouse && this.options.mouse.open) {
258
+ const mouse = Matter__default.default.Mouse.create(this.game.canvas);
259
+ let options = this.options.mouse.constraint ? {
260
+ mouse,
261
+ constraint: this.options.mouse.constraint
262
+ } : {
263
+ mouse
264
+ };
265
+ this.mouseConstraint = Matter__default.default.MouseConstraint.create(this.engine, options);
266
+ this.World.add(this.engine.world, this.mouseConstraint);
267
+ }
268
+ }
269
+ initBodyEvents() {
270
+ this.bodyEvents.forEach(eventName => {
271
+ Matter__default.default.Events.on(this.engine, eventName, e => {
272
+ const bodies = e.source.world.bodies;
273
+ bodies.forEach(body => {
274
+ const linked = body;
275
+ linked.component?.emit(eventName, body, linked.component.gameObject);
276
+ });
277
+ });
278
+ });
279
+ }
280
+ }
281
+
282
+ let PhysicsSystem = class PhysicsSystem extends engine.System {
283
+ static { this.systemName = 'PhysicsSystem'; }
284
+ /**
285
+ * System 初始化用,可以配置参数,游戏未开始
286
+ *
287
+ * System init, set params, game is not begain
288
+ * @param param init params
289
+ */
290
+ init(param) {
291
+ this.engine = new PhysicsEngine(this.game, param);
292
+ this.game.canvas.setAttribute('data-pixel-ratio', (param.resolution || '1'));
293
+ }
294
+ /**
295
+ * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。
296
+ *
297
+ * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data.
298
+ */
299
+ awake() { }
300
+ /**
301
+ * System 被安装后,所有的 awake 执行完后
302
+ *
303
+ * Called while the System installed, after all of systems' awake been called
304
+ */
305
+ start() {
306
+ this.engine.start();
307
+ }
308
+ /**
309
+ * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。
310
+ *
311
+ * Called by every loop, can do some operation, change some property or other component property.
312
+ */
313
+ update(e) {
314
+ const changes = this.componentObserver.clear();
315
+ for (const changed of changes) {
316
+ if (changed) {
317
+ this.componentChanged(changed);
318
+ }
319
+ }
320
+ this.engine.update(e);
321
+ }
322
+ componentChanged(changed) {
323
+ if (changed.component instanceof Physics) {
324
+ switch (changed.type) {
325
+ case engine.OBSERVER_TYPE.ADD: {
326
+ if (changed.gameObject.transform.parent && !changed.gameObject.getComponent(Physics).body) {
327
+ this.engine.add(changed.component);
328
+ }
329
+ break;
330
+ }
331
+ case engine.OBSERVER_TYPE.CHANGE: {
332
+ this.engine.change(changed.component);
333
+ break;
334
+ }
335
+ case engine.OBSERVER_TYPE.REMOVE: {
336
+ break;
337
+ }
338
+ }
339
+ }
340
+ else {
341
+ switch (changed.type) {
342
+ case engine.OBSERVER_TYPE.CHANGE: {
343
+ if (changed.component.parent) {
344
+ let physics = changed.gameObject.getComponent(Physics);
345
+ if (physics && !physics.body) {
346
+ this.engine.add(physics);
347
+ }
348
+ }
349
+ else {
350
+ let physics = changed.gameObject.getComponent(Physics);
351
+ physics && this.engine.remove(physics);
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }
357
+ /**
358
+ * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。
359
+ *
360
+ * Like update, called all of gameobject update.
361
+ */
362
+ lateUpdate() { }
363
+ /**
364
+ * 游戏开始和游戏暂停后开始播放的时候调用。
365
+ *
366
+ * Called while the game to play when game pause.
367
+ */
368
+ onResume() {
369
+ if (!this.engine.enabled) {
370
+ this.engine.awake();
371
+ }
372
+ }
373
+ /**
374
+ * 游戏暂停的时候调用。
375
+ *
376
+ * Called while the game paused.
377
+ */
378
+ onPause() {
379
+ this.engine.stop();
380
+ }
381
+ /**
382
+ * System 被销毁的时候调用。
383
+ * Called while the system be destroyed.
384
+ */
385
+ onDestroy() {
386
+ this.engine?.destroy();
387
+ }
388
+ };
389
+ PhysicsSystem = tslib.__decorate([
390
+ engine.decorators.componentObserver({
391
+ Physics: [{ prop: ['bodyParams'], deep: true }],
392
+ Transform: ['_parent'],
393
+ })
394
+ ], PhysicsSystem);
395
+ var PhysicsSystem_default = PhysicsSystem;
396
+
397
+ exports.Physics = Physics;
398
+ exports.PhysicsSystem = PhysicsSystem_default;
399
+ //# sourceMappingURL=plugin-matterjs.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-matterjs.cjs.js","sources":["../lib/Physics.ts","../lib/BodiesFactory.ts","../lib/MatterPixiDebugRenderer.ts","../lib/PhysicsEngine.ts","../lib/PhysicsSystem.ts"],"sourcesContent":["import { Component } from '@combos-fun/engine';\nimport Matter from 'matter-js';\nexport enum PhysicsType {\n RECTANGLE = 'rectangle',\n CIRCLE = 'circle',\n POLYGON = 'polygon',\n}\nexport interface PhysicsParams {\n type?: PhysicsType\n bodyOptions?: {\n isStatic?: boolean,\n restitution?: number,\n density?: number,\n [propName: string]: any,\n },\n position?: {\n x?: number\n y?: number\n }\n sides?: number\n radius?: number\n stopRotation?: boolean\n}\n\nexport class Physics extends Component<PhysicsParams> {\n static componentName: string = 'Physics';\n public bodyParams: PhysicsParams;\n public body: Matter.Body;\n private PhysicsEngine: Matter.Engine;\n\n init(params: PhysicsParams) {\n this.bodyParams = params;\n }\n\n update() {\n if (this.body && this.gameObject) {\n this.gameObject.transform.anchor.x = 0;\n this.gameObject.transform.anchor.y = 0;\n this.gameObject.transform.position.x = this.body.position.x;\n this.gameObject.transform.position.y = this.body.position.y;\n if (!this.bodyParams.stopRotation) {\n this.gameObject.transform.rotation = this.body.angle;\n }\n }\n }\n onDestroy() {\n Matter.World.remove(this.PhysicsEngine.world, this.body, true);\n }\n}\n","import Matter from 'matter-js';\nimport { PhysicsType, Physics } from './Physics';\nimport { GameObject } from '@combos-fun/engine';\ndeclare interface BodyOptions {\n chamfer?: number; // 斜切角\n angle?: number; // 旋转角\n isStatic?: boolean;\n density?: number; // 密度;\n restitution?: number; // 回弹系数\n velocity?: number; // 速率\n speed?: number; // 速度\n motion?: number; // 势能\n mass?: number;\n}\n\nexport interface RectangleParams {\n x: number;\n y: number;\n width: number;\n height: number;\n options: BodyOptions;\n}\n\nexport interface Verctor {\n x: number;\n y: number;\n}\nexport default class BodiesFactory {\n private Bodies: typeof Matter.Bodies;\n constructor() {\n this.Bodies = Matter.Bodies;\n }\n public create(component: Physics): Matter.Body {\n let body: Matter.Body = null;\n const { gameObject, bodyParams } = component;\n const coordinate = this.getCoordinate(gameObject);\n const x = bodyParams.position ? bodyParams.position.x : coordinate.x;\n const y = bodyParams.position ? bodyParams.position.y : coordinate.y;\n const halfW =\n (gameObject.transform.size.width * gameObject.transform.scale.x) / 2;\n const halfH =\n (gameObject.transform.size.height * gameObject.transform.scale.y) / 2;\n /** Matter.circle approximates with a polygon; NaN/0 radius breaks vertices. */\n const defaultRadius = Math.max(1, Math.min(halfW, halfH));\n switch (bodyParams.type) {\n case PhysicsType.RECTANGLE: {\n const width = gameObject.transform.size.width * gameObject.transform.scale.x;\n const height = gameObject.transform.size.height * gameObject.transform.scale.y;\n body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);\n break;\n }\n case PhysicsType.CIRCLE: {\n const radius = bodyParams.radius ?? defaultRadius;\n body = this.Bodies.circle(x, y, radius, bodyParams.bodyOptions);\n break;\n }\n case PhysicsType.POLYGON: {\n const sides = Math.max(3, bodyParams.sides ?? 6);\n const radius = bodyParams.radius ?? defaultRadius;\n body = this.Bodies.polygon(x, y, sides, radius, bodyParams.bodyOptions);\n break;\n }\n }\n return body;\n }\n\n private getCoordinate(gameObject: GameObject): Verctor {\n const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;\n const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;\n return {\n x,\n y,\n };\n }\n}\n","import Matter from 'matter-js';\nimport { Application, Graphics } from 'pixi.js';\n\nexport interface MatterPixiDebugOptions {\n engine: Matter.Engine;\n canvas: HTMLCanvasElement;\n width: number;\n height: number;\n resolution?: number;\n}\n\n/** WebGL wireframe overlay for Matter bodies in test mode. */\nexport class MatterPixiDebugRenderer {\n private readonly engine: Matter.Engine;\n private readonly opts: MatterPixiDebugOptions;\n private app: Application | null = null;\n private graphics: Graphics | null = null;\n private readonly onAfterUpdate: () => void;\n\n constructor(opts: MatterPixiDebugOptions) {\n this.opts = opts;\n this.engine = opts.engine;\n this.onAfterUpdate = () => this.redraw();\n }\n\n async init(): Promise<void> {\n const { canvas, width, height, resolution = 1 } = this.opts;\n const app = new Application();\n await app.init({\n canvas,\n width,\n height,\n resolution,\n autoDensity: true,\n antialias: true,\n backgroundAlpha: 0.12,\n preference: 'webgl',\n });\n this.app = app;\n this.graphics = new Graphics();\n app.stage.addChild(this.graphics);\n Matter.Events.on(this.engine, 'afterUpdate', this.onAfterUpdate);\n }\n\n private redraw(): void {\n const g = this.graphics;\n if (!g) {\n return;\n }\n g.clear();\n const bodies = Matter.Composite.allBodies(this.engine.world);\n for (let b = 0; b < bodies.length; b++) {\n const body = bodies[b];\n if (body.render?.visible === false) {\n continue;\n }\n const verts = body.vertices;\n if (!verts?.length) {\n continue;\n }\n const v0 = verts[0];\n g.moveTo(v0.x, v0.y);\n for (let i = 1; i < verts.length; i++) {\n g.lineTo(verts[i].x, verts[i].y);\n }\n g.closePath();\n g.stroke({ width: 1, color: 0x00e676, alpha: 0.9 });\n }\n }\n\n destroy(): void {\n Matter.Events.off(this.engine, 'afterUpdate', this.onAfterUpdate);\n if (this.app) {\n this.app.destroy(true, { children: true, texture: true });\n this.app = null;\n }\n this.graphics = null;\n }\n}\n","import Matter from 'matter-js';\n\nimport BodiesFactory from './BodiesFactory';\nimport { Component, Game } from '@combos-fun/engine';\nimport type { PhysicsSystemParams } from './PhysicsSystem';\nimport type { Physics } from './Physics';\nimport { MatterPixiDebugRenderer } from './MatterPixiDebugRenderer';\n\nexport interface PhysicsLinkedBody extends Matter.Body {\n component: Physics;\n}\n\nexport default class PhysicsEngine {\n private Engine: typeof Matter.Engine;\n private World: typeof Matter.World;\n private engine: Matter.Engine;\n private bodiesFatoty: BodiesFactory;\n private collisionEvents: string[];\n private bodyEvents: string[];\n private options: PhysicsSystemParams;\n private game: Game;\n private Runner: typeof Matter.Runner;\n private Constraint: typeof Matter.Constraint;\n private mouseConstraint: Matter.MouseConstraint;\n private runner: Matter.Runner;\n private debugRenderer: MatterPixiDebugRenderer | null = null;\n public enabled: boolean = false;\n constructor(game: Game, options: PhysicsSystemParams) {\n this.Engine = Matter.Engine;\n this.World = Matter.World;\n this.bodiesFatoty = new BodiesFactory();\n this.Runner = Matter.Runner;\n this.Constraint = Matter.Constraint;\n this.game = game;\n\n this.collisionEvents = ['collisionStart', 'collisionActive', 'collisionEnd'];\n this.bodyEvents = ['tick', 'beforeUpdate', 'afterUpdate', 'beforeRender', 'afterRender', 'afterTick'];\n this.options = options;\n this.runner = this.Runner.create({\n delta: 1000 / (this.options.fps || 60),\n frameDeltaSmoothing: (this.options.deltaSampleSize ?? 1) > 1,\n });\n }\n\n public start() {\n this.engine = this.Engine.create();\n const world = this.World.create(this.options.world as Matter.IWorldDefinition);\n this.engine.world = world;\n if (this.options.isTest) {\n const ownCanvas = !this.options.canvas;\n const canvas = this.options.canvas ?? document.createElement('canvas');\n if (ownCanvas && this.options.element) {\n this.options.element.appendChild(canvas);\n }\n const resolution = this.options.resolution || 1;\n this.debugRenderer = new MatterPixiDebugRenderer({\n engine: this.engine,\n canvas,\n width: this.game.canvas.width / resolution,\n height: this.game.canvas.height / resolution,\n resolution,\n });\n void this.debugRenderer.init().catch(err => {\n console.error('[plugin-matterjs] MatterPixiDebugRenderer init failed', err);\n });\n this.Runner.run(this.runner, this.engine);\n }\n this.enabled = true;\n this.initMouse();\n this.initCollisionEvents();\n this.initBodyEvents();\n }\n\n public update(e) {\n if (!this.engine) {\n return;\n }\n if (!this.options.isTest) {\n this.Runner.tick(this.runner, this.engine, e.currentTime);\n }\n }\n\n public stop() {\n this.enabled = false;\n this.runner.enabled = false;\n }\n\n public destroy() {\n this.debugRenderer?.destroy();\n this.debugRenderer = null;\n if (this.engine) {\n Matter.Runner.stop(this.runner);\n Matter.Engine.clear(this.engine);\n }\n }\n\n public awake() {\n this.enabled = true;\n this.runner.enabled = true;\n }\n public add(component) {\n const body = this.createBodies(component);\n this.World.add(this.engine.world, [body]);\n component.body = body;\n component.Body = Matter.Body;\n component.PhysicsEngine = this.engine;\n component.Constraint = this.Constraint;\n component.mouseConstraint = this.mouseConstraint;\n component.World = this.World;\n body.component = component;\n }\n\n public change(component: Physics) {\n const newBody = this.createBodies(component);\n this.World.remove(this.engine.world, component.body, true);\n this.World.add(this.engine.world, [newBody]);\n component.body = newBody;\n }\n public remove(component: Physics) {\n this.World.remove(this.engine.world, component.body, true);\n component.body = undefined;\n }\n\n private createBodies(params): any {\n const body = this.bodiesFatoty.create(params) as PhysicsLinkedBody;\n return body;\n }\n\n private initCollisionEvents() {\n (this.collisionEvents as Array<'collisionStart' | 'collisionActive' | 'collisionEnd'>).forEach(eventName => {\n Matter.Events.on(this.engine, eventName, (event: Matter.IEventCollision<Matter.Engine>) => {\n const pairs = event.pairs ?? [];\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i];\n const { bodyA, bodyB } = pair;\n const componentA: Component = (bodyA as PhysicsLinkedBody).component;\n const componentB: Component = (bodyB as PhysicsLinkedBody).component;\n componentA.emit(eventName, componentB.gameObject, componentA.gameObject);\n componentB.emit(eventName, componentA.gameObject, componentB.gameObject);\n }\n });\n });\n }\n\n private initMouse() {\n if (this.options.mouse && this.options.mouse.open) {\n const mouse = Matter.Mouse.create(this.game.canvas);\n let options = this.options.mouse.constraint ? {\n mouse,\n constraint: this.options.mouse.constraint\n } : {\n mouse\n };\n this.mouseConstraint = Matter.MouseConstraint.create(this.engine, options);\n this.World.add(this.engine.world, this.mouseConstraint);\n }\n }\n\n private initBodyEvents() {\n this.bodyEvents.forEach(eventName => {\n Matter.Events.on(this.engine, eventName, e => {\n const bodies = e.source.world.bodies;\n bodies.forEach(body => {\n const linked = body as PhysicsLinkedBody;\n linked.component?.emit(eventName, body, linked.component.gameObject);\n });\n });\n });\n }\n}\n","import { System, decorators, OBSERVER_TYPE, Transform } from '@combos-fun/engine';\nimport type { ComponentChanged } from \"@combos-fun/engine\";\nimport PhysicsEngine from './PhysicsEngine';\nimport { Physics } from './Physics';\n\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends Object ? DeepPartial<T[P]> : T[P];\n}\n\nexport interface PhysicsSystemParams {\n resolution?: number\n fps?: number\n isTest?: boolean\n element?: HTMLElement\n canvas?: HTMLCanvasElement\n deltaSampleSize?: number\n mouse?: {\n open: boolean\n constraint?: Matter.Constraint\n }\n world: DeepPartial<Matter.IWorldDefinition>\n}\n\n@decorators.componentObserver({\n Physics: [{ prop: ['bodyParams'], deep: true }],\n Transform: ['_parent'],\n})\nexport default class PhysicsSystem extends System<PhysicsSystemParams> {\n static systemName = 'PhysicsSystem';\n private engine: PhysicsEngine;\n\n /**\n * System 初始化用,可以配置参数,游戏未开始\n *\n * System init, set params, game is not begain\n * @param param init params\n */\n init(param?: PhysicsSystemParams) {\n this.engine = new PhysicsEngine(this.game, param);\n this.game.canvas.setAttribute('data-pixel-ratio', (param.resolution || '1') as string);\n }\n /**\n * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。\n *\n * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data.\n */\n awake() { }\n\n /**\n * System 被安装后,所有的 awake 执行完后\n *\n * Called while the System installed, after all of systems' awake been called\n */\n start() {\n this.engine.start();\n }\n /**\n * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。\n *\n * Called by every loop, can do some operation, change some property or other component property.\n */\n update(e) {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n if (changed) {\n this.componentChanged(changed);\n }\n }\n this.engine.update(e);\n }\n\n componentChanged(changed: ComponentChanged) {\n if (changed.component instanceof Physics) {\n switch (changed.type) {\n case OBSERVER_TYPE.ADD: {\n if (changed.gameObject.transform.parent && !changed.gameObject.getComponent(Physics).body) {\n this.engine.add(changed.component);\n }\n break;\n }\n case OBSERVER_TYPE.CHANGE: {\n this.engine.change(changed.component);\n break;\n }\n case OBSERVER_TYPE.REMOVE: {\n break;\n }\n }\n } else {\n switch (changed.type) {\n case OBSERVER_TYPE.CHANGE: {\n if ((changed.component as Transform).parent) {\n let physics = changed.gameObject.getComponent(Physics);\n if (physics && !physics.body) {\n this.engine.add(physics);\n }\n } else {\n let physics = changed.gameObject.getComponent(Physics);\n physics && this.engine.remove(physics);\n }\n }\n }\n }\n }\n /**\n * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。\n *\n * Like update, called all of gameobject update.\n */\n lateUpdate() { }\n /**\n * 游戏开始和游戏暂停后开始播放的时候调用。\n *\n * Called while the game to play when game pause.\n */\n onResume() {\n if (!this.engine.enabled) {\n this.engine.awake();\n }\n }\n /**\n * 游戏暂停的时候调用。\n *\n * Called while the game paused.\n */\n onPause() {\n this.engine.stop();\n }\n /**\n * System 被销毁的时候调用。\n * Called while the system be destroyed.\n */\n onDestroy() {\n this.engine?.destroy();\n }\n}\n"],"names":["PhysicsType","Component","Matter","Application","Graphics","System","OBSERVER_TYPE","__decorate","decorators"],"mappings":";;;;;;;;;;;AAEYA;AAAZ,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;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AAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/C,SAAS,EAAE,CAAC,SAAS,CAAC;KACvB;AACoB,CAAA,EAAA,aAAa,CA4GjC;4BA5GoB,aAAa;;;;;"}
@@ -0,0 +1 @@
1
+ "use strict";var e=require("tslib"),t=require("@combos-fun/engine"),s=require("matter-js"),i=require("pixi.js");function n(e){return e&&e.__esModule?e:{default:e}}var o,r=n(s);exports.PhysicsType=void 0,(o=exports.PhysicsType||(exports.PhysicsType={})).RECTANGLE="rectangle",o.CIRCLE="circle",o.POLYGON="polygon";class a extends t.Component{static{this.componentName="Physics"}init(e){this.bodyParams=e}update(){this.body&&this.gameObject&&(this.gameObject.transform.anchor.x=0,this.gameObject.transform.anchor.y=0,this.gameObject.transform.position.x=this.body.position.x,this.gameObject.transform.position.y=this.body.position.y,this.bodyParams.stopRotation||(this.gameObject.transform.rotation=this.body.angle))}onDestroy(){r.default.World.remove(this.PhysicsEngine.world,this.body,!0)}}class h{constructor(){this.Bodies=r.default.Bodies}create(e){let t=null;const{gameObject:s,bodyParams:i}=e,n=this.getCoordinate(s),o=i.position?i.position.x:n.x,r=i.position?i.position.y:n.y,a=s.transform.size.width*s.transform.scale.x/2,h=s.transform.size.height*s.transform.scale.y/2,c=Math.max(1,Math.min(a,h));switch(i.type){case exports.PhysicsType.RECTANGLE:{const e=s.transform.size.width*s.transform.scale.x,n=s.transform.size.height*s.transform.scale.y;t=this.Bodies.rectangle(o,r,e,n,i.bodyOptions);break}case exports.PhysicsType.CIRCLE:{const e=i.radius??c;t=this.Bodies.circle(o,r,e,i.bodyOptions);break}case exports.PhysicsType.POLYGON:{const e=Math.max(3,i.sides??6),s=i.radius??c;t=this.Bodies.polygon(o,r,e,s,i.bodyOptions);break}}return t}getCoordinate(e){return{x:e.transform.position.x+e.transform.anchor.x*e.parent.transform.size.width,y:e.transform.position.y+e.transform.anchor.y*e.parent.transform.size.height}}}class c{constructor(e){this.app=null,this.graphics=null,this.opts=e,this.engine=e.engine,this.onAfterUpdate=()=>this.redraw()}async init(){const{canvas:e,width:t,height:s,resolution:n=1}=this.opts,o=new i.Application;await o.init({canvas:e,width:t,height:s,resolution:n,autoDensity:!0,antialias:!0,backgroundAlpha:.12,preference:"webgl"}),this.app=o,this.graphics=new i.Graphics,o.stage.addChild(this.graphics),r.default.Events.on(this.engine,"afterUpdate",this.onAfterUpdate)}redraw(){const e=this.graphics;if(!e)return;e.clear();const t=r.default.Composite.allBodies(this.engine.world);for(let s=0;s<t.length;s++){const i=t[s];if(!1===i.render?.visible)continue;const n=i.vertices;if(!n?.length)continue;const o=n[0];e.moveTo(o.x,o.y);for(let t=1;t<n.length;t++)e.lineTo(n[t].x,n[t].y);e.closePath(),e.stroke({width:1,color:58998,alpha:.9})}}destroy(){r.default.Events.off(this.engine,"afterUpdate",this.onAfterUpdate),this.app&&(this.app.destroy(!0,{children:!0,texture:!0}),this.app=null),this.graphics=null}}class d{constructor(e,t){this.debugRenderer=null,this.enabled=!1,this.Engine=r.default.Engine,this.World=r.default.World,this.bodiesFatoty=new h,this.Runner=r.default.Runner,this.Constraint=r.default.Constraint,this.game=e,this.collisionEvents=["collisionStart","collisionActive","collisionEnd"],this.bodyEvents=["tick","beforeUpdate","afterUpdate","beforeRender","afterRender","afterTick"],this.options=t,this.runner=this.Runner.create({delta:1e3/(this.options.fps||60),frameDeltaSmoothing:(this.options.deltaSampleSize??1)>1})}start(){this.engine=this.Engine.create();const e=this.World.create(this.options.world);if(this.engine.world=e,this.options.isTest){const e=!this.options.canvas,t=this.options.canvas??document.createElement("canvas");e&&this.options.element&&this.options.element.appendChild(t);const s=this.options.resolution||1;this.debugRenderer=new c({engine:this.engine,canvas:t,width:this.game.canvas.width/s,height:this.game.canvas.height/s,resolution:s}),this.debugRenderer.init().catch(e=>{console.error("[plugin-matterjs] MatterPixiDebugRenderer init failed",e)}),this.Runner.run(this.runner,this.engine)}this.enabled=!0,this.initMouse(),this.initCollisionEvents(),this.initBodyEvents()}update(e){this.engine&&(this.options.isTest||this.Runner.tick(this.runner,this.engine,e.currentTime))}stop(){this.enabled=!1,this.runner.enabled=!1}destroy(){this.debugRenderer?.destroy(),this.debugRenderer=null,this.engine&&(r.default.Runner.stop(this.runner),r.default.Engine.clear(this.engine))}awake(){this.enabled=!0,this.runner.enabled=!0}add(e){const t=this.createBodies(e);this.World.add(this.engine.world,[t]),e.body=t,e.Body=r.default.Body,e.PhysicsEngine=this.engine,e.Constraint=this.Constraint,e.mouseConstraint=this.mouseConstraint,e.World=this.World,t.component=e}change(e){const t=this.createBodies(e);this.World.remove(this.engine.world,e.body,!0),this.World.add(this.engine.world,[t]),e.body=t}remove(e){this.World.remove(this.engine.world,e.body,!0),e.body=void 0}createBodies(e){return this.bodiesFatoty.create(e)}initCollisionEvents(){this.collisionEvents.forEach(e=>{r.default.Events.on(this.engine,e,t=>{const s=t.pairs??[];for(let t=0;t<s.length;t++){const i=s[t],{bodyA:n,bodyB:o}=i,r=n.component,a=o.component;r.emit(e,a.gameObject,r.gameObject),a.emit(e,r.gameObject,a.gameObject)}})})}initMouse(){if(this.options.mouse&&this.options.mouse.open){const e=r.default.Mouse.create(this.game.canvas);let t=this.options.mouse.constraint?{mouse:e,constraint:this.options.mouse.constraint}:{mouse:e};this.mouseConstraint=r.default.MouseConstraint.create(this.engine,t),this.World.add(this.engine.world,this.mouseConstraint)}}initBodyEvents(){this.bodyEvents.forEach(e=>{r.default.Events.on(this.engine,e,t=>{t.source.world.bodies.forEach(t=>{const s=t;s.component?.emit(e,t,s.component.gameObject)})})})}}let l=class extends t.System{static{this.systemName="PhysicsSystem"}init(e){this.engine=new d(this.game,e),this.game.canvas.setAttribute("data-pixel-ratio",e.resolution||"1")}awake(){}start(){this.engine.start()}update(e){const t=this.componentObserver.clear();for(const e of t)e&&this.componentChanged(e);this.engine.update(e)}componentChanged(e){if(e.component instanceof a)switch(e.type){case t.OBSERVER_TYPE.ADD:e.gameObject.transform.parent&&!e.gameObject.getComponent(a).body&&this.engine.add(e.component);break;case t.OBSERVER_TYPE.CHANGE:this.engine.change(e.component);case t.OBSERVER_TYPE.REMOVE:}else if(e.type===t.OBSERVER_TYPE.CHANGE)if(e.component.parent){let t=e.gameObject.getComponent(a);t&&!t.body&&this.engine.add(t)}else{let t=e.gameObject.getComponent(a);t&&this.engine.remove(t)}}lateUpdate(){}onResume(){this.engine.enabled||this.engine.awake()}onPause(){this.engine.stop()}onDestroy(){this.engine?.destroy()}};l=e.__decorate([t.decorators.componentObserver({Physics:[{prop:["bodyParams"],deep:!0}],Transform:["_parent"]})],l);var p=l;exports.Physics=a,exports.PhysicsSystem=p;
@@ -0,0 +1,106 @@
1
+ import { System, ComponentChanged, Component } from '@combos-fun/engine';
2
+ import Matter$1 from 'matter-js';
3
+
4
+ type DeepPartial<T> = {
5
+ [P in keyof T]?: T[P] extends Object ? DeepPartial<T[P]> : T[P];
6
+ };
7
+ interface PhysicsSystemParams {
8
+ resolution?: number;
9
+ fps?: number;
10
+ isTest?: boolean;
11
+ element?: HTMLElement;
12
+ canvas?: HTMLCanvasElement;
13
+ deltaSampleSize?: number;
14
+ mouse?: {
15
+ open: boolean;
16
+ constraint?: Matter.Constraint;
17
+ };
18
+ world: DeepPartial<Matter.IWorldDefinition>;
19
+ }
20
+ declare class PhysicsSystem extends System<PhysicsSystemParams> {
21
+ static systemName: string;
22
+ private engine;
23
+ /**
24
+ * System 初始化用,可以配置参数,游戏未开始
25
+ *
26
+ * System init, set params, game is not begain
27
+ * @param param init params
28
+ */
29
+ init(param?: PhysicsSystemParams): void;
30
+ /**
31
+ * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。
32
+ *
33
+ * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data.
34
+ */
35
+ awake(): void;
36
+ /**
37
+ * System 被安装后,所有的 awake 执行完后
38
+ *
39
+ * Called while the System installed, after all of systems' awake been called
40
+ */
41
+ start(): void;
42
+ /**
43
+ * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。
44
+ *
45
+ * Called by every loop, can do some operation, change some property or other component property.
46
+ */
47
+ update(e: any): void;
48
+ componentChanged(changed: ComponentChanged): void;
49
+ /**
50
+ * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。
51
+ *
52
+ * Like update, called all of gameobject update.
53
+ */
54
+ lateUpdate(): void;
55
+ /**
56
+ * 游戏开始和游戏暂停后开始播放的时候调用。
57
+ *
58
+ * Called while the game to play when game pause.
59
+ */
60
+ onResume(): void;
61
+ /**
62
+ * 游戏暂停的时候调用。
63
+ *
64
+ * Called while the game paused.
65
+ */
66
+ onPause(): void;
67
+ /**
68
+ * System 被销毁的时候调用。
69
+ * Called while the system be destroyed.
70
+ */
71
+ onDestroy(): void;
72
+ }
73
+
74
+ declare enum PhysicsType {
75
+ RECTANGLE = "rectangle",
76
+ CIRCLE = "circle",
77
+ POLYGON = "polygon"
78
+ }
79
+ interface PhysicsParams {
80
+ type?: PhysicsType;
81
+ bodyOptions?: {
82
+ isStatic?: boolean;
83
+ restitution?: number;
84
+ density?: number;
85
+ [propName: string]: any;
86
+ };
87
+ position?: {
88
+ x?: number;
89
+ y?: number;
90
+ };
91
+ sides?: number;
92
+ radius?: number;
93
+ stopRotation?: boolean;
94
+ }
95
+ declare class Physics extends Component<PhysicsParams> {
96
+ static componentName: string;
97
+ bodyParams: PhysicsParams;
98
+ body: Matter$1.Body;
99
+ private PhysicsEngine;
100
+ init(params: PhysicsParams): void;
101
+ update(): void;
102
+ onDestroy(): void;
103
+ }
104
+
105
+ export { Physics, PhysicsSystem, PhysicsType };
106
+ export type { PhysicsSystemParams };
@@ -0,0 +1,392 @@
1
+ import { __decorate } from 'tslib';
2
+ import { Component, System, OBSERVER_TYPE, decorators } from '@combos-fun/engine';
3
+ import Matter from 'matter-js';
4
+ import { Application, Graphics } from 'pixi.js';
5
+
6
+ var PhysicsType;
7
+ (function (PhysicsType) {
8
+ PhysicsType["RECTANGLE"] = "rectangle";
9
+ PhysicsType["CIRCLE"] = "circle";
10
+ PhysicsType["POLYGON"] = "polygon";
11
+ })(PhysicsType || (PhysicsType = {}));
12
+ class Physics extends Component {
13
+ static { this.componentName = 'Physics'; }
14
+ init(params) {
15
+ this.bodyParams = params;
16
+ }
17
+ update() {
18
+ if (this.body && this.gameObject) {
19
+ this.gameObject.transform.anchor.x = 0;
20
+ this.gameObject.transform.anchor.y = 0;
21
+ this.gameObject.transform.position.x = this.body.position.x;
22
+ this.gameObject.transform.position.y = this.body.position.y;
23
+ if (!this.bodyParams.stopRotation) {
24
+ this.gameObject.transform.rotation = this.body.angle;
25
+ }
26
+ }
27
+ }
28
+ onDestroy() {
29
+ Matter.World.remove(this.PhysicsEngine.world, this.body, true);
30
+ }
31
+ }
32
+
33
+ class BodiesFactory {
34
+ constructor() {
35
+ this.Bodies = Matter.Bodies;
36
+ }
37
+ create(component) {
38
+ let body = null;
39
+ const { gameObject, bodyParams } = component;
40
+ const coordinate = this.getCoordinate(gameObject);
41
+ const x = bodyParams.position ? bodyParams.position.x : coordinate.x;
42
+ const y = bodyParams.position ? bodyParams.position.y : coordinate.y;
43
+ const halfW = (gameObject.transform.size.width * gameObject.transform.scale.x) / 2;
44
+ const halfH = (gameObject.transform.size.height * gameObject.transform.scale.y) / 2;
45
+ /** Matter.circle approximates with a polygon; NaN/0 radius breaks vertices. */
46
+ const defaultRadius = Math.max(1, Math.min(halfW, halfH));
47
+ switch (bodyParams.type) {
48
+ case PhysicsType.RECTANGLE: {
49
+ const width = gameObject.transform.size.width * gameObject.transform.scale.x;
50
+ const height = gameObject.transform.size.height * gameObject.transform.scale.y;
51
+ body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);
52
+ break;
53
+ }
54
+ case PhysicsType.CIRCLE: {
55
+ const radius = bodyParams.radius ?? defaultRadius;
56
+ body = this.Bodies.circle(x, y, radius, bodyParams.bodyOptions);
57
+ break;
58
+ }
59
+ case PhysicsType.POLYGON: {
60
+ const sides = Math.max(3, bodyParams.sides ?? 6);
61
+ const radius = bodyParams.radius ?? defaultRadius;
62
+ body = this.Bodies.polygon(x, y, sides, radius, bodyParams.bodyOptions);
63
+ break;
64
+ }
65
+ }
66
+ return body;
67
+ }
68
+ getCoordinate(gameObject) {
69
+ const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;
70
+ const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;
71
+ return {
72
+ x,
73
+ y,
74
+ };
75
+ }
76
+ }
77
+
78
+ /** WebGL wireframe overlay for Matter bodies in test mode. */
79
+ class MatterPixiDebugRenderer {
80
+ constructor(opts) {
81
+ this.app = null;
82
+ this.graphics = null;
83
+ this.opts = opts;
84
+ this.engine = opts.engine;
85
+ this.onAfterUpdate = () => this.redraw();
86
+ }
87
+ async init() {
88
+ const { canvas, width, height, resolution = 1 } = this.opts;
89
+ const app = new Application();
90
+ await app.init({
91
+ canvas,
92
+ width,
93
+ height,
94
+ resolution,
95
+ autoDensity: true,
96
+ antialias: true,
97
+ backgroundAlpha: 0.12,
98
+ preference: 'webgl',
99
+ });
100
+ this.app = app;
101
+ this.graphics = new Graphics();
102
+ app.stage.addChild(this.graphics);
103
+ Matter.Events.on(this.engine, 'afterUpdate', this.onAfterUpdate);
104
+ }
105
+ redraw() {
106
+ const g = this.graphics;
107
+ if (!g) {
108
+ return;
109
+ }
110
+ g.clear();
111
+ const bodies = Matter.Composite.allBodies(this.engine.world);
112
+ for (let b = 0; b < bodies.length; b++) {
113
+ const body = bodies[b];
114
+ if (body.render?.visible === false) {
115
+ continue;
116
+ }
117
+ const verts = body.vertices;
118
+ if (!verts?.length) {
119
+ continue;
120
+ }
121
+ const v0 = verts[0];
122
+ g.moveTo(v0.x, v0.y);
123
+ for (let i = 1; i < verts.length; i++) {
124
+ g.lineTo(verts[i].x, verts[i].y);
125
+ }
126
+ g.closePath();
127
+ g.stroke({ width: 1, color: 0x00e676, alpha: 0.9 });
128
+ }
129
+ }
130
+ destroy() {
131
+ Matter.Events.off(this.engine, 'afterUpdate', this.onAfterUpdate);
132
+ if (this.app) {
133
+ this.app.destroy(true, { children: true, texture: true });
134
+ this.app = null;
135
+ }
136
+ this.graphics = null;
137
+ }
138
+ }
139
+
140
+ class PhysicsEngine {
141
+ constructor(game, options) {
142
+ this.debugRenderer = null;
143
+ this.enabled = false;
144
+ this.Engine = Matter.Engine;
145
+ this.World = Matter.World;
146
+ this.bodiesFatoty = new BodiesFactory();
147
+ this.Runner = Matter.Runner;
148
+ this.Constraint = Matter.Constraint;
149
+ this.game = game;
150
+ this.collisionEvents = ['collisionStart', 'collisionActive', 'collisionEnd'];
151
+ this.bodyEvents = ['tick', 'beforeUpdate', 'afterUpdate', 'beforeRender', 'afterRender', 'afterTick'];
152
+ this.options = options;
153
+ this.runner = this.Runner.create({
154
+ delta: 1000 / (this.options.fps || 60),
155
+ frameDeltaSmoothing: (this.options.deltaSampleSize ?? 1) > 1,
156
+ });
157
+ }
158
+ start() {
159
+ this.engine = this.Engine.create();
160
+ const world = this.World.create(this.options.world);
161
+ this.engine.world = world;
162
+ if (this.options.isTest) {
163
+ const ownCanvas = !this.options.canvas;
164
+ const canvas = this.options.canvas ?? document.createElement('canvas');
165
+ if (ownCanvas && this.options.element) {
166
+ this.options.element.appendChild(canvas);
167
+ }
168
+ const resolution = this.options.resolution || 1;
169
+ this.debugRenderer = new MatterPixiDebugRenderer({
170
+ engine: this.engine,
171
+ canvas,
172
+ width: this.game.canvas.width / resolution,
173
+ height: this.game.canvas.height / resolution,
174
+ resolution,
175
+ });
176
+ void this.debugRenderer.init().catch(err => {
177
+ console.error('[plugin-matterjs] MatterPixiDebugRenderer init failed', err);
178
+ });
179
+ this.Runner.run(this.runner, this.engine);
180
+ }
181
+ this.enabled = true;
182
+ this.initMouse();
183
+ this.initCollisionEvents();
184
+ this.initBodyEvents();
185
+ }
186
+ update(e) {
187
+ if (!this.engine) {
188
+ return;
189
+ }
190
+ if (!this.options.isTest) {
191
+ this.Runner.tick(this.runner, this.engine, e.currentTime);
192
+ }
193
+ }
194
+ stop() {
195
+ this.enabled = false;
196
+ this.runner.enabled = false;
197
+ }
198
+ destroy() {
199
+ this.debugRenderer?.destroy();
200
+ this.debugRenderer = null;
201
+ if (this.engine) {
202
+ Matter.Runner.stop(this.runner);
203
+ Matter.Engine.clear(this.engine);
204
+ }
205
+ }
206
+ awake() {
207
+ this.enabled = true;
208
+ this.runner.enabled = true;
209
+ }
210
+ add(component) {
211
+ const body = this.createBodies(component);
212
+ this.World.add(this.engine.world, [body]);
213
+ component.body = body;
214
+ component.Body = Matter.Body;
215
+ component.PhysicsEngine = this.engine;
216
+ component.Constraint = this.Constraint;
217
+ component.mouseConstraint = this.mouseConstraint;
218
+ component.World = this.World;
219
+ body.component = component;
220
+ }
221
+ change(component) {
222
+ const newBody = this.createBodies(component);
223
+ this.World.remove(this.engine.world, component.body, true);
224
+ this.World.add(this.engine.world, [newBody]);
225
+ component.body = newBody;
226
+ }
227
+ remove(component) {
228
+ this.World.remove(this.engine.world, component.body, true);
229
+ component.body = undefined;
230
+ }
231
+ createBodies(params) {
232
+ const body = this.bodiesFatoty.create(params);
233
+ return body;
234
+ }
235
+ initCollisionEvents() {
236
+ this.collisionEvents.forEach(eventName => {
237
+ Matter.Events.on(this.engine, eventName, (event) => {
238
+ const pairs = event.pairs ?? [];
239
+ for (let i = 0; i < pairs.length; i++) {
240
+ const pair = pairs[i];
241
+ const { bodyA, bodyB } = pair;
242
+ const componentA = bodyA.component;
243
+ const componentB = bodyB.component;
244
+ componentA.emit(eventName, componentB.gameObject, componentA.gameObject);
245
+ componentB.emit(eventName, componentA.gameObject, componentB.gameObject);
246
+ }
247
+ });
248
+ });
249
+ }
250
+ initMouse() {
251
+ if (this.options.mouse && this.options.mouse.open) {
252
+ const mouse = Matter.Mouse.create(this.game.canvas);
253
+ let options = this.options.mouse.constraint ? {
254
+ mouse,
255
+ constraint: this.options.mouse.constraint
256
+ } : {
257
+ mouse
258
+ };
259
+ this.mouseConstraint = Matter.MouseConstraint.create(this.engine, options);
260
+ this.World.add(this.engine.world, this.mouseConstraint);
261
+ }
262
+ }
263
+ initBodyEvents() {
264
+ this.bodyEvents.forEach(eventName => {
265
+ Matter.Events.on(this.engine, eventName, e => {
266
+ const bodies = e.source.world.bodies;
267
+ bodies.forEach(body => {
268
+ const linked = body;
269
+ linked.component?.emit(eventName, body, linked.component.gameObject);
270
+ });
271
+ });
272
+ });
273
+ }
274
+ }
275
+
276
+ let PhysicsSystem = class PhysicsSystem extends System {
277
+ static { this.systemName = 'PhysicsSystem'; }
278
+ /**
279
+ * System 初始化用,可以配置参数,游戏未开始
280
+ *
281
+ * System init, set params, game is not begain
282
+ * @param param init params
283
+ */
284
+ init(param) {
285
+ this.engine = new PhysicsEngine(this.game, param);
286
+ this.game.canvas.setAttribute('data-pixel-ratio', (param.resolution || '1'));
287
+ }
288
+ /**
289
+ * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。
290
+ *
291
+ * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data.
292
+ */
293
+ awake() { }
294
+ /**
295
+ * System 被安装后,所有的 awake 执行完后
296
+ *
297
+ * Called while the System installed, after all of systems' awake been called
298
+ */
299
+ start() {
300
+ this.engine.start();
301
+ }
302
+ /**
303
+ * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。
304
+ *
305
+ * Called by every loop, can do some operation, change some property or other component property.
306
+ */
307
+ update(e) {
308
+ const changes = this.componentObserver.clear();
309
+ for (const changed of changes) {
310
+ if (changed) {
311
+ this.componentChanged(changed);
312
+ }
313
+ }
314
+ this.engine.update(e);
315
+ }
316
+ componentChanged(changed) {
317
+ if (changed.component instanceof Physics) {
318
+ switch (changed.type) {
319
+ case OBSERVER_TYPE.ADD: {
320
+ if (changed.gameObject.transform.parent && !changed.gameObject.getComponent(Physics).body) {
321
+ this.engine.add(changed.component);
322
+ }
323
+ break;
324
+ }
325
+ case OBSERVER_TYPE.CHANGE: {
326
+ this.engine.change(changed.component);
327
+ break;
328
+ }
329
+ case OBSERVER_TYPE.REMOVE: {
330
+ break;
331
+ }
332
+ }
333
+ }
334
+ else {
335
+ switch (changed.type) {
336
+ case OBSERVER_TYPE.CHANGE: {
337
+ if (changed.component.parent) {
338
+ let physics = changed.gameObject.getComponent(Physics);
339
+ if (physics && !physics.body) {
340
+ this.engine.add(physics);
341
+ }
342
+ }
343
+ else {
344
+ let physics = changed.gameObject.getComponent(Physics);
345
+ physics && this.engine.remove(physics);
346
+ }
347
+ }
348
+ }
349
+ }
350
+ }
351
+ /**
352
+ * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。
353
+ *
354
+ * Like update, called all of gameobject update.
355
+ */
356
+ lateUpdate() { }
357
+ /**
358
+ * 游戏开始和游戏暂停后开始播放的时候调用。
359
+ *
360
+ * Called while the game to play when game pause.
361
+ */
362
+ onResume() {
363
+ if (!this.engine.enabled) {
364
+ this.engine.awake();
365
+ }
366
+ }
367
+ /**
368
+ * 游戏暂停的时候调用。
369
+ *
370
+ * Called while the game paused.
371
+ */
372
+ onPause() {
373
+ this.engine.stop();
374
+ }
375
+ /**
376
+ * System 被销毁的时候调用。
377
+ * Called while the system be destroyed.
378
+ */
379
+ onDestroy() {
380
+ this.engine?.destroy();
381
+ }
382
+ };
383
+ PhysicsSystem = __decorate([
384
+ decorators.componentObserver({
385
+ Physics: [{ prop: ['bodyParams'], deep: true }],
386
+ Transform: ['_parent'],
387
+ })
388
+ ], PhysicsSystem);
389
+ var PhysicsSystem_default = PhysicsSystem;
390
+
391
+ export { Physics, PhysicsSystem_default as PhysicsSystem, PhysicsType };
392
+ //# sourceMappingURL=plugin-matterjs.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-matterjs.esm.js","sources":["../lib/Physics.ts","../lib/BodiesFactory.ts","../lib/MatterPixiDebugRenderer.ts","../lib/PhysicsEngine.ts","../lib/PhysicsSystem.ts"],"sourcesContent":["import { Component } from '@combos-fun/engine';\nimport Matter from 'matter-js';\nexport enum PhysicsType {\n RECTANGLE = 'rectangle',\n CIRCLE = 'circle',\n POLYGON = 'polygon',\n}\nexport interface PhysicsParams {\n type?: PhysicsType\n bodyOptions?: {\n isStatic?: boolean,\n restitution?: number,\n density?: number,\n [propName: string]: any,\n },\n position?: {\n x?: number\n y?: number\n }\n sides?: number\n radius?: number\n stopRotation?: boolean\n}\n\nexport class Physics extends Component<PhysicsParams> {\n static componentName: string = 'Physics';\n public bodyParams: PhysicsParams;\n public body: Matter.Body;\n private PhysicsEngine: Matter.Engine;\n\n init(params: PhysicsParams) {\n this.bodyParams = params;\n }\n\n update() {\n if (this.body && this.gameObject) {\n this.gameObject.transform.anchor.x = 0;\n this.gameObject.transform.anchor.y = 0;\n this.gameObject.transform.position.x = this.body.position.x;\n this.gameObject.transform.position.y = this.body.position.y;\n if (!this.bodyParams.stopRotation) {\n this.gameObject.transform.rotation = this.body.angle;\n }\n }\n }\n onDestroy() {\n Matter.World.remove(this.PhysicsEngine.world, this.body, true);\n }\n}\n","import Matter from 'matter-js';\nimport { PhysicsType, Physics } from './Physics';\nimport { GameObject } from '@combos-fun/engine';\ndeclare interface BodyOptions {\n chamfer?: number; // 斜切角\n angle?: number; // 旋转角\n isStatic?: boolean;\n density?: number; // 密度;\n restitution?: number; // 回弹系数\n velocity?: number; // 速率\n speed?: number; // 速度\n motion?: number; // 势能\n mass?: number;\n}\n\nexport interface RectangleParams {\n x: number;\n y: number;\n width: number;\n height: number;\n options: BodyOptions;\n}\n\nexport interface Verctor {\n x: number;\n y: number;\n}\nexport default class BodiesFactory {\n private Bodies: typeof Matter.Bodies;\n constructor() {\n this.Bodies = Matter.Bodies;\n }\n public create(component: Physics): Matter.Body {\n let body: Matter.Body = null;\n const { gameObject, bodyParams } = component;\n const coordinate = this.getCoordinate(gameObject);\n const x = bodyParams.position ? bodyParams.position.x : coordinate.x;\n const y = bodyParams.position ? bodyParams.position.y : coordinate.y;\n const halfW =\n (gameObject.transform.size.width * gameObject.transform.scale.x) / 2;\n const halfH =\n (gameObject.transform.size.height * gameObject.transform.scale.y) / 2;\n /** Matter.circle approximates with a polygon; NaN/0 radius breaks vertices. */\n const defaultRadius = Math.max(1, Math.min(halfW, halfH));\n switch (bodyParams.type) {\n case PhysicsType.RECTANGLE: {\n const width = gameObject.transform.size.width * gameObject.transform.scale.x;\n const height = gameObject.transform.size.height * gameObject.transform.scale.y;\n body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);\n break;\n }\n case PhysicsType.CIRCLE: {\n const radius = bodyParams.radius ?? defaultRadius;\n body = this.Bodies.circle(x, y, radius, bodyParams.bodyOptions);\n break;\n }\n case PhysicsType.POLYGON: {\n const sides = Math.max(3, bodyParams.sides ?? 6);\n const radius = bodyParams.radius ?? defaultRadius;\n body = this.Bodies.polygon(x, y, sides, radius, bodyParams.bodyOptions);\n break;\n }\n }\n return body;\n }\n\n private getCoordinate(gameObject: GameObject): Verctor {\n const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;\n const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;\n return {\n x,\n y,\n };\n }\n}\n","import Matter from 'matter-js';\nimport { Application, Graphics } from 'pixi.js';\n\nexport interface MatterPixiDebugOptions {\n engine: Matter.Engine;\n canvas: HTMLCanvasElement;\n width: number;\n height: number;\n resolution?: number;\n}\n\n/** WebGL wireframe overlay for Matter bodies in test mode. */\nexport class MatterPixiDebugRenderer {\n private readonly engine: Matter.Engine;\n private readonly opts: MatterPixiDebugOptions;\n private app: Application | null = null;\n private graphics: Graphics | null = null;\n private readonly onAfterUpdate: () => void;\n\n constructor(opts: MatterPixiDebugOptions) {\n this.opts = opts;\n this.engine = opts.engine;\n this.onAfterUpdate = () => this.redraw();\n }\n\n async init(): Promise<void> {\n const { canvas, width, height, resolution = 1 } = this.opts;\n const app = new Application();\n await app.init({\n canvas,\n width,\n height,\n resolution,\n autoDensity: true,\n antialias: true,\n backgroundAlpha: 0.12,\n preference: 'webgl',\n });\n this.app = app;\n this.graphics = new Graphics();\n app.stage.addChild(this.graphics);\n Matter.Events.on(this.engine, 'afterUpdate', this.onAfterUpdate);\n }\n\n private redraw(): void {\n const g = this.graphics;\n if (!g) {\n return;\n }\n g.clear();\n const bodies = Matter.Composite.allBodies(this.engine.world);\n for (let b = 0; b < bodies.length; b++) {\n const body = bodies[b];\n if (body.render?.visible === false) {\n continue;\n }\n const verts = body.vertices;\n if (!verts?.length) {\n continue;\n }\n const v0 = verts[0];\n g.moveTo(v0.x, v0.y);\n for (let i = 1; i < verts.length; i++) {\n g.lineTo(verts[i].x, verts[i].y);\n }\n g.closePath();\n g.stroke({ width: 1, color: 0x00e676, alpha: 0.9 });\n }\n }\n\n destroy(): void {\n Matter.Events.off(this.engine, 'afterUpdate', this.onAfterUpdate);\n if (this.app) {\n this.app.destroy(true, { children: true, texture: true });\n this.app = null;\n }\n this.graphics = null;\n }\n}\n","import Matter from 'matter-js';\n\nimport BodiesFactory from './BodiesFactory';\nimport { Component, Game } from '@combos-fun/engine';\nimport type { PhysicsSystemParams } from './PhysicsSystem';\nimport type { Physics } from './Physics';\nimport { MatterPixiDebugRenderer } from './MatterPixiDebugRenderer';\n\nexport interface PhysicsLinkedBody extends Matter.Body {\n component: Physics;\n}\n\nexport default class PhysicsEngine {\n private Engine: typeof Matter.Engine;\n private World: typeof Matter.World;\n private engine: Matter.Engine;\n private bodiesFatoty: BodiesFactory;\n private collisionEvents: string[];\n private bodyEvents: string[];\n private options: PhysicsSystemParams;\n private game: Game;\n private Runner: typeof Matter.Runner;\n private Constraint: typeof Matter.Constraint;\n private mouseConstraint: Matter.MouseConstraint;\n private runner: Matter.Runner;\n private debugRenderer: MatterPixiDebugRenderer | null = null;\n public enabled: boolean = false;\n constructor(game: Game, options: PhysicsSystemParams) {\n this.Engine = Matter.Engine;\n this.World = Matter.World;\n this.bodiesFatoty = new BodiesFactory();\n this.Runner = Matter.Runner;\n this.Constraint = Matter.Constraint;\n this.game = game;\n\n this.collisionEvents = ['collisionStart', 'collisionActive', 'collisionEnd'];\n this.bodyEvents = ['tick', 'beforeUpdate', 'afterUpdate', 'beforeRender', 'afterRender', 'afterTick'];\n this.options = options;\n this.runner = this.Runner.create({\n delta: 1000 / (this.options.fps || 60),\n frameDeltaSmoothing: (this.options.deltaSampleSize ?? 1) > 1,\n });\n }\n\n public start() {\n this.engine = this.Engine.create();\n const world = this.World.create(this.options.world as Matter.IWorldDefinition);\n this.engine.world = world;\n if (this.options.isTest) {\n const ownCanvas = !this.options.canvas;\n const canvas = this.options.canvas ?? document.createElement('canvas');\n if (ownCanvas && this.options.element) {\n this.options.element.appendChild(canvas);\n }\n const resolution = this.options.resolution || 1;\n this.debugRenderer = new MatterPixiDebugRenderer({\n engine: this.engine,\n canvas,\n width: this.game.canvas.width / resolution,\n height: this.game.canvas.height / resolution,\n resolution,\n });\n void this.debugRenderer.init().catch(err => {\n console.error('[plugin-matterjs] MatterPixiDebugRenderer init failed', err);\n });\n this.Runner.run(this.runner, this.engine);\n }\n this.enabled = true;\n this.initMouse();\n this.initCollisionEvents();\n this.initBodyEvents();\n }\n\n public update(e) {\n if (!this.engine) {\n return;\n }\n if (!this.options.isTest) {\n this.Runner.tick(this.runner, this.engine, e.currentTime);\n }\n }\n\n public stop() {\n this.enabled = false;\n this.runner.enabled = false;\n }\n\n public destroy() {\n this.debugRenderer?.destroy();\n this.debugRenderer = null;\n if (this.engine) {\n Matter.Runner.stop(this.runner);\n Matter.Engine.clear(this.engine);\n }\n }\n\n public awake() {\n this.enabled = true;\n this.runner.enabled = true;\n }\n public add(component) {\n const body = this.createBodies(component);\n this.World.add(this.engine.world, [body]);\n component.body = body;\n component.Body = Matter.Body;\n component.PhysicsEngine = this.engine;\n component.Constraint = this.Constraint;\n component.mouseConstraint = this.mouseConstraint;\n component.World = this.World;\n body.component = component;\n }\n\n public change(component: Physics) {\n const newBody = this.createBodies(component);\n this.World.remove(this.engine.world, component.body, true);\n this.World.add(this.engine.world, [newBody]);\n component.body = newBody;\n }\n public remove(component: Physics) {\n this.World.remove(this.engine.world, component.body, true);\n component.body = undefined;\n }\n\n private createBodies(params): any {\n const body = this.bodiesFatoty.create(params) as PhysicsLinkedBody;\n return body;\n }\n\n private initCollisionEvents() {\n (this.collisionEvents as Array<'collisionStart' | 'collisionActive' | 'collisionEnd'>).forEach(eventName => {\n Matter.Events.on(this.engine, eventName, (event: Matter.IEventCollision<Matter.Engine>) => {\n const pairs = event.pairs ?? [];\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i];\n const { bodyA, bodyB } = pair;\n const componentA: Component = (bodyA as PhysicsLinkedBody).component;\n const componentB: Component = (bodyB as PhysicsLinkedBody).component;\n componentA.emit(eventName, componentB.gameObject, componentA.gameObject);\n componentB.emit(eventName, componentA.gameObject, componentB.gameObject);\n }\n });\n });\n }\n\n private initMouse() {\n if (this.options.mouse && this.options.mouse.open) {\n const mouse = Matter.Mouse.create(this.game.canvas);\n let options = this.options.mouse.constraint ? {\n mouse,\n constraint: this.options.mouse.constraint\n } : {\n mouse\n };\n this.mouseConstraint = Matter.MouseConstraint.create(this.engine, options);\n this.World.add(this.engine.world, this.mouseConstraint);\n }\n }\n\n private initBodyEvents() {\n this.bodyEvents.forEach(eventName => {\n Matter.Events.on(this.engine, eventName, e => {\n const bodies = e.source.world.bodies;\n bodies.forEach(body => {\n const linked = body as PhysicsLinkedBody;\n linked.component?.emit(eventName, body, linked.component.gameObject);\n });\n });\n });\n }\n}\n","import { System, decorators, OBSERVER_TYPE, Transform } from '@combos-fun/engine';\nimport type { ComponentChanged } from \"@combos-fun/engine\";\nimport PhysicsEngine from './PhysicsEngine';\nimport { Physics } from './Physics';\n\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends Object ? DeepPartial<T[P]> : T[P];\n}\n\nexport interface PhysicsSystemParams {\n resolution?: number\n fps?: number\n isTest?: boolean\n element?: HTMLElement\n canvas?: HTMLCanvasElement\n deltaSampleSize?: number\n mouse?: {\n open: boolean\n constraint?: Matter.Constraint\n }\n world: DeepPartial<Matter.IWorldDefinition>\n}\n\n@decorators.componentObserver({\n Physics: [{ prop: ['bodyParams'], deep: true }],\n Transform: ['_parent'],\n})\nexport default class PhysicsSystem extends System<PhysicsSystemParams> {\n static systemName = 'PhysicsSystem';\n private engine: PhysicsEngine;\n\n /**\n * System 初始化用,可以配置参数,游戏未开始\n *\n * System init, set params, game is not begain\n * @param param init params\n */\n init(param?: PhysicsSystemParams) {\n this.engine = new PhysicsEngine(this.game, param);\n this.game.canvas.setAttribute('data-pixel-ratio', (param.resolution || '1') as string);\n }\n /**\n * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。\n *\n * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data.\n */\n awake() { }\n\n /**\n * System 被安装后,所有的 awake 执行完后\n *\n * Called while the System installed, after all of systems' awake been called\n */\n start() {\n this.engine.start();\n }\n /**\n * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。\n *\n * Called by every loop, can do some operation, change some property or other component property.\n */\n update(e) {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n if (changed) {\n this.componentChanged(changed);\n }\n }\n this.engine.update(e);\n }\n\n componentChanged(changed: ComponentChanged) {\n if (changed.component instanceof Physics) {\n switch (changed.type) {\n case OBSERVER_TYPE.ADD: {\n if (changed.gameObject.transform.parent && !changed.gameObject.getComponent(Physics).body) {\n this.engine.add(changed.component);\n }\n break;\n }\n case OBSERVER_TYPE.CHANGE: {\n this.engine.change(changed.component);\n break;\n }\n case OBSERVER_TYPE.REMOVE: {\n break;\n }\n }\n } else {\n switch (changed.type) {\n case OBSERVER_TYPE.CHANGE: {\n if ((changed.component as Transform).parent) {\n let physics = changed.gameObject.getComponent(Physics);\n if (physics && !physics.body) {\n this.engine.add(physics);\n }\n } else {\n let physics = changed.gameObject.getComponent(Physics);\n physics && this.engine.remove(physics);\n }\n }\n }\n }\n }\n /**\n * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。\n *\n * Like update, called all of gameobject update.\n */\n lateUpdate() { }\n /**\n * 游戏开始和游戏暂停后开始播放的时候调用。\n *\n * Called while the game to play when game pause.\n */\n onResume() {\n if (!this.engine.enabled) {\n this.engine.awake();\n }\n }\n /**\n * 游戏暂停的时候调用。\n *\n * Called while the game paused.\n */\n onPause() {\n this.engine.stop();\n }\n /**\n * System 被销毁的时候调用。\n * Called while the system be destroyed.\n */\n onDestroy() {\n this.engine?.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;IAEY;AAAZ,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,WAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACrB,CAAC,EAJW,WAAW,KAAX,WAAW,GAAA,EAAA,CAAA,CAAA;AAsBjB,MAAO,OAAQ,SAAQ,SAAwB,CAAA;aAC5C,IAAA,CAAA,aAAa,GAAW,SAAS,CAAC;AAKzC,IAAA,IAAI,CAAC,MAAqB,EAAA;AACxB,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM;IAC1B;IAEA,MAAM,GAAA;QACJ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YAChC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC;YACtC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC;AACtC,YAAA,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC3D,YAAA,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ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AM,CAAC,OAAO,CAAC;oBACxC;gBACF;;QAEJ;IACF;AACA;;;;AAIG;AACH,IAAA,UAAU,KAAK;AACf;;;;AAIG;IACH,QAAQ,GAAA;AACN,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;AACxB,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;QACrB;IACF;AACA;;;;AAIG;IACH,OAAO,GAAA;AACL,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;IACpB;AACA;;;AAGG;IACH,SAAS,GAAA;AACP,QAAA,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;IACxB;;AA3GmB,aAAa,GAAA,UAAA,CAAA;IAJjC,UAAU,CAAC,iBAAiB,CAAC;AAC5B,QAAA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/C,SAAS,EAAE,CAAC,SAAS,CAAC;KACvB;AACoB,CAAA,EAAA,aAAa,CA4GjC;4BA5GoB,aAAa;;;;"}
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./dist/plugin-matterjs.cjs.prod.js');
5
+ } else {
6
+ module.exports = require('./dist/plugin-matterjs.cjs.js');
7
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@combos-fun/plugin-matterjs",
3
+ "version": "0.0.1",
4
+ "description": "@combos-fun/plugin-matterjs",
5
+ "main": "index.js",
6
+ "module": "dist/plugin-matterjs.esm.js",
7
+ "bundle": "CombosFun.plugin.renderer.matterjs",
8
+ "unpkg": "dist/CombosFun.plugin.renderer.matterjs.min.js",
9
+ "files": [
10
+ "index.js",
11
+ "dist"
12
+ ],
13
+ "types": "dist/plugin-matterjs.d.ts",
14
+ "keywords": [
15
+ "combos-fun",
16
+ "game"
17
+ ],
18
+ "author": "sun668 <q947692259@gmail.com>",
19
+ "dependencies": {
20
+ "@types/matter-js": "^0.20.2",
21
+ "matter-js": "^0.20.0",
22
+ "pixi.js": "^8.18.1",
23
+ "poly-decomp": "^0.3.0",
24
+ "@combos-fun/engine": "0.0.1"
25
+ },
26
+ "scripts": {
27
+ "build": "node ../../scripts/build-package.mjs"
28
+ }
29
+ }