melonjs 9.0.0 → 9.0.1

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v9.0.0
2
+ * melonJS Game Engine - v9.0.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -33,4 +33,4 @@
33
33
  *
34
34
  * MIT License
35
35
  */
36
- function(){var t;HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var e=this;if(!e.ctx||!e.ctx.listener)return e;for(var i=e._howls.length-1;i>=0;i--)e._howls[i].stereo(t);return e},HowlerGlobal.prototype.pos=function(t,e,i){var n=this;return n.ctx&&n.ctx.listener?(e="number"!=typeof e?n._pos[1]:e,i="number"!=typeof i?n._pos[2]:i,"number"!=typeof t?n._pos:(n._pos=[t,e,i],void 0!==n.ctx.listener.positionX?(n.ctx.listener.positionX.setTargetAtTime(n._pos[0],Howler.ctx.currentTime,.1),n.ctx.listener.positionY.setTargetAtTime(n._pos[1],Howler.ctx.currentTime,.1),n.ctx.listener.positionZ.setTargetAtTime(n._pos[2],Howler.ctx.currentTime,.1)):n.ctx.listener.setPosition(n._pos[0],n._pos[1],n._pos[2]),n)):n},HowlerGlobal.prototype.orientation=function(t,e,i,n,r,o){var s=this;if(!s.ctx||!s.ctx.listener)return s;var a=s._orientation;return e="number"!=typeof e?a[1]:e,i="number"!=typeof i?a[2]:i,n="number"!=typeof n?a[3]:n,r="number"!=typeof r?a[4]:r,o="number"!=typeof o?a[5]:o,"number"!=typeof t?a:(s._orientation=[t,e,i,n,r,o],void 0!==s.ctx.listener.forwardX?(s.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),s.ctx.listener.forwardY.setTargetAtTime(e,Howler.ctx.currentTime,.1),s.ctx.listener.forwardZ.setTargetAtTime(i,Howler.ctx.currentTime,.1),s.ctx.listener.upX.setTargetAtTime(n,Howler.ctx.currentTime,.1),s.ctx.listener.upY.setTargetAtTime(r,Howler.ctx.currentTime,.1),s.ctx.listener.upZ.setTargetAtTime(o,Howler.ctx.currentTime,.1)):s.ctx.listener.setOrientation(t,e,i,n,r,o),s)},Howl.prototype.init=(t=Howl.prototype.init,function(e){var i=this;return i._orientation=e.orientation||[1,0,0],i._stereo=e.stereo||null,i._pos=e.pos||null,i._pannerAttr={coneInnerAngle:void 0!==e.coneInnerAngle?e.coneInnerAngle:360,coneOuterAngle:void 0!==e.coneOuterAngle?e.coneOuterAngle:360,coneOuterGain:void 0!==e.coneOuterGain?e.coneOuterGain:0,distanceModel:void 0!==e.distanceModel?e.distanceModel:"inverse",maxDistance:void 0!==e.maxDistance?e.maxDistance:1e4,panningModel:void 0!==e.panningModel?e.panningModel:"HRTF",refDistance:void 0!==e.refDistance?e.refDistance:1,rolloffFactor:void 0!==e.rolloffFactor?e.rolloffFactor:1},i._onstereo=e.onstereo?[{fn:e.onstereo}]:[],i._onpos=e.onpos?[{fn:e.onpos}]:[],i._onorientation=e.onorientation?[{fn:e.onorientation}]:[],t.call(this,e)}),Howl.prototype.stereo=function(t,i){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"stereo",action:function(){n.stereo(t,i)}}),n;var r=void 0===Howler.ctx.createStereoPanner?"spatial":"stereo";if(void 0===i){if("number"!=typeof t)return n._stereo;n._stereo=t,n._pos=[t,0,0]}for(var o=n._getSoundIds(i),s=0;s<o.length;s++){var a=n._soundById(o[s]);if(a){if("number"!=typeof t)return a._stereo;a._stereo=t,a._pos=[t,0,0],a._node&&(a._pannerAttr.panningModel="equalpower",a._panner&&a._panner.pan||e(a,r),"spatial"===r?void 0!==a._panner.positionX?(a._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),a._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),a._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):a._panner.setPosition(t,0,0):a._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),n._emit("stereo",a._id)}}return n},Howl.prototype.pos=function(t,i,n,r){var o=this;if(!o._webAudio)return o;if("loaded"!==o._state)return o._queue.push({event:"pos",action:function(){o.pos(t,i,n,r)}}),o;if(i="number"!=typeof i?0:i,n="number"!=typeof n?-.5:n,void 0===r){if("number"!=typeof t)return o._pos;o._pos=[t,i,n]}for(var s=o._getSoundIds(r),a=0;a<s.length;a++){var h=o._soundById(s[a]);if(h){if("number"!=typeof t)return h._pos;h._pos=[t,i,n],h._node&&(h._panner&&!h._panner.pan||e(h,"spatial"),void 0!==h._panner.positionX?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(n,Howler.ctx.currentTime)):h._panner.setPosition(t,i,n)),o._emit("pos",h._id)}}return o},Howl.prototype.orientation=function(t,i,n,r){var o=this;if(!o._webAudio)return o;if("loaded"!==o._state)return o._queue.push({event:"orientation",action:function(){o.orientation(t,i,n,r)}}),o;if(i="number"!=typeof i?o._orientation[1]:i,n="number"!=typeof n?o._orientation[2]:n,void 0===r){if("number"!=typeof t)return o._orientation;o._orientation=[t,i,n]}for(var s=o._getSoundIds(r),a=0;a<s.length;a++){var h=o._soundById(s[a]);if(h){if("number"!=typeof t)return h._orientation;h._orientation=[t,i,n],h._node&&(h._panner||(h._pos||(h._pos=o._pos||[0,0,-.5]),e(h,"spatial")),void 0!==h._panner.orientationX?(h._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.orientationZ.setValueAtTime(n,Howler.ctx.currentTime)):h._panner.setOrientation(t,i,n)),o._emit("orientation",h._id)}}return o},Howl.prototype.pannerAttr=function(){var t,i,n,r=this,o=arguments;if(!r._webAudio)return r;if(0===o.length)return r._pannerAttr;if(1===o.length){if("object"!=typeof o[0])return(n=r._soundById(parseInt(o[0],10)))?n._pannerAttr:r._pannerAttr;t=o[0],void 0===i&&(t.pannerAttr||(t.pannerAttr={coneInnerAngle:t.coneInnerAngle,coneOuterAngle:t.coneOuterAngle,coneOuterGain:t.coneOuterGain,distanceModel:t.distanceModel,maxDistance:t.maxDistance,refDistance:t.refDistance,rolloffFactor:t.rolloffFactor,panningModel:t.panningModel}),r._pannerAttr={coneInnerAngle:void 0!==t.pannerAttr.coneInnerAngle?t.pannerAttr.coneInnerAngle:r._coneInnerAngle,coneOuterAngle:void 0!==t.pannerAttr.coneOuterAngle?t.pannerAttr.coneOuterAngle:r._coneOuterAngle,coneOuterGain:void 0!==t.pannerAttr.coneOuterGain?t.pannerAttr.coneOuterGain:r._coneOuterGain,distanceModel:void 0!==t.pannerAttr.distanceModel?t.pannerAttr.distanceModel:r._distanceModel,maxDistance:void 0!==t.pannerAttr.maxDistance?t.pannerAttr.maxDistance:r._maxDistance,refDistance:void 0!==t.pannerAttr.refDistance?t.pannerAttr.refDistance:r._refDistance,rolloffFactor:void 0!==t.pannerAttr.rolloffFactor?t.pannerAttr.rolloffFactor:r._rolloffFactor,panningModel:void 0!==t.pannerAttr.panningModel?t.pannerAttr.panningModel:r._panningModel})}else 2===o.length&&(t=o[0],i=parseInt(o[1],10));for(var s=r._getSoundIds(i),a=0;a<s.length;a++)if(n=r._soundById(s[a])){var h=n._pannerAttr;h={coneInnerAngle:void 0!==t.coneInnerAngle?t.coneInnerAngle:h.coneInnerAngle,coneOuterAngle:void 0!==t.coneOuterAngle?t.coneOuterAngle:h.coneOuterAngle,coneOuterGain:void 0!==t.coneOuterGain?t.coneOuterGain:h.coneOuterGain,distanceModel:void 0!==t.distanceModel?t.distanceModel:h.distanceModel,maxDistance:void 0!==t.maxDistance?t.maxDistance:h.maxDistance,refDistance:void 0!==t.refDistance?t.refDistance:h.refDistance,rolloffFactor:void 0!==t.rolloffFactor?t.rolloffFactor:h.rolloffFactor,panningModel:void 0!==t.panningModel?t.panningModel:h.panningModel};var l=n._panner;l?(l.coneInnerAngle=h.coneInnerAngle,l.coneOuterAngle=h.coneOuterAngle,l.coneOuterGain=h.coneOuterGain,l.distanceModel=h.distanceModel,l.maxDistance=h.maxDistance,l.refDistance=h.refDistance,l.rolloffFactor=h.rolloffFactor,l.panningModel=h.panningModel):(n._pos||(n._pos=r._pos||[0,0,-.5]),e(n,"spatial"))}return r},Sound.prototype.init=function(t){return function(){var e=this,i=e._parent;e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,t.call(this),e._stereo?i.stereo(e._stereo):e._pos&&i.pos(e._pos[0],e._pos[1],e._pos[2],e._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var e=this,i=e._parent;return e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,e._stereo?i.stereo(e._stereo):e._pos?i.pos(e._pos[0],e._pos[1],e._pos[2],e._id):e._panner&&(e._panner.disconnect(0),e._panner=void 0,i._refreshBuffer(e)),t.call(this)}}(Sound.prototype.reset);var e=function(t,e){"spatial"===(e=e||"spatial")?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,void 0!==t._panner.positionX?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),void 0!==t._panner.orientationX?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}}()}(howler);var ObservableVector2d=function(t){function e(e,i,n){if(void 0===e&&(e=0),void 0===i&&(i=0),t.call(this,e,i),void 0===n)throw new Error("undefined `onUpdate` callback");this.setCallback(n.onUpdate,n.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),this.setMuted(t,e),void 0!==i&&this.setCallback(i.onUpdate,i.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._x,this._y);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._x,this._y);this._y=e&&"y"in e?e.y:t},e.prototype._set=function(t,e){var i=this.onUpdate.call(this.scope,t,e,this._x,this._y);return i&&"x"in i&&"y"in i?(this._x=i.x,this._y=i.y):(this._x=t,this._y=e),this},e.prototype.setMuted=function(t,e){return this._x=t,this._y=e,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y)},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y)},e.prototype.scale=function(t,e){return this._set(this._x*t,this._y*(void 0!==e?e:t))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y)},e.prototype.div=function(t){return this._set(this._x/t,this._y/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y)},e.prototype.clamp=function(t,i){return new e(clamp(this.x,t,i),clamp(this.y,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e))},e.prototype.minV=function(t){return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y)},e.prototype.maxV=function(t){return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y))},e.prototype.negate=function(){return new e(-this._x,-this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y)},e.prototype.copy=function(t){return this._set(t.x,t.y)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},e.prototype.perp=function(){return this._set(this._y,-this._x)},e.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this._x-i,o=this._y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n)},e.prototype.dotProduct=function(t){return this._x*t.x+this._y*t.y},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this},e.prototype.distance=function(t){return Math.sqrt((this._x-t.x)*(this._x-t.x)+(this._y-t.y)*(this._y-t.y))},e.prototype.clone=function(){return pool.pull("ObservableVector2d",this._x,this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.toVector2d=function(){return pool.pull("Vector2d",this._x,this._y)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y},Object.defineProperties(e.prototype,i),e}(Vector2d),Vector3d=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this).onResetEvent.apply(t,e)};Vector3d.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype._set=function(t,e,i){return void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype.set=function(t,e,i){if(t!==+t||e!==+e||void 0!==i&&i!==+i)throw new Error("invalid x, y, z parameters (not a number)");return this._set(t,e,i)},Vector3d.prototype.setZero=function(){return this.set(0,0,0)},Vector3d.prototype.setV=function(t){return this._set(t.x,t.y,t.z)},Vector3d.prototype.add=function(t){return this._set(this.x+t.x,this.y+t.y,this.z+(t.z||0))},Vector3d.prototype.sub=function(t){return this._set(this.x-t.x,this.y-t.y,this.z-(t.z||0))},Vector3d.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this.x*t,this.y*e,this.z*(i||1))},Vector3d.prototype.scaleV=function(t){return this.scale(t.x,t.y,t.z)},Vector3d.prototype.toIso=function(){return this._set(this.x-this.y,.5*(this.x+this.y),this.z)},Vector3d.prototype.to2d=function(){return this._set(this.y+this.x/2,this.y-this.x/2,this.z)},Vector3d.prototype.div=function(t){return this._set(this.x/t,this.y/t,this.z/t)},Vector3d.prototype.abs=function(){return this._set(this.x<0?-this.x:this.x,this.y<0?-this.y:this.y,this.z<0?-this.z:this.z)},Vector3d.prototype.clamp=function(t,e){return new Vector3d(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.clampSelf=function(t,e){return this._set(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.minV=function(t){var e=t.z||0;return this._set(this.x<t.x?this.x:t.x,this.y<t.y?this.y:t.y,this.z<e?this.z:e)},Vector3d.prototype.maxV=function(t){var e=t.z||0;return this._set(this.x>t.x?this.x:t.x,this.y>t.y?this.y:t.y,this.z>e?this.z:e)},Vector3d.prototype.floor=function(){return new Vector3d(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.floorSelf=function(){return this._set(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.ceil=function(){return new Vector3d(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.ceilSelf=function(){return this._set(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.negate=function(){return new Vector3d(-this.x,-this.y,-this.z)},Vector3d.prototype.negateSelf=function(){return this._set(-this.x,-this.y,-this.z)},Vector3d.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},Vector3d.prototype.equals=function(){var t,e,i;return arguments.length>=2?(t=arguments[0],e=arguments[1],i=arguments[2]):(t=arguments[0].x,e=arguments[0].y,i=arguments[0].z),void 0===i&&(i=this.z),this.x===t&&this.y===e&&this.z===i},Vector3d.prototype.normalize=function(){return this.div(this.length()||1)},Vector3d.prototype.perp=function(){return this._set(this.y,-this.x,this.z)},Vector3d.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this.x-i,o=this.y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n,this.z)},Vector3d.prototype.dotProduct=function(t){return this.x*t.x+this.y*t.y+this.z*(void 0!==t.z?t.z:this.z)},Vector3d.prototype.length2=function(){return this.dotProduct(this)},Vector3d.prototype.length=function(){return Math.sqrt(this.length2())},Vector3d.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},Vector3d.prototype.distance=function(t){var e=this.x-t.x,i=this.y-t.y,n=this.z-(t.z||0);return Math.sqrt(e*e+i*i+n*n)},Vector3d.prototype.angle=function(t){return Math.acos(clamp(this.dotProduct(t)/(this.length()*t.length()),-1,1))},Vector3d.prototype.project=function(t){var e=this.dotProduct(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.projectN=function(t){var e=this.dotProduct(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.clone=function(){return pool.pull("Vector3d",this.x,this.y,this.z)},Vector3d.prototype.toString=function(){return"x:"+this.x+",y:"+this.y+",z:"+this.z};var ObservableVector3d=function(t){function e(e,i,n,r){if(void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),t.call(this,e,i,n),void 0===r)throw new Error("undefined `onUpdate` callback");this.setCallback(r.onUpdate,r.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0},z:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,n){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.setMuted(t,e,i),void 0!==n&&this.setCallback(n.onUpdate,n.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._z,this._x,this._y,this._z);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._z,this._x,this._y,this._z);this._y=e&&"y"in e?e.y:t},i.z.get=function(){return this._z},i.z.set=function(t){var e=this.onUpdate.call(this.scope,this._x,this._y,t,this._x,this._y,this._z);this._z=e&&"z"in e?e.z:t},e.prototype._set=function(t,e,i){var n=this.onUpdate.call(this.scope,t,e,i,this._x,this._y,this._z);return n&&"x"in n&&"y"in n&&"z"in n?(this._x=n.x,this._y=n.y,this._z=n.z):(this._x=t,this._y=e,this._z=i||0),this},e.prototype.setMuted=function(t,e,i){return this._x=t,this._y=e,this._z=i||0,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y,this._z+(t.z||0))},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y,this._z-(t.z||0))},e.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this._x*t,this._y*e,this._z*(i||1))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y,this._z*(t.z||1))},e.prototype.div=function(t){return this._set(this._x/t,this._y/t,this._z/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y,this._Z<0?-this._z:this._z)},e.prototype.clamp=function(t,i){return new e(clamp(this._x,t,i),clamp(this._y,t,i),clamp(this._z,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e),clamp(this._z,t,e))},e.prototype.minV=function(t){var e=t.z||0;return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y,this._z<e?this._z:e)},e.prototype.maxV=function(t){var e=t.z||0;return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y,this._z>e?this._z:e)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z))},e.prototype.negate=function(){return new e(-this._x,-this._y,-this._z,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y,-this._z)},e.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y&&this._z===(t.z||this._z)},e.prototype.perp=function(){return this._set(this._y,-this._x,this._z)},e.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this.x-i,o=this.y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n,this.z)},e.prototype.dotProduct=function(t){return this._x*t.x+this._y*t.y+this._z*(t.z||1)},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this._z+=(t.z-this._z)*e,this},e.prototype.distance=function(t){var e=this._x-t.x,i=this._y-t.y,n=this._z-(t.z||0);return Math.sqrt(e*e+i*i+n*n)},e.prototype.clone=function(){return pool.pull("ObservableVector3d",this._x,this._y,this._z,{onUpdate:this.onUpdate})},e.prototype.toVector3d=function(){return pool.pull("Vector3d",this._x,this._y,this._z)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y+",z:"+this._z},Object.defineProperties(e.prototype,i),e}(Vector3d),earcut$2={exports:{}};function earcut(t,e,i){i=i||2;var n,r,o,s,a,h,l,u=e&&e.length,c=u?e[0]*i:t.length,d=linkedList(t,0,c,i,!0),p=[];if(!d||d.next===d.prev)return p;if(u&&(d=eliminateHoles(t,e,d,i)),t.length>80*i){n=o=t[0],r=s=t[1];for(var f=i;f<c;f+=i)(a=t[f])<n&&(n=a),(h=t[f+1])<r&&(r=h),a>o&&(o=a),h>s&&(s=h);l=0!==(l=Math.max(o-n,s-r))?1/l:0}return earcutLinked(d,p,i,n,r,l),p}function linkedList(t,e,i,n,r){var o,s;if(r===signedArea(t,e,i,n)>0)for(o=e;o<i;o+=n)s=insertNode(o,t[o],t[o+1],s);else for(o=i-n;o>=e;o-=n)s=insertNode(o,t[o],t[o+1],s);return s&&equals(s,s.next)&&(removeNode(s),s=s.next),s}function filterPoints(t,e){if(!t)return t;e||(e=t);var i,n=t;do{if(i=!1,n.steiner||!equals(n,n.next)&&0!==area(n.prev,n,n.next))n=n.next;else{if(removeNode(n),(n=e=n.prev)===n.next)break;i=!0}}while(i||n!==e);return e}function earcutLinked(t,e,i,n,r,o,s){if(t){!s&&o&&indexCurve(t,n,r,o);for(var a,h,l=t;t.prev!==t.next;)if(a=t.prev,h=t.next,o?isEarHashed(t,n,r,o):isEar(t))e.push(a.i/i),e.push(t.i/i),e.push(h.i/i),removeNode(t),t=h.next,l=h.next;else if((t=h)===l){s?1===s?earcutLinked(t=cureLocalIntersections(filterPoints(t),e,i),e,i,n,r,o,2):2===s&&splitEarcut(t,e,i,n,r,o):earcutLinked(filterPoints(t),e,i,n,r,o,1);break}}}function isEar(t){var e=t.prev,i=t,n=t.next;if(area(e,i,n)>=0)return!1;for(var r=t.next.next;r!==t.prev;){if(pointInTriangle(e.x,e.y,i.x,i.y,n.x,n.y,r.x,r.y)&&area(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function isEarHashed(t,e,i,n){var r=t.prev,o=t,s=t.next;if(area(r,o,s)>=0)return!1;for(var a=r.x<o.x?r.x<s.x?r.x:s.x:o.x<s.x?o.x:s.x,h=r.y<o.y?r.y<s.y?r.y:s.y:o.y<s.y?o.y:s.y,l=r.x>o.x?r.x>s.x?r.x:s.x:o.x>s.x?o.x:s.x,u=r.y>o.y?r.y>s.y?r.y:s.y:o.y>s.y?o.y:s.y,c=zOrder(a,h,e,i,n),d=zOrder(l,u,e,i,n),p=t.prevZ,f=t.nextZ;p&&p.z>=c&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=c;){if(p!==t.prev&&p!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function cureLocalIntersections(t,e,i){var n=t;do{var r=n.prev,o=n.next.next;!equals(r,o)&&intersects(r,n,n.next,o)&&locallyInside(r,o)&&locallyInside(o,r)&&(e.push(r.i/i),e.push(n.i/i),e.push(o.i/i),removeNode(n),removeNode(n.next),n=t=o),n=n.next}while(n!==t);return filterPoints(n)}function splitEarcut(t,e,i,n,r,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&isValidDiagonal(s,a)){var h=splitPolygon(s,a);return s=filterPoints(s,s.next),h=filterPoints(h,h.next),earcutLinked(s,e,i,n,r,o),void earcutLinked(h,e,i,n,r,o)}a=a.next}s=s.next}while(s!==t)}function eliminateHoles(t,e,i,n){var r,o,s,a=[];for(r=0,o=e.length;r<o;r++)(s=linkedList(t,e[r]*n,r<o-1?e[r+1]*n:t.length,n,!1))===s.next&&(s.steiner=!0),a.push(getLeftmost(s));for(a.sort(compareX),r=0;r<a.length;r++)i=filterPoints(i=eliminateHole(a[r],i),i.next);return i}function compareX(t,e){return t.x-e.x}function eliminateHole(t,e){var i=findHoleBridge(t,e);if(!i)return e;var n=splitPolygon(i,t),r=filterPoints(i,i.next);return filterPoints(n,n.next),e===i?r:e}function findHoleBridge(t,e){var i,n=e,r=t.x,o=t.y,s=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var a=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(a<=r&&a>s){if(s=a,a===r){if(o===n.y)return n;if(o===n.next.y)return n.next}i=n.x<n.next.x?n:n.next}}n=n.next}while(n!==e);if(!i)return null;if(r===s)return i;var h,l=i,u=i.x,c=i.y,d=1/0;n=i;do{r>=n.x&&n.x>=u&&r!==n.x&&pointInTriangle(o<c?r:s,o,u,c,o<c?s:r,o,n.x,n.y)&&(h=Math.abs(o-n.y)/(r-n.x),locallyInside(n,t)&&(h<d||h===d&&(n.x>i.x||n.x===i.x&&sectorContainsSector(i,n)))&&(i=n,d=h)),n=n.next}while(n!==l);return i}function sectorContainsSector(t,e){return area(t.prev,t,e.prev)<0&&area(e.next,t,t.next)<0}function indexCurve(t,e,i,n){var r=t;do{null===r.z&&(r.z=zOrder(r.x,r.y,e,i,n)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,sortLinked(r)}function sortLinked(t){var e,i,n,r,o,s,a,h,l=1;do{for(i=t,t=null,o=null,s=0;i;){for(s++,n=i,a=0,e=0;e<l&&(a++,n=n.nextZ);e++);for(h=l;a>0||h>0&&n;)0!==a&&(0===h||!n||i.z<=n.z)?(r=i,i=i.nextZ,a--):(r=n,n=n.nextZ,h--),o?o.nextZ=r:t=r,r.prevZ=o,o=r;i=n}o.nextZ=null,l*=2}while(s>1);return t}function zOrder(t,e,i,n,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*r)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*r)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function getLeftmost(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function pointInTriangle(t,e,i,n,r,o,s,a){return(r-s)*(e-a)-(t-s)*(o-a)>=0&&(t-s)*(n-a)-(i-s)*(e-a)>=0&&(i-s)*(o-a)-(r-s)*(n-a)>=0}function isValidDiagonal(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!intersectsPolygon(t,e)&&(locallyInside(t,e)&&locallyInside(e,t)&&middleInside(t,e)&&(area(t.prev,t,e.prev)||area(t,e.prev,e))||equals(t,e)&&area(t.prev,t,t.next)>0&&area(e.prev,e,e.next)>0)}function area(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function equals(t,e){return t.x===e.x&&t.y===e.y}function intersects(t,e,i,n){var r=sign(area(t,e,i)),o=sign(area(t,e,n)),s=sign(area(i,n,t)),a=sign(area(i,n,e));return r!==o&&s!==a||(!(0!==r||!onSegment(t,i,e))||(!(0!==o||!onSegment(t,n,e))||(!(0!==s||!onSegment(i,t,n))||!(0!==a||!onSegment(i,e,n)))))}function onSegment(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function sign(t){return t>0?1:t<0?-1:0}function intersectsPolygon(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&intersects(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}function locallyInside(t,e){return area(t.prev,t,t.next)<0?area(t,e,t.next)>=0&&area(t,t.prev,e)>=0:area(t,e,t.prev)<0||area(t,t.next,e)<0}function middleInside(t,e){var i=t,n=!1,r=(t.x+e.x)/2,o=(t.y+e.y)/2;do{i.y>o!=i.next.y>o&&i.next.y!==i.y&&r<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==t);return n}function splitPolygon(t,e){var i=new Node$1(t.i,t.x,t.y),n=new Node$1(e.i,e.x,e.y),r=t.next,o=e.prev;return t.next=e,e.prev=t,i.next=r,r.prev=i,n.next=i,i.prev=n,o.next=n,n.prev=o,n}function insertNode(t,e,i,n){var r=new Node$1(t,e,i);return n?(r.next=n.next,r.prev=n,n.next.prev=r,n.next=r):(r.prev=r,r.next=r),r}function removeNode(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Node$1(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function signedArea(t,e,i,n){for(var r=0,o=e,s=i-n;o<i;o+=n)r+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return r}earcut$2.exports=earcut,earcut$2.exports.default=earcut,earcut.deviation=function(t,e,i,n){var r=e&&e.length,o=r?e[0]*i:t.length,s=Math.abs(signedArea(t,0,o,i));if(r)for(var a=0,h=e.length;a<h;a++){var l=e[a]*i,u=a<h-1?e[a+1]*i:t.length;s-=Math.abs(signedArea(t,l,u,i))}var c=0;for(a=0;a<n.length;a+=3){var d=n[a]*i,p=n[a+1]*i,f=n[a+2]*i;c+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},earcut.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},n=0,r=0;r<t.length;r++){for(var o=0;o<t[r].length;o++)for(var s=0;s<e;s++)i.vertices.push(t[r][o][s]);r>0&&(n+=t[r-1].length,i.holes.push(n))}return i};var earcut$1=earcut$2.exports;!function(){function t(t,e,i){Object.keys(i).forEach((function(n){if(e[n]=i[n],"function"!=typeof i[n])throw new TypeError("extend: Method `"+n+"` is not a function");Object.defineProperty(t.prototype,n,{configurable:!0,value:i[n]})}))}function e(t,e,i){return t.prototype[e].apply(this,i)}var i=function(){Object.apply(this,arguments)};(i.prototype=Object.create(Object.prototype)).constructor=i,Object.defineProperty(i,"extend",{value:function i(){for(var n=arguments,r={},o=new Array(arguments.length),s=0;s<arguments.length;s++)o.push(n[s]);function a(){return this.init.apply(this,arguments),this}if(a.prototype=Object.create(this.prototype),o.forEach((function(e){t(a,r,e.__methods__||e)})),!("init"in a.prototype))throw new TypeError("extend: Class is missing a constructor named `init`");return Object.defineProperty(a.prototype,"_super",{value:e}),Object.defineProperty(a,"__methods__",{value:r}),a.extend=i,a}}),"undefined"!=typeof window&&(window.Jay=i)}();var Polygon=window.Jay.extend({init:function(t,e,i){this.pos=new Vector2d,this._bounds,this.points=null,this.edges=[],this.indices=[],this.normals=[],this.shapeType="Polygon",this.setShape(t,e,i)},onResetEvent:function(t,e,i){this.setShape(t,e,i)},setShape:function(t,e,i){return this.pos.set(t,e),this.setVertices(i),this},setVertices:function(t){if(!Array.isArray(t))return this;if(t[0]instanceof Vector2d)this.points=t;else{var e=this.points=[];if("object"==typeof t[0])t.forEach((function(t){e.push(new Vector2d(t.x,t.y))}));else for(var i=0;i<t.length;i+=2)e.push(new Vector2d(t[i],t[i+1]))}return this.recalc(),this.updateBounds(),this},transform:function(t){for(var e=this.points,i=e.length,n=0;n<i;n++)t.apply(e[n]);return this.recalc(),this.updateBounds(),this},toIso:function(){return this.rotate(Math.PI/4).scale(Math.SQRT2,Math.SQRT1_2)},to2d:function(){return this.scale(Math.SQRT1_2,Math.SQRT2).rotate(-Math.PI/4)},rotate:function(t,e){if(0!==t){for(var i=this.points,n=i.length,r=0;r<n;r++)i[r].rotate(t,e);this.recalc(),this.updateBounds()}return this},scale:function(t,e){e=void 0!==e?e:t;for(var i=this.points,n=i.length,r=0;r<n;r++)i[r].scale(t,e);return this.recalc(),this.updateBounds(),this},scaleV:function(t){return this.scale(t.x,t.y)},recalc:function(){var t,e=this.edges,i=this.normals,n=this.indices,r=this.points,o=r.length;if(o<3)throw new Error("Requires at least 3 points");for(t=0;t<o;t++)void 0===e[t]&&(e[t]=new Vector2d),e[t].copy(r[(t+1)%o]).sub(r[t]),void 0===i[t]&&(i[t]=new Vector2d),i[t].copy(e[t]).perp().normalize();return e.length=o,i.length=o,n.length=0,this},getIndices:function(t,e){return 0===this.indices.length&&(this.indices=earcut$1(this.points.flatMap((function(t){return[t.x,t.y]})))),this.indices},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},contains:function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);for(var i=!1,n=this.pos.x,r=this.pos.y,o=this.points,s=o.length,a=0,h=s-1;a<s;h=a++){var l=o[a].y+r,u=o[a].x+n,c=o[h].y+r,d=o[h].x+n;l>e!=c>e&&t<(d-u)*(e-l)/(c-l)+u&&(i=!i)}return i},getBounds:function(){return void 0===this._bounds&&(this._bounds=pool.pull("Bounds")),this._bounds},updateBounds:function(){var t=this.getBounds();return t.update(this.points),t.translate(this.pos),t},clone:function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Polygon(this.pos.x,this.pos.y,t)}}),Rect=Polygon.extend({init:function(t,e,i,n){this._super(Polygon,"init",[t,e,[new Vector2d(0,0),new Vector2d(i,0),new Vector2d(i,n),new Vector2d(0,n)]]),this.shapeType="Rectangle"},onResetEvent:function(t,e,i,n){this.setShape(t,e,i,n)},setShape:function(t,e,i,n){var r=i;return this.pos.set(t,e),4===arguments.length&&((r=this.points)[0].set(0,0),r[1].set(i,0),r[2].set(i,n),r[3].set(0,n)),this.setVertices(r),this},resize:function(t,e){return this.width=t,this.height=e,this},scale:function(t,e){return void 0===e&&(e=t),this.width*=t,this.height*=e,this},clone:function(){return new Rect(this.pos.x,this.pos.y,this.width,this.height)},copy:function(t){return this.setShape(t.pos.x,t.pos.y,t.width,t.height)},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this},shift:function(){2===arguments.length?this.pos.set(arguments[0],arguments[1]):this.pos.setV(arguments[0])},union:function(t){var e=Math.min(this.left,t.left),i=Math.min(this.top,t.top);return this.resize(Math.max(this.right,t.right)-e,Math.max(this.bottom,t.bottom)-i),this.pos.set(e,i),this},overlaps:function(t){return this.left<t.right&&t.left<this.right&&this.top<t.bottom&&t.top<this.bottom},contains:function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Rect?(t=r.left,e=r.right,i=r.top,n=r.bottom):(t=e=r.x,i=n=r.y),t>=this.left&&e<=this.right&&i>=this.top&&n<=this.bottom},equals:function(t){return t.left===this.left&&t.right===this.right&&t.top===this.top&&t.bottom===this.bottom},isFinite:function(){return isFinite(this.pos.x)&&isFinite(this.pos.y)&&isFinite(this.width)&&isFinite(this.height)},toPolygon:function(){return new Polygon(this.pos.x,this.pos.y,this.points)}});Object.defineProperty(Rect.prototype,"left",{get:function(){return this.pos.x},configurable:!0}),Object.defineProperty(Rect.prototype,"right",{get:function(){var t=this.width;return this.pos.x+t||t},configurable:!0}),Object.defineProperty(Rect.prototype,"top",{get:function(){return this.pos.y},configurable:!0}),Object.defineProperty(Rect.prototype,"bottom",{get:function(){var t=this.height;return this.pos.y+t||t},configurable:!0}),Object.defineProperty(Rect.prototype,"width",{get:function(){return this.points[2].x},set:function(t){this.points[1].x=this.points[2].x=t,this.recalc(),this.updateBounds()},configurable:!0}),Object.defineProperty(Rect.prototype,"height",{get:function(){return this.points[2].y},set:function(t){this.points[2].y=this.points[3].y=t,this.recalc(),this.updateBounds()},configurable:!0}),Object.defineProperty(Rect.prototype,"centerX",{get:function(){return isFinite(this.width)?this.pos.x+this.width/2:this.width},set:function(t){this.pos.x=t-this.width/2},configurable:!0}),Object.defineProperty(Rect.prototype,"centerY",{get:function(){return isFinite(this.height)?this.pos.y+this.height/2:this.height},set:function(t){this.pos.y=t-this.height/2},configurable:!0});var _keyStatus={},_keyLock={},_keyLocked={},_keyRefs={},_preventDefaultForKeys={},_keyBindings={},keyDownEvent=function(t,e,i){e=e||t.keyCode||t.button;var n=_keyBindings[e];if(event.publish(event.KEYDOWN,[n,e,!n||!_keyLocked[n]]),n){if(!_keyLocked[n]){var r=void 0!==i?i:e;_keyRefs[n][r]||(_keyStatus[n]++,_keyRefs[n][r]=!0)}return!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyUpEvent=function(t,e,i){e=e||t.keyCode||t.button;var n=_keyBindings[e];if(event.publish(event.KEYUP,[n,e]),n){var r=void 0!==i?i:e;return _keyRefs[n][r]=void 0,_keyStatus[n]>0&&_keyStatus[n]--,_keyLocked[n]=!1,!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyBoardEventTarget=null,KEY={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PRINT_SCREEN:42,INSERT:45,DELETE:46,NUM0:48,NUM1:49,NUM2:50,NUM3:51,NUM4:52,NUM5:53,NUM6:54,NUM7:55,NUM8:56,NUM9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,WINDOW_KEY:91,NUMPAD0:96,NUMPAD1:97,NUMPAD2:98,NUMPAD3:99,NUMPAD4:100,NUMPAD5:101,NUMPAD6:102,NUMPAD7:103,NUMPAD8:104,NUMPAD9:105,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,TILDE:126,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,PLUS:187,COMMA:188,MINUS:189,PERIOD:190,FORWAND_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222};function initKeyboardEvent(){null===keyBoardEventTarget&&!1===device$1.isMobile&&((keyBoardEventTarget=window).addEventListener("keydown",keyDownEvent,!1),keyBoardEventTarget.addEventListener("keyup",keyUpEvent,!1))}function isKeyPressed(t){return!(!_keyStatus[t]||_keyLocked[t])&&(_keyLock[t]&&(_keyLocked[t]=!0),!0)}function keyStatus(t){return _keyStatus[t]>0}function triggerKeyEvent(t,e,i){!0===e?keyDownEvent({},t,i):keyUpEvent({},t,i)}function bindKey(t,e,i,n){void 0===n&&(n=preventDefault),_keyBindings[t]=e,_preventDefaultForKeys[t]=n,_keyStatus[e]=0,_keyLock[e]=i||!1,_keyLocked[e]=!1,_keyRefs[e]={}}function getBindingKey(t){return _keyBindings[t]}function unlockKey(t){_keyLocked[t]=!1}function unbindKey(t){var e=_keyBindings[t];_keyStatus[e]=0,_keyLock[e]=!1,_keyRefs[e]={},_keyBindings[t]=null,_preventDefaultForKeys[t]=null}var viewportOffset=new Vector2d,Pointer=Rect.extend({init:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=1),void 0===n&&(n=1),this.LEFT=0,this.MIDDLE=1,this.RIGHT=2,this.event=void 0,this.type=void 0,this.button=0,this.isPrimary=!1,this.pageX=0,this.pageY=0,this.clientX=0,this.clientY=0,this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0,this.gameX=0,this.gameY=0,this.gameScreenX=0,this.gameScreenY=0,this.gameWorldX=0,this.gameWorldY=0,this.gameLocalX=0,this.gameLocalY=0,this.pointerId=void 0,this.bind=[0,0,0],this._super(Rect,"init",[t,e,i,n])},setEvent:function(t,e,i,n,r,o){void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),void 0===r&&(r=0),void 0===o&&(o=1);var s=1,a=1;this.event=t,this.pageX=e,this.pageY=i,this.clientX=n,this.clientY=r,globalToLocal(this.pageX,this.pageY,this.pos),this.isNormalized=!device$1.PointerEvent||device$1.PointerEvent&&!(t instanceof window.PointerEvent),"wheel"===t.type?(this.deltaMode=t.deltaMode||0,this.deltaX=t.deltaX||0,this.deltaY=t.deltaY||0,this.deltaZ=t.deltaZ||0):(this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0),this.pointerId=o,this.isPrimary=void 0===t.isPrimary||t.isPrimary,this.button=t.button||0,this.type=t.type,this.gameScreenX=this.pos.x,this.gameScreenY=this.pos.y,void 0!==game$1.viewport&&game$1.viewport.localToWorld(this.gameScreenX,this.gameScreenY,viewportOffset),this.gameWorldX=viewportOffset.x,this.gameWorldY=viewportOffset.y,!1===this.isNormalized?(s=t.width||1,a=t.height||1):"number"==typeof t.radiusX&&(s=2*t.radiusX||1,a=2*t.radiusY||1),this.resize(s,a)}}),T_POINTERS=[],eventHandlers=new Map,currentPointer,pointerInitialized=!1,lastTimeStamp=0,activeEventList=[],WHEEL=["wheel"],POINTER_MOVE=["pointermove","mousemove","touchmove"],POINTER_DOWN=["pointerdown","mousedown","touchstart"],POINTER_UP=["pointerup","mouseup","touchend"],POINTER_CANCEL=["pointercancel","mousecancel","touchcancel"],POINTER_ENTER=["pointerenter","mouseenter","touchenter"],POINTER_OVER=["pointerover","mouseover","touchover"],POINTER_LEAVE=["pointerleave","mouseleave","touchleave"],pointerEventList=[WHEEL[0],POINTER_MOVE[0],POINTER_DOWN[0],POINTER_UP[0],POINTER_CANCEL[0],POINTER_ENTER[0],POINTER_OVER[0],POINTER_LEAVE[0]],mouseEventList=[WHEEL[0],POINTER_MOVE[1],POINTER_DOWN[1],POINTER_UP[1],POINTER_CANCEL[1],POINTER_ENTER[1],POINTER_OVER[1],POINTER_LEAVE[1]],touchEventList=[POINTER_MOVE[2],POINTER_DOWN[2],POINTER_UP[2],POINTER_CANCEL[2],POINTER_ENTER[2],POINTER_OVER[2],POINTER_LEAVE[2]],pointerEventMap={wheel:WHEEL,pointermove:POINTER_MOVE,pointerdown:POINTER_DOWN,pointerup:POINTER_UP,pointercancel:POINTER_CANCEL,pointerenter:POINTER_ENTER,pointerover:POINTER_OVER,pointerleave:POINTER_LEAVE},normalizedEvents=[];function registerEventListener(t,e){for(var i=0;i<t.length;i++)-1===POINTER_MOVE.indexOf(t[i])&&pointerEventTarget.addEventListener(t[i],e,{passive:!1===preventDefault})}function enablePointerEvent(){if(!pointerInitialized){currentPointer=new Rect(0,0,1,1),pointer=new Pointer(0,0,1,1);for(var t=0;t<device$1.maxTouchPoints;t++)T_POINTERS.push(new Pointer);var e;null===pointerEventTarget&&(pointerEventTarget=video$1.renderer.getScreenCanvas()),activeEventList=device$1.PointerEvent?pointerEventList:mouseEventList,device$1.touch&&!device$1.PointerEvent&&(activeEventList=activeEventList.concat(touchEventList)),registerEventListener(activeEventList,onPointerEvent),void 0===throttlingInterval&&(throttlingInterval=~~(1e3/timer$1.maxfps)),!0===device$1.autoFocus&&(device$1.focus(),pointerEventTarget.addEventListener(activeEventList[2],(function(){device$1.focus()}),{passive:!1===preventDefault}));var i=findAllActiveEvents(activeEventList,POINTER_MOVE);if(throttlingInterval<17)for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],onMoveEvent,{passive:!0});else for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],utils$1.function.throttle(onMoveEvent,throttlingInterval,!1),{passive:!0});setTouchAction(pointerEventTarget),pointerInitialized=!0}}function findActiveEvent(t,e){for(var i=0;i<e.length;i++){if(-1!==t.indexOf(e[i]))return e[i]}}function findAllActiveEvents(t,e){for(var i=[],n=0;n<e.length;n++){-1!==t.indexOf(e[n])&&i.push(e[n])}return i}function triggerEvent(t,e,i,n){var r;if(t.callbacks[e]){t.pointerId=n;for(var o=t.callbacks[e].length-1;o>=0&&(r=t.callbacks[e][o]);o--)if(!1===r(i))return!0}return!1}function dispatchEvent(t){for(var e=!1;t.length>0;){var i=t.pop();if(T_POINTERS.push(i),void 0!==i.event.timeStamp){if(i.event.timeStamp<lastTimeStamp)continue;lastTimeStamp=i.event.timeStamp}currentPointer.setShape(i.gameWorldX,i.gameWorldY,i.width,i.height),POINTER_MOVE.includes(i.type)&&(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY,event.publish(event.POINTERMOVE,[i]));for(var n,r=game$1.world.broadphase.retrieve(currentPointer,Container$1.prototype._sortReverseZ),o=(r=r.concat([game$1.viewport])).length;n=r[--o];){if(eventHandlers.has(n)&&!0!==n.isKinematic){var s=eventHandlers.get(n),a=s.region,h=a.ancestor,l=a.getBounds(),u=!1;if(!0===a.floating?(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY):(i.gameX=i.gameLocalX=i.gameWorldX,i.gameY=i.gameLocalY=i.gameWorldY),void 0!==h){var c=h.getBounds();i.gameLocalX=i.gameX-c.x,i.gameLocalY=i.gameY-c.y}if(a instanceof Renderable){var d=i.gameX,p=i.gameY;if(!a.currentTransform.isIdentity()){var f=a.currentTransform.applyInverse(pool.pull("Vector2d",d,p));d=f.x,p=f.y,pool.push(f)}u=l.contains(d,p)}else u=l.contains(i.gameX,i.gameY)&&(l===a||a.contains(i.gameLocalX,i.gameLocalY));switch(i.type){case POINTER_MOVE[0]:case POINTER_MOVE[1]:case POINTER_MOVE[2]:case POINTER_MOVE[3]:if(s.pointerId!==i.pointerId||u){if(null===s.pointerId&&u&&triggerEvent(s,findActiveEvent(activeEventList,POINTER_ENTER),i,i.pointerId)){e=!0;break}}else if(triggerEvent(s,findActiveEvent(activeEventList,POINTER_LEAVE),i,null)){e=!0;break}if(u&&triggerEvent(s,i.type,i,i.pointerId)){e=!0;break}break;case POINTER_UP[0]:case POINTER_UP[1]:case POINTER_UP[2]:case POINTER_UP[3]:if(s.pointerId===i.pointerId&&u&&triggerEvent(s,i.type,i,null)){e=!0;break}break;case POINTER_CANCEL[0]:case POINTER_CANCEL[1]:case POINTER_CANCEL[2]:case POINTER_CANCEL[3]:if(s.pointerId===i.pointerId&&triggerEvent(s,i.type,i,null)){e=!0;break}break;default:if(u&&triggerEvent(s,i.type,i,i.pointerId)){e=!0;break}}}if(!0===e)break}}return e}function normalizeEvent(t){var e;if(device$1.TouchEvent&&t.changedTouches)for(var i=0,n=t.changedTouches.length;i<n;i++){var r=t.changedTouches[i];(e=T_POINTERS.pop()).setEvent(t,r.pageX,r.pageY,r.clientX,r.clientY,r.identifier),normalizedEvents.push(e)}else(e=T_POINTERS.pop()).setEvent(t,t.pageX,t.pageY,t.clientX,t.clientY,t.pointerId),normalizedEvents.push(e);return!1===t.isPrimary||(normalizedEvents[0].isPrimary=!0,Object.assign(e,normalizedEvents[0])),normalizedEvents}function onMoveEvent(t){dispatchEvent(normalizeEvent(t))}function onPointerEvent(t){normalizeEvent(t);var e=normalizedEvents[0].button;(dispatchEvent(normalizedEvents)||"wheel"===t.type)&&t.preventDefault();var i=pointer.bind[e];i&&triggerKeyEvent(i,POINTER_DOWN.includes(t.type),e+1)}var pointerEventTarget=null,pointer,throttlingInterval;function globalToLocal(t,e,i){i=i||new Vector2d;var n=device$1.getElementBounds(video$1.renderer.getScreenCanvas()),r=device$1.devicePixelRatio;t-=n.left+(window.pageXOffset||0),e-=n.top+(window.pageYOffset||0);var o=video$1.scaleRatio;return 1===o.x&&1===o.y||(t/=o.x,e/=o.y),i.set(t*r,e*r)}function setTouchAction(t,e){t.style["touch-action"]=e||"none"}function bindPointer(){var t=arguments.length<2?pointer.LEFT:arguments[0],e=arguments.length<2?arguments[0]:arguments[1];if(enablePointerEvent(),!getBindingKey(e))throw new Error("no action defined for keycode "+e);pointer.bind[t]=e}function unbindPointer(t){pointer.bind[void 0===t?pointer.LEFT:t]=null}function registerPointerEvent(t,e,i){if(enablePointerEvent(),-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);if(void 0===e)throw new Error("registerPointerEvent: region for "+toString(e)+" event is undefined ");var n=findAllActiveEvents(activeEventList,pointerEventMap[t]);eventHandlers.has(e)||eventHandlers.set(e,{region:e,callbacks:{},pointerId:null});for(var r=eventHandlers.get(e),o=0;o<n.length;o++)t=n[o],r.callbacks[t]?r.callbacks[t].push(i):r.callbacks[t]=[i]}function releasePointerEvent(t,e,i){if(-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);var n=findAllActiveEvents(activeEventList,pointerEventMap[t]),r=eventHandlers.get(e);if(void 0!==r){for(var o=0;o<n.length;o++)if(t=n[o],r.callbacks[t]){if(void 0!==i)utils$1.array.remove(r.callbacks[t],i);else for(;r.callbacks[t].length>0;)r.callbacks[t].pop();0===r.callbacks[t].length&&delete r.callbacks[t]}0===Object.keys(r.callbacks).length&&eventHandlers.delete(e)}}function releaseAllPointerEvents(t){if(eventHandlers.has(t))for(var e=0;e<pointerEventList.length;e++)this.releasePointerEvent(pointerEventList[e],t)}var deadzone=.1;function defaultNormalizeFn(t){return t}function wiredXbox360NormalizeFn(t,e,i){return i===this.GAMEPAD.BUTTONS.L2||i===this.GAMEPAD.BUTTONS.R2?(t+1)/2:t}function ouyaNormalizeFn(t,e,i){return t=t>0?i===this.GAMEPAD.BUTTONS.L2?Math.max(0,t-2e4)/111070:(t-1)/131070:(65536+t)/131070+.5}var vendorProductRE=/^([0-9a-f]{1,4})-([0-9a-f]{1,4})-/i,leadingZeroRE=/^0+/;function addMapping(t,e){var i=t.replace(vendorProductRE,(function(t,e,i){return"000".substr(e.length-1)+e+"-"+"000".substr(i.length-1)+i+"-"})),n=t.replace(vendorProductRE,(function(t,e,i){return e.replace(leadingZeroRE,"")+"-"+i.replace(leadingZeroRE,"")+"-"}));e.analog=e.analog||e.buttons.map((function(){return-1})),e.normalize_fn=e.normalize_fn||defaultNormalizeFn,remap.set(i,e),remap.set(n,e)}var bindings={},remap=new Map,updateEventHandler;[["45e-28e-Xbox 360 Wired Controller",{axes:[0,1,3,4],buttons:[11,12,13,14,8,9,-1,-1,5,4,6,7,0,1,2,3,10],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:wiredXbox360NormalizeFn}],["54c-268-PLAYSTATION(R)3 Controller",{axes:[0,1,2,3],buttons:[14,13,15,12,10,11,8,9,0,3,1,2,4,6,7,5,16]}],["54c-5c4-Wireless Controller",{axes:[0,1,2,3],buttons:[1,0,2,3,4,5,6,7,8,9,10,11,14,15,16,17,12,13]}],["2836-1-OUYA Game Controller",{axes:[0,3,7,9],buttons:[3,6,4,5,7,8,15,16,-1,-1,9,10,11,12,13,14,-1],analog:[-1,-1,-1,-1,-1,-1,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}],["OUYA Game Controller (Vendor: 2836 Product: 0001)",{axes:[0,1,3,4],buttons:[0,3,1,2,4,5,12,13,-1,-1,6,7,8,9,10,11,-1],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}]].forEach((function(t){addMapping(t[0],t[1])}));var updateGamepads=function(){var t=navigator.getGamepads();Object.keys(bindings).forEach((function(e){var i=t[e];if(i){var n=null;"standard"!==i.mapping&&(n=remap.get(i.id));var r=bindings[e];Object.keys(r.buttons).forEach((function(t){var o=r.buttons[t],s=t,a=-1;if(!(n&&(s=n.buttons[t],a=n.analog[t],s<0&&a<0))){var h=i.buttons[s]||{};if(n&&a>=0){var l=n.normalize_fn(i.axes[a],-1,+t);h={value:l,pressed:h.pressed||Math.abs(l)>=deadzone}}event.publish(event.GAMEPAD_UPDATE,[e,"buttons",+t,h]),!o.pressed&&h.pressed?triggerKeyEvent(o.keyCode,!0,s+256):o.pressed&&!h.pressed&&triggerKeyEvent(o.keyCode,!1,s+256),o.value=h.value,o.pressed=h.pressed}})),Object.keys(r.axes).forEach((function(t){var o=r.axes[t],s=t;if(!(n&&(s=n.axes[t])<0)){var a=i.axes[s];if(void 0!==a){n&&(a=n.normalize_fn(a,+t,-1));var h=Math.sign(a)||1;if(0!==o[h].keyCode){var l=Math.abs(a)>=deadzone+Math.abs(o[h].threshold);event.publish(event.GAMEPAD_UPDATE,[e,"axes",+t,a]),!o[h].pressed&&l?(o[-h].pressed&&(triggerKeyEvent(o[-h].keyCode,!1,s+256),o[-h].value=0,o[-h].pressed=!1),triggerKeyEvent(o[h].keyCode,!0,s+256)):!o[h].pressed&&!o[-h].pressed||l||triggerKeyEvent(o[h=o[h].pressed?h:-h].keyCode,!1,s+256),o[h].value=a,o[h].pressed=l}}}}))}}))};window.addEventListener("gamepadconnected",(function(t){event.publish(event.GAMEPAD_CONNECTED,[t.gamepad])}),!1),window.addEventListener("gamepaddisconnected",(function(t){event.publish(event.GAMEPAD_DISCONNECTED,[t.gamepad])}),!1);var GAMEPAD={AXES:{LX:0,LY:1,RX:2,RY:3,EXTRA_1:4,EXTRA_2:5,EXTRA_3:6,EXTRA_4:7},BUTTONS:{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L1:4,R1:5,L2:6,R2:7,SELECT:8,BACK:8,START:9,FORWARD:9,L3:10,R3:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,HOME:16,EXTRA_1:17,EXTRA_2:18,EXTRA_3:19,EXTRA_4:20}};function bindGamepad(t,e,i){if(!getBindingKey(i))throw new Error("no action defined for keycode "+i);void 0===updateEventHandler&&"function"==typeof navigator.getGamepads&&(updateEventHandler=event.subscribe(event.GAME_UPDATE,updateGamepads)),bindings[t]||(bindings[t]={axes:{},buttons:{}});var n={keyCode:i,value:0,pressed:!1,threshold:e.threshold},r=bindings[t][e.type];if("buttons"===e.type)r[e.code]=n;else if("axes"===e.type){var o=Math.sign(e.threshold)||1;r[e.code]||(r[e.code]={});var s=r[e.code];s[o]=n,s[-o]||(s[-o]={keyCode:0,value:0,pressed:!1,threshold:-o})}}function unbindGamepad(t,e){if(!bindings[t])throw new Error("no bindings for gamepad "+t);bindings[t].buttons[e]={}}function setGamepadDeadzone(t){deadzone=t}var setGamepadMapping=addMapping,preventDefault=!0,input=Object.freeze({__proto__:null,preventDefault:preventDefault,get pointerEventTarget(){return pointerEventTarget},get pointer(){return pointer},get throttlingInterval(){return throttlingInterval},globalToLocal:globalToLocal,setTouchAction:setTouchAction,bindPointer:bindPointer,unbindPointer:unbindPointer,registerPointerEvent:registerPointerEvent,releasePointerEvent:releasePointerEvent,releaseAllPointerEvents:releaseAllPointerEvents,get keyBoardEventTarget(){return keyBoardEventTarget},KEY:KEY,initKeyboardEvent:initKeyboardEvent,isKeyPressed:isKeyPressed,keyStatus:keyStatus,triggerKeyEvent:triggerKeyEvent,bindKey:bindKey,getBindingKey:getBindingKey,unlockKey:unlockKey,unbindKey:unbindKey,GAMEPAD:GAMEPAD,bindGamepad:bindGamepad,unbindGamepad:unbindGamepad,setGamepadDeadzone:setGamepadDeadzone,setGamepadMapping:setGamepadMapping}),Renderable=Rect.extend({init:function(t,e,i,n){this._super(Rect,"init",[t,e,i,n]),this.isRenderable=!0,this.isKinematic=!0,this.body=void 0,void 0===this.currentTransform&&(this.currentTransform=pool.pull("Matrix2d")),this.currentTransform.identity(),this.GUID=void 0,this.onVisibilityChange=void 0,this.alwaysUpdate=!1,this.updateWhenPaused=!1,this.isPersistent=!1,this.floating=!1,this.anchorPoint instanceof ObservableVector2d?this.anchorPoint.setMuted(.5,.5).setCallback(this.onAnchorUpdate,this):this.anchorPoint=pool.pull("ObservableVector2d",.5,.5,{onUpdate:this.onAnchorUpdate,scope:this}),this.autoTransform=!0,this.alpha=1,this.ancestor=void 0,this.mask=void 0,this.tint=pool.pull("Color",255,255,255,1),this.name="",this.pos instanceof ObservableVector3d?this.pos.setMuted(t,e,0).setCallback(this.updateBoundsPos,this):this.pos=pool.pull("ObservableVector3d",t,e,0,{onUpdate:this.updateBoundsPos,scope:this}),this.isDirty=!1,this._flip={x:!1,y:!1},this._inViewport=!1,this.setOpacity(1)},onResetEvent:function(){this.init.apply(this,arguments)},getBounds:function(){return void 0===this._bounds&&(this._super(Rect,"getBounds"),this.isFinite()?this._bounds.setMinMax(this.pos.x,this.pos.y,this.pos.x+this.width,this.pos.y+this.height):this._bounds.setMinMax(this.pos.x,this.pos.y,this.width,this.height)),this._bounds},getOpacity:function(){return this.alpha},setOpacity:function(t){"number"==typeof t&&(this.alpha=clamp(t,0,1),isNaN(this.alpha)&&(this.alpha=1))},flipX:function(t){return this._flip.x=!!t,this.isDirty=!0,this},flipY:function(t){return this._flip.y=!!t,this.isDirty=!0,this},transform:function(t){return this.currentTransform.multiply(t),this.updateBoundsPos(this.pos.x,this.pos.y),this.isDirty=!0,this},angleTo:function(t){var e,i,n=this.getBounds();if(t instanceof Renderable){var r=t.getBounds();e=r.centerX-n.centerX,i=r.centerY-n.centerY}else e=t.x-n.centerX,i=t.y-n.centerY;return Math.atan2(i,e)},distanceTo:function(t){var e,i,n=this.getBounds();if(t instanceof Renderable){var r=t.getBounds();e=n.centerX-r.centerX,i=n.centerY-r.centerY}else e=n.centerX-t.x,i=n.centerY-t.y;return Math.sqrt(e*e+i*i)},lookAt:function(t){var e;e=t instanceof Renderable?t.pos:t;var i=this.angleTo(e);return this.rotate(i),this},rotate:function(t){return isNaN(t)||(this.currentTransform.rotate(t),this.isDirty=!0),this},scale:function(t,e){return this.currentTransform.scale(t,e),this._super(Rect,"scale",[t,e]),this.isDirty=!0,this},scaleV:function(t){return this.scale(t.x,t.y),this},update:function(){return this.isDirty},updateBounds:function(){return this._super(Rect,"updateBounds"),this.updateBoundsPos(this.pos.x,this.pos.y),this.getBounds()},updateBoundsPos:function(t,e){var i=this.getBounds();i.shift(t,e),void 0!==this.anchorPoint&&i.isFinite()&&i.translate(-this.anchorPoint.x*i.width,-this.anchorPoint.y*i.height),this.ancestor instanceof Container$1&&!0!==this.floating&&i.translate(this.ancestor.getAbsolutePosition())},getAbsolutePosition:function(){return void 0===this._absPos&&(this._absPos=pool.pull("Vector2d")),this._absPos.set(this.pos.x,this.pos.y),this.ancestor instanceof Container$1&&!0!==this.floating&&this._absPos.add(this.ancestor.getAbsolutePosition()),this._absPos},onAnchorUpdate:function(t,e){this.anchorPoint.setMuted(t,e),this.updateBoundsPos(this.pos.x,this.pos.y)},preDraw:function(t){var e=this.getBounds(),i=e.width*this.anchorPoint.x,n=e.height*this.anchorPoint.y;if(t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),this._flip.x||this._flip.y){var r=this._flip.x?this.centerX-i:0,o=this._flip.y?this.centerY-n:0;t.translate(r,o),t.scale(this._flip.x?-1:1,this._flip.y?-1:1),t.translate(-r,-o)}!0!==this.autoTransform||this.currentTransform.isIdentity()||(t.translate(this.pos.x,this.pos.y),t.transform(this.currentTransform),t.translate(-this.pos.x,-this.pos.y)),t.translate(-i,-n),void 0!==this.mask&&t.setMask(this.mask),t.setTint(this.tint)},draw:function(){},postDraw:function(t){void 0!==this.mask&&t.clearMask(),t.clearTint(),this.isDirty=!1,t.restore()},destroy:function(){pool.push(this.currentTransform),this.currentTransform=void 0,pool.push(this.anchorPoint),this.anchorPoint=void 0,pool.push(this.pos),this.pos=void 0,void 0!==this._absPos&&(pool.push(this._absPos),this._absPos=void 0),pool.push(this._bounds),this._bounds=void 0,this.onVisibilityChange=void 0,void 0!==this.mask&&(pool.push(this.mask),this.mask=void 0),void 0!==this.tint&&(pool.push(this.tint),this.tint=void 0),this.ancestor=void 0,void 0!==this.body&&(this.body.destroy.apply(this.body,arguments),this.body=void 0),releaseAllPointerEvents(this),this.onDestroyEvent.apply(this,arguments)},onDestroyEvent:function(){}});Object.defineProperty(Renderable.prototype,"inViewport",{get:function(){return this._inViewport},set:function(t){this._inViewport!==t&&(this._inViewport=t,"function"==typeof this.onVisibilityChange&&this.onVisibilityChange.call(this,t))},configurable:!0}),Object.defineProperty(Renderable.prototype,"isFlippedX",{get:function(){return!0===this._flip.x},configurable:!0}),Object.defineProperty(Renderable.prototype,"isFlippedY",{get:function(){return!0===this._flip.y},configurable:!0});var deferredRemove=function(t,e){this.removeChildNow(t,e)},globalFloatingCounter=0,Container=Renderable.extend({init:function(t,e,i,n,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=game$1.viewport.width),void 0===n&&(n=game$1.viewport.height),void 0===r&&(r=!1),this.pendingSort=null,this._super(Renderable,"init",[t,e,i,n]),this.root=r,this.children=void 0,this.sortOn=game$1.sortOn,this.autoSort=!0,this.autoDepth=!0,this.clipping=!1,this.onChildChange=function(){},this.enableChildBoundsUpdate=!1,this.drawCount=0,this.autoTransform=!0,this.isKinematic=!1,this.anchorPoint.set(0,0),!0===this.root&&event.subscribe(event.CANVAS_ONRESIZE,this.updateBounds.bind(this,!0))},reset:function(){this.pendingSort&&(clearTimeout(this.pendingSort),this.pendingSort=null);for(var t,e=this.getChildren(),i=e.length;i>=0;t=e[--i])t&&!0!==t.isPersistent&&this.removeChildNow(t);void 0!==this.currentTransform&&this.currentTransform.identity()},addChild:function(t,e){return t.ancestor instanceof Container?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils$1.createGUID(t.id)),t.ancestor=this,this.getChildren().push(t),void 0!==t.pos&&("number"==typeof e?t.pos.z=e:!0===this.autoDepth&&(t.pos.z=this.getChildren().length)),!0===this.autoSort&&this.sort(),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,this.getChildren().length-1),t},addChildAt:function(t,e){if(e>=0&&e<this.getChildren().length)return t.ancestor instanceof Container?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils$1.createGUID()),t.ancestor=this,this.getChildren().splice(e,0,t),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,e),t;throw new Error("Index ("+e+") Out Of Bounds for addChildAt()")},forEach:function(t,e){var i=this,n=0,r=this.getChildren(),o=r.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);n<o;)t.call(i,r[n],n,r),n++},swapChildren:function(t,e){var i=this.getChildIndex(t),n=this.getChildIndex(e);if(-1===i||-1===n)throw new Error(t+" Both the supplied childs must be a child of the caller "+this);var r=t.pos.z;t.pos.z=e.pos.z,e.pos.z=r,this.getChildren()[i]=e,this.getChildren()[n]=t},getChildAt:function(t){if(t>=0&&t<this.getChildren().length)return this.getChildren()[t];throw new Error("Index ("+t+") Out Of Bounds for getChildAt()")},getChildIndex:function(t){return this.getChildren().indexOf(t)},getNextChild:function(t){var e=this.getChildren().indexOf(t)-1;if(e>=0&&e<this.getChildren().length)return this.getChildAt(e)},hasChild:function(t){return this===t.ancestor},getChildByProp:function(t,e){var i=[];return this.forEach((function(n){!function(t,n){var r=t[n];e instanceof RegExp&&"string"==typeof r?e.test(r)&&i.push(t):r===e&&i.push(t)}(n,t),n instanceof Container&&(i=i.concat(n.getChildByProp(t,e)))})),i},getChildByType:function(t){var e=[];return this.forEach((function(i){i instanceof t&&e.push(i),i instanceof Container&&(e=e.concat(i.getChildByType(t)))})),e},getChildByName:function(t){return this.getChildByProp("name",t)},getChildByGUID:function(t){var e=this.getChildByProp("GUID",t);return e.length>0?e[0]:null},getChildren:function(){return void 0===this.children&&(this.children=[]),this.children},updateBounds:function(t){void 0===t&&(t=!1),this._super(Renderable,"updateBounds");var e=this.getBounds();return!0!==t&&!0!==this.enableChildBoundsUpdate||this.forEach((function(t){t.isRenderable&&(t.getBounds().isFinite()&&e.addBounds(t.getBounds()))})),e},isAttachedToRoot:function(){if(!0===this.root)return!0;for(var t=this.ancestor;t;){if(!0===t.root)return!0;t=t.ancestor}return!1},updateBoundsPos:function(t,e){var i=this;return this._super(Renderable,"updateBoundsPos",[t,e]),this.forEach((function(n){n.isRenderable&&n.updateBoundsPos(n.pos.x+t-i.pos.x,n.pos.y+e-i.pos.y)})),this.getBounds()},onActivateEvent:function(){this.forEach((function(t){"function"==typeof t.onActivateEvent&&t.onActivateEvent()}))},removeChild:function(t,e){if(!this.hasChild(t))throw new Error("Child is not mine.");utils$1.function.defer(deferredRemove,this,t,e)},removeChildNow:function(t,e){if(this.hasChild(t)&&this.getChildIndex(t)>=0){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent(),e||("function"==typeof t.destroy&&t.destroy(),pool.push(t));var i=this.getChildIndex(t);i>=0&&(this.getChildren().splice(i,1),t.ancestor=void 0),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,i)}},setChildsProperty:function(t,e,i){this.forEach((function(n){!0===i&&n instanceof Container&&n.setChildsProperty(t,e,i),n[t]=e}))},moveUp:function(t){var e=this.getChildIndex(t);e-1>=0&&this.swapChildren(t,this.getChildAt(e-1))},moveDown:function(t){var e=this.getChildIndex(t);e>=0&&e+1<this.getChildren().length&&this.swapChildren(t,this.getChildAt(e+1))},moveToTop:function(t){var e=this.getChildIndex(t);if(e>0){var i=this.getChildren();i.splice(0,0,i.splice(e,1)[0]),t.pos.z=i[1].pos.z+1}},moveToBottom:function(t){var e=this.getChildIndex(t),i=this.getChildren();e>=0&&e<i.length-1&&(i.splice(i.length-1,0,i.splice(e,1)[0]),t.pos.z=i[i.length-2].pos.z-1)},sort:function(t){this.pendingSort||(!0===t&&this.forEach((function(e){e instanceof Container&&e.sort(t)})),this.pendingSort=utils$1.function.defer((function(t){t.getChildren().sort(t["_sort"+t.sortOn.toUpperCase()]),t.pendingSort=null,game$1.repaint()}),this,this))},onDeactivateEvent:function(){this.forEach((function(t){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent()}))},_sortZ:function(t,e){return e.pos&&t.pos?e.pos.z-t.pos.z:t.pos?-1/0:1/0},_sortReverseZ:function(t,e){return t.pos&&e.pos?t.pos.z-e.pos.z:t.pos?1/0:-1/0},_sortX:function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.x-t.pos.x},_sortY:function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.y-t.pos.y},destroy:function(){this.reset(),this._super(Renderable,"destroy",arguments)},update:function(t){this._super(Renderable,"update",[t]);for(var e,i=!1,n=!1,r=state$1.isPaused(),o=this.getChildren(),s=o.length;s--,e=o[s];)r&&!e.updateWhenPaused||(e.isRenderable?((n=globalFloatingCounter>0||e.floating)&&globalFloatingCounter++,e.inViewport=!1,state$1.current().cameras.forEach((function(t){t.isVisible(e,n)&&(e.inViewport=!0)})),i=(e.inViewport||e.alwaysUpdate)&&e.update(t)||i,globalFloatingCounter>0&&globalFloatingCounter--):i=e.update(t)||i);return i},draw:function(t,e){var i=!1,n=this.getBounds();this.drawCount=0,!1===this.root&&!0===this.clipping&&!0===n.isFinite()&&t.clipRect(n.left,n.top,n.width,n.height),t.translate(this.pos.x,this.pos.y);for(var r,o=this.getChildren(),s=o.length;r=o[--s];)r.isRenderable&&(i=!0===r.floating,(r.inViewport||i)&&(i&&(t.save(),t.resetTransform()),r.preDraw(t),r.draw(t,e),r.postDraw(t),i&&t.restore(),this.drawCount++))}}),Container$1=Container,QT_ARRAY=[];function QT_ARRAY_POP(t,e,i,n){if(QT_ARRAY.length>0){var r=QT_ARRAY.pop();return r.bounds=t,r.max_objects=e||4,r.max_levels=i||4,r.level=n||0,r}return new QuadTree(t,e,i,n)}function QT_ARRAY_PUSH(t){QT_ARRAY.push(t)}var QT_VECTOR=new Vector2d,QuadTree=function(t,e,i,n){this.max_objects=e||4,this.max_levels=i||4,this.level=n||0,this.bounds=t,this.objects=[],this.nodes=[]};QuadTree.prototype.split=function(){var t=this.level+1,e=this.bounds.width/2,i=this.bounds.height/2,n=this.bounds.left,r=this.bounds.top;this.nodes[0]=QT_ARRAY_POP({left:n+e,top:r,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[1]=QT_ARRAY_POP({left:n,top:r,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[2]=QT_ARRAY_POP({left:n,top:r+i,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[3]=QT_ARRAY_POP({left:n+e,top:r+i,width:e,height:i},this.max_objects,this.max_levels,t)},QuadTree.prototype.getIndex=function(t){var e,i=-1,n=(e=t.floating||t.ancestor&&t.ancestor.floating?game$1.viewport.localToWorld(t.left,t.top,QT_VECTOR):QT_VECTOR.set(t.left,t.top)).x,r=e.y,o=t.width,s=t.height,a=this.bounds.left+this.bounds.width/2,h=this.bounds.top+this.bounds.height/2,l=r<h&&r+s<h,u=r>h;return n<a&&n+o<a?l?i=1:u&&(i=2):n>a&&(l?i=0:u&&(i=3)),i},QuadTree.prototype.insertContainer=function(t){for(var e,i=t.children.length;i--,e=t.children[i];)!0!==e.isKinematic&&(e instanceof Container$1?("rootContainer"!==e.name&&this.insert(e),this.insertContainer(e)):"function"==typeof e.getBounds&&this.insert(e))},QuadTree.prototype.insert=function(t){var e=-1;if(this.nodes.length>0&&-1!==(e=this.getIndex(t)))this.nodes[e].insert(t);else if(this.objects.push(t),this.objects.length>this.max_objects&&this.level<this.max_levels){0===this.nodes.length&&this.split();for(var i=0;i<this.objects.length;)-1!==(e=this.getIndex(this.objects[i]))?this.nodes[e].insert(this.objects.splice(i,1)[0]):i+=1}},QuadTree.prototype.retrieve=function(t,e){var i=this.objects;if(this.nodes.length>0){var n=this.getIndex(t);if(-1!==n)i=i.concat(this.nodes[n].retrieve(t));else for(var r=0;r<this.nodes.length;r+=1)i=i.concat(this.nodes[r].retrieve(t))}return"function"==typeof e&&i.sort(e),i},QuadTree.prototype.remove=function(t){var e=!1;if(void 0===t.getBounds)return!1;if(this.nodes.length>0){var i=this.getIndex(t);-1!==i&&(e=utils$1.array.remove(this.nodes[i],t))&&this.nodes[i].isPrunable()&&this.nodes.splice(i,1)}return!1===e&&-1!==this.objects.indexOf(t)&&(utils$1.array.remove(this.objects,t),e=!0),e},QuadTree.prototype.isPrunable=function(){return!(this.hasChildren()||this.objects.length>0)},QuadTree.prototype.hasChildren=function(){for(var t=0;t<this.nodes.length;t+=1){var e=this.nodes[t];if(e.length>0||e.objects.length>0)return!0}return!1},QuadTree.prototype.clear=function(t){this.objects.length=0;for(var e=0;e<this.nodes.length;e++)this.nodes[e].clear(),QT_ARRAY_PUSH(this.nodes[e]);this.nodes.length=0,void 0!==t&&this.bounds.setMinMax(t.min.x,t.min.y,t.max.x,t.max.y)};for(var LEFT_VORNOI_REGION=-1,MIDDLE_VORNOI_REGION=0,RIGHT_VORNOI_REGION=1,T_VECTORS=[],v=0;v<10;v++)T_VECTORS.push(new Vector2d);for(var T_ARRAYS=[],a=0;a<5;a++)T_ARRAYS.push([]);function flattenPointsOn(t,e,i){for(var n=Number.MAX_VALUE,r=-Number.MAX_VALUE,o=t.length,s=0;s<o;s++){var a=t[s].dotProduct(e);a<n&&(n=a),a>r&&(r=a)}i[0]=n,i[1]=r}function isSeparatingAxis(t,e,i,n,r,o){var s=T_ARRAYS.pop(),a=T_ARRAYS.pop(),h=T_VECTORS.pop().copy(e).sub(t),l=h.dotProduct(r);if(flattenPointsOn(i,r,s),flattenPointsOn(n,r,a),a[0]+=l,a[1]+=l,s[0]>a[1]||a[0]>s[1])return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!0;if(o){var u=0;if(s[0]<a[0])if(o.aInB=!1,s[1]<a[1])u=s[1]-a[0],o.bInA=!1;else{var c=s[1]-a[0],d=a[1]-s[0];u=c<d?c:-d}else if(o.bInA=!1,s[1]>a[1])u=s[0]-a[1],o.aInB=!1;else{var p=s[1]-a[0],f=a[1]-s[0];u=p<f?p:-f}var g=Math.abs(u);g<o.overlap&&(o.overlap=g,o.overlapN.copy(r),u<0&&o.overlapN.negateSelf())}return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!1}function vornoiRegion(t,e){var i=t.length2(),n=e.dotProduct(t);return n<0?LEFT_VORNOI_REGION:n>i?RIGHT_VORNOI_REGION:MIDDLE_VORNOI_REGION}function testPolygonPolygon(t,e,i,n,r){var o,s=e.points,a=e.normals,h=a.length,l=n.points,u=n.normals,c=u.length,d=T_VECTORS.pop().copy(t.pos).add(t.ancestor.getAbsolutePosition()).add(e.pos),p=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos);for(o=0;o<h;o++)if(isSeparatingAxis(d,p,s,l,a[o],r))return T_VECTORS.push(d),T_VECTORS.push(p),!1;for(o=0;o<c;o++)if(isSeparatingAxis(d,p,s,l,u[o],r))return T_VECTORS.push(d),T_VECTORS.push(p),!1;return r&&(r.a=t,r.b=i,r.overlapV.copy(r.overlapN).scale(r.overlap)),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipseEllipse(t,e,i,n,r){var o=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=e.radius,a=n.radius,h=s+a,l=h*h,u=o.length2();if(u>l)return T_VECTORS.push(o),!1;if(r){var c=Math.sqrt(u);r.a=t,r.b=i,r.overlap=h-c,r.overlapN.copy(o.normalize()),r.overlapV.copy(o).scale(r.overlap),r.aInB=s<=a&&c<=a-s,r.bInA=a<=s&&c<=s-a}return T_VECTORS.push(o),!0}function testPolygonEllipse(t,e,i,n,r){for(var o=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=n.radius,a=s*s,h=e.points,l=e.edges,u=l.length,c=T_VECTORS.pop(),d=T_VECTORS.pop(),p=T_VECTORS.pop(),f=0,g=0;g<u;g++){var m=g===u-1?0:g+1,y=0===g?u-1:g-1,v=0,_=null;c.copy(l[g]),p.copy(o).sub(h[g]),r&&p.length2()>a&&(r.aInB=!1);var x=vornoiRegion(c,p),w=!0;if(x===LEFT_VORNOI_REGION){var b=null;if(u>1&&(c.copy(l[y]),(x=vornoiRegion(c,b=T_VECTORS.pop().copy(o).sub(h[y])))!==RIGHT_VORNOI_REGION&&(w=!1)),w){if((f=p.length())>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),b&&T_VECTORS.push(b),!1;r&&(r.bInA=!1,_=p.normalize(),v=s-f)}b&&T_VECTORS.push(b)}else if(x===RIGHT_VORNOI_REGION){if(u>1&&(c.copy(l[m]),p.copy(o).sub(h[m]),(x=vornoiRegion(c,p))!==LEFT_VORNOI_REGION&&(w=!1)),w){if((f=p.length())>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!1;r&&(r.bInA=!1,_=p.normalize(),v=s-f)}}else{d.copy(e.normals[g]),f=p.dotProduct(d);var T=Math.abs(f);if((1===u||f>0)&&T>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!1;r&&(_=d,v=s-f,(f>=0||v<2*s)&&(r.bInA=!1))}_&&r&&Math.abs(v)<Math.abs(r.overlap)&&(r.overlap=v,r.overlapN.copy(_))}return r&&(r.a=t,r.b=i,r.overlapV.copy(r.overlapN).scale(r.overlap)),T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipsePolygon(t,e,i,n,r){var o=this.testPolygonEllipse(i,n,t,e,r);if(o&&r){var s=r.a,a=r.aInB;r.overlapN.negateSelf(),r.overlapV.negateSelf(),r.a=r.b,r.b=s,r.aInB=r.bInA,r.bInA=a}return o}var SAT=Object.freeze({__proto__:null,testPolygonPolygon:testPolygonPolygon,testEllipseEllipse:testEllipseEllipse,testPolygonEllipse:testPolygonEllipse,testEllipsePolygon:testEllipsePolygon}),dummyObj={pos:new Vector2d(0,0),ancestor:{_absPos:new Vector2d(0,0),getAbsolutePosition:function(){return this._absPos}}},ResponseObject=function(){return this.a=null,this.b=null,this.overlapN=new Vector2d,this.overlapV=new Vector2d,this.aInB=!0,this.bInA=!0,this.indexShapeA=-1,this.indexShapeB=-1,this.overlap=Number.MAX_VALUE,this};ResponseObject.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this.indexShapeA=-1,this.indexShapeB=-1,this};var collision={maxChildren:8,maxDepth:4,types:{NO_OBJECT:0,PLAYER_OBJECT:1,NPC_OBJECT:2,ENEMY_OBJECT:4,COLLECTABLE_OBJECT:8,ACTION_OBJECT:16,PROJECTILE_OBJECT:32,WORLD_SHAPE:64,USER:128,ALL_OBJECT:4294967295},response:new ResponseObject,shouldCollide:function(t,e){return!0!==t.isKinematic&&!0!==e.isKinematic&&t.body&&e.body&&0!=(t.body.collisionMask&e.body.collisionType)&&0!=(t.body.collisionType&e.body.collisionMask)},check:function(t,e){for(var i,n=0,r=e||this.response,o=game$1.world.broadphase.retrieve(t),s=o.length;i=o[--s];)if(i!==t&&this.shouldCollide(t,i)&&t.body.getBounds().overlaps(i.body.getBounds())){var a=t.body.shapes.length,h=i.body.shapes.length;if(0===a||0===h)continue;var l=0;do{var u=t.body.getShape(l),c=0;do{var d=i.body.getShape(c);!0===SAT["test"+u.shapeType+d.shapeType].call(this,t,u,i,d,r.clear())&&(n++,r.indexShapeA=l,r.indexShapeB=c,t.onCollision&&!1!==t.onCollision(r,i)&&t.body.respondToCollision.call(t.body,r),i.onCollision&&!1!==i.onCollision(r,t)&&i.body.respondToCollision.call(i.body,r)),c++}while(c<h);l++}while(l<a)}return n>0},rayCast:function(t,e){for(var i,n=0,r=e||[],o=game$1.world.broadphase.retrieve(t),s=o.length;i=o[--s];)if(i.body&&t.getBounds().overlaps(i.getBounds())){var a=i.body.shapes.length;if(0===i.body.shapes.length)continue;var h=t,l=0;do{var u=i.body.getShape(l);SAT["test"+h.shapeType+u.shapeType].call(this,dummyObj,h,i,u)&&(r[n]=i,n++),l++}while(l<a)}return r.length=n,r}},World=Container$1.extend({init:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=1/0),void 0===n&&(n=1/0),this._super(Container$1,"init",[t,e,i,n,!0]),this.name="rootContainer",this.anchorPoint.set(0,0),this.fps=60,this.gravity=new Vector2d(0,.98),this.preRender=!1,this.broadphase=new QuadTree(this.getBounds().clone(),collision.maxChildren,collision.maxDepth),event.subscribe(event.GAME_RESET,this.reset.bind(this)),event.subscribe(event.LEVEL_LOADED,(function(){game$1.world.broadphase.clear(game$1.world.getBounds())}))},reset:function(){this.broadphase.clear(),this.anchorPoint.set(0,0),this._super(Container$1,"reset")},update:function(t){return this.broadphase.clear(),this.broadphase.insertContainer(this),this._super(Container$1,"update",[t])}}),isDirty=!0,isAlwaysDirty=!1,frameCounter=0,frameRate=1,accumulator=0,accumulatorMax=0,accumulatorUpdateDelta=0,stepSize=1e3/60,updateDelta=0,lastUpdateStart=null,updateAverageDelta=0,game={viewport:void 0,world:null,mergeGroup:!0,sortOn:"z",onLevelLoaded:function(){},init:function(){this.world=new World,event.publish(event.GAME_INIT),isDirty=!0},reset:function(){void 0!==state$1.current()&&(this.viewport=state$1.current().cameras.get("default")),event.publish(event.GAME_RESET),this.updateFrameRate()},updateFrameRate:function(){frameCounter=0,frameRate=~~(.5+60/timer$1.maxfps),stepSize=1e3/this.world.fps,accumulator=0,accumulatorMax=10*stepSize,isAlwaysDirty=timer$1.maxfps>this.world.fps},getParentContainer:function(t){return t.ancestor},repaint:function(){isDirty=!0},update:function(t,e){if(++frameCounter%frameRate==0)for(frameCounter=0,event.publish(event.GAME_UPDATE,[t]),accumulator+=timer$1.getDelta(),accumulator=Math.min(accumulator,accumulatorMax),updateDelta=timer$1.interpolation?timer$1.getDelta():stepSize,accumulatorUpdateDelta=timer$1.interpolation?updateDelta:Math.max(updateDelta,updateAverageDelta);accumulator>=accumulatorUpdateDelta||timer$1.interpolation;)if(lastUpdateStart=window.performance.now(),isDirty=e.update(updateDelta)||isDirty,timer$1.lastUpdate=window.performance.now(),updateAverageDelta=timer$1.lastUpdate-lastUpdateStart,accumulator-=accumulatorUpdateDelta,timer$1.interpolation){accumulator=0;break}},draw:function(t){var e=video$1.renderer;!0===e.isContextValid&&(isDirty||isAlwaysDirty)&&(e.clear(),t.draw(e),isDirty=!1,e.flush())}},game$1=game,MIN=Math.min,MAX=Math.max,targetV=new Vector2d,Camera2d=Renderable.extend({init:function(t,e,i,n){this._super(Renderable,"init",[t,e,i-t,n-e]),this.AXIS={NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},this.bounds=pool.pull("Bounds"),this.smoothFollow=!0,this.damping=1,this.near=-1e3,this.far=1e3,this.projectionMatrix=new Matrix3d,this.invCurrentTransform=new Matrix2d,this.offset=new Vector2d,this.target=null,this.follow_axis=this.AXIS.NONE,this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null},this._fadeOut={color:null,tween:null},this._fadeIn={color:null,tween:null},this.name="default",this.setDeadzone(this.width/6,this.height/6),this.anchorPoint.set(0,0),this.isKinematic=!1,this.bounds.setMinMax(t,e,i,n),this._updateProjectionMatrix(),event.subscribe(event.GAME_RESET,this.reset.bind(this)),event.subscribe(event.CANVAS_ONRESIZE,this.resize.bind(this))},_updateProjectionMatrix:function(){this.projectionMatrix.ortho(0,this.width,this.height,0,this.near,this.far)},_followH:function(t){var e=this.pos.x;return t.x-this.pos.x>this.deadzone.right?e=MIN(t.x-this.deadzone.right,this.bounds.width-this.width):t.x-this.pos.x<this.deadzone.pos.x&&(e=MAX(t.x-this.deadzone.pos.x,this.bounds.left)),e},_followV:function(t){var e=this.pos.y;return t.y-this.pos.y>this.deadzone.bottom?e=MIN(t.y-this.deadzone.bottom,this.bounds.height-this.height):t.y-this.pos.y<this.deadzone.pos.y&&(e=MAX(t.y-this.deadzone.pos.y,this.bounds.top)),e},reset:function(t,e){this.pos.x=t||0,this.pos.y=e||0,this.unfollow(),this.smoothFollow=!0,this.damping=1,this.currentTransform.identity(),this.invCurrentTransform.identity().invert(),this._updateProjectionMatrix()},setDeadzone:function(t,e){void 0===this.deadzone&&(this.deadzone=new Rect(0,0,0,0)),this.deadzone.pos.set(~~((this.width-t)/2),~~((this.height-e)/2-.25*e)),this.deadzone.resize(t,e),this.smoothFollow=!1,this.updateTarget(),this.smoothFollow=!0},resize:function(t,e){return this._super(Renderable,"resize",[t,e]),this.smoothFollow=!1,this.setBounds(0,0,t,e),this.setDeadzone(t/6,e/6),this.update(),this.smoothFollow=!0,this._updateProjectionMatrix(),event.publish(event.VIEWPORT_ONRESIZE,[this.width,this.height]),this},setBounds:function(t,e,i,n){this.smoothFollow=!1,this.bounds.setMinMax(t,e,i+t,n+e),this.moveTo(this.pos.x,this.pos.y),this.update(),this.smoothFollow=!0},follow:function(t,e,i){if(t instanceof Renderable)this.target=t.pos;else{if(!(t instanceof Vector2d||t instanceof Vector3d||t instanceof ObservableVector2d||t instanceof ObservableVector3d))throw new Error("invalid target for me.Camera2d.follow");this.target=t}this.follow_axis=void 0===e?this.AXIS.BOTH:e,this.smoothFollow=!1,this.damping="number"!=typeof i?1:clamp(i,0,1),this.updateTarget(),this.smoothFollow=!0},unfollow:function(){this.target=null,this.follow_axis=this.AXIS.NONE},move:function(t,e){this.moveTo(this.pos.x+t,this.pos.y+e)},moveTo:function(t,e){var i=this.pos.x,n=this.pos.y;this.pos.x=clamp(t,this.bounds.left,this.bounds.width),this.pos.y=clamp(e,this.bounds.top,this.bounds.height),i===this.pos.x&&n===this.pos.y||event.publish(event.VIEWPORT_ONCHANGE,[this.pos])},updateTarget:function(){if(this.target){switch(targetV.setV(this.pos),this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:targetV.x=this._followH(this.target);break;case this.AXIS.VERTICAL:targetV.y=this._followV(this.target);break;case this.AXIS.BOTH:targetV.x=this._followH(this.target),targetV.y=this._followV(this.target)}if(!this.pos.equals(targetV)){if(!0===this.smoothFollow&&this.damping<1){if(toBeCloseTo(targetV.x,this.pos.x,2)&&toBeCloseTo(targetV.y,this.pos.y,2))return this.pos.setV(targetV),!1;this.pos.lerp(targetV,this.damping)}else this.pos.setV(targetV);return!0}}return!1},update:function(t){var e=this.updateTarget(t);return this._shake.duration>0&&(this._shake.duration-=t,this._shake.duration<=0?(this._shake.duration=0,this.offset.setZero(),"function"==typeof this._shake.onComplete&&this._shake.onComplete()):(this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.HORIZONTAL||(this.offset.x=(Math.random()-.5)*this._shake.intensity),this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.VERTICAL||(this.offset.y=(Math.random()-.5)*this._shake.intensity)),e=!0),!0===e&&event.publish(event.VIEWPORT_ONCHANGE,[this.pos]),null==this._fadeIn.tween&&null==this._fadeOut.tween||(e=!0),this.currentTransform.isIdentity()?this.invCurrentTransform.identity():this.invCurrentTransform.copy(this.currentTransform).invert(),e},shake:function(t,e,i,n,r){0!==this._shake.duration&&!0!==r||(this._shake.intensity=t,this._shake.duration=e,this._shake.axis=i||this.AXIS.BOTH,this._shake.onComplete="function"==typeof n?n:void 0)},fadeOut:function(t,e,i){void 0===e&&(e=1e3),this._fadeOut.color=pool.pull("Color").copy(t),this._fadeOut.tween=pool.pull("Tween",this._fadeOut.color).to({alpha:0},e).onComplete(i||null),this._fadeOut.tween.isPersistent=!0,this._fadeOut.tween.start()},fadeIn:function(t,e,i){void 0===e&&(e=1e3),this._fadeIn.color=pool.pull("Color").copy(t);var n=this._fadeIn.color.alpha;this._fadeIn.color.alpha=0,this._fadeIn.tween=pool.pull("Tween",this._fadeIn.color).to({alpha:n},e).onComplete(i||null),this._fadeIn.tween.isPersistent=!0,this._fadeIn.tween.start()},getWidth:function(){return this.width},getHeight:function(){return this.height},focusOn:function(t){var e=t.getBounds();this.moveTo(t.pos.x+e.left+e.width/2,t.pos.y+e.top+e.height/2)},isVisible:function(t,e){return void 0===e&&(e=t.floating),!0===e||!0===t.floating?video$1.renderer.overlaps(t.getBounds()):t.getBounds().overlaps(this)},localToWorld:function(t,e,i){return(i=i||new Vector2d).set(t,e).add(this.pos).sub(game$1.world.pos),this.currentTransform.isIdentity()||this.invCurrentTransform.apply(i),i},worldToLocal:function(t,e,i){return(i=i||new Vector2d).set(t,e),this.currentTransform.isIdentity()||this.currentTransform.apply(i),i.sub(this.pos).add(game$1.world.pos)},drawFX:function(t){this._fadeIn.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeIn.color),t.fillRect(0,0,this.width,this.height),t.restore(),1===this._fadeIn.color.alpha&&(this._fadeIn.tween=null,pool.push(this._fadeIn.color),this._fadeIn.color=null)),this._fadeOut.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeOut.color),t.fillRect(0,0,this.width,this.height),t.restore(),0===this._fadeOut.color.alpha&&(this._fadeOut.tween=null,pool.push(this._fadeOut.color),this._fadeOut.color=null))},draw:function(t,e){var i=this.pos.x+this.offset.x,n=this.pos.y+this.offset.y;e.currentTransform.translate(-i,-n),t.setProjection(this.projectionMatrix),t.clipRect(0,0,this.width,this.height),this.preDraw(t),e.preDraw(t),e.draw(t,this),this.drawFX(t),e.postDraw(t),this.postDraw(t),e.currentTransform.translate(i,n)}}),default_camera,default_settings={cameras:[]},Stage=window.Jay.extend({init:function(t){this.cameras=new Map,this.settings=Object.assign(default_settings,t||{})},reset:function(){var t=this;if(this.settings.cameras.forEach((function(e){t.cameras.set(e.name,e)})),!1===this.cameras.has("default")){if(void 0===default_camera){var e=video$1.renderer.getWidth(),i=video$1.renderer.getHeight();default_camera=new Camera2d(0,0,e,i)}this.cameras.set("default",default_camera)}game$1.reset(),this.onResetEvent.apply(this,arguments)},update:function(t){var e=game$1.world.update(t);return this.cameras.forEach((function(i){i.update(t)&&(e=!0)})),e},draw:function(t){this.cameras.forEach((function(e){e.draw(t,game$1.world)}))},destroy:function(){this.cameras.clear(),this.onDestroyEvent.apply(this,arguments)},onResetEvent:function(){"function"==typeof this.settings.onResetEvent&&this.settings.onResetEvent.apply(this,arguments)},onDestroyEvent:function(){"function"==typeof this.settings.onDestroyEvent&&this.settings.onDestroyEvent.apply(this,arguments)}}),ProgressBar=Renderable.extend({init:function(t,e,i,n){var r=this;this.barHeight=n,this._super(Renderable,"init",[t,e,i,n]),this.anchorPoint.set(0,0),this.loaderHdlr=event.subscribe(event.LOADER_PROGRESS,r.onProgressUpdate.bind(r)),this.resizeHdlr=event.subscribe(event.VIEWPORT_ONRESIZE,r.resize.bind(r)),this.anchorPoint.set(0,0),this.progress=0},onProgressUpdate:function(t){this.progress=~~(t*this.width),this.isDirty=!0},draw:function(t){t.clearColor("#202020"),t.setColor("black"),t.fillRect(this.pos.x,game$1.viewport.centerY,t.getWidth(),this.barHeight/2),t.setColor("#55aa00"),t.fillRect(this.pos.x,game$1.viewport.centerY,this.progress,this.barHeight/2)},onDestroyEvent:function(){event.unsubscribe(this.loaderHdlr),event.unsubscribe(this.resizeHdlr),this.loaderHdlr=this.resizeHdlr=null}}),IconLogo=Renderable.extend({init:function(t,e){this._super(Renderable,"init",[t,e,100,85]),this.iconCanvas=video$1.createCanvas(nextPowerOfTwo(this.width),nextPowerOfTwo(this.height),!1);var i=video$1.renderer.getContext2d(this.iconCanvas);i.beginPath(),i.moveTo(.7,48.9),i.bezierCurveTo(10.8,68.9,38.4,75.8,62.2,64.5),i.bezierCurveTo(86.1,53.1,97.2,27.7,87,7.7),i.lineTo(87,7.7),i.bezierCurveTo(89.9,15.4,73.9,30.2,50.5,41.4),i.bezierCurveTo(27.1,52.5,5.2,55.8,.7,48.9),i.lineTo(.7,48.9),i.closePath(),i.fillStyle="rgb(255, 255, 255)",i.fill(),i.beginPath(),i.moveTo(84,7),i.bezierCurveTo(87.6,14.7,72.5,30.2,50.2,41.6),i.bezierCurveTo(27.9,53,6.9,55.9,3.2,48.2),i.bezierCurveTo(-.5,40.4,14.6,24.9,36.9,13.5),i.bezierCurveTo(59.2,2.2,80.3,-.8,84,7),i.lineTo(84,7),i.closePath(),i.lineWidth=5.3,i.strokeStyle="rgb(255, 255, 255)",i.lineJoin="miter",i.miterLimit=4,i.stroke(),this.anchorPoint.set(.5,.5)},draw:function(t){t.drawImage(this.iconCanvas,t.getWidth()/2,this.pos.y)}}),TextLogo=Renderable.extend({init:function(t,e){this._super(Renderable,"init",[0,0,t,e]),this.textWidth=0,this.fontCanvas=video$1.createCanvas(256,64,!0),this.drawFont(video$1.renderer.getContext2d(this.fontCanvas)),this.anchorPoint.set(0,.5)},drawFont:function(t){var e=pool.pull("Text",0,0,{font:"century gothic",size:32,fillStyle:"white",textAlign:"middle",textBaseline:"top",text:"melon"}),i=pool.pull("Text",0,0,{font:"century gothic",size:32,fillStyle:"#55aa00",textAlign:"middle",textBaseline:"top",bold:!0,text:"JS"}),n=e.measureText(t).width,r=i.measureText(t).width;this.textWidth=n+r,this.pos.x=Math.round(this.width-this.textWidth/2),this.pos.y=Math.round(this.height+16),e._drawFont(t,["melon"],0,0),i._drawFont(t,["JS"],n,0),pool.push(e),pool.push(i)},draw:function(t){t.drawImage(this.fontCanvas,Math.round((t.getWidth()-this.textWidth)/2),this.pos.y)}}),defaultLoadingScreen=new Stage({onResetEvent:function(){game$1.world.addChild(new ProgressBar(0,video$1.renderer.getHeight()/2,video$1.renderer.getWidth(),8),1),game$1.world.addChild(new IconLogo(video$1.renderer.getWidth()/2,video$1.renderer.getHeight()/2-16-35),2),game$1.world.addChild(new TextLogo(video$1.renderer.getWidth(),video$1.renderer.getHeight()),2)}}),_state=-1,_animFrameId=-1,_isPaused=!1,_stages={},_fade={color:"",duration:0},_onSwitchComplete=null,_extraArgs=null,_pauseTime=0;function _startRunLoop(){-1===_animFrameId&&-1!==_state&&(timer$1.reset(),_animFrameId=window.requestAnimationFrame(_renderFrame))}function _resumeRunLoop(){_isPaused&&-1!==_state&&(timer$1.reset(),_isPaused=!1)}function _pauseRunLoop(){_isPaused=!0}function _renderFrame(t){var e=_stages[_state].stage;game$1.update(t,e),game$1.draw(e),-1!==_animFrameId&&(_animFrameId=window.requestAnimationFrame(_renderFrame))}function _stopRunLoop(){window.cancelAnimationFrame(_animFrameId),_animFrameId=-1}function _switchState(t){_stopRunLoop(),_stages[_state]&&_stages[_state].stage.destroy(),_stages[t]&&(_stages[_state=t].stage.reset.apply(_stages[_state].stage,_extraArgs),_startRunLoop(),_onSwitchComplete&&_onSwitchComplete(),game$1.repaint())}var state={LOADING:0,MENU:1,READY:2,PLAY:3,GAMEOVER:4,GAME_END:5,SCORE:6,CREDITS:7,SETTINGS:8,DEFAULT:9,USER:100,onPause:null,onResume:null,onStop:null,onRestart:null,init:function(){this.set(this.LOADING,defaultLoadingScreen),this.set(this.DEFAULT,new Stage);var t=this;event.subscribe(event.VIDEO_INIT,(function(){t.change(t.DEFAULT,!0)}))},stop:function(t){_state!==this.LOADING&&this.isRunning()&&(_stopRunLoop(),!0===t&&audio$1.pauseTrack(),_pauseTime=window.performance.now(),event.publish(event.STATE_STOP),"function"==typeof this.onStop&&this.onStop())},pause:function(t){_state===this.LOADING||this.isPaused()||(_pauseRunLoop(),!0===t&&audio$1.pauseTrack(),_pauseTime=window.performance.now(),event.publish(event.STATE_PAUSE),"function"==typeof this.onPause&&this.onPause())},restart:function(t){this.isRunning()||(_startRunLoop(),!0===t&&audio$1.resumeTrack(),_pauseTime=window.performance.now()-_pauseTime,game$1.repaint(),event.publish(event.STATE_RESTART,[_pauseTime]),"function"==typeof this.onRestart&&this.onRestart())},resume:function(t){this.isPaused()&&(_resumeRunLoop(),!0===t&&audio$1.resumeTrack(),_pauseTime=window.performance.now()-_pauseTime,event.publish(event.STATE_RESUME,[_pauseTime]),"function"==typeof this.onResume&&this.onResume())},isRunning:function(){return-1!==_animFrameId},isPaused:function(){return _isPaused},set:function(t,e,i){if(!(e instanceof Stage))throw new Error(e+" is not an instance of me.Stage");_stages[t]={},_stages[t].stage=e,_stages[t].transition=!0,!0===i&&this.change(t)},current:function(){if(void 0!==_stages[_state])return _stages[_state].stage},transition:function(t,e,i){"fade"===t&&(_fade.color=e,_fade.duration=i)},setTransition:function(t,e){_stages[t].transition=e},change:function(t,e){if(void 0===_stages[t])throw new Error("Undefined Stage for state '"+t+"'");this.isCurrent(t)||(_extraArgs=null,arguments.length>1&&(_extraArgs=Array.prototype.slice.call(arguments,1)),_fade.duration&&_stages[t].transition?(_onSwitchComplete=function(){game$1.viewport.fadeOut(_fade.color,_fade.duration)},game$1.viewport.fadeIn(_fade.color,_fade.duration,(function(){utils$1.function.defer(_switchState,this,t)}))):!0===e?_switchState(t):utils$1.function.defer(_switchState,this,t))},isCurrent:function(t){return _state===t}},state$1=state,Ellipse=window.Jay.extend({init:function(t,e,i,n){this.pos=new Vector2d,this._bounds=void 0,this.radius=NaN,this.radiusV=new Vector2d,this.radiusSq=new Vector2d,this.ratio=new Vector2d,this.shapeType="Ellipse",this.setShape(t,e,i,n)},onResetEvent:function(t,e,i,n){this.setShape(t,e,i,n)},setShape:function(t,e,i,n){var r=i/2,o=n/2;this.pos.set(t,e),this.radius=Math.max(r,o),this.ratio.set(r/this.radius,o/this.radius),this.radiusV.set(this.radius,this.radius).scaleV(this.ratio);var s=this.radius*this.radius;return this.radiusSq.set(s,s).scaleV(this.ratio),this.getBounds().setMinMax(t,e,t+i,t+n),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},rotate:function(t,e){return this.pos.rotate(t,e),this.getBounds().shift(this.pos),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},scale:function(t,e){return e=void 0!==e?e:t,this.setShape(this.pos.x,this.pos.y,2*this.radiusV.x*t,2*this.radiusV.y*e)},scaleV:function(t){return this.scale(t.x,t.y)},transform:function(){return this},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},contains:function(t,e){var i,n;return 2===arguments.length?(i=arguments[0],n=arguments[1]):(i=arguments[0].x,n=arguments[0].y),i-=this.pos.x,n-=this.pos.y,i*i/this.radiusSq.x+n*n/this.radiusSq.y<=1},getBounds:function(){return void 0===this._bounds&&(this._bounds=pool.pull("Bounds")),this._bounds},clone:function(){return new Ellipse(this.pos.x,this.pos.y,2*this.radiusV.x,2*this.radiusV.y)}}),Bounds$1=function(t){this.onResetEvent(t)},prototypeAccessors$1={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds$1.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds$1.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds$1.prototype.setMinMax=function(t,e,i,n){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=n},prototypeAccessors$1.x.get=function(){return this.min.x},prototypeAccessors$1.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors$1.y.get=function(){return this.min.y},prototypeAccessors$1.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors$1.width.get=function(){return this.max.x-this.min.x},prototypeAccessors$1.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors$1.height.get=function(){return this.max.y-this.min.y},prototypeAccessors$1.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors$1.left.get=function(){return this.min.x},prototypeAccessors$1.right.get=function(){return this.max.x},prototypeAccessors$1.top.get=function(){return this.min.y},prototypeAccessors$1.bottom.get=function(){return this.max.y},prototypeAccessors$1.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors$1.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors$1.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds$1.prototype.update=function(t){this.add(t,!0)},Bounds$1.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var n=t[i];n.x>this.max.x&&(this.max.x=n.x),n.x<this.min.x&&(this.min.x=n.x),n.y>this.max.y&&(this.max.y=n.y),n.y<this.min.y&&(this.min.y=n.y)}},Bounds$1.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds$1.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds$1.prototype.addFrame=function(t,e,i,n,r){var o=me.pool.pull("Vector2d");this.addPoint(o.set(t,e),r),this.addPoint(o.set(i,e),r),this.addPoint(o.set(t,n),r),this.addPoint(o.set(i,n),r),me.pool.push(o)},Bounds$1.prototype.contains=function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Bounds$1?(t=r.min.x,e=r.max.x,i=r.min.y,n=r.max.y):(t=e=r.x,i=n=r.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&n<=this.max.y},Bounds$1.prototype.overlaps=function(t){return this.left<=t.right&&this.right>=t.left&&this.bottom>=t.top&&this.top<=t.bottom},Bounds$1.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds$1.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds$1.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,n=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+n},Bounds$1.prototype.clone=function(){var t=new Bounds$1;return t.addBounds(this),t},Bounds$1.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds$1.prototype,prototypeAccessors$1);var Body=function(t,e,i){if(this.ancestor=t,void 0===this.bounds&&(this.bounds=new Bounds$1),void 0===this.shapes&&(this.shapes=[]),this.collisionMask=collision.types.ALL_OBJECT,this.collisionType=collision.types.ENEMY_OBJECT,void 0===this.vel&&(this.vel=new Vector2d),this.vel.set(0,0),void 0===this.accel&&(this.accel=new Vector2d),this.accel.set(0,0),void 0===this.force&&(this.force=new Vector2d),this.force.set(0,0),void 0===this.friction&&(this.friction=new Vector2d),this.friction.set(0,0),this.bounce=0,this.mass=1,void 0===this.maxVel&&(this.maxVel=new Vector2d),this.maxVel.set(490,490),void 0===this.gravity){var n=this;this.gravity=new ObservableVector2d(0,0,{onUpdate:function(t,e){"number"==typeof e&&(n.gravityScale=e/game$1.world.gravity.y),console.log("me.Body.gravity is deprecated, please see me.Body.gravityScale to modify gravity for a specific body")}})}if(this.gravityScale=1,this.ignoreGravity=!1,this.falling=!1,this.jumping=!1,"function"==typeof i&&(this.onBodyUpdate=i),this.bounds.clear(),void 0!==e)if(Array.isArray(e))for(var r=0;r<e.length;r++)this.addShape(e[r]);else this.addShape(e);this.ancestor.isKinematic=!1};function setTMXValue(name,type,value){var match;if("string"!=typeof value)return value;switch(type){case"int":case"float":value=Number(value);break;case"bool":value="true"===value;break;default:if(!value||utils$1.string.isBoolean(value))value=!value||"true"===value;else if(utils$1.string.isNumeric(value))value=Number(value);else if(0===value.search(/^json:/i)){match=value.split(/^json:/i)[1];try{value=JSON.parse(match)}catch(t){throw new Error("Unable to parse JSON: "+match)}}else if(0===value.search(/^eval:/i)){match=value.split(/^eval:/i)[1];try{value=eval(match)}catch(t){throw new Error("Unable to evaluate: "+match)}}else((match=value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/))||(match=value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/)))&&(value="#"+match[2]+match[1]);0===name.search(/^(ratio|anchorPoint)$/)&&"number"==typeof value&&(value={x:value,y:value})}return value}function parseAttributes(t,e){if(e.attributes&&e.attributes.length>0)for(var i=0;i<e.attributes.length;i++){var n=e.attributes.item(i);void 0!==n.name?t[n.name]=n.value:t[n.nodeName]=n.nodeValue}}function decompress(){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")}function decodeCSV(t){for(var e=t.replace("\n","").trim().split(","),i=[],n=0;n<e.length;n++)i.push(+e[n]);return i}function decodeBase64AsArray(t,e){var i,n,r;e=e||1;var o=window.atob(t.replace(/[^A-Za-z0-9\+\/\=]/g,"")),s=new Uint32Array(o.length/e);for(i=0,r=o.length/e;i<r;i++)for(s[i]=0,n=e-1;n>=0;--n)s[i]+=o.charCodeAt(i*e+n)<<(n<<3);return s}function decode(t,e,i){switch(i=i||"none",e=e||"none"){case"csv":return decodeCSV(t);case"base64":var n=decodeBase64AsArray(t,4);return"none"===i?n:decompress();case"none":return t;case"xml":throw new Error("XML encoding is deprecated, use base64 instead");default:throw new Error("Unknown layer encoding: "+e)}}function normalize(t,e){var i=e.nodeName;switch(i){case"data":var n=parse(e);n.text=n.text||n.chunk.text,n.encoding=n.encoding||"xml",t.data=decode(n.text,n.encoding,n.compression),t.encoding="none";break;case"imagelayer":case"layer":case"objectgroup":case"group":var r=parse(e);r.type="layer"===i?"tilelayer":i,r.image&&(r.image=r.image.source),t.layers=t.layers||[],t.layers.push(r);break;case"animation":t.animation=parse(e).frames;break;case"frame":case"object":var o=i+"s";t[o]=t[o]||[],t[o].push(parse(e));break;case"tile":var s=parse(e);s.image&&(s.imagewidth=s.image.width,s.imageheight=s.image.height,s.image=s.image.source),t.tiles=t.tiles||{},t.tiles[s.id]=s;break;case"tileset":var a=parse(e);a.image&&(a.imagewidth=a.image.width,a.imageheight=a.image.height,a.image=a.image.source),t.tilesets=t.tilesets||[],t.tilesets.push(a);break;case"polygon":case"polyline":t[i]=[];for(var h,l=parse(e).points.split(" "),u=0;u<l.length;u++)h=l[u].split(","),t[i].push({x:+h[0],y:+h[1]});break;case"properties":t.properties=parse(e);break;case"property":var c=parse(e),d=void 0!==c.value?c.value:c.text;t[c.name]=setTMXValue(c.name,c.type||"string",d);break;default:t[i]=parse(e)}}function parse(t){var e={},i="";if(1===t.nodeType&&parseAttributes(e,t),t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++){var r=t.childNodes.item(n);switch(r.nodeType){case 1:normalize(e,r);break;case 3:i+=r.nodeValue.trim()}}return i&&(e.text=i),e}function applyTMXProperties(t,e){var i=e.properties,n=e.propertytypes;if(void 0!==i)for(var r in i)if(i.hasOwnProperty(r)){var o="string",s=r,a=i[r];void 0!==i[r].name&&(s=i[r].name),void 0!==n?o=n[r]:void 0!==i[r].type&&(o=i[r].type),void 0!==i[r].value&&(a=i[r].value),t[s]=setTMXValue(s,o,a)}}Body.prototype.addShape=function(t){if(t instanceof Rect||t instanceof Bounds$1){var e=t.toPolygon();this.shapes.push(e),this.bounds.add(e.points),this.bounds.translate(e.pos)}else t instanceof Ellipse?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.addBounds(t.getBounds()),this.bounds.translate(t.getBounds().x,t.getBounds().y)):t instanceof Polygon?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.add(t.points),this.bounds.translate(t.pos)):this.fromJSON(t);return"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this),this.shapes.length},Body.prototype.setVertices=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=!0);var n=this.getShape(e);n instanceof Polygon?n.setShape(0,0,t):this.shapes[e]=new Polygon(0,0,t),this.bounds.add(this.shapes[e].points,i),"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this)},Body.prototype.addVertices=function(t,e){void 0===e&&(e=0),this.setVertices(t,e,!1)},Body.prototype.fromJSON=function(t,e){var i=t;if(void 0!==e&&(i=t[e]),void 0===i)throw new Error("Identifier ("+e+") undefined for the given JSON object)");if(i.length){for(var n=0;n<i.length;n++)this.addVertices(i[n].shape,n);this.mass=i[0].density||0,this.friction.set(i[0].friction||0,i[0].friction||0),this.bounce=i[0].bounce||0}return i.length},Body.prototype.getShape=function(t){return this.shapes[t||0]},Body.prototype.getBounds=function(){return this.bounds},Body.prototype.removeShape=function(t){this.bounds.clear(),utils$1.array.remove(this.shapes,t);for(var e=0;e<this.shapes.length;e++)this.addShape(this.shapes[e]);return this.shapes.length},Body.prototype.removeShapeAt=function(t){return this.removeShape(this.getShape(t))},Body.prototype.setCollisionMask=function(t){void 0===t&&(t=collision.types.ALL_OBJECT),this.collisionMask=t},Body.prototype.setCollisionType=function(t){if(void 0!==t){if(void 0===collision.types[t])throw new Error("Invalid value for the collisionType property");this.collisionType=collision.types[t]}},Body.prototype.respondToCollision=function(t){var e=t.overlapV;if(this.ancestor.pos.sub(e),0!==e.x&&(this.vel.x=~~(.5+this.vel.x-e.x)||0,this.bounce>0&&(this.vel.x*=-this.bounce)),0!==e.y){this.vel.y=~~(.5+this.vel.y-e.y)||0,this.bounce>0&&(this.vel.y*=-this.bounce);var i=Math.sign(game$1.world.gravity.y*this.gravityScale)||1;this.falling=e.y>=i,this.jumping=e.y<=-i}},Body.prototype.forEach=function(t,e){var i=this,n=0,r=this.shapes,o=r.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);n<o;)t.call(i,r[n],n,r),n++},Body.prototype.contains=function(){var t,e;if(2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.getBounds().contains(t,e))for(var i,n=this.shapes.length;n--,i=this.shapes[n];)if(i.contains(t,e))return!0;return!1},Body.prototype.rotate=function(t,e){var i=this;return void 0===e&&(e=this.getBounds().center),this.bounds.clear(),this.forEach((function(n){n.rotate(t,e),i.bounds.addBounds(n.getBounds()),n instanceof Ellipse?i.bounds.translate(n.getBounds().x,n.getBounds().y):i.bounds.translate(n.pos)})),this},Body.prototype.setVelocity=function(t,e){this.accel.x=0!==t?t:this.accel.x,this.accel.y=0!==e?e:this.accel.y,this.setMaxVelocity(t,e)},Body.prototype.setMaxVelocity=function(t,e){this.maxVel.x=t,this.maxVel.y=e},Body.prototype.setFriction=function(t,e){this.friction.x=t||0,this.friction.y=e||0},Body.prototype.applyFriction=function(t){var e=this.friction.x*timer$1.tick,i=t.x+e,n=t.x-e,r=this.friction.y*timer$1.tick,o=t.y+r,s=t.y-r;t.x=i<0?i:n>0?n:0,t.y=o<0?o:s>0?s:0},Body.prototype.computeVelocity=function(t){if(this.force.x&&(t.x+=this.force.x*timer$1.tick),this.force.y&&(t.y+=this.force.y*timer$1.tick),(this.friction.x||this.friction.y)&&this.applyFriction(t),!this.ignoreGravity){var e=game$1.world.gravity;t.x+=e.x*this.gravityScale*this.mass*timer$1.tick,t.y+=e.y*this.gravityScale*this.mass*timer$1.tick,this.falling=t.y*Math.sign(e.y*this.gravityScale)>0,this.jumping=!this.falling&&this.jumping}0!==t.y&&(t.y=clamp(t.y,-this.maxVel.y,this.maxVel.y)),0!==t.x&&(t.x=clamp(t.x,-this.maxVel.x,this.maxVel.x))},Body.prototype.update=function(){return this.computeVelocity(this.vel),this.ancestor.pos.add(this.vel),0!==this.vel.x||0!==this.vel.y},Body.prototype.destroy=function(){this.onBodyUpdate=void 0,this.ancestor=void 0,this.shapes.length=0};var TextureCache=function(t){this.cache=new Map,this.tinted=new Map,this.units=new Map,this.max_size=t||1/0,this.clear()};function createAtlas(t,e,i,n){return void 0===i&&(i="default"),void 0===n&&(n="no-repeat"),{meta:{app:"melonJS",size:{w:t,h:e},repeat:n,image:"default"},frames:[{filename:i,frame:{x:0,y:0,w:t,h:e}}]}}TextureCache.prototype.clear=function(){this.cache.clear(),this.tinted.clear(),this.units.clear(),this.length=0},TextureCache.prototype.validate=function(){if(this.length>=this.max_size)throw new Error("Texture cache overflow: "+this.max_size+" texture units available for this GPU.")},TextureCache.prototype.get=function(t,e){return this.cache.has(t)||(e||(e=createAtlas(t.width,t.height,t.src?utils$1.file.getBasename(t.src):void 0)),this.set(t,new Texture(e,t,!1))),this.cache.get(t)},TextureCache.prototype.tint=function(t,e){var i=this.tinted.get(t);return void 0===i&&(i=this.tinted.set(t,new Map)),i.has(e)||i.set(e,video$1.renderer.tint(t,e,"multiply")),i.get(e)},TextureCache.prototype.set=function(t,e){var i=t.width,n=t.height;if(!(1!==video$1.renderer.WebGLVersion||isPowerOfTwo(i)&&isPowerOfTwo(n))){var r=void 0!==t.src?t.src:t;console.warn("[Texture] "+r+" is not a POT texture ("+i+"x"+n+")")}this.cache.set(t,e)},TextureCache.prototype.getUnit=function(t){return this.units.has(t)||(this.validate(),this.units.set(t,this.length++)),this.units.get(t)};var Texture=function(t,e,i){if(this.format=null,this.sources=new Map,this.atlases=new Map,void 0!==t)for(var n in t=Array.isArray(t)?t:[t]){var r=t[n];if(void 0!==r.meta){if(r.meta.app.includes("texturepacker")||r.meta.app.includes("free-tex-packer")){if(this.format="texturepacker",void 0===e){var o=loader$1.getImage(r.meta.image);if(!o)throw new Error("Atlas texture '"+o+"' not found");this.sources.set(r.meta.image,o)}else this.sources.set(r.meta.image||"default","string"==typeof e?loader$1.getImage(e):e);this.repeat="no-repeat"}else if(r.meta.app.includes("ShoeBox")){if(!r.meta.exporter||!r.meta.exporter.includes("melonJS"))throw new Error("ShoeBox requires the JSON exporter : https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx");this.format="ShoeBox",this.repeat="no-repeat",this.sources.set("default","string"==typeof e?loader$1.getImage(e):e)}else r.meta.app.includes("melonJS")&&(this.format="melonJS",this.repeat=r.meta.repeat||"no-repeat",this.sources.set("default","string"==typeof e?loader$1.getImage(e):e));this.atlases.set(r.meta.image||"default",this.parse(r))}else void 0!==r.framewidth&&void 0!==r.frameheight&&(this.format="Spritesheet (fixed cell size)",this.repeat="no-repeat",void 0!==e&&(r.image="string"==typeof e?loader$1.getImage(e):e),this.atlases.set("default",this.parseFromSpriteSheet(r)),this.sources.set("default",r.image))}if(0===this.atlases.length)throw new Error("texture atlas format not supported");!1!==i&&this.sources.forEach((function(t){i instanceof TextureCache?i.set(t,this):video$1.renderer.cache.set(t,this)}))};Texture.prototype.parse=function(t){var e={},i=this;return t.frames.forEach((function(n){if(n.hasOwnProperty("filename")){var r,o,s=n.frame,a=n.spriteSourceSize&&n.sourceSize&&n.pivot;a&&(r=n.sourceSize.w*n.pivot.x-(n.trimmed?n.spriteSourceSize.x:0),o=n.sourceSize.h*n.pivot.y-(n.trimmed?n.spriteSourceSize.y:0)),e[n.filename]={name:n.filename,texture:t.meta.image||"default",offset:new Vector2d(s.x,s.y),anchorPoint:a?new Vector2d(r/s.w,o/s.h):null,trimmed:!!n.trimmed,width:s.w,height:s.h,angle:!0===n.rotated?-ETA:0},i.addUvsMap(e,n.filename,t.meta.size.w,t.meta.size.h)}})),e},Texture.prototype.parseFromSpriteSheet=function(t){var e={},i=t.image,n=t.spacing||0,r=t.margin||0,o=i.width,s=i.height,a=pool.pull("Vector2d",~~((o-r+n)/(t.framewidth+n)),~~((s-r+n)/(t.frameheight+n)));if(o%(t.framewidth+n)!=0||s%(t.frameheight+n)!=0){var h=a.x*(t.framewidth+n),l=a.y*(t.frameheight+n);h-o!==n&&l-s!==n&&(o=h,s=l,console.warn("Spritesheet Texture for image: "+i.src+" is not divisible by "+(t.framewidth+n)+"x"+(t.frameheight+n)+", truncating effective size to "+o+"x"+s))}for(var u=0,c=a.x*a.y;u<c;u++){var d=""+u;e[d]={name:d,texture:"default",offset:new Vector2d(r+(n+t.framewidth)*(u%a.x),r+(n+t.frameheight)*~~(u/a.x)),anchorPoint:t.anchorPoint||null,trimmed:!1,width:t.framewidth,height:t.frameheight,angle:0},this.addUvsMap(e,d,o,s)}return pool.push(a),e},Texture.prototype.addUvsMap=function(t,e,i,n){if(video$1.renderer instanceof WebGLRenderer){var r=t[e].offset,o=t[e].width,s=t[e].height;t[e].uvs=new Float32Array([r.x/i,r.y/n,(r.x+o)/i,(r.y+s)/n]),t[r.x+","+r.y+","+i+","+n]=t[e]}return t[e]},Texture.prototype.addQuadRegion=function(t,e,i,n,r){!0===video$1.renderer.settings.verbose&&console.warn("Adding texture region",t,"for texture",this);var o=this.getTexture(),s=this.getAtlas(),a=o.width,h=o.height;return s[t]={name:t,offset:new Vector2d(e,i),width:n,height:r,angle:0},this.addUvsMap(s,t,a,h),s[t]},Texture.prototype.getAtlas=function(t){return"string"==typeof t?this.atlases.get(t):this.atlases.values().next().value},Texture.prototype.getFormat=function(){return this.format},Texture.prototype.getTexture=function(t){return"object"==typeof t&&"string"==typeof t.texture?this.sources.get(t.texture):this.sources.values().next().value},Texture.prototype.getRegion=function(t,e){var i;return"string"==typeof e?i=this.getAtlas(e)[t]:this.atlases.forEach((function(e){void 0!==e[t]&&(i=e[t])})),i},Texture.prototype.getUVs=function(t){var e=this.getRegion(t);if(void 0===e){var i=t.split(","),n=+i[0],r=+i[1],o=+i[2],s=+i[3];e=this.addQuadRegion(t,n,r,o,s)}return e.uvs},Texture.prototype.createSpriteFromName=function(t,e){return pool.pull("me.Sprite",0,0,Object.assign({image:this,region:t},e||{}))},Texture.prototype.createAnimationFromName=function(t,e){for(var i,n=[],r={},o=0,s=0,a=0;a<t.length;++a){if(null==(i=this.getRegion(t[a])))throw new Error("Texture - region for "+t[a]+" not found");n[a]=i,r[t[a]]=a,o=Math.max(i.width,o),s=Math.max(i.height,s)}return new Sprite(0,0,Object.assign({image:this,framewidth:o,frameheight:s,margin:0,spacing:0,atlas:n,atlasIndices:r},e||{}))};var Sprite=Renderable.extend({init:function(t,e,i){if(this.animationpause=!1,this.animationspeed=100,this.offset=pool.pull("Vector2d",0,0),this.source=null,this.anim={},this.resetAnim=void 0,this.current={name:"default",length:0,offset:new Vector2d,width:0,height:0,angle:0,idx:0},this.dt=0,this._flicker={isFlickering:!1,duration:0,callback:null,state:!1},this._super(Renderable,"init",[t,e,0,0]),i.image instanceof Texture){if(this.source=i.image,this.image=this.source.getTexture(),this.textureAtlas=i.image,void 0!==i.region){var n=this.source.getRegion(i.region);if(!n)throw new Error("Texture - region for "+i.region+" not found");this.setRegion(n),this.current.width=i.framewidth||n.width,this.current.height=i.frameheight||n.height}}else this.image="object"==typeof i.image?i.image:loader$1.getImage(i.image),this.current.width=i.framewidth=i.framewidth||this.image.width,this.current.height=i.frameheight=i.frameheight||this.image.height,this.source=video$1.renderer.cache.get(this.image,i),this.textureAtlas=this.source.getAtlas();void 0!==i.atlas&&(this.textureAtlas=i.atlas,this.atlasIndices=i.atlasIndices),this.width=this.current.width,this.height=this.current.height,void 0!==i.flipX&&this.flipX(!!i.flipX),void 0!==i.flipY&&this.flipY(!!i.flipY),void 0!==i.rotation&&this.currentTransform.rotate(i.rotation),i.anchorPoint&&this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y),void 0!==i.tint&&this.tint.setColor(i.tint),"string"==typeof i.name&&(this.name=i.name),0!==this.addAnimation("default",null)&&this.setCurrentAnimation("default"),this.autoTransform=!0},isFlickering:function(){return this._flicker.isFlickering},flicker:function(t,e){return this._flicker.duration=t,this._flicker.duration<=0?(this._flicker.isFlickering=!1,this._flicker.callback=null):this._flicker.isFlickering||(this._flicker.callback=e,this._flicker.isFlickering=!0),this},addAnimation:function(t,e,i){this.anim[t]={name:t,frames:[],idx:0,length:0};var n=0;if("object"!=typeof this.textureAtlas)return 0;null==e&&(e=[],Object.keys(this.textureAtlas).forEach((function(t,i){e[i]=i})));for(var r=0,o=e.length;r<o;r++){var s,a=e[r],h=(s="number"==typeof a||"string"==typeof a?{name:a,delay:i||this.animationspeed}:a).name;if("number"==typeof h)void 0!==this.textureAtlas[h]&&(this.anim[t].frames[r]=Object.assign({},this.textureAtlas[h],s),n++);else{if(this.source.getFormat().includes("Spritesheet"))throw new Error("string parameters for addAnimation are not allowed for standard spritesheet based Texture");this.anim[t].frames[r]=Object.assign({},this.textureAtlas[this.atlasIndices[h]],s),n++}}return this.anim[t].length=n,n},setCurrentAnimation:function(t,e,i){if(!this.anim[t])throw new Error("animation id '"+t+"' not defined");return this.current.name=t,this.current.length=this.anim[this.current.name].length,this.resetAnim="string"==typeof e?this.setCurrentAnimation.bind(this,e,null,!0):"function"==typeof e?e:void 0,this.setAnimationFrame(this.current.idx),i||(this.dt=0),this.isDirty=!0,this},reverseAnimation:function(t){return void 0!==t&&void 0!==this.anim[t]?this.anim[t].frames.reverse():this.anim[this.current.name].frames.reverse(),this.isDirty=!0,this},isCurrentAnimation:function(t){return this.current.name===t},setRegion:function(t){return this.image=this.source.getTexture(t),this.current.offset.setV(t.offset),this.current.angle=t.angle,this.width=this.current.width=t.width,this.height=this.current.height=t.height,t.anchorPoint&&this.anchorPoint.set(this._flip.x&&!0===t.trimmed?1-t.anchorPoint.x:t.anchorPoint.x,this._flip.y&&!0===t.trimmed?1-t.anchorPoint.y:t.anchorPoint.y),this.isDirty=!0,this},setAnimationFrame:function(t){return this.current.idx=(t||0)%this.current.length,this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx))},getCurrentAnimationFrame:function(){return this.current.idx},getAnimationFrameObjectByIndex:function(t){return this.anim[this.current.name].frames[t]},update:function(t){if(!this.animationpause&&this.current&&this.current.length>0){var e=this.getAnimationFrameObjectByIndex(this.current.idx).delay;for(this.dt+=t;this.dt>=e;){this.isDirty=!0,this.dt-=e;var i=this.current.length>1?this.current.idx+1:this.current.idx;if(this.setAnimationFrame(i),0===this.current.idx&&"function"==typeof this.resetAnim&&!1===this.resetAnim()){this.setAnimationFrame(this.current.length-1),this.dt%=e;break}e=this.getAnimationFrameObjectByIndex(this.current.idx).delay}}return this._flicker.isFlickering&&(this._flicker.duration-=t,this._flicker.duration<0&&("function"==typeof this._flicker.callback&&this._flicker.callback(),this.flicker(-1)),this.isDirty=!0),this.isDirty},destroy:function(){pool.push(this.offset),this.offset=void 0,this._super(Renderable,"destroy")},draw:function(t){if(!this._flicker.isFlickering||(this._flicker.state=!this._flicker.state,this._flicker.state)){var e=this.current,i=this.pos.x,n=this.pos.y,r=e.width,o=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-n),t.rotate(e.angle),i-=o,r=e.height,o=e.width),t.drawImage(this.image,a.x+s.x,a.y+s.y,r,o,i,n,r,o)}}}),TMX_FLIP_H=2147483648,TMX_FLIP_V=1073741824,TMX_FLIP_AD=536870912,TMX_CLEAR_BIT_MASK$1=536870911,Tile=function(t){function e(e,i,n,r){var o,s;if(t.call(this),r.isCollection){var a=r.getTileImage(n&TMX_CLEAR_BIT_MASK$1);o=a.width,s=a.height}else o=r.tilewidth,s=r.tileheight;this.setMinMax(0,0,o,s),this.tileset=r,this.currentTransform=null,this.col=e,this.row=i,this.tileId=n,this.flippedX=0!=(this.tileId&TMX_FLIP_H),this.flippedY=0!=(this.tileId&TMX_FLIP_V),this.flippedAD=0!=(this.tileId&TMX_FLIP_AD),this.flipped=this.flippedX||this.flippedY||this.flippedAD,!0===this.flipped&&(null===this.currentTransform&&(this.currentTransform=new Matrix2d),this.setTileTransform(this.currentTransform.identity())),this.tileId&=TMX_CLEAR_BIT_MASK$1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setTileTransform=function(t){t.translate(this.width/2,this.height/2),this.flippedAD&&(t.rotate(-90*Math.PI/180),t.scale(-1,1)),this.flippedX&&t.scale(this.flippedAD?1:-1,this.flippedAD?-1:1),this.flippedY&&t.scale(this.flippedAD?-1:1,this.flippedAD?1:-1),t.translate(-this.width/2,-this.height/2)},e.prototype.getRenderable=function(t){var e,i=this.tileset;if(i.animations.has(this.tileId)){var n=[],r=[];i.animations.get(this.tileId).frames.forEach((function(t){r.push(t.tileid),n.push({name:""+t.tileid,delay:t.duration})})),(e=i.texture.createAnimationFromName(r,t)).addAnimation(this.tileId-i.firstgid,n),e.setCurrentAnimation(this.tileId-i.firstgid)}else if(!0===i.isCollection){var o=i.getTileImage(this.tileId);(e=new Sprite(0,0,Object.assign({image:o}))).anchorPoint.set(0,0),e.scale(t.width/this.width,t.height/this.height),void 0!==t.rotation&&(e.anchorPoint.set(.5,.5),e.currentTransform.rotate(t.rotation),e.currentTransform.translate(t.width/2,t.height/2),t.rotation=void 0)}else(e=i.texture.createSpriteFromName(this.tileId-i.firstgid,t)).anchorPoint.set(0,0);return this.setTileTransform(e.currentTransform),e},e}(Bounds$1),Line=Polygon.extend({contains:function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y;var i=this.points[0],n=this.points[1];return(e-i.y)*(n.x-i.x)==(n.y-i.y)*(t-i.x)},recalc:function(){var t=this.edges,e=this.normals,i=this.indices,n=this.points;if(2!==n.length)throw new Error("Requires exactly 2 points");return void 0===t[0]&&(t[0]=new Vector2d),t[0].copy(n[1]).sub(n[0]),void 0===e[0]&&(e[0]=new Vector2d),e[0].copy(t[0]).perp().normalize(),i.length=0,this},clone:function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Line(this.pos.x,this.pos.y,t)}}),Renderer=function(t){return this.settings=t,this.isContextValid=!0,this.currentScissor=new Int32Array([0,0,this.settings.width,this.settings.height]),this.currentBlendMode="normal",!0===device$1.ejecta?this.canvas=document.getElementById("canvas"):void 0!==window.canvas?this.canvas=window.canvas:void 0!==this.settings.canvas?this.canvas=this.settings.canvas:this.canvas=video$1.createCanvas(this.settings.zoomX,this.settings.zoomY),this.backBufferCanvas=this.canvas,this.context=null,this.currentColor=new Color(0,0,0,1),this.currentTint=new Color(255,255,255,1),this.projectionMatrix=new Matrix3d,this.uvOffset=0,this.Texture=Texture,event.subscribe(event.GAME_RESET,(function(){video$1.renderer.reset()})),this};Renderer.prototype.clear=function(){},Renderer.prototype.reset=function(){this.resetTransform(),this.setBlendMode(this.settings.blendMode),this.setColor("#000000"),this.clearTint(),this.cache.clear(),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},Renderer.prototype.getCanvas=function(){return this.backBufferCanvas},Renderer.prototype.getScreenCanvas=function(){return this.canvas},Renderer.prototype.getScreenContext=function(){return this.context},Renderer.prototype.getBlendMode=function(){return this.currentBlendMode},Renderer.prototype.getContext2d=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a 2d context");if(void 0===t.getContext)throw new Error("Your browser does not support HTML5 canvas.");"boolean"!=typeof e&&(e=!0);var i=t.getContext("2d",{alpha:e});return i.canvas||(i.canvas=t),this.setAntiAlias(i,this.settings.antiAlias),i},Renderer.prototype.getWidth=function(){return this.backBufferCanvas.width},Renderer.prototype.getHeight=function(){return this.backBufferCanvas.height},Renderer.prototype.getColor=function(){return this.currentColor},Renderer.prototype.globalAlpha=function(){return this.currentColor.glArray[3]},Renderer.prototype.overlaps=function(t){return t.left<=this.getWidth()&&t.right>=0&&t.top<=this.getHeight()&&t.bottom>=0},Renderer.prototype.resize=function(t,e){t===this.backBufferCanvas.width&&e===this.backBufferCanvas.height||(this.canvas.width=this.backBufferCanvas.width=t,this.canvas.height=this.backBufferCanvas.height=e,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=t,this.currentScissor[3]=e,event.publish(event.CANVAS_ONRESIZE,[t,e]))},Renderer.prototype.setAntiAlias=function(t,e){var i=t.canvas;setPrefixed("imageSmoothingEnabled",!0===e,t),!0!==e?(i.style["image-rendering"]="optimizeSpeed",i.style["image-rendering"]="-moz-crisp-edges",i.style["image-rendering"]="-o-crisp-edges",i.style["image-rendering"]="-webkit-optimize-contrast",i.style["image-rendering"]="optimize-contrast",i.style["image-rendering"]="crisp-edges",i.style["image-rendering"]="pixelated",i.style.msInterpolationMode="nearest-neighbor"):i.style["image-rendering"]="auto"},Renderer.prototype.setProjection=function(t){this.projectionMatrix.copy(t)},Renderer.prototype.stroke=function(t,e){t instanceof Rect||t instanceof Bounds$1?this.strokeRect(t.left,t.top,t.width,t.height,e):t instanceof Line||t instanceof Polygon?this.strokePolygon(t,e):t instanceof Ellipse&&this.strokeEllipse(t.pos.x,t.pos.y,t.radiusV.x,t.radiusV.y,e)},Renderer.prototype.tint=function(t,e,i){var n=video$1.createCanvas(t.width,t.height,!0),r=this.getContext2d(n);return r.save(),r.fillStyle=e instanceof Color?e.toRGB():e,r.fillRect(0,0,t.width,t.height),r.globalCompositeOperation=i||"multiply",r.drawImage(t,0,0),r.globalCompositeOperation="destination-atop",r.drawImage(t,0,0),r.restore(),n},Renderer.prototype.fill=function(t){this.stroke(t,!0)},Renderer.prototype.setMask=function(t){},Renderer.prototype.clearMask=function(){},Renderer.prototype.setTint=function(t){this.currentTint.copy(t)},Renderer.prototype.clearTint=function(){this.currentTint.setColor(255,255,255,1)},Renderer.prototype.drawFont=function(){};var CanvasRenderer=function(t){function e(e){return t.call(this,e),this.context=this.getContext2d(this.getScreenCanvas(),this.settings.transparent),this.settings.doubleBuffering?(this.backBufferCanvas=video$1.createCanvas(this.settings.width,this.settings.height,!0),this.backBufferContext2D=this.getContext2d(this.backBufferCanvas)):(this.backBufferCanvas=this.getScreenCanvas(),this.backBufferContext2D=this.context),this.setBlendMode(this.settings.blendMode),this.setColor(this.currentColor),this.cache=new TextureCache,!1===this.settings.textureSeamFix||this.settings.antiAlias||(this.uvOffset=1),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),this.clearColor(this.currentColor,!0!==this.settings.transparent)},e.prototype.resetTransform=function(){this.backBufferContext2D.setTransform(1,0,0,1,0,0)},e.prototype.setBlendMode=function(t,e){if(e=e||this.getContext(),this.currentBlendMode=t,"multiply"===t)e.globalCompositeOperation="multiply";else e.globalCompositeOperation="source-over",this.currentBlendMode="normal";this.settings.doubleBuffering&&this.settings.transparent&&(this.context.globalCompositeOperation="copy")},e.prototype.clear=function(){this.settings.transparent&&this.clearColor("rgba(0,0,0,0)",!0)},e.prototype.flush=function(){this.settings.doubleBuffering&&this.context.drawImage(this.backBufferCanvas,0,0)},e.prototype.clearColor=function(t,e){this.save(),this.resetTransform(),this.backBufferContext2D.globalCompositeOperation=e?"copy":"source-over",this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t,this.fillRect(0,0,this.backBufferCanvas.width,this.backBufferCanvas.height),this.restore()},e.prototype.clearRect=function(t,e,i,n){this.backBufferContext2D.clearRect(t,e,i,n)},e.prototype.createPattern=function(t,e){return this.backBufferContext2D.createPattern(t,e)},e.prototype.drawImage=function(t,e,i,n,r,o,s,a,h){if(!(this.backBufferContext2D.globalAlpha<1/255)){void 0===n?(n=a=t.width,r=h=t.height,o=e,s=i,e=0,i=0):void 0===o&&(o=e,s=i,a=n,h=r,n=t.width,r=t.height,e=0,i=0),!1===this.settings.subPixel&&(o=~~o,s=~~s);var l=t,u=this.currentTint.toArray();1===u[0]&&1===u[1]&&1===u[2]||(l=this.cache.tint(t,this.currentTint.toRGB())),this.backBufferContext2D.drawImage(l,e,i,n,r,o,s,a,h)}},e.prototype.drawPattern=function(t,e,i,n,r){if(!(this.backBufferContext2D.globalAlpha<1/255)){var o=this.backBufferContext2D.fillStyle;this.backBufferContext2D.fillStyle=t,this.backBufferContext2D.fillRect(e,i,n,r),this.backBufferContext2D.fillStyle=o}},e.prototype.strokeArc=function(t,e,i,n,r,o,s){var a=this.backBufferContext2D;a.globalAlpha<1/255||(a.translate(t,e),a.beginPath(),a.arc(0,0,i,n,r,o||!1),a[!0===s?"fill":"stroke"](),a.translate(-t,-e))},e.prototype.fillArc=function(t,e,i,n,r,o){this.strokeArc(t,e,i,n,r,o||!1,!0)},e.prototype.strokeEllipse=function(t,e,i,n,r){var o=this.backBufferContext2D;if(!(o.globalAlpha<1/255)){var s=t-i,a=t+i,h=e-n,l=e+n,u=.551784*i,c=.551784*n,d=t-u,p=t+u,f=e-c,g=e+c;o.beginPath(),o.moveTo(t,h),o.bezierCurveTo(p,h,a,f,a,e),o.bezierCurveTo(a,g,p,l,t,l),o.bezierCurveTo(d,l,s,g,s,e),o.bezierCurveTo(s,f,d,h,t,h),o[!0===r?"fill":"stroke"](),o.closePath()}},e.prototype.fillEllipse=function(t,e,i,n){this.strokeEllipse(t,e,i,n,!0)},e.prototype.strokeLine=function(t,e,i,n){var r=this.backBufferContext2D;r<1/255||(r.beginPath(),r.moveTo(t,e),r.lineTo(i,n),r.stroke())},e.prototype.fillLine=function(t,e,i,n){this.strokeLine(t,e,i,n)},e.prototype.strokePolygon=function(t,e){var i=this.backBufferContext2D;if(!(i.globalAlpha<1/255)){var n;this.translate(t.pos.x,t.pos.y),i.beginPath(),i.moveTo(t.points[0].x,t.points[0].y);for(var r=1;r<t.points.length;r++)n=t.points[r],i.lineTo(n.x,n.y);i.lineTo(t.points[0].x,t.points[0].y),i[!0===e?"fill":"stroke"](),i.closePath(),this.translate(-t.pos.x,-t.pos.y)}},e.prototype.fillPolygon=function(t){this.strokePolygon(t,!0)},e.prototype.strokeRect=function(t,e,i,n,r){if(!0===r)this.fillRect(t,e,i,n);else{if(this.backBufferContext2D.globalAlpha<1/255)return;this.backBufferContext2D.strokeRect(t,e,i,n)}},e.prototype.fillRect=function(t,e,i,n){this.backBufferContext2D.globalAlpha<1/255||this.backBufferContext2D.fillRect(t,e,i,n)},e.prototype.getContext=function(){return this.backBufferContext2D},e.prototype.getFontContext=function(){return this.getContext()},e.prototype.save=function(){this.backBufferContext2D.save()},e.prototype.restore=function(){this.backBufferContext2D.restore(),this.currentColor.glArray[3]=this.backBufferContext2D.globalAlpha,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},e.prototype.rotate=function(t){this.backBufferContext2D.rotate(t)},e.prototype.scale=function(t,e){this.backBufferContext2D.scale(t,e)},e.prototype.setColor=function(t){this.backBufferContext2D.strokeStyle=this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t},e.prototype.setGlobalAlpha=function(t){this.backBufferContext2D.globalAlpha=this.currentColor.glArray[3]=t},e.prototype.setLineWidth=function(t){this.backBufferContext2D.lineWidth=t},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=t.toArray(),i=e[0],n=e[1],r=e[3],o=e[4],s=e[6],a=e[7];!1===this.settings.subPixel&&(s|=0,a|=0),this.backBufferContext2D.transform(i,n,r,o,s,a)},e.prototype.translate=function(t,e){!1===this.settings.subPixel?this.backBufferContext2D.translate(~~t,~~e):this.backBufferContext2D.translate(t,e)},e.prototype.clipRect=function(t,e,i,n){var r=this.backBufferCanvas;if(0!==t||0!==e||i!==r.width||n!==r.height){var o=this.currentScissor;if(o[0]!==t||o[1]!==e||o[2]!==i||o[3]!==n){var s=this.backBufferContext2D;s.beginPath(),s.rect(t,e,i,n),s.clip(),o[0]=t,o[1]=e,o[2]=i,o[3]=n}}},e.prototype.setMask=function(t){var e=this.backBufferContext2D,i=t.pos.x,n=t.pos.y;if(t instanceof Ellipse){var r=t.radiusV.x,o=t.radiusV.y,s=i-r,a=i+r,h=n-o,l=n+o,u=.551784*r,c=.551784*o,d=i-u,p=i+u,f=n-c,g=n+c;e.beginPath(),e.moveTo(i,h),e.bezierCurveTo(p,h,a,f,a,n),e.bezierCurveTo(a,g,p,l,i,l),e.bezierCurveTo(d,l,s,g,s,n),e.bezierCurveTo(s,f,d,h,i,h)}else{var m;e.save(),e.beginPath(),e.moveTo(i+t.points[0].x,n+t.points[0].y);for(var y=1;y<t.points.length;y++)m=t.points[y],e.lineTo(i+m.x,n+m.y);e.closePath()}e.clip()},e.prototype.clearMask=function(){this.backBufferContext2D.restore()},e}(Renderer);function initArray(t){t.layerData=new Array(t.cols);for(var e=0;e<t.cols;e++){t.layerData[e]=new Array(t.rows);for(var i=0;i<t.rows;i++)t.layerData[e][i]=null}}function setLayerData(t,e){var i=0;initArray(t);for(var n=0;n<t.rows;n++)for(var r=0;r<t.cols;r++){var o=e[i++];0!==o&&(t.layerData[r][n]=t.getTileById(o,r,n))}}function preRenderLayer(t,e){for(var i=0;i<t.rows;i++)for(var n=0;n<t.cols;n++){var r=t.layerData[n][i];r instanceof Tile&&t.getRenderer().drawTile(e,n,i,r)}}var TMXLayer=Renderable.extend({init:function(t,e,i,n,r,o,s){this._super(Renderable,"init",[0,0,0,0]),this.tilewidth=e.tilewidth||i,this.tileheight=e.tileheight||n,this.orientation=r,this.tilesets=o,this.tileset=this.tilesets?this.tilesets.getTilesetByIndex(0):null,this.maxTileSize={width:0,height:0};for(var a=0;a<this.tilesets.length;a++){var h=this.tilesets.getTilesetByIndex(a);this.maxTileSize.width=Math.max(this.maxTileSize.width,h.tilewidth),this.maxTileSize.height=Math.max(this.maxTileSize.height,h.tileheight)}this.animatedTilesets=[],this.isAnimated=!1,this.renderorder=e.renderorder||"right-down",this.pos.z=s,this.anchorPoint.set(0,0),this.name=e.name,this.cols=+e.width,this.rows=+e.height;var l=void 0!==e.visible?+e.visible:1;this.setOpacity(l?+e.opacity:0),"string"==typeof e.tintcolor&&this.tint.parseHex(e.tintcolor,!0),"isometric"===this.orientation?(this.width=(this.cols+this.rows)*(this.tilewidth/2),this.height=(this.cols+this.rows)*(this.tileheight/2)):(this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight),applyTMXProperties(this,e),void 0===this.preRender&&(this.preRender=game$1.world.preRender),this.setRenderer(t.getRenderer()),setLayerData(this,decode(e.data,e.encoding,e.compression))},onActivateEvent:function(){if(void 0===this.animatedTilesets&&(this.animatedTilesets=[]),this.tilesets)for(var t=this.tilesets.tilesets,e=0;e<t.length;e++)t[e].isAnimated&&this.animatedTilesets.push(t[e]);this.isAnimated=this.animatedTilesets.length>0,this.isAnimated&&(this.preRender=!1),this.getBounds().addBounds(this.getRenderer().getBounds(),!0),this.getBounds().shift(this.pos),!0!==this.preRender||this.canvasRenderer||(this.canvasRenderer=new CanvasRenderer({canvas:video$1.createCanvas(this.width,this.height),widht:this.width,heigth:this.height,transparent:!0}),preRenderLayer(this,this.canvasRenderer))},onDeactivateEvent:function(){this.animatedTilesets=void 0},setRenderer:function(t){this.renderer=t},getRenderer:function(){return this.renderer},getTileId:function(t,e){var i=this.getTile(t,e);return i?i.tileId:null},getTile:function(t,e){var i=null;if(this.contains(t,e)){var n=this.getRenderer().pixelToTileCoords(t,e,pool.pull("Vector2d"));i=this.cellAt(n.x,n.y),pool.push(n)}return i},setTile:function(t,e,i){return this.layerData[e][i]=t,t},getTileById:function(t,e,i){return this.tileset.contains(t)||(this.tileset=this.tilesets.getTilesetByGid(t)),new Tile(e,i,t,this.tileset)},cellAt:function(t,e,i){var n=~~t,r=~~e,o=this.getRenderer();return!1===i||n>=0&&n<o.cols&&r>=0&&r<o.rows?this.layerData[n][r]:null},clearTile:function(t,e){this.layerData[t][e]=null,this.preRender&&this.canvasRenderer.clearRect(t*this.tilewidth,e*this.tileheight,this.tilewidth,this.tileheight)},update:function(t){if(this.isAnimated){for(var e=!1,i=0;i<this.animatedTilesets.length;i++)e=this.animatedTilesets[i].update(t)||e;return e}return!1},draw:function(t,e){if(this.preRender){var i=Math.min(e.width,this.width),n=Math.min(e.height,this.height);t.drawImage(this.canvasRenderer.getCanvas(),e.pos.x,e.pos.y,i,n,e.pos.x,e.pos.y,i,n)}else this.getRenderer().drawTileLayer(t,this,e)}}),Bounds=function(t){this.onResetEvent(t)},prototypeAccessors={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds.prototype.setMinMax=function(t,e,i,n){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=n},prototypeAccessors.x.get=function(){return this.min.x},prototypeAccessors.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors.y.get=function(){return this.min.y},prototypeAccessors.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors.width.get=function(){return this.max.x-this.min.x},prototypeAccessors.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors.height.get=function(){return this.max.y-this.min.y},prototypeAccessors.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors.left.get=function(){return this.min.x},prototypeAccessors.right.get=function(){return this.max.x},prototypeAccessors.top.get=function(){return this.min.y},prototypeAccessors.bottom.get=function(){return this.max.y},prototypeAccessors.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds.prototype.update=function(t){this.add(t,!0)},Bounds.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var n=t[i];n.x>this.max.x&&(this.max.x=n.x),n.x<this.min.x&&(this.min.x=n.x),n.y>this.max.y&&(this.max.y=n.y),n.y<this.min.y&&(this.min.y=n.y)}},Bounds.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds.prototype.addFrame=function(t,e,i,n,r){var o=me.pool.pull("Vector2d");this.addPoint(o.set(t,e),r),this.addPoint(o.set(i,e),r),this.addPoint(o.set(t,n),r),this.addPoint(o.set(i,n),r),me.pool.push(o)},Bounds.prototype.contains=function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Bounds?(t=r.min.x,e=r.max.x,i=r.min.y,n=r.max.y):(t=e=r.x,i=n=r.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&n<=this.max.y},Bounds.prototype.overlaps=function(t){return this.left<=t.right&&this.right>=t.left&&this.bottom>=t.top&&this.top<=t.bottom},Bounds.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,n=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+n},Bounds.prototype.clone=function(){var t=new Bounds;return t.addBounds(this),t},Bounds.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds.prototype,prototypeAccessors);var TMXRenderer=function(t,e,i,n){this.cols=t,this.rows=e,this.tilewidth=i,this.tileheight=n,this.bounds=new Bounds};TMXRenderer.prototype.canRender=function(t){return this.tilewidth===t.tilewidth&&this.tileheight===t.tileheight},TMXRenderer.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return e.setMinMax(0,0,this.cols*this.tilewidth,this.rows*this.tileheight),e},TMXRenderer.prototype.pixelToTileCoords=function(t,e,i){return i},TMXRenderer.prototype.tileToPixelCoords=function(t,e,i){return i},TMXRenderer.prototype.drawTile=function(t,e,i,n){},TMXRenderer.prototype.drawTileLayer=function(t,e,i){};var TMXOrthogonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"orthogonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(t/this.tilewidth,e/this.tileheight)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set(t*this.tilewidth,e*this.tileheight)},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset;r.drawTile(t,r.tileoffset.x+e*this.tilewidth,r.tileoffset.y+(i+1)*this.tileheight-r.tileheight,n)},e.prototype.drawTileLayer=function(t,e,i){var n=1,r=1,o=this.pixelToTileCoords(Math.max(i.pos.x-(e.maxTileSize.width-e.tilewidth),0),Math.max(i.pos.y-(e.maxTileSize.height-e.tileheight),0),pool.pull("Vector2d")).floorSelf(),s=this.pixelToTileCoords(i.pos.x+i.width+this.tilewidth,i.pos.y+i.height+this.tileheight,pool.pull("Vector2d")).ceilSelf();switch(s.x=s.x>this.cols?this.cols:s.x,s.y=s.y>this.rows?this.rows:s.y,e.renderorder){case"right-up":s.y=o.y+(o.y=s.y)-s.y,r=-1;break;case"left-down":s.x=o.x+(o.x=s.x)-s.x,n=-1;break;case"left-up":s.x=o.x+(o.x=s.x)-s.x,s.y=o.y+(o.y=s.y)-s.y,n=-1,r=-1}for(var a=o.y;a!==s.y;a+=r)for(var h=o.x;h!==s.x;h+=n){var l=e.cellAt(h,a,!1);l&&this.drawTile(t,h,a,l)}pool.push(o),pool.push(s)},e}(TMXRenderer),TMXIsometricRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight),this.hTilewidth=this.tilewidth/2,this.hTileheight=this.tileheight/2,this.originX=this.rows*this.hTilewidth}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"isometric"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return e.setMinMax(0,0,(this.cols+this.rows)*(this.tilewidth/2),(this.cols+this.rows)*(this.tileheight/2)),e},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(e/this.tileheight+(t-this.originX)/this.tilewidth,e/this.tileheight-(t-this.originX)/this.tilewidth)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set((t-e)*this.hTilewidth+this.originX,(t+e)*this.hTileheight)},e.prototype.adjustPosition=function(t){var e=t.x/this.hTilewidth,i=t.y/this.tileheight,n=pool.pull("Vector2d");this.tileToPixelCoords(e,i,n),t.x=n.x,t.y=n.y,pool.push(n)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset;r.drawTile(t,(this.cols-1)*r.tilewidth+(e-i)*r.tilewidth>>1,-r.tilewidth+(e+i)*r.tileheight>>2,n)},e.prototype.drawTileLayer=function(t,e,i){var n=e.tileset,r=this.pixelToTileCoords(i.pos.x-n.tilewidth,i.pos.y-n.tileheight,pool.pull("Vector2d")).floorSelf(),o=this.pixelToTileCoords(i.pos.x+i.width+n.tilewidth,i.pos.y+i.height+n.tileheight,pool.pull("Vector2d")).ceilSelf(),s=this.tileToPixelCoords(o.x,o.y,pool.pull("Vector2d")),a=this.tileToPixelCoords(r.x,r.y,pool.pull("Vector2d"));a.x-=this.hTilewidth,a.y+=this.tileheight;var h=a.y-i.pos.y>this.hTileheight,l=i.pos.x-a.x<this.hTilewidth;h&&(l?(r.x--,a.x-=this.hTilewidth):(r.y--,a.x+=this.hTilewidth),a.y-=this.hTileheight);for(var u=h^l,c=r.clone(),d=2*a.y;d-2*this.tileheight<2*s.y;d+=this.tileheight){c.setV(r);for(var p=a.x;p<s.x;p+=this.tilewidth){var f=e.cellAt(c.x,c.y);if(f){var g=(n=f.tileset).tileoffset;n.drawTile(t,g.x+p,g.y+d/2-n.tileheight,f)}c.x++,c.y--}u?(r.y++,a.x-=this.hTilewidth,u=!1):(r.x++,a.x+=this.hTilewidth,u=!0)}pool.push(c),pool.push(r),pool.push(o),pool.push(s),pool.push(a)},e}(TMXRenderer),offsetsStaggerX=[{x:0,y:0},{x:1,y:-1},{x:1,y:0},{x:2,y:0}],offsetsStaggerY=[{x:0,y:0},{x:-1,y:1},{x:0,y:1},{x:0,y:2}],TMXHexagonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,-2&e.tilewidth,-2&e.tileheight),this.hexsidelength=e.hexsidelength||0,this.staggerX="x"===e.staggeraxis,this.staggerEven="even"===e.staggerindex,this.sidelengthx=0,this.sidelengthy=0,"hexagonal"===e.orientation&&(this.staggerX?this.sidelengthx=this.hexsidelength:this.sidelengthy=this.hexsidelength),this.sideoffsetx=(this.tilewidth-this.sidelengthx)/2,this.sideoffsety=(this.tileheight-this.sidelengthy)/2,this.columnwidth=this.sideoffsetx+this.sidelengthx,this.rowheight=this.sideoffsety+this.sidelengthy,this.centers=[new Vector2d,new Vector2d,new Vector2d,new Vector2d]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"hexagonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return this.staggerX?(e.setMinMax(0,0,this.cols*this.columnwidth+this.sideoffsetx,this.rows*(this.tileheight+this.sidelengthy)),e.width>1&&(e.height+=this.rowheight)):(e.setMinMax(0,0,this.cols*(this.tilewidth+this.sidelengthx),this.rows*this.rowheight+this.sideoffsety),e.height>1&&(e.width+=this.columnwidth)),e},e.prototype.doStaggerX=function(t){return this.staggerX&&1&t^this.staggerEven},e.prototype.doStaggerY=function(t){return!this.staggerX&&1&t^this.staggerEven},e.prototype.topLeft=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t-1,e):n.set(t-1,e-1):1&e^this.staggerEven?n.set(t,e-1):n.set(t-1,e-1),n},e.prototype.topRight=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t+1,e):n.set(t+1,e-1):1&e^this.staggerEven?n.set(t+1,e-1):n.set(t,e-1),n},e.prototype.bottomLeft=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t-1,e+1):n.set(t-1,e):1&e^this.staggerEven?n.set(t,e+1):n.set(t-1,e+1),n},e.prototype.bottomRight=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t+1,e+1):n.set(t+1,e):1&e^this.staggerEven?n.set(t+1,e+1):n.set(t,e+1),n},e.prototype.pixelToTileCoords=function(t,e,i){var n=i||new Vector2d;this.staggerX?t-=this.staggerEven?this.tilewidth:this.sideoffsetx:e-=this.staggerEven?this.tileheight:this.sideoffsety;var r,o,s,a,h=pool.pull("Vector2d",Math.floor(t/(2*this.columnwidth)),Math.floor(e/(2*this.rowheight))),l=pool.pull("Vector2d",t-h.x*(2*this.columnwidth),e-h.y*(2*this.rowheight));this.staggerX?(h.x=2*h.x,this.staggerEven&&++h.x):(h.y=2*h.y,this.staggerEven&&++h.y),this.staggerX?(s=(r=this.sidelengthx/2)+this.columnwidth,a=this.tileheight/2,this.centers[0].set(r,a),this.centers[1].set(s,a-this.rowheight),this.centers[2].set(s,a+this.rowheight),this.centers[3].set(s+this.columnwidth,a)):(o=this.sidelengthy/2,s=this.tilewidth/2,a=o+this.rowheight,this.centers[0].set(s,o),this.centers[1].set(s-this.columnwidth,a),this.centers[2].set(s+this.columnwidth,a),this.centers[3].set(s,a+this.rowheight));for(var u=0,c=Number.MAX_VALUE,d=0;d<4;++d){var p=this.centers[d].sub(l).length2();p<c&&(c=p,u=d)}var f=this.staggerX?offsetsStaggerX:offsetsStaggerY;return n.set(h.x+f[u].x,h.y+f[u].y),pool.push(h),pool.push(l),n},e.prototype.tileToPixelCoords=function(t,e,i){var n=Math.floor(t),r=Math.floor(e),o=i||new Vector2d;return this.staggerX?(o.y=r*(this.tileheight+this.sidelengthy),this.doStaggerX(n)&&(o.y+=this.rowheight),o.x=n*this.columnwidth):(o.x=n*(this.tilewidth+this.sidelengthx),this.doStaggerY(r)&&(o.x+=this.columnwidth),o.y=r*this.rowheight),o},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset,o=this.tileToPixelCoords(e,i,pool.pull("Vector2d"));r.drawTile(t,r.tileoffset.x+o.x,r.tileoffset.y+o.y+(this.tileheight-r.tileheight),n),pool.push(o)},e.prototype.drawTileLayer=function(t,e,i){var n,r=this.pixelToTileCoords(i.pos.x,i.pos.y,pool.pull("Vector2d"));r.sub(e.pos);var o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y,pool.pull("Vector2d")),s=r.clone(),a=o.clone(),h=i.pos.y-o.y<this.sideoffsety,l=i.pos.x-o.x<this.sideoffsetx;h&&r.y--,l&&r.x--;var u=e.cols,c=e.rows;if(this.staggerX){r.x=Math.max(0,r.x),r.y=Math.max(0,r.y),o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y);for(var d=this.doStaggerX(r.x+e.pos.x);o.y<i.bottom&&r.y<c;){for(s.setV(r),a.setV(o);a.x<i.right&&s.x<u;s.x+=2)(n=e.cellAt(s.x,s.y,!1))&&n.tileset.drawTile(t,a.x,a.y,n),a.x+=this.tilewidth+this.sidelengthx;d?(r.x-=1,r.y+=1,o.x-=this.columnwidth,d=!1):(r.x+=1,o.x+=this.columnwidth,d=!0),o.y+=this.rowheight}pool.push(s),pool.push(a)}else{for(r.x=Math.max(0,r.x),r.y=Math.max(0,r.y),o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y),this.doStaggerY(r.y)&&(o.x-=this.columnwidth);o.y<i.bottom&&r.y<c;r.y++){for(s.setV(r),a.setV(o),this.doStaggerY(r.y)&&(a.x+=this.columnwidth);a.x<i.right&&s.x<u;s.x++)(n=e.cellAt(s.x,s.y,!1))&&n.tileset.drawTile(t,a.x,a.y,n),a.x+=this.tilewidth+this.sidelengthx;o.y+=this.rowheight}pool.push(s),pool.push(a)}pool.push(r),pool.push(o)},e}(TMXRenderer),TMXStaggeredRenderer=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"staggered"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){var n=i||new Vector2d,r=t,o=e;this.staggerX?r-=this.staggerEven?this.sideoffsetx:0:o-=this.staggerEven?this.sideoffsety:0;var s=pool.pull("Vector2d",Math.floor(r/this.tilewidth),Math.floor(o/this.tileheight));this.staggerX?(s.x=2*s.x,this.staggerEven&&++s.x):(s.y=2*s.y,this.staggerEven&&++s.y);var a=pool.pull("Vector2d",r-s.x*this.tilewidth,o-s.y*this.tileheight),h=a.x*(this.tileheight/this.tilewidth);return this.sideoffsety-h>a.y&&(s=this.topLeft(s.x,s.y,s)),-this.sideoffsety+h>a.y&&(s=this.topRight(s.x,s.y,s)),this.sideoffsety+h<a.y&&(s=this.bottomLeft(s.x,s.y,s)),3*this.sideoffsety-h<a.y&&(s=this.bottomRight(s.x,s.y,s)),(n=this.tileToPixelCoords(s.x,s.y,n)).set(t-n.x,e-n.y),n.set(n.x-this.tilewidth/2,n.y*(this.tilewidth/this.tileheight)),n.div(this.tilewidth/Math.sqrt(2)).rotate(degToRad(-45)).add(s),pool.push(s),pool.push(a),n},e}(TMXHexagonalRenderer),TMXTileset=function(t){var e=0;if(this.TileProperties=[],this.imageCollection=[],this.firstgid=this.lastgid=+t.firstgid,void 0!==t.source){var i=t.source,n=utils$1.file.getExtension(i);if(("tsx"===n||"json"===n)&&!(t=loader$1.getTMX(utils$1.file.getBasename(i))))throw new Error(i+" external TSX/JSON tileset not found")}this.name=t.name,this.tilewidth=+t.tilewidth,this.tileheight=+t.tileheight,this.spacing=+t.spacing||0,this.margin=+t.margin||0,this.tileoffset=new Vector2d,this.isAnimated=!1,this.isCollection=!1,this.animations=new Map,this._lastUpdate=0;var r=t.tiles;for(e in r)if(r.hasOwnProperty(e)){if("animation"in r[e]&&(this.isAnimated=!0,this.animations.set(r[+e].animation[0].tileid,{dt:0,idx:0,frames:r[+e].animation,cur:r[+e].animation[0]})),"properties"in r[e])if(Array.isArray(r[e].properties)){var o={};for(var s in r[e].properties)o[r[e].properties[s].name]=r[e].properties[s].value;this.setTileProperty(+r[e].id+this.firstgid,o)}else this.setTileProperty(+e+this.firstgid,r[e].properties);if("image"in r[e]){var a=loader$1.getImage(r[e].image);if(!a)throw new Error("melonJS: '"+r[e].image+"' file for tile '"+(+e+this.firstgid)+"' not found!");this.imageCollection[+e+this.firstgid]=a}}this.isCollection=this.imageCollection.length>0;var h=t.tileoffset;h&&(this.tileoffset.x=+h.x,this.tileoffset.y=+h.y);var l=t.tileproperties;if(l)for(e in l)l.hasOwnProperty(e)&&this.setTileProperty(+e+this.firstgid,l[e]);if(!1===this.isCollection){if(this.image=loader$1.getImage(t.image),!this.image)throw new Error("melonJS: '"+t.image+"' file for tileset '"+this.name+"' not found!");this.texture=video$1.renderer.cache.get(this.image,{framewidth:this.tilewidth,frameheight:this.tileheight,margin:this.margin,spacing:this.spacing}),this.atlas=this.texture.getAtlas();var u=+t.columns||Math.round(this.image.width/(this.tilewidth+this.spacing)),c=Math.round(this.image.height/(this.tileheight+this.spacing));t.tilecount%u>0&&++c,this.lastgid=this.firstgid+(u*c-1||0),t.tilecount&&this.lastgid-this.firstgid+1!=+t.tilecount&&console.warn("Computed tilecount ("+(this.lastgid-this.firstgid+1)+") does not match expected tilecount ("+t.tilecount+")")}};TMXTileset.prototype.getTileImage=function(t){return this.imageCollection[t]},TMXTileset.prototype.setTileProperty=function(t,e){this.TileProperties[t]=e},TMXTileset.prototype.contains=function(t){return t>=this.firstgid&&t<=this.lastgid},TMXTileset.prototype.getViewTileId=function(t){var e=t-this.firstgid;return this.animations.has(e)?this.animations.get(e).cur.tileid:e},TMXTileset.prototype.getTileProperties=function(t){return this.TileProperties[t]},TMXTileset.prototype.update=function(t){var e=0,i=timer$1.getTime(),n=!1;return this._lastUpdate!==i&&(this._lastUpdate=i,this.animations.forEach((function(i){for(i.dt+=t,e=i.cur.duration;i.dt>=e;)i.dt-=e,i.idx=(i.idx+1)%i.frames.length,i.cur=i.frames[i.idx],e=i.cur.duration,n=!0}))),n},TMXTileset.prototype.drawTile=function(t,e,i,n){if(n.flipped&&(t.save(),t.translate(e,i),t.transform(n.currentTransform),e=i=0),!0===this.isCollection)t.drawImage(this.imageCollection[n.tileId],0,0,n.width,n.height,e,i,n.width,n.height);else{var r=this.atlas[this.getViewTileId(n.tileId)].offset;t.drawImage(this.image,r.x,r.y,this.tilewidth,this.tileheight,e,i,this.tilewidth+t.uvOffset,this.tileheight+t.uvOffset)}n.flipped&&t.restore()};var TMX_CLEAR_BIT_MASK=536870911,TMXTilesetGroup=function(){this.tilesets=[],this.length=0};TMXTilesetGroup.prototype.add=function(t){this.tilesets.push(t),this.length++},TMXTilesetGroup.prototype.getTilesetByIndex=function(t){return this.tilesets[t]},TMXTilesetGroup.prototype.getTilesetByGid=function(t){var e=-1;t&=TMX_CLEAR_BIT_MASK;for(var i=0,n=this.tilesets.length;i<n;i++){if(this.tilesets[i].contains(t))return this.tilesets[i];this.tilesets[i].firstgid===this.tilesets[i].lastgid&&t>=this.tilesets[i].firstgid&&(e=i)}if(-1!==e)return this.tilesets[e];throw new Error("no matching tileset found for gid "+t)};var TMXObject=function(t,e,i){this.points=void 0,this.name=e.name,this.x=+e.x,this.y=+e.y,this.z=+i,this.width=+e.width||0,this.height=+e.height||0,this.gid=+e.gid||null,this.tintcolor=e.tintcolor,this.type=e.type,this.type=e.type,this.rotation=degToRad(+e.rotation||0),this.id=+e.id||void 0,this.orientation=t.orientation,this.shapes=void 0,this.isEllipse=!1,this.isPolygon=!1,this.isPolyLine=!1,"number"==typeof this.gid?this.setTile(t.tilesets):void 0!==e.ellipse?this.isEllipse=!0:void 0!==e.polygon?(this.points=e.polygon,this.isPolygon=!0):void 0!==e.polyline&&(this.points=e.polyline,this.isPolyLine=!0),void 0!==e.text?(this.text=e.text,this.text.font=e.text.fontfamily||"sans-serif",this.text.size=e.text.pixelsize||16,this.text.fillStyle=e.text.color||"#000000",this.text.textAlign=e.text.halign||"left",this.text.textBaseline=e.text.valign||"top",this.text.width=this.width,this.text.height=this.height,applyTMXProperties(this.text,e)):(applyTMXProperties(this,e),this.shapes||(this.shapes=this.parseTMXShapes())),t.isEditor||t.getRenderer().adjustPosition(this)};TMXObject.prototype.setTile=function(t){var e=t.getTilesetByGid(this.gid);!1===e.isCollection&&(this.width=this.framewidth=e.tilewidth,this.height=this.frameheight=e.tileheight),this.tile=new Tile(this.x,this.y,this.gid,e)},TMXObject.prototype.parseTMXShapes=function(){var t=0,e=[];if(!0===this.isEllipse)e.push(new Ellipse(this.width/2,this.height/2,this.width,this.height).rotate(this.rotation));else if(!0===this.isPolygon)e.push(new Polygon(0,0,this.points).rotate(this.rotation));else if(!0===this.isPolyLine){var i,n,r=this.points,o=r.length-1;for(t=0;t<o;t++)i=new Vector2d(r[t].x,r[t].y),n=new Vector2d(r[t+1].x,r[t+1].y),0!==this.rotation&&(i=i.rotate(this.rotation),n=n.rotate(this.rotation)),e.push(new Line(0,0,[i,n]))}else e.push(new Polygon(0,0,[new Vector2d,new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)]).rotate(this.rotation));if("isometric"===this.orientation)for(t=0;t<e.length;t++)e[t].toIso();return e},TMXObject.prototype.getObjectPropertyByName=function(t){return this[t]};var TMXGroup=function(t,e,i){this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.tintcolor=e.tintcolor,this.z=i,this.objects=[];var n=void 0===e.visible||e.visible;this.opacity=!0===n?clamp(+e.opacity||1,0,1):0,applyTMXProperties(this,e);var r=this;e.objects&&e.objects.forEach((function(e){e.tintcolor=r.tintcolor,r.objects.push(new TMXObject(t,e,i))}));e.layers&&e.layers.forEach((function(e){var n=new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i++);n.setRenderer(t.getRenderer()),r.width=Math.max(r.width,n.width),r.height=Math.max(r.height,n.height),r.objects.push(n)}))};TMXGroup.prototype.destroy=function(){this.objects=null},TMXGroup.prototype.getObjectCount=function(){return this.objects.length},TMXGroup.prototype.getObjectByIndex=function(t){return this.objects[t]};var COLLISION_GROUP="collision",onresize_handler=null;function getNewDefaultRenderer(t){switch(t.orientation){case"orthogonal":return new TMXOrthogonalRenderer(t);case"isometric":return new TMXIsometricRenderer(t);case"hexagonal":return new TMXHexagonalRenderer(t);case"staggered":return new TMXStaggeredRenderer(t);default:throw new Error(t.orientation+" type TMX Tile Map not supported!")}}function readLayer(t,e,i){return new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i)}function readImageLayer(t,e,i){applyTMXProperties(e.properties,e);var n=pool.pull("ImageLayer",+e.offsetx||+e.x||0,+e.offsety||+e.y||0,Object.assign({name:e.name,image:e.image,z:i},e.properties)),r=void 0===e.visible||e.visible;return n.setOpacity(r?+e.opacity:0),n}function readTileset(t){return new TMXTileset(t)}function readObjectGroup(t,e,i){return new TMXGroup(t,e,i)}var TMXTileMap=function(t,e){if(this.data=e,this.name=t,this.cols=+e.width,this.rows=+e.height,this.tilewidth=+e.tilewidth,this.tileheight=+e.tileheight,this.infinite=+e.infinite,this.orientation=e.orientation,this.renderorder=e.renderorder||"right-down",this.version=e.version,this.tiledversion=e.tiledversion,this.tilesets=null,void 0===this.layers&&(this.layers=[]),void 0===this.objectGroups&&(this.objectGroups=[]),this.isEditor="melon-editor"===e.editor,this.nextobjectid=+e.nextobjectid||void 0,this.hexsidelength=+e.hexsidelength,this.staggeraxis=e.staggeraxis,this.staggerindex=e.staggerindex,this.bounds=this.getRenderer().getBounds().clone(),this.width=this.bounds.width,this.height=this.bounds.height,this.backgroundcolor=e.backgroundcolor,applyTMXProperties(this,e),this.initialized=!1,1===this.infinite)throw new Error("Tiled Infinite Map not supported!")};TMXTileMap.prototype.getRenderer=function(){return void 0!==this.renderer&&this.renderer.canRender(this)||(this.renderer=getNewDefaultRenderer(this)),this.renderer},TMXTileMap.prototype.getBounds=function(){return this.bounds},TMXTileMap.prototype.readMapObjects=function(t){if(!0!==this.initialized){var e=0,i=this;if(this.tilesets||(this.tilesets=new TMXTilesetGroup),void 0!==t.tilesets)t.tilesets.forEach((function(t){i.tilesets.add(readTileset(t))}));this.backgroundcolor&&this.layers.push(pool.pull("ColorLayer","background_color",this.backgroundcolor,e++)),this.background_image&&this.layers.push(pool.pull("ImageLayer",0,0,{name:"background_image",image:this.background_image,z:e++})),t.layers.forEach((function(t){switch(t.type){case"imagelayer":i.layers.push(readImageLayer(i,t,e++));break;case"tilelayer":i.layers.push(readLayer(i,t,e++));break;case"objectgroup":case"group":i.objectGroups.push(readObjectGroup(i,t,e++))}})),this.initialized=!0}},TMXTileMap.prototype.addTo=function(t,e,i){var n=t.autoSort,r=t.autoDepth,o=this.getBounds();function s(e,i){game$1.viewport.setBounds(0,0,Math.max(o.width,e),Math.max(o.height,i)),t.pos.set(Math.max(0,~~((e-o.width)/2)),Math.max(0,~~((i-o.height)/2)),t.pos.z)}t.autoSort=!1,t.autoDepth=!1,this.getLayers().forEach((function(e){t.addChild(e)})),this.getObjects(e).forEach((function(e){t.addChild(e)})),t.resize(this.bounds.width,this.bounds.height),t.sort(!0),!0===i&&(s(game$1.viewport.width,game$1.viewport.height),onresize_handler&&event.unsubscribe(onresize_handler),onresize_handler=event.subscribe(event.VIEWPORT_ONRESIZE,s)),t.autoSort=n,t.autoDepth=r},TMXTileMap.prototype.getObjects=function(t){var e,i=[],n=!1;this.readMapObjects(this.data);for(var r=0;r<this.objectGroups.length;r++){var o=this.objectGroups[r];n=o.name.toLowerCase().includes(COLLISION_GROUP),!1===t&&((e=new Container$1(0,0,this.width,this.height)).anchorPoint.set(0,0),e.name=o.name,e.pos.z=o.z,e.setOpacity(o.opacity),e.autoSort=!1,e.autoDepth=!1);for(var s=0;s<o.objects.length;s++){var a,h=o.objects[s];void 0===h.anchorPoint&&(h.anchorPoint={x:0,y:0}),void 0!==h.tintcolor&&(h.tint=pool.pull("Color"),h.tint.parseHex(h.tintcolor,!0)),h instanceof TMXLayer?a=h:"object"==typeof h.text?(void 0===h.text.anchorPoint&&(h.text.anchorPoint=h.anchorPoint),(a=!0===h.text.bitmap?pool.pull("BitmapText",h.x,h.y,h.text):pool.pull("Text",h.x,h.y,h.text)).pos.z=h.z):"object"==typeof h.tile?((a=h.tile.getRenderable(h)).body=new Body(a,h.shapes||new Rect(0,0,this.width,this.height)),a.pos.setMuted(h.x,h.y,h.z)):(void 0!==h.name&&""!==h.name?a=pool.pull(h.name,h.x,h.y,h):((a=pool.pull("Renderable",h.x,h.y,h.width,h.height)).anchorPoint.set(0,0),a.name=h.name,a.type=h.type,a.id=h.id,a.body=new Body(a,h.shapes||new Rect(0,0,a.width,a.height)),a.resize(a.body.getBounds().width,a.body.getBounds().height)),a.pos.z=h.z),n&&!h.name&&a.body&&(a.body.collisionType=collision.types.WORLD_SHAPE),!1!==t?(!0===a.isRenderable&&(a.setOpacity(a.getOpacity()*o.opacity),a.renderable instanceof Renderable&&a.renderable.setOpacity(a.renderable.getOpacity()*o.opacity)),i.push(a)):e.addChild(a)}!1===t&&e.children.length>0&&(e.autoSort=!0,e.autoDepth=!0,i.push(e))}return i},TMXTileMap.prototype.getLayers=function(){return this.readMapObjects(this.data),this.layers},TMXTileMap.prototype.destroy=function(){this.tilesets=void 0,this.layers.length=0,this.objectGroups.length=0,this.initialized=!1};var levels={},levelIdx=[],currentLevelIdx=0;function safeLoadLevel(t,e,i){e.container.reset(),game$1.reset(),levels[level.getCurrentLevelId()]&&levels[level.getCurrentLevelId()].destroy(),currentLevelIdx=levelIdx.indexOf(t),loadTMXLevel(t,e.container,e.flatten,e.setViewportBounds),event.publish(event.LEVEL_LOADED,[t]),e.onLoaded(t),i&&state$1.restart()}function loadTMXLevel(t,e,i,n){var r=levels[t];utils$1.resetGUID(t,r.nextobjectid),e.anchorPoint.set(0,0),r.addTo(e,i,n)}var level={add:function(t,e,i){if("tmx"===t)return null==levels[e]&&(levels[e]=new TMXTileMap(e,loader$1.getTMX(e)),levelIdx.push(e),i&&i(),!0);throw new Error("no level loader defined for format "+t)},load:function(t,e){if(e=Object.assign({container:game$1.world,onLoaded:game$1.onLevelLoaded,flatten:game$1.mergeGroup,setViewportBounds:!0},e||{}),void 0===levels[t])throw new Error("level "+t+" not found");if(!(levels[t]instanceof TMXTileMap))throw new Error("no level loader defined");return state$1.isRunning()?(state$1.stop(),utils$1.function.defer(safeLoadLevel,this,t,e,!0)):safeLoadLevel(t,e),!0},getCurrentLevelId:function(){return levelIdx[currentLevelIdx]},getCurrentLevel:function(){return levels[this.getCurrentLevelId()]},reload:function(t){return this.load(this.getCurrentLevelId(),t)},next:function(t){return currentLevelIdx+1<levelIdx.length&&this.load(levelIdx[currentLevelIdx+1],t)},previous:function(t){return currentLevelIdx-1>=0&&this.load(levelIdx[currentLevelIdx-1],t)},levelCount:function(){return levelIdx.length}},imgList={},tmxList={},binList={},jsonList={},baseURL={},resourceCount=0,loadCount=0,timerId$1=0;function checkLoadStatus(t){if(loadCount===resourceCount){if(!t&&!loader.onload)throw new Error("no load callback defined");clearTimeout(timerId$1);var e=t||loader.onload;setTimeout((function(){e(),event.publish(event.LOADER_COMPLETE)}),300)}else timerId$1=setTimeout((function(){checkLoadStatus(t)}),100)}function preloadImage(t,e,i){imgList[t.name]=new Image,imgList[t.name].onload=e,imgList[t.name].onerror=i,"string"==typeof loader.crossOrigin&&(imgList[t.name].crossOrigin=loader.crossOrigin),imgList[t.name].src=t.src+loader.nocache}function preloadFontFace(t,e,i){var n=new FontFace(t.name,t.src);n.load().then((function(){document.fonts.add(n),document.body.style.fontFamily=t.name,e()}),(function(e){i(t.name)}))}function preloadTMX(t,e,i){function n(e){tmxList[t.name]=e,"tmx"===t.type&&level.add(t.type,t.name)}if(t.data)return n(t.data),void e();var r=new XMLHttpRequest,o=utils$1.file.getExtension(t.src);r.overrideMimeType&&("json"===o?r.overrideMimeType("application/json"):r.overrideMimeType("text/xml")),r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.ontimeout=i,r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status||0===r.status&&r.responseText){var s=null;switch(o){case"xml":case"tmx":case"tsx":if(device$1.ua.match(/msie/i)||!r.responseXML){if(!window.DOMParser)throw new Error("XML file format loading not supported, use the JSON file format instead");s=(new DOMParser).parseFromString(r.responseText,"text/xml")}else s=r.responseXML;var a=parse(s);switch(o){case"tmx":s=a.map;break;case"tsx":s=a.tilesets[0]}break;case"json":s=JSON.parse(r.responseText);break;default:throw new Error("TMX file format "+o+"not supported !")}n(s),e()}else i(t.name)},r.send()}function preloadJSON(t,e,i){var n=new XMLHttpRequest;n.overrideMimeType&&n.overrideMimeType("application/json"),n.open("GET",t.src+loader.nocache,!0),n.withCredentials=loader.withCredentials,n.ontimeout=i,n.onreadystatechange=function(){4===n.readyState&&(200===n.status||0===n.status&&n.responseText?(jsonList[t.name]=JSON.parse(n.responseText),e()):i(t.name))},n.send()}function preloadBinary(t,e,i){var n=new XMLHttpRequest;n.open("GET",t.src+loader.nocache,!0),n.withCredentials=loader.withCredentials,n.responseType="arraybuffer",n.onerror=i,n.onload=function(){var i=n.response;if(i){for(var r=new Uint8Array(i),o=[],s=0;s<r.byteLength;s++)o[s]=String.fromCharCode(r[s]);binList[t.name]=o.join(""),e()}},n.send()}function preloadJavascript(t,e,i){var n=document.createElement("script");n.src=t.src,n.type="text/javascript","string"==typeof loader.crossOrigin&&(n.crossOrigin=loader.crossOrigin),n.defer=!0,n.onload=function(){e()},n.onerror=function(){i(t.name)},document.getElementsByTagName("body")[0].appendChild(n)}var loader={nocache:"",onload:void 0,onProgress:void 0,crossOrigin:void 0,withCredentials:!1,onResourceLoaded:function(t){var e=++loadCount/resourceCount;this.onProgress&&this.onProgress(e,t),event.publish(event.LOADER_PROGRESS,[e,t])},onLoadingError:function(t){throw new Error("Failed loading resource "+t.src)},setNocache:function(t){this.nocache=t?"?"+~~(1e7*Math.random()):""},setBaseURL:function(t,e){"*"!==t?baseURL[t]=e:(baseURL.audio=e,baseURL.binary=e,baseURL.image=e,baseURL.json=e,baseURL.js=e,baseURL.tmx=e,baseURL.tsx=e)},preload:function(t,e,i){for(var n=0;n<t.length;n++)resourceCount+=this.load(t[n],this.onResourceLoaded.bind(this,t[n]),this.onLoadingError.bind(this,t[n]));void 0!==e&&(this.onload=e),!1!==i&&state$1.change(state$1.LOADING),checkLoadStatus(e)},load:function(t,e,i){switch(void 0!==baseURL[t.type]&&(t.src=baseURL[t.type]+t.src),t.type){case"binary":return preloadBinary.call(this,t,e,i),1;case"image":return preloadImage.call(this,t,e,i),1;case"json":return preloadJSON.call(this,t,e,i),1;case"js":return preloadJavascript.call(this,t,e,i),1;case"tmx":case"tsx":return preloadTMX.call(this,t,e,i),1;case"audio":return audio$1.load(t,!!t.stream,e,i),1;case"fontface":return preloadFontFace.call(this,t,e,i),1;default:throw new Error("load : unknown or invalid resource type : "+t.type)}},unload:function(t){switch(t.type){case"binary":return t.name in binList&&(delete binList[t.name],!0);case"image":return t.name in imgList&&(delete imgList[t.name],!0);case"json":return t.name in jsonList&&(delete jsonList[t.name],!0);case"js":case"fontface":return!0;case"tmx":case"tsx":return t.name in tmxList&&(delete tmxList[t.name],!0);case"audio":return audio$1.unload(t.name);default:throw new Error("unload : unknown or invalid resource type : "+t.type)}},unloadAll:function(){var t;for(t in binList)binList.hasOwnProperty(t)&&this.unload({name:t,type:"binary"});for(t in imgList)imgList.hasOwnProperty(t)&&this.unload({name:t,type:"image"});for(t in tmxList)tmxList.hasOwnProperty(t)&&this.unload({name:t,type:"tmx"});for(t in jsonList)jsonList.hasOwnProperty(t)&&this.unload({name:t,type:"json"});audio$1.unloadAll()},getTMX:function(t){return(t=""+t)in tmxList?tmxList[t]:null},getBinary:function(t){return(t=""+t)in binList?binList[t]:null},getImage:function(t){return(t=utils$1.file.getBasename(""+t))in imgList?imgList[t]:null},getJSON:function(t){return(t=""+t)in jsonList?jsonList[t]:null},getLoadProgress:function(){return loadCount/resourceCount}},loader$1=loader,audioTracks={},current_track_id=null,retry_counter=0,soundLoadError=function(t,e){if(retry_counter++>3){var i="melonJS: failed loading "+t;if(!1!==audio.stopOnAudioError)throw new Error(i);audio.disable(),e&&e(),console.log(i+", disabling audio")}else audioTracks[t].load()},audio={stopOnAudioError:!0,init:function(t){if(!exports.initialized)throw new Error("me.audio.init() called before engine initialization.");return t="string"==typeof t?t:"mp3",this.audioFormats=t.split(","),!howler.Howler.noAudio},hasFormat:function(t){return this.hasAudio&&howler.Howler.codecs(t)},hasAudio:function(){return!howler.Howler.noAudio},enable:function(){this.unmuteAll()},disable:function(){this.muteAll()},load:function(t,e,i,n){var r=[];if(void 0===this.audioFormats||0===this.audioFormats.length)throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");for(var o=0;o<this.audioFormats.length;o++)r.push(t.src+t.name+"."+this.audioFormats[o]+loader$1.nocache);return audioTracks[t.name]=new howler.Howl({src:r,volume:howler.Howler.volume(),html5:!0===e,xhrWithCredentials:loader$1.withCredentials,onloaderror:function(){soundLoadError.call(this,t.name,n)},onload:function(){retry_counter=0,i&&i()}}),1},play:function(t,e,i,n){void 0===e&&(e=!1);var r=audioTracks[t];if(r&&void 0!==r){var o=r.play();return"boolean"==typeof e&&r.loop(e,o),r.volume("number"==typeof n?clamp(n,0,1):howler.Howler.volume(),o),"function"==typeof i&&(!0===e?r.on("end",i,o):r.once("end",i,o)),o}throw new Error("audio clip "+t+" does not exist")},fade:function(t,e,i,n,r){var o=audioTracks[t];if(!o||void 0===o)throw new Error("audio clip "+t+" does not exist");o.fade(e,i,n,r)},seek:function(t,e,i){var n=audioTracks[t];if(n&&void 0!==n)return n.seek.apply(n,Array.prototype.slice.call(arguments,1));throw new Error("audio clip "+t+" does not exist")},rate:function(t,e,i){var n=audioTracks[t];if(n&&void 0!==n)return n.rate.apply(n,Array.prototype.slice.call(arguments,1));throw new Error("audio clip "+t+" does not exist")},stop:function(t,e){if(void 0!==t){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.stop(e),i.off("end",void 0,e)}else howler.Howler.stop()},pause:function(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.pause(e)},resume:function(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.play(e)},playTrack:function(t,e){return current_track_id=t,this.play(current_track_id,!0,null,e)},stopTrack:function(){null!==current_track_id&&(audioTracks[current_track_id].stop(),current_track_id=null)},pauseTrack:function(){null!==current_track_id&&audioTracks[current_track_id].pause()},resumeTrack:function(){null!==current_track_id&&audioTracks[current_track_id].play()},getCurrentTrack:function(){return current_track_id},setVolume:function(t){howler.Howler.volume(t)},getVolume:function(){return howler.Howler.volume()},mute:function(t,e,i){i=void 0===i||!!i;var n=audioTracks[t];if(!n||void 0===n)throw new Error("audio clip "+t+" does not exist");n.mute(i,e)},unmute:function(t,e){this.mute(t,e,!1)},muteAll:function(){howler.Howler.mute(!0)},unmuteAll:function(){howler.Howler.mute(!1)},muted:function(){return howler.Howler._muted},unload:function(t){return t in audioTracks&&(audioTracks[t].unload(),delete audioTracks[t],!0)},unloadAll:function(){for(var t in audioTracks)audioTracks.hasOwnProperty(t)&&this.unload(t)}},audio$1=audio,data={};function isReserved(t){return"add"===t||"remove"===t}var save={init:function(){if(!0===device$1.localStorage){var t=localStorage.getItem("me.save");if("string"==typeof t&&t.length>0)(JSON.parse(t)||[]).forEach((function(t){data[t]=JSON.parse(localStorage.getItem("me.save."+t))}))}},add:function(t){var e=save;Object.keys(t).forEach((function(i){var n;isReserved(i)||(n=i,Object.defineProperty(e,n,{configurable:!0,enumerable:!0,get:function(){return data[n]},set:function(t){data[n]=t,!0===device$1.localStorage&&localStorage.setItem("me.save."+n,JSON.stringify(t))}}),i in data||(e[i]=t[i]))})),!0===device$1.localStorage&&localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))},remove:function(t){isReserved(t)||void 0!==data[t]&&(delete data[t],!0===device$1.localStorage&&(localStorage.removeItem("me.save."+t),localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))))}},accelInitialized=!1,deviceOrientationInitialized=!1,swipeEnabled=!0;function disableSwipeFn(t){return t.preventDefault(),"function"==typeof window.scroll&&window.scroll(0,0),!1}var readyBound=!1,isReady=!1,readyList=[],_domRect={left:0,top:0,x:0,y:0,width:0,height:0,right:0,bottom:0},device={_domReady:function(t){if(!isReady){if(!document.body)return setTimeout(this._domReady,13);for(document.removeEventListener&&document.removeEventListener("DOMContentLoaded",this._domReady,!1),window.removeEventListener("load",this._domReady,!1);readyList.length;)readyList.shift().call(window,[]);isReady=!0}},_check:function(){this._detectDevice(),this.isMobile&&this.enableSwipe(!1),this.TouchEvent=!!("ontouchstart"in window),this.PointerEvent=!!window.PointerEvent,window.gesture=prefixed("gesture"),this.touch=this.TouchEvent||this.PointerEvent,this.maxTouchPoints=this.touch?this.PointerEvent?navigator.maxTouchPoints||1:10:1,this.wheel="onwheel"in document.createElement("div"),this.hasPointerLockSupport=prefixed("pointerLockElement",document),this.hasPointerLockSupport&&(document.exitPointerLock=prefixed("exitPointerLock",document)),this.hasDeviceOrientation=!!window.DeviceOrientationEvent,this.hasAccelerometer=!!window.DeviceMotionEvent,this.hasFullscreenSupport=prefixed("fullscreenEnabled",document)||document.mozFullScreenEnabled,document.exitFullscreen=prefixed("cancelFullScreen",document)||prefixed("exitFullscreen",document),navigator.vibrate=prefixed("vibrate",navigator),this.hasWebAudio=!(!window.AudioContext&&!window.webkitAudioContext);try{this.localStorage=!!window.localStorage}catch(t){this.localStorage=!1}try{this.OffscreenCanvas=void 0!==window.OffscreenCanvas&&null!==new OffscreenCanvas(0,0).getContext("2d")}catch(t){this.OffscreenCanvas=!1}var t,e;window.addEventListener("blur",(function(){this.stopOnBlur&&state$1.stop(!0),this.pauseOnBlur&&state$1.pause(!0)}),!1),window.addEventListener("focus",(function(){this.stopOnBlur&&state$1.restart(!0),this.resumeOnFocus&&state$1.resume(!0),this.autoFocus&&this.focus()}),!1),void 0!==document.hidden?(t="hidden",e="visibilitychange"):void 0!==document.mozHidden?(t="mozHidden",e="mozvisibilitychange"):void 0!==document.msHidden?(t="msHidden",e="msvisibilitychange"):void 0!==document.webkitHidden&&(t="webkitHidden",e="webkitvisibilitychange"),"string"==typeof e&&document.addEventListener(e,(function(){document[t]?(this.stopOnBlur&&state$1.stop(!0),this.pauseOnBlur&&state$1.pause(!0)):(this.stopOnBlur&&state$1.restart(!0),this.resumeOnFocus&&state$1.resume(!0))}),!1)},_detectDevice:function(){this.iOS=/iPhone|iPad|iPod/i.test(this.ua),this.android=/Android/i.test(this.ua),this.android2=/Android 2/i.test(this.ua),this.linux=/Linux/i.test(this.ua),this.chromeOS=/CrOS/.test(this.ua),this.wp=/Windows Phone/i.test(this.ua),this.BlackBerry=/BlackBerry/i.test(this.ua),this.Kindle=/Kindle|Silk.*Mobile Safari/i.test(this.ua),this.isMobile=/Mobi/i.test(this.ua)||this.iOS||this.android||this.wp||this.BlackBerry||this.Kindle||!1,this.ejecta=void 0!==window.ejecta,this.isWeixin=/MicroMessenger/i.test(this.ua)},ua:navigator.userAgent,localStorage:!1,hasAccelerometer:!1,hasDeviceOrientation:!1,hasFullscreenSupport:!1,hasPointerLockSupport:!1,hasWebAudio:!1,nativeBase64:"function"==typeof window.atob,maxTouchPoints:1,touch:!1,wheel:!1,isMobile:!1,iOS:!1,android:!1,android2:!1,linux:!1,ejecta:!1,isWeixin:!1,chromeOS:!1,wp:!1,BlackBerry:!1,Kindle:!1,accelerationX:0,accelerationY:0,accelerationZ:0,gamma:0,beta:0,alpha:0,language:navigator.language||navigator.browserLanguage||navigator.userLanguage||"en",pauseOnBlur:!0,resumeOnFocus:!0,autoFocus:!0,stopOnBlur:!1,OffscreenCanvas:!1,onReady:function(t){isReady?t.call(window,[]):(readyList.push(t),readyBound||("complete"===document.readyState?window.setTimeout(this._domReady,0):(document.addEventListener&&document.addEventListener("DOMContentLoaded",this._domReady,!1),window.addEventListener("load",this._domReady,!1)),readyBound=!0))},enableSwipe:function(t){!1!==t?!1===swipeEnabled&&(window.document.removeEventListener("touchmove",disableSwipeFn,!1),swipeEnabled=!0):!0===swipeEnabled&&(window.document.addEventListener("touchmove",disableSwipeFn,!1),swipeEnabled=!1)},requestFullscreen:function(t){this.hasFullscreenSupport&&((t=t||video$1.getParent()).requestFullscreen=prefixed("requestFullscreen",t)||t.mozRequestFullScreen,t.requestFullscreen())},exitFullscreen:function(){this.hasFullscreenSupport&&document.exitFullscreen()},getScreenOrientation:function(){var t="portrait",e="landscape",i=window.screen;if(void 0!==i){var n=prefixed("orientation",i);if(void 0!==n&&"string"==typeof n.type)return n.type;if("string"==typeof n)return n}return"number"==typeof window.orientation?90===Math.abs(window.orientation)?e:t:window.outerWidth>window.outerHeight?e:t},lockOrientation:function(t){var e=window.screen;if(void 0!==e){var i=prefixed("lockOrientation",e);if(void 0!==i)return i(t)}return!1},unlockOrientation:function(t){var e=window.screen;if(void 0!==e){var i=prefixed("unlockOrientation",e);if(void 0!==i)return i(t)}return!1},isPortrait:function(){return this.getScreenOrientation().includes("portrait")},isLandscape:function(){return this.getScreenOrientation().includes("landscape")},getStorage:function(t){if(void 0===t&&(t="local"),"local"===t)return save;throw new Error("storage type "+t+" not supported")},getParentElement:function(t){var e=this.getElement(t);return null!==e.parentNode&&(e=e.parentNode),e},getElement:function(t){var e=null;return"undefined"!==t&&("string"==typeof t?e=document.getElementById(t):"object"==typeof t&&t.nodeType===Node.ELEMENT_NODE&&(e=t)),e||(e=document.body),e},getElementBounds:function(t){return"object"==typeof t&&t!==document.body&&void 0!==t.getBoundingClientRect?t.getBoundingClientRect():(_domRect.width=_domRect.right=window.innerWidth,_domRect.height=_domRect.bottom=window.innerHeight,_domRect)},getParentBounds:function(t){return this.getElementBounds(this.getParentElement(t))},isWebGLSupported:function(t){var e=!1;try{var i=document.createElement("canvas"),n={stencil:!0,failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat};e=!(!window.WebGLRenderingContext||!i.getContext("webgl",n)&&!i.getContext("experimental-webgl",n))}catch(t){e=!1}return e},getMaxShaderPrecision:function(t){return t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0?"highp":t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"},focus:function(){"function"==typeof window.focus&&window.focus()},onDeviceMotion:function(t){this.accelerationX=t.accelerationIncludingGravity.x,this.accelerationY=t.accelerationIncludingGravity.y,this.accelerationZ=t.accelerationIncludingGravity.z},onDeviceRotate:function(t){this.gamma=t.gamma,this.beta=t.beta,this.alpha=t.alpha},turnOnPointerLock:function(){if(this.hasPointerLockSupport){var t=video$1.getParent();if(this.ua.match(/Firefox/i)){var e=function(){(prefixed("fullscreenElement",document)||document.mozFullScreenElement)===t&&(document.removeEventListener("fullscreenchange",e),document.removeEventListener("mozfullscreenchange",e),t.requestPointerLock=prefixed("requestPointerLock",t),t.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),this.requestFullscreen()}else t.requestPointerLock()}},turnOffPointerLock:function(){this.hasPointerLockSupport&&document.exitPointerLock()},watchAccelerometer:function(){var t=this;return this.hasAccelerometer&&!accelInitialized&&(DeviceOrientationEvent&&"function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(window.addEventListener("devicemotion",t.onDeviceMotion,!1),accelInitialized=!0)})).catch(console.error):(window.addEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!0)),accelInitialized},unwatchAccelerometer:function(){accelInitialized&&(window.removeEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!1)},watchDeviceOrientation:function(){var t=this;return this.hasDeviceOrientation&&!deviceOrientationInitialized&&("function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(window.addEventListener("deviceorientation",t.onDeviceRotate,!1),deviceOrientationInitialized=!0)})).catch(console.error):(window.addEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!0)),deviceOrientationInitialized},unwatchDeviceOrientation:function(){deviceOrientationInitialized&&(window.removeEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!1)},vibrate:function(t){navigator.vibrate&&navigator.vibrate(t)}};Object.defineProperty(device,"devicePixelRatio",{get:function(){return window.devicePixelRatio||1}}),Object.defineProperty(device,"isFullscreen",{get:function(){return!!this.hasFullscreenSupport&&!(!prefixed("fullscreenElement",document)&&!document.mozFullScreenElement)}}),Object.defineProperty(device,"sound",{get:function(){return audio$1.hasAudio()}});var device$1=device;function extractUniforms(t,e){var i,n={},r=/uniform\s+(\w+)\s+(\w+)/g,o={},s={},a={};return[e.vertex,e.fragment].forEach((function(t){for(;i=r.exec(t);)o[i[2]]=i[1]})),Object.keys(o).forEach((function(i){var n=o[i];a[i]=t.getUniformLocation(e.program,i),s[i]={get:function(t){return function(){return a[t]}}(i),set:function(e,i,n){return 0===i.indexOf("mat")?function(i){t[n](a[e],!1,i)}:function(i){var r=n;i.length&&"v"!==n.substr(-1)&&(r+="v"),t[r](a[e],i)}}(i,n,"uniform"+fnHash[n])}})),Object.defineProperties(n,s),n}function extractAttributes(t,e){for(var i,n={},r=/attribute\s+\w+\s+(\w+)/g,o=0;i=r.exec(e.vertex);)n[i[1]]=o++;return n}function compileShader(t,e,i){var n=t.createShader(e);if(t.shaderSource(n,i),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n));return n}function compileProgram(t,e,i,n){var r=compileShader(t,t.VERTEX_SHADER,e),o=compileShader(t,t.FRAGMENT_SHADER,i),s=t.createProgram();for(var a in t.attachShader(s,r),t.attachShader(s,o),n)t.bindAttribLocation(s,n[a],a);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var h="Error initializing Shader "+this+"\ngl.VALIDATE_STATUS: "+t.getProgramParameter(s,t.VALIDATE_STATUS)+"\ngl.getError()"+t.getError()+"\ngl.getProgramInfoLog()"+t.getProgramInfoLog(s);throw t.deleteProgram(s),s=null,new Error(h)}return t.useProgram(s),t.deleteShader(r),t.deleteShader(o),s}var fnHash={bool:"1i",int:"1i",float:"1f",vec2:"2fv",vec3:"3fv",vec4:"4fv",bvec2:"2iv",bvec3:"3iv",bvec4:"4iv",ivec2:"2iv",ivec3:"3iv",ivec4:"4iv",mat2:"Matrix2fv",mat3:"Matrix3fv",mat4:"Matrix4fv",sampler2D:"1i"};function setPrecision(t,e){return"precision"!==t.substring(0,9)?"precision "+e+" float;"+t:t}function minify(t){return t=(t=(t=(t=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1")).replace(/(\\n\s+)|(\s+\\n)/g,"")).replace(/(\\r|\\n)+/g,"")).replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g,"$1")}var GLShader=function(t,e,i,n){return this.gl=t,this.vertex=setPrecision(minify(e),n||device$1.getMaxShaderPrecision(this.gl)),this.fragment=setPrecision(minify(i),n||device$1.getMaxShaderPrecision(this.gl)),this.attributes=extractAttributes(this.gl,this),this.program=compileProgram(this.gl,this.vertex,this.fragment,this.attributes),this.uniforms=extractUniforms(this.gl,this),event.subscribe(event.WEBGL_ONCONTEXT_LOST,this.destroy.bind(this)),this};GLShader.prototype.bind=function(){this.gl.useProgram(this.program)},GLShader.prototype.getAttribLocation=function(t){var e=this.attributes[t];return void 0!==e?e:-1},GLShader.prototype.setUniform=function(t,e){var i=this.uniforms;if(void 0===i[t])throw new Error("undefined ("+t+") uniform for shader "+this);"object"==typeof e&&"function"==typeof e.toArray?i[t]=e.toArray():i[t]=e},GLShader.prototype.destroy=function(){this.uniforms=null,this.attributes=null,this.gl.deleteProgram(this.program),this.vertex=null,this.fragment=null};var primitiveVertex="// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\n// Vertex color\nuniform vec4 uColor;\n\n// Fragment color\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(uColor.rgb * uColor.a, uColor.a);\n}\n",primitiveFragment="varying vec4 vColor;\n\nvoid main(void) {\n gl_FragColor = vColor;\n}\n",quadVertex="attribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n",quadFragment="uniform sampler2D uSampler;\nvarying vec4 vColor;\nvarying vec2 vRegion;\n\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vRegion) * vColor;\n}\n",VERTEX_SIZE=2,REGION_SIZE=2,COLOR_SIZE=4,ELEMENT_SIZE=VERTEX_SIZE+REGION_SIZE+COLOR_SIZE,ELEMENT_OFFSET=ELEMENT_SIZE*Float32Array.BYTES_PER_ELEMENT,VERTEX_ELEMENT=0,REGION_ELEMENT=VERTEX_ELEMENT+VERTEX_SIZE,COLOR_ELEMENT=REGION_ELEMENT+REGION_SIZE,ELEMENTS_PER_QUAD=4,INDICES_PER_QUAD=6,MAX_LENGTH=16e3,WebGLCompositor=function(t){var e=t.gl;this.length=0,this.currentTextureUnit=-1,this.boundTextures=[],this.v=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.renderer=t,this.gl=t.gl,this.color=t.currentColor,this.tint=t.currentTint,this.viewMatrix=t.currentTransform,this.activeShader=null,this.mode=e.TRIANGLES,this.attributes=[],this.primitiveShader=new GLShader(this.gl,primitiveVertex,primitiveFragment),this.quadShader=new GLShader(this.gl,quadVertex,quadFragment),this.addAttribute("aVertex",2,e.FLOAT,!1,0*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aRegion",2,e.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aColor",4,e.FLOAT,!1,4*Float32Array.BYTES_PER_ELEMENT),e.bindBuffer(e.ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ARRAY_BUFFER,MAX_LENGTH*ELEMENT_OFFSET*ELEMENTS_PER_QUAD,e.STREAM_DRAW),this.sbSize=256,this.sbIndex=0,this.stream=new Float32Array(this.sbSize*ELEMENT_SIZE*ELEMENTS_PER_QUAD),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ELEMENT_ARRAY_BUFFER,this.createIB(),e.STATIC_DRAW),event.subscribe(event.CANVAS_ONRESIZE,function(t,e){this.flush(),this.setViewport(0,0,t,e)}.bind(this)),this.reset()};WebGLCompositor.prototype.reset=function(){this.sbIndex=0,this.length=0,this.gl=this.renderer.gl,this.flush(),this.setViewport(0,0,this.renderer.getScreenCanvas().width,this.renderer.getScreenCanvas().height),this.clearColor(0,0,0,0);for(var t=0;t<this.renderer.maxTextures;t++){var e=this.boundTextures[t];null!==e&&this.gl.deleteTexture(e),this.boundTextures[t]=null}this.currentTextureUnit=-1,this.useShader(this.quadShader)},WebGLCompositor.prototype.addAttribute=function(t,e,i,n,r){this.attributes.push({name:t,size:e,type:i,normalized:n,offset:r})},WebGLCompositor.prototype.setViewport=function(t,e,i,n){this.gl.viewport(t,e,i,n)},WebGLCompositor.prototype.createTexture2D=function(t,e,i,n,r,o,s,a,h){void 0===n&&(n="no-repeat"),void 0===a&&(a=!0),void 0===h&&(h=!0);var l=this.gl,u=isPowerOfTwo(r||e.width)&&isPowerOfTwo(o||e.height),c=l.createTexture(),d=0!==n.search(/^repeat(-x)?$/)||!u&&2!==this.renderer.WebGLVersion?l.CLAMP_TO_EDGE:l.REPEAT,p=0!==n.search(/^repeat(-y)?$/)||!u&&2!==this.renderer.WebGLVersion?l.CLAMP_TO_EDGE:l.REPEAT;return this.setTexture2D(c,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,d),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,p),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,i),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,i),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),r||o||s?l.texImage2D(l.TEXTURE_2D,0,l.RGBA,r,o,s,l.RGBA,l.UNSIGNED_BYTE,e):l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,e),u&&!1!==h&&l.generateMipmap(l.TEXTURE_2D),c},WebGLCompositor.prototype.setTexture2D=function(t,e){var i=this.gl;t!==this.boundTextures[e]?(this.flush(),this.currentTextureUnit!==e&&(this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,t),this.boundTextures[e]=t):this.currentTextureUnit!==e&&(this.flush(),this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e))},WebGLCompositor.prototype.uploadTexture=function(t,e,i,n,r){var o=this.renderer.cache.getUnit(t),s=this.boundTextures[o];return null===s||r?this.createTexture2D(o,t.getTexture(),this.renderer.settings.antiAlias?this.gl.LINEAR:this.gl.NEAREST,t.repeat,e,i,n,t.premultipliedAlpha):this.setTexture2D(s,o),this.currentTextureUnit},WebGLCompositor.prototype.createIB=function(){for(var t=[0,1,2,2,1,3],e=new Array(MAX_LENGTH*INDICES_PER_QUAD),i=0;i<e.length;i++)e[i]=t[i%INDICES_PER_QUAD]+~~(i/INDICES_PER_QUAD)*ELEMENTS_PER_QUAD;return new Uint16Array(e)},WebGLCompositor.prototype.resizeSB=function(){this.sbSize<<=1;var t=new Float32Array(this.sbSize*ELEMENT_SIZE*ELEMENTS_PER_QUAD);t.set(this.stream),this.stream=t},WebGLCompositor.prototype.useShader=function(t){if(this.activeShader!==t){this.flush(),this.activeShader=t,this.activeShader.bind(),this.activeShader.setUniform("uProjectionMatrix",this.renderer.projectionMatrix);for(var e=0;e<this.attributes.length;++e){var i=this.gl,n=this.attributes[e],r=this.activeShader.getAttribLocation(n.name);-1!==r?(i.enableVertexAttribArray(r),i.vertexAttribPointer(r,n.size,n.type,n.normalized,ELEMENT_OFFSET,n.offset)):i.disableVertexAttribArray(e)}}},WebGLCompositor.prototype.addQuad=function(t,e,i,n,r,o){var s=this.color.toArray(),a=this.tint.toArray();if(!(s[3]<1/255)){a[3]=s[3],this.length>=MAX_LENGTH&&this.flush(),this.length>=this.sbSize&&this.resizeSB(),this.useShader(this.quadShader);var h=this.uploadTexture(t);this.quadShader.setUniform("uSampler",h);var l=this.viewMatrix,u=this.v[0].set(i,n),c=this.v[1].set(i+r,n),d=this.v[2].set(i,n+o),p=this.v[3].set(i+r,n+o);l.isIdentity()||(l.apply(u),l.apply(c),l.apply(d),l.apply(p));var f=this.sbIndex,g=f+ELEMENT_SIZE,m=g+ELEMENT_SIZE,y=m+ELEMENT_SIZE;this.stream[f+VERTEX_ELEMENT+0]=u.x,this.stream[f+VERTEX_ELEMENT+1]=u.y,this.stream[g+VERTEX_ELEMENT+0]=c.x,this.stream[g+VERTEX_ELEMENT+1]=c.y,this.stream[m+VERTEX_ELEMENT+0]=d.x,this.stream[m+VERTEX_ELEMENT+1]=d.y,this.stream[y+VERTEX_ELEMENT+0]=p.x,this.stream[y+VERTEX_ELEMENT+1]=p.y;var v=t.getUVs(e);this.stream[f+REGION_ELEMENT+0]=v[0],this.stream[f+REGION_ELEMENT+1]=v[1],this.stream[g+REGION_ELEMENT+0]=v[2],this.stream[g+REGION_ELEMENT+1]=v[1],this.stream[m+REGION_ELEMENT+0]=v[0],this.stream[m+REGION_ELEMENT+1]=v[3],this.stream[y+REGION_ELEMENT+0]=v[2],this.stream[y+REGION_ELEMENT+1]=v[3],this.stream.set(a,f+COLOR_ELEMENT),this.stream.set(a,g+COLOR_ELEMENT),this.stream.set(a,m+COLOR_ELEMENT),this.stream.set(a,y+COLOR_ELEMENT),this.sbIndex+=ELEMENT_SIZE*ELEMENTS_PER_QUAD,this.length++}},WebGLCompositor.prototype.flush=function(){if(this.length){var t=this.gl,e=this.length*ELEMENT_SIZE*ELEMENTS_PER_QUAD;t.bufferData(t.ARRAY_BUFFER,this.stream.subarray(0,e),t.STREAM_DRAW),t.drawElements(this.mode,this.length*INDICES_PER_QUAD,t.UNSIGNED_SHORT,0),this.sbIndex=0,this.length=0}},WebGLCompositor.prototype.drawVertices=function(t,e,i){var n=this.gl;i=i||e.length,this.useShader(this.primitiveShader),this.primitiveShader.setUniform("uColor",this.color);for(var r=0,o=this.viewMatrix,s=o.isIdentity(),a=0;a<i;a++)s||o.apply(e[a]),this.stream[r+0]=e[a].x,this.stream[r+1]=e[a].y,r+=ELEMENT_SIZE;n.bufferData(n.ARRAY_BUFFER,this.stream.subarray(0,i*ELEMENT_SIZE),n.STREAM_DRAW),n.drawArrays(t,0,i)},WebGLCompositor.prototype.clearColor=function(t,e,i,n){this.gl.clearColor(t,e,i,n)},WebGLCompositor.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)};var WebGLRenderer=function(t){function e(e){t.call(this,e),this.context=this.gl=this.getContextGL(this.getScreenCanvas(),e.transparent),this.webGLVersion=1,this.GPUVendor=null,this.GPURenderer=null,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this._colorStack=[],this._matrixStack=[],this._scissorStack=[],this._glPoints=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.currentTransform=new Matrix2d,this.currentCompositor=null;var i=this.settings.compositor||WebGLCompositor;this.setCompositor(new i(this)),this.gl.disable(this.gl.DEPTH_TEST),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.enable(this.gl.BLEND),this.setBlendMode(this.settings.blendMode);var n=this.gl.getExtension("WEBGL_debug_renderer_info");null!==n&&(this.GPUVendor=this.gl.getParameter(n.UNMASKED_VENDOR_WEBGL),this.GPURenderer=this.gl.getParameter(n.UNMASKED_RENDERER_WEBGL)),this.cache=new TextureCache(this.maxTextures);var r=this;return this.getScreenCanvas().addEventListener("webglcontextlost",(function(t){event.preventDefault(),r.isContextValid=!1,event.publish(event.WEBGL_ONCONTEXT_LOST,[r])}),!1),this.getScreenCanvas().addEventListener("webglcontextrestored",(function(t){r.reset(),r.isContextValid=!0,event.publish(event.WEBGL_ONCONTEXT_RESTORED,[r])}),!1),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),!1===this.isContextValid?this.currentCompositor.init(this):this.currentCompositor.reset(),this.gl.disable(this.gl.SCISSOR_TEST),void 0!==this.fontContext2D&&this.createFontTexture(this.cache)},e.prototype.setCompositor=function(t){null!==this.currentCompositor&&this.currentCompositor!==t&&this.currentCompositor.flush(),this.currentCompositor=t},e.prototype.resetTransform=function(){this.currentTransform.identity()},e.prototype.createFontTexture=function(t){if(void 0===this.fontTexture){var e=this.backBufferCanvas,i=e.width,n=e.height;1===this.WebGLVersion&&(isPowerOfTwo(i)||(i=nextPowerOfTwo(e.width)),isPowerOfTwo(n)||(n=nextPowerOfTwo(e.height)));var r=video$1.createCanvas(i,n,!0);this.fontContext2D=this.getContext2d(r),this.fontTexture=new Texture(createAtlas(e.width,e.height,"fontTexture"),r,t),this.currentCompositor.uploadTexture(this.fontTexture,0,0,0)}else t.set(this.fontContext2D.canvas,this.fontTexture)},e.prototype.createPattern=function(t,e){if(!(1!==video$1.renderer.WebGLVersion||isPowerOfTwo(t.width)&&isPowerOfTwo(t.height))){var i=void 0!==t.src?t.src:t;throw new Error("[WebGL Renderer] "+i+" is not a POT texture ("+t.width+"x"+t.height+")")}var n=new Texture(createAtlas(t.width,t.height,"pattern",e),t);return this.currentCompositor.uploadTexture(n),n},e.prototype.flush=function(){this.currentCompositor.flush()},e.prototype.clearColor=function(t,e){var i;this.save(),i=t instanceof Color?t.toArray():this.getColor().parseCSS(t).toArray(),this.currentCompositor.clearColor(i[0],i[1],i[2],!0===e?1:i[3]),this.currentCompositor.clear(),this.currentCompositor.clearColor(0,0,0,0),this.restore()},e.prototype.clearRect=function(t,e,i,n){var r=this.currentColor.clone();this.currentColor.copy("#000000"),this.fillRect(t,e,i,n),this.currentColor.copy(r),pool.push(r)},e.prototype.drawFont=function(t){var e=this.getFontContext();this.currentCompositor.uploadTexture(this.fontTexture,0,0,0,!0);var i=t.left+","+t.top+","+t.width+","+t.height;this.currentCompositor.addQuad(this.fontTexture,i,t.left,t.top,t.width,t.height),e.clearRect(t.left,t.top,t.width,t.height)},e.prototype.drawImage=function(t,e,i,n,r,o,s,a,h){void 0===n?(n=a=t.width,r=h=t.height,o=e,s=i,e=0,i=0):void 0===o&&(o=e,s=i,a=n,h=r,n=t.width,r=t.height,e=0,i=0),!1===this.settings.subPixel&&(o|=0,s|=0);var l=e+","+i+","+n+","+r;this.currentCompositor.addQuad(this.cache.get(t),l,o,s,a,h)},e.prototype.drawPattern=function(t,e,i,n,r){var o="0,0,"+n+","+r;this.currentCompositor.addQuad(t,o,e,i,n,r)},e.prototype.getScreenContext=function(){return this.gl},e.prototype.getContextGL=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a GL context");"boolean"!=typeof e&&(e=!0);var i,n={alpha:e,antialias:this.settings.antiAlias,depth:!1,stencil:!0,preserveDrawingBuffer:!1,premultipliedAlpha:e,powerPreference:this.settings.powerPreference,failIfMajorPerformanceCaveat:this.settings.failIfMajorPerformanceCaveat};if(!1===this.settings.preferWebGL1&&(i=t.getContext("webgl2",n))&&(this.WebGLVersion=2),i||(this.WebGLVersion=1,i=t.getContext("webgl",n)||t.getContext("experimental-webgl",n)),!i)throw new Error("A WebGL context could not be created.");return i},e.prototype.getContext=function(){return this.gl},e.prototype.setBlendMode=function(t,e){if((e=e||this.gl).enable(e.BLEND),"multiply"===t)e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode=t;else e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode="normal"},e.prototype.getFontContext=function(){return void 0===this.fontContext2D&&(console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !"),this.createFontTexture(this.cache)),this.fontContext2D},e.prototype.restore=function(){if(0!==this._matrixStack.length){var t=this._colorStack.pop(),e=this._matrixStack.pop();this.currentColor.copy(t),this.currentTransform.copy(e),pool.push(t),pool.push(e)}0!==this._scissorStack.length?this.currentScissor.set(this._scissorStack.pop()):(this.gl.disable(this.gl.SCISSOR_TEST),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height)},e.prototype.save=function(){this._colorStack.push(this.currentColor.clone()),this._matrixStack.push(this.currentTransform.clone()),this.gl.isEnabled(this.gl.SCISSOR_TEST)&&this._scissorStack.push(this.currentScissor.slice())},e.prototype.rotate=function(t){this.currentTransform.rotate(t)},e.prototype.scale=function(t,e){this.currentTransform.scale(t,e)},e.prototype.setAntiAlias=function(e,i){t.prototype.setAntiAlias.call(this,e,i)},e.prototype.setGlobalAlpha=function(t){this.currentColor.glArray[3]=t},e.prototype.setColor=function(t){var e=this.currentColor.glArray[3];this.currentColor.copy(t),this.currentColor.glArray[3]*=e},e.prototype.setLineWidth=function(t){this.getScreenContext().lineWidth(t)},e.prototype.strokeArc=function(t,e,i,n,r,o,s){if(!0===s)this.fillArc(t,e,i,n,r,o);else{var a,h=this._glPoints,l=Math.floor(24*Math.sqrt(2*i)),u=(r-n)/(2*l),c=2*u,d=Math.cos(u),p=Math.sin(u);for(a=h.length;a<l+1;a++)h.push(new Vector2d);for(a=0;a<l;a++){var f=u+n+c*a,g=Math.cos(f),m=-Math.sin(f);h[a].x=t+(d*g+p*m)*i,h[a].y=e+(d*-m+p*g)*i}this.currentCompositor.drawVertices(this.gl.LINE_STRIP,h,l)}},e.prototype.fillArc=function(t,e,i,n,r,o){var s,a=this._glPoints,h=0,l=Math.floor(24*Math.sqrt(2*i)),u=(r-n)/(2*l),c=2*u,d=Math.cos(u),p=Math.sin(u);for(s=a.length;s<2*l;s++)a.push(new Vector2d);for(s=0;s<l-1;s++){var f=u+n+c*s,g=Math.cos(f),m=-Math.sin(f);a[h++].set(t,e),a[h++].set(t-(d*g+p*m)*i,e-(d*-m+p*g)*i)}this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeEllipse=function(t,e,i,n,r){if(!0===r)this.fillEllipse(t,e,i,n);else{var o,s=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+n)),a=TAU/s,h=this._glPoints;for(o=h.length;o<s;o++)h.push(new Vector2d);for(o=0;o<s;o++)h[o].x=t+Math.sin(a*-o)*i,h[o].y=e+Math.cos(a*-o)*n;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,h,s)}},e.prototype.fillEllipse=function(t,e,i,n){var r,o=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+n)),s=TAU/o,a=this._glPoints,h=0;for(r=a.length;r<2*(o+1);r++)a.push(new Vector2d);for(r=0;r<o+1;r++)a[h++].set(t,e),a[h++].set(t+Math.sin(s*r)*i,e+Math.cos(s*r)*n);this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeLine=function(t,e,i,n){var r=this._glPoints;r[0].x=t,r[0].y=e,r[1].x=i,r[1].y=n,this.currentCompositor.drawVertices(this.gl.LINE_STRIP,r,2)},e.prototype.fillLine=function(t,e,i,n){this.strokeLine(t,e,i,n)},e.prototype.strokePolygon=function(t,e){if(!0===e)this.fillPolygon(t);else{var i,n=t.points.length,r=this._glPoints;for(i=r.length;i<n;i++)r.push(new Vector2d);for(i=0;i<n;i++)r[i].x=t.pos.x+t.points[i].x,r[i].y=t.pos.y+t.points[i].y;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,r,n)}},e.prototype.fillPolygon=function(t){var e,i=t.points,n=this._glPoints,r=t.getIndices(),o=t.pos.x,s=t.pos.y;for(e=n.length;e<r.length;e++)n.push(new Vector2d);for(e=0;e<r.length;e++)n[e].set(o+i[r[e]].x,s+i[r[e]].y);this.currentCompositor.drawVertices(this.gl.TRIANGLES,n,r.length)},e.prototype.strokeRect=function(t,e,i,n,r){if(!0===r)this.fillRect(t,e,i,n);else{var o=this._glPoints;o[0].x=t,o[0].y=e,o[1].x=t+i,o[1].y=e,o[2].x=t+i,o[2].y=e+n,o[3].x=t,o[3].y=e+n,this.currentCompositor.drawVertices(this.gl.LINE_LOOP,o,4)}},e.prototype.fillRect=function(t,e,i,n){var r=this._glPoints;r[0].x=t+i,r[0].y=e,r[1].x=t,r[1].y=e,r[2].x=t+i,r[2].y=e+n,r[3].x=t,r[3].y=e+n,this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,r,4)},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=this.currentTransform;if(e.multiply(t),!1===this.settings.subPixel){var i=e.toArray();i[6]|=0,i[7]|=0}},e.prototype.translate=function(t,e){var i=this.currentTransform;if(i.translate(t,e),!1===this.settings.subPixel){var n=i.toArray();n[6]|=0,n[7]|=0}},e.prototype.clipRect=function(t,e,i,n){var r=this.backBufferCanvas,o=this.gl;if(0!==t||0!==e||i!==r.width||n!==r.height){var s=this.currentScissor;if(o.isEnabled(o.SCISSOR_TEST)&&s[0]===t&&s[1]===e&&s[2]===i&&s[3]===n)return;this.flush(),o.enable(this.gl.SCISSOR_TEST),o.scissor(t+this.currentTransform.tx,r.height-n-e-this.currentTransform.ty,i,n),s[0]=t,s[1]=e,s[2]=i,s[3]=n}else o.disable(o.SCISSOR_TEST)},e.prototype.setMask=function(t){var e=this.gl;this.flush(),e.enable(e.STENCIL_TEST),e.clear(e.STENCIL_BUFFER_BIT),e.colorMask(!1,!1,!1,!1),e.stencilFunc(e.NOTEQUAL,1,1),e.stencilOp(e.REPLACE,e.REPLACE,e.REPLACE),this.fill(t),this.flush(),e.colorMask(!0,!0,!0,!0),e.stencilFunc(e.EQUAL,1,1),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)},e.prototype.clearMask=function(){this.flush(),this.gl.disable(this.gl.STENCIL_TEST)},e}(Renderer),designRatio=1,designWidth=0,designHeight=0,settings={parent:document.body,renderer:2,doubleBuffering:!1,autoScale:!1,scale:1,scaleMethod:"fit",transparent:!1,blendMode:"normal",antiAlias:!1,failIfMajorPerformanceCaveat:!0,subPixel:!1,preferWebGL1:!1,powerPreference:"default",verbose:!1,consoleHeader:!0};function autoDetectRenderer(t){try{if(device$1.isWebGLSupported(t))return new WebGLRenderer(t)}catch(t){console.log("Error creating WebGL renderer :"+t.message)}return new CanvasRenderer(t)}var video={CANVAS:0,WEBGL:1,AUTO:2,parent:null,scaleRatio:new Vector2d(1,1),init:function(t,e,i){if(!exports.initialized)throw new Error("me.video.init() called before engine initialization.");(settings=Object.assign(settings,i||{})).width=t,settings.height=e,settings.doubleBuffering=!!settings.doubleBuffering,settings.transparent=!!settings.transparent,settings.antiAlias=!!settings.antiAlias,settings.failIfMajorPerformanceCaveat=!!settings.failIfMajorPerformanceCaveat,settings.subPixel=!!settings.subPixel,settings.verbose=!!settings.verbose,-1!==settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/)?settings.autoScale="auto"===settings.scale||!0:(settings.scaleMethod="fit",settings.autoScale="auto"===settings.scale||!1),void 0!==settings.wrapper&&(warning("settings.wrapper","settings.parent","8.0.0"),settings.parent=settings.wrapper),!1!==settings.consoleHeader&&console.log("melonJS v"+version+" | http://melonjs.org");var n=utils$1.getUriFragment();!0!==n.webgl&&!0!==n.webgl1&&!0!==n.webgl2||(settings.renderer=this.WEBGL,!0===n.webgl1&&(settings.preferWebGL1=!0)),settings.scale=settings.autoScale?1:+settings.scale||1,this.scaleRatio.set(settings.scale,settings.scale),(settings.autoScale||1!==settings.scale)&&(settings.doubleBuffering=!0),designRatio=t/e,designWidth=t,designHeight=e,settings.zoomX=t*this.scaleRatio.x,settings.zoomY=e*this.scaleRatio.y,window.addEventListener("resize",utils$1.function.throttle((function(t){event.publish(event.WINDOW_ONRESIZE,[t])}),100),!1),window.addEventListener("orientationchange",(function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),!1),window.addEventListener("onmozorientationchange",(function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),!1),void 0!==window.screen&&(window.screen.onorientationchange=function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),window.addEventListener("scroll",utils$1.function.throttle((function(t){event.publish(event.WINDOW_ONSCROLL,[t])}),100),!1),event.subscribe(event.WINDOW_ONRESIZE,this.onresize.bind(this)),event.subscribe(event.WINDOW_ONORIENTATION_CHANGE,this.onresize.bind(this));try{switch(settings.renderer){case this.AUTO:case this.WEBGL:this.renderer=autoDetectRenderer(settings);break;default:this.renderer=new CanvasRenderer(settings)}}catch(t){return console(t.message),!1}(this.parent=device$1.getElement(settings.parent),this.parent.appendChild(this.renderer.getScreenCanvas()),this.onresize(),"MutationObserver"in window)&&new MutationObserver(this.onresize.bind(this)).observe(this.parent,{attributes:!1,childList:!0,subtree:!0});if(!1!==settings.consoleHeader){var r=this.renderer instanceof CanvasRenderer?"CANVAS":"WebGL"+this.renderer.WebGLVersion,o=device$1.hasWebAudio?"Web Audio":"HTML5 Audio",s="string"==typeof this.renderer.GPURenderer?" ("+this.renderer.GPURenderer+")":"";console.log(r+" renderer"+s+" | "+o+" | pixel ratio "+device$1.devicePixelRatio+" | "+(device$1.isMobile?"mobile":"desktop")+" | "+device$1.getScreenOrientation()+" | "+device$1.language),console.log("resolution: requested "+t+"x"+e+", got "+this.renderer.getWidth()+"x"+this.renderer.getHeight())}return event.publish(event.VIDEO_INIT),!0},createCanvas:function(t,e,i){var n;if(0===t||0===e)throw new Error("width or height was zero, Canvas could not be initialized !");return!0===device$1.OffscreenCanvas&&!0===i?void 0===(n=new OffscreenCanvas(0,0)).style&&(n.style={}):n=document.createElement("canvas"),n.width=t,n.height=e,n},getParent:function(){return this.parent},onresize:function(){var t=this.renderer,e=t.settings,i=1,n=1;if(e.autoScale){var r=1/0,o=1/0;if(window.getComputedStyle){var s=window.getComputedStyle(t.getScreenCanvas(),null);r=parseInt(s.maxWidth,10)||1/0,o=parseInt(s.maxHeight,10)||1/0}var a=device$1.getParentBounds(this.getParent()),h=Math.min(r,a.width),l=Math.min(o,a.height),u=h/l;if("fill-min"===e.scaleMethod&&u>designRatio||"fill-max"===e.scaleMethod&&u<designRatio||"flex-width"===e.scaleMethod){var c=Math.min(r,designHeight*u);i=n=h/c,t.resize(Math.floor(c),designHeight)}else if("fill-min"===e.scaleMethod&&u<designRatio||"fill-max"===e.scaleMethod&&u>designRatio||"flex-height"===e.scaleMethod){var d=Math.min(o,designWidth*(l/h));i=n=l/d,t.resize(designWidth,Math.floor(d))}else"flex"===e.scaleMethod?t.resize(Math.floor(h),Math.floor(l)):"stretch"===e.scaleMethod?(i=h/designWidth,n=l/designHeight):i=n=u<designRatio?h/designWidth:l/designHeight;this.scale(i,n)}},scale:function(t,e){var i=this.renderer,n=i.getScreenCanvas(),r=i.getScreenContext(),o=i.settings,s=device$1.devicePixelRatio,a=o.zoomX=n.width*t*s,h=o.zoomY=n.height*e*s;this.scaleRatio.set(t*s,e*s),n.style.width=a/s+"px",n.style.height=h/s+"px",i.setAntiAlias(r,o.antiAlias),i.setBlendMode(o.blendMode,r),game$1.repaint()}},video$1=video,GUID_base="",GUID_index=0,utils={agent:agentUtils,array:arrayUtils,file:fileUtils,string:stringUtils,function:fnUtils,getPixels:function(t){if(t instanceof HTMLImageElement){var e=CanvasRenderer.getContext2d(video$1.createCanvas(t.width,t.height));return e.drawImage(t,0,0),e.getImageData(0,0,t.width,t.height)}return t.getContext("2d").getImageData(0,0,t.width,t.height)},checkVersion:function(t,e){void 0===e&&(e=version);for(var i=t.split("."),n=e.split("."),r=Math.min(i.length,n.length),o=0,s=0;s<r&&!(o=+i[s]-+n[s]);s++);return o||i.length-n.length},getUriFragment:(UriFragments={},parsed=!1,function(t){var e;if(void 0===t){if(e=UriFragments,!0===parsed)return e;t=document.location,parsed=!0}else e={};return t&&t.hash&&t.hash.substr(1).split("&").filter((function(t){return""!==t})).forEach((function(t){var i=t.split("="),n=i.shift(),r=i.join("=");e[n]=r||!0})),e}),resetGUID:function(t,e){void 0===e&&(e=0),GUID_base=toHex$1(t.toString().toUpperCase()),GUID_index=e},createGUID:function(t){return void 0===t&&(t=1),GUID_index+=t,GUID_base+"-"+(t||GUID_index)}},UriFragments,parsed,utils$1=utils,framecount=0,framedelta=0,last=0,now=0,delta=0,step=0,minstep=0,timers=[],timerId=0;function clearTimer(t){for(var e=0,i=timers.length;e<i;e++)if(timers[e].timerId===t){timers.splice(e,1);break}}function updateTimers(t){last=now,(delta=(now=t)-last)<0&&(delta=0),timer.tick=delta>minstep&&timer.interpolation?delta/step:1;for(var e=0,i=timers.length;e<i;e++){var n=timers[e];n.pauseable&&state$1.isPaused()||(n.elapsed+=delta),n.elapsed>=n.delay&&(n.fn.apply(null,n.args),!0===n.repeat?n.elapsed-=n.delay:timer.clearTimeout(n.timerId))}}var timer={tick:1,fps:0,maxfps:60,interpolation:!1,lastUpdate:window.performance.now(),init:function(){this.reset(),now=last=0,event.subscribe(event.GAME_UPDATE,updateTimers)},reset:function(){last=now=window.performance.now(),delta=0,framedelta=0,framecount=0,step=Math.ceil(1e3/this.maxfps),minstep=1e3/this.maxfps*1.25},setTimeout:function(t,e,i){return timers.push({fn:t,delay:e,elapsed:0,repeat:!1,timerId:++timerId,pauseable:!0===i||!0,args:arguments.length>3?Array.prototype.slice.call(arguments,3):void 0}),timerId},setInterval:function(t,e,i){return timers.push({fn:t,delay:e,elapsed:0,repeat:!0,timerId:++timerId,pauseable:!0===i||!0,args:arguments.length>3?Array.prototype.slice.call(arguments,3):void 0}),timerId},clearTimeout:function(t){utils$1.function.defer(clearTimer,this,t)},clearInterval:function(t){utils$1.function.defer(clearTimer,this,t)},getTime:function(){return now},getDelta:function(){return delta},countFPS:function(){framecount++,framedelta+=delta,framecount%10==0&&(this.fps=clamp(Math.round(1e3*framecount/framedelta),0,this.maxfps),framedelta=0,framecount=0)}},timer$1=timer,lastTime=0,vendors=["ms","moz","webkit","o"],x,requestAnimationFrame=window.requestAnimationFrame,cancelAnimationFrame=window.cancelAnimationFrame;for(x=0;x<vendors.length&&!requestAnimationFrame;++x)requestAnimationFrame=window[vendors[x]+"RequestAnimationFrame"];for(x=0;x<vendors.length&&!cancelAnimationFrame;++x)cancelAnimationFrame=window[vendors[x]+"CancelAnimationFrame"]||window[vendors[x]+"CancelRequestAnimationFrame"];requestAnimationFrame&&cancelAnimationFrame||(requestAnimationFrame=function(t){var e=window.performance.now(),i=Math.max(0,1e3/timer$1.maxfps-(e-lastTime)),n=window.setTimeout((function(){t(e+i)}),i);return lastTime=e+i,n},cancelAnimationFrame=function(t){window.clearTimeout(t)},window.requestAnimationFrame=requestAnimationFrame,window.cancelAnimationFrame=cancelAnimationFrame);var plugins={},plugin={Base:window.Jay.extend({init:function(){this.version="9.0.0"}}),patch:function(t,e,i){if(void 0!==t.prototype&&(t=t.prototype),"function"!=typeof t[e])throw new Error(e+" is not an existing function");var n=t[e];Object.defineProperty(t,e,{configurable:!0,value:function(t,e){return function(){this._patched=n;var t=e.apply(this,arguments);return this._patched=null,t}}(0,i)})},register:function(t,e){if(plugins[e])throw new Error("plugin "+e+" already registered");var i=[];arguments.length>2&&(i=Array.prototype.slice.call(arguments,1)),i[0]=t;var n=new(t.bind.apply(t,i));if(void 0===n||!(n instanceof plugin.Base))throw new Error("Plugin should extend the me.plugin.Base Class !");if(utils$1.checkVersion(n.version)>0)throw new Error("Plugin version mismatch, expected: "+n.version+", got: "+version);plugins[e]=n}},Easing={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-Easing.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*Easing.Bounce.In(2*t):.5*Easing.Bounce.Out(2*t-1)+.5}}},Interpolation={Linear:function(t,e){var i=t.length-1,n=i*e,r=Math.floor(n),o=Interpolation.Utils.Linear;return e<0?o(t[0],t[1],n):e>1?o(t[i],t[i-1],i-n):o(t[r],t[r+1>i?i:r+1],n-r)},Bezier:function(t,e){var i,n=0,r=t.length-1,o=Math.pow,s=Interpolation.Utils.Bernstein;for(i=0;i<=r;i++)n+=o(1-e,r-i)*o(e,i)*t[i]*s(r,i);return n},CatmullRom:function(t,e){var i=t.length-1,n=i*e,r=Math.floor(n),o=Interpolation.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(r=Math.floor(n=i*(1+e))),o(t[(r-1+i)%i],t[r],t[(r+1)%i],t[(r+2)%i],n-r)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-n)-t[0]):e>1?t[i]-(o(t[i],t[i],t[i-1],t[i-1],n-i)-t[i]):o(t[r?r-1:0],t[r],t[i<r+1?i:r+1],t[i<r+2?i:r+2],n-r)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=Interpolation.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:function(){var t=[1];return function(e){var i,n=1;if(t[e])return t[e];for(i=e;i>1;i--)n*=i;return t[e]=n}}(),CatmullRom:function(t,e,i,n,r){var o=.5*(i-t),s=.5*(n-e),a=r*r;return(2*e-2*i+o+s)*(r*a)+(-3*e+3*i-2*o-s)*a+o*r+e}}},Tween=function(t){var e=null,i=null,n=null,r=null,o=null,s=null,a=null,h=null,l=null,u=null,c=null,d=null,p=null,f=null,g=null,m=null,y=null;this.isRenderable=!1,this._resumeCallback=function(t){l&&(l+=t)},this.setProperties=function(t){for(var v in e=t,i={},n={},r={},o=1e3,s=0,a=!1,h=0,l=null,u=Easing.Linear.None,c=Interpolation.Linear,d=[],p=null,f=!1,g=null,m=null,y=timer$1.lastUpdate,this.isPersistent=!1,this.updateWhenPaused=!1,t)"object"!=typeof t&&(i[v]=parseFloat(t[v]))},this.setProperties(t),this.onResetEvent=function(t){this.setProperties(t)},this.onActivateEvent=function(){event.subscribe(event.STATE_RESUME,this._resumeCallback)},this.onDeactivateEvent=function(){event.unsubscribe(event.STATE_RESUME,this._resumeCallback)},this.to=function(t,e){return n=t,void 0!==e&&("number"==typeof e?o=e:"object"==typeof e&&(e.duration&&(o=e.duration),e.yoyo&&this.yoyo(e.yoyo),e.easing&&this.easing(e.easing),e.repeat&&this.repeat(e.repeat),e.delay&&this.delay(e.delay),e.interpolation&&this.interpolation(e.interpolation),e.autoStart&&this.start())),this},this.start=function(t){for(var o in f=!1,game$1.world.addChild(this),l=(void 0===t?timer$1.getTime():t)+h,n){if(n[o]instanceof Array){if(0===n[o].length)continue;n[o]=[e[o]].concat(n[o])}i[o]=e[o],i[o]instanceof Array==!1&&(i[o]*=1),r[o]=i[o]||0}return this},this.stop=function(){return game$1.world.removeChildNow(this),this},this.delay=function(t){return h=t,this},this.repeat=function(t){return s=t,this},this.yoyo=function(t){return a=t,this},this.easing=function(t){if("function"!=typeof t)throw new Error("invalid easing function for me.Tween.easing()");return u=t,this},this.interpolation=function(t){return c=t,this},this.chain=function(){return d=arguments,this},this.onStart=function(t){return p=t,this},this.onUpdate=function(t){return g=t,this},this.onComplete=function(t){return m=t,this},this.update=function(t){var v,_=y=timer$1.lastUpdate>y?timer$1.lastUpdate:y+t;if(_<l)return!0;!1===f&&(null!==p&&p.call(e),f=!0);var x=(_-l)/o,w=u(x=x>1?1:x);for(v in n){var b=i[v]||0,T=n[v];T instanceof Array?e[v]=c(T,w):("string"==typeof T&&(T=b+parseFloat(T)),"number"==typeof T&&(e[v]=b+(T-b)*w))}if(null!==g&&g.call(e,w),1===x){if(s>0){for(v in isFinite(s)&&s--,r){if("string"==typeof n[v]&&(r[v]=r[v]+parseFloat(n[v])),a){var E=r[v];r[v]=n[v],n[v]=E}i[v]=r[v]}return l=_+h,!0}game$1.world.removeChildNow(this),null!==m&&m.call(e);for(var A=0,R=d.length;A<R;A++)d[A].start(_);return!1}return!0}},staticAccessors={Easing:{configurable:!0},Interpolation:{configurable:!0}};staticAccessors.Easing.get=function(){return Easing},staticAccessors.Interpolation.get=function(){return Interpolation},Object.defineProperties(Tween,staticAccessors);var runits=["ex","em","pt","px"],toPX=[12,24,.75,1],setContextStyle=function(t,e,i){t.font=e.font,t.fillStyle=e.fillStyle.toRGBA(),!0===i&&(t.strokeStyle=e.strokeStyle.toRGBA(),t.lineWidth=e.lineWidth),t.textAlign=e.textAlign,t.textBaseline=e.textBaseline},Text=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),void 0!==i.fillStyle?i.fillStyle instanceof Color?this.fillStyle=i.fillStyle:this.fillStyle=pool.pull("Color").parseCSS(i.fillStyle):this.fillStyle=pool.pull("Color",0,0,0),void 0!==i.strokeStyle?i.strokeStyle instanceof Color?this.strokeStyle=i.strokeStyle:this.strokeStyle=pool.pull("Color").parseCSS(i.strokeStyle):this.strokeStyle=pool.pull("Color",0,0,0),this.lineWidth=i.lineWidth||1,this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this._text=[],this.fontSize=10,void 0!==i.anchorPoint?this.anchorPoint.setV(i.anchorPoint):this.anchorPoint.set(0,0),void 0!==i.floating&&(this.floating=!!i.floating),this.setFont(i.font,i.size),!0===i.bold&&this.bold(),!0===i.italic&&this.italic(),this.setText(i.text)},bold:function(){return this.font="bold "+this.font,this.isDirty=!0,this},italic:function(){return this.font="italic "+this.font,this.isDirty=!0,this},setFont:function(t,e){var i=t.split(",").map((function(t){return t=t.trim(),/(^".*"$)|(^'.*'$)/.test(t)?t:'"'+t+'"'}));if("number"==typeof e)this.fontSize=e,e+="px";else{var n=e.match(/([-+]?[\d.]*)(.*)/);this.fontSize=parseFloat(n[1]),n[2]?this.fontSize*=toPX[runits.indexOf(n[2])]:e+="px"}return this.height=this.fontSize,this.font=e+" "+i.join(","),this.isDirty=!0,this},setText:function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this},measureText:function(t,e,i){var n;n=void 0===t?video$1.renderer.getFontContext():t instanceof Renderer?t.getFontContext():t;var r=i||this.getBounds(),o=this.fontSize*this.lineHeight,s=void 0!==e?(""+e).split("\n"):this._text;n.save(),setContextStyle(n,this),this.height=this.width=0;for(var a=0;a<s.length;a++)this.width=Math.max(n.measureText(utils$1.string.trimRight(""+s[a])).width,this.width),this.height+=o;return r.width=Math.ceil(this.width),r.height=Math.ceil(this.height),r.x=Math.floor("right"===this.textAlign?this.pos.x-this.width:"center"===this.textAlign?this.pos.x-this.width/2:this.pos.x),r.y=Math.floor(0===this.textBaseline.search(/^(top|hanging)$/)?this.pos.y:"middle"===this.textBaseline?this.pos.y-r.height/2:this.pos.y-r.height),n.restore(),r},update:function(){return!0===this.isDirty&&this.measureText(),this.isDirty},draw:function(t,e,i,n,r){void 0===this.ancestor?(this.setText(e),this.pos.x===i&&this.pos.y===n||(this.pos.x=i,this.pos.y=n,this.isDirty=!0),this.update(0),t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())):(i=this.pos.x,n=this.pos.y),!1===t.settings.subPixel&&(i=~~i,n=~~n),t.drawFont(this._drawFont(t.getFontContext(),this._text,i,n,r||!1)),void 0===this.ancestor&&t.restore(),this.isDirty=!1},drawStroke:function(t,e,i,n){this.draw.call(this,t,e,i,n,!0)},_drawFont:function(t,e,i,n,r){setContextStyle(t,this,r);for(var o=this.fontSize*this.lineHeight,s=0;s<e.length;s++){var a=utils$1.string.trimRight(""+e[s]);t[r?"strokeText":"fillText"](a,i,n),n+=o}return this.getBounds()},destroy:function(){pool.push(this.fillStyle),pool.push(this.strokeStyle),this.fillStyle=this.strokeStyle=void 0,this._text.length=0,this._super(Renderable,"destroy")}}),measureTextWidth=function(t,e){for(var i=e.split(""),n=0,r=null,o=0;o<i.length;o++){var s=i[o].charCodeAt(0),a=t.fontData.glyphs[s],h=r&&r.kerning?r.getKerning(s):0;n+=(a.xadvance+h)*t.fontScale.x,r=a}return n},measureTextHeight=function(t){return t.fontData.capHeight*t.lineHeight*t.fontScale.y},BitmapText=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this._text=[],this.fontScale=pool.pull("Vector2d",1,1),this.fontImage="object"==typeof i.font?i.font:loader$1.getImage(i.font),"string"!=typeof i.fontData?this.fontData=pool.pull("BitmapTextData",loader$1.getBinary(i.font)):this.fontData=pool.pull("BitmapTextData",i.fontData.includes("info face")?i.fontData:loader$1.getBinary(i.fontData)),void 0!==i.floating&&(this.floating=!!i.floating),"number"==typeof i.size&&1!==i.size&&this.resize(i.size),void 0!==i.fillStyle&&(i.fillStyle instanceof Color?this.fillStyle.setColor(i.fillStyle):this.fillStyle.parseCSS(i.fillStyle)),void 0!==i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0),this.setText(i.text)},set:function(t,e){return this.textAlign=t,e&&this.resize(e),this.isDirty=!0,this},setText:function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this},resize:function(t){return this.fontScale.set(t,t),this.isDirty=!0,this},measureText:function(t,e){t=t||this._text;var i=measureTextHeight(this),n=e||this.getBounds(),r="string"==typeof t?(""+t).split("\n"):t;n.height=n.width=0;for(var o=0;o<r.length;o++)n.width=Math.max(measureTextWidth(this,r[o]),n.width),n.height+=i;return n},update:function(){return!0===this.isDirty&&this.measureText(),this.isDirty},draw:function(t,e,i,n){var r=t.globalAlpha();void 0===this.ancestor?(this.setText(e),this.update(0),t.setGlobalAlpha(r*this.getOpacity())):(i=this.pos.x,n=this.pos.y);for(var o=i,s=measureTextHeight(this),a=0,h=0;h<this._text.length;h++){i=o;var l=utils$1.string.trimRight(this._text[h]),u=measureTextWidth(this,l);switch(this.textAlign){case"right":i-=u;break;case"center":i-=.5*u}switch(this.textBaseline){case"middle":n-=.5*s;break;case"ideographic":case"alphabetic":case"bottom":n-=s}!0===this.isDirty&&void 0===this.ancestor&&(0===h&&(this.pos.y=n),a<u&&(a=u,this.pos.x=i));for(var c=null,d=0,p=l.length;d<p;d++){var f=l.charCodeAt(d),g=this.fontData.glyphs[f],m=g.width,y=g.height,v=c&&c.kerning?c.getKerning(f):0;0!==m&&0!==y&&t.drawImage(this.fontImage,g.x,g.y,m,y,i+g.xoffset,n+g.yoffset*this.fontScale.y,m*this.fontScale.x,y*this.fontScale.y),i+=(g.xadvance+v)*this.fontScale.x,c=g}n+=s}void 0===this.ancestor&&t.setGlobalAlpha(r),this.isDirty=!1},destroy:function(){pool.push(this.fontScale),this.fontScale=void 0,pool.push(this.fontData),this.fontData=void 0,this._text.length=0,this._super(Renderable,"destroy")}});Object.defineProperty(BitmapText.prototype,"fillStyle",{get:function(){return this.tint},set:function(t){this.tint=t},configurable:!0});var LOG2_PAGE_SIZE=9,PAGE_SIZE=1<<LOG2_PAGE_SIZE,Glyph=function(){this.id=0,this.x=0,this.y=0,this.width=0,this.height=0,this.u=0,this.v=0,this.u2=0,this.v2=0,this.xoffset=0,this.yoffset=0,this.xadvance=0,this.fixedWidth=!1};Glyph.prototype.getKerning=function(t){if(this.kerning){var e=this.kerning[t>>>LOG2_PAGE_SIZE];if(e)return e[t&PAGE_SIZE-1]||0}return 0},Glyph.prototype.setKerning=function(t,e){this.kerning||(this.kerning={});var i=this.kerning[t>>>LOG2_PAGE_SIZE];void 0===i&&(this.kerning[t>>>LOG2_PAGE_SIZE]={},i=this.kerning[t>>>LOG2_PAGE_SIZE]),i[t&PAGE_SIZE-1]=e};var capChars=["M","N","B","D","C","E","F","K","A","G","H","I","J","L","O","P","Q","R","S","T","U","V","W","X","Y","Z"];function getValueFromPair(t,e){var i=t.match(e);if(!i)throw new Error("Could not find pattern "+e+" in string: "+t);return i[0].split("=")[1]}function getFirstGlyph(t){for(var e=Object.keys(t),i=0;i<e.length;i++)if(e[i]>32)return t[e[i]];return null}function createSpaceGlyph(t){var e=" ".charCodeAt(0),i=t[e];i||((i=new Glyph).id=e,i.xadvance=getFirstGlyph(t).xadvance,t[e]=i)}var BitmapTextData=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this).onResetEvent.apply(t,e)};BitmapTextData.prototype.onResetEvent=function(t){this.padTop=0,this.padRight=0,this.padBottom=0,this.padLeft=0,this.lineHeight=0,this.capHeight=1,this.descent=0,this.glyphs={},this.parse(t)},BitmapTextData.prototype.parse=function(t){if(!t)throw new Error("File containing font data was empty, cannot load the bitmap font.");var e=t.split(/\r\n|\n/),i=t.match(/padding\=\d+,\d+,\d+,\d+/g);if(!i)throw new Error("Padding not found in first line");var n=i[0].split("=")[1].split(",");this.padTop=parseFloat(n[0]),this.padLeft=parseFloat(n[1]),this.padBottom=parseFloat(n[2]),this.padRight=parseFloat(n[3]),this.lineHeight=parseFloat(getValueFromPair(e[1],/lineHeight\=\d+/g));var r,o=parseFloat(getValueFromPair(e[1],/base\=\d+/g)),s=this.padTop+this.padBottom,a=null;for(r=4;r<e.length;r++){var h=e[r],l=h.split(/=|\s+/);if(h&&!/^kernings/.test(h))if(/^kerning\s/.test(h)){var u=parseFloat(l[2]),c=parseFloat(l[4]),d=parseFloat(l[6]);null!=(a=this.glyphs[u])&&a.setKerning(c,d)}else{a=new Glyph;var p=parseFloat(l[2]);a.id=p,a.x=parseFloat(l[4]),a.y=parseFloat(l[6]),a.width=parseFloat(l[8]),a.height=parseFloat(l[10]),a.xoffset=parseFloat(l[12]),a.yoffset=parseFloat(l[14]),a.xadvance=parseFloat(l[16]),a.width>0&&a.height>0&&(this.descent=Math.min(o+a.yoffset,this.descent)),this.glyphs[p]=a}}this.descent+=this.padBottom,createSpaceGlyph(this.glyphs);var f=null;for(r=0;r<capChars.length;r++){var g=capChars[r];if(f=this.glyphs[g.charCodeAt(0)])break}if(f)this.capHeight=f.height;else for(var m in this.glyphs)if(this.glyphs.hasOwnProperty(m)){if(0===(a=this.glyphs[m]).height||0===a.width)continue;this.capHeight=Math.max(this.capHeight,a.height)}this.capHeight-=s};var ColorLayer=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[0,0,1/0,1/0]),this.name=t,this.pos.z=i,this.floating=!0,this.color=e instanceof Color?e:pool.pull("Color").parseCSS(e),this.anchorPoint.set(0,0)},draw:function(t,e){var i=t.getColor(),n=game$1.viewport.pos;t.setColor(this.color),t.fillRect(e.left-n.x,e.top-n.y,e.width,e.height),t.setColor(i)},destroy:function(){pool.push(this.color),this.color=void 0,this._super(Renderable,"destroy")}}),ImageLayer=Renderable.extend({init:function(t,e,i){if(this._super(Renderable,"init",[t,e,1/0,1/0]),this.image="object"==typeof i.image?i.image:loader$1.getImage(i.image),!this.image)throw new Error(("string"==typeof i.image?"'"+i.image+"'":"Image")+" file for Image Layer '"+this.name+"' not found!");this.imagewidth=this.image.width,this.imageheight=this.image.height,"string"==typeof i.name&&(this.name=i.name),this.floating=!0,this.pos.z=i.z||0,this.offset=pool.pull("Vector2d",t,e),this.ratio=pool.pull("Vector2d",1,1),void 0!==i.ratio&&("number"==typeof i.ratio?this.ratio.set(i.ratio,i.ratio):this.ratio.setV(i.ratio)),void 0===i.anchorPoint?this.anchorPoint.set(0,0):"number"==typeof i.anchorPoint?this.anchorPoint.set(i.anchorPoint,i.anchorPoint):this.anchorPoint.setV(i.anchorPoint),Object.defineProperty(this,"repeat",{get:function(){return this._repeat},set:function(t){switch(this._repeat=t,this._repeat){case"no-repeat":this.repeatX=!1,this.repeatY=!1;break;case"repeat-x":this.repeatX=!0,this.repeatY=!1;break;case"repeat-y":this.repeatX=!1,this.repeatY=!0;break;default:this.repeatX=!0,this.repeatY=!0}this.resize(game$1.viewport.width,game$1.viewport.height),this.createPattern()},configurable:!0}),this.repeat=i.repeat||"repeat",event.subscribe(event.WEBGL_ONCONTEXT_RESTORED,this.createPattern.bind(this))},onActivateEvent:function(){var t=this.updateLayer.bind(this);this.vpChangeHdlr=event.subscribe(event.VIEWPORT_ONCHANGE,t),this.vpResizeHdlr=event.subscribe(event.VIEWPORT_ONRESIZE,this.resize.bind(this)),this.vpLoadedHdlr=event.subscribe(event.LEVEL_LOADED,(function(){t(game$1.viewport.pos)})),!0!==this.ancestor.root&&this.updateLayer(game$1.viewport.pos)},resize:function(t,e){this._super(Renderable,"resize",[this.repeatX?1/0:t,this.repeatY?1/0:e])},createPattern:function(){this._pattern=video$1.renderer.createPattern(this.image,this._repeat)},updateLayer:function(t){var e=this.ratio.x,i=this.ratio.y;if(0!==e||0!==i){var n=game$1.viewport,r=this.imagewidth,o=this.imageheight,s=n.bounds.width,a=n.bounds.height,h=this.anchorPoint.x,l=this.anchorPoint.y,u=h*(e-1)*(s-n.width)+this.offset.x-e*t.x,c=l*(i-1)*(a-n.height)+this.offset.y-i*t.y;this.repeatX?this.pos.x=u%r:this.pos.x=u,this.repeatY?this.pos.y=c%o:this.pos.y=c}},preDraw:function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())},draw:function(t){var e=game$1.viewport,i=this.imagewidth,n=this.imageheight,r=e.bounds.width,o=e.bounds.height,s=this.anchorPoint.x,a=this.anchorPoint.y,h=this.pos.x,l=this.pos.y;0===this.ratio.x&&0===this.ratio.y&&(h+=s*(r-i),l+=a*(o-n)),t.translate(h,l),t.drawPattern(this._pattern,0,0,2*e.width,2*e.height)},onDeactivateEvent:function(){event.unsubscribe(this.vpChangeHdlr),event.unsubscribe(this.vpResizeHdlr),event.unsubscribe(this.vpLoadedHdlr)},destroy:function(){pool.push(this.offset),this.offset=void 0,pool.push(this.ratio),this.ratio=void 0,this._super(Renderable,"destroy")}}),GUI_Object=Sprite.extend({init:function(t,e,i){this.isClickable=!0,this.holdThreshold=250,this.isHoldable=!1,this.hover=!1,this.holdTimeout=null,this.updated=!1,this.released=!0,this._super(Sprite,"init",[t,e,i]),this.floating=!0,this.isKinematic=!1},update:function(t){var e=this._super(Sprite,"update",[t]);return this.updated?(this.released||(this.updated=!1),!0):e},clicked:function(t){if(0===t.button&&this.isClickable)return this.updated=!0,this.released=!1,this.isHoldable&&(null!==this.holdTimeout&&timer$1.clearTimeout(this.holdTimeout),this.holdTimeout=timer$1.setTimeout(this.hold.bind(this),this.holdThreshold,!1),this.released=!1),this.onClick.call(this,t)},onClick:function(){return!1},enter:function(t){return this.hover=!0,this.onOver.call(this,t)},onOver:function(){},leave:function(t){return this.hover=!1,this.release.call(this,t),this.onOut.call(this,t)},onOut:function(){},release:function(t){if(!1===this.released)return this.released=!0,timer$1.clearTimeout(this.holdTimeout),this.onRelease.call(this,t)},onRelease:function(){return!1},hold:function(){timer$1.clearTimeout(this.holdTimeout),this.released||this.onHold.call(this)},onHold:function(){},onActivateEvent:function(){registerPointerEvent("pointerdown",this,this.clicked.bind(this)),registerPointerEvent("pointerup",this,this.release.bind(this)),registerPointerEvent("pointercancel",this,this.release.bind(this)),registerPointerEvent("pointerenter",this,this.enter.bind(this)),registerPointerEvent("pointerleave",this,this.leave.bind(this))},onDeactivateEvent:function(){releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),releasePointerEvent("pointerenter",this),releasePointerEvent("pointerleave",this),timer$1.clearTimeout(this.holdTimeout)}}),Collectable=Sprite.extend({init:function(t,e,i){this._super(Sprite,"init",[t,e,i]),this.name=i.name,this.type=i.type,this.id=i.id,this.body=new Body(this,i.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.COLLECTABLE_OBJECT,i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0)}}),Trigger=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),this.anchorPoint.set(0,0),this.fade=i.fade,this.duration=i.duration,this.fading=!1,this.name="Trigger",this.type=i.type,this.id=i.id,this.gotolevel=i.to,this.triggerSettings={event:"level"},["type","container","onLoaded","flatten","setViewportBounds","to"].forEach(function(t){void 0!==i[t]&&(this.triggerSettings[t]=i[t])}.bind(this)),this.body=new Body(this,i.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.ACTION_OBJECT,this.resize(this.body.getBounds().width,this.body.getBounds().height)},getTriggerSettings:function(){return"string"==typeof this.triggerSettings.container&&(this.triggerSettings.container=game$1.world.getChildByName(this.triggerSettings.container)[0]),this.triggerSettings},onFadeComplete:function(){level.load(this.gotolevel,this.getTriggerSettings()),game$1.viewport.fadeOut(this.fade,this.duration)},triggerEvent:function(){var t=this.getTriggerSettings();if("level"!==t.event)throw new Error("Trigger invalid type");this.gotolevel=t.to,this.fade&&this.duration?this.fading||(this.fading=!0,game$1.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))):level.load(this.gotolevel,t)},onCollision:function(){return"Trigger"===this.name&&this.triggerEvent.apply(this),!1}}),ParticleContainer=Container$1.extend({init:function(t){this._super(Container$1,"init",[game$1.viewport.pos.x,game$1.viewport.pos.y,game$1.viewport.width,game$1.viewport.height]),this.autoSort=!1,this._updateCount=0,this._dt=0,this._emitter=t,this.autoTransform=!1,this.anchorPoint.set(0,0),this.isKinematic=!0},update:function(t){if(++this._updateCount>this._emitter.framesToSkip&&(this._updateCount=0),this._updateCount>0)return this._dt+=t,!1;t+=this._dt,this._dt=0;for(var e=game$1.viewport,i=this.children.length-1;i>=0;--i){var n=this.children[i];n.inViewport=e.isVisible(n,this.floating),n.update(t)||this.removeChildNow(n)}return!0},draw:function(t,e){if(this.children.length>0){var i,n=t.getContext();this._emitter.textureAdditive&&(i=n.globalCompositeOperation,n.globalCompositeOperation="lighter"),this._super(Container$1,"draw",[t,e]),this._emitter.textureAdditive&&(n.globalCompositeOperation=i)}}}),pixel=(canvas=video$1.createCanvas(1,1),context=canvas.getContext("2d"),context.fillStyle="#fff",context.fillRect(0,0,1,1),canvas),canvas,context,ParticleEmitterSettings={width:0,height:0,image:pixel,totalParticles:50,angle:Math.PI/2,angleVariation:0,minLife:1e3,maxLife:3e3,speed:2,speedVariation:1,minRotation:0,maxRotation:0,minStartScale:1,maxStartScale:1,minEndScale:0,maxEndScale:0,gravity:0,wind:0,followTrajectory:!1,textureAdditive:!1,onlyInViewport:!0,floating:!1,maxParticles:10,frequency:100,duration:1/0,framesToSkip:0},ParticleEmitter=Renderable.extend({init:function(t,e,i){this._stream=!1,this._frequencyTimer=0,this._durationTimer=0,this._enabled=!1,this._super(Renderable,"init",[t,e,1/0,1/0]),this.alwaysUpdate=!0,this.autoSort=!1,this.container=new ParticleContainer(this),Object.defineProperty(this.pos,"z",{get:function(){return this.container.pos.z}.bind(this),set:function(t){this.container.pos.z=t}.bind(this),enumerable:!0,configurable:!0}),Object.defineProperty(this,"floating",{get:function(){return this.container.floating},set:function(t){this.container.floating=t},enumerable:!0,configurable:!0}),this.reset(i)},onActivateEvent:function(){this.ancestor.addChild(this.container),this.container.pos.z=this.pos.z,this.ancestor.autoSort||this.ancestor.sort()},onDeactivateEvent:function(){this.ancestor.hasChild(this.container)&&this.ancestor.removeChildNow(this.container)},destroy:function(){this.reset()},getRandomPointX:function(){return this.pos.x+randomFloat(0,this.width)},getRandomPointY:function(){return this.pos.y+randomFloat(0,this.height)},reset:function(t){var e=ParticleEmitterSettings,i="number"==typeof(t=t||{}).width?t.width:e.width,n="number"==typeof t.height?t.height:e.height;this.resize(i,n),Object.assign(this,e,t),this.container.reset()},addParticles:function(t){for(var e=0;e<~~t;e++){var i=pool.pull("Particle",this);this.container.addChild(i)}},isRunning:function(){return this._enabled&&this._stream},streamParticles:function(t){this._enabled=!0,this._stream=!0,this.frequency=Math.max(this.frequency,1),this._durationTimer="number"==typeof t?t:this.duration},stopStream:function(){this._enabled=!1},burstParticles:function(t){this._enabled=!0,this._stream=!1,this.addParticles("number"==typeof t?t:this.totalParticles),this._enabled=!1},update:function(t){if(this._enabled&&this._stream){if(this._durationTimer!==1/0&&(this._durationTimer-=t,this._durationTimer<=0))return this.stopStream(),!1;this._frequencyTimer+=t;var e=this.container.children.length;e<this.totalParticles&&this._frequencyTimer>=this.frequency&&(e+this.maxParticles<=this.totalParticles?this.addParticles(this.maxParticles):this.addParticles(this.totalParticles-e),this._frequencyTimer=0)}return!0}}),Particle=Renderable.extend({init:function(t){this._super(Renderable,"init",[t.getRandomPointX(),t.getRandomPointY(),t.image.width,t.image.height]),this.alwaysUpdate=!0,this.image=t.image;var e=t.angle+(t.angleVariation>0?(randomFloat(0,2)-1)*t.angleVariation:0),i=t.speed+(t.speedVariation>0?(randomFloat(0,2)-1)*t.speedVariation:0);this.vel=new Vector2d(i*Math.cos(e),-i*Math.sin(e)),this.life=randomFloat(t.minLife,t.maxLife),this.startLife=this.life,this.startScale=clamp(randomFloat(t.minStartScale,t.maxStartScale),t.minStartScale,t.maxStartScale),this.endScale=clamp(randomFloat(t.minEndScale,t.maxEndScale),t.minEndScale,t.maxEndScale),this.gravity=t.gravity,this.wind=t.wind,this.followTrajectory=t.followTrajectory,this.onlyInViewport=t.onlyInViewport,this.pos.z=t.z,this._deltaInv=timer$1.maxfps/1e3,t.followTrajectory||(this.angle=randomFloat(t.minRotation,t.maxRotation))},update:function(t){var e=t*this._deltaInv;this.life=this.life>t?this.life-t:0;var i=this.life/this.startLife,n=this.startScale;this.startScale>this.endScale?n=(n*=i)<this.endScale?this.endScale:n:this.startScale<this.endScale&&(n=(n/=i)>this.endScale?this.endScale:n),this.alpha=i,this.vel.x+=this.wind*e,this.vel.y+=this.gravity*e;var r=this.followTrajectory?Math.atan2(this.vel.y,this.vel.x):this.angle;return this.pos.x+=this.vel.x*e,this.pos.y+=this.vel.y*e,this.currentTransform.setTransform(n,0,0,0,n,0,this.pos.x,this.pos.y,1).rotate(r),(this.inViewport||!this.onlyInViewport)&&this.life>0},preDraw:function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.alpha),t.transform(this.currentTransform)},draw:function(t){var e=this.width,i=this.height;t.drawImage(this.image,0,0,e,i,-e/2,-i/2,e,i)}}),Entity=Renderable.extend({init:function(t,e,i){if(this.children=[],"number"!=typeof i.width||"number"!=typeof i.height)throw new Error("height and width properties are mandatory when passing settings parameters to an object entity");this._super(Renderable,"init",[t,e,i.width,i.height]),i.image&&(i.framewidth=i.framewidth||i.width,i.frameheight=i.frameheight||i.height,this.renderable=new Sprite(0,0,i)),i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0),"string"==typeof i.name&&(this.name=i.name),this.type=i.type||"",this.id=i.id||"",this.alive=!0,void 0===i.shapes&&(i.shapes=new Polygon(0,0,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])),void 0!==this.body?this.body.init(this,i.shapes,this.onBodyUpdate.bind(this)):this.body=new Body(this,i.shapes,this.onBodyUpdate.bind(this)),0===this.width&&0===this.height&&this.resize(this.body.getBounds().width,this.body.getBounds().height),this.body.setCollisionMask(i.collisionMask),this.body.setCollisionType(i.collisionType),this.autoTransform=!1},update:function(t){return this.renderable?this.renderable.update(t):this._super(Renderable,"update",[t])},onBodyUpdate:function(t){this.getBounds().addBounds(t.getBounds(),!0),this.updateBoundsPos(this.pos.x,this.pos.y)},preDraw:function(t){t.save(),t.translate(this.pos.x+this.body.getBounds().x,this.pos.y+this.body.getBounds().y),this.renderable instanceof Renderable&&t.translate(this.anchorPoint.x*this.body.getBounds().width,this.anchorPoint.y*this.body.getBounds().height)},draw:function(t,e){var i=this.renderable;i instanceof Renderable&&(i.preDraw(t),i.draw(t,e),i.postDraw(t))},destroy:function(){this.renderable&&(this.renderable.destroy.apply(this.renderable,arguments),this.children.splice(0,1)),this._super(Renderable,"destroy",arguments)},onDeactivateEvent:function(){this.renderable&&this.renderable.onDeactivateEvent&&this.renderable.onDeactivateEvent()},onCollision:function(){return!1}});Object.defineProperty(Entity.prototype,"renderable",{get:function(){return this.children[0]},set:function(t){if(!(t instanceof Renderable))throw new Error(t+"should extend me.Renderable");this.children[0]=t,this.children[0].ancestor=this},configurable:!0});var DraggableEntity=Entity.extend({init:function(t,e,i){this._super(Entity,"init",[t,e,i]),this.dragging=!1,this.dragId=null,this.grabOffset=new Vector2d(0,0),this.onPointerEvent=registerPointerEvent,this.removePointerEvent=releasePointerEvent,this.initEvents()},initEvents:function(){var t=this;this.mouseDown=function(t){this.translatePointerEvent(t,event.DRAGSTART)},this.mouseUp=function(t){this.translatePointerEvent(t,event.DRAGEND)},this.onPointerEvent("pointerdown",this,this.mouseDown.bind(this)),this.onPointerEvent("pointerup",this,this.mouseUp.bind(this)),this.onPointerEvent("pointercancel",this,this.mouseUp.bind(this)),event.subscribe(event.POINTERMOVE,this.dragMove.bind(this)),event.subscribe(event.DRAGSTART,(function(e,i){i===t&&t.dragStart(e)})),event.subscribe(event.DRAGEND,(function(e,i){i===t&&t.dragEnd(e)}))},translatePointerEvent:function(t,e){event.publish(e,[t,this])},dragStart:function(t){if(!1===this.dragging)return this.dragging=!0,this.grabOffset.set(t.gameX,t.gameY),this.grabOffset.sub(this.pos),!1},dragMove:function(t){!0===this.dragging&&(this.pos.set(t.gameX,t.gameY,this.pos.z),this.pos.sub(this.grabOffset))},dragEnd:function(){if(!0===this.dragging)return this.dragging=!1,!1},destroy:function(){event.unsubscribe(event.POINTERMOVE,this.dragMove),event.unsubscribe(event.DRAGSTART,this.dragStart),event.unsubscribe(event.DRAGEND,this.dragEnd),this.removePointerEvent("pointerdown",this),this.removePointerEvent("pointerup",this)}}),DroptargetEntity=Entity.extend({init:function(t,e,i){this.CHECKMETHOD_OVERLAP="overlaps",this.CHECKMETHOD_CONTAINS="contains",this.checkMethod=null,this._super(Entity,"init",[t,e,i]),event.subscribe(event.DRAGEND,this.checkOnMe.bind(this)),this.checkMethod=this[this.CHECKMETHOD_OVERLAP]},setCheckMethod:function(t){void 0!==this[t]&&(this.checkMethod=this[t])},checkOnMe:function(t,e){e&&this.checkMethod(e.getBounds())&&this.drop(e)},drop:function(){},destroy:function(){event.unsubscribe(event.DRAGEND,this.checkOnMe)}}),Jay=window.Jay,version="9.0.0";exports.initialized=!1;var skipAutoInit=!1;function boot(){!0!==exports.initialized&&(device$1._check(),pool.register("me.Entity",Entity),pool.register("me.Collectable",Collectable),pool.register("me.Trigger",Trigger),pool.register("me.Tween",Tween,!0),pool.register("me.Color",Color,!0),pool.register("me.Particle",Particle,!0),pool.register("me.Sprite",Sprite),pool.register("me.Renderable",Renderable),pool.register("me.Text",Text,!0),pool.register("me.BitmapText",BitmapText,!0),pool.register("me.BitmapTextData",BitmapTextData,!0),pool.register("me.ImageLayer",ImageLayer,!0),pool.register("me.ColorLayer",ColorLayer,!0),pool.register("me.Vector2d",Vector2d,!0),pool.register("me.Vector3d",Vector3d,!0),pool.register("me.ObservableVector2d",ObservableVector2d,!0),pool.register("me.ObservableVector3d",ObservableVector3d,!0),pool.register("me.Matrix2d",Matrix2d,!0),pool.register("me.Matrix3d",Matrix3d,!0),pool.register("me.Rect",Rect,!0),pool.register("me.Polygon",Polygon,!0),pool.register("me.Line",Line,!0),pool.register("me.Ellipse",Ellipse,!0),pool.register("me.Bounds",Bounds$1,!0),pool.register("Entity",Entity),pool.register("Collectable",Collectable),pool.register("Trigger",Trigger),pool.register("Tween",Tween,!0),pool.register("Color",Color,!0),pool.register("Particle",Particle,!0),pool.register("Sprite",Sprite),pool.register("Renderable",Renderable),pool.register("Text",Text,!0),pool.register("BitmapText",BitmapText,!0),pool.register("BitmapTextData",BitmapTextData,!0),pool.register("ImageLayer",ImageLayer,!0),pool.register("ColorLayer",ColorLayer,!0),pool.register("Vector2d",Vector2d,!0),pool.register("Vector3d",Vector3d,!0),pool.register("ObservableVector2d",ObservableVector2d,!0),pool.register("ObservableVector3d",ObservableVector3d,!0),pool.register("Matrix2d",Matrix2d,!0),pool.register("Matrix3d",Matrix3d,!0),pool.register("Rect",Rect,!0),pool.register("Polygon",Polygon,!0),pool.register("Line",Line,!0),pool.register("Ellipse",Ellipse,!0),pool.register("Bounds",Bounds$1,!0),save.init(),timer$1.init(),loader$1.setNocache(utils$1.getUriFragment().nocache||!1),state$1.init(),initKeyboardEvent(),game$1.init(),exports.initialized=!0)}device$1.onReady((function(){boot()})),exports.BitmapText=BitmapText,exports.BitmapTextData=BitmapTextData,exports.Body=Body,exports.Bounds=Bounds$1,exports.Camera2d=Camera2d,exports.CanvasRenderer=CanvasRenderer,exports.Collectable=Collectable,exports.Color=Color,exports.ColorLayer=ColorLayer,exports.Container=Container$1,exports.DraggableEntity=DraggableEntity,exports.DroptargetEntity=DroptargetEntity,exports.Ellipse=Ellipse,exports.Entity=Entity,exports.GLShader=GLShader,exports.GUI_Object=GUI_Object,exports.ImageLayer=ImageLayer,exports.Line=Line,exports.Math=math,exports.Matrix2d=Matrix2d,exports.Matrix3d=Matrix3d,exports.Object=Jay,exports.ObservableVector2d=ObservableVector2d,exports.ObservableVector3d=ObservableVector3d,exports.Particle=Particle,exports.ParticleEmitter=ParticleEmitter,exports.Pointer=Pointer,exports.Polygon=Polygon,exports.QuadTree=QuadTree,exports.Rect=Rect,exports.Renderable=Renderable,exports.Renderer=Renderer,exports.Sprite=Sprite,exports.Stage=Stage,exports.TMXHexagonalRenderer=TMXHexagonalRenderer,exports.TMXIsometricRenderer=TMXIsometricRenderer,exports.TMXLayer=TMXLayer,exports.TMXOrthogonalRenderer=TMXOrthogonalRenderer,exports.TMXRenderer=TMXRenderer,exports.TMXStaggeredRenderer=TMXStaggeredRenderer,exports.TMXTileMap=TMXTileMap,exports.TMXTileset=TMXTileset,exports.TMXTilesetGroup=TMXTilesetGroup,exports.Text=Text,exports.Tile=Tile,exports.Trigger=Trigger,exports.Tween=Tween,exports.Vector2d=Vector2d,exports.Vector3d=Vector3d,exports.WebGLCompositor=WebGLCompositor,exports.WebGLRenderer=WebGLRenderer,exports.World=World,exports.audio=audio$1,exports.boot=boot,exports.collision=collision,exports.deprecated=deprecated,exports.device=device$1,exports.event=event,exports.game=game$1,exports.input=input,exports.level=level,exports.loader=loader$1,exports.plugin=plugin,exports.plugins=plugins,exports.pool=pool,exports.save=save,exports.skipAutoInit=skipAutoInit,exports.state=state$1,exports.timer=timer$1,exports.utils=utils$1,exports.version=version,exports.video=video$1,Object.defineProperty(exports,"__esModule",{value:!0})})),me.deprecated.apply();
36
+ function(){var t;HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var e=this;if(!e.ctx||!e.ctx.listener)return e;for(var i=e._howls.length-1;i>=0;i--)e._howls[i].stereo(t);return e},HowlerGlobal.prototype.pos=function(t,e,i){var n=this;return n.ctx&&n.ctx.listener?(e="number"!=typeof e?n._pos[1]:e,i="number"!=typeof i?n._pos[2]:i,"number"!=typeof t?n._pos:(n._pos=[t,e,i],void 0!==n.ctx.listener.positionX?(n.ctx.listener.positionX.setTargetAtTime(n._pos[0],Howler.ctx.currentTime,.1),n.ctx.listener.positionY.setTargetAtTime(n._pos[1],Howler.ctx.currentTime,.1),n.ctx.listener.positionZ.setTargetAtTime(n._pos[2],Howler.ctx.currentTime,.1)):n.ctx.listener.setPosition(n._pos[0],n._pos[1],n._pos[2]),n)):n},HowlerGlobal.prototype.orientation=function(t,e,i,n,r,o){var s=this;if(!s.ctx||!s.ctx.listener)return s;var a=s._orientation;return e="number"!=typeof e?a[1]:e,i="number"!=typeof i?a[2]:i,n="number"!=typeof n?a[3]:n,r="number"!=typeof r?a[4]:r,o="number"!=typeof o?a[5]:o,"number"!=typeof t?a:(s._orientation=[t,e,i,n,r,o],void 0!==s.ctx.listener.forwardX?(s.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),s.ctx.listener.forwardY.setTargetAtTime(e,Howler.ctx.currentTime,.1),s.ctx.listener.forwardZ.setTargetAtTime(i,Howler.ctx.currentTime,.1),s.ctx.listener.upX.setTargetAtTime(n,Howler.ctx.currentTime,.1),s.ctx.listener.upY.setTargetAtTime(r,Howler.ctx.currentTime,.1),s.ctx.listener.upZ.setTargetAtTime(o,Howler.ctx.currentTime,.1)):s.ctx.listener.setOrientation(t,e,i,n,r,o),s)},Howl.prototype.init=(t=Howl.prototype.init,function(e){var i=this;return i._orientation=e.orientation||[1,0,0],i._stereo=e.stereo||null,i._pos=e.pos||null,i._pannerAttr={coneInnerAngle:void 0!==e.coneInnerAngle?e.coneInnerAngle:360,coneOuterAngle:void 0!==e.coneOuterAngle?e.coneOuterAngle:360,coneOuterGain:void 0!==e.coneOuterGain?e.coneOuterGain:0,distanceModel:void 0!==e.distanceModel?e.distanceModel:"inverse",maxDistance:void 0!==e.maxDistance?e.maxDistance:1e4,panningModel:void 0!==e.panningModel?e.panningModel:"HRTF",refDistance:void 0!==e.refDistance?e.refDistance:1,rolloffFactor:void 0!==e.rolloffFactor?e.rolloffFactor:1},i._onstereo=e.onstereo?[{fn:e.onstereo}]:[],i._onpos=e.onpos?[{fn:e.onpos}]:[],i._onorientation=e.onorientation?[{fn:e.onorientation}]:[],t.call(this,e)}),Howl.prototype.stereo=function(t,i){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"stereo",action:function(){n.stereo(t,i)}}),n;var r=void 0===Howler.ctx.createStereoPanner?"spatial":"stereo";if(void 0===i){if("number"!=typeof t)return n._stereo;n._stereo=t,n._pos=[t,0,0]}for(var o=n._getSoundIds(i),s=0;s<o.length;s++){var a=n._soundById(o[s]);if(a){if("number"!=typeof t)return a._stereo;a._stereo=t,a._pos=[t,0,0],a._node&&(a._pannerAttr.panningModel="equalpower",a._panner&&a._panner.pan||e(a,r),"spatial"===r?void 0!==a._panner.positionX?(a._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),a._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),a._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):a._panner.setPosition(t,0,0):a._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),n._emit("stereo",a._id)}}return n},Howl.prototype.pos=function(t,i,n,r){var o=this;if(!o._webAudio)return o;if("loaded"!==o._state)return o._queue.push({event:"pos",action:function(){o.pos(t,i,n,r)}}),o;if(i="number"!=typeof i?0:i,n="number"!=typeof n?-.5:n,void 0===r){if("number"!=typeof t)return o._pos;o._pos=[t,i,n]}for(var s=o._getSoundIds(r),a=0;a<s.length;a++){var h=o._soundById(s[a]);if(h){if("number"!=typeof t)return h._pos;h._pos=[t,i,n],h._node&&(h._panner&&!h._panner.pan||e(h,"spatial"),void 0!==h._panner.positionX?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(n,Howler.ctx.currentTime)):h._panner.setPosition(t,i,n)),o._emit("pos",h._id)}}return o},Howl.prototype.orientation=function(t,i,n,r){var o=this;if(!o._webAudio)return o;if("loaded"!==o._state)return o._queue.push({event:"orientation",action:function(){o.orientation(t,i,n,r)}}),o;if(i="number"!=typeof i?o._orientation[1]:i,n="number"!=typeof n?o._orientation[2]:n,void 0===r){if("number"!=typeof t)return o._orientation;o._orientation=[t,i,n]}for(var s=o._getSoundIds(r),a=0;a<s.length;a++){var h=o._soundById(s[a]);if(h){if("number"!=typeof t)return h._orientation;h._orientation=[t,i,n],h._node&&(h._panner||(h._pos||(h._pos=o._pos||[0,0,-.5]),e(h,"spatial")),void 0!==h._panner.orientationX?(h._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.orientationZ.setValueAtTime(n,Howler.ctx.currentTime)):h._panner.setOrientation(t,i,n)),o._emit("orientation",h._id)}}return o},Howl.prototype.pannerAttr=function(){var t,i,n,r=this,o=arguments;if(!r._webAudio)return r;if(0===o.length)return r._pannerAttr;if(1===o.length){if("object"!=typeof o[0])return(n=r._soundById(parseInt(o[0],10)))?n._pannerAttr:r._pannerAttr;t=o[0],void 0===i&&(t.pannerAttr||(t.pannerAttr={coneInnerAngle:t.coneInnerAngle,coneOuterAngle:t.coneOuterAngle,coneOuterGain:t.coneOuterGain,distanceModel:t.distanceModel,maxDistance:t.maxDistance,refDistance:t.refDistance,rolloffFactor:t.rolloffFactor,panningModel:t.panningModel}),r._pannerAttr={coneInnerAngle:void 0!==t.pannerAttr.coneInnerAngle?t.pannerAttr.coneInnerAngle:r._coneInnerAngle,coneOuterAngle:void 0!==t.pannerAttr.coneOuterAngle?t.pannerAttr.coneOuterAngle:r._coneOuterAngle,coneOuterGain:void 0!==t.pannerAttr.coneOuterGain?t.pannerAttr.coneOuterGain:r._coneOuterGain,distanceModel:void 0!==t.pannerAttr.distanceModel?t.pannerAttr.distanceModel:r._distanceModel,maxDistance:void 0!==t.pannerAttr.maxDistance?t.pannerAttr.maxDistance:r._maxDistance,refDistance:void 0!==t.pannerAttr.refDistance?t.pannerAttr.refDistance:r._refDistance,rolloffFactor:void 0!==t.pannerAttr.rolloffFactor?t.pannerAttr.rolloffFactor:r._rolloffFactor,panningModel:void 0!==t.pannerAttr.panningModel?t.pannerAttr.panningModel:r._panningModel})}else 2===o.length&&(t=o[0],i=parseInt(o[1],10));for(var s=r._getSoundIds(i),a=0;a<s.length;a++)if(n=r._soundById(s[a])){var h=n._pannerAttr;h={coneInnerAngle:void 0!==t.coneInnerAngle?t.coneInnerAngle:h.coneInnerAngle,coneOuterAngle:void 0!==t.coneOuterAngle?t.coneOuterAngle:h.coneOuterAngle,coneOuterGain:void 0!==t.coneOuterGain?t.coneOuterGain:h.coneOuterGain,distanceModel:void 0!==t.distanceModel?t.distanceModel:h.distanceModel,maxDistance:void 0!==t.maxDistance?t.maxDistance:h.maxDistance,refDistance:void 0!==t.refDistance?t.refDistance:h.refDistance,rolloffFactor:void 0!==t.rolloffFactor?t.rolloffFactor:h.rolloffFactor,panningModel:void 0!==t.panningModel?t.panningModel:h.panningModel};var l=n._panner;l?(l.coneInnerAngle=h.coneInnerAngle,l.coneOuterAngle=h.coneOuterAngle,l.coneOuterGain=h.coneOuterGain,l.distanceModel=h.distanceModel,l.maxDistance=h.maxDistance,l.refDistance=h.refDistance,l.rolloffFactor=h.rolloffFactor,l.panningModel=h.panningModel):(n._pos||(n._pos=r._pos||[0,0,-.5]),e(n,"spatial"))}return r},Sound.prototype.init=function(t){return function(){var e=this,i=e._parent;e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,t.call(this),e._stereo?i.stereo(e._stereo):e._pos&&i.pos(e._pos[0],e._pos[1],e._pos[2],e._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var e=this,i=e._parent;return e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,e._stereo?i.stereo(e._stereo):e._pos?i.pos(e._pos[0],e._pos[1],e._pos[2],e._id):e._panner&&(e._panner.disconnect(0),e._panner=void 0,i._refreshBuffer(e)),t.call(this)}}(Sound.prototype.reset);var e=function(t,e){"spatial"===(e=e||"spatial")?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,void 0!==t._panner.positionX?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),void 0!==t._panner.orientationX?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}}()}(howler);var ObservableVector2d=function(t){function e(e,i,n){if(void 0===e&&(e=0),void 0===i&&(i=0),t.call(this,e,i),void 0===n)throw new Error("undefined `onUpdate` callback");this.setCallback(n.onUpdate,n.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),this.setMuted(t,e),void 0!==i&&this.setCallback(i.onUpdate,i.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._x,this._y);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._x,this._y);this._y=e&&"y"in e?e.y:t},e.prototype._set=function(t,e){var i=this.onUpdate.call(this.scope,t,e,this._x,this._y);return i&&"x"in i&&"y"in i?(this._x=i.x,this._y=i.y):(this._x=t,this._y=e),this},e.prototype.setMuted=function(t,e){return this._x=t,this._y=e,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y)},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y)},e.prototype.scale=function(t,e){return this._set(this._x*t,this._y*(void 0!==e?e:t))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y)},e.prototype.div=function(t){return this._set(this._x/t,this._y/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y)},e.prototype.clamp=function(t,i){return new e(clamp(this.x,t,i),clamp(this.y,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e))},e.prototype.minV=function(t){return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y)},e.prototype.maxV=function(t){return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y))},e.prototype.negate=function(){return new e(-this._x,-this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y)},e.prototype.copy=function(t){return this._set(t.x,t.y)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},e.prototype.perp=function(){return this._set(this._y,-this._x)},e.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this._x-i,o=this._y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n)},e.prototype.dotProduct=function(t){return this._x*t.x+this._y*t.y},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this},e.prototype.distance=function(t){return Math.sqrt((this._x-t.x)*(this._x-t.x)+(this._y-t.y)*(this._y-t.y))},e.prototype.clone=function(){return pool.pull("ObservableVector2d",this._x,this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.toVector2d=function(){return pool.pull("Vector2d",this._x,this._y)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y},Object.defineProperties(e.prototype,i),e}(Vector2d),Vector3d=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this).onResetEvent.apply(t,e)};Vector3d.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype._set=function(t,e,i){return void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype.set=function(t,e,i){if(t!==+t||e!==+e||void 0!==i&&i!==+i)throw new Error("invalid x, y, z parameters (not a number)");return this._set(t,e,i)},Vector3d.prototype.setZero=function(){return this.set(0,0,0)},Vector3d.prototype.setV=function(t){return this._set(t.x,t.y,t.z)},Vector3d.prototype.add=function(t){return this._set(this.x+t.x,this.y+t.y,this.z+(t.z||0))},Vector3d.prototype.sub=function(t){return this._set(this.x-t.x,this.y-t.y,this.z-(t.z||0))},Vector3d.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this.x*t,this.y*e,this.z*(i||1))},Vector3d.prototype.scaleV=function(t){return this.scale(t.x,t.y,t.z)},Vector3d.prototype.toIso=function(){return this._set(this.x-this.y,.5*(this.x+this.y),this.z)},Vector3d.prototype.to2d=function(){return this._set(this.y+this.x/2,this.y-this.x/2,this.z)},Vector3d.prototype.div=function(t){return this._set(this.x/t,this.y/t,this.z/t)},Vector3d.prototype.abs=function(){return this._set(this.x<0?-this.x:this.x,this.y<0?-this.y:this.y,this.z<0?-this.z:this.z)},Vector3d.prototype.clamp=function(t,e){return new Vector3d(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.clampSelf=function(t,e){return this._set(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.minV=function(t){var e=t.z||0;return this._set(this.x<t.x?this.x:t.x,this.y<t.y?this.y:t.y,this.z<e?this.z:e)},Vector3d.prototype.maxV=function(t){var e=t.z||0;return this._set(this.x>t.x?this.x:t.x,this.y>t.y?this.y:t.y,this.z>e?this.z:e)},Vector3d.prototype.floor=function(){return new Vector3d(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.floorSelf=function(){return this._set(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.ceil=function(){return new Vector3d(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.ceilSelf=function(){return this._set(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.negate=function(){return new Vector3d(-this.x,-this.y,-this.z)},Vector3d.prototype.negateSelf=function(){return this._set(-this.x,-this.y,-this.z)},Vector3d.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},Vector3d.prototype.equals=function(){var t,e,i;return arguments.length>=2?(t=arguments[0],e=arguments[1],i=arguments[2]):(t=arguments[0].x,e=arguments[0].y,i=arguments[0].z),void 0===i&&(i=this.z),this.x===t&&this.y===e&&this.z===i},Vector3d.prototype.normalize=function(){return this.div(this.length()||1)},Vector3d.prototype.perp=function(){return this._set(this.y,-this.x,this.z)},Vector3d.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this.x-i,o=this.y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n,this.z)},Vector3d.prototype.dotProduct=function(t){return this.x*t.x+this.y*t.y+this.z*(void 0!==t.z?t.z:this.z)},Vector3d.prototype.length2=function(){return this.dotProduct(this)},Vector3d.prototype.length=function(){return Math.sqrt(this.length2())},Vector3d.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},Vector3d.prototype.distance=function(t){var e=this.x-t.x,i=this.y-t.y,n=this.z-(t.z||0);return Math.sqrt(e*e+i*i+n*n)},Vector3d.prototype.angle=function(t){return Math.acos(clamp(this.dotProduct(t)/(this.length()*t.length()),-1,1))},Vector3d.prototype.project=function(t){var e=this.dotProduct(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.projectN=function(t){var e=this.dotProduct(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.clone=function(){return pool.pull("Vector3d",this.x,this.y,this.z)},Vector3d.prototype.toString=function(){return"x:"+this.x+",y:"+this.y+",z:"+this.z};var ObservableVector3d=function(t){function e(e,i,n,r){if(void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),t.call(this,e,i,n),void 0===r)throw new Error("undefined `onUpdate` callback");this.setCallback(r.onUpdate,r.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0},z:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,n){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.setMuted(t,e,i),void 0!==n&&this.setCallback(n.onUpdate,n.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._z,this._x,this._y,this._z);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._z,this._x,this._y,this._z);this._y=e&&"y"in e?e.y:t},i.z.get=function(){return this._z},i.z.set=function(t){var e=this.onUpdate.call(this.scope,this._x,this._y,t,this._x,this._y,this._z);this._z=e&&"z"in e?e.z:t},e.prototype._set=function(t,e,i){var n=this.onUpdate.call(this.scope,t,e,i,this._x,this._y,this._z);return n&&"x"in n&&"y"in n&&"z"in n?(this._x=n.x,this._y=n.y,this._z=n.z):(this._x=t,this._y=e,this._z=i||0),this},e.prototype.setMuted=function(t,e,i){return this._x=t,this._y=e,this._z=i||0,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y,this._z+(t.z||0))},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y,this._z-(t.z||0))},e.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this._x*t,this._y*e,this._z*(i||1))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y,this._z*(t.z||1))},e.prototype.div=function(t){return this._set(this._x/t,this._y/t,this._z/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y,this._Z<0?-this._z:this._z)},e.prototype.clamp=function(t,i){return new e(clamp(this._x,t,i),clamp(this._y,t,i),clamp(this._z,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e),clamp(this._z,t,e))},e.prototype.minV=function(t){var e=t.z||0;return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y,this._z<e?this._z:e)},e.prototype.maxV=function(t){var e=t.z||0;return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y,this._z>e?this._z:e)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z))},e.prototype.negate=function(){return new e(-this._x,-this._y,-this._z,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y,-this._z)},e.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y&&this._z===(t.z||this._z)},e.prototype.perp=function(){return this._set(this._y,-this._x,this._z)},e.prototype.rotate=function(t,e){var i=0,n=0;"object"==typeof e&&(i=e.x,n=e.y);var r=this.x-i,o=this.y-n,s=Math.cos(t),a=Math.sin(t);return this._set(r*s-o*a+i,r*a+o*s+n,this.z)},e.prototype.dotProduct=function(t){return this._x*t.x+this._y*t.y+this._z*(t.z||1)},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this._z+=(t.z-this._z)*e,this},e.prototype.distance=function(t){var e=this._x-t.x,i=this._y-t.y,n=this._z-(t.z||0);return Math.sqrt(e*e+i*i+n*n)},e.prototype.clone=function(){return pool.pull("ObservableVector3d",this._x,this._y,this._z,{onUpdate:this.onUpdate})},e.prototype.toVector3d=function(){return pool.pull("Vector3d",this._x,this._y,this._z)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y+",z:"+this._z},Object.defineProperties(e.prototype,i),e}(Vector3d),earcut$2={exports:{}};function earcut(t,e,i){i=i||2;var n,r,o,s,a,h,l,u=e&&e.length,c=u?e[0]*i:t.length,d=linkedList(t,0,c,i,!0),p=[];if(!d||d.next===d.prev)return p;if(u&&(d=eliminateHoles(t,e,d,i)),t.length>80*i){n=o=t[0],r=s=t[1];for(var f=i;f<c;f+=i)(a=t[f])<n&&(n=a),(h=t[f+1])<r&&(r=h),a>o&&(o=a),h>s&&(s=h);l=0!==(l=Math.max(o-n,s-r))?1/l:0}return earcutLinked(d,p,i,n,r,l),p}function linkedList(t,e,i,n,r){var o,s;if(r===signedArea(t,e,i,n)>0)for(o=e;o<i;o+=n)s=insertNode(o,t[o],t[o+1],s);else for(o=i-n;o>=e;o-=n)s=insertNode(o,t[o],t[o+1],s);return s&&equals(s,s.next)&&(removeNode(s),s=s.next),s}function filterPoints(t,e){if(!t)return t;e||(e=t);var i,n=t;do{if(i=!1,n.steiner||!equals(n,n.next)&&0!==area(n.prev,n,n.next))n=n.next;else{if(removeNode(n),(n=e=n.prev)===n.next)break;i=!0}}while(i||n!==e);return e}function earcutLinked(t,e,i,n,r,o,s){if(t){!s&&o&&indexCurve(t,n,r,o);for(var a,h,l=t;t.prev!==t.next;)if(a=t.prev,h=t.next,o?isEarHashed(t,n,r,o):isEar(t))e.push(a.i/i),e.push(t.i/i),e.push(h.i/i),removeNode(t),t=h.next,l=h.next;else if((t=h)===l){s?1===s?earcutLinked(t=cureLocalIntersections(filterPoints(t),e,i),e,i,n,r,o,2):2===s&&splitEarcut(t,e,i,n,r,o):earcutLinked(filterPoints(t),e,i,n,r,o,1);break}}}function isEar(t){var e=t.prev,i=t,n=t.next;if(area(e,i,n)>=0)return!1;for(var r=t.next.next;r!==t.prev;){if(pointInTriangle(e.x,e.y,i.x,i.y,n.x,n.y,r.x,r.y)&&area(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function isEarHashed(t,e,i,n){var r=t.prev,o=t,s=t.next;if(area(r,o,s)>=0)return!1;for(var a=r.x<o.x?r.x<s.x?r.x:s.x:o.x<s.x?o.x:s.x,h=r.y<o.y?r.y<s.y?r.y:s.y:o.y<s.y?o.y:s.y,l=r.x>o.x?r.x>s.x?r.x:s.x:o.x>s.x?o.x:s.x,u=r.y>o.y?r.y>s.y?r.y:s.y:o.y>s.y?o.y:s.y,c=zOrder(a,h,e,i,n),d=zOrder(l,u,e,i,n),p=t.prevZ,f=t.nextZ;p&&p.z>=c&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=c;){if(p!==t.prev&&p!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&pointInTriangle(r.x,r.y,o.x,o.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function cureLocalIntersections(t,e,i){var n=t;do{var r=n.prev,o=n.next.next;!equals(r,o)&&intersects(r,n,n.next,o)&&locallyInside(r,o)&&locallyInside(o,r)&&(e.push(r.i/i),e.push(n.i/i),e.push(o.i/i),removeNode(n),removeNode(n.next),n=t=o),n=n.next}while(n!==t);return filterPoints(n)}function splitEarcut(t,e,i,n,r,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&isValidDiagonal(s,a)){var h=splitPolygon(s,a);return s=filterPoints(s,s.next),h=filterPoints(h,h.next),earcutLinked(s,e,i,n,r,o),void earcutLinked(h,e,i,n,r,o)}a=a.next}s=s.next}while(s!==t)}function eliminateHoles(t,e,i,n){var r,o,s,a=[];for(r=0,o=e.length;r<o;r++)(s=linkedList(t,e[r]*n,r<o-1?e[r+1]*n:t.length,n,!1))===s.next&&(s.steiner=!0),a.push(getLeftmost(s));for(a.sort(compareX),r=0;r<a.length;r++)i=filterPoints(i=eliminateHole(a[r],i),i.next);return i}function compareX(t,e){return t.x-e.x}function eliminateHole(t,e){var i=findHoleBridge(t,e);if(!i)return e;var n=splitPolygon(i,t),r=filterPoints(i,i.next);return filterPoints(n,n.next),e===i?r:e}function findHoleBridge(t,e){var i,n=e,r=t.x,o=t.y,s=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var a=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(a<=r&&a>s){if(s=a,a===r){if(o===n.y)return n;if(o===n.next.y)return n.next}i=n.x<n.next.x?n:n.next}}n=n.next}while(n!==e);if(!i)return null;if(r===s)return i;var h,l=i,u=i.x,c=i.y,d=1/0;n=i;do{r>=n.x&&n.x>=u&&r!==n.x&&pointInTriangle(o<c?r:s,o,u,c,o<c?s:r,o,n.x,n.y)&&(h=Math.abs(o-n.y)/(r-n.x),locallyInside(n,t)&&(h<d||h===d&&(n.x>i.x||n.x===i.x&&sectorContainsSector(i,n)))&&(i=n,d=h)),n=n.next}while(n!==l);return i}function sectorContainsSector(t,e){return area(t.prev,t,e.prev)<0&&area(e.next,t,t.next)<0}function indexCurve(t,e,i,n){var r=t;do{null===r.z&&(r.z=zOrder(r.x,r.y,e,i,n)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,sortLinked(r)}function sortLinked(t){var e,i,n,r,o,s,a,h,l=1;do{for(i=t,t=null,o=null,s=0;i;){for(s++,n=i,a=0,e=0;e<l&&(a++,n=n.nextZ);e++);for(h=l;a>0||h>0&&n;)0!==a&&(0===h||!n||i.z<=n.z)?(r=i,i=i.nextZ,a--):(r=n,n=n.nextZ,h--),o?o.nextZ=r:t=r,r.prevZ=o,o=r;i=n}o.nextZ=null,l*=2}while(s>1);return t}function zOrder(t,e,i,n,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*r)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*r)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function getLeftmost(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function pointInTriangle(t,e,i,n,r,o,s,a){return(r-s)*(e-a)-(t-s)*(o-a)>=0&&(t-s)*(n-a)-(i-s)*(e-a)>=0&&(i-s)*(o-a)-(r-s)*(n-a)>=0}function isValidDiagonal(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!intersectsPolygon(t,e)&&(locallyInside(t,e)&&locallyInside(e,t)&&middleInside(t,e)&&(area(t.prev,t,e.prev)||area(t,e.prev,e))||equals(t,e)&&area(t.prev,t,t.next)>0&&area(e.prev,e,e.next)>0)}function area(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function equals(t,e){return t.x===e.x&&t.y===e.y}function intersects(t,e,i,n){var r=sign(area(t,e,i)),o=sign(area(t,e,n)),s=sign(area(i,n,t)),a=sign(area(i,n,e));return r!==o&&s!==a||(!(0!==r||!onSegment(t,i,e))||(!(0!==o||!onSegment(t,n,e))||(!(0!==s||!onSegment(i,t,n))||!(0!==a||!onSegment(i,e,n)))))}function onSegment(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function sign(t){return t>0?1:t<0?-1:0}function intersectsPolygon(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&intersects(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}function locallyInside(t,e){return area(t.prev,t,t.next)<0?area(t,e,t.next)>=0&&area(t,t.prev,e)>=0:area(t,e,t.prev)<0||area(t,t.next,e)<0}function middleInside(t,e){var i=t,n=!1,r=(t.x+e.x)/2,o=(t.y+e.y)/2;do{i.y>o!=i.next.y>o&&i.next.y!==i.y&&r<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==t);return n}function splitPolygon(t,e){var i=new Node$1(t.i,t.x,t.y),n=new Node$1(e.i,e.x,e.y),r=t.next,o=e.prev;return t.next=e,e.prev=t,i.next=r,r.prev=i,n.next=i,i.prev=n,o.next=n,n.prev=o,n}function insertNode(t,e,i,n){var r=new Node$1(t,e,i);return n?(r.next=n.next,r.prev=n,n.next.prev=r,n.next=r):(r.prev=r,r.next=r),r}function removeNode(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Node$1(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function signedArea(t,e,i,n){for(var r=0,o=e,s=i-n;o<i;o+=n)r+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return r}earcut$2.exports=earcut,earcut$2.exports.default=earcut,earcut.deviation=function(t,e,i,n){var r=e&&e.length,o=r?e[0]*i:t.length,s=Math.abs(signedArea(t,0,o,i));if(r)for(var a=0,h=e.length;a<h;a++){var l=e[a]*i,u=a<h-1?e[a+1]*i:t.length;s-=Math.abs(signedArea(t,l,u,i))}var c=0;for(a=0;a<n.length;a+=3){var d=n[a]*i,p=n[a+1]*i,f=n[a+2]*i;c+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},earcut.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},n=0,r=0;r<t.length;r++){for(var o=0;o<t[r].length;o++)for(var s=0;s<e;s++)i.vertices.push(t[r][o][s]);r>0&&(n+=t[r-1].length,i.holes.push(n))}return i};var earcut$1=earcut$2.exports;!function(){function t(t,e,i){Object.keys(i).forEach((function(n){if(e[n]=i[n],"function"!=typeof i[n])throw new TypeError("extend: Method `"+n+"` is not a function");Object.defineProperty(t.prototype,n,{configurable:!0,value:i[n]})}))}function e(t,e,i){return t.prototype[e].apply(this,i)}var i=function(){Object.apply(this,arguments)};(i.prototype=Object.create(Object.prototype)).constructor=i,Object.defineProperty(i,"extend",{value:function i(){for(var n=arguments,r={},o=new Array(arguments.length),s=0;s<arguments.length;s++)o.push(n[s]);function a(){return this.init.apply(this,arguments),this}if(a.prototype=Object.create(this.prototype),o.forEach((function(e){t(a,r,e.__methods__||e)})),!("init"in a.prototype))throw new TypeError("extend: Class is missing a constructor named `init`");return Object.defineProperty(a.prototype,"_super",{value:e}),Object.defineProperty(a,"__methods__",{value:r}),a.extend=i,a}}),"undefined"!=typeof window&&(window.Jay=i)}();var Polygon=window.Jay.extend({init:function(t,e,i){this.pos=new Vector2d,this._bounds,this.points=null,this.edges=[],this.indices=[],this.normals=[],this.shapeType="Polygon",this.setShape(t,e,i)},onResetEvent:function(t,e,i){this.setShape(t,e,i)},setShape:function(t,e,i){return this.pos.set(t,e),this.setVertices(i),this},setVertices:function(t){if(!Array.isArray(t))return this;if(t[0]instanceof Vector2d)this.points=t;else{var e=this.points=[];if("object"==typeof t[0])t.forEach((function(t){e.push(new Vector2d(t.x,t.y))}));else for(var i=0;i<t.length;i+=2)e.push(new Vector2d(t[i],t[i+1]))}return this.recalc(),this.updateBounds(),this},transform:function(t){for(var e=this.points,i=e.length,n=0;n<i;n++)t.apply(e[n]);return this.recalc(),this.updateBounds(),this},toIso:function(){return this.rotate(Math.PI/4).scale(Math.SQRT2,Math.SQRT1_2)},to2d:function(){return this.scale(Math.SQRT1_2,Math.SQRT2).rotate(-Math.PI/4)},rotate:function(t,e){if(0!==t){for(var i=this.points,n=i.length,r=0;r<n;r++)i[r].rotate(t,e);this.recalc(),this.updateBounds()}return this},scale:function(t,e){e=void 0!==e?e:t;for(var i=this.points,n=i.length,r=0;r<n;r++)i[r].scale(t,e);return this.recalc(),this.updateBounds(),this},scaleV:function(t){return this.scale(t.x,t.y)},recalc:function(){var t,e=this.edges,i=this.normals,n=this.indices,r=this.points,o=r.length;if(o<3)throw new Error("Requires at least 3 points");for(t=0;t<o;t++)void 0===e[t]&&(e[t]=new Vector2d),e[t].copy(r[(t+1)%o]).sub(r[t]),void 0===i[t]&&(i[t]=new Vector2d),i[t].copy(e[t]).perp().normalize();return e.length=o,i.length=o,n.length=0,this},getIndices:function(t,e){return 0===this.indices.length&&(this.indices=earcut$1(this.points.flatMap((function(t){return[t.x,t.y]})))),this.indices},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},contains:function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);for(var i=!1,n=this.pos.x,r=this.pos.y,o=this.points,s=o.length,a=0,h=s-1;a<s;h=a++){var l=o[a].y+r,u=o[a].x+n,c=o[h].y+r,d=o[h].x+n;l>e!=c>e&&t<(d-u)*(e-l)/(c-l)+u&&(i=!i)}return i},getBounds:function(){return void 0===this._bounds&&(this._bounds=pool.pull("Bounds")),this._bounds},updateBounds:function(){var t=this.getBounds();return t.update(this.points),t.translate(this.pos),t},clone:function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Polygon(this.pos.x,this.pos.y,t)}}),Rect=Polygon.extend({init:function(t,e,i,n){this._super(Polygon,"init",[t,e,[new Vector2d(0,0),new Vector2d(i,0),new Vector2d(i,n),new Vector2d(0,n)]]),this.shapeType="Rectangle"},onResetEvent:function(t,e,i,n){this.setShape(t,e,i,n)},setShape:function(t,e,i,n){var r=i;return this.pos.set(t,e),4===arguments.length&&((r=this.points)[0].set(0,0),r[1].set(i,0),r[2].set(i,n),r[3].set(0,n)),this.setVertices(r),this},resize:function(t,e){return this.width=t,this.height=e,this},scale:function(t,e){return void 0===e&&(e=t),this.width*=t,this.height*=e,this},clone:function(){return new Rect(this.pos.x,this.pos.y,this.width,this.height)},copy:function(t){return this.setShape(t.pos.x,t.pos.y,t.width,t.height)},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this},shift:function(){2===arguments.length?this.pos.set(arguments[0],arguments[1]):this.pos.setV(arguments[0])},union:function(t){var e=Math.min(this.left,t.left),i=Math.min(this.top,t.top);return this.resize(Math.max(this.right,t.right)-e,Math.max(this.bottom,t.bottom)-i),this.pos.set(e,i),this},overlaps:function(t){return this.left<t.right&&t.left<this.right&&this.top<t.bottom&&t.top<this.bottom},contains:function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Rect?(t=r.left,e=r.right,i=r.top,n=r.bottom):(t=e=r.x,i=n=r.y),t>=this.left&&e<=this.right&&i>=this.top&&n<=this.bottom},equals:function(t){return t.left===this.left&&t.right===this.right&&t.top===this.top&&t.bottom===this.bottom},isFinite:function(){return isFinite(this.pos.x)&&isFinite(this.pos.y)&&isFinite(this.width)&&isFinite(this.height)},toPolygon:function(){return new Polygon(this.pos.x,this.pos.y,this.points)}});Object.defineProperty(Rect.prototype,"left",{get:function(){return this.pos.x},configurable:!0}),Object.defineProperty(Rect.prototype,"right",{get:function(){var t=this.width;return this.pos.x+t||t},configurable:!0}),Object.defineProperty(Rect.prototype,"top",{get:function(){return this.pos.y},configurable:!0}),Object.defineProperty(Rect.prototype,"bottom",{get:function(){var t=this.height;return this.pos.y+t||t},configurable:!0}),Object.defineProperty(Rect.prototype,"width",{get:function(){return this.points[2].x},set:function(t){this.points[1].x=this.points[2].x=t,this.recalc(),this.updateBounds()},configurable:!0}),Object.defineProperty(Rect.prototype,"height",{get:function(){return this.points[2].y},set:function(t){this.points[2].y=this.points[3].y=t,this.recalc(),this.updateBounds()},configurable:!0}),Object.defineProperty(Rect.prototype,"centerX",{get:function(){return isFinite(this.width)?this.pos.x+this.width/2:this.width},set:function(t){this.pos.x=t-this.width/2},configurable:!0}),Object.defineProperty(Rect.prototype,"centerY",{get:function(){return isFinite(this.height)?this.pos.y+this.height/2:this.height},set:function(t){this.pos.y=t-this.height/2},configurable:!0});var _keyStatus={},_keyLock={},_keyLocked={},_keyRefs={},_preventDefaultForKeys={},_keyBindings={},keyDownEvent=function(t,e,i){e=e||t.keyCode||t.button;var n=_keyBindings[e];if(event.publish(event.KEYDOWN,[n,e,!n||!_keyLocked[n]]),n){if(!_keyLocked[n]){var r=void 0!==i?i:e;_keyRefs[n][r]||(_keyStatus[n]++,_keyRefs[n][r]=!0)}return!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyUpEvent=function(t,e,i){e=e||t.keyCode||t.button;var n=_keyBindings[e];if(event.publish(event.KEYUP,[n,e]),n){var r=void 0!==i?i:e;return _keyRefs[n][r]=void 0,_keyStatus[n]>0&&_keyStatus[n]--,_keyLocked[n]=!1,!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyBoardEventTarget=null,KEY={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PRINT_SCREEN:42,INSERT:45,DELETE:46,NUM0:48,NUM1:49,NUM2:50,NUM3:51,NUM4:52,NUM5:53,NUM6:54,NUM7:55,NUM8:56,NUM9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,WINDOW_KEY:91,NUMPAD0:96,NUMPAD1:97,NUMPAD2:98,NUMPAD3:99,NUMPAD4:100,NUMPAD5:101,NUMPAD6:102,NUMPAD7:103,NUMPAD8:104,NUMPAD9:105,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,TILDE:126,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,PLUS:187,COMMA:188,MINUS:189,PERIOD:190,FORWAND_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222};function initKeyboardEvent(){null===keyBoardEventTarget&&!1===device$1.isMobile&&((keyBoardEventTarget=window).addEventListener("keydown",keyDownEvent,!1),keyBoardEventTarget.addEventListener("keyup",keyUpEvent,!1))}function isKeyPressed(t){return!(!_keyStatus[t]||_keyLocked[t])&&(_keyLock[t]&&(_keyLocked[t]=!0),!0)}function keyStatus(t){return _keyStatus[t]>0}function triggerKeyEvent(t,e,i){!0===e?keyDownEvent({},t,i):keyUpEvent({},t,i)}function bindKey(t,e,i,n){void 0===n&&(n=preventDefault),_keyBindings[t]=e,_preventDefaultForKeys[t]=n,_keyStatus[e]=0,_keyLock[e]=i||!1,_keyLocked[e]=!1,_keyRefs[e]={}}function getBindingKey(t){return _keyBindings[t]}function unlockKey(t){_keyLocked[t]=!1}function unbindKey(t){var e=_keyBindings[t];_keyStatus[e]=0,_keyLock[e]=!1,_keyRefs[e]={},_keyBindings[t]=null,_preventDefaultForKeys[t]=null}var viewportOffset=new Vector2d,Pointer=Rect.extend({init:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=1),void 0===n&&(n=1),this.LEFT=0,this.MIDDLE=1,this.RIGHT=2,this.event=void 0,this.type=void 0,this.button=0,this.isPrimary=!1,this.pageX=0,this.pageY=0,this.clientX=0,this.clientY=0,this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0,this.gameX=0,this.gameY=0,this.gameScreenX=0,this.gameScreenY=0,this.gameWorldX=0,this.gameWorldY=0,this.gameLocalX=0,this.gameLocalY=0,this.pointerId=void 0,this.bind=[0,0,0],this._super(Rect,"init",[t,e,i,n])},setEvent:function(t,e,i,n,r,o){void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),void 0===r&&(r=0),void 0===o&&(o=1);var s=1,a=1;this.event=t,this.pageX=e,this.pageY=i,this.clientX=n,this.clientY=r,globalToLocal(this.pageX,this.pageY,this.pos),this.isNormalized=!device$1.PointerEvent||device$1.PointerEvent&&!(t instanceof window.PointerEvent),"wheel"===t.type?(this.deltaMode=t.deltaMode||0,this.deltaX=t.deltaX||0,this.deltaY=t.deltaY||0,this.deltaZ=t.deltaZ||0):(this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0),this.pointerId=o,this.isPrimary=void 0===t.isPrimary||t.isPrimary,this.button=t.button||0,this.type=t.type,this.gameScreenX=this.pos.x,this.gameScreenY=this.pos.y,void 0!==game$1.viewport&&game$1.viewport.localToWorld(this.gameScreenX,this.gameScreenY,viewportOffset),this.gameWorldX=viewportOffset.x,this.gameWorldY=viewportOffset.y,!1===this.isNormalized?(s=t.width||1,a=t.height||1):"number"==typeof t.radiusX&&(s=2*t.radiusX||1,a=2*t.radiusY||1),this.resize(s,a)}}),T_POINTERS=[],eventHandlers=new Map,currentPointer,pointerInitialized=!1,lastTimeStamp=0,activeEventList=[],WHEEL=["wheel"],POINTER_MOVE=["pointermove","mousemove","touchmove"],POINTER_DOWN=["pointerdown","mousedown","touchstart"],POINTER_UP=["pointerup","mouseup","touchend"],POINTER_CANCEL=["pointercancel","mousecancel","touchcancel"],POINTER_ENTER=["pointerenter","mouseenter","touchenter"],POINTER_OVER=["pointerover","mouseover","touchover"],POINTER_LEAVE=["pointerleave","mouseleave","touchleave"],pointerEventList=[WHEEL[0],POINTER_MOVE[0],POINTER_DOWN[0],POINTER_UP[0],POINTER_CANCEL[0],POINTER_ENTER[0],POINTER_OVER[0],POINTER_LEAVE[0]],mouseEventList=[WHEEL[0],POINTER_MOVE[1],POINTER_DOWN[1],POINTER_UP[1],POINTER_CANCEL[1],POINTER_ENTER[1],POINTER_OVER[1],POINTER_LEAVE[1]],touchEventList=[POINTER_MOVE[2],POINTER_DOWN[2],POINTER_UP[2],POINTER_CANCEL[2],POINTER_ENTER[2],POINTER_OVER[2],POINTER_LEAVE[2]],pointerEventMap={wheel:WHEEL,pointermove:POINTER_MOVE,pointerdown:POINTER_DOWN,pointerup:POINTER_UP,pointercancel:POINTER_CANCEL,pointerenter:POINTER_ENTER,pointerover:POINTER_OVER,pointerleave:POINTER_LEAVE},normalizedEvents=[];function registerEventListener(t,e){for(var i=0;i<t.length;i++)-1===POINTER_MOVE.indexOf(t[i])&&pointerEventTarget.addEventListener(t[i],e,{passive:!1===preventDefault})}function enablePointerEvent(){if(!pointerInitialized){currentPointer=new Rect(0,0,1,1),pointer=new Pointer(0,0,1,1);for(var t=0;t<device$1.maxTouchPoints;t++)T_POINTERS.push(new Pointer);var e;null===pointerEventTarget&&(pointerEventTarget=video$1.renderer.getScreenCanvas()),activeEventList=device$1.PointerEvent?pointerEventList:mouseEventList,device$1.touch&&!device$1.PointerEvent&&(activeEventList=activeEventList.concat(touchEventList)),registerEventListener(activeEventList,onPointerEvent),void 0===throttlingInterval&&(throttlingInterval=~~(1e3/timer$1.maxfps)),!0===device$1.autoFocus&&(device$1.focus(),pointerEventTarget.addEventListener(activeEventList[2],(function(){device$1.focus()}),{passive:!1===preventDefault}));var i=findAllActiveEvents(activeEventList,POINTER_MOVE);if(throttlingInterval<17)for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],onMoveEvent,{passive:!0});else for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],utils$1.function.throttle(onMoveEvent,throttlingInterval,!1),{passive:!0});setTouchAction(pointerEventTarget),pointerInitialized=!0}}function findActiveEvent(t,e){for(var i=0;i<e.length;i++){if(-1!==t.indexOf(e[i]))return e[i]}}function findAllActiveEvents(t,e){for(var i=[],n=0;n<e.length;n++){-1!==t.indexOf(e[n])&&i.push(e[n])}return i}function triggerEvent(t,e,i,n){var r;if(t.callbacks[e]){t.pointerId=n;for(var o=t.callbacks[e].length-1;o>=0&&(r=t.callbacks[e][o]);o--)if(!1===r(i))return!0}return!1}function dispatchEvent(t){for(var e=!1;t.length>0;){var i=t.pop();if(T_POINTERS.push(i),void 0!==i.event.timeStamp){if(i.event.timeStamp<lastTimeStamp)continue;lastTimeStamp=i.event.timeStamp}currentPointer.setShape(i.gameWorldX,i.gameWorldY,i.width,i.height),POINTER_MOVE.includes(i.type)&&(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY,event.publish(event.POINTERMOVE,[i]));for(var n,r=game$1.world.broadphase.retrieve(currentPointer,Container$1.prototype._sortReverseZ),o=(r=r.concat([game$1.viewport])).length;n=r[--o];){if(eventHandlers.has(n)&&!0!==n.isKinematic){var s=eventHandlers.get(n),a=s.region,h=a.ancestor,l=a.getBounds(),u=!1;if(!0===a.floating?(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY):(i.gameX=i.gameLocalX=i.gameWorldX,i.gameY=i.gameLocalY=i.gameWorldY),void 0!==h){var c=h.getBounds();i.gameLocalX=i.gameX-c.x,i.gameLocalY=i.gameY-c.y}if(a instanceof Renderable){var d=i.gameX,p=i.gameY;if(!a.currentTransform.isIdentity()){var f=a.currentTransform.applyInverse(pool.pull("Vector2d",d,p));d=f.x,p=f.y,pool.push(f)}u=l.contains(d,p)}else u=l.contains(i.gameX,i.gameY)&&(l===a||a.contains(i.gameLocalX,i.gameLocalY));switch(i.type){case POINTER_MOVE[0]:case POINTER_MOVE[1]:case POINTER_MOVE[2]:case POINTER_MOVE[3]:if(s.pointerId!==i.pointerId||u){if(null===s.pointerId&&u&&triggerEvent(s,findActiveEvent(activeEventList,POINTER_ENTER),i,i.pointerId)){e=!0;break}}else if(triggerEvent(s,findActiveEvent(activeEventList,POINTER_LEAVE),i,null)){e=!0;break}if(u&&triggerEvent(s,i.type,i,i.pointerId)){e=!0;break}break;case POINTER_UP[0]:case POINTER_UP[1]:case POINTER_UP[2]:case POINTER_UP[3]:if(s.pointerId===i.pointerId&&u&&triggerEvent(s,i.type,i,null)){e=!0;break}break;case POINTER_CANCEL[0]:case POINTER_CANCEL[1]:case POINTER_CANCEL[2]:case POINTER_CANCEL[3]:if(s.pointerId===i.pointerId&&triggerEvent(s,i.type,i,null)){e=!0;break}break;default:if(u&&triggerEvent(s,i.type,i,i.pointerId)){e=!0;break}}}if(!0===e)break}}return e}function normalizeEvent(t){var e;if(device$1.TouchEvent&&t.changedTouches)for(var i=0,n=t.changedTouches.length;i<n;i++){var r=t.changedTouches[i];(e=T_POINTERS.pop()).setEvent(t,r.pageX,r.pageY,r.clientX,r.clientY,r.identifier),normalizedEvents.push(e)}else(e=T_POINTERS.pop()).setEvent(t,t.pageX,t.pageY,t.clientX,t.clientY,t.pointerId),normalizedEvents.push(e);return!1===t.isPrimary||(normalizedEvents[0].isPrimary=!0,Object.assign(e,normalizedEvents[0])),normalizedEvents}function onMoveEvent(t){dispatchEvent(normalizeEvent(t))}function onPointerEvent(t){normalizeEvent(t);var e=normalizedEvents[0].button;(dispatchEvent(normalizedEvents)||"wheel"===t.type)&&t.preventDefault();var i=pointer.bind[e];i&&triggerKeyEvent(i,POINTER_DOWN.includes(t.type),e+1)}var pointerEventTarget=null,pointer,throttlingInterval;function globalToLocal(t,e,i){i=i||new Vector2d;var n=device$1.getElementBounds(video$1.renderer.getScreenCanvas()),r=device$1.devicePixelRatio;t-=n.left+(window.pageXOffset||0),e-=n.top+(window.pageYOffset||0);var o=video$1.scaleRatio;return 1===o.x&&1===o.y||(t/=o.x,e/=o.y),i.set(t*r,e*r)}function setTouchAction(t,e){t.style["touch-action"]=e||"none"}function bindPointer(){var t=arguments.length<2?pointer.LEFT:arguments[0],e=arguments.length<2?arguments[0]:arguments[1];if(enablePointerEvent(),!getBindingKey(e))throw new Error("no action defined for keycode "+e);pointer.bind[t]=e}function unbindPointer(t){pointer.bind[void 0===t?pointer.LEFT:t]=null}function registerPointerEvent(t,e,i){if(enablePointerEvent(),-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);if(void 0===e)throw new Error("registerPointerEvent: region for "+toString(e)+" event is undefined ");var n=findAllActiveEvents(activeEventList,pointerEventMap[t]);eventHandlers.has(e)||eventHandlers.set(e,{region:e,callbacks:{},pointerId:null});for(var r=eventHandlers.get(e),o=0;o<n.length;o++)t=n[o],r.callbacks[t]?r.callbacks[t].push(i):r.callbacks[t]=[i]}function releasePointerEvent(t,e,i){if(-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);var n=findAllActiveEvents(activeEventList,pointerEventMap[t]),r=eventHandlers.get(e);if(void 0!==r){for(var o=0;o<n.length;o++)if(t=n[o],r.callbacks[t]){if(void 0!==i)utils$1.array.remove(r.callbacks[t],i);else for(;r.callbacks[t].length>0;)r.callbacks[t].pop();0===r.callbacks[t].length&&delete r.callbacks[t]}0===Object.keys(r.callbacks).length&&eventHandlers.delete(e)}}function releaseAllPointerEvents(t){if(eventHandlers.has(t))for(var e=0;e<pointerEventList.length;e++)this.releasePointerEvent(pointerEventList[e],t)}var deadzone=.1;function defaultNormalizeFn(t){return t}function wiredXbox360NormalizeFn(t,e,i){return i===this.GAMEPAD.BUTTONS.L2||i===this.GAMEPAD.BUTTONS.R2?(t+1)/2:t}function ouyaNormalizeFn(t,e,i){return t=t>0?i===this.GAMEPAD.BUTTONS.L2?Math.max(0,t-2e4)/111070:(t-1)/131070:(65536+t)/131070+.5}var vendorProductRE=/^([0-9a-f]{1,4})-([0-9a-f]{1,4})-/i,leadingZeroRE=/^0+/;function addMapping(t,e){var i=t.replace(vendorProductRE,(function(t,e,i){return"000".substr(e.length-1)+e+"-"+"000".substr(i.length-1)+i+"-"})),n=t.replace(vendorProductRE,(function(t,e,i){return e.replace(leadingZeroRE,"")+"-"+i.replace(leadingZeroRE,"")+"-"}));e.analog=e.analog||e.buttons.map((function(){return-1})),e.normalize_fn=e.normalize_fn||defaultNormalizeFn,remap.set(i,e),remap.set(n,e)}var bindings={},remap=new Map,updateEventHandler;[["45e-28e-Xbox 360 Wired Controller",{axes:[0,1,3,4],buttons:[11,12,13,14,8,9,-1,-1,5,4,6,7,0,1,2,3,10],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:wiredXbox360NormalizeFn}],["54c-268-PLAYSTATION(R)3 Controller",{axes:[0,1,2,3],buttons:[14,13,15,12,10,11,8,9,0,3,1,2,4,6,7,5,16]}],["54c-5c4-Wireless Controller",{axes:[0,1,2,3],buttons:[1,0,2,3,4,5,6,7,8,9,10,11,14,15,16,17,12,13]}],["2836-1-OUYA Game Controller",{axes:[0,3,7,9],buttons:[3,6,4,5,7,8,15,16,-1,-1,9,10,11,12,13,14,-1],analog:[-1,-1,-1,-1,-1,-1,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}],["OUYA Game Controller (Vendor: 2836 Product: 0001)",{axes:[0,1,3,4],buttons:[0,3,1,2,4,5,12,13,-1,-1,6,7,8,9,10,11,-1],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}]].forEach((function(t){addMapping(t[0],t[1])}));var updateGamepads=function(){var t=navigator.getGamepads();Object.keys(bindings).forEach((function(e){var i=t[e];if(i){var n=null;"standard"!==i.mapping&&(n=remap.get(i.id));var r=bindings[e];Object.keys(r.buttons).forEach((function(t){var o=r.buttons[t],s=t,a=-1;if(!(n&&(s=n.buttons[t],a=n.analog[t],s<0&&a<0))){var h=i.buttons[s]||{};if(n&&a>=0){var l=n.normalize_fn(i.axes[a],-1,+t);h={value:l,pressed:h.pressed||Math.abs(l)>=deadzone}}event.publish(event.GAMEPAD_UPDATE,[e,"buttons",+t,h]),!o.pressed&&h.pressed?triggerKeyEvent(o.keyCode,!0,s+256):o.pressed&&!h.pressed&&triggerKeyEvent(o.keyCode,!1,s+256),o.value=h.value,o.pressed=h.pressed}})),Object.keys(r.axes).forEach((function(t){var o=r.axes[t],s=t;if(!(n&&(s=n.axes[t])<0)){var a=i.axes[s];if(void 0!==a){n&&(a=n.normalize_fn(a,+t,-1));var h=Math.sign(a)||1;if(0!==o[h].keyCode){var l=Math.abs(a)>=deadzone+Math.abs(o[h].threshold);event.publish(event.GAMEPAD_UPDATE,[e,"axes",+t,a]),!o[h].pressed&&l?(o[-h].pressed&&(triggerKeyEvent(o[-h].keyCode,!1,s+256),o[-h].value=0,o[-h].pressed=!1),triggerKeyEvent(o[h].keyCode,!0,s+256)):!o[h].pressed&&!o[-h].pressed||l||triggerKeyEvent(o[h=o[h].pressed?h:-h].keyCode,!1,s+256),o[h].value=a,o[h].pressed=l}}}}))}}))};window.addEventListener("gamepadconnected",(function(t){event.publish(event.GAMEPAD_CONNECTED,[t.gamepad])}),!1),window.addEventListener("gamepaddisconnected",(function(t){event.publish(event.GAMEPAD_DISCONNECTED,[t.gamepad])}),!1);var GAMEPAD={AXES:{LX:0,LY:1,RX:2,RY:3,EXTRA_1:4,EXTRA_2:5,EXTRA_3:6,EXTRA_4:7},BUTTONS:{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L1:4,R1:5,L2:6,R2:7,SELECT:8,BACK:8,START:9,FORWARD:9,L3:10,R3:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,HOME:16,EXTRA_1:17,EXTRA_2:18,EXTRA_3:19,EXTRA_4:20}};function bindGamepad(t,e,i){if(!getBindingKey(i))throw new Error("no action defined for keycode "+i);void 0===updateEventHandler&&"function"==typeof navigator.getGamepads&&(updateEventHandler=event.subscribe(event.GAME_UPDATE,updateGamepads)),bindings[t]||(bindings[t]={axes:{},buttons:{}});var n={keyCode:i,value:0,pressed:!1,threshold:e.threshold},r=bindings[t][e.type];if("buttons"===e.type)r[e.code]=n;else if("axes"===e.type){var o=Math.sign(e.threshold)||1;r[e.code]||(r[e.code]={});var s=r[e.code];s[o]=n,s[-o]||(s[-o]={keyCode:0,value:0,pressed:!1,threshold:-o})}}function unbindGamepad(t,e){if(!bindings[t])throw new Error("no bindings for gamepad "+t);bindings[t].buttons[e]={}}function setGamepadDeadzone(t){deadzone=t}var setGamepadMapping=addMapping,preventDefault=!0,input=Object.freeze({__proto__:null,preventDefault:preventDefault,get pointerEventTarget(){return pointerEventTarget},get pointer(){return pointer},get throttlingInterval(){return throttlingInterval},globalToLocal:globalToLocal,setTouchAction:setTouchAction,bindPointer:bindPointer,unbindPointer:unbindPointer,registerPointerEvent:registerPointerEvent,releasePointerEvent:releasePointerEvent,releaseAllPointerEvents:releaseAllPointerEvents,get keyBoardEventTarget(){return keyBoardEventTarget},KEY:KEY,initKeyboardEvent:initKeyboardEvent,isKeyPressed:isKeyPressed,keyStatus:keyStatus,triggerKeyEvent:triggerKeyEvent,bindKey:bindKey,getBindingKey:getBindingKey,unlockKey:unlockKey,unbindKey:unbindKey,GAMEPAD:GAMEPAD,bindGamepad:bindGamepad,unbindGamepad:unbindGamepad,setGamepadDeadzone:setGamepadDeadzone,setGamepadMapping:setGamepadMapping}),Renderable=Rect.extend({init:function(t,e,i,n){this._super(Rect,"init",[t,e,i,n]),this.isRenderable=!0,this.isKinematic=!0,this.body=void 0,void 0===this.currentTransform&&(this.currentTransform=pool.pull("Matrix2d")),this.currentTransform.identity(),this.GUID=void 0,this.onVisibilityChange=void 0,this.alwaysUpdate=!1,this.updateWhenPaused=!1,this.isPersistent=!1,this.floating=!1,this.anchorPoint instanceof ObservableVector2d?this.anchorPoint.setMuted(.5,.5).setCallback(this.onAnchorUpdate,this):this.anchorPoint=pool.pull("ObservableVector2d",.5,.5,{onUpdate:this.onAnchorUpdate,scope:this}),this.autoTransform=!0,this.alpha=1,this.ancestor=void 0,this.mask=void 0,this.tint=pool.pull("Color",255,255,255,1),this.name="",this.pos instanceof ObservableVector3d?this.pos.setMuted(t,e,0).setCallback(this.updateBoundsPos,this):this.pos=pool.pull("ObservableVector3d",t,e,0,{onUpdate:this.updateBoundsPos,scope:this}),this.isDirty=!1,this._flip={x:!1,y:!1},this._inViewport=!1,this.setOpacity(1)},onResetEvent:function(){this.init.apply(this,arguments)},getBounds:function(){return void 0===this._bounds&&(this._super(Rect,"getBounds"),this.isFinite()?this._bounds.setMinMax(this.pos.x,this.pos.y,this.pos.x+this.width,this.pos.y+this.height):this._bounds.setMinMax(this.pos.x,this.pos.y,this.width,this.height)),this._bounds},getOpacity:function(){return this.alpha},setOpacity:function(t){"number"==typeof t&&(this.alpha=clamp(t,0,1),isNaN(this.alpha)&&(this.alpha=1))},flipX:function(t){return this._flip.x=!!t,this.isDirty=!0,this},flipY:function(t){return this._flip.y=!!t,this.isDirty=!0,this},transform:function(t){return this.currentTransform.multiply(t),this.updateBoundsPos(this.pos.x,this.pos.y),this.isDirty=!0,this},angleTo:function(t){var e,i,n=this.getBounds();if(t instanceof Renderable){var r=t.getBounds();e=r.centerX-n.centerX,i=r.centerY-n.centerY}else e=t.x-n.centerX,i=t.y-n.centerY;return Math.atan2(i,e)},distanceTo:function(t){var e,i,n=this.getBounds();if(t instanceof Renderable){var r=t.getBounds();e=n.centerX-r.centerX,i=n.centerY-r.centerY}else e=n.centerX-t.x,i=n.centerY-t.y;return Math.sqrt(e*e+i*i)},lookAt:function(t){var e;e=t instanceof Renderable?t.pos:t;var i=this.angleTo(e);return this.rotate(i),this},rotate:function(t){return isNaN(t)||(this.currentTransform.rotate(t),this.isDirty=!0),this},scale:function(t,e){return this.currentTransform.scale(t,e),this._super(Rect,"scale",[t,e]),this.isDirty=!0,this},scaleV:function(t){return this.scale(t.x,t.y),this},update:function(){return this.isDirty},updateBounds:function(){return this._super(Rect,"updateBounds"),this.updateBoundsPos(this.pos.x,this.pos.y),this.getBounds()},updateBoundsPos:function(t,e){var i=this.getBounds();i.shift(t,e),void 0!==this.anchorPoint&&i.isFinite()&&i.translate(-this.anchorPoint.x*i.width,-this.anchorPoint.y*i.height),this.ancestor instanceof Container$1&&!0!==this.floating&&i.translate(this.ancestor.getAbsolutePosition())},getAbsolutePosition:function(){return void 0===this._absPos&&(this._absPos=pool.pull("Vector2d")),this._absPos.set(this.pos.x,this.pos.y),this.ancestor instanceof Container$1&&!0!==this.floating&&this._absPos.add(this.ancestor.getAbsolutePosition()),this._absPos},onAnchorUpdate:function(t,e){this.anchorPoint.setMuted(t,e),this.updateBoundsPos(this.pos.x,this.pos.y)},preDraw:function(t){var e=this.getBounds(),i=e.width*this.anchorPoint.x,n=e.height*this.anchorPoint.y;if(t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),this._flip.x||this._flip.y){var r=this._flip.x?this.centerX-i:0,o=this._flip.y?this.centerY-n:0;t.translate(r,o),t.scale(this._flip.x?-1:1,this._flip.y?-1:1),t.translate(-r,-o)}!0!==this.autoTransform||this.currentTransform.isIdentity()||(t.translate(this.pos.x,this.pos.y),t.transform(this.currentTransform),t.translate(-this.pos.x,-this.pos.y)),t.translate(-i,-n),void 0!==this.mask&&t.setMask(this.mask),t.setTint(this.tint)},draw:function(){},postDraw:function(t){void 0!==this.mask&&t.clearMask(),t.clearTint(),this.isDirty=!1,t.restore()},destroy:function(){pool.push(this.currentTransform),this.currentTransform=void 0,pool.push(this.anchorPoint),this.anchorPoint=void 0,pool.push(this.pos),this.pos=void 0,void 0!==this._absPos&&(pool.push(this._absPos),this._absPos=void 0),pool.push(this._bounds),this._bounds=void 0,this.onVisibilityChange=void 0,void 0!==this.mask&&(pool.push(this.mask),this.mask=void 0),void 0!==this.tint&&(pool.push(this.tint),this.tint=void 0),this.ancestor=void 0,void 0!==this.body&&(this.body.destroy.apply(this.body,arguments),this.body=void 0),releaseAllPointerEvents(this),this.onDestroyEvent.apply(this,arguments)},onDestroyEvent:function(){}});Object.defineProperty(Renderable.prototype,"inViewport",{get:function(){return this._inViewport},set:function(t){this._inViewport!==t&&(this._inViewport=t,"function"==typeof this.onVisibilityChange&&this.onVisibilityChange.call(this,t))},configurable:!0}),Object.defineProperty(Renderable.prototype,"isFlippedX",{get:function(){return!0===this._flip.x},configurable:!0}),Object.defineProperty(Renderable.prototype,"isFlippedY",{get:function(){return!0===this._flip.y},configurable:!0});var deferredRemove=function(t,e){this.removeChildNow(t,e)},globalFloatingCounter=0,Container=Renderable.extend({init:function(t,e,i,n,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=game$1.viewport.width),void 0===n&&(n=game$1.viewport.height),void 0===r&&(r=!1),this.pendingSort=null,this._super(Renderable,"init",[t,e,i,n]),this.root=r,this.children=void 0,this.sortOn=game$1.sortOn,this.autoSort=!0,this.autoDepth=!0,this.clipping=!1,this.onChildChange=function(){},this.enableChildBoundsUpdate=!1,this.drawCount=0,this.autoTransform=!0,this.isKinematic=!1,this.anchorPoint.set(0,0),!0===this.root&&event.subscribe(event.CANVAS_ONRESIZE,this.updateBounds.bind(this,!0))},reset:function(){this.pendingSort&&(clearTimeout(this.pendingSort),this.pendingSort=null);for(var t,e=this.getChildren(),i=e.length;i>=0;t=e[--i])t&&!0!==t.isPersistent&&this.removeChildNow(t);void 0!==this.currentTransform&&this.currentTransform.identity()},addChild:function(t,e){return t.ancestor instanceof Container?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils$1.createGUID(t.id)),t.ancestor=this,this.getChildren().push(t),void 0!==t.pos&&("number"==typeof e?t.pos.z=e:!0===this.autoDepth&&(t.pos.z=this.getChildren().length)),!0===this.autoSort&&this.sort(),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,this.getChildren().length-1),t},addChildAt:function(t,e){if(e>=0&&e<this.getChildren().length)return t.ancestor instanceof Container?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils$1.createGUID()),t.ancestor=this,this.getChildren().splice(e,0,t),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,e),t;throw new Error("Index ("+e+") Out Of Bounds for addChildAt()")},forEach:function(t,e){var i=this,n=0,r=this.getChildren(),o=r.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);n<o;)t.call(i,r[n],n,r),n++},swapChildren:function(t,e){var i=this.getChildIndex(t),n=this.getChildIndex(e);if(-1===i||-1===n)throw new Error(t+" Both the supplied childs must be a child of the caller "+this);var r=t.pos.z;t.pos.z=e.pos.z,e.pos.z=r,this.getChildren()[i]=e,this.getChildren()[n]=t},getChildAt:function(t){if(t>=0&&t<this.getChildren().length)return this.getChildren()[t];throw new Error("Index ("+t+") Out Of Bounds for getChildAt()")},getChildIndex:function(t){return this.getChildren().indexOf(t)},getNextChild:function(t){var e=this.getChildren().indexOf(t)-1;if(e>=0&&e<this.getChildren().length)return this.getChildAt(e)},hasChild:function(t){return this===t.ancestor},getChildByProp:function(t,e){var i=[];return this.forEach((function(n){!function(t,n){var r=t[n];e instanceof RegExp&&"string"==typeof r?e.test(r)&&i.push(t):r===e&&i.push(t)}(n,t),n instanceof Container&&(i=i.concat(n.getChildByProp(t,e)))})),i},getChildByType:function(t){var e=[];return this.forEach((function(i){i instanceof t&&e.push(i),i instanceof Container&&(e=e.concat(i.getChildByType(t)))})),e},getChildByName:function(t){return this.getChildByProp("name",t)},getChildByGUID:function(t){var e=this.getChildByProp("GUID",t);return e.length>0?e[0]:null},getChildren:function(){return void 0===this.children&&(this.children=[]),this.children},updateBounds:function(t){void 0===t&&(t=!1),this._super(Renderable,"updateBounds");var e=this.getBounds();return!0!==t&&!0!==this.enableChildBoundsUpdate||this.forEach((function(t){t.isRenderable&&(t.getBounds().isFinite()&&e.addBounds(t.getBounds()))})),e},isAttachedToRoot:function(){if(!0===this.root)return!0;for(var t=this.ancestor;t;){if(!0===t.root)return!0;t=t.ancestor}return!1},updateBoundsPos:function(t,e){var i=this;return this._super(Renderable,"updateBoundsPos",[t,e]),this.forEach((function(n){n.isRenderable&&n.updateBoundsPos(n.pos.x+t-i.pos.x,n.pos.y+e-i.pos.y)})),this.getBounds()},onActivateEvent:function(){this.forEach((function(t){"function"==typeof t.onActivateEvent&&t.onActivateEvent()}))},removeChild:function(t,e){if(!this.hasChild(t))throw new Error("Child is not mine.");utils$1.function.defer(deferredRemove,this,t,e)},removeChildNow:function(t,e){if(this.hasChild(t)&&this.getChildIndex(t)>=0){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent(),e||("function"==typeof t.destroy&&t.destroy(),pool.push(t));var i=this.getChildIndex(t);i>=0&&(this.getChildren().splice(i,1),t.ancestor=void 0),!0===this.isAttachedToRoot()&&game$1.repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,i)}},setChildsProperty:function(t,e,i){this.forEach((function(n){!0===i&&n instanceof Container&&n.setChildsProperty(t,e,i),n[t]=e}))},moveUp:function(t){var e=this.getChildIndex(t);e-1>=0&&this.swapChildren(t,this.getChildAt(e-1))},moveDown:function(t){var e=this.getChildIndex(t);e>=0&&e+1<this.getChildren().length&&this.swapChildren(t,this.getChildAt(e+1))},moveToTop:function(t){var e=this.getChildIndex(t);if(e>0){var i=this.getChildren();i.splice(0,0,i.splice(e,1)[0]),t.pos.z=i[1].pos.z+1}},moveToBottom:function(t){var e=this.getChildIndex(t),i=this.getChildren();e>=0&&e<i.length-1&&(i.splice(i.length-1,0,i.splice(e,1)[0]),t.pos.z=i[i.length-2].pos.z-1)},sort:function(t){this.pendingSort||(!0===t&&this.forEach((function(e){e instanceof Container&&e.sort(t)})),this.pendingSort=utils$1.function.defer((function(t){t.getChildren().sort(t["_sort"+t.sortOn.toUpperCase()]),t.pendingSort=null,game$1.repaint()}),this,this))},onDeactivateEvent:function(){this.forEach((function(t){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent()}))},_sortZ:function(t,e){return e.pos&&t.pos?e.pos.z-t.pos.z:t.pos?-1/0:1/0},_sortReverseZ:function(t,e){return t.pos&&e.pos?t.pos.z-e.pos.z:t.pos?1/0:-1/0},_sortX:function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.x-t.pos.x},_sortY:function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.y-t.pos.y},destroy:function(){this.reset(),this._super(Renderable,"destroy",arguments)},update:function(t){this._super(Renderable,"update",[t]);for(var e,i=!1,n=!1,r=state$1.isPaused(),o=this.getChildren(),s=o.length;s--,e=o[s];)r&&!e.updateWhenPaused||(e.isRenderable?((n=globalFloatingCounter>0||e.floating)&&globalFloatingCounter++,e.inViewport=!1,state$1.current().cameras.forEach((function(t){t.isVisible(e,n)&&(e.inViewport=!0)})),i=(e.inViewport||e.alwaysUpdate)&&e.update(t)||i,globalFloatingCounter>0&&globalFloatingCounter--):i=e.update(t)||i);return i},draw:function(t,e){var i=!1,n=this.getBounds();this.drawCount=0,!1===this.root&&!0===this.clipping&&!0===n.isFinite()&&t.clipRect(n.left,n.top,n.width,n.height),t.translate(this.pos.x,this.pos.y);for(var r,o=this.getChildren(),s=o.length;r=o[--s];)r.isRenderable&&(i=!0===r.floating,(r.inViewport||i)&&(i&&(t.save(),t.resetTransform()),r.preDraw(t),r.draw(t,e),r.postDraw(t),i&&t.restore(),this.drawCount++))}}),Container$1=Container,QT_ARRAY=[];function QT_ARRAY_POP(t,e,i,n){if(QT_ARRAY.length>0){var r=QT_ARRAY.pop();return r.bounds=t,r.max_objects=e||4,r.max_levels=i||4,r.level=n||0,r}return new QuadTree(t,e,i,n)}function QT_ARRAY_PUSH(t){QT_ARRAY.push(t)}var QT_VECTOR=new Vector2d,QuadTree=function(t,e,i,n){this.max_objects=e||4,this.max_levels=i||4,this.level=n||0,this.bounds=t,this.objects=[],this.nodes=[]};QuadTree.prototype.split=function(){var t=this.level+1,e=this.bounds.width/2,i=this.bounds.height/2,n=this.bounds.left,r=this.bounds.top;this.nodes[0]=QT_ARRAY_POP({left:n+e,top:r,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[1]=QT_ARRAY_POP({left:n,top:r,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[2]=QT_ARRAY_POP({left:n,top:r+i,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[3]=QT_ARRAY_POP({left:n+e,top:r+i,width:e,height:i},this.max_objects,this.max_levels,t)},QuadTree.prototype.getIndex=function(t){var e,i=-1,n=(e=t.floating||t.ancestor&&t.ancestor.floating?game$1.viewport.localToWorld(t.left,t.top,QT_VECTOR):QT_VECTOR.set(t.left,t.top)).x,r=e.y,o=t.width,s=t.height,a=this.bounds.left+this.bounds.width/2,h=this.bounds.top+this.bounds.height/2,l=r<h&&r+s<h,u=r>h;return n<a&&n+o<a?l?i=1:u&&(i=2):n>a&&(l?i=0:u&&(i=3)),i},QuadTree.prototype.insertContainer=function(t){for(var e,i=t.children.length;i--,e=t.children[i];)!0!==e.isKinematic&&(e instanceof Container$1?("rootContainer"!==e.name&&this.insert(e),this.insertContainer(e)):"function"==typeof e.getBounds&&this.insert(e))},QuadTree.prototype.insert=function(t){var e=-1;if(this.nodes.length>0&&-1!==(e=this.getIndex(t)))this.nodes[e].insert(t);else if(this.objects.push(t),this.objects.length>this.max_objects&&this.level<this.max_levels){0===this.nodes.length&&this.split();for(var i=0;i<this.objects.length;)-1!==(e=this.getIndex(this.objects[i]))?this.nodes[e].insert(this.objects.splice(i,1)[0]):i+=1}},QuadTree.prototype.retrieve=function(t,e){var i=this.objects;if(this.nodes.length>0){var n=this.getIndex(t);if(-1!==n)i=i.concat(this.nodes[n].retrieve(t));else for(var r=0;r<this.nodes.length;r+=1)i=i.concat(this.nodes[r].retrieve(t))}return"function"==typeof e&&i.sort(e),i},QuadTree.prototype.remove=function(t){var e=!1;if(void 0===t.getBounds)return!1;if(this.nodes.length>0){var i=this.getIndex(t);-1!==i&&(e=utils$1.array.remove(this.nodes[i],t))&&this.nodes[i].isPrunable()&&this.nodes.splice(i,1)}return!1===e&&-1!==this.objects.indexOf(t)&&(utils$1.array.remove(this.objects,t),e=!0),e},QuadTree.prototype.isPrunable=function(){return!(this.hasChildren()||this.objects.length>0)},QuadTree.prototype.hasChildren=function(){for(var t=0;t<this.nodes.length;t+=1){var e=this.nodes[t];if(e.length>0||e.objects.length>0)return!0}return!1},QuadTree.prototype.clear=function(t){this.objects.length=0;for(var e=0;e<this.nodes.length;e++)this.nodes[e].clear(),QT_ARRAY_PUSH(this.nodes[e]);this.nodes.length=0,void 0!==t&&this.bounds.setMinMax(t.min.x,t.min.y,t.max.x,t.max.y)};for(var LEFT_VORNOI_REGION=-1,MIDDLE_VORNOI_REGION=0,RIGHT_VORNOI_REGION=1,T_VECTORS=[],v=0;v<10;v++)T_VECTORS.push(new Vector2d);for(var T_ARRAYS=[],a=0;a<5;a++)T_ARRAYS.push([]);function flattenPointsOn(t,e,i){for(var n=Number.MAX_VALUE,r=-Number.MAX_VALUE,o=t.length,s=0;s<o;s++){var a=t[s].dotProduct(e);a<n&&(n=a),a>r&&(r=a)}i[0]=n,i[1]=r}function isSeparatingAxis(t,e,i,n,r,o){var s=T_ARRAYS.pop(),a=T_ARRAYS.pop(),h=T_VECTORS.pop().copy(e).sub(t),l=h.dotProduct(r);if(flattenPointsOn(i,r,s),flattenPointsOn(n,r,a),a[0]+=l,a[1]+=l,s[0]>a[1]||a[0]>s[1])return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!0;if(o){var u=0;if(s[0]<a[0])if(o.aInB=!1,s[1]<a[1])u=s[1]-a[0],o.bInA=!1;else{var c=s[1]-a[0],d=a[1]-s[0];u=c<d?c:-d}else if(o.bInA=!1,s[1]>a[1])u=s[0]-a[1],o.aInB=!1;else{var p=s[1]-a[0],f=a[1]-s[0];u=p<f?p:-f}var g=Math.abs(u);g<o.overlap&&(o.overlap=g,o.overlapN.copy(r),u<0&&o.overlapN.negateSelf())}return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!1}function vornoiRegion(t,e){var i=t.length2(),n=e.dotProduct(t);return n<0?LEFT_VORNOI_REGION:n>i?RIGHT_VORNOI_REGION:MIDDLE_VORNOI_REGION}function testPolygonPolygon(t,e,i,n,r){var o,s=e.points,a=e.normals,h=a.length,l=n.points,u=n.normals,c=u.length,d=T_VECTORS.pop().copy(t.pos).add(t.ancestor.getAbsolutePosition()).add(e.pos),p=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos);for(o=0;o<h;o++)if(isSeparatingAxis(d,p,s,l,a[o],r))return T_VECTORS.push(d),T_VECTORS.push(p),!1;for(o=0;o<c;o++)if(isSeparatingAxis(d,p,s,l,u[o],r))return T_VECTORS.push(d),T_VECTORS.push(p),!1;return r&&(r.a=t,r.b=i,r.overlapV.copy(r.overlapN).scale(r.overlap)),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipseEllipse(t,e,i,n,r){var o=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=e.radius,a=n.radius,h=s+a,l=h*h,u=o.length2();if(u>l)return T_VECTORS.push(o),!1;if(r){var c=Math.sqrt(u);r.a=t,r.b=i,r.overlap=h-c,r.overlapN.copy(o.normalize()),r.overlapV.copy(o).scale(r.overlap),r.aInB=s<=a&&c<=a-s,r.bInA=a<=s&&c<=s-a}return T_VECTORS.push(o),!0}function testPolygonEllipse(t,e,i,n,r){for(var o=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(n.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=n.radius,a=s*s,h=e.points,l=e.edges,u=l.length,c=T_VECTORS.pop(),d=T_VECTORS.pop(),p=T_VECTORS.pop(),f=0,g=0;g<u;g++){var m=g===u-1?0:g+1,y=0===g?u-1:g-1,v=0,_=null;c.copy(l[g]),p.copy(o).sub(h[g]),r&&p.length2()>a&&(r.aInB=!1);var x=vornoiRegion(c,p),w=!0;if(x===LEFT_VORNOI_REGION){var b=null;if(u>1&&(c.copy(l[y]),(x=vornoiRegion(c,b=T_VECTORS.pop().copy(o).sub(h[y])))!==RIGHT_VORNOI_REGION&&(w=!1)),w){if((f=p.length())>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),b&&T_VECTORS.push(b),!1;r&&(r.bInA=!1,_=p.normalize(),v=s-f)}b&&T_VECTORS.push(b)}else if(x===RIGHT_VORNOI_REGION){if(u>1&&(c.copy(l[m]),p.copy(o).sub(h[m]),(x=vornoiRegion(c,p))!==LEFT_VORNOI_REGION&&(w=!1)),w){if((f=p.length())>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!1;r&&(r.bInA=!1,_=p.normalize(),v=s-f)}}else{d.copy(e.normals[g]),f=p.dotProduct(d);var T=Math.abs(f);if((1===u||f>0)&&T>s)return T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!1;r&&(_=d,v=s-f,(f>=0||v<2*s)&&(r.bInA=!1))}_&&r&&Math.abs(v)<Math.abs(r.overlap)&&(r.overlap=v,r.overlapN.copy(_))}return r&&(r.a=t,r.b=i,r.overlapV.copy(r.overlapN).scale(r.overlap)),T_VECTORS.push(o),T_VECTORS.push(c),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipsePolygon(t,e,i,n,r){var o=this.testPolygonEllipse(i,n,t,e,r);if(o&&r){var s=r.a,a=r.aInB;r.overlapN.negateSelf(),r.overlapV.negateSelf(),r.a=r.b,r.b=s,r.aInB=r.bInA,r.bInA=a}return o}var SAT=Object.freeze({__proto__:null,testPolygonPolygon:testPolygonPolygon,testEllipseEllipse:testEllipseEllipse,testPolygonEllipse:testPolygonEllipse,testEllipsePolygon:testEllipsePolygon}),dummyObj={pos:new Vector2d(0,0),ancestor:{_absPos:new Vector2d(0,0),getAbsolutePosition:function(){return this._absPos}}},ResponseObject=function(){return this.a=null,this.b=null,this.overlapN=new Vector2d,this.overlapV=new Vector2d,this.aInB=!0,this.bInA=!0,this.indexShapeA=-1,this.indexShapeB=-1,this.overlap=Number.MAX_VALUE,this};ResponseObject.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this.indexShapeA=-1,this.indexShapeB=-1,this};var collision={maxChildren:8,maxDepth:4,types:{NO_OBJECT:0,PLAYER_OBJECT:1,NPC_OBJECT:2,ENEMY_OBJECT:4,COLLECTABLE_OBJECT:8,ACTION_OBJECT:16,PROJECTILE_OBJECT:32,WORLD_SHAPE:64,USER:128,ALL_OBJECT:4294967295},response:new ResponseObject,shouldCollide:function(t,e){return!0!==t.isKinematic&&!0!==e.isKinematic&&t.body&&e.body&&0!=(t.body.collisionMask&e.body.collisionType)&&0!=(t.body.collisionType&e.body.collisionMask)},check:function(t,e){for(var i,n=0,r=e||this.response,o=game$1.world.broadphase.retrieve(t),s=o.length;i=o[--s];)if(i!==t&&this.shouldCollide(t,i)&&t.body.getBounds().overlaps(i.body.getBounds())){var a=t.body.shapes.length,h=i.body.shapes.length;if(0===a||0===h)continue;var l=0;do{var u=t.body.getShape(l),c=0;do{var d=i.body.getShape(c);!0===SAT["test"+u.shapeType+d.shapeType].call(this,t,u,i,d,r.clear())&&(n++,r.indexShapeA=l,r.indexShapeB=c,t.onCollision&&!1!==t.onCollision(r,i)&&t.body.respondToCollision.call(t.body,r),i.onCollision&&!1!==i.onCollision(r,t)&&i.body.respondToCollision.call(i.body,r)),c++}while(c<h);l++}while(l<a)}return n>0},rayCast:function(t,e){for(var i,n=0,r=e||[],o=game$1.world.broadphase.retrieve(t),s=o.length;i=o[--s];)if(i.body&&t.getBounds().overlaps(i.getBounds())){var a=i.body.shapes.length;if(0===i.body.shapes.length)continue;var h=t,l=0;do{var u=i.body.getShape(l);SAT["test"+h.shapeType+u.shapeType].call(this,dummyObj,h,i,u)&&(r[n]=i,n++),l++}while(l<a)}return r.length=n,r}},World=Container$1.extend({init:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=1/0),void 0===n&&(n=1/0),this._super(Container$1,"init",[t,e,i,n,!0]),this.name="rootContainer",this.anchorPoint.set(0,0),this.fps=60,this.gravity=new Vector2d(0,.98),this.preRender=!1,this.broadphase=new QuadTree(this.getBounds().clone(),collision.maxChildren,collision.maxDepth),event.subscribe(event.GAME_RESET,this.reset.bind(this)),event.subscribe(event.LEVEL_LOADED,(function(){game$1.world.broadphase.clear(game$1.world.getBounds())}))},reset:function(){this.broadphase.clear(),this.anchorPoint.set(0,0),this._super(Container$1,"reset")},update:function(t){return this.broadphase.clear(),this.broadphase.insertContainer(this),this._super(Container$1,"update",[t])}}),isDirty=!0,isAlwaysDirty=!1,frameCounter=0,frameRate=1,accumulator=0,accumulatorMax=0,accumulatorUpdateDelta=0,stepSize=1e3/60,updateDelta=0,lastUpdateStart=null,updateAverageDelta=0,game={viewport:void 0,world:null,mergeGroup:!0,sortOn:"z",onLevelLoaded:function(){},init:function(){this.world=new World,event.publish(event.GAME_INIT),isDirty=!0},reset:function(){void 0!==state$1.current()&&(this.viewport=state$1.current().cameras.get("default")),event.publish(event.GAME_RESET),this.updateFrameRate()},updateFrameRate:function(){frameCounter=0,frameRate=~~(.5+60/timer$1.maxfps),stepSize=1e3/this.world.fps,accumulator=0,accumulatorMax=10*stepSize,isAlwaysDirty=timer$1.maxfps>this.world.fps},getParentContainer:function(t){return t.ancestor},repaint:function(){isDirty=!0},update:function(t,e){if(++frameCounter%frameRate==0)for(frameCounter=0,event.publish(event.GAME_UPDATE,[t]),accumulator+=timer$1.getDelta(),accumulator=Math.min(accumulator,accumulatorMax),updateDelta=timer$1.interpolation?timer$1.getDelta():stepSize,accumulatorUpdateDelta=timer$1.interpolation?updateDelta:Math.max(updateDelta,updateAverageDelta);accumulator>=accumulatorUpdateDelta||timer$1.interpolation;)if(lastUpdateStart=window.performance.now(),isDirty=e.update(updateDelta)||isDirty,timer$1.lastUpdate=window.performance.now(),updateAverageDelta=timer$1.lastUpdate-lastUpdateStart,accumulator-=accumulatorUpdateDelta,timer$1.interpolation){accumulator=0;break}},draw:function(t){var e=video$1.renderer;!0===e.isContextValid&&(isDirty||isAlwaysDirty)&&(e.clear(),t.draw(e),isDirty=!1,e.flush())}},game$1=game,MIN=Math.min,MAX=Math.max,targetV=new Vector2d,Camera2d=Renderable.extend({init:function(t,e,i,n){this._super(Renderable,"init",[t,e,i-t,n-e]),this.AXIS={NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},this.bounds=pool.pull("Bounds"),this.smoothFollow=!0,this.damping=1,this.near=-1e3,this.far=1e3,this.projectionMatrix=new Matrix3d,this.invCurrentTransform=new Matrix2d,this.offset=new Vector2d,this.target=null,this.follow_axis=this.AXIS.NONE,this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null},this._fadeOut={color:null,tween:null},this._fadeIn={color:null,tween:null},this.name="default",this.setDeadzone(this.width/6,this.height/6),this.anchorPoint.set(0,0),this.isKinematic=!1,this.bounds.setMinMax(t,e,i,n),this._updateProjectionMatrix(),event.subscribe(event.GAME_RESET,this.reset.bind(this)),event.subscribe(event.CANVAS_ONRESIZE,this.resize.bind(this))},_updateProjectionMatrix:function(){this.projectionMatrix.ortho(0,this.width,this.height,0,this.near,this.far)},_followH:function(t){var e=this.pos.x;return t.x-this.pos.x>this.deadzone.right?e=MIN(t.x-this.deadzone.right,this.bounds.width-this.width):t.x-this.pos.x<this.deadzone.pos.x&&(e=MAX(t.x-this.deadzone.pos.x,this.bounds.left)),e},_followV:function(t){var e=this.pos.y;return t.y-this.pos.y>this.deadzone.bottom?e=MIN(t.y-this.deadzone.bottom,this.bounds.height-this.height):t.y-this.pos.y<this.deadzone.pos.y&&(e=MAX(t.y-this.deadzone.pos.y,this.bounds.top)),e},reset:function(t,e){this.pos.x=t||0,this.pos.y=e||0,this.unfollow(),this.smoothFollow=!0,this.damping=1,this.currentTransform.identity(),this.invCurrentTransform.identity().invert(),this._updateProjectionMatrix()},setDeadzone:function(t,e){void 0===this.deadzone&&(this.deadzone=new Rect(0,0,0,0)),this.deadzone.pos.set(~~((this.width-t)/2),~~((this.height-e)/2-.25*e)),this.deadzone.resize(t,e),this.smoothFollow=!1,this.updateTarget(),this.smoothFollow=!0},resize:function(t,e){return this._super(Renderable,"resize",[t,e]),this.smoothFollow=!1,this.setBounds(0,0,t,e),this.setDeadzone(t/6,e/6),this.update(),this.smoothFollow=!0,this._updateProjectionMatrix(),event.publish(event.VIEWPORT_ONRESIZE,[this.width,this.height]),this},setBounds:function(t,e,i,n){this.smoothFollow=!1,this.bounds.setMinMax(t,e,i+t,n+e),this.moveTo(this.pos.x,this.pos.y),this.update(),this.smoothFollow=!0},follow:function(t,e,i){if(t instanceof Renderable)this.target=t.pos;else{if(!(t instanceof Vector2d||t instanceof Vector3d||t instanceof ObservableVector2d||t instanceof ObservableVector3d))throw new Error("invalid target for me.Camera2d.follow");this.target=t}this.follow_axis=void 0===e?this.AXIS.BOTH:e,this.smoothFollow=!1,this.damping="number"!=typeof i?1:clamp(i,0,1),this.updateTarget(),this.smoothFollow=!0},unfollow:function(){this.target=null,this.follow_axis=this.AXIS.NONE},move:function(t,e){this.moveTo(this.pos.x+t,this.pos.y+e)},moveTo:function(t,e){var i=this.pos.x,n=this.pos.y;this.pos.x=clamp(t,this.bounds.left,this.bounds.width),this.pos.y=clamp(e,this.bounds.top,this.bounds.height),i===this.pos.x&&n===this.pos.y||event.publish(event.VIEWPORT_ONCHANGE,[this.pos])},updateTarget:function(){if(this.target){switch(targetV.setV(this.pos),this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:targetV.x=this._followH(this.target);break;case this.AXIS.VERTICAL:targetV.y=this._followV(this.target);break;case this.AXIS.BOTH:targetV.x=this._followH(this.target),targetV.y=this._followV(this.target)}if(!this.pos.equals(targetV)){if(!0===this.smoothFollow&&this.damping<1){if(toBeCloseTo(targetV.x,this.pos.x,2)&&toBeCloseTo(targetV.y,this.pos.y,2))return this.pos.setV(targetV),!1;this.pos.lerp(targetV,this.damping)}else this.pos.setV(targetV);return!0}}return!1},update:function(t){var e=this.updateTarget(t);return this._shake.duration>0&&(this._shake.duration-=t,this._shake.duration<=0?(this._shake.duration=0,this.offset.setZero(),"function"==typeof this._shake.onComplete&&this._shake.onComplete()):(this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.HORIZONTAL||(this.offset.x=(Math.random()-.5)*this._shake.intensity),this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.VERTICAL||(this.offset.y=(Math.random()-.5)*this._shake.intensity)),e=!0),!0===e&&event.publish(event.VIEWPORT_ONCHANGE,[this.pos]),null==this._fadeIn.tween&&null==this._fadeOut.tween||(e=!0),this.currentTransform.isIdentity()?this.invCurrentTransform.identity():this.invCurrentTransform.copy(this.currentTransform).invert(),e},shake:function(t,e,i,n,r){0!==this._shake.duration&&!0!==r||(this._shake.intensity=t,this._shake.duration=e,this._shake.axis=i||this.AXIS.BOTH,this._shake.onComplete="function"==typeof n?n:void 0)},fadeOut:function(t,e,i){void 0===e&&(e=1e3),this._fadeOut.color=pool.pull("Color").copy(t),this._fadeOut.tween=pool.pull("Tween",this._fadeOut.color).to({alpha:0},e).onComplete(i||null),this._fadeOut.tween.isPersistent=!0,this._fadeOut.tween.start()},fadeIn:function(t,e,i){void 0===e&&(e=1e3),this._fadeIn.color=pool.pull("Color").copy(t);var n=this._fadeIn.color.alpha;this._fadeIn.color.alpha=0,this._fadeIn.tween=pool.pull("Tween",this._fadeIn.color).to({alpha:n},e).onComplete(i||null),this._fadeIn.tween.isPersistent=!0,this._fadeIn.tween.start()},getWidth:function(){return this.width},getHeight:function(){return this.height},focusOn:function(t){var e=t.getBounds();this.moveTo(t.pos.x+e.left+e.width/2,t.pos.y+e.top+e.height/2)},isVisible:function(t,e){return void 0===e&&(e=t.floating),!0===e||!0===t.floating?video$1.renderer.overlaps(t.getBounds()):t.getBounds().overlaps(this)},localToWorld:function(t,e,i){return(i=i||new Vector2d).set(t,e).add(this.pos).sub(game$1.world.pos),this.currentTransform.isIdentity()||this.invCurrentTransform.apply(i),i},worldToLocal:function(t,e,i){return(i=i||new Vector2d).set(t,e),this.currentTransform.isIdentity()||this.currentTransform.apply(i),i.sub(this.pos).add(game$1.world.pos)},drawFX:function(t){this._fadeIn.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeIn.color),t.fillRect(0,0,this.width,this.height),t.restore(),1===this._fadeIn.color.alpha&&(this._fadeIn.tween=null,pool.push(this._fadeIn.color),this._fadeIn.color=null)),this._fadeOut.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeOut.color),t.fillRect(0,0,this.width,this.height),t.restore(),0===this._fadeOut.color.alpha&&(this._fadeOut.tween=null,pool.push(this._fadeOut.color),this._fadeOut.color=null))},draw:function(t,e){var i=this.pos.x+this.offset.x,n=this.pos.y+this.offset.y;e.currentTransform.translate(-i,-n),t.setProjection(this.projectionMatrix),t.clipRect(0,0,this.width,this.height),this.preDraw(t),e.preDraw(t),e.draw(t,this),this.drawFX(t),e.postDraw(t),this.postDraw(t),e.currentTransform.translate(i,n)}}),default_camera,default_settings={cameras:[]},Stage=window.Jay.extend({init:function(t){this.cameras=new Map,this.settings=Object.assign(default_settings,t||{})},reset:function(){var t=this;if(this.settings.cameras.forEach((function(e){t.cameras.set(e.name,e)})),!1===this.cameras.has("default")){if(void 0===default_camera){var e=video$1.renderer.getWidth(),i=video$1.renderer.getHeight();default_camera=new Camera2d(0,0,e,i)}this.cameras.set("default",default_camera)}game$1.reset(),this.onResetEvent.apply(this,arguments)},update:function(t){var e=game$1.world.update(t);return this.cameras.forEach((function(i){i.update(t)&&(e=!0)})),e},draw:function(t){this.cameras.forEach((function(e){e.draw(t,game$1.world)}))},destroy:function(){this.cameras.clear(),this.onDestroyEvent.apply(this,arguments)},onResetEvent:function(){"function"==typeof this.settings.onResetEvent&&this.settings.onResetEvent.apply(this,arguments)},onDestroyEvent:function(){"function"==typeof this.settings.onDestroyEvent&&this.settings.onDestroyEvent.apply(this,arguments)}}),ProgressBar=Renderable.extend({init:function(t,e,i,n){var r=this;this.barHeight=n,this._super(Renderable,"init",[t,e,i,n]),this.anchorPoint.set(0,0),this.loaderHdlr=event.subscribe(event.LOADER_PROGRESS,r.onProgressUpdate.bind(r)),this.resizeHdlr=event.subscribe(event.VIEWPORT_ONRESIZE,r.resize.bind(r)),this.anchorPoint.set(0,0),this.progress=0},onProgressUpdate:function(t){this.progress=~~(t*this.width),this.isDirty=!0},draw:function(t){t.clearColor("#202020"),t.setColor("black"),t.fillRect(this.pos.x,game$1.viewport.centerY,t.getWidth(),this.barHeight/2),t.setColor("#55aa00"),t.fillRect(this.pos.x,game$1.viewport.centerY,this.progress,this.barHeight/2)},onDestroyEvent:function(){event.unsubscribe(this.loaderHdlr),event.unsubscribe(this.resizeHdlr),this.loaderHdlr=this.resizeHdlr=null}}),IconLogo=Renderable.extend({init:function(t,e){this._super(Renderable,"init",[t,e,100,85]),this.iconCanvas=video$1.createCanvas(nextPowerOfTwo(this.width),nextPowerOfTwo(this.height),!1);var i=video$1.renderer.getContext2d(this.iconCanvas);i.beginPath(),i.moveTo(.7,48.9),i.bezierCurveTo(10.8,68.9,38.4,75.8,62.2,64.5),i.bezierCurveTo(86.1,53.1,97.2,27.7,87,7.7),i.lineTo(87,7.7),i.bezierCurveTo(89.9,15.4,73.9,30.2,50.5,41.4),i.bezierCurveTo(27.1,52.5,5.2,55.8,.7,48.9),i.lineTo(.7,48.9),i.closePath(),i.fillStyle="rgb(255, 255, 255)",i.fill(),i.beginPath(),i.moveTo(84,7),i.bezierCurveTo(87.6,14.7,72.5,30.2,50.2,41.6),i.bezierCurveTo(27.9,53,6.9,55.9,3.2,48.2),i.bezierCurveTo(-.5,40.4,14.6,24.9,36.9,13.5),i.bezierCurveTo(59.2,2.2,80.3,-.8,84,7),i.lineTo(84,7),i.closePath(),i.lineWidth=5.3,i.strokeStyle="rgb(255, 255, 255)",i.lineJoin="miter",i.miterLimit=4,i.stroke(),this.anchorPoint.set(.5,.5)},draw:function(t){t.drawImage(this.iconCanvas,t.getWidth()/2,this.pos.y)}}),TextLogo=Renderable.extend({init:function(t,e){this._super(Renderable,"init",[0,0,t,e]),this.textWidth=0,this.fontCanvas=video$1.createCanvas(256,64,!0),this.drawFont(video$1.renderer.getContext2d(this.fontCanvas)),this.anchorPoint.set(0,.5)},drawFont:function(t){var e=pool.pull("Text",0,0,{font:"century gothic",size:32,fillStyle:"white",textAlign:"middle",textBaseline:"top",text:"melon"}),i=pool.pull("Text",0,0,{font:"century gothic",size:32,fillStyle:"#55aa00",textAlign:"middle",textBaseline:"top",bold:!0,text:"JS"}),n=e.measureText(t).width,r=i.measureText(t).width;this.textWidth=n+r,this.pos.x=Math.round(this.width-this.textWidth/2),this.pos.y=Math.round(this.height+16),e._drawFont(t,["melon"],0,0),i._drawFont(t,["JS"],n,0),pool.push(e),pool.push(i)},draw:function(t){t.drawImage(this.fontCanvas,Math.round((t.getWidth()-this.textWidth)/2),this.pos.y)}}),defaultLoadingScreen=new Stage({onResetEvent:function(){game$1.world.addChild(new ProgressBar(0,video$1.renderer.getHeight()/2,video$1.renderer.getWidth(),8),1),game$1.world.addChild(new IconLogo(video$1.renderer.getWidth()/2,video$1.renderer.getHeight()/2-16-35),2),game$1.world.addChild(new TextLogo(video$1.renderer.getWidth(),video$1.renderer.getHeight()),2)}}),_state=-1,_animFrameId=-1,_isPaused=!1,_stages={},_fade={color:"",duration:0},_onSwitchComplete=null,_extraArgs=null,_pauseTime=0;function _startRunLoop(){-1===_animFrameId&&-1!==_state&&(timer$1.reset(),_animFrameId=window.requestAnimationFrame(_renderFrame))}function _resumeRunLoop(){_isPaused&&-1!==_state&&(timer$1.reset(),_isPaused=!1)}function _pauseRunLoop(){_isPaused=!0}function _renderFrame(t){var e=_stages[_state].stage;game$1.update(t,e),game$1.draw(e),-1!==_animFrameId&&(_animFrameId=window.requestAnimationFrame(_renderFrame))}function _stopRunLoop(){window.cancelAnimationFrame(_animFrameId),_animFrameId=-1}function _switchState(t){_stopRunLoop(),_stages[_state]&&_stages[_state].stage.destroy(),_stages[t]&&(_stages[_state=t].stage.reset.apply(_stages[_state].stage,_extraArgs),_startRunLoop(),_onSwitchComplete&&_onSwitchComplete(),game$1.repaint())}var state={LOADING:0,MENU:1,READY:2,PLAY:3,GAMEOVER:4,GAME_END:5,SCORE:6,CREDITS:7,SETTINGS:8,DEFAULT:9,USER:100,onPause:null,onResume:null,onStop:null,onRestart:null,init:function(){this.set(this.LOADING,defaultLoadingScreen),this.set(this.DEFAULT,new Stage);var t=this;event.subscribe(event.VIDEO_INIT,(function(){t.change(t.DEFAULT,!0)}))},stop:function(t){_state!==this.LOADING&&this.isRunning()&&(_stopRunLoop(),!0===t&&audio$1.pauseTrack(),_pauseTime=window.performance.now(),event.publish(event.STATE_STOP),"function"==typeof this.onStop&&this.onStop())},pause:function(t){_state===this.LOADING||this.isPaused()||(_pauseRunLoop(),!0===t&&audio$1.pauseTrack(),_pauseTime=window.performance.now(),event.publish(event.STATE_PAUSE),"function"==typeof this.onPause&&this.onPause())},restart:function(t){this.isRunning()||(_startRunLoop(),!0===t&&audio$1.resumeTrack(),_pauseTime=window.performance.now()-_pauseTime,game$1.repaint(),event.publish(event.STATE_RESTART,[_pauseTime]),"function"==typeof this.onRestart&&this.onRestart())},resume:function(t){this.isPaused()&&(_resumeRunLoop(),!0===t&&audio$1.resumeTrack(),_pauseTime=window.performance.now()-_pauseTime,event.publish(event.STATE_RESUME,[_pauseTime]),"function"==typeof this.onResume&&this.onResume())},isRunning:function(){return-1!==_animFrameId},isPaused:function(){return _isPaused},set:function(t,e,i){if(!(e instanceof Stage))throw new Error(e+" is not an instance of me.Stage");_stages[t]={},_stages[t].stage=e,_stages[t].transition=!0,!0===i&&this.change(t)},current:function(){if(void 0!==_stages[_state])return _stages[_state].stage},transition:function(t,e,i){"fade"===t&&(_fade.color=e,_fade.duration=i)},setTransition:function(t,e){_stages[t].transition=e},change:function(t,e){if(void 0===_stages[t])throw new Error("Undefined Stage for state '"+t+"'");this.isCurrent(t)||(_extraArgs=null,arguments.length>1&&(_extraArgs=Array.prototype.slice.call(arguments,1)),_fade.duration&&_stages[t].transition?(_onSwitchComplete=function(){game$1.viewport.fadeOut(_fade.color,_fade.duration)},game$1.viewport.fadeIn(_fade.color,_fade.duration,(function(){utils$1.function.defer(_switchState,this,t)}))):!0===e?_switchState(t):utils$1.function.defer(_switchState,this,t))},isCurrent:function(t){return _state===t}},state$1=state,Ellipse=window.Jay.extend({init:function(t,e,i,n){this.pos=new Vector2d,this._bounds=void 0,this.radius=NaN,this.radiusV=new Vector2d,this.radiusSq=new Vector2d,this.ratio=new Vector2d,this.shapeType="Ellipse",this.setShape(t,e,i,n)},onResetEvent:function(t,e,i,n){this.setShape(t,e,i,n)},setShape:function(t,e,i,n){var r=i/2,o=n/2;this.pos.set(t,e),this.radius=Math.max(r,o),this.ratio.set(r/this.radius,o/this.radius),this.radiusV.set(this.radius,this.radius).scaleV(this.ratio);var s=this.radius*this.radius;return this.radiusSq.set(s,s).scaleV(this.ratio),this.getBounds().setMinMax(t,e,t+i,t+n),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},rotate:function(t,e){return this.pos.rotate(t,e),this.getBounds().shift(this.pos),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},scale:function(t,e){return e=void 0!==e?e:t,this.setShape(this.pos.x,this.pos.y,2*this.radiusV.x*t,2*this.radiusV.y*e)},scaleV:function(t){return this.scale(t.x,t.y)},transform:function(){return this},translate:function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},contains:function(t,e){var i,n;return 2===arguments.length?(i=arguments[0],n=arguments[1]):(i=arguments[0].x,n=arguments[0].y),i-=this.pos.x,n-=this.pos.y,i*i/this.radiusSq.x+n*n/this.radiusSq.y<=1},getBounds:function(){return void 0===this._bounds&&(this._bounds=pool.pull("Bounds")),this._bounds},clone:function(){return new Ellipse(this.pos.x,this.pos.y,2*this.radiusV.x,2*this.radiusV.y)}}),Bounds$1=function(t){this.onResetEvent(t)},prototypeAccessors$1={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds$1.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds$1.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds$1.prototype.setMinMax=function(t,e,i,n){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=n},prototypeAccessors$1.x.get=function(){return this.min.x},prototypeAccessors$1.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors$1.y.get=function(){return this.min.y},prototypeAccessors$1.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors$1.width.get=function(){return this.max.x-this.min.x},prototypeAccessors$1.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors$1.height.get=function(){return this.max.y-this.min.y},prototypeAccessors$1.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors$1.left.get=function(){return this.min.x},prototypeAccessors$1.right.get=function(){return this.max.x},prototypeAccessors$1.top.get=function(){return this.min.y},prototypeAccessors$1.bottom.get=function(){return this.max.y},prototypeAccessors$1.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors$1.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors$1.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds$1.prototype.update=function(t){this.add(t,!0)},Bounds$1.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var n=t[i];n.x>this.max.x&&(this.max.x=n.x),n.x<this.min.x&&(this.min.x=n.x),n.y>this.max.y&&(this.max.y=n.y),n.y<this.min.y&&(this.min.y=n.y)}},Bounds$1.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds$1.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds$1.prototype.addFrame=function(t,e,i,n,r){var o=me.pool.pull("Vector2d");this.addPoint(o.set(t,e),r),this.addPoint(o.set(i,e),r),this.addPoint(o.set(t,n),r),this.addPoint(o.set(i,n),r),me.pool.push(o)},Bounds$1.prototype.contains=function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Bounds$1?(t=r.min.x,e=r.max.x,i=r.min.y,n=r.max.y):(t=e=r.x,i=n=r.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&n<=this.max.y},Bounds$1.prototype.overlaps=function(t){return this.left<=t.right&&this.right>=t.left&&this.bottom>=t.top&&this.top<=t.bottom},Bounds$1.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds$1.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds$1.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,n=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+n},Bounds$1.prototype.clone=function(){var t=new Bounds$1;return t.addBounds(this),t},Bounds$1.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds$1.prototype,prototypeAccessors$1);var Body=function(t,e,i){if(this.ancestor=t,void 0===this.bounds&&(this.bounds=new Bounds$1),void 0===this.shapes&&(this.shapes=[]),this.collisionMask=collision.types.ALL_OBJECT,this.collisionType=collision.types.ENEMY_OBJECT,void 0===this.vel&&(this.vel=new Vector2d),this.vel.set(0,0),void 0===this.accel&&(this.accel=new Vector2d),this.accel.set(0,0),void 0===this.force&&(this.force=new Vector2d),this.force.set(0,0),void 0===this.friction&&(this.friction=new Vector2d),this.friction.set(0,0),this.bounce=0,this.mass=1,void 0===this.maxVel&&(this.maxVel=new Vector2d),this.maxVel.set(490,490),void 0===this.gravity){var n=this;this.gravity=new ObservableVector2d(0,0,{onUpdate:function(t,e){"number"==typeof e&&(n.gravityScale=e/game$1.world.gravity.y),console.log("me.Body.gravity is deprecated, please see me.Body.gravityScale to modify gravity for a specific body")}})}if(this.gravityScale=1,this.ignoreGravity=!1,this.falling=!1,this.jumping=!1,"function"==typeof i&&(this.onBodyUpdate=i),this.bounds.clear(),void 0!==e)if(Array.isArray(e))for(var r=0;r<e.length;r++)this.addShape(e[r]);else this.addShape(e);this.ancestor.isKinematic=!1};function setTMXValue(name,type,value){var match;if("string"!=typeof value)return value;switch(type){case"int":case"float":value=Number(value);break;case"bool":value="true"===value;break;default:if(!value||utils$1.string.isBoolean(value))value=!value||"true"===value;else if(utils$1.string.isNumeric(value))value=Number(value);else if(0===value.search(/^json:/i)){match=value.split(/^json:/i)[1];try{value=JSON.parse(match)}catch(t){throw new Error("Unable to parse JSON: "+match)}}else if(0===value.search(/^eval:/i)){match=value.split(/^eval:/i)[1];try{value=eval(match)}catch(t){throw new Error("Unable to evaluate: "+match)}}else((match=value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/))||(match=value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/)))&&(value="#"+match[2]+match[1]);0===name.search(/^(ratio|anchorPoint)$/)&&"number"==typeof value&&(value={x:value,y:value})}return value}function parseAttributes(t,e){if(e.attributes&&e.attributes.length>0)for(var i=0;i<e.attributes.length;i++){var n=e.attributes.item(i);void 0!==n.name?t[n.name]=n.value:t[n.nodeName]=n.nodeValue}}function decompress(){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")}function decodeCSV(t){for(var e=t.replace("\n","").trim().split(","),i=[],n=0;n<e.length;n++)i.push(+e[n]);return i}function decodeBase64AsArray(t,e){var i,n,r;e=e||1;var o=window.atob(t.replace(/[^A-Za-z0-9\+\/\=]/g,"")),s=new Uint32Array(o.length/e);for(i=0,r=o.length/e;i<r;i++)for(s[i]=0,n=e-1;n>=0;--n)s[i]+=o.charCodeAt(i*e+n)<<(n<<3);return s}function decode(t,e,i){switch(i=i||"none",e=e||"none"){case"csv":return decodeCSV(t);case"base64":var n=decodeBase64AsArray(t,4);return"none"===i?n:decompress();case"none":return t;case"xml":throw new Error("XML encoding is deprecated, use base64 instead");default:throw new Error("Unknown layer encoding: "+e)}}function normalize(t,e){var i=e.nodeName;switch(i){case"data":var n=parse(e);n.text=n.text||n.chunk.text,n.encoding=n.encoding||"xml",t.data=decode(n.text,n.encoding,n.compression),t.encoding="none";break;case"imagelayer":case"layer":case"objectgroup":case"group":var r=parse(e);r.type="layer"===i?"tilelayer":i,r.image&&(r.image=r.image.source),t.layers=t.layers||[],t.layers.push(r);break;case"animation":t.animation=parse(e).frames;break;case"frame":case"object":var o=i+"s";t[o]=t[o]||[],t[o].push(parse(e));break;case"tile":var s=parse(e);s.image&&(s.imagewidth=s.image.width,s.imageheight=s.image.height,s.image=s.image.source),t.tiles=t.tiles||{},t.tiles[s.id]=s;break;case"tileset":var a=parse(e);a.image&&(a.imagewidth=a.image.width,a.imageheight=a.image.height,a.image=a.image.source),t.tilesets=t.tilesets||[],t.tilesets.push(a);break;case"polygon":case"polyline":t[i]=[];for(var h,l=parse(e).points.split(" "),u=0;u<l.length;u++)h=l[u].split(","),t[i].push({x:+h[0],y:+h[1]});break;case"properties":t.properties=parse(e);break;case"property":var c=parse(e),d=void 0!==c.value?c.value:c.text;t[c.name]=setTMXValue(c.name,c.type||"string",d);break;default:t[i]=parse(e)}}function parse(t){var e={},i="";if(1===t.nodeType&&parseAttributes(e,t),t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++){var r=t.childNodes.item(n);switch(r.nodeType){case 1:normalize(e,r);break;case 3:i+=r.nodeValue.trim()}}return i&&(e.text=i),e}function applyTMXProperties(t,e){var i=e.properties,n=e.propertytypes;if(void 0!==i)for(var r in i)if(i.hasOwnProperty(r)){var o="string",s=r,a=i[r];void 0!==i[r].name&&(s=i[r].name),void 0!==n?o=n[r]:void 0!==i[r].type&&(o=i[r].type),void 0!==i[r].value&&(a=i[r].value),t[s]=setTMXValue(s,o,a)}}Body.prototype.addShape=function(t){if(t instanceof Rect||t instanceof Bounds$1){var e=t.toPolygon();this.shapes.push(e),this.bounds.add(e.points),this.bounds.translate(e.pos)}else t instanceof Ellipse?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.addBounds(t.getBounds()),this.bounds.translate(t.getBounds().x,t.getBounds().y)):t instanceof Polygon?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.add(t.points),this.bounds.translate(t.pos)):this.fromJSON(t);return"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this),this.shapes.length},Body.prototype.setVertices=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=!0);var n=this.getShape(e);n instanceof Polygon?n.setShape(0,0,t):this.shapes[e]=new Polygon(0,0,t),this.bounds.add(this.shapes[e].points,i),"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this)},Body.prototype.addVertices=function(t,e){void 0===e&&(e=0),this.setVertices(t,e,!1)},Body.prototype.fromJSON=function(t,e){var i=t;if(void 0!==e&&(i=t[e]),void 0===i)throw new Error("Identifier ("+e+") undefined for the given JSON object)");if(i.length){for(var n=0;n<i.length;n++)this.addVertices(i[n].shape,n);this.mass=i[0].density||0,this.friction.set(i[0].friction||0,i[0].friction||0),this.bounce=i[0].bounce||0}return i.length},Body.prototype.getShape=function(t){return this.shapes[t||0]},Body.prototype.getBounds=function(){return this.bounds},Body.prototype.removeShape=function(t){this.bounds.clear(),utils$1.array.remove(this.shapes,t);for(var e=0;e<this.shapes.length;e++)this.addShape(this.shapes[e]);return this.shapes.length},Body.prototype.removeShapeAt=function(t){return this.removeShape(this.getShape(t))},Body.prototype.setCollisionMask=function(t){void 0===t&&(t=collision.types.ALL_OBJECT),this.collisionMask=t},Body.prototype.setCollisionType=function(t){if(void 0!==t){if(void 0===collision.types[t])throw new Error("Invalid value for the collisionType property");this.collisionType=collision.types[t]}},Body.prototype.respondToCollision=function(t){var e=t.overlapV;if(this.ancestor.pos.sub(e),0!==e.x&&(this.vel.x=~~(.5+this.vel.x-e.x)||0,this.bounce>0&&(this.vel.x*=-this.bounce)),0!==e.y){this.vel.y=~~(.5+this.vel.y-e.y)||0,this.bounce>0&&(this.vel.y*=-this.bounce);var i=Math.sign(game$1.world.gravity.y*this.gravityScale)||1;this.falling=e.y>=i,this.jumping=e.y<=-i}},Body.prototype.forEach=function(t,e){var i=this,n=0,r=this.shapes,o=r.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);n<o;)t.call(i,r[n],n,r),n++},Body.prototype.contains=function(){var t,e;if(2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.getBounds().contains(t,e))for(var i,n=this.shapes.length;n--,i=this.shapes[n];)if(i.contains(t,e))return!0;return!1},Body.prototype.rotate=function(t,e){var i=this;return void 0===e&&(e=this.getBounds().center),this.bounds.clear(),this.forEach((function(n){n.rotate(t,e),i.bounds.addBounds(n.getBounds()),n instanceof Ellipse?i.bounds.translate(n.getBounds().x,n.getBounds().y):i.bounds.translate(n.pos)})),this},Body.prototype.setVelocity=function(t,e){this.accel.x=0!==t?t:this.accel.x,this.accel.y=0!==e?e:this.accel.y,this.setMaxVelocity(t,e)},Body.prototype.setMaxVelocity=function(t,e){this.maxVel.x=t,this.maxVel.y=e},Body.prototype.setFriction=function(t,e){this.friction.x=t||0,this.friction.y=e||0},Body.prototype.applyFriction=function(t){var e=this.friction.x*timer$1.tick,i=t.x+e,n=t.x-e,r=this.friction.y*timer$1.tick,o=t.y+r,s=t.y-r;t.x=i<0?i:n>0?n:0,t.y=o<0?o:s>0?s:0},Body.prototype.computeVelocity=function(t){if(this.force.x&&(t.x+=this.force.x*timer$1.tick),this.force.y&&(t.y+=this.force.y*timer$1.tick),(this.friction.x||this.friction.y)&&this.applyFriction(t),!this.ignoreGravity){var e=game$1.world.gravity;t.x+=e.x*this.gravityScale*this.mass*timer$1.tick,t.y+=e.y*this.gravityScale*this.mass*timer$1.tick,this.falling=t.y*Math.sign(e.y*this.gravityScale)>0,this.jumping=!this.falling&&this.jumping}0!==t.y&&(t.y=clamp(t.y,-this.maxVel.y,this.maxVel.y)),0!==t.x&&(t.x=clamp(t.x,-this.maxVel.x,this.maxVel.x))},Body.prototype.update=function(){return this.computeVelocity(this.vel),this.ancestor.pos.add(this.vel),0!==this.vel.x||0!==this.vel.y},Body.prototype.destroy=function(){this.onBodyUpdate=void 0,this.ancestor=void 0,this.shapes.length=0};var TextureCache=function(t){this.cache=new Map,this.tinted=new Map,this.units=new Map,this.max_size=t||1/0,this.clear()};function createAtlas(t,e,i,n){return void 0===i&&(i="default"),void 0===n&&(n="no-repeat"),{meta:{app:"melonJS",size:{w:t,h:e},repeat:n,image:"default"},frames:[{filename:i,frame:{x:0,y:0,w:t,h:e}}]}}TextureCache.prototype.clear=function(){this.cache.clear(),this.tinted.clear(),this.units.clear(),this.length=0},TextureCache.prototype.validate=function(){if(this.length>=this.max_size)throw new Error("Texture cache overflow: "+this.max_size+" texture units available for this GPU.")},TextureCache.prototype.get=function(t,e){return this.cache.has(t)||(e||(e=createAtlas(t.width,t.height,t.src?utils$1.file.getBasename(t.src):void 0)),this.set(t,new Texture(e,t,!1))),this.cache.get(t)},TextureCache.prototype.tint=function(t,e){var i=this.tinted.get(t);return void 0===i&&(i=this.tinted.set(t,new Map)),i.has(e)||i.set(e,video$1.renderer.tint(t,e,"multiply")),i.get(e)},TextureCache.prototype.set=function(t,e){var i=t.width,n=t.height;if(!(1!==video$1.renderer.WebGLVersion||isPowerOfTwo(i)&&isPowerOfTwo(n))){var r=void 0!==t.src?t.src:t;console.warn("[Texture] "+r+" is not a POT texture ("+i+"x"+n+")")}this.cache.set(t,e)},TextureCache.prototype.getUnit=function(t){return this.units.has(t)||(this.validate(),this.units.set(t,this.length++)),this.units.get(t)};var Texture=function(t,e,i){if(this.format=null,this.sources=new Map,this.atlases=new Map,void 0!==t)for(var n in t=Array.isArray(t)?t:[t]){var r=t[n];if(void 0!==r.meta){if(r.meta.app.includes("texturepacker")||r.meta.app.includes("free-tex-packer")){if(this.format="texturepacker",void 0===e){var o=loader$1.getImage(r.meta.image);if(!o)throw new Error("Atlas texture '"+o+"' not found");this.sources.set(r.meta.image,o)}else this.sources.set(r.meta.image||"default","string"==typeof e?loader$1.getImage(e):e);this.repeat="no-repeat"}else if(r.meta.app.includes("ShoeBox")){if(!r.meta.exporter||!r.meta.exporter.includes("melonJS"))throw new Error("ShoeBox requires the JSON exporter : https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx");this.format="ShoeBox",this.repeat="no-repeat",this.sources.set("default","string"==typeof e?loader$1.getImage(e):e)}else r.meta.app.includes("melonJS")&&(this.format="melonJS",this.repeat=r.meta.repeat||"no-repeat",this.sources.set("default","string"==typeof e?loader$1.getImage(e):e));this.atlases.set(r.meta.image||"default",this.parse(r))}else void 0!==r.framewidth&&void 0!==r.frameheight&&(this.format="Spritesheet (fixed cell size)",this.repeat="no-repeat",void 0!==e&&(r.image="string"==typeof e?loader$1.getImage(e):e),this.atlases.set("default",this.parseFromSpriteSheet(r)),this.sources.set("default",r.image))}if(0===this.atlases.length)throw new Error("texture atlas format not supported");!1!==i&&this.sources.forEach((function(t){i instanceof TextureCache?i.set(t,this):video$1.renderer.cache.set(t,this)}))};Texture.prototype.parse=function(t){var e={},i=this;return t.frames.forEach((function(n){if(n.hasOwnProperty("filename")){var r,o,s=n.frame,a=n.spriteSourceSize&&n.sourceSize&&n.pivot;a&&(r=n.sourceSize.w*n.pivot.x-(n.trimmed?n.spriteSourceSize.x:0),o=n.sourceSize.h*n.pivot.y-(n.trimmed?n.spriteSourceSize.y:0)),e[n.filename]={name:n.filename,texture:t.meta.image||"default",offset:new Vector2d(s.x,s.y),anchorPoint:a?new Vector2d(r/s.w,o/s.h):null,trimmed:!!n.trimmed,width:s.w,height:s.h,angle:!0===n.rotated?-ETA:0},i.addUvsMap(e,n.filename,t.meta.size.w,t.meta.size.h)}})),e},Texture.prototype.parseFromSpriteSheet=function(t){var e={},i=t.image,n=t.spacing||0,r=t.margin||0,o=i.width,s=i.height,a=pool.pull("Vector2d",~~((o-r+n)/(t.framewidth+n)),~~((s-r+n)/(t.frameheight+n)));if(o%(t.framewidth+n)!=0||s%(t.frameheight+n)!=0){var h=a.x*(t.framewidth+n),l=a.y*(t.frameheight+n);h-o!==n&&l-s!==n&&(o=h,s=l,console.warn("Spritesheet Texture for image: "+i.src+" is not divisible by "+(t.framewidth+n)+"x"+(t.frameheight+n)+", truncating effective size to "+o+"x"+s))}for(var u=0,c=a.x*a.y;u<c;u++){var d=""+u;e[d]={name:d,texture:"default",offset:new Vector2d(r+(n+t.framewidth)*(u%a.x),r+(n+t.frameheight)*~~(u/a.x)),anchorPoint:t.anchorPoint||null,trimmed:!1,width:t.framewidth,height:t.frameheight,angle:0},this.addUvsMap(e,d,o,s)}return pool.push(a),e},Texture.prototype.addUvsMap=function(t,e,i,n){if(video$1.renderer instanceof WebGLRenderer){var r=t[e].offset,o=t[e].width,s=t[e].height;t[e].uvs=new Float32Array([r.x/i,r.y/n,(r.x+o)/i,(r.y+s)/n]),t[r.x+","+r.y+","+i+","+n]=t[e]}return t[e]},Texture.prototype.addQuadRegion=function(t,e,i,n,r){!0===video$1.renderer.settings.verbose&&console.warn("Adding texture region",t,"for texture",this);var o=this.getTexture(),s=this.getAtlas(),a=o.width,h=o.height;return s[t]={name:t,offset:new Vector2d(e,i),width:n,height:r,angle:0},this.addUvsMap(s,t,a,h),s[t]},Texture.prototype.getAtlas=function(t){return"string"==typeof t?this.atlases.get(t):this.atlases.values().next().value},Texture.prototype.getFormat=function(){return this.format},Texture.prototype.getTexture=function(t){return"object"==typeof t&&"string"==typeof t.texture?this.sources.get(t.texture):this.sources.values().next().value},Texture.prototype.getRegion=function(t,e){var i;return"string"==typeof e?i=this.getAtlas(e)[t]:this.atlases.forEach((function(e){void 0!==e[t]&&(i=e[t])})),i},Texture.prototype.getUVs=function(t){var e=this.getRegion(t);if(void 0===e){var i=t.split(","),n=+i[0],r=+i[1],o=+i[2],s=+i[3];e=this.addQuadRegion(t,n,r,o,s)}return e.uvs},Texture.prototype.createSpriteFromName=function(t,e){return pool.pull("me.Sprite",0,0,Object.assign({image:this,region:t},e||{}))},Texture.prototype.createAnimationFromName=function(t,e){for(var i,n=[],r={},o=0,s=0,a=0;a<t.length;++a){if(null==(i=this.getRegion(t[a])))throw new Error("Texture - region for "+t[a]+" not found");n[a]=i,r[t[a]]=a,o=Math.max(i.width,o),s=Math.max(i.height,s)}return new Sprite(0,0,Object.assign({image:this,framewidth:o,frameheight:s,margin:0,spacing:0,atlas:n,atlasIndices:r},e||{}))};var Sprite=Renderable.extend({init:function(t,e,i){if(this.animationpause=!1,this.animationspeed=100,this.offset=pool.pull("Vector2d",0,0),this.source=null,this.anim={},this.resetAnim=void 0,this.current={name:"default",length:0,offset:new Vector2d,width:0,height:0,angle:0,idx:0},this.dt=0,this._flicker={isFlickering:!1,duration:0,callback:null,state:!1},this._super(Renderable,"init",[t,e,0,0]),i.image instanceof Texture){if(this.source=i.image,this.image=this.source.getTexture(),this.textureAtlas=i.image,void 0!==i.region){var n=this.source.getRegion(i.region);if(!n)throw new Error("Texture - region for "+i.region+" not found");this.setRegion(n),this.current.width=i.framewidth||n.width,this.current.height=i.frameheight||n.height}}else this.image="object"==typeof i.image?i.image:loader$1.getImage(i.image),this.current.width=i.framewidth=i.framewidth||this.image.width,this.current.height=i.frameheight=i.frameheight||this.image.height,this.source=video$1.renderer.cache.get(this.image,i),this.textureAtlas=this.source.getAtlas();void 0!==i.atlas&&(this.textureAtlas=i.atlas,this.atlasIndices=i.atlasIndices),this.width=this.current.width,this.height=this.current.height,void 0!==i.flipX&&this.flipX(!!i.flipX),void 0!==i.flipY&&this.flipY(!!i.flipY),void 0!==i.rotation&&this.currentTransform.rotate(i.rotation),i.anchorPoint&&this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y),void 0!==i.tint&&this.tint.setColor(i.tint),"string"==typeof i.name&&(this.name=i.name),0!==this.addAnimation("default",null)&&this.setCurrentAnimation("default"),this.autoTransform=!0},isFlickering:function(){return this._flicker.isFlickering},flicker:function(t,e){return this._flicker.duration=t,this._flicker.duration<=0?(this._flicker.isFlickering=!1,this._flicker.callback=null):this._flicker.isFlickering||(this._flicker.callback=e,this._flicker.isFlickering=!0),this},addAnimation:function(t,e,i){this.anim[t]={name:t,frames:[],idx:0,length:0};var n=0;if("object"!=typeof this.textureAtlas)return 0;null==e&&(e=[],Object.keys(this.textureAtlas).forEach((function(t,i){e[i]=i})));for(var r=0,o=e.length;r<o;r++){var s,a=e[r],h=(s="number"==typeof a||"string"==typeof a?{name:a,delay:i||this.animationspeed}:a).name;if("number"==typeof h)void 0!==this.textureAtlas[h]&&(this.anim[t].frames[r]=Object.assign({},this.textureAtlas[h],s),n++);else{if(this.source.getFormat().includes("Spritesheet"))throw new Error("string parameters for addAnimation are not allowed for standard spritesheet based Texture");this.anim[t].frames[r]=Object.assign({},this.textureAtlas[this.atlasIndices[h]],s),n++}}return this.anim[t].length=n,n},setCurrentAnimation:function(t,e,i){if(!this.anim[t])throw new Error("animation id '"+t+"' not defined");return this.current.name=t,this.current.length=this.anim[this.current.name].length,this.resetAnim="string"==typeof e?this.setCurrentAnimation.bind(this,e,null,!0):"function"==typeof e?e:void 0,this.setAnimationFrame(this.current.idx),i||(this.dt=0),this.isDirty=!0,this},reverseAnimation:function(t){return void 0!==t&&void 0!==this.anim[t]?this.anim[t].frames.reverse():this.anim[this.current.name].frames.reverse(),this.isDirty=!0,this},isCurrentAnimation:function(t){return this.current.name===t},setRegion:function(t){return this.image=this.source.getTexture(t),this.current.offset.setV(t.offset),this.current.angle=t.angle,this.width=this.current.width=t.width,this.height=this.current.height=t.height,t.anchorPoint&&this.anchorPoint.set(this._flip.x&&!0===t.trimmed?1-t.anchorPoint.x:t.anchorPoint.x,this._flip.y&&!0===t.trimmed?1-t.anchorPoint.y:t.anchorPoint.y),this.isDirty=!0,this},setAnimationFrame:function(t){return this.current.idx=(t||0)%this.current.length,this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx))},getCurrentAnimationFrame:function(){return this.current.idx},getAnimationFrameObjectByIndex:function(t){return this.anim[this.current.name].frames[t]},update:function(t){if(!this.animationpause&&this.current&&this.current.length>0){var e=this.getAnimationFrameObjectByIndex(this.current.idx).delay;for(this.dt+=t;this.dt>=e;){this.isDirty=!0,this.dt-=e;var i=this.current.length>1?this.current.idx+1:this.current.idx;if(this.setAnimationFrame(i),0===this.current.idx&&"function"==typeof this.resetAnim&&!1===this.resetAnim()){this.setAnimationFrame(this.current.length-1),this.dt%=e;break}e=this.getAnimationFrameObjectByIndex(this.current.idx).delay}}return this._flicker.isFlickering&&(this._flicker.duration-=t,this._flicker.duration<0&&("function"==typeof this._flicker.callback&&this._flicker.callback(),this.flicker(-1)),this.isDirty=!0),this.isDirty},destroy:function(){pool.push(this.offset),this.offset=void 0,this._super(Renderable,"destroy")},draw:function(t){if(!this._flicker.isFlickering||(this._flicker.state=!this._flicker.state,this._flicker.state)){var e=this.current,i=this.pos.x,n=this.pos.y,r=e.width,o=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-n),t.rotate(e.angle),i-=o,r=e.height,o=e.width),t.drawImage(this.image,a.x+s.x,a.y+s.y,r,o,i,n,r,o)}}}),TMX_FLIP_H=2147483648,TMX_FLIP_V=1073741824,TMX_FLIP_AD=536870912,TMX_CLEAR_BIT_MASK$1=536870911,Tile=function(t){function e(e,i,n,r){var o,s;if(t.call(this),r.isCollection){var a=r.getTileImage(n&TMX_CLEAR_BIT_MASK$1);o=a.width,s=a.height}else o=r.tilewidth,s=r.tileheight;this.setMinMax(0,0,o,s),this.tileset=r,this.currentTransform=null,this.col=e,this.row=i,this.tileId=n,this.flippedX=0!=(this.tileId&TMX_FLIP_H),this.flippedY=0!=(this.tileId&TMX_FLIP_V),this.flippedAD=0!=(this.tileId&TMX_FLIP_AD),this.flipped=this.flippedX||this.flippedY||this.flippedAD,!0===this.flipped&&(null===this.currentTransform&&(this.currentTransform=new Matrix2d),this.setTileTransform(this.currentTransform.identity())),this.tileId&=TMX_CLEAR_BIT_MASK$1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setTileTransform=function(t){t.translate(this.width/2,this.height/2),this.flippedAD&&(t.rotate(-90*Math.PI/180),t.scale(-1,1)),this.flippedX&&t.scale(this.flippedAD?1:-1,this.flippedAD?-1:1),this.flippedY&&t.scale(this.flippedAD?-1:1,this.flippedAD?1:-1),t.translate(-this.width/2,-this.height/2)},e.prototype.getRenderable=function(t){var e,i=this.tileset;if(i.animations.has(this.tileId)){var n=[],r=[];i.animations.get(this.tileId).frames.forEach((function(t){r.push(t.tileid),n.push({name:""+t.tileid,delay:t.duration})})),(e=i.texture.createAnimationFromName(r,t)).addAnimation(this.tileId-i.firstgid,n),e.setCurrentAnimation(this.tileId-i.firstgid)}else if(!0===i.isCollection){var o=i.getTileImage(this.tileId);(e=new Sprite(0,0,Object.assign({image:o}))).anchorPoint.set(0,0),e.scale(t.width/this.width,t.height/this.height),void 0!==t.rotation&&(e.anchorPoint.set(.5,.5),e.currentTransform.rotate(t.rotation),e.currentTransform.translate(t.width/2,t.height/2),t.rotation=void 0)}else(e=i.texture.createSpriteFromName(this.tileId-i.firstgid,t)).anchorPoint.set(0,0);return this.setTileTransform(e.currentTransform),e},e}(Bounds$1),Line=Polygon.extend({contains:function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y;var i=this.points[0],n=this.points[1];return(e-i.y)*(n.x-i.x)==(n.y-i.y)*(t-i.x)},recalc:function(){var t=this.edges,e=this.normals,i=this.indices,n=this.points;if(2!==n.length)throw new Error("Requires exactly 2 points");return void 0===t[0]&&(t[0]=new Vector2d),t[0].copy(n[1]).sub(n[0]),void 0===e[0]&&(e[0]=new Vector2d),e[0].copy(t[0]).perp().normalize(),i.length=0,this},clone:function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Line(this.pos.x,this.pos.y,t)}}),Renderer=function(t){return this.settings=t,this.isContextValid=!0,this.currentScissor=new Int32Array([0,0,this.settings.width,this.settings.height]),this.currentBlendMode="normal",!0===device$1.ejecta?this.canvas=document.getElementById("canvas"):void 0!==window.canvas?this.canvas=window.canvas:void 0!==this.settings.canvas?this.canvas=this.settings.canvas:this.canvas=video$1.createCanvas(this.settings.zoomX,this.settings.zoomY),this.backBufferCanvas=this.canvas,this.context=null,this.currentColor=new Color(0,0,0,1),this.currentTint=new Color(255,255,255,1),this.projectionMatrix=new Matrix3d,this.uvOffset=0,this.Texture=Texture,event.subscribe(event.GAME_RESET,(function(){video$1.renderer.reset()})),this};Renderer.prototype.clear=function(){},Renderer.prototype.reset=function(){this.resetTransform(),this.setBlendMode(this.settings.blendMode),this.setColor("#000000"),this.clearTint(),this.cache.clear(),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},Renderer.prototype.getCanvas=function(){return this.backBufferCanvas},Renderer.prototype.getScreenCanvas=function(){return this.canvas},Renderer.prototype.getScreenContext=function(){return this.context},Renderer.prototype.getBlendMode=function(){return this.currentBlendMode},Renderer.prototype.getContext2d=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a 2d context");if(void 0===t.getContext)throw new Error("Your browser does not support HTML5 canvas.");"boolean"!=typeof e&&(e=!0);var i=t.getContext("2d",{alpha:e});return i.canvas||(i.canvas=t),this.setAntiAlias(i,this.settings.antiAlias),i},Renderer.prototype.getWidth=function(){return this.backBufferCanvas.width},Renderer.prototype.getHeight=function(){return this.backBufferCanvas.height},Renderer.prototype.getColor=function(){return this.currentColor},Renderer.prototype.globalAlpha=function(){return this.currentColor.glArray[3]},Renderer.prototype.overlaps=function(t){return t.left<=this.getWidth()&&t.right>=0&&t.top<=this.getHeight()&&t.bottom>=0},Renderer.prototype.resize=function(t,e){t===this.backBufferCanvas.width&&e===this.backBufferCanvas.height||(this.canvas.width=this.backBufferCanvas.width=t,this.canvas.height=this.backBufferCanvas.height=e,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=t,this.currentScissor[3]=e,event.publish(event.CANVAS_ONRESIZE,[t,e]))},Renderer.prototype.setAntiAlias=function(t,e){var i=t.canvas;setPrefixed("imageSmoothingEnabled",!0===e,t),!0!==e?(i.style["image-rendering"]="optimizeSpeed",i.style["image-rendering"]="-moz-crisp-edges",i.style["image-rendering"]="-o-crisp-edges",i.style["image-rendering"]="-webkit-optimize-contrast",i.style["image-rendering"]="optimize-contrast",i.style["image-rendering"]="crisp-edges",i.style["image-rendering"]="pixelated",i.style.msInterpolationMode="nearest-neighbor"):i.style["image-rendering"]="auto"},Renderer.prototype.setProjection=function(t){this.projectionMatrix.copy(t)},Renderer.prototype.stroke=function(t,e){t instanceof Rect||t instanceof Bounds$1?this.strokeRect(t.left,t.top,t.width,t.height,e):t instanceof Line||t instanceof Polygon?this.strokePolygon(t,e):t instanceof Ellipse&&this.strokeEllipse(t.pos.x,t.pos.y,t.radiusV.x,t.radiusV.y,e)},Renderer.prototype.tint=function(t,e,i){var n=video$1.createCanvas(t.width,t.height,!0),r=this.getContext2d(n);return r.save(),r.fillStyle=e instanceof Color?e.toRGB():e,r.fillRect(0,0,t.width,t.height),r.globalCompositeOperation=i||"multiply",r.drawImage(t,0,0),r.globalCompositeOperation="destination-atop",r.drawImage(t,0,0),r.restore(),n},Renderer.prototype.fill=function(t){this.stroke(t,!0)},Renderer.prototype.setMask=function(t){},Renderer.prototype.clearMask=function(){},Renderer.prototype.setTint=function(t){this.currentTint.copy(t)},Renderer.prototype.clearTint=function(){this.currentTint.setColor(255,255,255,1)},Renderer.prototype.drawFont=function(){};var CanvasRenderer=function(t){function e(e){return t.call(this,e),this.context=this.getContext2d(this.getScreenCanvas(),this.settings.transparent),this.settings.doubleBuffering?(this.backBufferCanvas=video$1.createCanvas(this.settings.width,this.settings.height,!0),this.backBufferContext2D=this.getContext2d(this.backBufferCanvas)):(this.backBufferCanvas=this.getScreenCanvas(),this.backBufferContext2D=this.context),this.setBlendMode(this.settings.blendMode),this.setColor(this.currentColor),this.cache=new TextureCache,!1===this.settings.textureSeamFix||this.settings.antiAlias||(this.uvOffset=1),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),this.clearColor(this.currentColor,!0!==this.settings.transparent)},e.prototype.resetTransform=function(){this.backBufferContext2D.setTransform(1,0,0,1,0,0)},e.prototype.setBlendMode=function(t,e){if(e=e||this.getContext(),this.currentBlendMode=t,"multiply"===t)e.globalCompositeOperation="multiply";else e.globalCompositeOperation="source-over",this.currentBlendMode="normal";this.settings.doubleBuffering&&this.settings.transparent&&(this.context.globalCompositeOperation="copy")},e.prototype.clear=function(){this.settings.transparent&&this.clearColor("rgba(0,0,0,0)",!0)},e.prototype.flush=function(){this.settings.doubleBuffering&&this.context.drawImage(this.backBufferCanvas,0,0)},e.prototype.clearColor=function(t,e){this.save(),this.resetTransform(),this.backBufferContext2D.globalCompositeOperation=e?"copy":"source-over",this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t,this.fillRect(0,0,this.backBufferCanvas.width,this.backBufferCanvas.height),this.restore()},e.prototype.clearRect=function(t,e,i,n){this.backBufferContext2D.clearRect(t,e,i,n)},e.prototype.createPattern=function(t,e){return this.backBufferContext2D.createPattern(t,e)},e.prototype.drawImage=function(t,e,i,n,r,o,s,a,h){if(!(this.backBufferContext2D.globalAlpha<1/255)){void 0===n?(n=a=t.width,r=h=t.height,o=e,s=i,e=0,i=0):void 0===o&&(o=e,s=i,a=n,h=r,n=t.width,r=t.height,e=0,i=0),!1===this.settings.subPixel&&(o=~~o,s=~~s);var l=t,u=this.currentTint.toArray();1===u[0]&&1===u[1]&&1===u[2]||(l=this.cache.tint(t,this.currentTint.toRGB())),this.backBufferContext2D.drawImage(l,e,i,n,r,o,s,a,h)}},e.prototype.drawPattern=function(t,e,i,n,r){if(!(this.backBufferContext2D.globalAlpha<1/255)){var o=this.backBufferContext2D.fillStyle;this.backBufferContext2D.fillStyle=t,this.backBufferContext2D.fillRect(e,i,n,r),this.backBufferContext2D.fillStyle=o}},e.prototype.strokeArc=function(t,e,i,n,r,o,s){var a=this.backBufferContext2D;a.globalAlpha<1/255||(a.translate(t,e),a.beginPath(),a.arc(0,0,i,n,r,o||!1),a[!0===s?"fill":"stroke"](),a.translate(-t,-e))},e.prototype.fillArc=function(t,e,i,n,r,o){this.strokeArc(t,e,i,n,r,o||!1,!0)},e.prototype.strokeEllipse=function(t,e,i,n,r){var o=this.backBufferContext2D;if(!(o.globalAlpha<1/255)){var s=t-i,a=t+i,h=e-n,l=e+n,u=.551784*i,c=.551784*n,d=t-u,p=t+u,f=e-c,g=e+c;o.beginPath(),o.moveTo(t,h),o.bezierCurveTo(p,h,a,f,a,e),o.bezierCurveTo(a,g,p,l,t,l),o.bezierCurveTo(d,l,s,g,s,e),o.bezierCurveTo(s,f,d,h,t,h),o[!0===r?"fill":"stroke"](),o.closePath()}},e.prototype.fillEllipse=function(t,e,i,n){this.strokeEllipse(t,e,i,n,!0)},e.prototype.strokeLine=function(t,e,i,n){var r=this.backBufferContext2D;r<1/255||(r.beginPath(),r.moveTo(t,e),r.lineTo(i,n),r.stroke())},e.prototype.fillLine=function(t,e,i,n){this.strokeLine(t,e,i,n)},e.prototype.strokePolygon=function(t,e){var i=this.backBufferContext2D;if(!(i.globalAlpha<1/255)){var n;this.translate(t.pos.x,t.pos.y),i.beginPath(),i.moveTo(t.points[0].x,t.points[0].y);for(var r=1;r<t.points.length;r++)n=t.points[r],i.lineTo(n.x,n.y);i.lineTo(t.points[0].x,t.points[0].y),i[!0===e?"fill":"stroke"](),i.closePath(),this.translate(-t.pos.x,-t.pos.y)}},e.prototype.fillPolygon=function(t){this.strokePolygon(t,!0)},e.prototype.strokeRect=function(t,e,i,n,r){if(!0===r)this.fillRect(t,e,i,n);else{if(this.backBufferContext2D.globalAlpha<1/255)return;this.backBufferContext2D.strokeRect(t,e,i,n)}},e.prototype.fillRect=function(t,e,i,n){this.backBufferContext2D.globalAlpha<1/255||this.backBufferContext2D.fillRect(t,e,i,n)},e.prototype.getContext=function(){return this.backBufferContext2D},e.prototype.getFontContext=function(){return this.getContext()},e.prototype.save=function(){this.backBufferContext2D.save()},e.prototype.restore=function(){this.backBufferContext2D.restore(),this.currentColor.glArray[3]=this.backBufferContext2D.globalAlpha,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},e.prototype.rotate=function(t){this.backBufferContext2D.rotate(t)},e.prototype.scale=function(t,e){this.backBufferContext2D.scale(t,e)},e.prototype.setColor=function(t){this.backBufferContext2D.strokeStyle=this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t},e.prototype.setGlobalAlpha=function(t){this.backBufferContext2D.globalAlpha=this.currentColor.glArray[3]=t},e.prototype.setLineWidth=function(t){this.backBufferContext2D.lineWidth=t},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=t.toArray(),i=e[0],n=e[1],r=e[3],o=e[4],s=e[6],a=e[7];!1===this.settings.subPixel&&(s|=0,a|=0),this.backBufferContext2D.transform(i,n,r,o,s,a)},e.prototype.translate=function(t,e){!1===this.settings.subPixel?this.backBufferContext2D.translate(~~t,~~e):this.backBufferContext2D.translate(t,e)},e.prototype.clipRect=function(t,e,i,n){var r=this.backBufferCanvas;if(0!==t||0!==e||i!==r.width||n!==r.height){var o=this.currentScissor;if(o[0]!==t||o[1]!==e||o[2]!==i||o[3]!==n){var s=this.backBufferContext2D;s.beginPath(),s.rect(t,e,i,n),s.clip(),o[0]=t,o[1]=e,o[2]=i,o[3]=n}}},e.prototype.setMask=function(t){var e=this.backBufferContext2D,i=t.pos.x,n=t.pos.y;if(t instanceof Ellipse){var r=t.radiusV.x,o=t.radiusV.y,s=i-r,a=i+r,h=n-o,l=n+o,u=.551784*r,c=.551784*o,d=i-u,p=i+u,f=n-c,g=n+c;e.beginPath(),e.moveTo(i,h),e.bezierCurveTo(p,h,a,f,a,n),e.bezierCurveTo(a,g,p,l,i,l),e.bezierCurveTo(d,l,s,g,s,n),e.bezierCurveTo(s,f,d,h,i,h)}else{var m;e.save(),e.beginPath(),e.moveTo(i+t.points[0].x,n+t.points[0].y);for(var y=1;y<t.points.length;y++)m=t.points[y],e.lineTo(i+m.x,n+m.y);e.closePath()}e.clip()},e.prototype.clearMask=function(){this.backBufferContext2D.restore()},e}(Renderer);function initArray(t){t.layerData=new Array(t.cols);for(var e=0;e<t.cols;e++){t.layerData[e]=new Array(t.rows);for(var i=0;i<t.rows;i++)t.layerData[e][i]=null}}function setLayerData(t,e){var i=0;initArray(t);for(var n=0;n<t.rows;n++)for(var r=0;r<t.cols;r++){var o=e[i++];0!==o&&(t.layerData[r][n]=t.getTileById(o,r,n))}}function preRenderLayer(t,e){for(var i=0;i<t.rows;i++)for(var n=0;n<t.cols;n++){var r=t.layerData[n][i];r instanceof Tile&&t.getRenderer().drawTile(e,n,i,r)}}var TMXLayer=Renderable.extend({init:function(t,e,i,n,r,o,s){this._super(Renderable,"init",[0,0,0,0]),this.tilewidth=e.tilewidth||i,this.tileheight=e.tileheight||n,this.orientation=r,this.tilesets=o,this.tileset=this.tilesets?this.tilesets.getTilesetByIndex(0):null,this.maxTileSize={width:0,height:0};for(var a=0;a<this.tilesets.length;a++){var h=this.tilesets.getTilesetByIndex(a);this.maxTileSize.width=Math.max(this.maxTileSize.width,h.tilewidth),this.maxTileSize.height=Math.max(this.maxTileSize.height,h.tileheight)}this.animatedTilesets=[],this.isAnimated=!1,this.renderorder=e.renderorder||"right-down",this.pos.z=s,this.anchorPoint.set(0,0),this.name=e.name,this.cols=+e.width,this.rows=+e.height;var l=void 0!==e.visible?+e.visible:1;this.setOpacity(l?+e.opacity:0),"string"==typeof e.tintcolor&&this.tint.parseHex(e.tintcolor,!0),"isometric"===this.orientation?(this.width=(this.cols+this.rows)*(this.tilewidth/2),this.height=(this.cols+this.rows)*(this.tileheight/2)):(this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight),applyTMXProperties(this,e),void 0===this.preRender&&(this.preRender=game$1.world.preRender),this.setRenderer(t.getRenderer()),setLayerData(this,decode(e.data,e.encoding,e.compression))},onActivateEvent:function(){if(void 0===this.animatedTilesets&&(this.animatedTilesets=[]),this.tilesets)for(var t=this.tilesets.tilesets,e=0;e<t.length;e++)t[e].isAnimated&&this.animatedTilesets.push(t[e]);this.isAnimated=this.animatedTilesets.length>0,this.isAnimated&&(this.preRender=!1),this.getBounds().addBounds(this.getRenderer().getBounds(),!0),this.getBounds().shift(this.pos),!0!==this.preRender||this.canvasRenderer||(this.canvasRenderer=new CanvasRenderer({canvas:video$1.createCanvas(this.width,this.height),widht:this.width,heigth:this.height,transparent:!0}),preRenderLayer(this,this.canvasRenderer))},onDeactivateEvent:function(){this.animatedTilesets=void 0},setRenderer:function(t){this.renderer=t},getRenderer:function(){return this.renderer},getTileId:function(t,e){var i=this.getTile(t,e);return i?i.tileId:null},getTile:function(t,e){var i=null;if(this.contains(t,e)){var n=this.getRenderer().pixelToTileCoords(t,e,pool.pull("Vector2d"));i=this.cellAt(n.x,n.y),pool.push(n)}return i},setTile:function(t,e,i){return this.layerData[e][i]=t,t},getTileById:function(t,e,i){return this.tileset.contains(t)||(this.tileset=this.tilesets.getTilesetByGid(t)),new Tile(e,i,t,this.tileset)},cellAt:function(t,e,i){var n=~~t,r=~~e,o=this.getRenderer();return!1===i||n>=0&&n<o.cols&&r>=0&&r<o.rows?this.layerData[n][r]:null},clearTile:function(t,e){this.layerData[t][e]=null,this.preRender&&this.canvasRenderer.clearRect(t*this.tilewidth,e*this.tileheight,this.tilewidth,this.tileheight)},update:function(t){if(this.isAnimated){for(var e=!1,i=0;i<this.animatedTilesets.length;i++)e=this.animatedTilesets[i].update(t)||e;return e}return!1},draw:function(t,e){if(this.preRender){var i=Math.min(e.width,this.width),n=Math.min(e.height,this.height);t.drawImage(this.canvasRenderer.getCanvas(),e.pos.x,e.pos.y,i,n,e.pos.x,e.pos.y,i,n)}else this.getRenderer().drawTileLayer(t,this,e)}}),Bounds=function(t){this.onResetEvent(t)},prototypeAccessors={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds.prototype.setMinMax=function(t,e,i,n){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=n},prototypeAccessors.x.get=function(){return this.min.x},prototypeAccessors.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors.y.get=function(){return this.min.y},prototypeAccessors.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors.width.get=function(){return this.max.x-this.min.x},prototypeAccessors.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors.height.get=function(){return this.max.y-this.min.y},prototypeAccessors.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors.left.get=function(){return this.min.x},prototypeAccessors.right.get=function(){return this.max.x},prototypeAccessors.top.get=function(){return this.min.y},prototypeAccessors.bottom.get=function(){return this.max.y},prototypeAccessors.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds.prototype.update=function(t){this.add(t,!0)},Bounds.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var n=t[i];n.x>this.max.x&&(this.max.x=n.x),n.x<this.min.x&&(this.min.x=n.x),n.y>this.max.y&&(this.max.y=n.y),n.y<this.min.y&&(this.min.y=n.y)}},Bounds.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds.prototype.addFrame=function(t,e,i,n,r){var o=me.pool.pull("Vector2d");this.addPoint(o.set(t,e),r),this.addPoint(o.set(i,e),r),this.addPoint(o.set(t,n),r),this.addPoint(o.set(i,n),r),me.pool.push(o)},Bounds.prototype.contains=function(){var t,e,i,n,r=arguments[0];return 2===arguments.length?(t=e=r,i=n=arguments[1]):r instanceof Bounds?(t=r.min.x,e=r.max.x,i=r.min.y,n=r.max.y):(t=e=r.x,i=n=r.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&n<=this.max.y},Bounds.prototype.overlaps=function(t){return this.left<=t.right&&this.right>=t.left&&this.bottom>=t.top&&this.top<=t.bottom},Bounds.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,n=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+n},Bounds.prototype.clone=function(){var t=new Bounds;return t.addBounds(this),t},Bounds.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds.prototype,prototypeAccessors);var TMXRenderer=function(t,e,i,n){this.cols=t,this.rows=e,this.tilewidth=i,this.tileheight=n,this.bounds=new Bounds};TMXRenderer.prototype.canRender=function(t){return this.tilewidth===t.tilewidth&&this.tileheight===t.tileheight},TMXRenderer.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return e.setMinMax(0,0,this.cols*this.tilewidth,this.rows*this.tileheight),e},TMXRenderer.prototype.pixelToTileCoords=function(t,e,i){return i},TMXRenderer.prototype.tileToPixelCoords=function(t,e,i){return i},TMXRenderer.prototype.drawTile=function(t,e,i,n){},TMXRenderer.prototype.drawTileLayer=function(t,e,i){};var TMXOrthogonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"orthogonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(t/this.tilewidth,e/this.tileheight)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set(t*this.tilewidth,e*this.tileheight)},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset;r.drawTile(t,r.tileoffset.x+e*this.tilewidth,r.tileoffset.y+(i+1)*this.tileheight-r.tileheight,n)},e.prototype.drawTileLayer=function(t,e,i){var n=1,r=1,o=this.pixelToTileCoords(Math.max(i.pos.x-(e.maxTileSize.width-e.tilewidth),0),Math.max(i.pos.y-(e.maxTileSize.height-e.tileheight),0),pool.pull("Vector2d")).floorSelf(),s=this.pixelToTileCoords(i.pos.x+i.width+this.tilewidth,i.pos.y+i.height+this.tileheight,pool.pull("Vector2d")).ceilSelf();switch(s.x=s.x>this.cols?this.cols:s.x,s.y=s.y>this.rows?this.rows:s.y,e.renderorder){case"right-up":s.y=o.y+(o.y=s.y)-s.y,r=-1;break;case"left-down":s.x=o.x+(o.x=s.x)-s.x,n=-1;break;case"left-up":s.x=o.x+(o.x=s.x)-s.x,s.y=o.y+(o.y=s.y)-s.y,n=-1,r=-1}for(var a=o.y;a!==s.y;a+=r)for(var h=o.x;h!==s.x;h+=n){var l=e.cellAt(h,a,!1);l&&this.drawTile(t,h,a,l)}pool.push(o),pool.push(s)},e}(TMXRenderer),TMXIsometricRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight),this.hTilewidth=this.tilewidth/2,this.hTileheight=this.tileheight/2,this.originX=this.rows*this.hTilewidth}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"isometric"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return e.setMinMax(0,0,(this.cols+this.rows)*(this.tilewidth/2),(this.cols+this.rows)*(this.tileheight/2)),e},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(e/this.tileheight+(t-this.originX)/this.tilewidth,e/this.tileheight-(t-this.originX)/this.tilewidth)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set((t-e)*this.hTilewidth+this.originX,(t+e)*this.hTileheight)},e.prototype.adjustPosition=function(t){var e=t.x/this.hTilewidth,i=t.y/this.tileheight,n=pool.pull("Vector2d");this.tileToPixelCoords(e,i,n),t.x=n.x,t.y=n.y,pool.push(n)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset;r.drawTile(t,(this.cols-1)*r.tilewidth+(e-i)*r.tilewidth>>1,-r.tilewidth+(e+i)*r.tileheight>>2,n)},e.prototype.drawTileLayer=function(t,e,i){var n=e.tileset,r=this.pixelToTileCoords(i.pos.x-n.tilewidth,i.pos.y-n.tileheight,pool.pull("Vector2d")).floorSelf(),o=this.pixelToTileCoords(i.pos.x+i.width+n.tilewidth,i.pos.y+i.height+n.tileheight,pool.pull("Vector2d")).ceilSelf(),s=this.tileToPixelCoords(o.x,o.y,pool.pull("Vector2d")),a=this.tileToPixelCoords(r.x,r.y,pool.pull("Vector2d"));a.x-=this.hTilewidth,a.y+=this.tileheight;var h=a.y-i.pos.y>this.hTileheight,l=i.pos.x-a.x<this.hTilewidth;h&&(l?(r.x--,a.x-=this.hTilewidth):(r.y--,a.x+=this.hTilewidth),a.y-=this.hTileheight);for(var u=h^l,c=r.clone(),d=2*a.y;d-2*this.tileheight<2*s.y;d+=this.tileheight){c.setV(r);for(var p=a.x;p<s.x;p+=this.tilewidth){var f=e.cellAt(c.x,c.y);if(f){var g=(n=f.tileset).tileoffset;n.drawTile(t,g.x+p,g.y+d/2-n.tileheight,f)}c.x++,c.y--}u?(r.y++,a.x-=this.hTilewidth,u=!1):(r.x++,a.x+=this.hTilewidth,u=!0)}pool.push(c),pool.push(r),pool.push(o),pool.push(s),pool.push(a)},e}(TMXRenderer),offsetsStaggerX=[{x:0,y:0},{x:1,y:-1},{x:1,y:0},{x:2,y:0}],offsetsStaggerY=[{x:0,y:0},{x:-1,y:1},{x:0,y:1},{x:0,y:2}],TMXHexagonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,-2&e.tilewidth,-2&e.tileheight),this.hexsidelength=e.hexsidelength||0,this.staggerX="x"===e.staggeraxis,this.staggerEven="even"===e.staggerindex,this.sidelengthx=0,this.sidelengthy=0,"hexagonal"===e.orientation&&(this.staggerX?this.sidelengthx=this.hexsidelength:this.sidelengthy=this.hexsidelength),this.sideoffsetx=(this.tilewidth-this.sidelengthx)/2,this.sideoffsety=(this.tileheight-this.sidelengthy)/2,this.columnwidth=this.sideoffsetx+this.sidelengthx,this.rowheight=this.sideoffsety+this.sidelengthy,this.centers=[new Vector2d,new Vector2d,new Vector2d,new Vector2d]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"hexagonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pool.pull("Bounds"):this.bounds;return this.staggerX?(e.setMinMax(0,0,this.cols*this.columnwidth+this.sideoffsetx,this.rows*(this.tileheight+this.sidelengthy)),e.width>1&&(e.height+=this.rowheight)):(e.setMinMax(0,0,this.cols*(this.tilewidth+this.sidelengthx),this.rows*this.rowheight+this.sideoffsety),e.height>1&&(e.width+=this.columnwidth)),e},e.prototype.doStaggerX=function(t){return this.staggerX&&1&t^this.staggerEven},e.prototype.doStaggerY=function(t){return!this.staggerX&&1&t^this.staggerEven},e.prototype.topLeft=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t-1,e):n.set(t-1,e-1):1&e^this.staggerEven?n.set(t,e-1):n.set(t-1,e-1),n},e.prototype.topRight=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t+1,e):n.set(t+1,e-1):1&e^this.staggerEven?n.set(t+1,e-1):n.set(t,e-1),n},e.prototype.bottomLeft=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t-1,e+1):n.set(t-1,e):1&e^this.staggerEven?n.set(t,e+1):n.set(t-1,e+1),n},e.prototype.bottomRight=function(t,e,i){var n=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?n.set(t+1,e+1):n.set(t+1,e):1&e^this.staggerEven?n.set(t+1,e+1):n.set(t,e+1),n},e.prototype.pixelToTileCoords=function(t,e,i){var n=i||new Vector2d;this.staggerX?t-=this.staggerEven?this.tilewidth:this.sideoffsetx:e-=this.staggerEven?this.tileheight:this.sideoffsety;var r,o,s,a,h=pool.pull("Vector2d",Math.floor(t/(2*this.columnwidth)),Math.floor(e/(2*this.rowheight))),l=pool.pull("Vector2d",t-h.x*(2*this.columnwidth),e-h.y*(2*this.rowheight));this.staggerX?(h.x=2*h.x,this.staggerEven&&++h.x):(h.y=2*h.y,this.staggerEven&&++h.y),this.staggerX?(s=(r=this.sidelengthx/2)+this.columnwidth,a=this.tileheight/2,this.centers[0].set(r,a),this.centers[1].set(s,a-this.rowheight),this.centers[2].set(s,a+this.rowheight),this.centers[3].set(s+this.columnwidth,a)):(o=this.sidelengthy/2,s=this.tilewidth/2,a=o+this.rowheight,this.centers[0].set(s,o),this.centers[1].set(s-this.columnwidth,a),this.centers[2].set(s+this.columnwidth,a),this.centers[3].set(s,a+this.rowheight));for(var u=0,c=Number.MAX_VALUE,d=0;d<4;++d){var p=this.centers[d].sub(l).length2();p<c&&(c=p,u=d)}var f=this.staggerX?offsetsStaggerX:offsetsStaggerY;return n.set(h.x+f[u].x,h.y+f[u].y),pool.push(h),pool.push(l),n},e.prototype.tileToPixelCoords=function(t,e,i){var n=Math.floor(t),r=Math.floor(e),o=i||new Vector2d;return this.staggerX?(o.y=r*(this.tileheight+this.sidelengthy),this.doStaggerX(n)&&(o.y+=this.rowheight),o.x=n*this.columnwidth):(o.x=n*(this.tilewidth+this.sidelengthx),this.doStaggerY(r)&&(o.x+=this.columnwidth),o.y=r*this.rowheight),o},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,n){var r=n.tileset,o=this.tileToPixelCoords(e,i,pool.pull("Vector2d"));r.drawTile(t,r.tileoffset.x+o.x,r.tileoffset.y+o.y+(this.tileheight-r.tileheight),n),pool.push(o)},e.prototype.drawTileLayer=function(t,e,i){var n,r=this.pixelToTileCoords(i.pos.x,i.pos.y,pool.pull("Vector2d"));r.sub(e.pos);var o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y,pool.pull("Vector2d")),s=r.clone(),a=o.clone(),h=i.pos.y-o.y<this.sideoffsety,l=i.pos.x-o.x<this.sideoffsetx;h&&r.y--,l&&r.x--;var u=e.cols,c=e.rows;if(this.staggerX){r.x=Math.max(0,r.x),r.y=Math.max(0,r.y),o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y);for(var d=this.doStaggerX(r.x+e.pos.x);o.y<i.bottom&&r.y<c;){for(s.setV(r),a.setV(o);a.x<i.right&&s.x<u;s.x+=2)(n=e.cellAt(s.x,s.y,!1))&&n.tileset.drawTile(t,a.x,a.y,n),a.x+=this.tilewidth+this.sidelengthx;d?(r.x-=1,r.y+=1,o.x-=this.columnwidth,d=!1):(r.x+=1,o.x+=this.columnwidth,d=!0),o.y+=this.rowheight}pool.push(s),pool.push(a)}else{for(r.x=Math.max(0,r.x),r.y=Math.max(0,r.y),o=this.tileToPixelCoords(r.x+e.pos.x,r.y+e.pos.y),this.doStaggerY(r.y)&&(o.x-=this.columnwidth);o.y<i.bottom&&r.y<c;r.y++){for(s.setV(r),a.setV(o),this.doStaggerY(r.y)&&(a.x+=this.columnwidth);a.x<i.right&&s.x<u;s.x++)(n=e.cellAt(s.x,s.y,!1))&&n.tileset.drawTile(t,a.x,a.y,n),a.x+=this.tilewidth+this.sidelengthx;o.y+=this.rowheight}pool.push(s),pool.push(a)}pool.push(r),pool.push(o)},e}(TMXRenderer),TMXStaggeredRenderer=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"staggered"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){var n=i||new Vector2d,r=t,o=e;this.staggerX?r-=this.staggerEven?this.sideoffsetx:0:o-=this.staggerEven?this.sideoffsety:0;var s=pool.pull("Vector2d",Math.floor(r/this.tilewidth),Math.floor(o/this.tileheight));this.staggerX?(s.x=2*s.x,this.staggerEven&&++s.x):(s.y=2*s.y,this.staggerEven&&++s.y);var a=pool.pull("Vector2d",r-s.x*this.tilewidth,o-s.y*this.tileheight),h=a.x*(this.tileheight/this.tilewidth);return this.sideoffsety-h>a.y&&(s=this.topLeft(s.x,s.y,s)),-this.sideoffsety+h>a.y&&(s=this.topRight(s.x,s.y,s)),this.sideoffsety+h<a.y&&(s=this.bottomLeft(s.x,s.y,s)),3*this.sideoffsety-h<a.y&&(s=this.bottomRight(s.x,s.y,s)),(n=this.tileToPixelCoords(s.x,s.y,n)).set(t-n.x,e-n.y),n.set(n.x-this.tilewidth/2,n.y*(this.tilewidth/this.tileheight)),n.div(this.tilewidth/Math.sqrt(2)).rotate(degToRad(-45)).add(s),pool.push(s),pool.push(a),n},e}(TMXHexagonalRenderer),TMXTileset=function(t){var e=0;if(this.TileProperties=[],this.imageCollection=[],this.firstgid=this.lastgid=+t.firstgid,void 0!==t.source){var i=t.source,n=utils$1.file.getExtension(i);if(("tsx"===n||"json"===n)&&!(t=loader$1.getTMX(utils$1.file.getBasename(i))))throw new Error(i+" external TSX/JSON tileset not found")}this.name=t.name,this.tilewidth=+t.tilewidth,this.tileheight=+t.tileheight,this.spacing=+t.spacing||0,this.margin=+t.margin||0,this.tileoffset=new Vector2d,this.isAnimated=!1,this.isCollection=!1,this.animations=new Map,this._lastUpdate=0;var r=t.tiles;for(e in r)if(r.hasOwnProperty(e)){if("animation"in r[e]&&(this.isAnimated=!0,this.animations.set(r[+e].animation[0].tileid,{dt:0,idx:0,frames:r[+e].animation,cur:r[+e].animation[0]})),"properties"in r[e])if(Array.isArray(r[e].properties)){var o={};for(var s in r[e].properties)o[r[e].properties[s].name]=r[e].properties[s].value;this.setTileProperty(+r[e].id+this.firstgid,o)}else this.setTileProperty(+e+this.firstgid,r[e].properties);if("image"in r[e]){var a=loader$1.getImage(r[e].image);if(!a)throw new Error("melonJS: '"+r[e].image+"' file for tile '"+(+e+this.firstgid)+"' not found!");this.imageCollection[+e+this.firstgid]=a}}this.isCollection=this.imageCollection.length>0;var h=t.tileoffset;h&&(this.tileoffset.x=+h.x,this.tileoffset.y=+h.y);var l=t.tileproperties;if(l)for(e in l)l.hasOwnProperty(e)&&this.setTileProperty(+e+this.firstgid,l[e]);if(!1===this.isCollection){if(this.image=loader$1.getImage(t.image),!this.image)throw new Error("melonJS: '"+t.image+"' file for tileset '"+this.name+"' not found!");this.texture=video$1.renderer.cache.get(this.image,{framewidth:this.tilewidth,frameheight:this.tileheight,margin:this.margin,spacing:this.spacing}),this.atlas=this.texture.getAtlas();var u=+t.columns||Math.round(this.image.width/(this.tilewidth+this.spacing)),c=Math.round(this.image.height/(this.tileheight+this.spacing));t.tilecount%u>0&&++c,this.lastgid=this.firstgid+(u*c-1||0),t.tilecount&&this.lastgid-this.firstgid+1!=+t.tilecount&&console.warn("Computed tilecount ("+(this.lastgid-this.firstgid+1)+") does not match expected tilecount ("+t.tilecount+")")}};TMXTileset.prototype.getTileImage=function(t){return this.imageCollection[t]},TMXTileset.prototype.setTileProperty=function(t,e){this.TileProperties[t]=e},TMXTileset.prototype.contains=function(t){return t>=this.firstgid&&t<=this.lastgid},TMXTileset.prototype.getViewTileId=function(t){var e=t-this.firstgid;return this.animations.has(e)?this.animations.get(e).cur.tileid:e},TMXTileset.prototype.getTileProperties=function(t){return this.TileProperties[t]},TMXTileset.prototype.update=function(t){var e=0,i=timer$1.getTime(),n=!1;return this._lastUpdate!==i&&(this._lastUpdate=i,this.animations.forEach((function(i){for(i.dt+=t,e=i.cur.duration;i.dt>=e;)i.dt-=e,i.idx=(i.idx+1)%i.frames.length,i.cur=i.frames[i.idx],e=i.cur.duration,n=!0}))),n},TMXTileset.prototype.drawTile=function(t,e,i,n){if(n.flipped&&(t.save(),t.translate(e,i),t.transform(n.currentTransform),e=i=0),!0===this.isCollection)t.drawImage(this.imageCollection[n.tileId],0,0,n.width,n.height,e,i,n.width,n.height);else{var r=this.atlas[this.getViewTileId(n.tileId)].offset;t.drawImage(this.image,r.x,r.y,this.tilewidth,this.tileheight,e,i,this.tilewidth+t.uvOffset,this.tileheight+t.uvOffset)}n.flipped&&t.restore()};var TMX_CLEAR_BIT_MASK=536870911,TMXTilesetGroup=function(){this.tilesets=[],this.length=0};TMXTilesetGroup.prototype.add=function(t){this.tilesets.push(t),this.length++},TMXTilesetGroup.prototype.getTilesetByIndex=function(t){return this.tilesets[t]},TMXTilesetGroup.prototype.getTilesetByGid=function(t){var e=-1;t&=TMX_CLEAR_BIT_MASK;for(var i=0,n=this.tilesets.length;i<n;i++){if(this.tilesets[i].contains(t))return this.tilesets[i];this.tilesets[i].firstgid===this.tilesets[i].lastgid&&t>=this.tilesets[i].firstgid&&(e=i)}if(-1!==e)return this.tilesets[e];throw new Error("no matching tileset found for gid "+t)};var TMXObject=function(t,e,i){this.points=void 0,this.name=e.name,this.x=+e.x,this.y=+e.y,this.z=+i,this.width=+e.width||0,this.height=+e.height||0,this.gid=+e.gid||null,this.tintcolor=e.tintcolor,this.type=e.type,this.type=e.type,this.rotation=degToRad(+e.rotation||0),this.id=+e.id||void 0,this.orientation=t.orientation,this.shapes=void 0,this.isEllipse=!1,this.isPolygon=!1,this.isPolyLine=!1,"number"==typeof this.gid?this.setTile(t.tilesets):void 0!==e.ellipse?this.isEllipse=!0:void 0!==e.polygon?(this.points=e.polygon,this.isPolygon=!0):void 0!==e.polyline&&(this.points=e.polyline,this.isPolyLine=!0),void 0!==e.text?(this.text=e.text,this.text.font=e.text.fontfamily||"sans-serif",this.text.size=e.text.pixelsize||16,this.text.fillStyle=e.text.color||"#000000",this.text.textAlign=e.text.halign||"left",this.text.textBaseline=e.text.valign||"top",this.text.width=this.width,this.text.height=this.height,applyTMXProperties(this.text,e)):(applyTMXProperties(this,e),this.shapes||(this.shapes=this.parseTMXShapes())),t.isEditor||t.getRenderer().adjustPosition(this)};TMXObject.prototype.setTile=function(t){var e=t.getTilesetByGid(this.gid);!1===e.isCollection&&(this.width=this.framewidth=e.tilewidth,this.height=this.frameheight=e.tileheight),this.tile=new Tile(this.x,this.y,this.gid,e)},TMXObject.prototype.parseTMXShapes=function(){var t=0,e=[];if(!0===this.isEllipse)e.push(new Ellipse(this.width/2,this.height/2,this.width,this.height).rotate(this.rotation));else if(!0===this.isPolygon)e.push(new Polygon(0,0,this.points).rotate(this.rotation));else if(!0===this.isPolyLine){var i,n,r=this.points,o=r.length-1;for(t=0;t<o;t++)i=new Vector2d(r[t].x,r[t].y),n=new Vector2d(r[t+1].x,r[t+1].y),0!==this.rotation&&(i=i.rotate(this.rotation),n=n.rotate(this.rotation)),e.push(new Line(0,0,[i,n]))}else e.push(new Polygon(0,0,[new Vector2d,new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)]).rotate(this.rotation));if("isometric"===this.orientation)for(t=0;t<e.length;t++)e[t].toIso();return e},TMXObject.prototype.getObjectPropertyByName=function(t){return this[t]};var TMXGroup=function(t,e,i){this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.tintcolor=e.tintcolor,this.z=i,this.objects=[];var n=void 0===e.visible||e.visible;this.opacity=!0===n?clamp(+e.opacity||1,0,1):0,applyTMXProperties(this,e);var r=this;e.objects&&e.objects.forEach((function(e){e.tintcolor=r.tintcolor,r.objects.push(new TMXObject(t,e,i))}));e.layers&&e.layers.forEach((function(e){var n=new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i++);n.setRenderer(t.getRenderer()),r.width=Math.max(r.width,n.width),r.height=Math.max(r.height,n.height),r.objects.push(n)}))};TMXGroup.prototype.destroy=function(){this.objects=null},TMXGroup.prototype.getObjectCount=function(){return this.objects.length},TMXGroup.prototype.getObjectByIndex=function(t){return this.objects[t]};var COLLISION_GROUP="collision",onresize_handler=null;function getNewDefaultRenderer(t){switch(t.orientation){case"orthogonal":return new TMXOrthogonalRenderer(t);case"isometric":return new TMXIsometricRenderer(t);case"hexagonal":return new TMXHexagonalRenderer(t);case"staggered":return new TMXStaggeredRenderer(t);default:throw new Error(t.orientation+" type TMX Tile Map not supported!")}}function readLayer(t,e,i){return new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i)}function readImageLayer(t,e,i){applyTMXProperties(e.properties,e);var n=pool.pull("ImageLayer",+e.offsetx||+e.x||0,+e.offsety||+e.y||0,Object.assign({name:e.name,image:e.image,z:i},e.properties)),r=void 0===e.visible||e.visible;return n.setOpacity(r?+e.opacity:0),n}function readTileset(t){return new TMXTileset(t)}function readObjectGroup(t,e,i){return new TMXGroup(t,e,i)}var TMXTileMap=function(t,e){if(this.data=e,this.name=t,this.cols=+e.width,this.rows=+e.height,this.tilewidth=+e.tilewidth,this.tileheight=+e.tileheight,this.infinite=+e.infinite,this.orientation=e.orientation,this.renderorder=e.renderorder||"right-down",this.version=e.version,this.tiledversion=e.tiledversion,this.tilesets=null,void 0===this.layers&&(this.layers=[]),void 0===this.objectGroups&&(this.objectGroups=[]),this.isEditor="melon-editor"===e.editor,this.nextobjectid=+e.nextobjectid||void 0,this.hexsidelength=+e.hexsidelength,this.staggeraxis=e.staggeraxis,this.staggerindex=e.staggerindex,this.bounds=this.getRenderer().getBounds().clone(),this.width=this.bounds.width,this.height=this.bounds.height,this.backgroundcolor=e.backgroundcolor,applyTMXProperties(this,e),this.initialized=!1,1===this.infinite)throw new Error("Tiled Infinite Map not supported!")};TMXTileMap.prototype.getRenderer=function(){return void 0!==this.renderer&&this.renderer.canRender(this)||(this.renderer=getNewDefaultRenderer(this)),this.renderer},TMXTileMap.prototype.getBounds=function(){return this.bounds},TMXTileMap.prototype.readMapObjects=function(t){if(!0!==this.initialized){var e=0,i=this;if(this.tilesets||(this.tilesets=new TMXTilesetGroup),void 0!==t.tilesets)t.tilesets.forEach((function(t){i.tilesets.add(readTileset(t))}));this.backgroundcolor&&this.layers.push(pool.pull("ColorLayer","background_color",this.backgroundcolor,e++)),this.background_image&&this.layers.push(pool.pull("ImageLayer",0,0,{name:"background_image",image:this.background_image,z:e++})),t.layers.forEach((function(t){switch(t.type){case"imagelayer":i.layers.push(readImageLayer(i,t,e++));break;case"tilelayer":i.layers.push(readLayer(i,t,e++));break;case"objectgroup":case"group":i.objectGroups.push(readObjectGroup(i,t,e++))}})),this.initialized=!0}},TMXTileMap.prototype.addTo=function(t,e,i){var n=t.autoSort,r=t.autoDepth,o=this.getBounds();function s(e,i){game$1.viewport.setBounds(0,0,Math.max(o.width,e),Math.max(o.height,i)),t.pos.set(Math.max(0,~~((e-o.width)/2)),Math.max(0,~~((i-o.height)/2)),t.pos.z)}t.autoSort=!1,t.autoDepth=!1,this.getLayers().forEach((function(e){t.addChild(e)})),this.getObjects(e).forEach((function(e){t.addChild(e)})),t.resize(this.bounds.width,this.bounds.height),t.sort(!0),!0===i&&(s(game$1.viewport.width,game$1.viewport.height),onresize_handler&&event.unsubscribe(onresize_handler),onresize_handler=event.subscribe(event.VIEWPORT_ONRESIZE,s)),t.autoSort=n,t.autoDepth=r},TMXTileMap.prototype.getObjects=function(t){var e,i=[],n=!1;this.readMapObjects(this.data);for(var r=0;r<this.objectGroups.length;r++){var o=this.objectGroups[r];n=o.name.toLowerCase().includes(COLLISION_GROUP),!1===t&&((e=new Container$1(0,0,this.width,this.height)).anchorPoint.set(0,0),e.name=o.name,e.pos.z=o.z,e.setOpacity(o.opacity),e.autoSort=!1,e.autoDepth=!1);for(var s=0;s<o.objects.length;s++){var a,h=o.objects[s];void 0===h.anchorPoint&&(h.anchorPoint={x:0,y:0}),void 0!==h.tintcolor&&(h.tint=pool.pull("Color"),h.tint.parseHex(h.tintcolor,!0)),h instanceof TMXLayer?a=h:"object"==typeof h.text?(void 0===h.text.anchorPoint&&(h.text.anchorPoint=h.anchorPoint),(a=!0===h.text.bitmap?pool.pull("BitmapText",h.x,h.y,h.text):pool.pull("Text",h.x,h.y,h.text)).pos.z=h.z):"object"==typeof h.tile?((a=h.tile.getRenderable(h)).body=new Body(a,h.shapes||new Rect(0,0,this.width,this.height)),a.pos.setMuted(h.x,h.y,h.z)):(void 0!==h.name&&""!==h.name?a=pool.pull(h.name,h.x,h.y,h):((a=pool.pull("Renderable",h.x,h.y,h.width,h.height)).anchorPoint.set(0,0),a.name=h.name,a.type=h.type,a.id=h.id,a.body=new Body(a,h.shapes||new Rect(0,0,a.width,a.height)),a.resize(a.body.getBounds().width,a.body.getBounds().height)),a.pos.z=h.z),n&&!h.name&&a.body&&(a.body.collisionType=collision.types.WORLD_SHAPE),!1!==t?(!0===a.isRenderable&&(a.setOpacity(a.getOpacity()*o.opacity),a.renderable instanceof Renderable&&a.renderable.setOpacity(a.renderable.getOpacity()*o.opacity)),i.push(a)):e.addChild(a)}!1===t&&e.children.length>0&&(e.autoSort=!0,e.autoDepth=!0,i.push(e))}return i},TMXTileMap.prototype.getLayers=function(){return this.readMapObjects(this.data),this.layers},TMXTileMap.prototype.destroy=function(){this.tilesets=void 0,this.layers.length=0,this.objectGroups.length=0,this.initialized=!1};var levels={},levelIdx=[],currentLevelIdx=0;function safeLoadLevel(t,e,i){e.container.reset(),game$1.reset(),levels[level.getCurrentLevelId()]&&levels[level.getCurrentLevelId()].destroy(),currentLevelIdx=levelIdx.indexOf(t),loadTMXLevel(t,e.container,e.flatten,e.setViewportBounds),event.publish(event.LEVEL_LOADED,[t]),e.onLoaded(t),i&&state$1.restart()}function loadTMXLevel(t,e,i,n){var r=levels[t];utils$1.resetGUID(t,r.nextobjectid),e.anchorPoint.set(0,0),r.addTo(e,i,n)}var level={add:function(t,e,i){if("tmx"===t)return null==levels[e]&&(levels[e]=new TMXTileMap(e,loader$1.getTMX(e)),levelIdx.push(e),i&&i(),!0);throw new Error("no level loader defined for format "+t)},load:function(t,e){if(e=Object.assign({container:game$1.world,onLoaded:game$1.onLevelLoaded,flatten:game$1.mergeGroup,setViewportBounds:!0},e||{}),void 0===levels[t])throw new Error("level "+t+" not found");if(!(levels[t]instanceof TMXTileMap))throw new Error("no level loader defined");return state$1.isRunning()?(state$1.stop(),utils$1.function.defer(safeLoadLevel,this,t,e,!0)):safeLoadLevel(t,e),!0},getCurrentLevelId:function(){return levelIdx[currentLevelIdx]},getCurrentLevel:function(){return levels[this.getCurrentLevelId()]},reload:function(t){return this.load(this.getCurrentLevelId(),t)},next:function(t){return currentLevelIdx+1<levelIdx.length&&this.load(levelIdx[currentLevelIdx+1],t)},previous:function(t){return currentLevelIdx-1>=0&&this.load(levelIdx[currentLevelIdx-1],t)},levelCount:function(){return levelIdx.length}},imgList={},tmxList={},binList={},jsonList={},baseURL={},resourceCount=0,loadCount=0,timerId$1=0;function checkLoadStatus(t){if(loadCount===resourceCount){if(!t&&!loader.onload)throw new Error("no load callback defined");clearTimeout(timerId$1);var e=t||loader.onload;setTimeout((function(){e(),event.publish(event.LOADER_COMPLETE)}),300)}else timerId$1=setTimeout((function(){checkLoadStatus(t)}),100)}function preloadImage(t,e,i){imgList[t.name]=new Image,imgList[t.name].onload=e,imgList[t.name].onerror=i,"string"==typeof loader.crossOrigin&&(imgList[t.name].crossOrigin=loader.crossOrigin),imgList[t.name].src=t.src+loader.nocache}function preloadFontFace(t,e,i){var n=new FontFace(t.name,t.src);n.load().then((function(){document.fonts.add(n),document.body.style.fontFamily=t.name,e()}),(function(e){i(t.name)}))}function preloadTMX(t,e,i){function n(e){tmxList[t.name]=e,"tmx"===t.type&&level.add(t.type,t.name)}if(t.data)return n(t.data),void e();var r=new XMLHttpRequest,o=utils$1.file.getExtension(t.src);r.overrideMimeType&&("json"===o?r.overrideMimeType("application/json"):r.overrideMimeType("text/xml")),r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.ontimeout=i,r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status||0===r.status&&r.responseText){var s=null;switch(o){case"xml":case"tmx":case"tsx":if(device$1.ua.match(/msie/i)||!r.responseXML){if(!window.DOMParser)throw new Error("XML file format loading not supported, use the JSON file format instead");s=(new DOMParser).parseFromString(r.responseText,"text/xml")}else s=r.responseXML;var a=parse(s);switch(o){case"tmx":s=a.map;break;case"tsx":s=a.tilesets[0]}break;case"json":s=JSON.parse(r.responseText);break;default:throw new Error("TMX file format "+o+"not supported !")}n(s),e()}else i(t.name)},r.send()}function preloadJSON(t,e,i){var n=new XMLHttpRequest;n.overrideMimeType&&n.overrideMimeType("application/json"),n.open("GET",t.src+loader.nocache,!0),n.withCredentials=loader.withCredentials,n.ontimeout=i,n.onreadystatechange=function(){4===n.readyState&&(200===n.status||0===n.status&&n.responseText?(jsonList[t.name]=JSON.parse(n.responseText),e()):i(t.name))},n.send()}function preloadBinary(t,e,i){var n=new XMLHttpRequest;n.open("GET",t.src+loader.nocache,!0),n.withCredentials=loader.withCredentials,n.responseType="arraybuffer",n.onerror=i,n.onload=function(){var i=n.response;if(i){for(var r=new Uint8Array(i),o=[],s=0;s<r.byteLength;s++)o[s]=String.fromCharCode(r[s]);binList[t.name]=o.join(""),e()}},n.send()}function preloadJavascript(t,e,i){var n=document.createElement("script");n.src=t.src,n.type="text/javascript","string"==typeof loader.crossOrigin&&(n.crossOrigin=loader.crossOrigin),n.defer=!0,n.onload=function(){e()},n.onerror=function(){i(t.name)},document.getElementsByTagName("body")[0].appendChild(n)}var loader={nocache:"",onload:void 0,onProgress:void 0,crossOrigin:void 0,withCredentials:!1,onResourceLoaded:function(t){var e=++loadCount/resourceCount;this.onProgress&&this.onProgress(e,t),event.publish(event.LOADER_PROGRESS,[e,t])},onLoadingError:function(t){throw new Error("Failed loading resource "+t.src)},setNocache:function(t){this.nocache=t?"?"+~~(1e7*Math.random()):""},setBaseURL:function(t,e){"*"!==t?baseURL[t]=e:(baseURL.audio=e,baseURL.binary=e,baseURL.image=e,baseURL.json=e,baseURL.js=e,baseURL.tmx=e,baseURL.tsx=e)},preload:function(t,e,i){for(var n=0;n<t.length;n++)resourceCount+=this.load(t[n],this.onResourceLoaded.bind(this,t[n]),this.onLoadingError.bind(this,t[n]));void 0!==e&&(this.onload=e),!1!==i&&state$1.change(state$1.LOADING),checkLoadStatus(e)},load:function(t,e,i){switch(void 0!==baseURL[t.type]&&(t.src=baseURL[t.type]+t.src),t.type){case"binary":return preloadBinary.call(this,t,e,i),1;case"image":return preloadImage.call(this,t,e,i),1;case"json":return preloadJSON.call(this,t,e,i),1;case"js":return preloadJavascript.call(this,t,e,i),1;case"tmx":case"tsx":return preloadTMX.call(this,t,e,i),1;case"audio":return audio$1.load(t,!!t.stream,e,i),1;case"fontface":return preloadFontFace.call(this,t,e,i),1;default:throw new Error("load : unknown or invalid resource type : "+t.type)}},unload:function(t){switch(t.type){case"binary":return t.name in binList&&(delete binList[t.name],!0);case"image":return t.name in imgList&&(delete imgList[t.name],!0);case"json":return t.name in jsonList&&(delete jsonList[t.name],!0);case"js":case"fontface":return!0;case"tmx":case"tsx":return t.name in tmxList&&(delete tmxList[t.name],!0);case"audio":return audio$1.unload(t.name);default:throw new Error("unload : unknown or invalid resource type : "+t.type)}},unloadAll:function(){var t;for(t in binList)binList.hasOwnProperty(t)&&this.unload({name:t,type:"binary"});for(t in imgList)imgList.hasOwnProperty(t)&&this.unload({name:t,type:"image"});for(t in tmxList)tmxList.hasOwnProperty(t)&&this.unload({name:t,type:"tmx"});for(t in jsonList)jsonList.hasOwnProperty(t)&&this.unload({name:t,type:"json"});audio$1.unloadAll()},getTMX:function(t){return(t=""+t)in tmxList?tmxList[t]:null},getBinary:function(t){return(t=""+t)in binList?binList[t]:null},getImage:function(t){return(t=utils$1.file.getBasename(""+t))in imgList?imgList[t]:null},getJSON:function(t){return(t=""+t)in jsonList?jsonList[t]:null},getLoadProgress:function(){return loadCount/resourceCount}},loader$1=loader,audioTracks={},current_track_id=null,retry_counter=0,soundLoadError=function(t,e){if(retry_counter++>3){var i="melonJS: failed loading "+t;if(!1!==audio.stopOnAudioError)throw new Error(i);audio.disable(),e&&e(),console.log(i+", disabling audio")}else audioTracks[t].load()},audio={stopOnAudioError:!0,init:function(t){if(!exports.initialized)throw new Error("me.audio.init() called before engine initialization.");return t="string"==typeof t?t:"mp3",this.audioFormats=t.split(","),!howler.Howler.noAudio},hasFormat:function(t){return this.hasAudio&&howler.Howler.codecs(t)},hasAudio:function(){return!howler.Howler.noAudio},enable:function(){this.unmuteAll()},disable:function(){this.muteAll()},load:function(t,e,i,n){var r=[];if(void 0===this.audioFormats||0===this.audioFormats.length)throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");for(var o=0;o<this.audioFormats.length;o++)r.push(t.src+t.name+"."+this.audioFormats[o]+loader$1.nocache);return audioTracks[t.name]=new howler.Howl({src:r,volume:howler.Howler.volume(),html5:!0===e,xhrWithCredentials:loader$1.withCredentials,onloaderror:function(){soundLoadError.call(this,t.name,n)},onload:function(){retry_counter=0,i&&i()}}),1},play:function(t,e,i,n){void 0===e&&(e=!1);var r=audioTracks[t];if(r&&void 0!==r){var o=r.play();return"boolean"==typeof e&&r.loop(e,o),r.volume("number"==typeof n?clamp(n,0,1):howler.Howler.volume(),o),"function"==typeof i&&(!0===e?r.on("end",i,o):r.once("end",i,o)),o}throw new Error("audio clip "+t+" does not exist")},fade:function(t,e,i,n,r){var o=audioTracks[t];if(!o||void 0===o)throw new Error("audio clip "+t+" does not exist");o.fade(e,i,n,r)},seek:function(t,e,i){var n=audioTracks[t];if(n&&void 0!==n)return n.seek.apply(n,Array.prototype.slice.call(arguments,1));throw new Error("audio clip "+t+" does not exist")},rate:function(t,e,i){var n=audioTracks[t];if(n&&void 0!==n)return n.rate.apply(n,Array.prototype.slice.call(arguments,1));throw new Error("audio clip "+t+" does not exist")},stop:function(t,e){if(void 0!==t){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.stop(e),i.off("end",void 0,e)}else howler.Howler.stop()},pause:function(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.pause(e)},resume:function(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.play(e)},playTrack:function(t,e){return current_track_id=t,this.play(current_track_id,!0,null,e)},stopTrack:function(){null!==current_track_id&&(audioTracks[current_track_id].stop(),current_track_id=null)},pauseTrack:function(){null!==current_track_id&&audioTracks[current_track_id].pause()},resumeTrack:function(){null!==current_track_id&&audioTracks[current_track_id].play()},getCurrentTrack:function(){return current_track_id},setVolume:function(t){howler.Howler.volume(t)},getVolume:function(){return howler.Howler.volume()},mute:function(t,e,i){i=void 0===i||!!i;var n=audioTracks[t];if(!n||void 0===n)throw new Error("audio clip "+t+" does not exist");n.mute(i,e)},unmute:function(t,e){this.mute(t,e,!1)},muteAll:function(){howler.Howler.mute(!0)},unmuteAll:function(){howler.Howler.mute(!1)},muted:function(){return howler.Howler._muted},unload:function(t){return t in audioTracks&&(audioTracks[t].unload(),delete audioTracks[t],!0)},unloadAll:function(){for(var t in audioTracks)audioTracks.hasOwnProperty(t)&&this.unload(t)}},audio$1=audio,data={};function isReserved(t){return"add"===t||"remove"===t}var save={init:function(){if(!0===device$1.localStorage){var t=localStorage.getItem("me.save");if("string"==typeof t&&t.length>0)(JSON.parse(t)||[]).forEach((function(t){data[t]=JSON.parse(localStorage.getItem("me.save."+t))}))}},add:function(t){var e=save;Object.keys(t).forEach((function(i){var n;isReserved(i)||(n=i,Object.defineProperty(e,n,{configurable:!0,enumerable:!0,get:function(){return data[n]},set:function(t){data[n]=t,!0===device$1.localStorage&&localStorage.setItem("me.save."+n,JSON.stringify(t))}}),i in data||(e[i]=t[i]))})),!0===device$1.localStorage&&localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))},remove:function(t){isReserved(t)||void 0!==data[t]&&(delete data[t],!0===device$1.localStorage&&(localStorage.removeItem("me.save."+t),localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))))}},accelInitialized=!1,deviceOrientationInitialized=!1,swipeEnabled=!0;function disableSwipeFn(t){return t.preventDefault(),"function"==typeof window.scroll&&window.scroll(0,0),!1}var readyBound=!1,isReady=!1,readyList=[],_domRect={left:0,top:0,x:0,y:0,width:0,height:0,right:0,bottom:0},device={_domReady:function(t){if(!isReady){if(!document.body)return setTimeout(this._domReady,13);for(document.removeEventListener&&document.removeEventListener("DOMContentLoaded",this._domReady,!1),window.removeEventListener("load",this._domReady,!1);readyList.length;)readyList.shift().call(window,[]);isReady=!0}},_check:function(){this._detectDevice(),this.isMobile&&this.enableSwipe(!1),this.TouchEvent=!!("ontouchstart"in window),this.PointerEvent=!!window.PointerEvent,window.gesture=prefixed("gesture"),this.touch=this.TouchEvent||this.PointerEvent,this.maxTouchPoints=this.touch?this.PointerEvent?navigator.maxTouchPoints||1:10:1,this.wheel="onwheel"in document.createElement("div"),this.hasPointerLockSupport=prefixed("pointerLockElement",document),this.hasPointerLockSupport&&(document.exitPointerLock=prefixed("exitPointerLock",document)),this.hasDeviceOrientation=!!window.DeviceOrientationEvent,this.hasAccelerometer=!!window.DeviceMotionEvent,this.hasFullscreenSupport=prefixed("fullscreenEnabled",document)||document.mozFullScreenEnabled,document.exitFullscreen=prefixed("cancelFullScreen",document)||prefixed("exitFullscreen",document),navigator.vibrate=prefixed("vibrate",navigator),this.hasWebAudio=!(!window.AudioContext&&!window.webkitAudioContext);try{this.localStorage=!!window.localStorage}catch(t){this.localStorage=!1}try{this.OffscreenCanvas=void 0!==window.OffscreenCanvas&&null!==new OffscreenCanvas(0,0).getContext("2d")}catch(t){this.OffscreenCanvas=!1}var t,e;window.addEventListener("blur",(function(){this.stopOnBlur&&state$1.stop(!0),this.pauseOnBlur&&state$1.pause(!0)}),!1),window.addEventListener("focus",(function(){this.stopOnBlur&&state$1.restart(!0),this.resumeOnFocus&&state$1.resume(!0),this.autoFocus&&this.focus()}),!1),void 0!==document.hidden?(t="hidden",e="visibilitychange"):void 0!==document.mozHidden?(t="mozHidden",e="mozvisibilitychange"):void 0!==document.msHidden?(t="msHidden",e="msvisibilitychange"):void 0!==document.webkitHidden&&(t="webkitHidden",e="webkitvisibilitychange"),"string"==typeof e&&document.addEventListener(e,(function(){document[t]?(this.stopOnBlur&&state$1.stop(!0),this.pauseOnBlur&&state$1.pause(!0)):(this.stopOnBlur&&state$1.restart(!0),this.resumeOnFocus&&state$1.resume(!0))}),!1)},_detectDevice:function(){this.iOS=/iPhone|iPad|iPod/i.test(this.ua),this.android=/Android/i.test(this.ua),this.android2=/Android 2/i.test(this.ua),this.linux=/Linux/i.test(this.ua),this.chromeOS=/CrOS/.test(this.ua),this.wp=/Windows Phone/i.test(this.ua),this.BlackBerry=/BlackBerry/i.test(this.ua),this.Kindle=/Kindle|Silk.*Mobile Safari/i.test(this.ua),this.isMobile=/Mobi/i.test(this.ua)||this.iOS||this.android||this.wp||this.BlackBerry||this.Kindle||!1,this.ejecta=void 0!==window.ejecta,this.isWeixin=/MicroMessenger/i.test(this.ua)},ua:navigator.userAgent,localStorage:!1,hasAccelerometer:!1,hasDeviceOrientation:!1,hasFullscreenSupport:!1,hasPointerLockSupport:!1,hasWebAudio:!1,nativeBase64:"function"==typeof window.atob,maxTouchPoints:1,touch:!1,wheel:!1,isMobile:!1,iOS:!1,android:!1,android2:!1,linux:!1,ejecta:!1,isWeixin:!1,chromeOS:!1,wp:!1,BlackBerry:!1,Kindle:!1,accelerationX:0,accelerationY:0,accelerationZ:0,gamma:0,beta:0,alpha:0,language:navigator.language||navigator.browserLanguage||navigator.userLanguage||"en",pauseOnBlur:!0,resumeOnFocus:!0,autoFocus:!0,stopOnBlur:!1,OffscreenCanvas:!1,onReady:function(t){isReady?t.call(window,[]):(readyList.push(t),readyBound||("complete"===document.readyState?window.setTimeout(this._domReady,0):(document.addEventListener&&document.addEventListener("DOMContentLoaded",this._domReady,!1),window.addEventListener("load",this._domReady,!1)),readyBound=!0))},enableSwipe:function(t){!1!==t?!1===swipeEnabled&&(window.document.removeEventListener("touchmove",disableSwipeFn,!1),swipeEnabled=!0):!0===swipeEnabled&&(window.document.addEventListener("touchmove",disableSwipeFn,!1),swipeEnabled=!1)},requestFullscreen:function(t){this.hasFullscreenSupport&&((t=t||video$1.getParent()).requestFullscreen=prefixed("requestFullscreen",t)||t.mozRequestFullScreen,t.requestFullscreen())},exitFullscreen:function(){this.hasFullscreenSupport&&document.exitFullscreen()},getScreenOrientation:function(){var t="portrait",e="landscape",i=window.screen;if(void 0!==i){var n=prefixed("orientation",i);if(void 0!==n&&"string"==typeof n.type)return n.type;if("string"==typeof n)return n}return"number"==typeof window.orientation?90===Math.abs(window.orientation)?e:t:window.outerWidth>window.outerHeight?e:t},lockOrientation:function(t){var e=window.screen;if(void 0!==e){var i=prefixed("lockOrientation",e);if(void 0!==i)return i(t)}return!1},unlockOrientation:function(t){var e=window.screen;if(void 0!==e){var i=prefixed("unlockOrientation",e);if(void 0!==i)return i(t)}return!1},isPortrait:function(){return this.getScreenOrientation().includes("portrait")},isLandscape:function(){return this.getScreenOrientation().includes("landscape")},getStorage:function(t){if(void 0===t&&(t="local"),"local"===t)return save;throw new Error("storage type "+t+" not supported")},getParentElement:function(t){var e=this.getElement(t);return null!==e.parentNode&&(e=e.parentNode),e},getElement:function(t){var e=null;return"undefined"!==t&&("string"==typeof t?e=document.getElementById(t):"object"==typeof t&&t.nodeType===Node.ELEMENT_NODE&&(e=t)),e||(e=document.body),e},getElementBounds:function(t){return"object"==typeof t&&t!==document.body&&void 0!==t.getBoundingClientRect?t.getBoundingClientRect():(_domRect.width=_domRect.right=window.innerWidth,_domRect.height=_domRect.bottom=window.innerHeight,_domRect)},getParentBounds:function(t){return this.getElementBounds(this.getParentElement(t))},isWebGLSupported:function(t){var e=!1;try{var i=document.createElement("canvas"),n={stencil:!0,failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat};e=!(!window.WebGLRenderingContext||!i.getContext("webgl",n)&&!i.getContext("experimental-webgl",n))}catch(t){e=!1}return e},getMaxShaderPrecision:function(t){return t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0?"highp":t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"},focus:function(){"function"==typeof window.focus&&window.focus()},onDeviceMotion:function(t){this.accelerationX=t.accelerationIncludingGravity.x,this.accelerationY=t.accelerationIncludingGravity.y,this.accelerationZ=t.accelerationIncludingGravity.z},onDeviceRotate:function(t){this.gamma=t.gamma,this.beta=t.beta,this.alpha=t.alpha},turnOnPointerLock:function(){if(this.hasPointerLockSupport){var t=video$1.getParent();if(this.ua.match(/Firefox/i)){var e=function(){(prefixed("fullscreenElement",document)||document.mozFullScreenElement)===t&&(document.removeEventListener("fullscreenchange",e),document.removeEventListener("mozfullscreenchange",e),t.requestPointerLock=prefixed("requestPointerLock",t),t.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),this.requestFullscreen()}else t.requestPointerLock()}},turnOffPointerLock:function(){this.hasPointerLockSupport&&document.exitPointerLock()},watchAccelerometer:function(){var t=this;return this.hasAccelerometer&&!accelInitialized&&(DeviceOrientationEvent&&"function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(window.addEventListener("devicemotion",t.onDeviceMotion,!1),accelInitialized=!0)})).catch(console.error):(window.addEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!0)),accelInitialized},unwatchAccelerometer:function(){accelInitialized&&(window.removeEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!1)},watchDeviceOrientation:function(){var t=this;return this.hasDeviceOrientation&&!deviceOrientationInitialized&&("function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(window.addEventListener("deviceorientation",t.onDeviceRotate,!1),deviceOrientationInitialized=!0)})).catch(console.error):(window.addEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!0)),deviceOrientationInitialized},unwatchDeviceOrientation:function(){deviceOrientationInitialized&&(window.removeEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!1)},vibrate:function(t){navigator.vibrate&&navigator.vibrate(t)}};Object.defineProperty(device,"devicePixelRatio",{get:function(){return window.devicePixelRatio||1}}),Object.defineProperty(device,"isFullscreen",{get:function(){return!!this.hasFullscreenSupport&&!(!prefixed("fullscreenElement",document)&&!document.mozFullScreenElement)}}),Object.defineProperty(device,"sound",{get:function(){return audio$1.hasAudio()}});var device$1=device;function extractUniforms(t,e){var i,n={},r=/uniform\s+(\w+)\s+(\w+)/g,o={},s={},a={};return[e.vertex,e.fragment].forEach((function(t){for(;i=r.exec(t);)o[i[2]]=i[1]})),Object.keys(o).forEach((function(i){var n=o[i];a[i]=t.getUniformLocation(e.program,i),s[i]={get:function(t){return function(){return a[t]}}(i),set:function(e,i,n){return 0===i.indexOf("mat")?function(i){t[n](a[e],!1,i)}:function(i){var r=n;i.length&&"v"!==n.substr(-1)&&(r+="v"),t[r](a[e],i)}}(i,n,"uniform"+fnHash[n])}})),Object.defineProperties(n,s),n}function extractAttributes(t,e){for(var i,n={},r=/attribute\s+\w+\s+(\w+)/g,o=0;i=r.exec(e.vertex);)n[i[1]]=o++;return n}function compileShader(t,e,i){var n=t.createShader(e);if(t.shaderSource(n,i),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n));return n}function compileProgram(t,e,i,n){var r=compileShader(t,t.VERTEX_SHADER,e),o=compileShader(t,t.FRAGMENT_SHADER,i),s=t.createProgram();for(var a in t.attachShader(s,r),t.attachShader(s,o),n)t.bindAttribLocation(s,n[a],a);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var h="Error initializing Shader "+this+"\ngl.VALIDATE_STATUS: "+t.getProgramParameter(s,t.VALIDATE_STATUS)+"\ngl.getError()"+t.getError()+"\ngl.getProgramInfoLog()"+t.getProgramInfoLog(s);throw t.deleteProgram(s),s=null,new Error(h)}return t.useProgram(s),t.deleteShader(r),t.deleteShader(o),s}var fnHash={bool:"1i",int:"1i",float:"1f",vec2:"2fv",vec3:"3fv",vec4:"4fv",bvec2:"2iv",bvec3:"3iv",bvec4:"4iv",ivec2:"2iv",ivec3:"3iv",ivec4:"4iv",mat2:"Matrix2fv",mat3:"Matrix3fv",mat4:"Matrix4fv",sampler2D:"1i"};function setPrecision(t,e){return"precision"!==t.substring(0,9)?"precision "+e+" float;"+t:t}function minify(t){return t=(t=(t=(t=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1")).replace(/(\\n\s+)|(\s+\\n)/g,"")).replace(/(\\r|\\n)+/g,"")).replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g,"$1")}var GLShader=function(t,e,i,n){return this.gl=t,this.vertex=setPrecision(minify(e),n||device$1.getMaxShaderPrecision(this.gl)),this.fragment=setPrecision(minify(i),n||device$1.getMaxShaderPrecision(this.gl)),this.attributes=extractAttributes(this.gl,this),this.program=compileProgram(this.gl,this.vertex,this.fragment,this.attributes),this.uniforms=extractUniforms(this.gl,this),event.subscribe(event.WEBGL_ONCONTEXT_LOST,this.destroy.bind(this)),this};GLShader.prototype.bind=function(){this.gl.useProgram(this.program)},GLShader.prototype.getAttribLocation=function(t){var e=this.attributes[t];return void 0!==e?e:-1},GLShader.prototype.setUniform=function(t,e){var i=this.uniforms;if(void 0===i[t])throw new Error("undefined ("+t+") uniform for shader "+this);"object"==typeof e&&"function"==typeof e.toArray?i[t]=e.toArray():i[t]=e},GLShader.prototype.destroy=function(){this.uniforms=null,this.attributes=null,this.gl.deleteProgram(this.program),this.vertex=null,this.fragment=null};var primitiveVertex="// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\n// Vertex color\nuniform vec4 uColor;\n\n// Fragment color\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(uColor.rgb * uColor.a, uColor.a);\n}\n",primitiveFragment="varying vec4 vColor;\n\nvoid main(void) {\n gl_FragColor = vColor;\n}\n",quadVertex="attribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n",quadFragment="uniform sampler2D uSampler;\nvarying vec4 vColor;\nvarying vec2 vRegion;\n\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vRegion) * vColor;\n}\n",VERTEX_SIZE=2,REGION_SIZE=2,COLOR_SIZE=4,ELEMENT_SIZE=VERTEX_SIZE+REGION_SIZE+COLOR_SIZE,ELEMENT_OFFSET=ELEMENT_SIZE*Float32Array.BYTES_PER_ELEMENT,VERTEX_ELEMENT=0,REGION_ELEMENT=VERTEX_ELEMENT+VERTEX_SIZE,COLOR_ELEMENT=REGION_ELEMENT+REGION_SIZE,ELEMENTS_PER_QUAD=4,INDICES_PER_QUAD=6,MAX_LENGTH=16e3,WebGLCompositor=function(t){var e=t.gl;this.length=0,this.currentTextureUnit=-1,this.boundTextures=[],this.v=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.renderer=t,this.gl=t.gl,this.color=t.currentColor,this.tint=t.currentTint,this.viewMatrix=t.currentTransform,this.activeShader=null,this.mode=e.TRIANGLES,this.attributes=[],this.primitiveShader=new GLShader(this.gl,primitiveVertex,primitiveFragment),this.quadShader=new GLShader(this.gl,quadVertex,quadFragment),this.addAttribute("aVertex",2,e.FLOAT,!1,0*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aRegion",2,e.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aColor",4,e.FLOAT,!1,4*Float32Array.BYTES_PER_ELEMENT),e.bindBuffer(e.ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ARRAY_BUFFER,MAX_LENGTH*ELEMENT_OFFSET*ELEMENTS_PER_QUAD,e.STREAM_DRAW),this.sbSize=256,this.sbIndex=0,this.stream=new Float32Array(this.sbSize*ELEMENT_SIZE*ELEMENTS_PER_QUAD),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ELEMENT_ARRAY_BUFFER,this.createIB(),e.STATIC_DRAW),event.subscribe(event.CANVAS_ONRESIZE,function(t,e){this.flush(),this.setViewport(0,0,t,e)}.bind(this)),this.reset()};WebGLCompositor.prototype.reset=function(){this.sbIndex=0,this.length=0,this.gl=this.renderer.gl,this.flush(),this.setViewport(0,0,this.renderer.getScreenCanvas().width,this.renderer.getScreenCanvas().height),this.clearColor(0,0,0,0);for(var t=0;t<this.renderer.maxTextures;t++){var e=this.boundTextures[t];null!==e&&this.gl.deleteTexture(e),this.boundTextures[t]=null}this.currentTextureUnit=-1,this.useShader(this.quadShader)},WebGLCompositor.prototype.addAttribute=function(t,e,i,n,r){this.attributes.push({name:t,size:e,type:i,normalized:n,offset:r})},WebGLCompositor.prototype.setViewport=function(t,e,i,n){this.gl.viewport(t,e,i,n)},WebGLCompositor.prototype.createTexture2D=function(t,e,i,n,r,o,s,a,h){void 0===n&&(n="no-repeat"),void 0===a&&(a=!0),void 0===h&&(h=!0);var l=this.gl,u=isPowerOfTwo(r||e.width)&&isPowerOfTwo(o||e.height),c=l.createTexture(),d=0!==n.search(/^repeat(-x)?$/)||!u&&2!==this.renderer.WebGLVersion?l.CLAMP_TO_EDGE:l.REPEAT,p=0!==n.search(/^repeat(-y)?$/)||!u&&2!==this.renderer.WebGLVersion?l.CLAMP_TO_EDGE:l.REPEAT;return this.setTexture2D(c,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,d),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,p),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,i),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,i),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),r||o||s?l.texImage2D(l.TEXTURE_2D,0,l.RGBA,r,o,s,l.RGBA,l.UNSIGNED_BYTE,e):l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,e),u&&!1!==h&&l.generateMipmap(l.TEXTURE_2D),c},WebGLCompositor.prototype.setTexture2D=function(t,e){var i=this.gl;t!==this.boundTextures[e]?(this.flush(),this.currentTextureUnit!==e&&(this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,t),this.boundTextures[e]=t):this.currentTextureUnit!==e&&(this.flush(),this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e))},WebGLCompositor.prototype.uploadTexture=function(t,e,i,n,r){var o=this.renderer.cache.getUnit(t),s=this.boundTextures[o];return null===s||r?this.createTexture2D(o,t.getTexture(),this.renderer.settings.antiAlias?this.gl.LINEAR:this.gl.NEAREST,t.repeat,e,i,n,t.premultipliedAlpha):this.setTexture2D(s,o),this.currentTextureUnit},WebGLCompositor.prototype.createIB=function(){for(var t=[0,1,2,2,1,3],e=new Array(MAX_LENGTH*INDICES_PER_QUAD),i=0;i<e.length;i++)e[i]=t[i%INDICES_PER_QUAD]+~~(i/INDICES_PER_QUAD)*ELEMENTS_PER_QUAD;return new Uint16Array(e)},WebGLCompositor.prototype.resizeSB=function(){this.sbSize<<=1;var t=new Float32Array(this.sbSize*ELEMENT_SIZE*ELEMENTS_PER_QUAD);t.set(this.stream),this.stream=t},WebGLCompositor.prototype.useShader=function(t){if(this.activeShader!==t){this.flush(),this.activeShader=t,this.activeShader.bind(),this.activeShader.setUniform("uProjectionMatrix",this.renderer.projectionMatrix);for(var e=0;e<this.attributes.length;++e){var i=this.gl,n=this.attributes[e],r=this.activeShader.getAttribLocation(n.name);-1!==r?(i.enableVertexAttribArray(r),i.vertexAttribPointer(r,n.size,n.type,n.normalized,ELEMENT_OFFSET,n.offset)):i.disableVertexAttribArray(e)}}},WebGLCompositor.prototype.addQuad=function(t,e,i,n,r,o){var s=this.color.toArray(),a=this.tint.toArray();if(!(s[3]<1/255)){a[3]=s[3],this.length>=MAX_LENGTH&&this.flush(),this.length>=this.sbSize&&this.resizeSB(),this.useShader(this.quadShader);var h=this.uploadTexture(t);this.quadShader.setUniform("uSampler",h);var l=this.viewMatrix,u=this.v[0].set(i,n),c=this.v[1].set(i+r,n),d=this.v[2].set(i,n+o),p=this.v[3].set(i+r,n+o);l.isIdentity()||(l.apply(u),l.apply(c),l.apply(d),l.apply(p));var f=this.sbIndex,g=f+ELEMENT_SIZE,m=g+ELEMENT_SIZE,y=m+ELEMENT_SIZE;this.stream[f+VERTEX_ELEMENT+0]=u.x,this.stream[f+VERTEX_ELEMENT+1]=u.y,this.stream[g+VERTEX_ELEMENT+0]=c.x,this.stream[g+VERTEX_ELEMENT+1]=c.y,this.stream[m+VERTEX_ELEMENT+0]=d.x,this.stream[m+VERTEX_ELEMENT+1]=d.y,this.stream[y+VERTEX_ELEMENT+0]=p.x,this.stream[y+VERTEX_ELEMENT+1]=p.y;var v=t.getUVs(e);this.stream[f+REGION_ELEMENT+0]=v[0],this.stream[f+REGION_ELEMENT+1]=v[1],this.stream[g+REGION_ELEMENT+0]=v[2],this.stream[g+REGION_ELEMENT+1]=v[1],this.stream[m+REGION_ELEMENT+0]=v[0],this.stream[m+REGION_ELEMENT+1]=v[3],this.stream[y+REGION_ELEMENT+0]=v[2],this.stream[y+REGION_ELEMENT+1]=v[3],this.stream.set(a,f+COLOR_ELEMENT),this.stream.set(a,g+COLOR_ELEMENT),this.stream.set(a,m+COLOR_ELEMENT),this.stream.set(a,y+COLOR_ELEMENT),this.sbIndex+=ELEMENT_SIZE*ELEMENTS_PER_QUAD,this.length++}},WebGLCompositor.prototype.flush=function(){if(this.length){var t=this.gl,e=this.length*ELEMENT_SIZE*ELEMENTS_PER_QUAD;t.bufferData(t.ARRAY_BUFFER,this.stream.subarray(0,e),t.STREAM_DRAW),t.drawElements(this.mode,this.length*INDICES_PER_QUAD,t.UNSIGNED_SHORT,0),this.sbIndex=0,this.length=0}},WebGLCompositor.prototype.drawVertices=function(t,e,i){var n=this.gl;i=i||e.length,this.useShader(this.primitiveShader),this.primitiveShader.setUniform("uColor",this.color);for(var r=0,o=this.viewMatrix,s=o.isIdentity(),a=0;a<i;a++)s||o.apply(e[a]),this.stream[r+0]=e[a].x,this.stream[r+1]=e[a].y,r+=ELEMENT_SIZE;n.bufferData(n.ARRAY_BUFFER,this.stream.subarray(0,i*ELEMENT_SIZE),n.STREAM_DRAW),n.drawArrays(t,0,i)},WebGLCompositor.prototype.clearColor=function(t,e,i,n){this.gl.clearColor(t,e,i,n)},WebGLCompositor.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)};var WebGLRenderer=function(t){function e(e){t.call(this,e),this.context=this.gl=this.getContextGL(this.getScreenCanvas(),e.transparent),this.webGLVersion=1,this.GPUVendor=null,this.GPURenderer=null,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this._colorStack=[],this._matrixStack=[],this._scissorStack=[],this._glPoints=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.currentTransform=new Matrix2d,this.currentCompositor=null;var i=this.settings.compositor||WebGLCompositor;this.setCompositor(new i(this)),this.gl.disable(this.gl.DEPTH_TEST),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.enable(this.gl.BLEND),this.setBlendMode(this.settings.blendMode);var n=this.gl.getExtension("WEBGL_debug_renderer_info");null!==n&&(this.GPUVendor=this.gl.getParameter(n.UNMASKED_VENDOR_WEBGL),this.GPURenderer=this.gl.getParameter(n.UNMASKED_RENDERER_WEBGL)),this.cache=new TextureCache(this.maxTextures);var r=this;return this.getScreenCanvas().addEventListener("webglcontextlost",(function(t){event.preventDefault(),r.isContextValid=!1,event.publish(event.WEBGL_ONCONTEXT_LOST,[r])}),!1),this.getScreenCanvas().addEventListener("webglcontextrestored",(function(t){r.reset(),r.isContextValid=!0,event.publish(event.WEBGL_ONCONTEXT_RESTORED,[r])}),!1),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),!1===this.isContextValid?this.currentCompositor.init(this):this.currentCompositor.reset(),this.gl.disable(this.gl.SCISSOR_TEST),void 0!==this.fontContext2D&&this.createFontTexture(this.cache)},e.prototype.setCompositor=function(t){null!==this.currentCompositor&&this.currentCompositor!==t&&this.currentCompositor.flush(),this.currentCompositor=t},e.prototype.resetTransform=function(){this.currentTransform.identity()},e.prototype.createFontTexture=function(t){if(void 0===this.fontTexture){var e=this.backBufferCanvas,i=e.width,n=e.height;1===this.WebGLVersion&&(isPowerOfTwo(i)||(i=nextPowerOfTwo(e.width)),isPowerOfTwo(n)||(n=nextPowerOfTwo(e.height)));var r=video$1.createCanvas(i,n,!0);this.fontContext2D=this.getContext2d(r),this.fontTexture=new Texture(createAtlas(e.width,e.height,"fontTexture"),r,t),this.currentCompositor.uploadTexture(this.fontTexture,0,0,0)}else t.set(this.fontContext2D.canvas,this.fontTexture)},e.prototype.createPattern=function(t,e){if(!(1!==video$1.renderer.WebGLVersion||isPowerOfTwo(t.width)&&isPowerOfTwo(t.height))){var i=void 0!==t.src?t.src:t;throw new Error("[WebGL Renderer] "+i+" is not a POT texture ("+t.width+"x"+t.height+")")}var n=new Texture(createAtlas(t.width,t.height,"pattern",e),t);return this.currentCompositor.uploadTexture(n),n},e.prototype.flush=function(){this.currentCompositor.flush()},e.prototype.clearColor=function(t,e){var i;this.save(),i=t instanceof Color?t.toArray():this.getColor().parseCSS(t).toArray(),this.currentCompositor.clearColor(i[0],i[1],i[2],!0===e?1:i[3]),this.currentCompositor.clear(),this.currentCompositor.clearColor(0,0,0,0),this.restore()},e.prototype.clearRect=function(t,e,i,n){var r=this.currentColor.clone();this.currentColor.copy("#000000"),this.fillRect(t,e,i,n),this.currentColor.copy(r),pool.push(r)},e.prototype.drawFont=function(t){var e=this.getFontContext();this.currentCompositor.uploadTexture(this.fontTexture,0,0,0,!0);var i=t.left+","+t.top+","+t.width+","+t.height;this.currentCompositor.addQuad(this.fontTexture,i,t.left,t.top,t.width,t.height),e.clearRect(t.left,t.top,t.width,t.height)},e.prototype.drawImage=function(t,e,i,n,r,o,s,a,h){void 0===n?(n=a=t.width,r=h=t.height,o=e,s=i,e=0,i=0):void 0===o&&(o=e,s=i,a=n,h=r,n=t.width,r=t.height,e=0,i=0),!1===this.settings.subPixel&&(o|=0,s|=0);var l=e+","+i+","+n+","+r;this.currentCompositor.addQuad(this.cache.get(t),l,o,s,a,h)},e.prototype.drawPattern=function(t,e,i,n,r){var o="0,0,"+n+","+r;this.currentCompositor.addQuad(t,o,e,i,n,r)},e.prototype.getScreenContext=function(){return this.gl},e.prototype.getContextGL=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a GL context");"boolean"!=typeof e&&(e=!0);var i,n={alpha:e,antialias:this.settings.antiAlias,depth:!1,stencil:!0,preserveDrawingBuffer:!1,premultipliedAlpha:e,powerPreference:this.settings.powerPreference,failIfMajorPerformanceCaveat:this.settings.failIfMajorPerformanceCaveat};if(!1===this.settings.preferWebGL1&&(i=t.getContext("webgl2",n))&&(this.WebGLVersion=2),i||(this.WebGLVersion=1,i=t.getContext("webgl",n)||t.getContext("experimental-webgl",n)),!i)throw new Error("A WebGL context could not be created.");return i},e.prototype.getContext=function(){return this.gl},e.prototype.setBlendMode=function(t,e){if((e=e||this.gl).enable(e.BLEND),"multiply"===t)e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode=t;else e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode="normal"},e.prototype.getFontContext=function(){return void 0===this.fontContext2D&&(console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !"),this.createFontTexture(this.cache)),this.fontContext2D},e.prototype.restore=function(){if(0!==this._matrixStack.length){var t=this._colorStack.pop(),e=this._matrixStack.pop();this.currentColor.copy(t),this.currentTransform.copy(e),pool.push(t),pool.push(e)}0!==this._scissorStack.length?this.currentScissor.set(this._scissorStack.pop()):(this.gl.disable(this.gl.SCISSOR_TEST),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height)},e.prototype.save=function(){this._colorStack.push(this.currentColor.clone()),this._matrixStack.push(this.currentTransform.clone()),this.gl.isEnabled(this.gl.SCISSOR_TEST)&&this._scissorStack.push(this.currentScissor.slice())},e.prototype.rotate=function(t){this.currentTransform.rotate(t)},e.prototype.scale=function(t,e){this.currentTransform.scale(t,e)},e.prototype.setAntiAlias=function(e,i){t.prototype.setAntiAlias.call(this,e,i)},e.prototype.setGlobalAlpha=function(t){this.currentColor.glArray[3]=t},e.prototype.setColor=function(t){var e=this.currentColor.glArray[3];this.currentColor.copy(t),this.currentColor.glArray[3]*=e},e.prototype.setLineWidth=function(t){this.getScreenContext().lineWidth(t)},e.prototype.strokeArc=function(t,e,i,n,r,o,s){if(!0===s)this.fillArc(t,e,i,n,r,o);else{var a,h=this._glPoints,l=Math.floor(24*Math.sqrt(2*i)),u=(r-n)/(2*l),c=2*u,d=Math.cos(u),p=Math.sin(u);for(a=h.length;a<l+1;a++)h.push(new Vector2d);for(a=0;a<l;a++){var f=u+n+c*a,g=Math.cos(f),m=-Math.sin(f);h[a].x=t+(d*g+p*m)*i,h[a].y=e+(d*-m+p*g)*i}this.currentCompositor.drawVertices(this.gl.LINE_STRIP,h,l)}},e.prototype.fillArc=function(t,e,i,n,r,o){var s,a=this._glPoints,h=0,l=Math.floor(24*Math.sqrt(2*i)),u=(r-n)/(2*l),c=2*u,d=Math.cos(u),p=Math.sin(u);for(s=a.length;s<2*l;s++)a.push(new Vector2d);for(s=0;s<l-1;s++){var f=u+n+c*s,g=Math.cos(f),m=-Math.sin(f);a[h++].set(t,e),a[h++].set(t-(d*g+p*m)*i,e-(d*-m+p*g)*i)}this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeEllipse=function(t,e,i,n,r){if(!0===r)this.fillEllipse(t,e,i,n);else{var o,s=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+n)),a=TAU/s,h=this._glPoints;for(o=h.length;o<s;o++)h.push(new Vector2d);for(o=0;o<s;o++)h[o].x=t+Math.sin(a*-o)*i,h[o].y=e+Math.cos(a*-o)*n;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,h,s)}},e.prototype.fillEllipse=function(t,e,i,n){var r,o=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+n)),s=TAU/o,a=this._glPoints,h=0;for(r=a.length;r<2*(o+1);r++)a.push(new Vector2d);for(r=0;r<o+1;r++)a[h++].set(t,e),a[h++].set(t+Math.sin(s*r)*i,e+Math.cos(s*r)*n);this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeLine=function(t,e,i,n){var r=this._glPoints;r[0].x=t,r[0].y=e,r[1].x=i,r[1].y=n,this.currentCompositor.drawVertices(this.gl.LINE_STRIP,r,2)},e.prototype.fillLine=function(t,e,i,n){this.strokeLine(t,e,i,n)},e.prototype.strokePolygon=function(t,e){if(!0===e)this.fillPolygon(t);else{var i,n=t.points.length,r=this._glPoints;for(i=r.length;i<n;i++)r.push(new Vector2d);for(i=0;i<n;i++)r[i].x=t.pos.x+t.points[i].x,r[i].y=t.pos.y+t.points[i].y;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,r,n)}},e.prototype.fillPolygon=function(t){var e,i=t.points,n=this._glPoints,r=t.getIndices(),o=t.pos.x,s=t.pos.y;for(e=n.length;e<r.length;e++)n.push(new Vector2d);for(e=0;e<r.length;e++)n[e].set(o+i[r[e]].x,s+i[r[e]].y);this.currentCompositor.drawVertices(this.gl.TRIANGLES,n,r.length)},e.prototype.strokeRect=function(t,e,i,n,r){if(!0===r)this.fillRect(t,e,i,n);else{var o=this._glPoints;o[0].x=t,o[0].y=e,o[1].x=t+i,o[1].y=e,o[2].x=t+i,o[2].y=e+n,o[3].x=t,o[3].y=e+n,this.currentCompositor.drawVertices(this.gl.LINE_LOOP,o,4)}},e.prototype.fillRect=function(t,e,i,n){var r=this._glPoints;r[0].x=t+i,r[0].y=e,r[1].x=t,r[1].y=e,r[2].x=t+i,r[2].y=e+n,r[3].x=t,r[3].y=e+n,this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,r,4)},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=this.currentTransform;if(e.multiply(t),!1===this.settings.subPixel){var i=e.toArray();i[6]|=0,i[7]|=0}},e.prototype.translate=function(t,e){var i=this.currentTransform;if(i.translate(t,e),!1===this.settings.subPixel){var n=i.toArray();n[6]|=0,n[7]|=0}},e.prototype.clipRect=function(t,e,i,n){var r=this.backBufferCanvas,o=this.gl;if(0!==t||0!==e||i!==r.width||n!==r.height){var s=this.currentScissor;if(o.isEnabled(o.SCISSOR_TEST)&&s[0]===t&&s[1]===e&&s[2]===i&&s[3]===n)return;this.flush(),o.enable(this.gl.SCISSOR_TEST),o.scissor(t+this.currentTransform.tx,r.height-n-e-this.currentTransform.ty,i,n),s[0]=t,s[1]=e,s[2]=i,s[3]=n}else o.disable(o.SCISSOR_TEST)},e.prototype.setMask=function(t){var e=this.gl;this.flush(),e.enable(e.STENCIL_TEST),e.clear(e.STENCIL_BUFFER_BIT),e.colorMask(!1,!1,!1,!1),e.stencilFunc(e.NOTEQUAL,1,1),e.stencilOp(e.REPLACE,e.REPLACE,e.REPLACE),this.fill(t),this.flush(),e.colorMask(!0,!0,!0,!0),e.stencilFunc(e.EQUAL,1,1),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)},e.prototype.clearMask=function(){this.flush(),this.gl.disable(this.gl.STENCIL_TEST)},e}(Renderer),designRatio=1,designWidth=0,designHeight=0,settings={parent:document.body,renderer:2,doubleBuffering:!1,autoScale:!1,scale:1,scaleMethod:"fit",transparent:!1,blendMode:"normal",antiAlias:!1,failIfMajorPerformanceCaveat:!0,subPixel:!1,preferWebGL1:!1,powerPreference:"default",verbose:!1,consoleHeader:!0};function autoDetectRenderer(t){try{if(device$1.isWebGLSupported(t))return new WebGLRenderer(t)}catch(t){console.log("Error creating WebGL renderer :"+t.message)}return new CanvasRenderer(t)}var video={CANVAS:0,WEBGL:1,AUTO:2,parent:null,scaleRatio:new Vector2d(1,1),init:function(t,e,i){if(!exports.initialized)throw new Error("me.video.init() called before engine initialization.");(settings=Object.assign(settings,i||{})).width=t,settings.height=e,settings.doubleBuffering=!!settings.doubleBuffering,settings.transparent=!!settings.transparent,settings.antiAlias=!!settings.antiAlias,settings.failIfMajorPerformanceCaveat=!!settings.failIfMajorPerformanceCaveat,settings.subPixel=!!settings.subPixel,settings.verbose=!!settings.verbose,-1!==settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/)?settings.autoScale="auto"===settings.scale||!0:(settings.scaleMethod="fit",settings.autoScale="auto"===settings.scale||!1),void 0!==settings.wrapper&&(warning("settings.wrapper","settings.parent","8.0.0"),settings.parent=settings.wrapper),!1!==settings.consoleHeader&&console.log("melonJS v"+version+" | http://melonjs.org");var n=utils$1.getUriFragment();!0!==n.webgl&&!0!==n.webgl1&&!0!==n.webgl2||(settings.renderer=this.WEBGL,!0===n.webgl1&&(settings.preferWebGL1=!0)),settings.scale=settings.autoScale?1:+settings.scale||1,this.scaleRatio.set(settings.scale,settings.scale),(settings.autoScale||1!==settings.scale)&&(settings.doubleBuffering=!0),designRatio=t/e,designWidth=t,designHeight=e,settings.zoomX=t*this.scaleRatio.x,settings.zoomY=e*this.scaleRatio.y,window.addEventListener("resize",utils$1.function.throttle((function(t){event.publish(event.WINDOW_ONRESIZE,[t])}),100),!1),window.addEventListener("orientationchange",(function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),!1),window.addEventListener("onmozorientationchange",(function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),!1),void 0!==window.screen&&(window.screen.onorientationchange=function(t){event.publish(event.WINDOW_ONORIENTATION_CHANGE,[t])}),window.addEventListener("scroll",utils$1.function.throttle((function(t){event.publish(event.WINDOW_ONSCROLL,[t])}),100),!1),event.subscribe(event.WINDOW_ONRESIZE,this.onresize.bind(this)),event.subscribe(event.WINDOW_ONORIENTATION_CHANGE,this.onresize.bind(this));try{switch(settings.renderer){case this.AUTO:case this.WEBGL:this.renderer=autoDetectRenderer(settings);break;default:this.renderer=new CanvasRenderer(settings)}}catch(t){return console(t.message),!1}(this.parent=device$1.getElement(settings.parent),this.parent.appendChild(this.renderer.getScreenCanvas()),this.onresize(),"MutationObserver"in window)&&new MutationObserver(this.onresize.bind(this)).observe(this.parent,{attributes:!1,childList:!0,subtree:!0});if(!1!==settings.consoleHeader){var r=this.renderer instanceof CanvasRenderer?"CANVAS":"WebGL"+this.renderer.WebGLVersion,o=device$1.hasWebAudio?"Web Audio":"HTML5 Audio",s="string"==typeof this.renderer.GPURenderer?" ("+this.renderer.GPURenderer+")":"";console.log(r+" renderer"+s+" | "+o+" | pixel ratio "+device$1.devicePixelRatio+" | "+(device$1.isMobile?"mobile":"desktop")+" | "+device$1.getScreenOrientation()+" | "+device$1.language),console.log("resolution: requested "+t+"x"+e+", got "+this.renderer.getWidth()+"x"+this.renderer.getHeight())}return event.publish(event.VIDEO_INIT),!0},createCanvas:function(t,e,i){var n;if(0===t||0===e)throw new Error("width or height was zero, Canvas could not be initialized !");return!0===device$1.OffscreenCanvas&&!0===i?void 0===(n=new OffscreenCanvas(0,0)).style&&(n.style={}):n=document.createElement("canvas"),n.width=t,n.height=e,n},getParent:function(){return this.parent},onresize:function(){var t=this.renderer,e=t.settings,i=1,n=1;if(e.autoScale){var r=1/0,o=1/0;if(window.getComputedStyle){var s=window.getComputedStyle(t.getScreenCanvas(),null);r=parseInt(s.maxWidth,10)||1/0,o=parseInt(s.maxHeight,10)||1/0}var a=device$1.getParentBounds(this.getParent()),h=Math.min(r,a.width),l=Math.min(o,a.height),u=h/l;if("fill-min"===e.scaleMethod&&u>designRatio||"fill-max"===e.scaleMethod&&u<designRatio||"flex-width"===e.scaleMethod){var c=Math.min(r,designHeight*u);i=n=h/c,t.resize(Math.floor(c),designHeight)}else if("fill-min"===e.scaleMethod&&u<designRatio||"fill-max"===e.scaleMethod&&u>designRatio||"flex-height"===e.scaleMethod){var d=Math.min(o,designWidth*(l/h));i=n=l/d,t.resize(designWidth,Math.floor(d))}else"flex"===e.scaleMethod?t.resize(Math.floor(h),Math.floor(l)):"stretch"===e.scaleMethod?(i=h/designWidth,n=l/designHeight):i=n=u<designRatio?h/designWidth:l/designHeight;this.scale(i,n)}},scale:function(t,e){var i=this.renderer,n=i.getScreenCanvas(),r=i.getScreenContext(),o=i.settings,s=device$1.devicePixelRatio,a=o.zoomX=n.width*t*s,h=o.zoomY=n.height*e*s;this.scaleRatio.set(t*s,e*s),n.style.width=a/s+"px",n.style.height=h/s+"px",i.setAntiAlias(r,o.antiAlias),i.setBlendMode(o.blendMode,r),game$1.repaint()}},video$1=video,GUID_base="",GUID_index=0,utils={agent:agentUtils,array:arrayUtils,file:fileUtils,string:stringUtils,function:fnUtils,getPixels:function(t){if(t instanceof HTMLImageElement){var e=CanvasRenderer.getContext2d(video$1.createCanvas(t.width,t.height));return e.drawImage(t,0,0),e.getImageData(0,0,t.width,t.height)}return t.getContext("2d").getImageData(0,0,t.width,t.height)},checkVersion:function(t,e){void 0===e&&(e=version);for(var i=t.split("."),n=e.split("."),r=Math.min(i.length,n.length),o=0,s=0;s<r&&!(o=+i[s]-+n[s]);s++);return o||i.length-n.length},getUriFragment:(UriFragments={},parsed=!1,function(t){var e;if(void 0===t){if(e=UriFragments,!0===parsed)return e;t=document.location,parsed=!0}else e={};return t&&t.hash&&t.hash.substr(1).split("&").filter((function(t){return""!==t})).forEach((function(t){var i=t.split("="),n=i.shift(),r=i.join("=");e[n]=r||!0})),e}),resetGUID:function(t,e){void 0===e&&(e=0),GUID_base=toHex$1(t.toString().toUpperCase()),GUID_index=e},createGUID:function(t){return void 0===t&&(t=1),GUID_index+=t,GUID_base+"-"+(t||GUID_index)}},UriFragments,parsed,utils$1=utils,framecount=0,framedelta=0,last=0,now=0,delta=0,step=0,minstep=0,timers=[],timerId=0;function clearTimer(t){for(var e=0,i=timers.length;e<i;e++)if(timers[e].timerId===t){timers.splice(e,1);break}}function updateTimers(t){last=now,(delta=(now=t)-last)<0&&(delta=0),timer.tick=delta>minstep&&timer.interpolation?delta/step:1;for(var e=0,i=timers.length;e<i;e++){var n=timers[e];n.pauseable&&state$1.isPaused()||(n.elapsed+=delta),n.elapsed>=n.delay&&(n.fn.apply(null,n.args),!0===n.repeat?n.elapsed-=n.delay:timer.clearTimeout(n.timerId))}}var timer={tick:1,fps:0,maxfps:60,interpolation:!1,lastUpdate:window.performance.now(),init:function(){this.reset(),now=last=0,event.subscribe(event.GAME_UPDATE,updateTimers)},reset:function(){last=now=window.performance.now(),delta=0,framedelta=0,framecount=0,step=Math.ceil(1e3/this.maxfps),minstep=1e3/this.maxfps*1.25},setTimeout:function(t,e,i){return timers.push({fn:t,delay:e,elapsed:0,repeat:!1,timerId:++timerId,pauseable:!0===i||!0,args:arguments.length>3?Array.prototype.slice.call(arguments,3):void 0}),timerId},setInterval:function(t,e,i){return timers.push({fn:t,delay:e,elapsed:0,repeat:!0,timerId:++timerId,pauseable:!0===i||!0,args:arguments.length>3?Array.prototype.slice.call(arguments,3):void 0}),timerId},clearTimeout:function(t){utils$1.function.defer(clearTimer,this,t)},clearInterval:function(t){utils$1.function.defer(clearTimer,this,t)},getTime:function(){return now},getDelta:function(){return delta},countFPS:function(){framecount++,framedelta+=delta,framecount%10==0&&(this.fps=clamp(Math.round(1e3*framecount/framedelta),0,this.maxfps),framedelta=0,framecount=0)}},timer$1=timer,lastTime=0,vendors=["ms","moz","webkit","o"],x,requestAnimationFrame=window.requestAnimationFrame,cancelAnimationFrame=window.cancelAnimationFrame;for(x=0;x<vendors.length&&!requestAnimationFrame;++x)requestAnimationFrame=window[vendors[x]+"RequestAnimationFrame"];for(x=0;x<vendors.length&&!cancelAnimationFrame;++x)cancelAnimationFrame=window[vendors[x]+"CancelAnimationFrame"]||window[vendors[x]+"CancelRequestAnimationFrame"];requestAnimationFrame&&cancelAnimationFrame||(requestAnimationFrame=function(t){var e=window.performance.now(),i=Math.max(0,1e3/timer$1.maxfps-(e-lastTime)),n=window.setTimeout((function(){t(e+i)}),i);return lastTime=e+i,n},cancelAnimationFrame=function(t){window.clearTimeout(t)},window.requestAnimationFrame=requestAnimationFrame,window.cancelAnimationFrame=cancelAnimationFrame);var plugins={},plugin={Base:window.Jay.extend({init:function(){this.version="9.0.1"}}),patch:function(t,e,i){if(void 0!==t.prototype&&(t=t.prototype),"function"!=typeof t[e])throw new Error(e+" is not an existing function");var n=t[e];Object.defineProperty(t,e,{configurable:!0,value:function(t,e){return function(){this._patched=n;var t=e.apply(this,arguments);return this._patched=null,t}}(0,i)})},register:function(t,e){if(plugins[e])throw new Error("plugin "+e+" already registered");var i=[];arguments.length>2&&(i=Array.prototype.slice.call(arguments,1)),i[0]=t;var n=new(t.bind.apply(t,i));if(void 0===n||!(n instanceof plugin.Base))throw new Error("Plugin should extend the me.plugin.Base Class !");if(utils$1.checkVersion(n.version)>0)throw new Error("Plugin version mismatch, expected: "+n.version+", got: "+version);plugins[e]=n}},Easing={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-Easing.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*Easing.Bounce.In(2*t):.5*Easing.Bounce.Out(2*t-1)+.5}}},Interpolation={Linear:function(t,e){var i=t.length-1,n=i*e,r=Math.floor(n),o=Interpolation.Utils.Linear;return e<0?o(t[0],t[1],n):e>1?o(t[i],t[i-1],i-n):o(t[r],t[r+1>i?i:r+1],n-r)},Bezier:function(t,e){var i,n=0,r=t.length-1,o=Math.pow,s=Interpolation.Utils.Bernstein;for(i=0;i<=r;i++)n+=o(1-e,r-i)*o(e,i)*t[i]*s(r,i);return n},CatmullRom:function(t,e){var i=t.length-1,n=i*e,r=Math.floor(n),o=Interpolation.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(r=Math.floor(n=i*(1+e))),o(t[(r-1+i)%i],t[r],t[(r+1)%i],t[(r+2)%i],n-r)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-n)-t[0]):e>1?t[i]-(o(t[i],t[i],t[i-1],t[i-1],n-i)-t[i]):o(t[r?r-1:0],t[r],t[i<r+1?i:r+1],t[i<r+2?i:r+2],n-r)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=Interpolation.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:function(){var t=[1];return function(e){var i,n=1;if(t[e])return t[e];for(i=e;i>1;i--)n*=i;return t[e]=n}}(),CatmullRom:function(t,e,i,n,r){var o=.5*(i-t),s=.5*(n-e),a=r*r;return(2*e-2*i+o+s)*(r*a)+(-3*e+3*i-2*o-s)*a+o*r+e}}},Tween=function(t){var e=null,i=null,n=null,r=null,o=null,s=null,a=null,h=null,l=null,u=null,c=null,d=null,p=null,f=null,g=null,m=null,y=null;this.isRenderable=!1,this._resumeCallback=function(t){l&&(l+=t)},this.setProperties=function(t){for(var v in e=t,i={},n={},r={},o=1e3,s=0,a=!1,h=0,l=null,u=Easing.Linear.None,c=Interpolation.Linear,d=[],p=null,f=!1,g=null,m=null,y=timer$1.lastUpdate,this.isPersistent=!1,this.updateWhenPaused=!1,t)"object"!=typeof t&&(i[v]=parseFloat(t[v]))},this.setProperties(t),this.onResetEvent=function(t){this.setProperties(t)},this.onActivateEvent=function(){event.subscribe(event.STATE_RESUME,this._resumeCallback)},this.onDeactivateEvent=function(){event.unsubscribe(event.STATE_RESUME,this._resumeCallback)},this.to=function(t,e){return n=t,void 0!==e&&("number"==typeof e?o=e:"object"==typeof e&&(e.duration&&(o=e.duration),e.yoyo&&this.yoyo(e.yoyo),e.easing&&this.easing(e.easing),e.repeat&&this.repeat(e.repeat),e.delay&&this.delay(e.delay),e.interpolation&&this.interpolation(e.interpolation),e.autoStart&&this.start())),this},this.start=function(t){for(var o in f=!1,game$1.world.addChild(this),l=(void 0===t?timer$1.getTime():t)+h,n){if(n[o]instanceof Array){if(0===n[o].length)continue;n[o]=[e[o]].concat(n[o])}i[o]=e[o],i[o]instanceof Array==!1&&(i[o]*=1),r[o]=i[o]||0}return this},this.stop=function(){return game$1.world.removeChildNow(this),this},this.delay=function(t){return h=t,this},this.repeat=function(t){return s=t,this},this.yoyo=function(t){return a=t,this},this.easing=function(t){if("function"!=typeof t)throw new Error("invalid easing function for me.Tween.easing()");return u=t,this},this.interpolation=function(t){return c=t,this},this.chain=function(){return d=arguments,this},this.onStart=function(t){return p=t,this},this.onUpdate=function(t){return g=t,this},this.onComplete=function(t){return m=t,this},this.update=function(t){var v,_=y=timer$1.lastUpdate>y?timer$1.lastUpdate:y+t;if(_<l)return!0;!1===f&&(null!==p&&p.call(e),f=!0);var x=(_-l)/o,w=u(x=x>1?1:x);for(v in n){var b=i[v]||0,T=n[v];T instanceof Array?e[v]=c(T,w):("string"==typeof T&&(T=b+parseFloat(T)),"number"==typeof T&&(e[v]=b+(T-b)*w))}if(null!==g&&g.call(e,w),1===x){if(s>0){for(v in isFinite(s)&&s--,r){if("string"==typeof n[v]&&(r[v]=r[v]+parseFloat(n[v])),a){var E=r[v];r[v]=n[v],n[v]=E}i[v]=r[v]}return l=_+h,!0}game$1.world.removeChildNow(this),null!==m&&m.call(e);for(var A=0,R=d.length;A<R;A++)d[A].start(_);return!1}return!0}},staticAccessors={Easing:{configurable:!0},Interpolation:{configurable:!0}};staticAccessors.Easing.get=function(){return Easing},staticAccessors.Interpolation.get=function(){return Interpolation},Object.defineProperties(Tween,staticAccessors);var runits=["ex","em","pt","px"],toPX=[12,24,.75,1],setContextStyle=function(t,e,i){t.font=e.font,t.fillStyle=e.fillStyle.toRGBA(),!0===i&&(t.strokeStyle=e.strokeStyle.toRGBA(),t.lineWidth=e.lineWidth),t.textAlign=e.textAlign,t.textBaseline=e.textBaseline},Text=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),void 0!==i.fillStyle?i.fillStyle instanceof Color?this.fillStyle=i.fillStyle:this.fillStyle=pool.pull("Color").parseCSS(i.fillStyle):this.fillStyle=pool.pull("Color",0,0,0),void 0!==i.strokeStyle?i.strokeStyle instanceof Color?this.strokeStyle=i.strokeStyle:this.strokeStyle=pool.pull("Color").parseCSS(i.strokeStyle):this.strokeStyle=pool.pull("Color",0,0,0),this.lineWidth=i.lineWidth||1,this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this._text=[],this.fontSize=10,void 0!==i.anchorPoint?this.anchorPoint.setV(i.anchorPoint):this.anchorPoint.set(0,0),void 0!==i.floating&&(this.floating=!!i.floating),this.setFont(i.font,i.size),!0===i.bold&&this.bold(),!0===i.italic&&this.italic(),this.setText(i.text)},bold:function(){return this.font="bold "+this.font,this.isDirty=!0,this},italic:function(){return this.font="italic "+this.font,this.isDirty=!0,this},setFont:function(t,e){var i=t.split(",").map((function(t){return t=t.trim(),/(^".*"$)|(^'.*'$)/.test(t)?t:'"'+t+'"'}));if("number"==typeof e)this.fontSize=e,e+="px";else{var n=e.match(/([-+]?[\d.]*)(.*)/);this.fontSize=parseFloat(n[1]),n[2]?this.fontSize*=toPX[runits.indexOf(n[2])]:e+="px"}return this.height=this.fontSize,this.font=e+" "+i.join(","),this.isDirty=!0,this},setText:function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this},measureText:function(t,e,i){var n;n=void 0===t?video$1.renderer.getFontContext():t instanceof Renderer?t.getFontContext():t;var r=i||this.getBounds(),o=this.fontSize*this.lineHeight,s=void 0!==e?(""+e).split("\n"):this._text;n.save(),setContextStyle(n,this),this.height=this.width=0;for(var a=0;a<s.length;a++)this.width=Math.max(n.measureText(utils$1.string.trimRight(""+s[a])).width,this.width),this.height+=o;return r.width=Math.ceil(this.width),r.height=Math.ceil(this.height),r.x=Math.floor("right"===this.textAlign?this.pos.x-this.width:"center"===this.textAlign?this.pos.x-this.width/2:this.pos.x),r.y=Math.floor(0===this.textBaseline.search(/^(top|hanging)$/)?this.pos.y:"middle"===this.textBaseline?this.pos.y-r.height/2:this.pos.y-r.height),n.restore(),r},update:function(){return!0===this.isDirty&&this.measureText(),this.isDirty},draw:function(t,e,i,n,r){void 0===this.ancestor?(this.setText(e),this.pos.x===i&&this.pos.y===n||(this.pos.x=i,this.pos.y=n,this.isDirty=!0),this.update(0),t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())):(i=this.pos.x,n=this.pos.y),!1===t.settings.subPixel&&(i=~~i,n=~~n),t.drawFont(this._drawFont(t.getFontContext(),this._text,i,n,r||!1)),void 0===this.ancestor&&t.restore(),this.isDirty=!1},drawStroke:function(t,e,i,n){this.draw.call(this,t,e,i,n,!0)},_drawFont:function(t,e,i,n,r){setContextStyle(t,this,r);for(var o=this.fontSize*this.lineHeight,s=0;s<e.length;s++){var a=utils$1.string.trimRight(""+e[s]);t[r?"strokeText":"fillText"](a,i,n),n+=o}return this.getBounds()},destroy:function(){pool.push(this.fillStyle),pool.push(this.strokeStyle),this.fillStyle=this.strokeStyle=void 0,this._text.length=0,this._super(Renderable,"destroy")}}),measureTextWidth=function(t,e){for(var i=e.split(""),n=0,r=null,o=0;o<i.length;o++){var s=i[o].charCodeAt(0),a=t.fontData.glyphs[s],h=r&&r.kerning?r.getKerning(s):0;n+=(a.xadvance+h)*t.fontScale.x,r=a}return n},measureTextHeight=function(t){return t.fontData.capHeight*t.lineHeight*t.fontScale.y},BitmapText=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this._text=[],this.fontScale=pool.pull("Vector2d",1,1),this.fontImage="object"==typeof i.font?i.font:loader$1.getImage(i.font),"string"!=typeof i.fontData?this.fontData=pool.pull("BitmapTextData",loader$1.getBinary(i.font)):this.fontData=pool.pull("BitmapTextData",i.fontData.includes("info face")?i.fontData:loader$1.getBinary(i.fontData)),void 0!==i.floating&&(this.floating=!!i.floating),"number"==typeof i.size&&1!==i.size&&this.resize(i.size),void 0!==i.fillStyle&&(i.fillStyle instanceof Color?this.fillStyle.setColor(i.fillStyle):this.fillStyle.parseCSS(i.fillStyle)),void 0!==i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0),this.setText(i.text)},set:function(t,e){return this.textAlign=t,e&&this.resize(e),this.isDirty=!0,this},setText:function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this},resize:function(t){return this.fontScale.set(t,t),this.isDirty=!0,this},measureText:function(t,e){t=t||this._text;var i=measureTextHeight(this),n=e||this.getBounds(),r="string"==typeof t?(""+t).split("\n"):t;n.height=n.width=0;for(var o=0;o<r.length;o++)n.width=Math.max(measureTextWidth(this,r[o]),n.width),n.height+=i;return n},update:function(){return!0===this.isDirty&&this.measureText(),this.isDirty},draw:function(t,e,i,n){var r=t.globalAlpha();void 0===this.ancestor?(this.setText(e),this.update(0),t.setGlobalAlpha(r*this.getOpacity())):(i=this.pos.x,n=this.pos.y);for(var o=i,s=measureTextHeight(this),a=0,h=0;h<this._text.length;h++){i=o;var l=utils$1.string.trimRight(this._text[h]),u=measureTextWidth(this,l);switch(this.textAlign){case"right":i-=u;break;case"center":i-=.5*u}switch(this.textBaseline){case"middle":n-=.5*s;break;case"ideographic":case"alphabetic":case"bottom":n-=s}!0===this.isDirty&&void 0===this.ancestor&&(0===h&&(this.pos.y=n),a<u&&(a=u,this.pos.x=i));for(var c=null,d=0,p=l.length;d<p;d++){var f=l.charCodeAt(d),g=this.fontData.glyphs[f],m=g.width,y=g.height,v=c&&c.kerning?c.getKerning(f):0;0!==m&&0!==y&&t.drawImage(this.fontImage,g.x,g.y,m,y,i+g.xoffset,n+g.yoffset*this.fontScale.y,m*this.fontScale.x,y*this.fontScale.y),i+=(g.xadvance+v)*this.fontScale.x,c=g}n+=s}void 0===this.ancestor&&t.setGlobalAlpha(r),this.isDirty=!1},destroy:function(){pool.push(this.fontScale),this.fontScale=void 0,pool.push(this.fontData),this.fontData=void 0,this._text.length=0,this._super(Renderable,"destroy")}});Object.defineProperty(BitmapText.prototype,"fillStyle",{get:function(){return this.tint},set:function(t){this.tint=t},configurable:!0});var LOG2_PAGE_SIZE=9,PAGE_SIZE=1<<LOG2_PAGE_SIZE,Glyph=function(){this.id=0,this.x=0,this.y=0,this.width=0,this.height=0,this.u=0,this.v=0,this.u2=0,this.v2=0,this.xoffset=0,this.yoffset=0,this.xadvance=0,this.fixedWidth=!1};Glyph.prototype.getKerning=function(t){if(this.kerning){var e=this.kerning[t>>>LOG2_PAGE_SIZE];if(e)return e[t&PAGE_SIZE-1]||0}return 0},Glyph.prototype.setKerning=function(t,e){this.kerning||(this.kerning={});var i=this.kerning[t>>>LOG2_PAGE_SIZE];void 0===i&&(this.kerning[t>>>LOG2_PAGE_SIZE]={},i=this.kerning[t>>>LOG2_PAGE_SIZE]),i[t&PAGE_SIZE-1]=e};var capChars=["M","N","B","D","C","E","F","K","A","G","H","I","J","L","O","P","Q","R","S","T","U","V","W","X","Y","Z"];function getValueFromPair(t,e){var i=t.match(e);if(!i)throw new Error("Could not find pattern "+e+" in string: "+t);return i[0].split("=")[1]}function getFirstGlyph(t){for(var e=Object.keys(t),i=0;i<e.length;i++)if(e[i]>32)return t[e[i]];return null}function createSpaceGlyph(t){var e=" ".charCodeAt(0),i=t[e];i||((i=new Glyph).id=e,i.xadvance=getFirstGlyph(t).xadvance,t[e]=i)}var BitmapTextData=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this).onResetEvent.apply(t,e)};BitmapTextData.prototype.onResetEvent=function(t){this.padTop=0,this.padRight=0,this.padBottom=0,this.padLeft=0,this.lineHeight=0,this.capHeight=1,this.descent=0,this.glyphs={},this.parse(t)},BitmapTextData.prototype.parse=function(t){if(!t)throw new Error("File containing font data was empty, cannot load the bitmap font.");var e=t.split(/\r\n|\n/),i=t.match(/padding\=\d+,\d+,\d+,\d+/g);if(!i)throw new Error("Padding not found in first line");var n=i[0].split("=")[1].split(",");this.padTop=parseFloat(n[0]),this.padLeft=parseFloat(n[1]),this.padBottom=parseFloat(n[2]),this.padRight=parseFloat(n[3]),this.lineHeight=parseFloat(getValueFromPair(e[1],/lineHeight\=\d+/g));var r,o=parseFloat(getValueFromPair(e[1],/base\=\d+/g)),s=this.padTop+this.padBottom,a=null;for(r=4;r<e.length;r++){var h=e[r],l=h.split(/=|\s+/);if(h&&!/^kernings/.test(h))if(/^kerning\s/.test(h)){var u=parseFloat(l[2]),c=parseFloat(l[4]),d=parseFloat(l[6]);null!=(a=this.glyphs[u])&&a.setKerning(c,d)}else{a=new Glyph;var p=parseFloat(l[2]);a.id=p,a.x=parseFloat(l[4]),a.y=parseFloat(l[6]),a.width=parseFloat(l[8]),a.height=parseFloat(l[10]),a.xoffset=parseFloat(l[12]),a.yoffset=parseFloat(l[14]),a.xadvance=parseFloat(l[16]),a.width>0&&a.height>0&&(this.descent=Math.min(o+a.yoffset,this.descent)),this.glyphs[p]=a}}this.descent+=this.padBottom,createSpaceGlyph(this.glyphs);var f=null;for(r=0;r<capChars.length;r++){var g=capChars[r];if(f=this.glyphs[g.charCodeAt(0)])break}if(f)this.capHeight=f.height;else for(var m in this.glyphs)if(this.glyphs.hasOwnProperty(m)){if(0===(a=this.glyphs[m]).height||0===a.width)continue;this.capHeight=Math.max(this.capHeight,a.height)}this.capHeight-=s};var ColorLayer=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[0,0,1/0,1/0]),this.name=t,this.pos.z=i,this.floating=!0,this.color=e instanceof Color?e:pool.pull("Color").parseCSS(e),this.anchorPoint.set(0,0)},draw:function(t,e){var i=t.getColor(),n=game$1.viewport.pos;t.setColor(this.color),t.fillRect(e.left-n.x,e.top-n.y,e.width,e.height),t.setColor(i)},destroy:function(){pool.push(this.color),this.color=void 0,this._super(Renderable,"destroy")}}),ImageLayer=Renderable.extend({init:function(t,e,i){if(this._super(Renderable,"init",[t,e,1/0,1/0]),this.image="object"==typeof i.image?i.image:loader$1.getImage(i.image),!this.image)throw new Error(("string"==typeof i.image?"'"+i.image+"'":"Image")+" file for Image Layer '"+this.name+"' not found!");this.imagewidth=this.image.width,this.imageheight=this.image.height,"string"==typeof i.name&&(this.name=i.name),this.floating=!0,this.pos.z=i.z||0,this.offset=pool.pull("Vector2d",t,e),this.ratio=pool.pull("Vector2d",1,1),void 0!==i.ratio&&("number"==typeof i.ratio?this.ratio.set(i.ratio,i.ratio):this.ratio.setV(i.ratio)),void 0===i.anchorPoint?this.anchorPoint.set(0,0):"number"==typeof i.anchorPoint?this.anchorPoint.set(i.anchorPoint,i.anchorPoint):this.anchorPoint.setV(i.anchorPoint),Object.defineProperty(this,"repeat",{get:function(){return this._repeat},set:function(t){switch(this._repeat=t,this._repeat){case"no-repeat":this.repeatX=!1,this.repeatY=!1;break;case"repeat-x":this.repeatX=!0,this.repeatY=!1;break;case"repeat-y":this.repeatX=!1,this.repeatY=!0;break;default:this.repeatX=!0,this.repeatY=!0}this.resize(game$1.viewport.width,game$1.viewport.height),this.createPattern()},configurable:!0}),this.repeat=i.repeat||"repeat",event.subscribe(event.WEBGL_ONCONTEXT_RESTORED,this.createPattern.bind(this))},onActivateEvent:function(){var t=this.updateLayer.bind(this);this.vpChangeHdlr=event.subscribe(event.VIEWPORT_ONCHANGE,t),this.vpResizeHdlr=event.subscribe(event.VIEWPORT_ONRESIZE,this.resize.bind(this)),this.vpLoadedHdlr=event.subscribe(event.LEVEL_LOADED,(function(){t(game$1.viewport.pos)})),!0!==this.ancestor.root&&this.updateLayer(game$1.viewport.pos)},resize:function(t,e){this._super(Renderable,"resize",[this.repeatX?1/0:t,this.repeatY?1/0:e])},createPattern:function(){this._pattern=video$1.renderer.createPattern(this.image,this._repeat)},updateLayer:function(t){var e=this.ratio.x,i=this.ratio.y;if(0!==e||0!==i){var n=game$1.viewport,r=this.imagewidth,o=this.imageheight,s=n.bounds.width,a=n.bounds.height,h=this.anchorPoint.x,l=this.anchorPoint.y,u=h*(e-1)*(s-n.width)+this.offset.x-e*t.x,c=l*(i-1)*(a-n.height)+this.offset.y-i*t.y;this.repeatX?this.pos.x=u%r:this.pos.x=u,this.repeatY?this.pos.y=c%o:this.pos.y=c}},preDraw:function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())},draw:function(t){var e=game$1.viewport,i=this.imagewidth,n=this.imageheight,r=e.bounds.width,o=e.bounds.height,s=this.anchorPoint.x,a=this.anchorPoint.y,h=this.pos.x,l=this.pos.y;0===this.ratio.x&&0===this.ratio.y&&(h+=s*(r-i),l+=a*(o-n)),t.translate(h,l),t.drawPattern(this._pattern,0,0,2*e.width,2*e.height)},onDeactivateEvent:function(){event.unsubscribe(this.vpChangeHdlr),event.unsubscribe(this.vpResizeHdlr),event.unsubscribe(this.vpLoadedHdlr)},destroy:function(){pool.push(this.offset),this.offset=void 0,pool.push(this.ratio),this.ratio=void 0,this._super(Renderable,"destroy")}}),GUI_Object=Sprite.extend({init:function(t,e,i){this.isClickable=!0,this.holdThreshold=250,this.isHoldable=!1,this.hover=!1,this.holdTimeout=null,this.updated=!1,this.released=!0,this._super(Sprite,"init",[t,e,i]),this.floating=!0,this.isKinematic=!1},update:function(t){var e=this._super(Sprite,"update",[t]);return this.updated?(this.released||(this.updated=!1),!0):e},clicked:function(t){if(0===t.button&&this.isClickable)return this.updated=!0,this.released=!1,this.isHoldable&&(null!==this.holdTimeout&&timer$1.clearTimeout(this.holdTimeout),this.holdTimeout=timer$1.setTimeout(this.hold.bind(this),this.holdThreshold,!1),this.released=!1),this.onClick.call(this,t)},onClick:function(){return!1},enter:function(t){return this.hover=!0,this.onOver.call(this,t)},onOver:function(){},leave:function(t){return this.hover=!1,this.release.call(this,t),this.onOut.call(this,t)},onOut:function(){},release:function(t){if(!1===this.released)return this.released=!0,timer$1.clearTimeout(this.holdTimeout),this.onRelease.call(this,t)},onRelease:function(){return!1},hold:function(){timer$1.clearTimeout(this.holdTimeout),this.released||this.onHold.call(this)},onHold:function(){},onActivateEvent:function(){registerPointerEvent("pointerdown",this,this.clicked.bind(this)),registerPointerEvent("pointerup",this,this.release.bind(this)),registerPointerEvent("pointercancel",this,this.release.bind(this)),registerPointerEvent("pointerenter",this,this.enter.bind(this)),registerPointerEvent("pointerleave",this,this.leave.bind(this))},onDeactivateEvent:function(){releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),releasePointerEvent("pointerenter",this),releasePointerEvent("pointerleave",this),timer$1.clearTimeout(this.holdTimeout)}}),Collectable=Sprite.extend({init:function(t,e,i){this._super(Sprite,"init",[t,e,i]),this.name=i.name,this.type=i.type,this.id=i.id,this.body=new Body(this,i.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.COLLECTABLE_OBJECT,i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0)}}),Trigger=Renderable.extend({init:function(t,e,i){this._super(Renderable,"init",[t,e,i.width||0,i.height||0]),this.anchorPoint.set(0,0),this.fade=i.fade,this.duration=i.duration,this.fading=!1,this.name="Trigger",this.type=i.type,this.id=i.id,this.gotolevel=i.to,this.triggerSettings={event:"level"},["type","container","onLoaded","flatten","setViewportBounds","to"].forEach(function(t){void 0!==i[t]&&(this.triggerSettings[t]=i[t])}.bind(this)),this.body=new Body(this,i.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.ACTION_OBJECT,this.resize(this.body.getBounds().width,this.body.getBounds().height)},getTriggerSettings:function(){return"string"==typeof this.triggerSettings.container&&(this.triggerSettings.container=game$1.world.getChildByName(this.triggerSettings.container)[0]),this.triggerSettings},onFadeComplete:function(){level.load(this.gotolevel,this.getTriggerSettings()),game$1.viewport.fadeOut(this.fade,this.duration)},triggerEvent:function(){var t=this.getTriggerSettings();if("level"!==t.event)throw new Error("Trigger invalid type");this.gotolevel=t.to,this.fade&&this.duration?this.fading||(this.fading=!0,game$1.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))):level.load(this.gotolevel,t)},onCollision:function(){return"Trigger"===this.name&&this.triggerEvent.apply(this),!1}}),ParticleContainer=Container$1.extend({init:function(t){this._super(Container$1,"init",[game$1.viewport.pos.x,game$1.viewport.pos.y,game$1.viewport.width,game$1.viewport.height]),this.autoSort=!1,this._updateCount=0,this._dt=0,this._emitter=t,this.autoTransform=!1,this.anchorPoint.set(0,0),this.isKinematic=!0},update:function(t){if(++this._updateCount>this._emitter.framesToSkip&&(this._updateCount=0),this._updateCount>0)return this._dt+=t,!1;t+=this._dt,this._dt=0;for(var e=game$1.viewport,i=this.children.length-1;i>=0;--i){var n=this.children[i];n.inViewport=e.isVisible(n,this.floating),n.update(t)||this.removeChildNow(n)}return!0},draw:function(t,e){if(this.children.length>0){var i,n=t.getContext();this._emitter.textureAdditive&&(i=n.globalCompositeOperation,n.globalCompositeOperation="lighter"),this._super(Container$1,"draw",[t,e]),this._emitter.textureAdditive&&(n.globalCompositeOperation=i)}}}),pixel=(canvas=video$1.createCanvas(1,1),context=canvas.getContext("2d"),context.fillStyle="#fff",context.fillRect(0,0,1,1),canvas),canvas,context,ParticleEmitterSettings={width:0,height:0,image:pixel,totalParticles:50,angle:Math.PI/2,angleVariation:0,minLife:1e3,maxLife:3e3,speed:2,speedVariation:1,minRotation:0,maxRotation:0,minStartScale:1,maxStartScale:1,minEndScale:0,maxEndScale:0,gravity:0,wind:0,followTrajectory:!1,textureAdditive:!1,onlyInViewport:!0,floating:!1,maxParticles:10,frequency:100,duration:1/0,framesToSkip:0},ParticleEmitter=Renderable.extend({init:function(t,e,i){this._stream=!1,this._frequencyTimer=0,this._durationTimer=0,this._enabled=!1,this._super(Renderable,"init",[t,e,1/0,1/0]),this.alwaysUpdate=!0,this.autoSort=!1,this.container=new ParticleContainer(this),Object.defineProperty(this.pos,"z",{get:function(){return this.container.pos.z}.bind(this),set:function(t){this.container.pos.z=t}.bind(this),enumerable:!0,configurable:!0}),Object.defineProperty(this,"floating",{get:function(){return this.container.floating},set:function(t){this.container.floating=t},enumerable:!0,configurable:!0}),this.reset(i)},onActivateEvent:function(){this.ancestor.addChild(this.container),this.container.pos.z=this.pos.z,this.ancestor.autoSort||this.ancestor.sort()},onDeactivateEvent:function(){this.ancestor.hasChild(this.container)&&this.ancestor.removeChildNow(this.container)},destroy:function(){this.reset()},getRandomPointX:function(){return this.pos.x+randomFloat(0,this.width)},getRandomPointY:function(){return this.pos.y+randomFloat(0,this.height)},reset:function(t){var e=ParticleEmitterSettings,i="number"==typeof(t=t||{}).width?t.width:e.width,n="number"==typeof t.height?t.height:e.height;this.resize(i,n),Object.assign(this,e,t),this.container.reset()},addParticles:function(t){for(var e=0;e<~~t;e++){var i=pool.pull("Particle",this);this.container.addChild(i)}},isRunning:function(){return this._enabled&&this._stream},streamParticles:function(t){this._enabled=!0,this._stream=!0,this.frequency=Math.max(this.frequency,1),this._durationTimer="number"==typeof t?t:this.duration},stopStream:function(){this._enabled=!1},burstParticles:function(t){this._enabled=!0,this._stream=!1,this.addParticles("number"==typeof t?t:this.totalParticles),this._enabled=!1},update:function(t){if(this._enabled&&this._stream){if(this._durationTimer!==1/0&&(this._durationTimer-=t,this._durationTimer<=0))return this.stopStream(),!1;this._frequencyTimer+=t;var e=this.container.children.length;e<this.totalParticles&&this._frequencyTimer>=this.frequency&&(e+this.maxParticles<=this.totalParticles?this.addParticles(this.maxParticles):this.addParticles(this.totalParticles-e),this._frequencyTimer=0)}return!0}}),Particle=Renderable.extend({init:function(t){this._super(Renderable,"init",[t.getRandomPointX(),t.getRandomPointY(),t.image.width,t.image.height]),this.alwaysUpdate=!0,this.image=t.image;var e=t.angle+(t.angleVariation>0?(randomFloat(0,2)-1)*t.angleVariation:0),i=t.speed+(t.speedVariation>0?(randomFloat(0,2)-1)*t.speedVariation:0);this.vel=new Vector2d(i*Math.cos(e),-i*Math.sin(e)),this.life=randomFloat(t.minLife,t.maxLife),this.startLife=this.life,this.startScale=clamp(randomFloat(t.minStartScale,t.maxStartScale),t.minStartScale,t.maxStartScale),this.endScale=clamp(randomFloat(t.minEndScale,t.maxEndScale),t.minEndScale,t.maxEndScale),this.gravity=t.gravity,this.wind=t.wind,this.followTrajectory=t.followTrajectory,this.onlyInViewport=t.onlyInViewport,this.pos.z=t.z,this._deltaInv=timer$1.maxfps/1e3,t.followTrajectory||(this.angle=randomFloat(t.minRotation,t.maxRotation))},update:function(t){var e=t*this._deltaInv;this.life=this.life>t?this.life-t:0;var i=this.life/this.startLife,n=this.startScale;this.startScale>this.endScale?n=(n*=i)<this.endScale?this.endScale:n:this.startScale<this.endScale&&(n=(n/=i)>this.endScale?this.endScale:n),this.alpha=i,this.vel.x+=this.wind*e,this.vel.y+=this.gravity*e;var r=this.followTrajectory?Math.atan2(this.vel.y,this.vel.x):this.angle;return this.pos.x+=this.vel.x*e,this.pos.y+=this.vel.y*e,this.currentTransform.setTransform(n,0,0,0,n,0,this.pos.x,this.pos.y,1).rotate(r),(this.inViewport||!this.onlyInViewport)&&this.life>0},preDraw:function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.alpha),t.transform(this.currentTransform)},draw:function(t){var e=this.width,i=this.height;t.drawImage(this.image,0,0,e,i,-e/2,-i/2,e,i)}}),Entity=Renderable.extend({init:function(t,e,i){if(this.children=[],"number"!=typeof i.width||"number"!=typeof i.height)throw new Error("height and width properties are mandatory when passing settings parameters to an object entity");this._super(Renderable,"init",[t,e,i.width,i.height]),i.image&&(i.framewidth=i.framewidth||i.width,i.frameheight=i.frameheight||i.height,this.renderable=new Sprite(0,0,i)),i.anchorPoint?this.anchorPoint.set(i.anchorPoint.x,i.anchorPoint.y):this.anchorPoint.set(0,0),"string"==typeof i.name&&(this.name=i.name),this.type=i.type||"",this.id=i.id||"",this.alive=!0,void 0===i.shapes&&(i.shapes=new Polygon(0,0,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])),void 0!==this.body?this.body.init(this,i.shapes,this.onBodyUpdate.bind(this)):this.body=new Body(this,i.shapes,this.onBodyUpdate.bind(this)),0===this.width&&0===this.height&&this.resize(this.body.getBounds().width,this.body.getBounds().height),this.body.setCollisionMask(i.collisionMask),this.body.setCollisionType(i.collisionType),this.autoTransform=!1},update:function(t){return this.renderable?this.renderable.update(t):this._super(Renderable,"update",[t])},onBodyUpdate:function(t){this.getBounds().addBounds(t.getBounds(),!0),this.updateBoundsPos(this.pos.x,this.pos.y)},preDraw:function(t){t.save(),t.translate(this.pos.x+this.body.getBounds().x,this.pos.y+this.body.getBounds().y),this.renderable instanceof Renderable&&t.translate(this.anchorPoint.x*this.body.getBounds().width,this.anchorPoint.y*this.body.getBounds().height)},draw:function(t,e){var i=this.renderable;i instanceof Renderable&&(i.preDraw(t),i.draw(t,e),i.postDraw(t))},destroy:function(){this.renderable&&(this.renderable.destroy.apply(this.renderable,arguments),this.children.splice(0,1)),this._super(Renderable,"destroy",arguments)},onDeactivateEvent:function(){this.renderable&&this.renderable.onDeactivateEvent&&this.renderable.onDeactivateEvent()},onCollision:function(){return!1}});Object.defineProperty(Entity.prototype,"renderable",{get:function(){return this.children[0]},set:function(t){if(!(t instanceof Renderable))throw new Error(t+"should extend me.Renderable");this.children[0]=t,this.children[0].ancestor=this},configurable:!0});var DraggableEntity=Entity.extend({init:function(t,e,i){this._super(Entity,"init",[t,e,i]),this.dragging=!1,this.dragId=null,this.grabOffset=new Vector2d(0,0),this.onPointerEvent=registerPointerEvent,this.removePointerEvent=releasePointerEvent,this.initEvents()},initEvents:function(){var t=this;this.mouseDown=function(t){this.translatePointerEvent(t,event.DRAGSTART)},this.mouseUp=function(t){this.translatePointerEvent(t,event.DRAGEND)},this.onPointerEvent("pointerdown",this,this.mouseDown.bind(this)),this.onPointerEvent("pointerup",this,this.mouseUp.bind(this)),this.onPointerEvent("pointercancel",this,this.mouseUp.bind(this)),event.subscribe(event.POINTERMOVE,this.dragMove.bind(this)),event.subscribe(event.DRAGSTART,(function(e,i){i===t&&t.dragStart(e)})),event.subscribe(event.DRAGEND,(function(e,i){i===t&&t.dragEnd(e)}))},translatePointerEvent:function(t,e){event.publish(e,[t,this])},dragStart:function(t){if(!1===this.dragging)return this.dragging=!0,this.grabOffset.set(t.gameX,t.gameY),this.grabOffset.sub(this.pos),!1},dragMove:function(t){!0===this.dragging&&(this.pos.set(t.gameX,t.gameY,this.pos.z),this.pos.sub(this.grabOffset))},dragEnd:function(){if(!0===this.dragging)return this.dragging=!1,!1},destroy:function(){event.unsubscribe(event.POINTERMOVE,this.dragMove),event.unsubscribe(event.DRAGSTART,this.dragStart),event.unsubscribe(event.DRAGEND,this.dragEnd),this.removePointerEvent("pointerdown",this),this.removePointerEvent("pointerup",this)}}),DroptargetEntity=Entity.extend({init:function(t,e,i){this.CHECKMETHOD_OVERLAP="overlaps",this.CHECKMETHOD_CONTAINS="contains",this.checkMethod=null,this._super(Entity,"init",[t,e,i]),event.subscribe(event.DRAGEND,this.checkOnMe.bind(this)),this.checkMethod=this[this.CHECKMETHOD_OVERLAP]},setCheckMethod:function(t){void 0!==this[t]&&(this.checkMethod=this[t])},checkOnMe:function(t,e){e&&this.checkMethod(e.getBounds())&&this.drop(e)},drop:function(){},destroy:function(){event.unsubscribe(event.DRAGEND,this.checkOnMe)}}),Jay=window.Jay,version="9.0.1";exports.initialized=!1;var skipAutoInit=!1;function boot(){!0!==exports.initialized&&(device$1._check(),pool.register("me.Entity",Entity),pool.register("me.Collectable",Collectable),pool.register("me.Trigger",Trigger),pool.register("me.Tween",Tween,!0),pool.register("me.Color",Color,!0),pool.register("me.Particle",Particle,!0),pool.register("me.Sprite",Sprite),pool.register("me.Renderable",Renderable),pool.register("me.Text",Text,!0),pool.register("me.BitmapText",BitmapText,!0),pool.register("me.BitmapTextData",BitmapTextData,!0),pool.register("me.ImageLayer",ImageLayer,!0),pool.register("me.ColorLayer",ColorLayer,!0),pool.register("me.Vector2d",Vector2d,!0),pool.register("me.Vector3d",Vector3d,!0),pool.register("me.ObservableVector2d",ObservableVector2d,!0),pool.register("me.ObservableVector3d",ObservableVector3d,!0),pool.register("me.Matrix2d",Matrix2d,!0),pool.register("me.Matrix3d",Matrix3d,!0),pool.register("me.Rect",Rect,!0),pool.register("me.Polygon",Polygon,!0),pool.register("me.Line",Line,!0),pool.register("me.Ellipse",Ellipse,!0),pool.register("me.Bounds",Bounds$1,!0),pool.register("Entity",Entity),pool.register("Collectable",Collectable),pool.register("Trigger",Trigger),pool.register("Tween",Tween,!0),pool.register("Color",Color,!0),pool.register("Particle",Particle,!0),pool.register("Sprite",Sprite),pool.register("Renderable",Renderable),pool.register("Text",Text,!0),pool.register("BitmapText",BitmapText,!0),pool.register("BitmapTextData",BitmapTextData,!0),pool.register("ImageLayer",ImageLayer,!0),pool.register("ColorLayer",ColorLayer,!0),pool.register("Vector2d",Vector2d,!0),pool.register("Vector3d",Vector3d,!0),pool.register("ObservableVector2d",ObservableVector2d,!0),pool.register("ObservableVector3d",ObservableVector3d,!0),pool.register("Matrix2d",Matrix2d,!0),pool.register("Matrix3d",Matrix3d,!0),pool.register("Rect",Rect,!0),pool.register("Polygon",Polygon,!0),pool.register("Line",Line,!0),pool.register("Ellipse",Ellipse,!0),pool.register("Bounds",Bounds$1,!0),save.init(),timer$1.init(),loader$1.setNocache(utils$1.getUriFragment().nocache||!1),state$1.init(),initKeyboardEvent(),game$1.init(),exports.initialized=!0)}device$1.onReady((function(){boot()})),exports.BitmapText=BitmapText,exports.BitmapTextData=BitmapTextData,exports.Body=Body,exports.Bounds=Bounds$1,exports.Camera2d=Camera2d,exports.CanvasRenderer=CanvasRenderer,exports.Collectable=Collectable,exports.Color=Color,exports.ColorLayer=ColorLayer,exports.Container=Container$1,exports.DraggableEntity=DraggableEntity,exports.DroptargetEntity=DroptargetEntity,exports.Ellipse=Ellipse,exports.Entity=Entity,exports.GLShader=GLShader,exports.GUI_Object=GUI_Object,exports.ImageLayer=ImageLayer,exports.Line=Line,exports.Math=math,exports.Matrix2d=Matrix2d,exports.Matrix3d=Matrix3d,exports.Object=Jay,exports.ObservableVector2d=ObservableVector2d,exports.ObservableVector3d=ObservableVector3d,exports.Particle=Particle,exports.ParticleEmitter=ParticleEmitter,exports.Pointer=Pointer,exports.Polygon=Polygon,exports.QuadTree=QuadTree,exports.Rect=Rect,exports.Renderable=Renderable,exports.Renderer=Renderer,exports.Sprite=Sprite,exports.Stage=Stage,exports.TMXHexagonalRenderer=TMXHexagonalRenderer,exports.TMXIsometricRenderer=TMXIsometricRenderer,exports.TMXLayer=TMXLayer,exports.TMXOrthogonalRenderer=TMXOrthogonalRenderer,exports.TMXRenderer=TMXRenderer,exports.TMXStaggeredRenderer=TMXStaggeredRenderer,exports.TMXTileMap=TMXTileMap,exports.TMXTileset=TMXTileset,exports.TMXTilesetGroup=TMXTilesetGroup,exports.Text=Text,exports.Tile=Tile,exports.Trigger=Trigger,exports.Tween=Tween,exports.Vector2d=Vector2d,exports.Vector3d=Vector3d,exports.WebGLCompositor=WebGLCompositor,exports.WebGLRenderer=WebGLRenderer,exports.World=World,exports.audio=audio$1,exports.boot=boot,exports.collision=collision,exports.deprecated=deprecated,exports.device=device$1,exports.event=event,exports.game=game$1,exports.input=input,exports.level=level,exports.loader=loader$1,exports.plugin=plugin,exports.plugins=plugins,exports.pool=pool,exports.save=save,exports.skipAutoInit=skipAutoInit,exports.state=state$1,exports.timer=timer$1,exports.utils=utils$1,exports.version=version,exports.video=video$1,Object.defineProperty(exports,"__esModule",{value:!0})})),me.deprecated.apply();