@eva/plugin-matterjs 2.0.0-beta.1 → 2.0.0-beta.2
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.
|
@@ -18,37 +18,12 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
18
18
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
19
19
|
and limitations under the License.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise */
|
|
22
|
-
|
|
23
|
-
var extendStatics = function(d, b) {
|
|
24
|
-
extendStatics = Object.setPrototypeOf ||
|
|
25
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
27
|
-
return extendStatics(d, b);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function __extends(d, b) {
|
|
31
|
-
extendStatics(d, b);
|
|
32
|
-
function __() { this.constructor = d; }
|
|
33
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
-
}
|
|
35
21
|
|
|
36
22
|
function __decorate(decorators, target, key, desc) {
|
|
37
23
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
38
24
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
39
25
|
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;
|
|
40
26
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function __values(o) {
|
|
44
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
45
|
-
if (m) return m.call(o);
|
|
46
|
-
return {
|
|
47
|
-
next: function () {
|
|
48
|
-
if (o && i >= o.length) o = void 0;
|
|
49
|
-
return { value: o && o[i++], done: !o };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
27
|
}
|
|
53
28
|
|
|
54
29
|
/*!
|
|
@@ -10889,15 +10864,11 @@ exports.PhysicsType = void 0;
|
|
|
10889
10864
|
PhysicsType["CIRCLE"] = "circle";
|
|
10890
10865
|
PhysicsType["POLYGON"] = "polygon";
|
|
10891
10866
|
})(exports.PhysicsType || (exports.PhysicsType = {}));
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
function Physics() {
|
|
10895
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
10896
|
-
}
|
|
10897
|
-
Physics.prototype.init = function (params) {
|
|
10867
|
+
class Physics extends eva_js.Component {
|
|
10868
|
+
init(params) {
|
|
10898
10869
|
this.bodyParams = params;
|
|
10899
|
-
}
|
|
10900
|
-
|
|
10870
|
+
}
|
|
10871
|
+
update() {
|
|
10901
10872
|
if (this.body && this.gameObject) {
|
|
10902
10873
|
this.gameObject.transform.anchor.x = 0;
|
|
10903
10874
|
this.gameObject.transform.anchor.y = 0;
|
|
@@ -10907,28 +10878,27 @@ var Physics = (function (_super) {
|
|
|
10907
10878
|
this.gameObject.transform.rotation = this.body.angle;
|
|
10908
10879
|
}
|
|
10909
10880
|
}
|
|
10910
|
-
}
|
|
10911
|
-
|
|
10881
|
+
}
|
|
10882
|
+
onDestroy() {
|
|
10912
10883
|
Matter$1.World.remove(this.PhysicsEngine.world, this.body, true);
|
|
10913
|
-
}
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
}(eva_js.Component));
|
|
10884
|
+
}
|
|
10885
|
+
}
|
|
10886
|
+
Physics.componentName = 'Physics';
|
|
10917
10887
|
|
|
10918
|
-
|
|
10919
|
-
|
|
10888
|
+
class BodiesFactory {
|
|
10889
|
+
constructor() {
|
|
10920
10890
|
this.Bodies = Matter$1.Bodies;
|
|
10921
10891
|
}
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10892
|
+
create(component) {
|
|
10893
|
+
let body = null;
|
|
10894
|
+
const { gameObject, bodyParams } = component;
|
|
10895
|
+
const coordinate = this.getCoordinate(gameObject);
|
|
10896
|
+
const x = bodyParams.position ? bodyParams.position.x : coordinate.x;
|
|
10897
|
+
const y = bodyParams.position ? bodyParams.position.y : coordinate.y;
|
|
10928
10898
|
switch (bodyParams.type) {
|
|
10929
10899
|
case exports.PhysicsType.RECTANGLE: {
|
|
10930
|
-
|
|
10931
|
-
|
|
10900
|
+
const width = gameObject.transform.size.width * gameObject.transform.scale.x;
|
|
10901
|
+
const height = gameObject.transform.size.height * gameObject.transform.scale.y;
|
|
10932
10902
|
body = this.Bodies.rectangle(x, y, width, height, bodyParams.bodyOptions);
|
|
10933
10903
|
break;
|
|
10934
10904
|
}
|
|
@@ -10942,25 +10912,23 @@ var BodiesFactory = (function () {
|
|
|
10942
10912
|
}
|
|
10943
10913
|
}
|
|
10944
10914
|
return body;
|
|
10945
|
-
}
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10915
|
+
}
|
|
10916
|
+
getCoordinate(gameObject) {
|
|
10917
|
+
const x = gameObject.transform.position.x + gameObject.transform.anchor.x * gameObject.parent.transform.size.width;
|
|
10918
|
+
const y = gameObject.transform.position.y + gameObject.transform.anchor.y * gameObject.parent.transform.size.height;
|
|
10949
10919
|
return {
|
|
10950
|
-
x
|
|
10951
|
-
y
|
|
10920
|
+
x,
|
|
10921
|
+
y,
|
|
10952
10922
|
};
|
|
10953
|
-
}
|
|
10954
|
-
|
|
10955
|
-
}());
|
|
10956
|
-
var BodiesFactory$1 = BodiesFactory;
|
|
10923
|
+
}
|
|
10924
|
+
}
|
|
10957
10925
|
|
|
10958
|
-
|
|
10959
|
-
|
|
10926
|
+
class PhysicsEngine {
|
|
10927
|
+
constructor(game, options) {
|
|
10960
10928
|
this.enabled = false;
|
|
10961
10929
|
this.Engine = Matter$1.Engine;
|
|
10962
10930
|
this.World = Matter$1.World;
|
|
10963
|
-
this.bodiesFatoty = new BodiesFactory
|
|
10931
|
+
this.bodiesFatoty = new BodiesFactory();
|
|
10964
10932
|
this.Render = Matter$1.Render;
|
|
10965
10933
|
this.Runner = Matter$1.Runner;
|
|
10966
10934
|
this.Constraint = Matter$1.Constraint;
|
|
@@ -10973,13 +10941,13 @@ var PhysicsEngine = (function () {
|
|
|
10973
10941
|
deltaSampleSize: this.options.deltaSampleSize || 1,
|
|
10974
10942
|
});
|
|
10975
10943
|
}
|
|
10976
|
-
|
|
10944
|
+
start() {
|
|
10977
10945
|
var _a;
|
|
10978
10946
|
this.engine = this.Engine.create();
|
|
10979
|
-
|
|
10947
|
+
const world = this.World.create(this.options.world);
|
|
10980
10948
|
this.engine.world = world;
|
|
10981
10949
|
if (this.options.isTest) {
|
|
10982
|
-
|
|
10950
|
+
const render = this.Render.create({
|
|
10983
10951
|
element: this.options.element,
|
|
10984
10952
|
engine: this.engine,
|
|
10985
10953
|
canvas: (_a = this.options.canvas) !== null && _a !== void 0 ? _a : document.createElement('canvas'),
|
|
@@ -10997,22 +10965,22 @@ var PhysicsEngine = (function () {
|
|
|
10997
10965
|
this.initMouse();
|
|
10998
10966
|
this.initCollisionEvents();
|
|
10999
10967
|
this.initBodyEvents();
|
|
11000
|
-
}
|
|
11001
|
-
|
|
10968
|
+
}
|
|
10969
|
+
update(e) {
|
|
11002
10970
|
if (!this.options.isTest) {
|
|
11003
10971
|
this.Runner.tick(this.runner, this.engine, e.currentTime);
|
|
11004
10972
|
}
|
|
11005
|
-
}
|
|
11006
|
-
|
|
10973
|
+
}
|
|
10974
|
+
stop() {
|
|
11007
10975
|
this.enabled = false;
|
|
11008
10976
|
this.runner.enabled = false;
|
|
11009
|
-
}
|
|
11010
|
-
|
|
10977
|
+
}
|
|
10978
|
+
awake() {
|
|
11011
10979
|
this.enabled = true;
|
|
11012
10980
|
this.runner.enabled = true;
|
|
11013
|
-
}
|
|
11014
|
-
|
|
11015
|
-
|
|
10981
|
+
}
|
|
10982
|
+
add(component) {
|
|
10983
|
+
const body = this.createBodies(component);
|
|
11016
10984
|
this.World.add(this.engine.world, [body]);
|
|
11017
10985
|
component.body = body;
|
|
11018
10986
|
component.Body = Matter$1.Body;
|
|
@@ -11021,101 +10989,82 @@ var PhysicsEngine = (function () {
|
|
|
11021
10989
|
component.mouseConstraint = this.mouseConstraint;
|
|
11022
10990
|
component.World = this.World;
|
|
11023
10991
|
body.component = component;
|
|
11024
|
-
}
|
|
11025
|
-
|
|
11026
|
-
|
|
10992
|
+
}
|
|
10993
|
+
change(component) {
|
|
10994
|
+
const newBody = this.createBodies(component);
|
|
11027
10995
|
this.World.remove(this.engine.world, component.body, true);
|
|
11028
10996
|
this.World.add(this.engine.world, [newBody]);
|
|
11029
10997
|
component.body = newBody;
|
|
11030
|
-
}
|
|
11031
|
-
|
|
10998
|
+
}
|
|
10999
|
+
remove(component) {
|
|
11032
11000
|
this.World.remove(this.engine.world, component.body, true);
|
|
11033
11001
|
component.body = undefined;
|
|
11034
|
-
}
|
|
11035
|
-
|
|
11036
|
-
|
|
11002
|
+
}
|
|
11003
|
+
createBodies(params) {
|
|
11004
|
+
const body = this.bodiesFatoty.create(params);
|
|
11037
11005
|
return body;
|
|
11038
|
-
}
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
var componentB = bodyB.component;
|
|
11006
|
+
}
|
|
11007
|
+
initCollisionEvents() {
|
|
11008
|
+
this.collisionEvents.forEach(eventName => {
|
|
11009
|
+
Matter$1.Events.on(this.engine, eventName, event => {
|
|
11010
|
+
const pairs = event.pairs || [];
|
|
11011
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
11012
|
+
const pair = pairs[i];
|
|
11013
|
+
const { bodyA, bodyB } = pair;
|
|
11014
|
+
const componentA = bodyA.component;
|
|
11015
|
+
const componentB = bodyB.component;
|
|
11049
11016
|
componentA.emit(eventName, componentB.gameObject, componentA.gameObject);
|
|
11050
11017
|
componentB.emit(eventName, componentA.gameObject, componentB.gameObject);
|
|
11051
11018
|
}
|
|
11052
11019
|
});
|
|
11053
11020
|
});
|
|
11054
|
-
}
|
|
11055
|
-
|
|
11021
|
+
}
|
|
11022
|
+
initMouse() {
|
|
11056
11023
|
if (this.options.mouse && this.options.mouse.open) {
|
|
11057
|
-
|
|
11058
|
-
|
|
11024
|
+
const mouse = Matter$1.Mouse.create(this.game.canvas);
|
|
11025
|
+
let options = this.options.mouse.constraint
|
|
11059
11026
|
? {
|
|
11060
|
-
mouse
|
|
11027
|
+
mouse,
|
|
11061
11028
|
constraint: this.options.mouse.constraint,
|
|
11062
11029
|
}
|
|
11063
11030
|
: {
|
|
11064
|
-
mouse
|
|
11031
|
+
mouse,
|
|
11065
11032
|
};
|
|
11066
11033
|
this.mouseConstraint = Matter$1.MouseConstraint.create(this.engine, options);
|
|
11067
11034
|
this.World.add(this.engine.world, this.mouseConstraint);
|
|
11068
11035
|
}
|
|
11069
|
-
}
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
bodies.forEach(function (body) {
|
|
11036
|
+
}
|
|
11037
|
+
initBodyEvents() {
|
|
11038
|
+
this.bodyEvents.forEach(eventName => {
|
|
11039
|
+
Matter$1.Events.on(this.engine, eventName, e => {
|
|
11040
|
+
const bodies = e.source.world.bodies;
|
|
11041
|
+
bodies.forEach(body => {
|
|
11076
11042
|
body.component.emit(eventName, body, body.component.gameObject);
|
|
11077
11043
|
});
|
|
11078
11044
|
});
|
|
11079
11045
|
});
|
|
11080
|
-
};
|
|
11081
|
-
return PhysicsEngine;
|
|
11082
|
-
}());
|
|
11083
|
-
var PhysicsEngine$1 = PhysicsEngine;
|
|
11084
|
-
|
|
11085
|
-
var PhysicsSystem = (function (_super) {
|
|
11086
|
-
__extends(PhysicsSystem, _super);
|
|
11087
|
-
function PhysicsSystem() {
|
|
11088
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
11089
11046
|
}
|
|
11090
|
-
|
|
11091
|
-
|
|
11047
|
+
}
|
|
11048
|
+
|
|
11049
|
+
let PhysicsSystem = class PhysicsSystem extends eva_js.System {
|
|
11050
|
+
init(param) {
|
|
11051
|
+
this.engine = new PhysicsEngine(this.game, param);
|
|
11092
11052
|
this.game.canvas.setAttribute('data-pixel-ratio', (param.resolution || '1'));
|
|
11093
|
-
}
|
|
11094
|
-
|
|
11095
|
-
|
|
11053
|
+
}
|
|
11054
|
+
awake() { }
|
|
11055
|
+
start() {
|
|
11096
11056
|
this.engine.start();
|
|
11097
|
-
}
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
var changed = changes_1_1.value;
|
|
11104
|
-
if (changed) {
|
|
11105
|
-
this.componentChanged(changed);
|
|
11106
|
-
}
|
|
11107
|
-
}
|
|
11108
|
-
}
|
|
11109
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
11110
|
-
finally {
|
|
11111
|
-
try {
|
|
11112
|
-
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
11057
|
+
}
|
|
11058
|
+
update(e) {
|
|
11059
|
+
const changes = this.componentObserver.clear();
|
|
11060
|
+
for (const changed of changes) {
|
|
11061
|
+
if (changed) {
|
|
11062
|
+
this.componentChanged(changed);
|
|
11113
11063
|
}
|
|
11114
|
-
finally { if (e_1) throw e_1.error; }
|
|
11115
11064
|
}
|
|
11116
11065
|
this.engine.update(e);
|
|
11117
|
-
}
|
|
11118
|
-
|
|
11066
|
+
}
|
|
11067
|
+
componentChanged(changed) {
|
|
11119
11068
|
if (changed.component instanceof Physics) {
|
|
11120
11069
|
switch (changed.type) {
|
|
11121
11070
|
case eva_js.OBSERVER_TYPE.ADD: {
|
|
@@ -11137,38 +11086,37 @@ var PhysicsSystem = (function (_super) {
|
|
|
11137
11086
|
switch (changed.type) {
|
|
11138
11087
|
case eva_js.OBSERVER_TYPE.CHANGE: {
|
|
11139
11088
|
if (changed.component.parent) {
|
|
11140
|
-
|
|
11089
|
+
let physics = changed.gameObject.getComponent(Physics);
|
|
11141
11090
|
if (physics && !physics.body) {
|
|
11142
11091
|
this.engine.add(physics);
|
|
11143
11092
|
}
|
|
11144
11093
|
}
|
|
11145
11094
|
else {
|
|
11146
|
-
|
|
11095
|
+
let physics = changed.gameObject.getComponent(Physics);
|
|
11147
11096
|
physics && this.engine.remove(physics);
|
|
11148
11097
|
}
|
|
11149
11098
|
}
|
|
11150
11099
|
}
|
|
11151
11100
|
}
|
|
11152
|
-
}
|
|
11153
|
-
|
|
11154
|
-
|
|
11101
|
+
}
|
|
11102
|
+
lateUpdate() { }
|
|
11103
|
+
onResume() {
|
|
11155
11104
|
if (!this.engine.enabled) {
|
|
11156
11105
|
this.engine.awake();
|
|
11157
11106
|
}
|
|
11158
|
-
}
|
|
11159
|
-
|
|
11107
|
+
}
|
|
11108
|
+
onPause() {
|
|
11160
11109
|
this.engine.stop();
|
|
11161
|
-
}
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
}(eva_js.System));
|
|
11110
|
+
}
|
|
11111
|
+
onDestroy() { }
|
|
11112
|
+
};
|
|
11113
|
+
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
11114
|
+
PhysicsSystem = __decorate([
|
|
11115
|
+
eva_js.decorators.componentObserver({
|
|
11116
|
+
Physics: [{ prop: ['bodyParams'], deep: true }],
|
|
11117
|
+
Transform: ['_parent'],
|
|
11118
|
+
})
|
|
11119
|
+
], PhysicsSystem);
|
|
11172
11120
|
var PhysicsSystem$1 = PhysicsSystem;
|
|
11173
11121
|
|
|
11174
11122
|
exports.Physics = Physics;
|