This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/static/lib/crafty-min.js

14 lines
148 KiB
JavaScript
Raw Normal View History

2018-09-30 18:21:59 +00:00
/**
* craftyjs 0.9.0
* http://craftyjs.com/
*
* Copyright 2018, Louis Stowasser
* Licensed under the MIT license.
*/
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(){throw new Error("setTimeout has not been defined")}function e(){throw new Error("clearTimeout has not been defined")}function f(a){if(l===setTimeout)return setTimeout(a,0);if((l===d||!l)&&setTimeout)return l=setTimeout,setTimeout(a,0);try{return l(a,0)}catch(b){try{return l.call(null,a,0)}catch(b){return l.call(this,a,0)}}}function g(a){if(m===clearTimeout)return clearTimeout(a);if((m===e||!m)&&clearTimeout)return m=clearTimeout,clearTimeout(a);try{return m(a)}catch(b){try{return m.call(null,a)}catch(b){return m.call(this,a)}}}function h(){q&&o&&(q=!1,o.length?p=o.concat(p):r=-1,p.length&&i())}function i(){if(!q){var a=f(h);q=!0;for(var b=p.length;b;){for(o=p,p=[];++r<b;)o&&o[r].run();r=-1,b=p.length}o=null,q=!1,g(a)}}function j(a,b){this.fun=a,this.array=b}function k(){}var l,m,n=b.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:d}catch(a){l=d}try{m="function"==typeof clearTimeout?clearTimeout:e}catch(a){m=e}}();var o,p=[],q=!1,r=-1;n.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];p.push(new j(a,b)),1!==p.length||q||f(i)},j.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=k,n.addListener=k,n.once=k,n.off=k,n.removeListener=k,n.removeAllListeners=k,n.emit=k,n.binding=function(a){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(a){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},{}],2:[function(a,b,c){function d(a,b,c,d){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,get:function(){return c[d]},set:function(a){c[d]=a}})}b.exports={defineAliases:function(a){d(a,"image_whitelist",a,"imageWhitelist"),d(a,"mouseDispatch",a.s("Mouse"),"processEvent"),d(a,"mouseButtonsDown",a.s("Mouse"),"_buttonDown"),d(a,"lastEvent",a.s("Mouse"),"lastMouseEvent"),d(a,"mouseObjs",a.s("Mouse"),"mouseObjs"),d(a,"keyboardDispatch",a.s("Keyboard"),"processEvent"),d(a,"keydown",a.s("Keyboard"),"_keyDown"),d(a,"resetKeyDown",a.s("Keyboard"),"resetKeyDown"),d(a,"touchDispatch",a,"_touchDispatch"),d(a,"touchObjs",a.s("Touch"),"touchObjs"),a.touchHandler={},d(a.touchHandler,"fingers",a.s("Touch"),"touchPoints")}}},{}],3:[function(a,b,c){function d(a){this.button=a}function e(a){this.key=a}function f(a){this.inputs=a}var g=a("../core/core.js");d.prototype={isDown:function(){var a=this.mouseSystem;return a||(this.mouseSystem=a=g.s("Mouse")),a.isButtonDown(this.button)}},e.prototype={isDown:function(){var a=this.keyboardSystem;return a||(this.keyboardSystem=a=g.s("Keyboard")),a.isKeyDown(this.key)}},f.prototype={timeDown:null,isActive:function(){for(var a in this.inputs){if(this.inputs[a].isDown())return this.timeDown||(this.timeDown=Date.now()),!0}return delete this.timeDown,!1},destroy:function(){for(var a in this.inputs)"function"==typeof this.inputs[a].destroy&&this.inputs[a].destroy()}},g.s("Controls",{init:function(){this._dpads={},this._triggers={},g.s("Mouse").bind("MouseDown",this.updateTriggers.bind(this)),g.s("Mouse").bind("MouseUp",this.updateTriggers.bind(this)),g.s("Mouse").bind("DoubleClick",this.updateTriggers.bind(this)),g.s("Mouse").bind("Click",this.updateTriggers.bind(this))},events:{EnterFrame:"runEvents",KeyDown:"updateTriggers",KeyUp:"updateTriggers"},updateTriggers:function(a){for(var b in this._triggers){var c=this._triggers[b];this.updateTriggerInput(c)}},runEvents:function(){for(var a in this._dpads){var b=this._dpads[a];b.oldX=b.x,b.oldY=b.y,this.updateDpadInput(b,b.multipleDirecti
"../core/core.js":10}],13:[function(a,b,c){var d=a("../core/core.js");b.exports={init:function(){this.changed=[],this.bind("Change",this._changed_attributes),this.bind("Change",this._changed_triggers)},_changed_triggers:function(a,b){var c;b=d.extend.call({pre:""},b);for(c in a)this.trigger("Change["+b.pre+c+"]",a[c]),a[c].constructor===Object&&this._changed_triggers(a[c],{pre:b.pre+c+"."})},_changed_attributes:function(a){var b;for(b in a)this.changed.push(b);return this},is_dirty:function(a){return 0===arguments.length?!!this.changed.length:this.changed.indexOf(a)>-1}}},{"../core/core.js":10}],14:[function(a,b,c){var d=a("../core/core.js");b.exports={_scenes:{},_current:null,scene:function(a,b,c){if(1===arguments.length||"function"!=typeof arguments[1])return void d.enterScene(a,arguments[1]);d.defineScene(a,b,c)},defineScene:function(a,b,c){if("function"!=typeof b)throw"Init function is the wrong type.";this._scenes[a]={},this._scenes[a].initialize=b,void 0!==c&&(this._scenes[a].uninitialize=c)},enterScene:function(a,b){if("function"==typeof b)throw"Scene data cannot be a function";d.trigger("SceneDestroy",{newScene:a}),d.viewport.reset(),d("2D").each(function(){this.has("Persist")||this.destroy()}),null!==this._current&&"uninitialize"in this._scenes[this._current]&&this._scenes[this._current].uninitialize.call(this);var c=this._current;this._current=a,d.trigger("SceneChange",{oldScene:c,newScene:a}),this._scenes.hasOwnProperty(a)?this._scenes[a].initialize.call(this,b):d.error('The scene "'+a+'" does not exist')}}},{"../core/core.js":10}],15:[function(a,b,c){var d=a("../core/core.js");try{var e="undefined"!=typeof window&&window.localStorage||new a("node-localstorage").LocalStorage("./localStorage")}catch(a){var e=null}var f=function(a,b){var c=b;if(!e)return d.error("Local storage is not accessible. (Perhaps you are including crafty.js cross-domain?)"),!1;if(1===arguments.length)try{return JSON.parse(e.getItem(a))}catch(b){return e.getItem(a)}else"object"==typeof b&&(c=JSON.stringify(b)),e.setItem(a,c)};f.remove=function(a){if(!e)return void d.error("Local storage is not accessible. (Perhaps you are including crafty.js cross-domain?)");e.removeItem(a)},b.exports=f},{"../core/core.js":10}],16:[function(a,b,c){function d(a,b){var c={};for(var d in b)c[d]=b[d];for(d in a)d in b||(c[d]=a[d]);return c}var e=a("../core/core.js");e._systems={},e.s=function(a,b,c,d){if(!b)return e._systems[a];"boolean"==typeof c&&(d=c,c=null),!1===d?(e._systems[a]=new e.CraftySystem(a,b,c),e.trigger("SystemLoaded",a)):e._registerLazySystem(a,b,c)},e._registerLazySystem=function(a,b,c){Object.defineProperty(e._systems,a,{get:function(){return Object.defineProperty(e._systems,a,{value:new e.CraftySystem(a,b,c),writable:!0,enumerable:!0,configurable:!0}),e.trigger("SystemLoaded",a),e._systems[a]},configurable:!0})},e.CraftySystem=function(){var a=1;return function(b,c,f){if(this.name=b,!c)return this;if(this._systemTemplate=c,this.extend(c),this.options=d(this.options,f),e._addCallbackMethods(this),this[0]="system"+a++,"properties"in c){var g=c.properties;for(var h in g)Object.defineProperty(this,h,g[h])}if("events"in c){var i=c.events;for(var j in i){var k="function"==typeof i[j]?i[j]:c[i[j]];this.bind(j,k)}}"function"==typeof this.init&&this.init(b)}}(),e.CraftySystem.prototype={extend:function(a){for(var b in a)void 0===this[b]&&(this[b]=a[b])},bind:function(a,b){return this._bindCallback(a,b),this},trigger:function(a,b){return this._runCallbacks(a,b),this},unbind:function(a,b){return this._unbindCallbacks(a,b),this},one:function(a,b){var c=this,d=function(e){b.call(c,e),c.unbind(a,d)};return c.bind(a,d)},uniqueBind:function(a,b){return this.unbind(a,b),this.bind(a,b)},destroy:function(){e.trigger("SystemDestroyed",this),"function"==typeof this.remove&&this.remove(),this._unbindAll(),delete e._systems[this.name]}}},{"../core/core.js":10}],17:[function(a,b,c){b.exports={delaySpeed:1,init:function(){this._delays=[],this._delaysPaused=!1,this.bind("UpdateFrame",function(a){if(!this._delaysPaused)for(var b=this._delays.length;--b>=0;){var c=
return this.inner+=a,this._element.innerHTML+=a,this},prepend:function(a){return this.inner=a+this.inner,this._element.innerHTML=a+this.inner,this}})},{"../core/core.js":10}],33:[function(a,b,c){var d=a("../core/core.js");d.defaultShader("Image",new d.WebGLShader("attribute vec2 aPosition;\nattribute vec3 aOrientation;\nattribute vec2 aLayer;\nattribute vec2 aTextureCoord;\n\nvarying mediump vec3 vTextureCoord;\n\nuniform vec4 uViewport;\nuniform mediump vec2 uTextureDimensions;\n\nmat4 viewportScale = mat4(2.0 / uViewport.z, 0, 0, 0, 0, -2.0 / uViewport.w, 0,0, 0, 0,1,0, -1,+1,0,1);\nvec4 viewportTranslation = vec4(uViewport.xy, 0, 0);\n\nvoid main() {\n vec2 pos = aPosition;\n vec2 entityOrigin = aOrientation.xy;\n mat2 entityRotationMatrix = mat2(cos(aOrientation.z), sin(aOrientation.z), -sin(aOrientation.z), cos(aOrientation.z));\n \n pos = entityRotationMatrix * (pos - entityOrigin) + entityOrigin ;\n gl_Position = viewportScale * (viewportTranslation + vec4(pos, 1.0/(1.0+exp(aLayer.x) ), 1) );\n vTextureCoord = vec3(aTextureCoord, aLayer.y);\n}","varying mediump vec3 vTextureCoord;\n \nuniform sampler2D uSampler;\nuniform mediump vec2 uTextureDimensions;\n\nvoid main(void) {\n highp vec2 coord = vTextureCoord.xy / uTextureDimensions;\n mediump vec4 base_color = texture2D(uSampler, coord);\n gl_FragColor = vec4(base_color.rgb*base_color.a*vTextureCoord.z, base_color.a*vTextureCoord.z);\n}",[{name:"aPosition",width:2},{name:"aOrientation",width:3},{name:"aLayer",width:2},{name:"aTextureCoord",width:2}],function(a,b){var c=a.pos;a.program.writeVector("aTextureCoord",0,0,0,c._h,c._w,0,c._w,c._h)})),d.c("Image",{_repeat:"repeat",ready:!1,init:function(){this.bind("Draw",this._drawImage),this.bind("LayerAttached",this._setupImage)},remove:function(){this.unbind("LayerAttached",this._setupImage),this.unbind("Draw",this._drawImage)},image:function(a,b){if(this.__image=a,this._repeat=b||"no-repeat",this.img=d.asset(a),this.img)this._setupImage(this._drawLayer);else{this.img=new Image,d.asset(a,this.img),this.img.src=a;var c=this;this.img.onload=function(){c._setupImage(c._drawLayer)}}return this.trigger("Invalidate"),this},_setupImage:function(a){this.img&&a&&("Canvas"===a.type?this._pattern=this._drawContext.createPattern(this.img,this._repeat):"WebGL"===a.type&&(this._establishShader("image:"+this.__image,d.defaultShader("Image")),this.program.setTexture(this._drawLayer.makeTexture(this.__image,this.img,"no-repeat"!==this._repeat))),"no-repeat"===this._repeat&&(this.w=this.w||this.img.width,this.h=this.h||this.img.height),this.ready=!0,this.trigger("Invalidate"))},_drawImage:function(a){if("canvas"===a.type){if(!this.ready||!this._pattern)return;var b=a.ctx;b.fillStyle=this._pattern,b.save(),b.translate(a.pos._x,a.pos._y),b.fillRect(0,0,a.pos._w,a.pos._h),b.restore()}else"DOM"===a.type?this.__image&&(a.style.backgroundImage="url("+this.__image+")",a.style.backgroundRepeat=this._repeat):"webgl"===a.type&&a.program.draw(a,this)}})},{"../core/core.js":10}],34:[function(a,b,c){var d=a("../core/core.js");d.extend({_drawLayerTemplates:{},_drawLayers:[],_addDrawLayerInstance:function(a){d._drawLayers.push(a),this._drawLayers.sort(function(a,b){return a.options.z-b.options.z})},_removeDrawLayerInstance:function(a){var b=this._drawLayers.indexOf(a);b>=0&&this._drawLayers.splice(b,1),this._drawLayers.sort(function(a,b){return a.options.z-b.options.z})},_registerLayerTemplate:function(a,b){this._drawLayerTemplates[a]=b;var c=this._commonLayerProperties;for(var d in c)b[d]||(b[d]=c[d])},_commonLayerProperties:{options:{xResponse:1,yResponse:1,scaleResponse:1,z:0},_pointerEntities:0,_dirtyViewport:!1,_cachedViewportRect:null,init:function(){this._cachedViewportRect={},this.trigger("LayerInit"),this.uniqueBind("InvalidateViewport",function(){this._dirtyViewport=!0}),this.trigger("PixelartSet",d._pixelartEnabled),d._addDrawLayerInstance(this)},remove:function(){this.trigger("LayerRemove"),d._removeDrawLayerInstance(this)},_sort:function(a,b){return a._globalZ-b._globalZ},_viewportRect:function(a){var b=this._cache
var b=this._indexArray,c=this.index_pointer;b[0+c]=0+a,b[1+c]=1+a,b[2+c]=2+a,b[3+c]=1+a,b[4+c]=2+a,b[5+c]=3+a,this.index_pointer+=6},renderBatch:function(){var a=this.context;a.bindBuffer(a.ARRAY_BUFFER,this._attributeBuffer),a.bufferData(a.ARRAY_BUFFER,this._attributeArray,a.STATIC_DRAW),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBuffer),a.bufferData(a.ELEMENT_ARRAY_BUFFER,this._indexArray,a.STATIC_DRAW),a.drawElements(a.TRIANGLES,this.index_pointer,a.UNSIGNED_SHORT,0)},setViewportUniforms:function(a,b){var c=this.context;c.useProgram(this.shader),c.uniform4f(this.shader.viewport,-a._x,-a._y,a._w,a._h)},writeVector:function(a,b,c){for(var d=this._attribute_table[a],e=this.stride,f=d.offset+this.ent_offset*e,g=d.width,h=arguments.length-1,i=this._attributeArray,j=0;j<4;j++)for(var k=0;k<g;k++)i[f+e*j+k]=arguments[(g*j+k)%h+1]}},e._registerLayerTemplate("WebGL",{type:"WebGL",context:null,_compileShader:function(a,b){var c=this.context,d=c.createShader(b);if(c.shaderSource(d,a),c.compileShader(d),!c.getShaderParameter(d,c.COMPILE_STATUS))throw c.getShaderInfoLog(d);return d},_makeProgram:function(a){var b=this.context,c=this._compileShader(a.fragmentCode,b.FRAGMENT_SHADER),d=this._compileShader(a.vertexCode,b.VERTEX_SHADER),e=b.createProgram();if(b.attachShader(e,d),b.attachShader(e,c),b.linkProgram(e),!b.getProgramParameter(e,b.LINK_STATUS))throw"Could not initialise shaders";return e.viewport=b.getUniformLocation(e,"uViewport"),e},getProgramWrapper:function(a,b){if(void 0===this.programs[a]){var c=this._makeProgram(b),e=new d(this,c);e.name=a,e.initAttributes(b.attributeList),e.draw=b.drawCallback,e.setViewportUniforms(this._viewportRect(),this.options),this.programs[a]=e}return this.programs[a]},makeTexture:function(a,b,c){return this.texture_manager.makeTexture(a,b,c)},events:{LayerInit:"layerInit",LayerRemove:"layerRemove",RenderScene:"_render",PixelartSet:"_setPixelart",ViewportResize:"_resize"},layerInit:function(){if(!e.support.webgl)return e.trigger("NoWebGL"),void e.stop();this.programs={};var a;a=f.createElement("canvas"),a.width=e.viewport.width,a.height=e.viewport.height,a.style.position="absolute",a.style.left="0px",a.style.top="0px",a.style.zIndex=this.options.z,e.stage.elem.appendChild(a);var b;try{b=a.getContext("webgl",{premultipliedalpha:!0})||a.getContext("experimental-webgl",{premultipliedalpha:!0}),b.viewportWidth=a.width,b.viewportHeight=a.height}catch(a){return e.trigger("NoWebGL"),void e.stop()}this.context=b,this._canvas=a,b.clearColor(0,0,0,0),b.disable(b.DEPTH_TEST),b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA),b.enable(b.BLEND),this.texture_manager=new e.TextureManager(b,this),this._dirtyViewport=!0},layerRemove:function(){this._canvas.parentNode.removeChild(this._canvas)},_resize:function(){var a=this._canvas;a.width=e.viewport.width,a.height=e.viewport.height;var b=this.context;b.viewportWidth=a.width,b.viewportHeight=a.height},_setPixelart:function(a){var b=this.context;this.texture_filter=a?b.NEAREST:b.LINEAR},visible_gl:[],_render:function(a){a=a||this._viewportRect();var b=this.context;b.viewport(0,0,b.viewportWidth,b.viewportHeight),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var c=this.programs;if(this._dirtyViewport){var d=this._viewportRect();for(var f in c)c[f].setViewportUniforms(d,this.options);this._dirtyViewport=!1}var g,h=e.map.search(a),i=0,j=h.length,k=this.visible_gl;for(k.length=0,i=0;i<j;i++)g=h[i],g._visible&&g.program&&g._drawLayer===this&&k.push(g);k.sort(this._sort),j=k.length;var l=null;for(i=0;i<j;i++)g=k[i],l!==g.program&&(null!==l&&l.renderBatch(),l=g.program,l.index_pointer=0,l.switchTo()),g.draw(),g._changed=!1;null!==l&&l.renderBatch()},dirty:function(a){},attach:function(a){a._drawContext=this.context},detach:function(a){a.program&&a.program.unregisterEntity(a)}})},{"../core/core.js":10}],42:[function(a,b,c){var d=a("../core/core.js");d.extend({WebGLShader:function(a,b,c,d){this.vertexCode=a,this.fragmentCode=b,this.attributeList=c,this.drawCallback=d},defaultShader:function(a,b){if(this._defaultShaders=this._defaultShaders||{},1===arguments.length)return thi
this[a]=b,this.trigger("Move",e);else if("_h"===a||"_w"===a){c=this._mbr;var f=this[a];this[a]=b,c&&this._calculateMBR(),"_w"===a?this.trigger("Resize",{axis:"w",amount:b-f}):"_h"===a&&this.trigger("Resize",{axis:"h",amount:b-f}),this.trigger("Move",e)}else if("_z"===a){var g=b<<0;b=b===g?g:g+1,this._globalZ=1e5*b+this[0],this[a]=b,this.trigger("Reorder")}this[a]=b,this.trigger("Invalidate"),d.rectManager._pool.recycle(e)}}}),d.polygon=function(a){arguments.length>1&&(a=Array.prototype.slice.call(arguments,0)),this.points=a},d.polygon.prototype={containsPoint:function(a,b){var c,d,e=this.points,f=e.length/2,g=!1;for(c=0,d=f-1;c<f;d=c++)e[2*c+1]>b!=e[2*d+1]>b&&a<(e[2*d]-e[2*c])*(b-e[2*c+1])/(e[2*d+1]-e[2*c+1])+e[2*c]&&(g=!g);return g},shift:function(a,b){for(var c=0,d=this.points,e=d.length;c<e;c+=2)d[c]+=a,d[c+1]+=b},clone:function(){return new d.polygon(this.points.slice(0))},rotate:function(a,b,c,d,e){for(var f,g,h=0,i=this.points,j=i.length;h<j;h+=2)f=b+(i[h]-b)*d+(i[h+1]-c)*e,g=c-(i[h]-b)*e+(i[h+1]-c)*d,i[h]=f,i[h+1]=g},intersectRay:function(a,b){for(var c,d,e,f,g,h,i,j,k,l=this.points,m=1/0,n=a._x,o=b.x,p=a._y,q=b.y,r=0,s=l.length,t=l[s-2],u=l[s-1];r<s;r+=2)h=l[r],j=l[r+1],i=h-t,k=j-u,d=(t-n)*k-(u-p)*i,f=(t-n)*q-(u-p)*o,g=o*k-q*i,0!==g?(c=d/g,(e=f/g)>=0&&e<=1&&c>=0&&c<m&&(m=c)):0!==d&&0!==f||(c=(t-n)*o+(u-p)*q,c>=0&&c<m&&(m=c),(c=(h-n)*o+(j-p)*q)>=0&&c<m&&(m=c)),t=h,u=j;return m}},d.circle=function(a,b,c){this.x=a,this.y=b,this.radius=c,this.points=[];for(var d,e=0;e<16;e+=2)d=e*Math.PI/8,this.points[e]=this.x+Math.sin(d)*c,this.points[e+1]=this.y+Math.cos(d)*c},d.circle.prototype={containsPoint:function(a,b){var c=this.radius,d=this.x-a,e=this.y-b;return d*d+e*e<c*c},shift:function(a,b){this.x+=a,this.y+=b;for(var c=0,d=this.points,e=d.length;c<e;c+=2)d[c]+=a,d[c+1]+=b},rotate:function(){}},d.matrix=function(a){this.mtx=a,this.width=a[0].length,this.height=a.length},d.matrix.prototype={x:function(a){if(this.width===a.height){for(var b=[],c=0;c<this.height;c++){b[c]=[];for(var e=0;e<a.width;e++){for(var f=0,g=0;g<this.width;g++)f+=this.mtx[c][g]*a.mtx[g][e];b[c][e]=f}}return new d.matrix(b)}},e:function(a,b){return a<1||a>this.mtx.length||b<1||b>this.mtx[0].length?null:this.mtx[a-1][b-1]}}},{"../core/core.js":10}],55:[function(a,b,c){var d=a("../core/core.js"),e=Math.PI/180;d.extend({raycast:function(a,b){for(var c,e,f="obj",g=1/0,h=!0,i=2,j=arguments.length;i<j;++i)c=arguments[i],e=typeof c,"number"===e?g=c+1e-6:"string"===e?f=c:"boolean"===e&&(h=c);var k=a._x,l=a._y,m=b.x,n=b.y,o={},p=[];if(g<0){var q=null,r=1/0;d.map.traverseRay(a,b,function(c,d){if(q&&r<d)return p.push({obj:q,distance:r,x:k+r*m,y:l+r*n}),q=null,r=1/0,!0;if(c.map&&c.__c[f]&&!o[c[0]]){o[c[0]]=!0;var e=c.map.intersectRay(a,b);e<r&&(q=c,r=e)}}),q&&p.push({obj:q,distance:r,x:k+r*m,y:l+r*n})}else d.map.traverseRay(a,b,function(c,d){if(d>g)return!0;if(c.map&&c.__c[f]&&!o[c[0]]){o[c[0]]=!0;var e=c.map.intersectRay(a,b);e<g&&p.push({obj:c,distance:e,x:k+e*m,y:l+e*n})}});return h&&p.sort(function(a,b){return a.distance-b.distance}),p}}),d.c("Collision",{init:function(){this.requires("2D"),this._collisionData={},this.collision()},remove:function(){this._cbr=null,this.unbind("Resize",this._resizeMap),this.unbind("Resize",this._checkBounds)},collision:function(a){if(this.unbind("Resize",this._resizeMap),this.unbind("Resize",this._checkBounds),a){if(arguments.length>1){var b=Array.prototype.slice.call(arguments,0);a=new d.polygon(b)}else a=a.constructor===Array?new d.polygon(a.slice()):a.clone();this._findBounds(a.points)}else a=new d.polygon([0,0,this._w,0,this._w,this._h,0,this._h]),this.bind("Resize",this._resizeMap),this._cbr=null;return this.rotation&&a.rotate(this.rotation,this._origin.x,this._origin.y,Math.cos(-this.rotation*e),Math.sin(-this.rotation*e)),this.map=a,this.attach(this.map),this.map.shift(this._x,this._y),this.trigger("NewHitbox",a),this},cbr:function(a){return a=a||{},this._cbr?(a._x=this._cbr._x,a._y=this._cbr._y,a._w=this._cbr._w,a._h=this._cbr._h,a):this.mbr(a)},_findBounds:function(a){for(var b=1/0,c=-1/0,d=1/0,e=-1/0,f=a.length,g=0