@eva/plugin-matterjs 2.0.0-beta.1 → 2.0.0-beta.3
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.
|
@@ -3,23 +3,6 @@ window.EVA.plugin = window.EVA.plugin || {};
|
|
|
3
3
|
window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
|
|
4
4
|
var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
5
5
|
'use strict';
|
|
6
|
-
var extendStatics = function (d, b) {
|
|
7
|
-
extendStatics = Object.setPrototypeOf || {
|
|
8
|
-
__proto__: []
|
|
9
|
-
} instanceof Array && function (d, b) {
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
} || function (d, b) {
|
|
12
|
-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
13
|
-
};
|
|
14
|
-
return extendStatics(d, b);
|
|
15
|
-
};
|
|
16
|
-
function __extends(d, b) {
|
|
17
|
-
extendStatics(d, b);
|
|
18
|
-
function __() {
|
|
19
|
-
this.constructor = d;
|
|
20
|
-
}
|
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
-
}
|
|
23
6
|
function __decorate(decorators, target, key, desc) {
|
|
24
7
|
var c = arguments.length,
|
|
25
8
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -27,22 +10,6 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
27
10
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
11
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
12
|
}
|
|
30
|
-
function __values(o) {
|
|
31
|
-
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
32
|
-
m = s && o[s],
|
|
33
|
-
i = 0;
|
|
34
|
-
if (m) return m.call(o);
|
|
35
|
-
if (o && typeof o.length === "number") return {
|
|
36
|
-
next: function () {
|
|
37
|
-
if (o && i >= o.length) o = void 0;
|
|
38
|
-
return {
|
|
39
|
-
value: o && o[i++],
|
|
40
|
-
done: !o
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
45
|
-
}
|
|
46
13
|
function __WEBPACK_EXTERNAL_MODULE__27__() {
|
|
47
14
|
try {
|
|
48
15
|
return require('poly-decomp');
|
|
@@ -5321,15 +5288,11 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5321
5288
|
PhysicsType["CIRCLE"] = "circle";
|
|
5322
5289
|
PhysicsType["POLYGON"] = "polygon";
|
|
5323
5290
|
})(exports.PhysicsType || (exports.PhysicsType = {}));
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
function Physics() {
|
|
5327
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
5328
|
-
}
|
|
5329
|
-
Physics.prototype.init = function (params) {
|
|
5291
|
+
class Physics extends eva_js.Component {
|
|
5292
|
+
init(params) {
|
|
5330
5293
|
this.bodyParams = params;
|
|
5331
|
-
}
|
|
5332
|
-
|
|
5294
|
+
}
|
|
5295
|
+
update() {
|
|
5333
5296
|
if (this.body && this.gameObject) {
|
|
5334
5297
|
this.gameObject.transform.anchor.x = 0;
|
|
5335
5298
|
this.gameObject.transform.anchor.y = 0;
|
|
@@ -5339,29 +5302,30 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5339
5302
|
this.gameObject.transform.rotation = this.body.angle;
|
|
5340
5303
|
}
|
|
5341
5304
|
}
|
|
5342
|
-
}
|
|
5343
|
-
|
|
5305
|
+
}
|
|
5306
|
+
onDestroy() {
|
|
5344
5307
|
Matter$1.World.remove(this.PhysicsEngine.world, this.body, true);
|
|
5345
|
-
}
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
function BodiesFactory() {
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
Physics.componentName = 'Physics';
|
|
5311
|
+
class BodiesFactory {
|
|
5312
|
+
constructor() {
|
|
5351
5313
|
this.Bodies = Matter$1.Bodies;
|
|
5352
5314
|
}
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5315
|
+
create(component) {
|
|
5316
|
+
let body = null;
|
|
5317
|
+
const {
|
|
5318
|
+
gameObject,
|
|
5319
|
+
bodyParams
|
|
5320
|
+
} = component;
|
|
5321
|
+
const coordinate = this.getCoordinate(gameObject);
|
|
5322
|
+
const x = bodyParams.position ? bodyParams.position.x : coordinate.x;
|
|
5323
|
+
const y = bodyParams.position ? bodyParams.position.y : coordinate.y;
|
|
5360
5324
|
switch (bodyParams.type) {
|
|
5361
5325
|
case exports.PhysicsType.RECTANGLE:
|
|
5362
5326
|
{
|
|
5363
|
-
|
|
5364
|
-
|
|
5327
|
+
const width = gameObject.transform.size.width * gameObject.transform.scale.x;
|
|
5328
|
+
const height = gameObject.transform.size.height * gameObject.transform.scale.y;
|
|
5365
5329
|
body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);
|
|
5366
5330
|
break;
|
|
5367
5331
|
}
|
|
@@ -5377,24 +5341,22 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5377
5341
|
}
|
|
5378
5342
|
}
|
|
5379
5343
|
return body;
|
|
5380
|
-
}
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5344
|
+
}
|
|
5345
|
+
getCoordinate(gameObject) {
|
|
5346
|
+
const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;
|
|
5347
|
+
const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;
|
|
5384
5348
|
return {
|
|
5385
|
-
x
|
|
5386
|
-
y
|
|
5349
|
+
x,
|
|
5350
|
+
y
|
|
5387
5351
|
};
|
|
5388
|
-
}
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
var PhysicsEngine = function () {
|
|
5393
|
-
function PhysicsEngine(game, options) {
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
class PhysicsEngine {
|
|
5355
|
+
constructor(game, options) {
|
|
5394
5356
|
this.enabled = false;
|
|
5395
5357
|
this.Engine = Matter$1.Engine;
|
|
5396
5358
|
this.World = Matter$1.World;
|
|
5397
|
-
this.bodiesFatoty = new BodiesFactory
|
|
5359
|
+
this.bodiesFatoty = new BodiesFactory();
|
|
5398
5360
|
this.Render = Matter$1.Render;
|
|
5399
5361
|
this.Runner = Matter$1.Runner;
|
|
5400
5362
|
this.Constraint = Matter$1.Constraint;
|
|
@@ -5407,13 +5369,13 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5407
5369
|
deltaSampleSize: this.options.deltaSampleSize || 1
|
|
5408
5370
|
});
|
|
5409
5371
|
}
|
|
5410
|
-
|
|
5372
|
+
start() {
|
|
5411
5373
|
var _a;
|
|
5412
5374
|
this.engine = this.Engine.create();
|
|
5413
|
-
|
|
5375
|
+
const world = this.World.create(this.options.world);
|
|
5414
5376
|
this.engine.world = world;
|
|
5415
5377
|
if (this.options.isTest) {
|
|
5416
|
-
|
|
5378
|
+
const render = this.Render.create({
|
|
5417
5379
|
element: this.options.element,
|
|
5418
5380
|
engine: this.engine,
|
|
5419
5381
|
canvas: (_a = this.options.canvas) !== null && _a !== void 0 ? _a : document.createElement('canvas'),
|
|
@@ -5431,22 +5393,22 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5431
5393
|
this.initMouse();
|
|
5432
5394
|
this.initCollisionEvents();
|
|
5433
5395
|
this.initBodyEvents();
|
|
5434
|
-
}
|
|
5435
|
-
|
|
5396
|
+
}
|
|
5397
|
+
update(e) {
|
|
5436
5398
|
if (!this.options.isTest) {
|
|
5437
5399
|
this.Runner.tick(this.runner, this.engine, e.currentTime);
|
|
5438
5400
|
}
|
|
5439
|
-
}
|
|
5440
|
-
|
|
5401
|
+
}
|
|
5402
|
+
stop() {
|
|
5441
5403
|
this.enabled = false;
|
|
5442
5404
|
this.runner.enabled = false;
|
|
5443
|
-
}
|
|
5444
|
-
|
|
5405
|
+
}
|
|
5406
|
+
awake() {
|
|
5445
5407
|
this.enabled = true;
|
|
5446
5408
|
this.runner.enabled = true;
|
|
5447
|
-
}
|
|
5448
|
-
|
|
5449
|
-
|
|
5409
|
+
}
|
|
5410
|
+
add(component) {
|
|
5411
|
+
const body = this.createBodies(component);
|
|
5450
5412
|
this.World.add(this.engine.world, [body]);
|
|
5451
5413
|
component.body = body;
|
|
5452
5414
|
component.Body = Matter$1.Body;
|
|
@@ -5455,102 +5417,82 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5455
5417
|
component.mouseConstraint = this.mouseConstraint;
|
|
5456
5418
|
component.World = this.World;
|
|
5457
5419
|
body.component = component;
|
|
5458
|
-
}
|
|
5459
|
-
|
|
5460
|
-
|
|
5420
|
+
}
|
|
5421
|
+
change(component) {
|
|
5422
|
+
const newBody = this.createBodies(component);
|
|
5461
5423
|
this.World.remove(this.engine.world, component.body, true);
|
|
5462
5424
|
this.World.add(this.engine.world, [newBody]);
|
|
5463
5425
|
component.body = newBody;
|
|
5464
|
-
}
|
|
5465
|
-
|
|
5426
|
+
}
|
|
5427
|
+
remove(component) {
|
|
5466
5428
|
this.World.remove(this.engine.world, component.body, true);
|
|
5467
5429
|
component.body = undefined;
|
|
5468
|
-
}
|
|
5469
|
-
|
|
5470
|
-
|
|
5430
|
+
}
|
|
5431
|
+
createBodies(params) {
|
|
5432
|
+
const body = this.bodiesFatoty.create(params);
|
|
5471
5433
|
return body;
|
|
5472
|
-
}
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
bodyB
|
|
5482
|
-
|
|
5483
|
-
|
|
5434
|
+
}
|
|
5435
|
+
initCollisionEvents() {
|
|
5436
|
+
this.collisionEvents.forEach(eventName => {
|
|
5437
|
+
Matter$1.Events.on(this.engine, eventName, event => {
|
|
5438
|
+
const pairs = event.pairs || [];
|
|
5439
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
5440
|
+
const pair = pairs[i];
|
|
5441
|
+
const {
|
|
5442
|
+
bodyA,
|
|
5443
|
+
bodyB
|
|
5444
|
+
} = pair;
|
|
5445
|
+
const componentA = bodyA.component;
|
|
5446
|
+
const componentB = bodyB.component;
|
|
5484
5447
|
componentA.emit(eventName, componentB.gameObject, componentA.gameObject);
|
|
5485
5448
|
componentB.emit(eventName, componentA.gameObject, componentB.gameObject);
|
|
5486
5449
|
}
|
|
5487
5450
|
});
|
|
5488
5451
|
});
|
|
5489
|
-
}
|
|
5490
|
-
|
|
5452
|
+
}
|
|
5453
|
+
initMouse() {
|
|
5491
5454
|
if (this.options.mouse && this.options.mouse.open) {
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
mouse
|
|
5455
|
+
const mouse = Matter$1.Mouse.create(this.game.canvas);
|
|
5456
|
+
let options = this.options.mouse.constraint ? {
|
|
5457
|
+
mouse,
|
|
5495
5458
|
constraint: this.options.mouse.constraint
|
|
5496
5459
|
} : {
|
|
5497
|
-
mouse
|
|
5460
|
+
mouse
|
|
5498
5461
|
};
|
|
5499
5462
|
this.mouseConstraint = Matter$1.MouseConstraint.create(this.engine, options);
|
|
5500
5463
|
this.World.add(this.engine.world, this.mouseConstraint);
|
|
5501
5464
|
}
|
|
5502
|
-
}
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
bodies.forEach(function (body) {
|
|
5465
|
+
}
|
|
5466
|
+
initBodyEvents() {
|
|
5467
|
+
this.bodyEvents.forEach(eventName => {
|
|
5468
|
+
Matter$1.Events.on(this.engine, eventName, e => {
|
|
5469
|
+
const bodies = e.source.world.bodies;
|
|
5470
|
+
bodies.forEach(body => {
|
|
5509
5471
|
body.component.emit(eventName, body, body.component.gameObject);
|
|
5510
5472
|
});
|
|
5511
5473
|
});
|
|
5512
5474
|
});
|
|
5513
|
-
};
|
|
5514
|
-
return PhysicsEngine;
|
|
5515
|
-
}();
|
|
5516
|
-
var PhysicsEngine$1 = PhysicsEngine;
|
|
5517
|
-
var PhysicsSystem = function (_super) {
|
|
5518
|
-
__extends(PhysicsSystem, _super);
|
|
5519
|
-
function PhysicsSystem() {
|
|
5520
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
5521
5475
|
}
|
|
5522
|
-
|
|
5523
|
-
|
|
5476
|
+
}
|
|
5477
|
+
let PhysicsSystem = class PhysicsSystem extends eva_js.System {
|
|
5478
|
+
init(param) {
|
|
5479
|
+
this.engine = new PhysicsEngine(this.game, param);
|
|
5524
5480
|
this.game.canvas.setAttribute('data-pixel-ratio', param.resolution || '1');
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
|
-
|
|
5481
|
+
}
|
|
5482
|
+
awake() {}
|
|
5483
|
+
start() {
|
|
5528
5484
|
this.engine.start();
|
|
5529
|
-
}
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
var changed = changes_1_1.value;
|
|
5536
|
-
if (changed) {
|
|
5537
|
-
this.componentChanged(changed);
|
|
5538
|
-
}
|
|
5539
|
-
}
|
|
5540
|
-
} catch (e_1_1) {
|
|
5541
|
-
e_1 = {
|
|
5542
|
-
error: e_1_1
|
|
5543
|
-
};
|
|
5544
|
-
} finally {
|
|
5545
|
-
try {
|
|
5546
|
-
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
5547
|
-
} finally {
|
|
5548
|
-
if (e_1) throw e_1.error;
|
|
5485
|
+
}
|
|
5486
|
+
update(e) {
|
|
5487
|
+
const changes = this.componentObserver.clear();
|
|
5488
|
+
for (const changed of changes) {
|
|
5489
|
+
if (changed) {
|
|
5490
|
+
this.componentChanged(changed);
|
|
5549
5491
|
}
|
|
5550
5492
|
}
|
|
5551
5493
|
this.engine.update(e);
|
|
5552
|
-
}
|
|
5553
|
-
|
|
5494
|
+
}
|
|
5495
|
+
componentChanged(changed) {
|
|
5554
5496
|
if (changed.component instanceof Physics) {
|
|
5555
5497
|
switch (changed.type) {
|
|
5556
5498
|
case eva_js.OBSERVER_TYPE.ADD:
|
|
@@ -5575,38 +5517,37 @@ var _EVA_IIFE_matterjs = function (exports, eva_js) {
|
|
|
5575
5517
|
case eva_js.OBSERVER_TYPE.CHANGE:
|
|
5576
5518
|
{
|
|
5577
5519
|
if (changed.component.parent) {
|
|
5578
|
-
|
|
5520
|
+
let physics = changed.gameObject.getComponent(Physics);
|
|
5579
5521
|
if (physics && !physics.body) {
|
|
5580
5522
|
this.engine.add(physics);
|
|
5581
5523
|
}
|
|
5582
5524
|
} else {
|
|
5583
|
-
|
|
5525
|
+
let physics = changed.gameObject.getComponent(Physics);
|
|
5584
5526
|
physics && this.engine.remove(physics);
|
|
5585
5527
|
}
|
|
5586
5528
|
}
|
|
5587
5529
|
}
|
|
5588
5530
|
}
|
|
5589
|
-
}
|
|
5590
|
-
|
|
5591
|
-
|
|
5531
|
+
}
|
|
5532
|
+
lateUpdate() {}
|
|
5533
|
+
onResume() {
|
|
5592
5534
|
if (!this.engine.enabled) {
|
|
5593
5535
|
this.engine.awake();
|
|
5594
5536
|
}
|
|
5595
|
-
}
|
|
5596
|
-
|
|
5537
|
+
}
|
|
5538
|
+
onPause() {
|
|
5597
5539
|
this.engine.stop();
|
|
5598
|
-
}
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
}(eva_js.System);
|
|
5540
|
+
}
|
|
5541
|
+
onDestroy() {}
|
|
5542
|
+
};
|
|
5543
|
+
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
5544
|
+
PhysicsSystem = __decorate([eva_js.decorators.componentObserver({
|
|
5545
|
+
Physics: [{
|
|
5546
|
+
prop: ['bodyParams'],
|
|
5547
|
+
deep: true
|
|
5548
|
+
}],
|
|
5549
|
+
Transform: ['_parent']
|
|
5550
|
+
})], PhysicsSystem);
|
|
5610
5551
|
var PhysicsSystem$1 = PhysicsSystem;
|
|
5611
5552
|
exports.Physics = Physics;
|
|
5612
5553
|
exports.PhysicsSystem = PhysicsSystem$1;
|