!function(){vara={},b={};!function(){vara=1;b.create=function(a){varb={id:o.nextId(),type:"body",label:"Body",angle:0,position:{x:0,y:0},force:{x:0,y:0},torque:0,positionImpulse:{x:0,y:0},constraintImpulse:{x:0,y:0,angle:0},speed:0,angularSpeed:0,velocity:{x:0,y:0},angularVelocity:0,isStatic:!1,isSleeping:!1,motion:0,sleepThreshold:60,density:.001,restitution:0,friction:.1,frictionAir:.01,groupId:0,slop:.05,timeScale:1,render:{visible:!0,sprite:{xScale:1,yScale:1},path:"L 0 0 L 40 0 L 40 40 L 0 40",lineWidth:1.5}},d=o.extend(b,a);returnc(d),d},b.nextGroupId=function(){returna++};varc=function(a){a.vertices=a.vertices||z.fromPath(a.render.path),a.axes=a.axes||w.fromVertices(a.vertices),a.area=z.area(a.vertices),a.bounds=x.create(a.vertices),a.mass=a.mass||a.density*a.area,a.inverseMass=1/a.mass,a.inertia=a.inertia||z.inertia(a.vertices,a.mass),a.inverseInertia=1/a.inertia,a.positionPrev=a.positionPrev||{x:a.position.x,y:a.position.y},a.anglePrev=a.anglePrev||a.angle,a.render.fillStyle=a.render.fillStyle||(a.isStatic?"#eeeeee":o.choose(["#556270","#4ECDC4","#C7F464","#FF6B6B","#C44D58"])),a.render.strokeStyle=a.render.strokeStyle||o.shadeColor(a.render.fillStyle,-20),z.create(a.vertices,a);varc=z.centre(a.vertices);z.translate(a.vertices,a.position),z.translate(a.vertices,c,-1),z.rotate(a.vertices,a.angle,a.position),w.rotate(a.axes,a.angle),x.update(a.bounds,a.vertices,a.velocity),b.setStatic(a,a.isStatic),t.set(a,a.isSleeping)};b.setStatic=function(a,b){a.isStatic=b,b&&(a.restitution=0,a.friction=1,a.mass=a.inertia=a.density=1/0,a.inverseMass=a.inverseInertia=0,a.render.lineWidth=1,a.positionPrev.x=a.position.x,a.positionPrev.y=a.position.y,a.anglePrev=a.angle,a.angularVelocity=0,a.speed=0,a.angularSpeed=0,a.motion=0)},b.resetForcesAll=function(a){for(varb=0;b<a.length;b++){varc=a[b];c.force.x=0,c.force.y=0,c.torque=0}},b.applyGravityAll=function(a,b){for(varc=0;c<a.length;c++){vard=a[c];d.isStatic||d.isSleeping||(d.force.y+=d.mass*b.y*.001,d.force.x+=d.mass*b.x*.001)}},b.updateAll=function(a,c,d,e){for(varf=0;f<a.length;f++){varg=a[f];g.isStatic||g.isSleeping||g.bounds.max.x<e.min.x||g.bounds.min.x>e.max.x||g.bounds.max.y<e.min.y||g.bounds.min.y>e.max.y||b.update(g,c,d)}},b.update=function(a,b,c){vard=b*b*a.timeScale,e=1-a.frictionAir,f=a.position.x-a.positionPrev.x,g=a.position.y-a.positionPrev.y;a.velocity.x=f*e*c+a.force.x/a.mass*d,a.velocity.y=g*e*c+a.force.y/a.mass*d,a.positionPrev.x=a.position.x,a.positionPrev.y=a.position.y,a.position.x+=a.velocity.x,a.position.y+=a.velocity.y,a.angularVelocity=(a.angle-a.anglePrev)*e*c+a.torque/a.inertia*d,a.anglePrev=a.angle,a.angle+=a.angularVelocity,a.speed=y.magnitude(a.velocity),a.angularSpeed=Math.abs(a.angularVelocity),z.translate(a.vertices,a.velocity),0!==a.angularVelocity&&(z.rotate(a.vertices,a.angularVelocity,a.position),w.rotate(a.axes,a.angularVelocity)),x.update(a.bounds,a.vertices,a.velocity)},b.applyForce=function(a,b,c){a.force.x+=c.x,a.force.y+=c.y;vard={x:b.x-a.position.x,y:b.y-a.position.y};a.torque+=(d.x*c.y-d.y*c.x)*a.inverseInertia},b.translate=function(a,b){a.positionPrev.x+=b.x,a.positionPrev.y+=b.y,a.position.x+=b.x,a.position.y+=b.y,z.translate(a.vertices,b),x.update(a.bounds,a.vertices,a.velocity)},b.rotate=function(a,b){a.anglePrev+=b,a.angle+=b,z.rotate(a.vertices,b,a.position),w.rotate(a.axes,b),x.update(a.bounds,a.vertices,a.velocity)},b.scale=function(a,b,c,d){z.scale(a.vertices,b,c,d),a.axes=w.fromVertices(a.vertices),a.area=z.area(a.vertices),a.mass=a.density*a.area,a.inverseMass=1/a.mass,z.translate(a.vertices,{x:-a.position.x,y:-a.position.y}),a.inertia=z.inertia(a.vertices,a.mass),a.inverseInertia=1/a.inertia,z.translate(a.vertices,{x:a.position.x,y:a.position.y}),x.update(a.bounds,a.vertices,a.velocity)}}();varc={};!function(){c.create=function(a){returno.extend({id:o.nextId(),type:"composite",parent:null,isModified:!1,bodies:[],constraints:[],composites:[],label:"Composite"},a)},c.setModified=function(a,b,d,e){if(a.isModified=b,d&&a.parent&&c.setModified(a.parent,b,d,e),e)for(varf=0;f<a.composites.length;f++){varg=a.co
b.translate(f,i),f.positionPrev.x=f.position.x,f.positionPrev.y=f.position.y;break;case"constraint":varj=f.pointA;f.bodyA&&(j=f.pointB),j.x=c-e.mousedownOffset.x,j.y=d-e.mousedownOffset.y;vark=f.bodyA?y.add(f.bodyA.position,f.pointA):f.pointA,l=f.bodyB?y.add(f.bodyB.position,f.pointB):f.pointB;f.length=y.magnitude(y.sub(k,l))}},t=function(a,c,d){for(vare,f,g=a.selected,h=0;h<g.length;h++)switch(e=g[h],f=e.data,f.type){case"body":b.scale(f,c,d,f.position),f.circleRadius&&(f.circleRadius*=c)}},u=function(a,c){for(vard,e,f=a.selected,g=0;g<f.length;g++)switch(d=f[g],e=d.data,e.type){case"body":b.rotate(e,c)}},v=function(a,b){b?(a.autoRewind&&(w(a,[]),C.loadState(a.serializer,a.engine,"pauseState")),a.engine.timing.timeScale=0,a.isPaused=!0,a.controls.pauseButton.text("Play"),q.trigger(a,"paused")):(a.autoRewind&&C.saveState(a.serializer,a.engine,"pauseState"),a.engine.timing.timeScale=1,a.isPaused=!1,a.controls.pauseButton.text("Pause"),q.trigger(a,"play"))},w=function(a,b){varc,d,e=a.controls.worldTree.data("jstree");for(d=0;d<a.selected.length;d++)c=a.selected[d].data,e.deselect_node(c.type+"_"+c.id,!0);for(a.selected=[],console.clear(),d=0;d<b.length;d++)c=b[d],c&&(A(a,c),5>d?console.log(c.label+" "+c.id+": %O",c):6===d&&console.warn("Omitted inspecting "+(b.length-5)+" more objects"))},A=function(a,b){if(b){varc=a.controls.worldTree.data("jstree");a.selected.push({data:b}),c.select_node(b.type+"_"+b.id,!0)}},B=function(a,b){b[0].state=b[0].state||{opened:!0},a.settings.core.data=b,a.refresh(-1)},E=function(a,b,c){vard=[],e={id:"composite_"+a.id,data:{compositeId:b},type:"composite",text:(a.label?a.label:"Composite")+" "+a.id,li_attr:{"class":"jstree-node-type-composite"}},f=F(a.composites,a.id);returnf.id="composites_"+a.id,d.push(f),c?f.children:(f=G(a.bodies,a.id),f.id="bodies_"+a.id,d.push(f),f=H(a.constraints,a.id),f.id="constraints_"+a.id,d.push(f),e.children=d,e)},F=function(a,b){for(varc={type:"composites",text:"Composites",data:{compositeId:b},children:[],li_attr:{"class":"jstree-node-type-composites"}},d=0;d<a.length;d++){vare=a[d];c.children.push(E(e,b))}returnc},G=function(a,b){for(varc={type:"bodies",text:"Bodies",data:{compositeId:b},children:[],li_attr:{"class":"jstree-node-type-bodies"}},d=0;d<a.length;d++){vare=a[d];c.children.push({type:"body",id:"body_"+e.id,data:{compositeId:b},text:(e.label?e.label:"Body")+" "+e.id,li_attr:{"class":"jstree-node-type-body"}})}returnc},H=function(a,b){for(varc={type:"constraints",text:"Constraints",data:{compositeId:b},children:[],li_attr:{"class":"jstree-node-type-constraints"}},d=0;d<a.length;d++){vare=a[d];c.children.push({type:"constraint",id:"constraint_"+e.id,data:{compositeId:b},text:(e.label?e.label:"Constraint")+" "+e.id,li_attr:{"class":"jstree-node-type-constraint"}})}returnc},I=function(a){varb=c.create();c.add(a.root,b),a.root.composites.splice(a.root.composites.length-1,1),a.root.composites.unshift(b),c.setModified(a.engine.world,!0,!0,!1)},J=function(a){a.engine;if(0===a.selected.length)returnvoidalert("No objects were selected, so export could not be created. Can only export objects that are in the World composite.");for(varb="export-objects",d=c.create({label:"Exported Objects"}),f=0;f<a.selected.length;f++){varg=a.selected[f].data;c.get(d,g.id,g.type)||(c.add(d,g),1===a.selected.length&&(b="export-"+g.label+"-"+g.id))}b=b.toLowerCase().replace(/[^\w\-]/g,"")+".json";varh=C.serialise(a.serializer,d,a.exportIndent);if(e){vari=newBlob([h],{type:"application/json"}),j=document.createElement("a");j.download=b,j.href=(window.webkitURL||window.URL).createObjectURL(i),j.dataset.downloadurl=["application/json",j.download,j.href].join(":"),j.click()}elsewindow.open("data:application/json;charset=utf-8,"+escape(h));q.trigger(a,"export")},K=function(a){varb,d=(a.engine,document.createElement("div"));d.innerHTML='<input type="file">',b=d.firstChild,b.addEventListener("change",function(){vard=b.files[0];if(d.name.match(/\.(txt|json)$/)){vare=newFileReader;e.onload=function(){varb=a.serializer.parse(e.result);if(b){b.label="ImportedO