@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
- var Physics = function (_super) {
5325
- __extends(Physics, _super);
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
- Physics.prototype.update = function () {
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
- Physics.prototype.onDestroy = function () {
5305
+ }
5306
+ onDestroy() {
5344
5307
  Matter$1.World.remove(this.PhysicsEngine.world, this.body, true);
5345
- };
5346
- Physics.componentName = 'Physics';
5347
- return Physics;
5348
- }(eva_js.Component);
5349
- var BodiesFactory = function () {
5350
- function BodiesFactory() {
5308
+ }
5309
+ }
5310
+ Physics.componentName = 'Physics';
5311
+ class BodiesFactory {
5312
+ constructor() {
5351
5313
  this.Bodies = Matter$1.Bodies;
5352
5314
  }
5353
- BodiesFactory.prototype.create = function (component) {
5354
- var body = null;
5355
- var gameObject = component.gameObject,
5356
- bodyParams = component.bodyParams;
5357
- var coordinate = this.getCoordinate(gameObject);
5358
- var x = bodyParams.position ? bodyParams.position.x : coordinate.x;
5359
- var y = bodyParams.position ? bodyParams.position.y : coordinate.y;
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
- var width = gameObject.transform.size.width * gameObject.transform.scale.x;
5364
- var height = gameObject.transform.size.height * gameObject.transform.scale.y;
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
- BodiesFactory.prototype.getCoordinate = function (gameObject) {
5382
- var x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;
5383
- var y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;
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: x,
5386
- y: y
5349
+ x,
5350
+ y
5387
5351
  };
5388
- };
5389
- return BodiesFactory;
5390
- }();
5391
- var BodiesFactory$1 = BodiesFactory;
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$1();
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
- PhysicsEngine.prototype.start = function () {
5372
+ start() {
5411
5373
  var _a;
5412
5374
  this.engine = this.Engine.create();
5413
- var world = this.World.create(this.options.world);
5375
+ const world = this.World.create(this.options.world);
5414
5376
  this.engine.world = world;
5415
5377
  if (this.options.isTest) {
5416
- var render = this.Render.create({
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
- PhysicsEngine.prototype.update = function (e) {
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
- PhysicsEngine.prototype.stop = function () {
5401
+ }
5402
+ stop() {
5441
5403
  this.enabled = false;
5442
5404
  this.runner.enabled = false;
5443
- };
5444
- PhysicsEngine.prototype.awake = function () {
5405
+ }
5406
+ awake() {
5445
5407
  this.enabled = true;
5446
5408
  this.runner.enabled = true;
5447
- };
5448
- PhysicsEngine.prototype.add = function (component) {
5449
- var body = this.createBodies(component);
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
- PhysicsEngine.prototype.change = function (component) {
5460
- var newBody = this.createBodies(component);
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
- PhysicsEngine.prototype.remove = function (component) {
5426
+ }
5427
+ remove(component) {
5466
5428
  this.World.remove(this.engine.world, component.body, true);
5467
5429
  component.body = undefined;
5468
- };
5469
- PhysicsEngine.prototype.createBodies = function (params) {
5470
- var body = this.bodiesFatoty.create(params);
5430
+ }
5431
+ createBodies(params) {
5432
+ const body = this.bodiesFatoty.create(params);
5471
5433
  return body;
5472
- };
5473
- PhysicsEngine.prototype.initCollisionEvents = function () {
5474
- var _this = this;
5475
- this.collisionEvents.forEach(function (eventName) {
5476
- Matter$1.Events.on(_this.engine, eventName, function (event) {
5477
- var pairs = event.pairs || [];
5478
- for (var i = 0; i < pairs.length; i++) {
5479
- var pair = pairs[i];
5480
- var bodyA = pair.bodyA,
5481
- bodyB = pair.bodyB;
5482
- var componentA = bodyA.component;
5483
- var componentB = bodyB.component;
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
- PhysicsEngine.prototype.initMouse = function () {
5452
+ }
5453
+ initMouse() {
5491
5454
  if (this.options.mouse && this.options.mouse.open) {
5492
- var mouse = Matter$1.Mouse.create(this.game.canvas);
5493
- var options = this.options.mouse.constraint ? {
5494
- mouse: 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: 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
- PhysicsEngine.prototype.initBodyEvents = function () {
5504
- var _this = this;
5505
- this.bodyEvents.forEach(function (eventName) {
5506
- Matter$1.Events.on(_this.engine, eventName, function (e) {
5507
- var bodies = e.source.world.bodies;
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
- PhysicsSystem.prototype.init = function (param) {
5523
- this.engine = new PhysicsEngine$1(this.game, param);
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
- PhysicsSystem.prototype.awake = function () {};
5527
- PhysicsSystem.prototype.start = function () {
5481
+ }
5482
+ awake() {}
5483
+ start() {
5528
5484
  this.engine.start();
5529
- };
5530
- PhysicsSystem.prototype.update = function (e) {
5531
- var e_1, _a;
5532
- var changes = this.componentObserver.clear();
5533
- try {
5534
- for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
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
- PhysicsSystem.prototype.componentChanged = function (changed) {
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
- var physics = changed.gameObject.getComponent(Physics);
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
- var physics = changed.gameObject.getComponent(Physics);
5525
+ let physics = changed.gameObject.getComponent(Physics);
5584
5526
  physics && this.engine.remove(physics);
5585
5527
  }
5586
5528
  }
5587
5529
  }
5588
5530
  }
5589
- };
5590
- PhysicsSystem.prototype.lateUpdate = function () {};
5591
- PhysicsSystem.prototype.onResume = function () {
5531
+ }
5532
+ lateUpdate() {}
5533
+ onResume() {
5592
5534
  if (!this.engine.enabled) {
5593
5535
  this.engine.awake();
5594
5536
  }
5595
- };
5596
- PhysicsSystem.prototype.onPause = function () {
5537
+ }
5538
+ onPause() {
5597
5539
  this.engine.stop();
5598
- };
5599
- PhysicsSystem.prototype.onDestroy = function () {};
5600
- PhysicsSystem.systemName = 'PhysicsSystem';
5601
- PhysicsSystem = __decorate([eva_js.decorators.componentObserver({
5602
- Physics: [{
5603
- prop: ['bodyParams'],
5604
- deep: true
5605
- }],
5606
- Transform: ['_parent']
5607
- })], PhysicsSystem);
5608
- return PhysicsSystem;
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;