(options)
| 117 | }; |
| 118 | |
| 119 | const prepareMatter = (options) => { |
| 120 | const Matter = requireUncached(options.useDev ? '../build/matter.dev' : '../build/matter'); |
| 121 | |
| 122 | if (Matter.Common._nextId !== 0) { |
| 123 | throw 'Matter instance has already been used.'; |
| 124 | } |
| 125 | |
| 126 | Matter.Common.info = Matter.Common.warn = Matter.Common.log; |
| 127 | |
| 128 | if (options.stableSort) { |
| 129 | if (Matter.Collision) { |
| 130 | const MatterCollisionCollides = Matter.Collision.collides; |
| 131 | Matter.Collision.collides = function(bodyA, bodyB, pairs) { |
| 132 | const _bodyA = bodyA.id < bodyB.id ? bodyA : bodyB; |
| 133 | const _bodyB = bodyA.id < bodyB.id ? bodyB : bodyA; |
| 134 | return MatterCollisionCollides(_bodyA, _bodyB, pairs); |
| 135 | }; |
| 136 | } else { |
| 137 | const MatterSATCollides = Matter.SAT.collides; |
| 138 | Matter.SAT.collides = function(bodyA, bodyB, previousCollision, pairActive) { |
| 139 | const _bodyA = bodyA.id < bodyB.id ? bodyA : bodyB; |
| 140 | const _bodyB = bodyA.id < bodyB.id ? bodyB : bodyA; |
| 141 | return MatterSATCollides(_bodyA, _bodyB, previousCollision, pairActive); |
| 142 | }; |
| 143 | } |
| 144 | |
| 145 | Matter.after('Detector.collisions', function() { this.sort(collisionCompareId); }); |
| 146 | Matter.after('Composite.allBodies', function() { sortById(this); }); |
| 147 | Matter.after('Composite.allConstraints', function() { sortById(this); }); |
| 148 | Matter.after('Composite.allComposites', function() { sortById(this); }); |
| 149 | |
| 150 | Matter.before('Pairs.update', function(pairs) { |
| 151 | pairs.list.sort((pairA, pairB) => collisionCompareId(pairA.collision, pairB.collision)); |
| 152 | }); |
| 153 | |
| 154 | Matter.after('Pairs.update', function(pairs) { |
| 155 | pairs.list.sort((pairA, pairB) => collisionCompareId(pairA.collision, pairB.collision)); |
| 156 | }); |
| 157 | } |
| 158 | |
| 159 | if (options.jitter) { |
| 160 | Matter.after('Body.create', function() { |
| 161 | Matter.Body.applyForce(this, this.position, { |
| 162 | x: Math.cos(this.id * this.id) * options.jitter * this.mass, |
| 163 | y: Math.sin(this.id * this.id) * options.jitter * this.mass |
| 164 | }); |
| 165 | }); |
| 166 | } |
| 167 | |
| 168 | return Matter; |
| 169 | }; |
| 170 | |
| 171 | const prepareEnvironment = options => { |
| 172 | const logs = []; |
no test coverage detected
searching dependent graphs…