0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-03-14 00:38:41 -04:00
This commit is contained in:
maowtm 2024-07-17 18:10:21 +01:00 committed by GitHub
commit 0c30ee9fa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 0 deletions

BIN
src/body/.Body.js.swp Normal file

Binary file not shown.

BIN
src/body/.Composite.js.swp Normal file

Binary file not shown.

View file

@ -877,6 +877,26 @@ var Axes = require('../geometry/Axes');
*
*/
/**
* Fired before a body is going to be removed
*
* @event beforeRemoved
* @this {body} The body that is going to be removed
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired after a body was removed
*
* @event afterRemoved
* @this {body} The body that was removed
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired when a body starts sleeping (where `this` is the body).
*

View file

@ -175,6 +175,11 @@ var Body = require('./Body');
* @return {composite} The original compositeA with the objects from compositeB added
*/
Composite.addComposite = function(compositeA, compositeB) {
if (compositeA.composites.find(function (compos) {
return compos.id == compositeB.id;
})) {
return;
}
compositeA.composites.push(compositeB);
compositeB.parent = compositeA;
Composite.setModified(compositeA, true, true, false);
@ -235,6 +240,11 @@ var Body = require('./Body');
* @return {composite} The original composite with the body added
*/
Composite.addBody = function(composite, body) {
if (composite.bodies.find(function (bodyB) {
return bodyB.id == body.id;
})) {
return;
}
composite.bodies.push(body);
Composite.setModified(composite, true, true, false);
return composite;
@ -250,6 +260,7 @@ var Body = require('./Body');
* @return {composite} The original composite with the body removed
*/
Composite.removeBody = function(composite, body, deep) {
Events.trigger(body, 'beforeRemoved', {});
var position = Common.indexOf(composite.bodies, body);
if (position !== -1) {
@ -263,6 +274,7 @@ var Body = require('./Body');
}
}
Events.trigger(body, 'afterRemoved', {});
return composite;
};
@ -289,6 +301,11 @@ var Body = require('./Body');
* @return {composite} The original composite with the constraint added
*/
Composite.addConstraint = function(composite, constraint) {
if (composite.constraints.find(function (constraintB) {
return constraintB.id == constraint.id;
})) {
return;
}
composite.constraints.push(constraint);
Composite.setModified(composite, true, true, false);
return composite;