angry-pixel 1.2.14 → 1.2.15
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.
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/package.test.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),e=function(){function e(e,i,n,o){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,o)}return Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),e.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},e.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},e.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},e.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},e.prototype.contains=function(i){return i instanceof e?i.x1<=this.x1&&i.x>=this.x&&i.y1<=this.y1&&i.y>=this.y:i instanceof t&&!(i.x<this.x||i.y<this.y||i.x>=this.x1||i.y>=this.y1)},e}(),i=function(t,e,i){return Math.min(i,Math.max(e,t))},n=function(t,e){return Math.round(Math.random()*(e-t))+t},o=function(t,e,i){return void 0===i&&(i=2),r(Math.random()*(e-t)+t,i)},r=function(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},s=function(t,e,i){void 0===i&&(i=1);for(var n=[],o=t;o<=e;o+=i)n.push(o);return n},a=function(t,e,i){return t>=e&&t<=i},h=function(){function e(e,i){void 0===e&&(e=null),void 0===i&&(i=null),this._degrees=0,this._radians=0,this._direction=new t,e?this.radians=e:i&&(this.degrees=i)}return Object.defineProperty(e.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),e.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},e}(),c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},c(t,e)};function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l,p=function(){return p=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},p.apply(this,arguments)};function d(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Init=0]="Init",t[t.Start=1]="Start",t[t.Update=2]="Update",t[t.UpdateEngine=3]="UpdateEngine",t[t.UpdateCollider=4]="UpdateCollider",t[t.UpdatePhysics=5]="UpdatePhysics",t[t.UpdateTransform=6]="UpdateTransform",t[t.UpdatePreRender=7]="UpdatePreRender",t[t.UpdateCamera=8]="UpdateCamera",t[t.UpdateRender=9]="UpdateRender",t[t.Destroy=10]="Destroy",t[t.StopGame=11]="StopGame"}(l||(l={}));var f,g,y,m=function(){function t(t,e,i,n,o,r,s){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=o,this.sceneManager=r,this.canvasColor=s,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[l.Start,l.Update,l.StopGame],this.gameObjectEvents=[l.Start,l.Update]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.dispatchFrameEvent(l.StopGame),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene()),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(l.Start),this.inputManager.update(),this.dispatchFrameEvent(l.Update),this.dispatchFrameEvent(l.UpdateEngine),this.dispatchFrameEvent(l.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(l.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(l.UpdatePreRender),this.dispatchFrameEvent(l.UpdateCamera),this.dispatchFrameEvent(l.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(l.UpdatePhysics),this.dispatchFrameEvent(l.UpdateCollider),this.dispatchFrameEvent(l.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),v=function(){function t(t){this.updateEvent=l.Update,this.started=!1,this.container=t,this.gameConfig=this.container.getConstant("GameConfig"),this.gameConfig.headless||(this.assetManager=this.container.getSingleton("AssetManager"),this.domManager=this.container.getSingleton("DomManager"),this.inputManager=this.container.getSingleton("InputManager"),this.renderManager=this.container.getSingleton("RenderManager")),this.gameObjectManager=this.container.getSingleton("GameObjectManager"),this.physicsManager=this.container.getSingleton("PhysicsManager"),this.sceneManager=this.container.getSingleton("SceneManager"),this.timeManager=this.container.getSingleton("TimeManager")}return t.prototype.dispatch=function(t,e){t===l.Init&&this.init?this.init(e):t!==l.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===l.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===l.StopGame&&(this.onDestroy&&this.onDestroy(),this._stopGame()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),b=function(t){function e(e,i,n){void 0===n&&(n="");var o=t.call(this,e)||this;return o.allowMultiple=!0,o._active=!0,o.gameObject=i,o.name=n,o}return u(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChange())},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getLoadedScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){},e}(v),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateEngine,e}return u(e,t),e}(b),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateCollider,e}return u(e,t),e}(b),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdatePhysics,e}return u(e,t),e}(b),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateTransform,e}return u(e,t),e}(b),j=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdatePreRender,e}return u(e,t),e}(b),P=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateCamera,e}return u(e,t),e}(b),O=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateRender,e}return u(e,t),e}(b);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(f||(f={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(g||(g={})),function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric",t[t.Video=5]="Video"}(y||(y={}));var C=function(){function t(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}return t.prototype.setViewport=function(t,e){var i=t.position,n=t.zoom;e===g.WorldSpace?(this.viewport.x=i.x-this.gl.canvas.width/n/2,this.viewport.x1=i.x+this.gl.canvas.width/n/2,this.viewport.y=i.y-this.gl.canvas.height/n/2,this.viewport.y1=i.y+this.gl.canvas.height/n/2):(this.viewport.x=-this.gl.canvas.width/2,this.viewport.x1=this.gl.canvas.width/2,this.viewport.y=-this.gl.canvas.height/2,this.viewport.y1=this.gl.canvas.height/2)},t.prototype.setObjectForResizeable=function(t){var e=t.position,i=t.width,n=t.height,o=t.rotation,r=void 0===o?0:o,s=Math.abs(Math.sin(r)),a=Math.abs(Math.cos(r)),h=s*n+a*i,c=s*i+a*n;this.object.x=e.x-h/2,this.object.x1=e.x+h/2,this.object.y=e.y-c/2,this.object.y1=e.y+c/2},t.prototype.setObjectForText=function(t){var e=t.position,i=t.text,n=t.fontSize,o=t.lineSeparation,r=t.letterSpacing,s=t.rotation,a=i.split("\n").reduce((function(t,e){return Math.max(t,e.length)}),0)*(n+(null!=r?r:0))*2,h=i.split("\n").length*(n+(null!=o?o:0));this.setObjectForResizeable({position:e,width:a,height:h,rotation:s})},t.prototype.setObjectForGeometric=function(t){var e=this,i=t.position,n=t.vertexModel,o=t.shape,r=t.radius;o===f.Circumference?(this.object.x=i.x-r,this.object.y=i.y-r,this.object.x1=i.x+r,this.object.y1=i.y+r):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,n.forEach((function(t){e.object.x=Math.min(t.x+i.x,e.object.x),e.object.y=Math.min(t.y+i.y,e.object.y),e.object.x1=Math.max(t.x+i.x,e.object.x1),e.object.y1=Math.max(t.y+i.y,e.object.y1)})))},t.prototype.setObjectForTilemap=function(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.renderPosition,width:t.tilemap.width*t.tilemap.tileWidth,height:t.tilemap.height*t.tilemap.tileHeight,rotation:t.rotation})},t.prototype.applyCullingInTiles=function(t){var e=this,i=t.tiles,n=t.tilemap,o=n.width,r=n.tileWidth,s=n.tileHeight;t.culledTiles=i.map((function(t,i){return e.viewport.x1>=e.object.x+i%o*r&&e.viewport.x<=e.object.x+i%o*r+r&&e.viewport.y1>=e.object.y1-((i/o|0)*s+s)&&e.viewport.y<=e.object.y1-(i/o|0)*s?t:0}))},t.prototype.isInViewPort=function(t,e){switch(this.setViewport(e,t.location),t.type){case y.Video:case y.Mask:case y.Sprite:this.setObjectForResizeable(t);break;case y.Geometric:this.setObjectForGeometric(t);break;case y.Text:this.setObjectForText(t);break;case y.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1},t.prototype.applyCulling=function(t,e){var i=this;return e.filter((function(e){return!!i.isInViewPort(e,t)&&(e.type===y.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),A=function(){return A=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},A.apply(this,arguments)};function R(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var S,E=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new E,this._center=new E,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof E&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new E,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}(),function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(S||(S={}));var T,D=function(){function t(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}return t.prototype.addRenderData=function(t){this.renderData.push(t)},t.prototype.addCameraData=function(t){this.cameraData.push(t)},t.prototype.render=function(){var t=this;this.cameraData.sort((function(t,e){return t.depth-e.depth})).forEach((function(e){return t.renderByCamera(e)}))},t.prototype.renderByCamera=function(t){var e=this;this.cullingManager.applyCulling(t,this.renderData.filter((function(e){return t.layers.includes(e.layer)})).sort((function(e,i){return t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer)})).map((function(t){return t.type===y.Tilemap?function(t){var e=A(A({},t),{culledTiles:[],tilemap:A(A({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new E});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==S.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===S.RightDown?-t.tilemap.realHeight/2:t.orientation===S.RightUp?t.tilemap.realHeight/2:0))}(e),e}(t):t}))).forEach((function(i){return e.webglManager.render(i,t)}))},t.prototype.clearData=function(){this.renderData=[],this.cameraData=[]},t.prototype.clearScreen=function(t){this.webglManager.clearCanvas(t)},t.prototype.preloadTexture=function(t){this.webglManager.createTexture(t)},t}();!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(T||(T={}));var B=function(){function t(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}return t.prototype.getContextVersion=function(){return null!==this.canvas.getContext(T.WebGL2)?T.WebGL2:null!==this.canvas.getContext(T.LegacyWebGL)?T.LegacyWebGL:void 0},t}(),F=function(){function t(){this.fontAtlas=new Map}return t.prototype.hasFontAtlas=function(t){return this.fontAtlas.has(this.symbol(t))},t.prototype.getFontAtlas=function(t){return this.fontAtlas.get(this.symbol(t))},t.prototype.getOrCreate=function(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)},t.prototype.create=function(t,e,i){this.bitmapSize=i,this.chars=[];for(var n=0;n<t.length;n+=2)for(var o=t[n];o<=t[n+1];o++)this.chars.push(String.fromCharCode(o));var r=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),r),r},t.prototype.symbol=function(t){return Symbol.for(t instanceof FontFace?t.family:t)},t.prototype.renderAtlas=function(t){var e=new I(t,this.bitmapSize,Math.ceil(Math.sqrt(this.chars.length))),i=e.canvas.getContext("2d");i.clearRect(0,0,e.canvas.width,e.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font="".concat(this.bitmapSize,"px ").concat(t);for(var n=0,o=0,r=0;r<this.chars.length;r++)i.fillText(this.chars[r],n,o),e.glyphs.set(this.chars[r],{id:r,width:i.measureText(this.chars[r]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,o+=this.bitmapSize);return e},t}(),I=function(t,e,i){this.fontFaceFamily=t,this.bitmapFontSize=e,this.gridSize=i,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*this.bitmapFontSize,this.canvas.height=this.canvas.width},U=function(){function t(t,e){this.gl=t,this.shaderLoader=e}return t.prototype.create=function(t,e){var i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,o),this.gl.linkProgram(i);var r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){var s=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error("Unable to initialize the Program: ".concat(s))}return i},t}(),L=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===T.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision highp float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)},t}(),k=function(){function t(t){this.gl=t}return t.prototype.load=function(t,e){var i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);var n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){var o=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error("Unable to initialize the shader program: ".concat(o))}return i},t}(),V="undefined"!=typeof Float32Array?Float32Array:Array;function G(){var t=new V(16);return V!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function H(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function W(t,e,i){var n,o,r,s,a,h,c,u,l,p,d,f,g=i[0],y=i[1],m=i[2];return e===t?(t[12]=e[0]*g+e[4]*y+e[8]*m+e[12],t[13]=e[1]*g+e[5]*y+e[9]*m+e[13],t[14]=e[2]*g+e[6]*y+e[10]*m+e[14],t[15]=e[3]*g+e[7]*y+e[11]*m+e[15]):(n=e[0],o=e[1],r=e[2],s=e[3],a=e[4],h=e[5],c=e[6],u=e[7],l=e[8],p=e[9],d=e[10],f=e[11],t[0]=n,t[1]=o,t[2]=r,t[3]=s,t[4]=a,t[5]=h,t[6]=c,t[7]=u,t[8]=l,t[9]=p,t[10]=d,t[11]=f,t[12]=n*g+a*y+l*m+e[12],t[13]=o*g+h*y+p*m+e[13],t[14]=r*g+c*y+d*m+e[14],t[15]=s*g+u*y+f*m+e[15]),t}function z(t,e,i){var n=i[0],o=i[1],r=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function X(t,e,i){var n=Math.sin(i),o=Math.cos(i),r=e[0],s=e[1],a=e[2],h=e[3],c=e[4],u=e[5],l=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*o+c*n,t[1]=s*o+u*n,t[2]=a*o+l*n,t[3]=h*o+p*n,t[4]=c*o-r*n,t[5]=u*o-s*n,t[6]=l*o-a*n,t[7]=p*o-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var Y,N=function(t){var e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},q=function(t,e,i,n){var o,r;(function(t,e,i,n,o,r,s){var a=1/(e-i),h=1/(n-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=(e+i)*a,t[13]=(o+n)*h,t[14]=-0,t[15]=1})(t=H(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===g.WorldSpace&&(z(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1]),W(t,t,[-i.position.x,-i.position.y,0]))},K=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G();var i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(function(t,e,i){void 0===i&&(i=1);for(var n=[],o=1;o<=60;o+=i)n.push(o);return n}(0,0,1).reduce((function(t,e){return R(R([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case f.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case f.Line:this.renderLines(t,e,this.gl.LINES,i);break;case f.Circumference:this.renderCircumference(t,e)}},t.prototype.renderLines=function(t,e,i,n){var o,r=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(r)&&this.vertices.set(r,new Float32Array(this.generatePolygonVertices(t.vertexModel)));var s=this.vertices.get(r);this.lastVertices===r&&n===y.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW)),this.lastVertices=r,this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var a=N(t.color),h=a.r,c=a.g,u=a.b,l=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,c,u,l),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)},t.prototype.generateVerticesKey=function(t){return Symbol.for(t.reduce((function(t,e){return"".concat(t).concat(e.x).concat(e.y)}),t.length.toString()))},t.prototype.generatePolygonVertices=function(t){for(var e=[],i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e},t.prototype.renderCircumference=function(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),z(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var i=N(t.color),n=i.r,o=i.g,r=i.b,s=i.a;this.gl.uniform4f(this.programManager.solidColorUniform,n,o,r,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)},t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Y||(Y={}));var Q,$=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=y.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G();for(var i=2*Math.PI/60,n=[0,0],o=0;o<=60;o++)n.push(Math.cos(o*i),Math.sin(o*i));this.circumferenceVertices=new Float32Array(n)}return t.prototype.render=function(t,e,i){var n,o;i===y.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===Y.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,t.shape===Y.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha>=0&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var r=N(t.color),s=r.r,a=r.g,h=r.b,c=r.a;this.gl.uniform4f(this.programManager.solidColorUniform,s,a,h,c),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),t.shape===Y.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape},t}(),J=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,o,r,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),t.slice&&(W(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}();!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Q||(Q={}));var Z=new E,tt=new E,et=[32,126,161,255],it=Q.Center,nt=function(){function t(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=y.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new E,this.modelPosition=new E,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G()}return t.prototype.render=function(t,e,i){var n;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);var o=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(o,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),this.setPositionFromOrientation(t),W(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=H(this.textureMatrix),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);var r=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+o.fontFaceFamily,o.canvas,t.smooth);this.lastTexture===r&&i===y.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=r),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);var s=N(t.color),a=s.r,h=s.g,c=s.b,u=s.a;this.gl.uniform4f(this.programManager.maskColorUniform,a,h,c,u),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.setDefaultValues=function(t){var e,i,n,o,r,s,a,h,c,u;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:Z,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:tt,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(o=t.bitmap.charRanges)&&void 0!==o?o:et):t.bitmap={margin:Z,spacing:tt,fontSize:64,charRanges:et},t.color=null!==(r=t.color)&&void 0!==r?r:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(c=t.orientation)&&void 0!==c?c:it,t.rotation=null!==(u=t.rotation)&&void 0!==u?u:0},t.prototype.generateTextVertices=function(t,e){var i=e.text,n=e.fontSize,o=e.bitmap,r=e.letterSpacing,s=e.lineSeparation;this.posVertices=[],this.texVertices=[];var a=0,h=0,c=0;r/=n,s/=n;for(var u=0;u<i.length;u++){var l=i[u];if("\n"!==l){var p=t.glyphs.get(l);if(p){var d=p.width/t.bitmapFontSize;this.posVertices.push(a,h-1,a+d,h-1,a,h,a,h,a+d,h-1,a+d,h);var f=p.id%t.gridSize*t.bitmapFontSize,g=(p.id/t.gridSize|0)*t.bitmapFontSize,y=(f+o.margin.x)/t.canvas.width,m=(g+o.margin.y)/t.canvas.width,v=(f+p.width+o.spacing.x)/t.canvas.width,b=(g+t.bitmapFontSize+o.spacing.y)/t.canvas.width;this.texVertices.push(y,b,v,b,y,m,y,m,v,b,v,m),a+=d+r}}else c=Math.max(c,a),a=0,h-=1+s}this.textSize.set(Math.max(c,a)*n,Math.abs(h-1)*n)},t.prototype.setPositionFromOrientation=function(t){this.modelPosition.set(t.position.x+(t.orientation===Q.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Q.Center||t.orientation===Q.RightCenter?this.textSize.y/2:t.orientation===Q.RightUp?this.textSize.y:0))},t}(),ot=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.tileset={width:0,tileWidth:0,tileHeight:0,texMargin:new E,texSpacing:new E,texWidth:0,texHeight:0,texCorrection:new E},this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G()}return t.prototype.render=function(t,e,i){var n,o,r,s;if(0===t.culledTiles.reduce((function(t,e){return t+e}),0))throw new Error("Nothing to render");if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)throw new Error("Nothing to render");this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),z(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===y.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.processTileset=function(t){var e,i,n,o,r,s,a,h=t.tileset;h.margin=null!==(e=h.margin)&&void 0!==e?e:new E,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new E,h.correction=null!==(n=h.correction)&&void 0!==n?n:new E,this.tileset.width=h.width,this.tileset.tileWidth=h.tileWidth+(null!==(o=h.margin.x)&&void 0!==o?o:0)+(null!==(r=h.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=h.tileHeight+(null!==(s=h.margin.y)&&void 0!==s?s:0)+(null!==(a=h.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(h.margin.x/this.tileset.tileWidth,h.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(h.spacing.x/this.tileset.tileWidth,h.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(h.correction.x/this.tileset.tileWidth,h.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y},t.prototype.generateVertices=function(t){var e=this,i=t.culledTiles,n=t.tilemap;this.posVertices=[],this.texVertices=[];var o=Math.floor(i.length/n.width);i.forEach((function(t,i){if(0!==t){var r=i%n.width-n.width/2,s=o/2-Math.floor(i/n.width);e.posVertices.push(r,s-1,r+1,s-1,r,s,r,s,r+1,s-1,r+1,s);var a=(t-1)%e.tileset.width+e.tileset.texMargin.x+e.tileset.texCorrection.x,h=Math.floor((t-1)/e.tileset.width)+e.tileset.texMargin.y+e.tileset.texCorrection.y;e.texVertices.push(a,h+e.tileset.texHeight,a+e.tileset.texWidth,h+e.tileset.texHeight,a,h,a,h,a+e.tileset.texWidth,h+e.tileset.texHeight,a+e.tileset.texWidth,h)}}))},t}(),rt=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,o,r,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),t.slice&&(W(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),st=function(){function t(t){this.gl=t}return t.prototype.createFromImage=function(t,e,i){var n=this;return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(function(){return n.createFromSource(t,i,e)})),i},t.prototype.createFromCanvas=function(t,e,i){return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i},t.prototype.createPixelTexture=function(){var t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t},t.prototype.createFromSource=function(t,e,i){void 0===i&&(i=!0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)},t}(),at=function(){function t(t){this.textureFactory=t,this.textures=new Map}return t.prototype.getOrCreateTextureFromImage=function(t,e){var i;return void 0===e&&(e=!0),null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)},t.prototype.createTextureFromImage=function(t,e){void 0===e&&(e=!0);var i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i},t.prototype.getOrCreateTextureFromCanvas=function(t,e,i){var n;return void 0===i&&(i=!0),null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)},t.prototype.createTextureFromCanvas=function(t,e,i){void 0===i&&(i=!0);var n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n},t.prototype.getOrCreateTextureFromVideo=function(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)},t.prototype.createTextureFromVideo=function(t){var e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e},t}(),ht=function(){function t(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}return t.prototype.render=function(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}},t.prototype.clearCanvas=function(t){var e=N(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.createTexture=function(t,e){void 0===e&&(e=!1),this.textureManager.createTextureFromImage(t,e)},t}(),ct=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),ut=function(){function t(t,e,i,n){this._position=new ct,this._center=new ct,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ct&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),lt=function(t,e,i){return Math.min(i,Math.max(e,t))};!function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ct,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var pt,dt=function(){function t(){}return t.prototype.create=function(t){var e=t.shape,i=t.layer,n=t.updateCollisions,o=t.physics,r=t.position,s=t.rotation,a=t.group,h=t.onCollision;return{id:0,active:!0,layer:i,shape:e,updateCollisions:n,physics:o,position:null!=r?r:new ct,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),ft=function(){function t(t,e){void 0===e&&(e=0),this.area=new ut(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}return t.prototype.resize=function(t){this.clear(),this.area.copy(t)},t.prototype.clear=function(){this.items=[],this.children.forEach((function(t){return t.clear()})),this.children=[]},t.prototype.insert=function(t,e){0===this.children.length&&this.items.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.items.push([t,e])},t.prototype.split=function(){var e=this,i=this.area.width/2,n=this.area.height/2;this.children=[new ut(this.area.x,this.area.y,i,n),new ut(this.area.x,this.area.y+n,i,n),new ut(this.area.x+i,this.area.y+n,i,n),new ut(this.area.x+i,this.area.y,i,n)].map((function(i){return new t(i,e.depth+1)})),this.items.forEach((function(t){return e.insertItemIntoChildren(t[0],t[1])})),this.items=[]},t.prototype.insertItemIntoChildren=function(t,e){this.getChildrenForArea(e).forEach((function(i){return i.insert(t,e)}))},t.prototype.retrieve=function(t){var e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})):this.items.forEach((function(t){return e.push(t[0])})),e},t.prototype.getChildrenForArea=function(t){var e=[];return t.x<=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[0]),t.x<=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[1]),t.x1>=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[2]),t.x1>=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[3]),e},t}(),gt=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},yt=function(){function t(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}return Object.defineProperty(t.prototype,"subdivisions",{get:function(){return this._subdivisions},set:function(t){this._subdivisions=lt(t,1,20)},enumerable:!1,configurable:!0}),t.prototype.resize=function(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(var e=0;e<this._subdivisions;e++){this.itemsInCells[e]=[];for(var i=0;i<this._subdivisions;i++)this.itemsInCells[e][i]=[]}},t.prototype.clear=function(){for(var t=0;t<this._subdivisions;t++)for(var e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]},t.prototype.insert=function(t,e){this.updateCoordinates(e);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].push(t)},t.prototype.retrieve=function(t){var e=[];this.updateCoordinates(t);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].forEach((function(t){return e.includes(t)?null:e.push(t)}));return e},t.prototype.updateCoordinates=function(t){this.coordinates.x0=gt(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=gt(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=gt(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=gt(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(pt||(pt={}));var mt,vt=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new ct,this.maxArea=new ct,this.newArea=new ut(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:pt.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new ut(0,0,0,0),this.fixedCollisionArea=!!e,t===pt.SpartialGrid?this.broadPhaseResolver=new yt(this.collisionArea):this.broadPhaseResolver=new ft(this.collisionArea)},t.prototype.addCollider=function(t){t.id=this.colliders.length,this.colliders.push(t)},t.prototype.getCollider=function(t){return this.colliders[t]},t.prototype.removeCollider=function(t){this.colliders.splice(t.id,1),this.colliders.forEach((function(t,e){return t.id=e}))},t.prototype.clearColliders=function(){this.colliders=[]},t.prototype.getCollisionsForCollider=function(t){return t.active?this.collisions.filter((function(e){return e.localCollider.id===t.id})):[]},t.prototype.refreshCollisionsForCollider=function(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((function(e){return e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id})),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))},t.prototype.resolve=function(){var t=this;this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((function(t){return t.active})),this.broadPhaseResolver.clear(),this.activeColliders.forEach((function(e){t.updateShape(e)})),!1===this.fixedCollisionArea&&(this.updateNewArea(),!1===this.newArea.equals(this.collisionArea)&&(this.collisionArea.copy(this.newArea),this.broadPhaseResolver.resize(this.collisionArea))),this.checkForSpartialGridResize(),this.activeColliders.forEach((function(e){var i=e.id,n=e.shape.boundingBox;return t.broadPhaseResolver.insert(i,n)})),this.updateCollisions())},t.prototype.updateShape=function(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()},t.prototype.updateNewArea=function(){var t=this;this.activeColliders.forEach((function(e){var i=e.shape.boundingBox;t.minArea.set(Math.min(i.x,t.minArea.x),Math.min(i.y,t.minArea.y)),t.maxArea.set(Math.max(i.x1,t.maxArea.x),Math.max(i.y1,t.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)},t.prototype.checkForSpartialGridResize=function(){this.broadPhaseResolver instanceof yt&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)},t.prototype.updateCollisions=function(){var t=this;this.activeColliders.filter((function(t){return t.updateCollisions})).forEach((function(e){return t.narrowPhase(e,t.broadPhase(e))}))},t.prototype.broadPhase=function(t){var e=this;return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active})).filter((function(i){return e.collisionMatrix.some((function(e){return e[0]===t.layer&&e[1]===i.layer||e[1]===t.layer&&e[0]===i.layer}))})):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active}))},t.prototype.narrowPhase=function(t,e){var i=this;e.filter((function(e){return!(t.group&&e.group&&e.group===t.group||t.id===e.id)})).forEach((function(e){if(!i.isResolved(t,e)){var n=i.method.getCollisionResolution(t.shape,e.shape);null!==n&&(i.collisions.push({localCollider:t,remoteCollider:e,resolution:n},{localCollider:e,remoteCollider:t,resolution:{direction:n.displacementDirection,displacementDirection:n.direction,penetration:n.penetration}}),t.onCollision&&t.onCollision(n))}}))},t.prototype.isResolved=function(t,e){for(var i=0,n=this.collisions;i<n.length;i++){var o=n[i];if(o.localCollider.id===t.id&&o.remoteCollider.id===e.id)return!0}return!1},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(mt||(mt={}));var bt,xt=function(){function t(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}return t.prototype.getCollisionResolution=function(t,e){return t.type===mt.Polygon&&e.type===mt.Polygon?this.AABBResolver.resolve(t,e):t.type===mt.Circumference&&e.type===mt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===mt.Polygon&&e.type===mt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===mt.Circumference&&e.type===mt.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(bt||(bt={}));var _t=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===mt.Circumference&&e.type===mt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),Mt=function(){function t(){this.direction=new ct,this.displacementDirection=new ct}return t.prototype.resolve=function(t,e){var i=t.boundingBox,n=e.boundingBox;return this.overlapX=Math.min(i.x1,n.x1)-Math.max(i.x,n.x),this.overlapY=Math.min(i.y1,n.y1)-Math.max(i.y,n.y),this.overlapX<0||this.overlapY<0?null:(this.checkOverlapForLines(i,n),this.direction.set(Math.sign(n.center.x-i.center.x),Math.sign(n.center.y-i.center.y)),this.preventContainment(i,n),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),ct.unit(this.displacementDirection,this.displacementDirection),{direction:ct.scale(new ct,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),penetration:this.minOverlap})},t.prototype.checkOverlapForLines=function(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))},t.prototype.preventContainment=function(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){var i=Math.abs(t.y-e.y),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)&&(i=Math.abs(t.x-e.x),n=Math.abs(t.x1-e.x1),this.overlapX+=i<n?i:n)},t}(),wt=function(){function t(){this.closestPoint=new ct,this.distance=new ct,this.direction=new ct}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(lt(t.position.x,e.boundingBox.x,e.boundingBox.x1),lt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),ct.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(ct.unit(this.direction,this.distance),{direction:i?ct.scale(new ct,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():ct.scale(new ct,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),jt=function(){function t(){this.distance=new ct,this.direction=new ct}return t.prototype.resolve=function(t,e){return ct.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(ct.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:ct.scale(new ct,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),Pt=function(t,e){return Pt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},Pt(t,e)};function Ot(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var Ct,At=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new ct,this.distance=new ct(1/0,1/0),this.cache=new ct}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===mt.Circumference?this.setCircumferenceAxis(t,e):e.type===mt.Circumference&&this.setCircumferenceAxis(e,t),this.axes=Ot([],t.projectionAxes,!0),e.projectionAxes.forEach((function(t){return i.axes.some((function(e){return e.equals(t)}))?null:i.axes.push(t)}));for(var n=0;n<this.axes.length;n++){if(t.type===mt.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===mt.Circumference&&this.setCircumferenceVertices(e,this.axes[n]),this.projectShapeOntoAxis(this.projA,t,this.axes[n]),this.projectShapeOntoAxis(this.projB,e,this.axes[n]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;if(this.invertAxis=!0,this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){var o=Math.abs(this.projA.min-this.projB.min),r=Math.abs(this.projA.max-this.projB.max);o<r?this.currentOverlap+=o:(this.currentOverlap+=r,ct.scale(this.axes[n],this.axes[n],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[n]),this.invertAxis&&this.projA.max<this.projB.max&&ct.scale(this.smallestAxis,this.axes[n],-1))}return{direction:ct.scale(new ct,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}},t.prototype.projectShapeOntoAxis=function(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((function(e){t.min=Math.min(ct.dot(i,e),t.min),t.max=Math.max(ct.dot(i,e),t.max)})),t},t.prototype.setCircumferenceAxis=function(t,e){var i=this;this.distance.set(1/0,1/0),e.vertices.forEach((function(e){ct.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),ct.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){ct.add(t.vertices[0],t.position,ct.scale(this.cache,ct.unit(this.cache,e),-t.radius)),ct.add(t.vertices[1],t.position,ct.scale(this.cache,ct.unit(this.cache,e),t.radius))},t}(),Rt=function(){function t(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}return t.prototype.addCollider=function(t){var e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e},t.prototype.removeCollider=function(t){this.collisionManager.removeCollider(t)},t.prototype.getCollisionsForCollider=function(t){return this.collisionManager.getCollisionsForCollider(t)},t.prototype.addRigidBody=function(t){var e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e},t.prototype.removeRigidBody=function(t){this.rigidBodyManager.removeRigidBody(t)},t.prototype.resolve=function(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)},t.prototype.clear=function(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()},t}(),St=function(){function t(){}return t.prototype.create=function(t){var e=t.colliderIds,i=t.type,n=t.gravity,o=t.position,r=t.velocity,s=t.onResolve;if(0===e.length)throw new Error("RigidBody needs at least one collider");return{active:!0,colliderIds:e,type:i,gravity:null!=n?n:0,position:null!=o?o:new ct,velocity:null!=r?r:new ct,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Ct||(Ct={}));var Et=["x","y"],Tt=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new ct,this.displacement=new ct,this.cacheDisplacement=0}return t.prototype.addRigidBody=function(t){this.rigidBodies.push(t)},t.prototype.removeRigidBody=function(t){var e=this.rigidBodies.indexOf(t);e>=0&&this.rigidBodies.splice(e,1)},t.prototype.clearRigidBodies=function(){this.rigidBodies=[]},t.prototype.resolve=function(t){var e=this;this.activeRigidBodies=this.rigidBodies.filter((function(t){return t.active})),this.colliders=this.activeRigidBodies.reduce((function(t,e){return Ot(Ot([],t,!0),e.colliderIds,!0)}),[]),this.activeRigidBodies.forEach((function(i){i.type===Ct.Dynamic?e.dynamicUpdate(i,t):i.type===Ct.Kinematic&&e.kinematicUpdate(i,t),i.onResolve&&i.onResolve(i)}))},t.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),Et.forEach((function(n){i.applyVelocity(t,e,n),i.obtainDisplacement(t,n),i.applyReposition(t,n)}))},t.prototype.kinematicUpdate=function(t,e){var i=this;ct.add(t.position,t.position,ct.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){ct.add(t.position,t.position,i.velocity),i.collisionManager.refreshCollisionsForCollider(t)}))},t.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},t.prototype.applyVelocity=function(t,e,i){var n=this;this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((function(t){return n.collisionManager.getCollider(t)})).forEach((function(t){t.position[i]+=n.velocity[i],n.collisionManager.refreshCollisionsForCollider(t)})))},t.prototype.obtainDisplacement=function(t,e){var i=this;this.displacement[e]=0,this.getCollisions(t).forEach((function(t){i.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,i.displacement[e]=Math.abs(i.displacement[e])>Math.abs(i.cacheDisplacement)?i.displacement[e]:i.cacheDisplacement}))},t.prototype.applyReposition=function(t,e){var i=this;0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){t.position[e]+=i.displacement[e],i.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))},t.prototype.getCollisions=function(t){var e=this;return t.colliderIds.map((function(t){return e.collisionManager.getCollider(t)})).filter((function(t){return t.active&&t.physics})).reduce((function(t,i){return t.push.apply(t,e.collisionManager.getCollisionsForCollider(i).filter((function(t){return t.remoteCollider.physics&&e.colliders.includes(t.remoteCollider.id)}))),t}),[])},t}(),Dt=function(){function t(t){this.radius=t,this.type=mt.Circumference,this.boundingBox=new ut(0,0,0,0),this.vertices=[new ct,new ct],this.projectionAxes=[new ct],this._position=new ct}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},t}(),Bt=function(){function t(t){this.vertexModel=t,this.type=mt.Polygon,this.vertices=[new ct,new ct],this.projectionAxes=[new ct],this.boundingBox=new ut(0,0,0,0),this.rotation=0,this._position=new ct}return t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){ct.normal(this.projectionAxes[0],ct.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),Ft=function(){function t(t){this.vertexModel=t,this.type=mt.Polygon,this.vertices=[],this.boundingBox=new ut(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new ct,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(var e=0;e<this.vertexModel.length;e++)this.vertices.push(new ct),this._projectionAxes.push(new ct)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,e=0;e<this.vertices.length;e++)ct.normal(this._projectionAxes[e],ct.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),It=function(t){function e(e,i){var n=t.call(this,[new ct(-e/2,-i/2),new ct(-e/2,i/2),new ct(e/2,i/2),new ct(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new ct,new ct],n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}Pt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,t),e.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},e.prototype.updateProjectionAxes=function(){ct.unit(this.projectionAxes[0],ct.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),ct.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(Ft),Ut=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new Ut,this._center=new Ut,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof Ut&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Ut,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Lt,kt=function(){function t(){var t=this;this.gamepads=new Map,this.eventHandler=function(e){"gamepadconnected"===e.type?t.gamepadConnected(e.gamepad):"gamepaddisconnected"===e.type&&t.gamepadDisconected(e.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}return t.prototype.getGamepad=function(t){var e;return null!==(e=this.gamepads.get(t))&&void 0!==e?e:null},t.prototype.getGamepads=function(){return Array.from(this.gamepads.values())},t.prototype.gamepadConnected=function(t){this.gamepads.set(t.index,new Vt),this.gamepads.get(t.index).updateFromGamepad(t)},t.prototype.gamepadDisconected=function(t){this.gamepads.delete(t.index)},t.prototype.update=function(){for(var t=0,e=this.getGamepadsFromBrowser();t<e.length;t++){var i=e[t];null!==i&&(!1===this.gamepads.has(i.index)?this.gamepadConnected(i):this.gamepads.get(i.index).updateFromGamepad(i))}},t.prototype.getGamepadsFromBrowser=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),Vt=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Ut,this._leftStickAxes=new Ut,this._rightStickAxes=new Ut,this._vibrating=!1}return t.prototype.updateFromGamepad=function(t){var e=this;this._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){var o=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return o._vibrating=!1})).finally((function(){return o._vibrating=!1})))},t}(),Gt=function(){function t(t,e,i,n){this.mouse=t,this.keyboard=e,this.gamepad=i,this.touch=n}return t.prototype.update=function(){this.mouse.update(),this.gamepad.update()},t}(),Ht=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),Wt=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Ut,this._hasMoved=!1,this._wheelScroll=new Ut,this.lastPositionInViewport=new Ut,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),zt=function(){function t(t){var e=this;this._touching=!1,this._interactions=[],this.eventHandler=function(t){"touchstart"===t.type&&(e._touching=!0,e.updatePosition(t)),"touchmove"===t.type&&e.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(e._touching=!1)},this.canvas=t,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"interactions",{get:function(){return this._interactions},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){if(t.preventDefault(),t.stopPropagation(),this._interactions=[],0!==t.targetTouches.length)for(var e=0;e<t.targetTouches.length;e++)this._interactions[e]={positionInViewport:new Ut((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new Ut(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Lt||(Lt={}));var Xt,Yt=function(){function t(t){this.renderManager=t,this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.loadImage=function(t,e){var i=this;void 0===e&&(e=!1);var n=new Image;n.crossOrigin="",n.src=t;var o=this.createAsset(t,Lt.Image,n),r=function(){e&&i.renderManager.preloadTexture(n),o.loaded=!0};return n.naturalWidth?r():n.addEventListener("load",r),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,Lt.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url(".concat(e,")")),n=this.createAsset(e,Lt.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.loadVideo=function(t){var e=document.createElement("video");e.playsInline=!0,e.src=t;var i=this.createAsset(t,Lt.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Image&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getAudio=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Audio&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getFont=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Font&&e.family===t})))||void 0===e?void 0:e.element},t.prototype.getVideo=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Video&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var n={type:e,url:t,element:i,loaded:!1};return this.assets.push(n),n},t}(),Nt=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return u(e,t),e}(Error),qt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Nt("containerNode cannot be empty or null.");this.containerNode=t,this.gameWidth=e,this.gameHeight=i,this.setupCanvas()}return Object.defineProperty(t.prototype,"canvas",{get:function(){return this._canvas},enumerable:!1,configurable:!0}),t.prototype.setupCanvas=function(){this._canvas=document.createElement("canvas"),this._canvas.id="angryPixelGameCanvas",this._canvas.width=Math.floor(this.gameWidth),this._canvas.height=Math.floor(this.gameHeight),this.canvas.tabIndex=0,this._canvas.addEventListener("contextmenu",(function(t){return t.preventDefault()})),this.containerNode.appendChild(this._canvas),this.canvas.focus()},t}(),Kt=function(){function t(t){this.container=t,this.gameObjects=[],this.lastId=0}return t.prototype.addGameObject=function(t,e,i,n){var o=new t(this.container,++this.lastId,n,i);return this.gameObjects.push(o),o.dispatch(l.Init,e),o},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):d([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(t){var e=this;void 0===t&&(t=!1),this.gameObjects.filter((function(e){return t||!e.keep})).forEach((function(t){return e.destroy(t,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var n=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(n),n.dispatch(l.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Qt=function(){function t(t,e,i,n){this.timeManager=t,this.physicsManager=e,this.gameObjectManager=i,this.sceneManager=n,this.running=!1,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[l.Start,l.Update,l.StopGame],this.gameObjectEvents=[l.Start,l.Update]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.dispatchFrameEvent(l.StopGame),this.physicsManager.clear()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.load(),this.dispatchFrameEvent(l.Start),this.dispatchFrameEvent(l.Update),this.dispatchFrameEvent(l.UpdateEngine),this.dispatchFrameEvent(l.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene())},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(l.UpdatePhysics),this.dispatchFrameEvent(l.UpdateCollider),this.dispatchFrameEvent(l.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),$t=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.sceneNamePendingToLoad=null}return t.prototype.addScene=function(t,e,i,n){var o=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new Nt("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(o.container,e,o.container.getConstant("Game"));return o.currentScene=n,n.dispatch(l.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new Nt("Scene with name ".concat(t," does not exists"));this.sceneNamePendingToLoad=t},t.prototype.getLoadedScene=function(){return this.currentScene},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new Nt("There is no opening scene");this.scenes.get(this.openingSceneName)()},t.prototype.pendingSceneToload=function(){return null!==this.sceneNamePendingToLoad},t.prototype.loadPendingScene=function(){this.sceneNamePendingToLoad&&(this.scenes.get(this.sceneNamePendingToLoad)(),this.sceneNamePendingToLoad=null)},t.prototype.unloadCurrentScene=function(){this.currentScene&&(this.currentScene.dispatch(l.Destroy),this.currentScene=void 0)},t}(),Jt=[60,120,180,240],Zt=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!Jt.includes(t))throw new Nt("Invalid Physics frame rate. Allowed: [".concat(Jt.join(", "),"]"));this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t.prototype.updateForGame=function(t){this.unscaledDeltaTime=Math.min(Math.max(this.minGameDeltatime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t},t.prototype.updateForBrowser=function(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForBrowser),this.maxDeltaTime),this.thenForBrowser=t},t.prototype.updateForPhysics=function(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t},t}(),te=function(){function t(){this.instances=new Map,this.constructors=new Map,this.constants=new Map}return t.prototype.add=function(t,e){if(this.constructors.has(t))throw new Nt("There is already an object constructor with the name ".concat(t));this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new Nt("Invalid object constructor name: ".concat(t));return!1===this.instances.has(t)&&this.instances.set(t,this.constructors.get(t)()),this.instances.get(t)},t.prototype.getTranscient=function(t){if(!1===this.constructors.has(t))throw new Nt("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Nt("There is already a constant value with the name ".concat(t));this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new Nt("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),ee=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),ie=function(){function t(t,e,i,n){this._position=new ee,this._center=new ee,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ee&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),ne=function(t,e,i){return t>=e&&t<=i},oe=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ee,t?this.radians=t:e&&(this.degrees=e)}return Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},t}(),re={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new ee(1,1),collisions:{collisionMethod:bt.SAT,collisionBroadPhaseMethod:pt.SpartialGrid}},se=function(){function t(t){this._config=p(p({},re),t),this._config.collisions=p(p({},re.collisions),t.collisions),this.container=new te,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){(function(t,e){if(t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new Zt(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new Kt(t)})),t.add("PhysicsManager",(function(){return function(t){var e=void 0===t?{}:t,i=e.collisionArea,n=e.collisionMatrix,o=e.collisionMethod,r=e.collisionBroadPhaseMethod,s=new jt,a=o===bt.AABB?new xt(new Mt,new wt,s):new _t(s,new At),h=new vt(a,r,i,n),c=new dt,u=new Tt(h),l=new St;return new Rt(h,c,u,l)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Qt(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new qt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new B(t),i=e.gl,n=e.contextVersion,o=new L(i,n,new U(i,new k(i))),r=new at(new st(i)),s=new ht(i,o,r,new Map([[y.Sprite,new J(i,o,r)],[y.Text,new nt(i,o,r,new F)],[y.Tilemap,new ot(i,o,r)],[y.Geometric,new K(i,o)],[y.Mask,new $(i,o)],[y.Video,new rt(i,o,r)]]));return new D(s,new C(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Gt(new Wt(t),new Ht(t),new kt,new zt(t))}(i)})),t.add("AssetManager",(function(){return new Yt(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new m(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))}t.add("SceneManager",(function(){return new $t(t,e.headless?void 0:t.getSingleton("RenderManager"))}))})(this.container,this._config),this.sceneManager=this.container.getSingleton("SceneManager"),this.iterationManager=this.container.getSingleton("IterationManager")},Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"running",{get:function(){return this.iterationManager.running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i,n){this.sceneManager.addScene(t,e,"object"==typeof i?i:void 0,"boolean"==typeof i?i:null!=n&&n)},t.prototype.run=function(){this.iterationManager.start()},t.prototype.stop=function(){this.iterationManager.stop()},t.prototype.pause=function(){this.iterationManager.pause()},t.prototype.resume=function(){this.iterationManager.resume()},t}(),ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.parentScale=!0,e.parentRotation=!0,e._position=new ee,e._scale=new ee(1,1),e._rotation=new oe,e._innerPosition=new ee,e._parent=null,e.cache=new ee,e.lastParentRadians=0,e.lastPosition=new ee,e.scaledInnerPosition=new ee,e}return u(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&ee.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),e.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},e.prototype.setPositionFromParent=function(){this._innerPosition.magnitude>0?(0!==this._parent.rotation.radians&&this.lastParentRadians!==this._parent.rotation.radians&&(this.translateInnerPosition(),this.lastParentRadians=this._parent.rotation.radians),this.parentScale?(this.updateScaledInnerPosition(),ee.add(this._position,this._parent.position,this.scaledInnerPosition)):ee.add(this._position,this._parent.position,this._innerPosition)):this._position.copy(this._parent.position),this._rotation.radians=this.parentRotation?this._parent.rotation.radians+this._rotation.radians:this._rotation.radians,this.parentScale&&this._scale.copy(this.parent._scale)},e.prototype.translateInnerPosition=function(){var t=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(t),Math.sin(t)),ee.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},e.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},e}(w),he=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return u(e,t),e.prototype.update=function(){this.activateColliders&&(this.colliders.forEach((function(t){return t.active=!0})),this.activateColliders=!1),this.updateRealSize(),this.updatePosition(),this.updateColliders()},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],o=0,r=this.physicsManager.getCollisionsForCollider(n);o<r.length;o++){var s=r[o];if(s.remoteCollider.layer===t)return this.createCollisionData(s)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var o=n[i],r=0,s=this.physicsManager.getCollisionsForCollider(o);r<s.length;r++){var a=s[r];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(Number(t.remoteCollider.group)),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject},localCollider:t.localCollider}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(_),ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e}return u(e,t),Object.defineProperty(e.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBodyType",{get:function(){return this.rigidBody.type},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e,i=t.rigidBodyType,n=t.gravity;if(0===this.getColliderIds().length)throw new Nt("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:i,colliderIds:this.getColliderIds(),gravity:null!==(e=Math.abs(n))&&void 0!==e?e:0,velocity:new ee,position:new ee})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new Nt("RigidBody needs at least one Collider with physics");this.rigidBody.colliderIds=this.getColliderIds(),this.rigidBody.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position},e.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof he&&t.physics})).reduce((function(t,e){return d(d([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},e.prototype.onActiveChange=function(){this.rigidBody.active=this.active},e.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},e}(x),ue="Default",le=function(t){function e(e,i,n,o){void 0===n&&(n=""),void 0===o&&(o=null);var r=t.call(this,e)||this;return r.layer="Default",r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.id=i,r.name=n,r.addComponent(ae),o&&(r.transform.position=o.transform.position,r.parent=o),r}return u(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus(),this.onActiveChange())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(ae)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(ce)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getLoadedScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,o="string"==typeof e?e:i,r=new t(this.container,this,o);return this.checkMultipleComponent(r,t),this.components.push(r),r.dispatch(l.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new Nt("GameObject only allows one component of type ".concat(e.name))},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(l.Destroy)},e.prototype.addChild=function(t,e,i){var n=this.gameObjectManager.addGameObject(t,e,this,i);return n.transform.innerPosition.set(0,0),n.transform.position.copy(this.transform.position),n},e.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},e.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParent(this,t)},e.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},e.prototype._destroy=function(){var t=this;this.destroyComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype.destroyComponents=function(){for(var t=0;t<this.components.length;t++)this.components[t].dispatch(l.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(v),pe=["Default"],de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new ie(0,0,0,0),e.worldSpaceRect=new ie(0,0,0,0),e.depth=0,e.layers=pe,e._zoom=1,e}return u(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new Nt("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.layers.push(t)},e.prototype.init=function(){this.canvas=this.domManager.canvas,this.cameraData={position:new ee,layers:[],depth:1}},e.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},e.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},e.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},e.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},e}(P),fe=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(de)},Object.defineProperty(e.prototype,"layers",{get:function(){return this.camera.layers},set:function(t){this.camera.layers=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this.camera.depth},set:function(t){this.camera.depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this.camera.zoom},set:function(t){this.camera.zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this.camera.worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this.camera.viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.camera.layers.push(t)},e}(le),ge=function(t){function e(e,i,n){var o=t.call(this,e)||this;return o.name=i,o.game=n,o.game.config.headless||o.addGameObject(fe),o}return u(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(fe)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!1),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!0),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(v),ye=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.scaledVertexModel=[],e.scaledOffset=new ee,e.scaledPosition=new ee,e.finalRotation=0,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==bt.SAT)throw new Nt("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new Nt("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new ee);this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Ft(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},e.prototype.updatePosition=function(){ee.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.scaledPosition),this.colliders[0].rotation=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel},e}(he),me=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:y.Geometric,location:g.WorldSpace,layer:this.gameObject.layer,position:new ee,shape:f.Polygon,color:"#00FF00"},this.collider=e},e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.rotation=this.collider.shape.rotation,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},e}(O),ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.realWidth=0,e.realHeight=0,e.realOffset=new ee,e.realPosition=new ee,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===bt.SAT,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(o=t.debug)&&void 0!==o?o:this.debug)&&this.gameConfig.debugEnabled,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new It(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){this.realWidth=this.width*Math.abs(this.gameObject.transform.scale.x),this.realHeight=this.height*Math.abs(this.gameObject.transform.scale.y),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.realRotation=this.applyRotation?this.gameObject.transform.rotation.radians+this.rotation.radians:0},e.prototype.updatePosition=function(){ee.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].rotation=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight)},e}(he),be=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.realRadius=0,e.realOffset=new ee,e.realPosition=new ee,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r;this.radius=t.radius,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(o=t.debug)&&void 0!==o?o:this.debug)&&this.gameConfig.debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new Dt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(xe,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},e.prototype.updatePosition=function(){ee.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].shape.radius=this.realRadius},e}(he),xe=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:y.Geometric,location:g.WorldSpace,layer:this.gameObject.layer,position:new ee,shape:f.Circumference,color:"#00FF00"},this.collider=e},e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},e}(O),_e=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i;this.tilemapRenderer=t.tilemapRenderer,this.layer=t.layer,this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.physics=!0,this.composite=null!==(i=t.composite)&&void 0!==i&&i,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===S.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([S.Center,S.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==S.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(Me,{colliders:this.colliders}))},e.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(e,i){var n;t.needsCollider(e,i)&&t.colliders.push(t.physicsManager.addCollider({layer:null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,position:new ee(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new It(t.scaledTileWidth,t.scaledTileHeight),updateCollisions:!1,physics:t.physics,group:t.gameObject.id.toString()}))}))},e.prototype.needsCollider=function(t,e){var i=this;return 0!==t&&this.getNeighbors(e).some((function(t){return!t||!i.tilemapRenderer.tiles[t]||0===i.tilemapRenderer.tiles[t]}))},e.prototype.useLineColliders=function(){var t,e,i=this,n=[],o=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var r=e%i.tilemapRenderer.width,s=Math.floor(e/i.tilemapRenderer.width);n[s]||(n[s]=[]),n[s+1]||(n[s+1]=[]),o[s]||(o[s]=[]),o[s+1]||(o[s+1]=[]);var a=i.getNeighbors(e);i.hasTile(a[0])||(n[s][r]=!0),i.hasTile(a[2])||(n[s+1][r]=!0),i.hasTile(a[1])||(o[s][r]=!0),i.hasTile(a[3])||(o[s][r+1]=!0)}}));for(var r=0;r<n.length;r++)if(n[r])for(var s=0;s<n[r].length;s++)!t||!e||r===e.y&&n[r][s]||(this.addLineCollider(t,e),t=void 0,e=void 0),n[r][s]&&(t||(t=new ee(s,r)),e=new ee(s+1,r));for(t&&e&&this.addLineCollider(t,e),t=void 0,e=void 0,s=0;s<=this.tilemapRenderer.width;s++)for(r=0;r<o.length;r++)o[r]&&(!t||!e||s===e.x&&o[r][s]||(this.addLineCollider(t,e),t=void 0,e=void 0),o[r][s]&&(t||(t=new ee(s,r)),e=new ee(s,r+1)));t&&e&&this.addLineCollider(t,e)},e.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},e.prototype.addLineCollider=function(t,e){var i,n=this.physicsManager.addCollider({layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,position:this.position.clone(),shape:new Bt([new ee(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new ee(e.x*this.scaledTileWidth,e.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id.toString()});this.colliders.push(n)},e.prototype.getNeighbors=function(t){return[t-this.tilemapRenderer.width>=0?t-this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width>0?t-1:void 0,t+this.tilemapRenderer.width<=this.tilemapRenderer.width*this.tilemapRenderer.height?t+this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width<this.tilemapRenderer.width-1?t+1:void 0]},e.prototype.updateRealSize=function(){},e.prototype.updatePosition=function(){},e.prototype.updateColliders=function(){var t=this;this.colliders.forEach((function(e){var i;return e.layer=null!==(i=t.layer)&&void 0!==i?i:t.gameObject.layer}))},e}(he),Me=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return u(e,t),e.prototype.init=function(t){var e=this,i=t.colliders;this.colliders=i,this.colliders.forEach((function(t,i){e.renderData[i]={type:y.Geometric,layer:e.gameObject.layer,location:g.WorldSpace,position:new ee,shape:f.Polygon,color:"#00FF00"}}))},e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},e}(O),we=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.scaledVertexModel=[],e.scaledOffset=new ee,e.scaledPosition=new ee,e.finalRotation=0,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==bt.SAT)throw new Nt("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new Nt("Edge Collider needs at least 2 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new ee);for(a=0;a<this.scaledVertexModel.length-1;a++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Bt([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(je,{colliders:this.colliders}))},e.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},e.prototype.updatePosition=function(){ee.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].position.copy(this.scaledPosition),this.colliders[e].rotation=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]]},e}(he),je=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return u(e,t),e.prototype.init=function(t){var e=this,i=t.colliders;this.colliders=i,this.colliders.forEach((function(t,i){e.renderData[i]={type:y.Geometric,layer:e.gameObject.layer,location:g.WorldSpace,position:new ee,shape:f.Line,color:"#00FF00"}}))},e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},e}(O),Pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.innerPosition=new ee,e.cachePosition=new ee,e.cacheRenderPosition=new ee,e.scaledOffset=new ee,e.cacheScale=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(e=t.offset)&&void 0!==e?e:new ee,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new oe,this.flipHorizontal=null!==(n=t.flipHorizontal)&&void 0!==n&&n,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:1,this._tiled=null!==(s=t.tiled)&&void 0!==s?s:new ee(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(a=t.maskColorMix)&&void 0!==a?a:0,this.tintColor=t.tintColor,this.layer=t.layer,this.scale=null!==(c=null!==(h=t.scale)&&void 0!==h?h:this.gameConfig.spriteDefaultScale.clone())&&void 0!==c?c:new ee(1,1),this.width=t.width,this.height=t.height},Object.defineProperty(e.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new Nt("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),e.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},e.prototype.updateRenderDataArray=function(){if(this.renderData.length!==this._tiled.x*this._tiled.y){this.renderData=[];for(var t=0;t<this._tiled.x*this._tiled.y;t++)this.renderData[t]={type:y.Sprite,location:g.WorldSpace,layer:"",position:new ee,image:this.sprite.image,width:0,height:0}}},e.prototype.updateRenderData=function(t,e,i){var n,o,r;this.renderData[t].location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData[t].layer=null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,this.renderData[t].image=this.sprite.image,this.renderData[t].width=(null!==(o=this.width)&&void 0!==o?o:this.sprite.width)*Math.abs(this.cacheScale.x),this.renderData[t].height=(null!==(r=this.height)&&void 0!==r?r:this.sprite.height)*Math.abs(this.cacheScale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.cacheScale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.cacheScale.y<0,this.renderData[t].rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData[t].smooth=this.sprite.smooth,this.renderData[t].alpha=this.opacity,this.renderData[t].maskColor=this.maskColor,this.renderData[t].maskColorMix=this.maskColorMix,this.renderData[t].tintColor=this.tintColor,this.calculateRenderPosition(t,e,i),this.renderManager.addRenderData(this.renderData[t])},e.prototype.calculateRenderPosition=function(t,e,i){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[t].width/2*(this._tiled.x-1),this.renderData[t].height/2*(this._tiled.y-1)),ee.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),ee.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){ee.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var e=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[t].position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},e}(O),Oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.lastFrameText="",e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c,u,l,p,d;if(this.text=null!==(e=t.text)&&void 0!==e?e:"",this.font=null!==(i=t.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=t.fontSize)&&void 0!==n?n:12,this.width=null!==(o=t.width)&&void 0!==o?o:100,this.height=null!==(r=t.height)&&void 0!==r?r:100,this.offset=null!==(s=t.offset)&&void 0!==s?s:new ee,this.color=null!==(a=t.color)&&void 0!==a?a:"#000000",this.charRanges=null!==(h=t.charRanges)&&void 0!==h?h:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=t.letterSpacing)&&void 0!==u?u:0,this.smooth=null!==(l=t.smooth)&&void 0!==l&&l,this.rotation=null!==(p=t.rotation)&&void 0!==p?p:new oe,this.opacity=null!==(d=t.opacity)&&void 0!==d?d:1,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new Nt("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Nt("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:y.Text,location:g.WorldSpace,position:new ee,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},e.prototype.update=function(){var t,e;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.fontSize=this.fontSize,this.renderData.color=this.color,this.renderData.orientation=this.orientation,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.rotation=null!==(e=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==e?e:0,this.renderData.alpha=this.opacity,ee.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text)},e.prototype.crop=function(){var t=this;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,o=this.text.split("\n");n<o.length;n++)for(var r=o[n].split(" ").reduce((function(e,i){var n=e[e.length-1]+(e[e.length-1].length>0?" ":"")+i;return n.length*(t.fontSize+t.letterSpacing)>t.width?e.push(i):e[e.length-1]=n,e}),[""]),s=0,a=r;s<a.length;s++){var h=a[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(h)}return e.join("\n")},e}(O),Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new ee,e.rotation=new oe,e.opacity=1,e.innerPosition=new ee,e.scaledOffset=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a;this.shape=t.shape,this.color=t.color,this.width=null!==(e=t.width)&&void 0!==e?e:0,this.height=null!==(i=t.height)&&void 0!==i?i:0,this.radius=null!==(n=t.radius)&&void 0!==n?n:0,this.offset=null!==(o=t.offset)&&void 0!==o?o:this.offset,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:this.rotation,this.opacity=null!==(s=t.opacity)&&void 0!==s?s:this.opacity,this.layer=t.layer,this.renderData={type:y.Mask,layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,width:0,height:0,radius:0,color:"",shape:this.shape}},e.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.shape=this.shape,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.radius=this.radius*Math.abs(Math.max(this.gameObject.transform.scale.x,this.gameObject.transform.scale.y)),this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},e.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){ee.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e}(O),Ae=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Re=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.innerPosition=new ee,e.scaledOffset=new ee,e._playing=!1,e._paused=!1,e.videoEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e.video.removeEventListener("ended",e.videoEventHandler))},e.userInputEventHandler=function(){Ae.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.video&&e._playing&&e.video.play()},e}return u(e,t),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.video&&(this.video.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.video&&(this.video.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c,u;this.video=t.video,this.width=null!==(e=t.width)&&void 0!==e?e:this.video.videoWidth,this.height=null!==(i=t.height)&&void 0!==i?i:this.video.videoHeight,this.offset=null!==(n=t.offset)&&void 0!==n?n:new ee,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new oe,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(s=t.flipVertical)&&void 0!==s&&s,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this.maskColor=t.maskColor,this.maskColorMix=null!==(h=t.maskColorMix)&&void 0!==h?h:0,this.tintColor=t.tintColor,this.layer=t.layer,this.slice=t.slice,this._volume=null!==(c=t.volume)&&void 0!==c?c:1,this._loop=null!==(u=t.loop)&&void 0!==u&&u,this.renderData={type:y.Video,location:g.WorldSpace,layer:"",position:new ee,video:this.video,width:this.width,height:this.height}},e.prototype.play=function(){var t=this;if((this.video||!this.video.duration)&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.video.play();this.video.loop=this._loop,this.video.volume=this._volume,this.video.addEventListener("ended",this.videoEventHandler),this._playing=!0;var e=this.video.play();void 0!==e&&e.catch((function(){Ae.forEach((function(e){return window.addEventListener(e,t.userInputEventHandler)}))}))}},e.prototype.stop=function(){this._playing&&(this.video.pause(),this.video.currentTime=0,this.video.removeEventListener("ended",this.videoEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this.video.pause(),this._paused=!0)},e.prototype.update=function(){var t;this.video&&this.video.duration&&(this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.video=this.video,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.slice=this.slice,this.renderData.flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData.flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.maskColor=this.maskColor,this.renderData.maskColorMix=this.maskColorMix,this.renderData.tintColor=this.tintColor,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData))},e.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){ee.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop()},e}(O),Se=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return u(e,t),e.prototype.init=function(t){var e,i=this,n=t.tiles,o=t.tileset,r=t.tileWidth,s=t.tileHeight,a=t.width,h=t.layer,c=t.orientation,u=t.opacity,l=t.tintColor,p=t.smooth;n.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?i.tiles.push(Number(t)):null}))})),this.tileset=o,this.width=a,this.tileWidth=null!=r?r:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=h,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=null!=c?c:S.Center,this.opacity=u,this.tintColor=l,this.renderData={type:y.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},e.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},e.prototype.updateRenderData=function(){var t;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.position.copy(this.gameObject.transform.position),this.renderData.tintColor=this.tintColor,this.renderData.alpha=this.opacity,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},e}(O),Ee=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return u(e,t),e.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,o=t.tileWidth,r=t.tileHeight,s=t.layer,a=t.orientation,h=t.smooth;if(this.tiledData=e,this.tileset=n,this.tileWidth=null!=o?o:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=r?r:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=s,this.smooth=null!=h&&h,this.orientation=null!=a?a:S.Center,this.tiledLayer=this.tiledData.layers.find((function(t){return t.name===i})),!this.tiledLayer)throw new Nt("Invalid tilemap layer");this.width=this.tiledLayer.width,this.height=this.tiledLayer.height,this.processTilemap()},e.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},e.prototype.processTilemap=function(){var t=this;!0===this.tiledLayer.visible&&(this.opacity=this.tiledLayer.opacity,this.tintColor=this.tiledLayer.tintcolor,this.tiledData.infinite?this.tiledLayer.chunks.sort((function(t,e){return t.x-e.x})).sort((function(t,e){return t.y-e.y})).forEach((function(e){return t.processChunk(e)})):this.processChunk(this.tiledLayer)),this.updateRenderData(),this.tilesetTileIds=[]},e.prototype.processChunk=function(t){var e,i=this,n={type:y.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:S.RightDown,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=n.tiles:n.tiles.forEach((function(e,n){i.tiles[i.tiledLayer.width*(t.y+Math.floor(n/t.width))+t.x+n%t.width]=e})),this.renderData.push(n),this.chunks.push(t)},e.prototype.getTilesetTileId=function(t){return this.tilesetTileIds[t]||(this.tilesetTileIds[t]=this.tiledData.tilesets.reduce((function(e,i){return t>=i.firstgid?t-i.firstgid+1:e}),0)),this.tilesetTileIds[t]},e.prototype.updateRenderData=function(){var t=this;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.tiledLayer.width*this.scaledTileWidth,this.realHeight=this.tiledLayer.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+(t.orientation===S.Center?-t.realWidth/2:0)+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+([S.Center,S.RightCenter].includes(t.orientation)?t.realHeight/2:t.orientation==S.RightUp?t.realHeight:0)-t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.opacity}))},e}(O),Te=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return u(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e="default"),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new De(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Nt("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null,this.paused=!1)},e.prototype.isPlayingAnimation=function(t){return void 0===t&&(t="default"),null!==this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e.prototype.isPaused=function(){return this.paused},e}(x),De=function(){function t(t){this._sprite=null,this._restarted=!1,this.currentFrame=0,this.frameTime=0,this._animation=t}return Object.defineProperty(t.prototype,"sprite",{get:function(){return this._sprite},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"restarted",{get:function(){return this._restarted},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){return this._animation.loop},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this.currentFrame=0,this.frameTime=0,this._restarted=!0},t.prototype.playFrame=function(t){this._restarted=!1,this.frameTime>=1/this._animation.framerate&&(this.frameTime=0,this.currentFrame=this.currentFrame+1===this._animation.sprites.length?0:this.currentFrame+1,this._restarted=0===this.currentFrame),this._sprite=this._animation.sprites[this.currentFrame],this.frameTime+=t},t}(),Be=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Fe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.tracks=[],e.audioSourceCache=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e._audioSource.removeEventListener("ended",e.audioEventHandler))},e.userInputEventHandler=function(){Be.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return u(e,t),Object.defineProperty(e.prototype,"audioSource",{get:function(){return this._audioSource},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this._audioSource&&(this._audioSource.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this._audioSource&&(this._audioSource.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e=this,i=void 0===t?{}:t,n=i.loop,o=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&Be.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=o?o:1,this._loop=null!=n&&n},e.prototype.playClip=function(t,e){t.currentTime>0&&(t.currentTime=0),t.volume=null!=e?e:this._volume,t.play()},e.prototype.addAudioSource=function(t,e){void 0===e&&(e="default");var i=t.cloneNode();this.audioSourceCache.set(e,i);var n=this.audioContext.createMediaElementSource(i);n.connect(this.audioContext.destination),this.tracks.push(n)},e.prototype.loadAudioSource=function(t,e,i){this.stop(),this._audioSource=this.audioSourceCache.get(t),this._loop=null!=e?e:this._loop,this._volume=null!=i?i:this._volume},e.prototype.play=function(){if(this._audioSource&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this._audioSource.play();this._audioSource.volume=this._volume,this._audioSource.loop=this._loop,this._audioSource.addEventListener("ended",this.audioEventHandler),this._playing=!0,"running"===this.audioContext.state&&this._audioSource.play()}},e.prototype.stop=function(){this._playing&&(this._audioSource.pause(),this._audioSource.currentTime=0,this._audioSource.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this._audioSource.pause(),this._paused=!0)},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop(),this.audioContext.close()},e}(x),Ie=function(){function t(t){var e,i=this;this._width=null,this._height=null,this._loaded=!1,this.image=t.image,this.smooth=null!==(e=t.smooth)&&void 0!==e&&e,this.slice=t.slice,this.slice&&(this._width=this.slice.width,this._height=this.slice.height);var n=function(){var t,e;i._width=null!==(t=i._width)&&void 0!==t?t:i.image.naturalWidth,i._height=null!==(e=i._height)&&void 0!==e?e:i.image.naturalHeight,i._loaded=!0};this.image.naturalWidth?n():this.image.addEventListener("load",(function(){return n()}))}return Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Xt||(Xt={}));var Ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.width=100,e.height=100,e.radius=50,e.touchEnabled=!0,e.offset=new ee,e.pressed=!1,e.mouse=e.inputManager.mouse,e.touch=e.inputManager.touch,e.position=new ee,e.distance=new ee,e.pressedLastFrame=!1,e.scaled={width:0,height:0,radius:0,offset:new ee},e}return u(e,t),e.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,o=t.touchEnabled,r=t.width,s=t.offset;this.type=e,this.width=null!=r?r:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=o?o:this.touchEnabled,this.offset=null!=s?s:this.offset},e.prototype.update=function(){this.scale(),ee.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},e.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this.offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this.offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y))},e.prototype.resolveMouseAndRectangle=function(){this.type===Xt.Rectangle&&(this.pressed=ne(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&ne(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2))},e.prototype.resolveMouseAndCircumference=function(){this.type===Xt.Circumference&&(ee.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},e.prototype.resolveTouchAndRectangle=function(){if(this.type===Xt.Rectangle)for(var t=0,e=this.touch.interactions;t<e.length;t++){var i=e[t],n=i.positionInViewport,o=i.radius;if(this.pressed)return;this.pressed=this.position.x+this.scaled.width/2>=n.x-o.x&&this.position.x-this.scaled.width/2<=n.x+o.x&&this.position.y+this.scaled.height/2>=n.y-o.y&&this.position.y-this.scaled.height/2<=n.y+o.y}},e.prototype.resolveTouchAndCircumference=function(){if(this.type===Xt.Circumference)for(var t=0,e=this.touch.interactions;t<e.length;t++){var i=e[t],n=i.positionInViewport,o=i.radius;if(this.pressed)return;ee.subtract(this.distance,this.position,n),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},e}(x),Le=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new ee,e}return u(e,t),e.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},e.prototype.update=function(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(ee.round(this.position,ee.add(this.position,this.camera.transform.position,ee.scale(this.position,this.inputManager.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=this.inputManager.mouse.leftButtonPressed},e}(le),ke=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new ke,this._center=new ke,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ke&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ke,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Ve=function(){function t(){var t=this;this.gamepads=new Map,this.eventHandler=function(e){"gamepadconnected"===e.type?t.gamepadConnected(e.gamepad):"gamepaddisconnected"===e.type&&t.gamepadDisconected(e.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}return t.prototype.getGamepad=function(t){var e;return null!==(e=this.gamepads.get(t))&&void 0!==e?e:null},t.prototype.getGamepads=function(){return Array.from(this.gamepads.values())},t.prototype.gamepadConnected=function(t){this.gamepads.set(t.index,new Ge),this.gamepads.get(t.index).updateFromGamepad(t)},t.prototype.gamepadDisconected=function(t){this.gamepads.delete(t.index)},t.prototype.update=function(){for(var t=0,e=this.getGamepadsFromBrowser();t<e.length;t++){var i=e[t];null!==i&&(!1===this.gamepads.has(i.index)?this.gamepadConnected(i):this.gamepads.get(i.index).updateFromGamepad(i))}},t.prototype.getGamepadsFromBrowser=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),Ge=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new ke,this._leftStickAxes=new ke,this._rightStickAxes=new ke,this._vibrating=!1}return t.prototype.updateFromGamepad=function(t){var e=this;this._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){var o=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return o._vibrating=!1})).finally((function(){return o._vibrating=!1})))},t}(),He=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),We=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new ke,this._hasMoved=!1,this._wheelScroll=new ke,this.lastPositionInViewport=new ke,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),ze=function(){function t(t){var e=this;this._touching=!1,this._interactions=[],this.eventHandler=function(t){"touchstart"===t.type&&(e._touching=!0,e.updatePosition(t)),"touchmove"===t.type&&e.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(e._touching=!1)},this.canvas=t,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"interactions",{get:function(){return this._interactions},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){if(t.preventDefault(),t.stopPropagation(),this._interactions=[],0!==t.targetTouches.length)for(var e=0;e<t.targetTouches.length;e++)this._interactions[e]={positionInViewport:new ke((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new ke(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Xe=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),Ye=function(){function t(t,e,i,n){this._position=new Xe,this._center=new Xe,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof Xe&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}();!function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Xe,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Ne,qe,Ke,Qe=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)};!function(){function t(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}Object.defineProperty(t.prototype,"subdivisions",{get:function(){return this._subdivisions},set:function(t){this._subdivisions=function(t,e,i){return Math.min(i,Math.max(e,t))}(t,1,20)},enumerable:!1,configurable:!0}),t.prototype.resize=function(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(var e=0;e<this._subdivisions;e++){this.itemsInCells[e]=[];for(var i=0;i<this._subdivisions;i++)this.itemsInCells[e][i]=[]}},t.prototype.clear=function(){for(var t=0;t<this._subdivisions;t++)for(var e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]},t.prototype.insert=function(t,e){this.updateCoordinates(e);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].push(t)},t.prototype.retrieve=function(t){var e=[];this.updateCoordinates(t);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].forEach((function(t){return e.includes(t)?null:e.push(t)}));return e},t.prototype.updateCoordinates=function(t){this.coordinates.x0=Qe(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Qe(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Qe(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Qe(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}(),function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Ne||(Ne={})),function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(qe||(qe={})),function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(Ke||(Ke={}));var $e,Je=function(t,e){return Je=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},Je(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}($e||($e={})),function(){function t(t){this.radius=t,this.type=qe.Circumference,this.boundingBox=new Ye(0,0,0,0),this.vertices=[new Xe,new Xe],this.projectionAxes=[new Xe],this._position=new Xe}Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}(),function(){function t(t){this.vertexModel=t,this.type=qe.Polygon,this.vertices=[new Xe,new Xe],this.projectionAxes=[new Xe],this.boundingBox=new Ye(0,0,0,0),this.rotation=0,this._position=new Xe}t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){Xe.normal(this.projectionAxes[0],Xe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var Ze=function(){function t(t){this.vertexModel=t,this.type=qe.Polygon,this.vertices=[],this.boundingBox=new Ye(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Xe,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(var e=0;e<this.vertexModel.length;e++)this.vertices.push(new Xe),this._projectionAxes.push(new Xe)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,e=0;e<this.vertices.length;e++)Xe.normal(this._projectionAxes[e],Xe.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}();!function(t){function e(e,i){var n=t.call(this,[new Xe(-e/2,-i/2),new Xe(-e/2,i/2),new Xe(e/2,i/2),new Xe(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Xe,new Xe],n}(function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}Je(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)})(e,t),e.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},e.prototype.updateProjectionAxes=function(){Xe.unit(this.projectionAxes[0],Xe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Xe.normal(this.projectionAxes[1],this.projectionAxes[0])}}(Ze);export{Te as Animator,Fe as AudioPlayer,be as BallCollider,ve as BoxCollider,Ne as BroadPhaseMethods,Ue as Button,Xt as ButtonType,de as Camera,Ke as CollisionMethods,b as Component,we as EdgeCollider,se as Game,fe as GameCamera,le as GameObject,Ve as GamepadController,Ge as GamepadData,He as KeyboardController,ue as LAYER_DEFAULT,Ce as MaskRenderer,Y as MaskShape,We as MouseController,M as PhysicsComponent,ye as PolygonCollider,me as PolygonColliderRenderer,j as PreRenderComponent,e as Rectangle,ce as RigidBody,Ct as RigidBodyType,h as Rotation,ge as Scene,Le as SpacePointer,Ie as Sprite,Pe as SpriteRenderer,Q as TextOrientation,Oe as TextRenderer,Ee as TiledTilemapRenderer,_e as TilemapCollider,S as TilemapOrientation,Se as TilemapRenderer,ze as TouchController,ae as Transform,t as Vector2,Re as VideoRenderer,a as between,i as clamp,r as fixedRound,o as randomFloat,n as randomInt,s as range};
|
|
1
|
+
var t=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),e=function(){function e(e,i,n,o){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,o)}return Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),e.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},e.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},e.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},e.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},e.prototype.contains=function(i){return i instanceof e?i.x1<=this.x1&&i.x>=this.x&&i.y1<=this.y1&&i.y>=this.y:i instanceof t&&!(i.x<this.x||i.y<this.y||i.x>=this.x1||i.y>=this.y1)},e}(),i=function(t,e,i){return Math.min(i,Math.max(e,t))},n=function(t,e){return Math.round(Math.random()*(e-t))+t},o=function(t,e,i){return void 0===i&&(i=2),r(Math.random()*(e-t)+t,i)},r=function(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},s=function(t,e,i){void 0===i&&(i=1);for(var n=[],o=t;o<=e;o+=i)n.push(o);return n},a=function(t,e,i){return t>=e&&t<=i},h=function(){function e(e,i){void 0===e&&(e=null),void 0===i&&(i=null),this._degrees=0,this._radians=0,this._direction=new t,e?this.radians=e:i&&(this.degrees=i)}return Object.defineProperty(e.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),e.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},e}(),c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},c(t,e)};function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l,p=function(){return p=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},p.apply(this,arguments)};function d(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Init=0]="Init",t[t.Start=1]="Start",t[t.Update=2]="Update",t[t.UpdateEngine=3]="UpdateEngine",t[t.UpdateCollider=4]="UpdateCollider",t[t.UpdatePhysics=5]="UpdatePhysics",t[t.UpdateTransform=6]="UpdateTransform",t[t.UpdatePreRender=7]="UpdatePreRender",t[t.UpdateCamera=8]="UpdateCamera",t[t.UpdateRender=9]="UpdateRender",t[t.Destroy=10]="Destroy",t[t.StopGame=11]="StopGame"}(l||(l={}));var f,g,y,m=function(){function t(t,e,i,n,o,r,s){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=o,this.sceneManager=r,this.canvasColor=s,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[l.Start,l.Update,l.StopGame],this.gameObjectEvents=[l.Start,l.Update]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.dispatchFrameEvent(l.StopGame),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene()),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(l.Start),this.inputManager.update(),this.dispatchFrameEvent(l.Update),this.dispatchFrameEvent(l.UpdateEngine),this.dispatchFrameEvent(l.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(l.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(l.UpdatePreRender),this.dispatchFrameEvent(l.UpdateCamera),this.dispatchFrameEvent(l.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(l.UpdatePhysics),this.dispatchFrameEvent(l.UpdateCollider),this.dispatchFrameEvent(l.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),v=function(){function t(t){this.updateEvent=l.Update,this.started=!1,this.container=t,this.gameConfig=this.container.getConstant("GameConfig"),this.gameConfig.headless||(this.assetManager=this.container.getSingleton("AssetManager"),this.domManager=this.container.getSingleton("DomManager"),this.inputManager=this.container.getSingleton("InputManager"),this.renderManager=this.container.getSingleton("RenderManager")),this.gameObjectManager=this.container.getSingleton("GameObjectManager"),this.physicsManager=this.container.getSingleton("PhysicsManager"),this.sceneManager=this.container.getSingleton("SceneManager"),this.timeManager=this.container.getSingleton("TimeManager")}return t.prototype.dispatch=function(t,e){t===l.Init&&this.init?this.init(e):t!==l.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===l.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===l.StopGame&&(this.onDestroy&&this.onDestroy(),this._stopGame()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),b=function(t){function e(e,i,n){void 0===n&&(n="");var o=t.call(this,e)||this;return o.allowMultiple=!0,o._active=!0,o.gameObject=i,o.name=n,o}return u(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChange())},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getLoadedScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){},e}(v),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateEngine,e}return u(e,t),e}(b),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateCollider,e}return u(e,t),e}(b),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdatePhysics,e}return u(e,t),e}(b),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateTransform,e}return u(e,t),e}(b),j=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdatePreRender,e}return u(e,t),e}(b),P=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateCamera,e}return u(e,t),e}(b),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=l.UpdateRender,e}return u(e,t),e}(b);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(f||(f={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(g||(g={})),function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric",t[t.Video=5]="Video"}(y||(y={}));var O=function(){function t(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}return t.prototype.setViewport=function(t,e){var i=t.position,n=t.zoom;e===g.WorldSpace?(this.viewport.x=i.x-this.gl.canvas.width/n/2,this.viewport.x1=i.x+this.gl.canvas.width/n/2,this.viewport.y=i.y-this.gl.canvas.height/n/2,this.viewport.y1=i.y+this.gl.canvas.height/n/2):(this.viewport.x=-this.gl.canvas.width/2,this.viewport.x1=this.gl.canvas.width/2,this.viewport.y=-this.gl.canvas.height/2,this.viewport.y1=this.gl.canvas.height/2)},t.prototype.setObjectForResizeable=function(t){var e=t.position,i=t.width,n=t.height,o=t.rotation,r=void 0===o?0:o,s=Math.abs(Math.sin(r)),a=Math.abs(Math.cos(r)),h=s*n+a*i,c=s*i+a*n;this.object.x=e.x-h/2,this.object.x1=e.x+h/2,this.object.y=e.y-c/2,this.object.y1=e.y+c/2},t.prototype.setObjectForText=function(t){var e=t.position,i=t.text,n=t.fontSize,o=t.lineSeparation,r=t.letterSpacing,s=t.rotation,a=i.split("\n").reduce((function(t,e){return Math.max(t,e.length)}),0)*(n+(null!=r?r:0))*2,h=i.split("\n").length*(n+(null!=o?o:0));this.setObjectForResizeable({position:e,width:a,height:h,rotation:s})},t.prototype.setObjectForGeometric=function(t){var e=this,i=t.position,n=t.vertexModel,o=t.shape,r=t.radius;o===f.Circumference?(this.object.x=i.x-r,this.object.y=i.y-r,this.object.x1=i.x+r,this.object.y1=i.y+r):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,n.forEach((function(t){e.object.x=Math.min(t.x+i.x,e.object.x),e.object.y=Math.min(t.y+i.y,e.object.y),e.object.x1=Math.max(t.x+i.x,e.object.x1),e.object.y1=Math.max(t.y+i.y,e.object.y1)})))},t.prototype.setObjectForTilemap=function(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.renderPosition,width:t.tilemap.width*t.tilemap.tileWidth,height:t.tilemap.height*t.tilemap.tileHeight,rotation:t.rotation})},t.prototype.applyCullingInTiles=function(t){var e=this,i=t.tiles,n=t.tilemap,o=n.width,r=n.tileWidth,s=n.tileHeight;t.culledTiles=i.map((function(t,i){return e.viewport.x1>=e.object.x+i%o*r&&e.viewport.x<=e.object.x+i%o*r+r&&e.viewport.y1>=e.object.y1-((i/o|0)*s+s)&&e.viewport.y<=e.object.y1-(i/o|0)*s?t:0}))},t.prototype.isInViewPort=function(t,e){switch(this.setViewport(e,t.location),t.type){case y.Video:case y.Mask:case y.Sprite:this.setObjectForResizeable(t);break;case y.Geometric:this.setObjectForGeometric(t);break;case y.Text:this.setObjectForText(t);break;case y.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1},t.prototype.applyCulling=function(t,e){var i=this;return e.filter((function(e){return!!i.isInViewPort(e,t)&&(e.type===y.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),A=function(){return A=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},A.apply(this,arguments)};function R(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var S,E=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new E,this._center=new E,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof E&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new E,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}(),function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(S||(S={}));var T,D=function(){function t(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}return t.prototype.addRenderData=function(t){this.renderData.push(t)},t.prototype.addCameraData=function(t){this.cameraData.push(t)},t.prototype.render=function(){var t=this;this.cameraData.sort((function(t,e){return t.depth-e.depth})).forEach((function(e){return t.renderByCamera(e)}))},t.prototype.renderByCamera=function(t){var e=this;this.cullingManager.applyCulling(t,this.renderData.filter((function(e){return t.layers.includes(e.layer)})).sort((function(e,i){return t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer)})).map((function(t){return t.type===y.Tilemap?function(t){var e=A(A({},t),{culledTiles:[],tilemap:A(A({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new E});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==S.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===S.RightDown?-t.tilemap.realHeight/2:t.orientation===S.RightUp?t.tilemap.realHeight/2:0))}(e),e}(t):t}))).forEach((function(i){return e.webglManager.render(i,t)}))},t.prototype.clearData=function(){this.renderData=[],this.cameraData=[]},t.prototype.clearScreen=function(t){this.webglManager.clearCanvas(t)},t.prototype.preloadTexture=function(t){this.webglManager.createTexture(t)},t}();!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(T||(T={}));var B=function(){function t(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}return t.prototype.getContextVersion=function(){return null!==this.canvas.getContext(T.WebGL2)?T.WebGL2:null!==this.canvas.getContext(T.LegacyWebGL)?T.LegacyWebGL:void 0},t}(),F=function(){function t(){this.fontAtlas=new Map}return t.prototype.hasFontAtlas=function(t){return this.fontAtlas.has(this.symbol(t))},t.prototype.getFontAtlas=function(t){return this.fontAtlas.get(this.symbol(t))},t.prototype.getOrCreate=function(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)},t.prototype.create=function(t,e,i){this.bitmapSize=i,this.chars=[];for(var n=0;n<t.length;n+=2)for(var o=t[n];o<=t[n+1];o++)this.chars.push(String.fromCharCode(o));var r=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),r),r},t.prototype.symbol=function(t){return Symbol.for(t instanceof FontFace?t.family:t)},t.prototype.renderAtlas=function(t){var e=new I(t,this.bitmapSize,Math.ceil(Math.sqrt(this.chars.length))),i=e.canvas.getContext("2d");i.clearRect(0,0,e.canvas.width,e.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font="".concat(this.bitmapSize,"px ").concat(t);for(var n=0,o=0,r=0;r<this.chars.length;r++)i.fillText(this.chars[r],n,o),e.glyphs.set(this.chars[r],{id:r,width:i.measureText(this.chars[r]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,o+=this.bitmapSize);return e},t}(),I=function(t,e,i){this.fontFaceFamily=t,this.bitmapFontSize=e,this.gridSize=i,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*this.bitmapFontSize,this.canvas.height=this.canvas.width},U=function(){function t(t,e){this.gl=t,this.shaderLoader=e}return t.prototype.create=function(t,e){var i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,o),this.gl.linkProgram(i);var r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){var s=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error("Unable to initialize the Program: ".concat(s))}return i},t}(),L=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===T.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision highp float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)},t}(),k=function(){function t(t){this.gl=t}return t.prototype.load=function(t,e){var i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);var n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){var o=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error("Unable to initialize the shader program: ".concat(o))}return i},t}(),V="undefined"!=typeof Float32Array?Float32Array:Array;function G(){var t=new V(16);return V!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function H(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function W(t,e,i){var n,o,r,s,a,h,c,u,l,p,d,f,g=i[0],y=i[1],m=i[2];return e===t?(t[12]=e[0]*g+e[4]*y+e[8]*m+e[12],t[13]=e[1]*g+e[5]*y+e[9]*m+e[13],t[14]=e[2]*g+e[6]*y+e[10]*m+e[14],t[15]=e[3]*g+e[7]*y+e[11]*m+e[15]):(n=e[0],o=e[1],r=e[2],s=e[3],a=e[4],h=e[5],c=e[6],u=e[7],l=e[8],p=e[9],d=e[10],f=e[11],t[0]=n,t[1]=o,t[2]=r,t[3]=s,t[4]=a,t[5]=h,t[6]=c,t[7]=u,t[8]=l,t[9]=p,t[10]=d,t[11]=f,t[12]=n*g+a*y+l*m+e[12],t[13]=o*g+h*y+p*m+e[13],t[14]=r*g+c*y+d*m+e[14],t[15]=s*g+u*y+f*m+e[15]),t}function z(t,e,i){var n=i[0],o=i[1],r=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function X(t,e,i){var n=Math.sin(i),o=Math.cos(i),r=e[0],s=e[1],a=e[2],h=e[3],c=e[4],u=e[5],l=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*o+c*n,t[1]=s*o+u*n,t[2]=a*o+l*n,t[3]=h*o+p*n,t[4]=c*o-r*n,t[5]=u*o-s*n,t[6]=l*o-a*n,t[7]=p*o-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var Y,N=function(t){var e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},q=function(t,e,i,n){var o,r;(function(t,e,i,n,o,r,s){var a=1/(e-i),h=1/(n-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=(e+i)*a,t[13]=(o+n)*h,t[14]=-0,t[15]=1})(t=H(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===g.WorldSpace&&(z(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1]),W(t,t,[-i.position.x,-i.position.y,0]))},K=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G();var i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(function(t,e,i){void 0===i&&(i=1);for(var n=[],o=1;o<=60;o+=i)n.push(o);return n}(0,0,1).reduce((function(t,e){return R(R([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case f.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case f.Line:this.renderLines(t,e,this.gl.LINES,i);break;case f.Circumference:this.renderCircumference(t,e)}},t.prototype.renderLines=function(t,e,i,n){var o,r=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(r)&&this.vertices.set(r,new Float32Array(this.generatePolygonVertices(t.vertexModel)));var s=this.vertices.get(r);this.lastVertices===r&&n===y.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW)),this.lastVertices=r,this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var a=N(t.color),h=a.r,c=a.g,u=a.b,l=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,c,u,l),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)},t.prototype.generateVerticesKey=function(t){return Symbol.for(t.reduce((function(t,e){return"".concat(t).concat(e.x).concat(e.y)}),t.length.toString()))},t.prototype.generatePolygonVertices=function(t){for(var e=[],i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e},t.prototype.renderCircumference=function(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),z(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var i=N(t.color),n=i.r,o=i.g,r=i.b,s=i.a;this.gl.uniform4f(this.programManager.solidColorUniform,n,o,r,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)},t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Y||(Y={}));var Q,$=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=y.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G();for(var i=2*Math.PI/60,n=[0,0],o=0;o<=60;o++)n.push(Math.cos(o*i),Math.sin(o*i));this.circumferenceVertices=new Float32Array(n)}return t.prototype.render=function(t,e,i){var n,o;i===y.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===Y.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,t.shape===Y.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha>=0&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var r=N(t.color),s=r.r,a=r.g,h=r.b,c=r.a;this.gl.uniform4f(this.programManager.solidColorUniform,s,a,h,c),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),t.shape===Y.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape},t}(),J=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,o,r,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),t.slice&&(W(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}();!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Q||(Q={}));var Z=new E,tt=new E,et=[32,126,161,255],it=Q.Center,nt=function(){function t(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=y.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new E,this.modelPosition=new E,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G()}return t.prototype.render=function(t,e,i){var n;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);var o=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(o,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),this.setPositionFromOrientation(t),W(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=H(this.textureMatrix),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);var r=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+o.fontFaceFamily,o.canvas,t.smooth);this.lastTexture===r&&i===y.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=r),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);var s=N(t.color),a=s.r,h=s.g,c=s.b,u=s.a;this.gl.uniform4f(this.programManager.maskColorUniform,a,h,c,u),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.setDefaultValues=function(t){var e,i,n,o,r,s,a,h,c,u;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:Z,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:tt,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(o=t.bitmap.charRanges)&&void 0!==o?o:et):t.bitmap={margin:Z,spacing:tt,fontSize:64,charRanges:et},t.color=null!==(r=t.color)&&void 0!==r?r:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(c=t.orientation)&&void 0!==c?c:it,t.rotation=null!==(u=t.rotation)&&void 0!==u?u:0},t.prototype.generateTextVertices=function(t,e){var i=e.text,n=e.fontSize,o=e.bitmap,r=e.letterSpacing,s=e.lineSeparation;this.posVertices=[],this.texVertices=[];var a=0,h=0,c=0;r/=n,s/=n;for(var u=0;u<i.length;u++){var l=i[u];if("\n"!==l){var p=t.glyphs.get(l);if(p){var d=p.width/t.bitmapFontSize;this.posVertices.push(a,h-1,a+d,h-1,a,h,a,h,a+d,h-1,a+d,h);var f=p.id%t.gridSize*t.bitmapFontSize,g=(p.id/t.gridSize|0)*t.bitmapFontSize,y=(f+o.margin.x)/t.canvas.width,m=(g+o.margin.y)/t.canvas.width,v=(f+p.width+o.spacing.x)/t.canvas.width,b=(g+t.bitmapFontSize+o.spacing.y)/t.canvas.width;this.texVertices.push(y,b,v,b,y,m,y,m,v,b,v,m),a+=d+r}}else c=Math.max(c,a),a=0,h-=1+s}this.textSize.set(Math.max(c,a)*n,Math.abs(h-1)*n)},t.prototype.setPositionFromOrientation=function(t){this.modelPosition.set(t.position.x+(t.orientation===Q.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Q.Center||t.orientation===Q.RightCenter?this.textSize.y/2:t.orientation===Q.RightUp?this.textSize.y:0))},t}(),ot=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.tileset={width:0,tileWidth:0,tileHeight:0,texMargin:new E,texSpacing:new E,texWidth:0,texHeight:0,texCorrection:new E},this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G()}return t.prototype.render=function(t,e,i){var n,o,r,s;if(0===t.culledTiles.reduce((function(t,e){return t+e}),0))throw new Error("Nothing to render");if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)throw new Error("Nothing to render");this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),z(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===y.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.processTileset=function(t){var e,i,n,o,r,s,a,h=t.tileset;h.margin=null!==(e=h.margin)&&void 0!==e?e:new E,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new E,h.correction=null!==(n=h.correction)&&void 0!==n?n:new E,this.tileset.width=h.width,this.tileset.tileWidth=h.tileWidth+(null!==(o=h.margin.x)&&void 0!==o?o:0)+(null!==(r=h.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=h.tileHeight+(null!==(s=h.margin.y)&&void 0!==s?s:0)+(null!==(a=h.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(h.margin.x/this.tileset.tileWidth,h.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(h.spacing.x/this.tileset.tileWidth,h.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(h.correction.x/this.tileset.tileWidth,h.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y},t.prototype.generateVertices=function(t){var e=this,i=t.culledTiles,n=t.tilemap;this.posVertices=[],this.texVertices=[];var o=Math.floor(i.length/n.width);i.forEach((function(t,i){if(0!==t){var r=i%n.width-n.width/2,s=o/2-Math.floor(i/n.width);e.posVertices.push(r,s-1,r+1,s-1,r,s,r,s,r+1,s-1,r+1,s);var a=(t-1)%e.tileset.width+e.tileset.texMargin.x+e.tileset.texCorrection.x,h=Math.floor((t-1)/e.tileset.width)+e.tileset.texMargin.y+e.tileset.texCorrection.y;e.texVertices.push(a,h+e.tileset.texHeight,a+e.tileset.texWidth,h+e.tileset.texHeight,a,h,a,h,a+e.tileset.texWidth,h+e.tileset.texHeight,a+e.tileset.texWidth,h)}}))},t}(),rt=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=G(),this.modelMatrix=G(),this.textureMatrix=G(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,o,r,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=H(this.modelMatrix),W(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),X(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=H(this.textureMatrix),t.slice&&(W(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),q(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);var a=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){var h=N(t.tintColor),c=h.r,u=h.g,l=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=N(t.maskColor);c=d.r,u=d.g,l=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),st=function(){function t(t){this.gl=t}return t.prototype.createFromImage=function(t,e,i){var n=this;return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(function(){return n.createFromSource(t,i,e)})),i},t.prototype.createFromCanvas=function(t,e,i){return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i},t.prototype.createPixelTexture=function(){var t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t},t.prototype.createFromSource=function(t,e,i){void 0===i&&(i=!0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)},t}(),at=function(){function t(t){this.textureFactory=t,this.textures=new Map}return t.prototype.getOrCreateTextureFromImage=function(t,e){var i;return void 0===e&&(e=!0),null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)},t.prototype.createTextureFromImage=function(t,e){void 0===e&&(e=!0);var i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i},t.prototype.getOrCreateTextureFromCanvas=function(t,e,i){var n;return void 0===i&&(i=!0),null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)},t.prototype.createTextureFromCanvas=function(t,e,i){void 0===i&&(i=!0);var n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n},t.prototype.getOrCreateTextureFromVideo=function(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)},t.prototype.createTextureFromVideo=function(t){var e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e},t}(),ht=function(){function t(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}return t.prototype.render=function(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}},t.prototype.clearCanvas=function(t){var e=N(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.createTexture=function(t,e){void 0===e&&(e=!1),this.textureManager.createTextureFromImage(t,e)},t}(),ct=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),ut=function(){function t(t,e,i,n){this._position=new ct,this._center=new ct,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ct&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),lt=function(t,e,i){return Math.min(i,Math.max(e,t))};!function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ct,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var pt,dt=function(){function t(){}return t.prototype.create=function(t){var e=t.shape,i=t.layer,n=t.updateCollisions,o=t.physics,r=t.position,s=t.rotation,a=t.group,h=t.onCollision;return{id:0,active:!0,layer:i,shape:e,updateCollisions:n,physics:o,position:null!=r?r:new ct,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),ft=function(){function t(t,e){void 0===e&&(e=0),this.area=new ut(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}return t.prototype.resize=function(t){this.clear(),this.area.copy(t)},t.prototype.clear=function(){this.items=[],this.children.forEach((function(t){return t.clear()})),this.children=[]},t.prototype.insert=function(t,e){0===this.children.length&&this.items.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.items.push([t,e])},t.prototype.split=function(){var e=this,i=this.area.width/2,n=this.area.height/2;this.children=[new ut(this.area.x,this.area.y,i,n),new ut(this.area.x,this.area.y+n,i,n),new ut(this.area.x+i,this.area.y+n,i,n),new ut(this.area.x+i,this.area.y,i,n)].map((function(i){return new t(i,e.depth+1)})),this.items.forEach((function(t){return e.insertItemIntoChildren(t[0],t[1])})),this.items=[]},t.prototype.insertItemIntoChildren=function(t,e){this.getChildrenForArea(e).forEach((function(i){return i.insert(t,e)}))},t.prototype.retrieve=function(t){var e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})):this.items.forEach((function(t){return e.push(t[0])})),e},t.prototype.getChildrenForArea=function(t){var e=[];return t.x<=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[0]),t.x<=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[1]),t.x1>=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[2]),t.x1>=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[3]),e},t}(),gt=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},yt=function(){function t(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}return Object.defineProperty(t.prototype,"subdivisions",{get:function(){return this._subdivisions},set:function(t){this._subdivisions=lt(t,1,20)},enumerable:!1,configurable:!0}),t.prototype.resize=function(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(var e=0;e<this._subdivisions;e++){this.itemsInCells[e]=[];for(var i=0;i<this._subdivisions;i++)this.itemsInCells[e][i]=[]}},t.prototype.clear=function(){for(var t=0;t<this._subdivisions;t++)for(var e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]},t.prototype.insert=function(t,e){this.updateCoordinates(e);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].push(t)},t.prototype.retrieve=function(t){var e=[];this.updateCoordinates(t);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].forEach((function(t){return e.includes(t)?null:e.push(t)}));return e},t.prototype.updateCoordinates=function(t){this.coordinates.x0=gt(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=gt(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=gt(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=gt(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(pt||(pt={}));var mt,vt=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new ct,this.maxArea=new ct,this.newArea=new ut(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:pt.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new ut(0,0,0,0),this.fixedCollisionArea=!!e,t===pt.SpartialGrid?this.broadPhaseResolver=new yt(this.collisionArea):this.broadPhaseResolver=new ft(this.collisionArea)},t.prototype.addCollider=function(t){t.id=this.colliders.length,this.colliders.push(t)},t.prototype.getCollider=function(t){return this.colliders[t]},t.prototype.removeCollider=function(t){this.colliders.splice(t.id,1),this.colliders.forEach((function(t,e){return t.id=e}))},t.prototype.clearColliders=function(){this.colliders=[]},t.prototype.getCollisionsForCollider=function(t){return t.active?this.collisions.filter((function(e){return e.localCollider.id===t.id})):[]},t.prototype.refreshCollisionsForCollider=function(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((function(e){return e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id})),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))},t.prototype.resolve=function(){var t=this;this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((function(t){return t.active})),this.broadPhaseResolver.clear(),this.activeColliders.forEach((function(e){t.updateShape(e)})),!1===this.fixedCollisionArea&&(this.updateNewArea(),!1===this.newArea.equals(this.collisionArea)&&(this.collisionArea.copy(this.newArea),this.broadPhaseResolver.resize(this.collisionArea))),this.checkForSpartialGridResize(),this.activeColliders.forEach((function(e){var i=e.id,n=e.shape.boundingBox;return t.broadPhaseResolver.insert(i,n)})),this.updateCollisions())},t.prototype.updateShape=function(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()},t.prototype.updateNewArea=function(){var t=this;this.activeColliders.forEach((function(e){var i=e.shape.boundingBox;t.minArea.set(Math.min(i.x,t.minArea.x),Math.min(i.y,t.minArea.y)),t.maxArea.set(Math.max(i.x1,t.maxArea.x),Math.max(i.y1,t.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)},t.prototype.checkForSpartialGridResize=function(){this.broadPhaseResolver instanceof yt&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)},t.prototype.updateCollisions=function(){var t=this;this.activeColliders.filter((function(t){return t.updateCollisions})).forEach((function(e){return t.narrowPhase(e,t.broadPhase(e))}))},t.prototype.broadPhase=function(t){var e=this;return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active})).filter((function(i){return e.collisionMatrix.some((function(e){return e[0]===t.layer&&e[1]===i.layer||e[1]===t.layer&&e[0]===i.layer}))})):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active}))},t.prototype.narrowPhase=function(t,e){var i=this;e.filter((function(e){return!(t.group&&e.group&&e.group===t.group||t.id===e.id)})).forEach((function(e){if(!i.isResolved(t,e)){var n=i.method.getCollisionResolution(t.shape,e.shape);null!==n&&(i.collisions.push({localCollider:t,remoteCollider:e,resolution:n},{localCollider:e,remoteCollider:t,resolution:{direction:n.displacementDirection,displacementDirection:n.direction,penetration:n.penetration}}),t.onCollision&&t.onCollision(n))}}))},t.prototype.isResolved=function(t,e){for(var i=0,n=this.collisions;i<n.length;i++){var o=n[i];if(o.localCollider.id===t.id&&o.remoteCollider.id===e.id)return!0}return!1},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(mt||(mt={}));var bt,xt=function(){function t(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}return t.prototype.getCollisionResolution=function(t,e){return t.type===mt.Polygon&&e.type===mt.Polygon?this.AABBResolver.resolve(t,e):t.type===mt.Circumference&&e.type===mt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===mt.Polygon&&e.type===mt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===mt.Circumference&&e.type===mt.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(bt||(bt={}));var _t=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===mt.Circumference&&e.type===mt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),Mt=function(){function t(){this.direction=new ct,this.displacementDirection=new ct}return t.prototype.resolve=function(t,e){var i=t.boundingBox,n=e.boundingBox;return this.overlapX=Math.min(i.x1,n.x1)-Math.max(i.x,n.x),this.overlapY=Math.min(i.y1,n.y1)-Math.max(i.y,n.y),this.overlapX<0||this.overlapY<0?null:(this.checkOverlapForLines(i,n),this.direction.set(Math.sign(n.center.x-i.center.x),Math.sign(n.center.y-i.center.y)),this.preventContainment(i,n),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),ct.unit(this.displacementDirection,this.displacementDirection),{direction:ct.scale(new ct,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),penetration:this.minOverlap})},t.prototype.checkOverlapForLines=function(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))},t.prototype.preventContainment=function(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){var i=Math.abs(t.y-e.y),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)&&(i=Math.abs(t.x-e.x),n=Math.abs(t.x1-e.x1),this.overlapX+=i<n?i:n)},t}(),wt=function(){function t(){this.closestPoint=new ct,this.distance=new ct,this.direction=new ct}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(lt(t.position.x,e.boundingBox.x,e.boundingBox.x1),lt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),ct.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(ct.unit(this.direction,this.distance),{direction:i?ct.scale(new ct,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():ct.scale(new ct,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),jt=function(){function t(){this.distance=new ct,this.direction=new ct}return t.prototype.resolve=function(t,e){return ct.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(ct.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:ct.scale(new ct,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),Pt=function(t,e){return Pt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},Pt(t,e)};function Ct(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var Ot,At=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new ct,this.distance=new ct(1/0,1/0),this.cache=new ct}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===mt.Circumference?this.setCircumferenceAxis(t,e):e.type===mt.Circumference&&this.setCircumferenceAxis(e,t),this.axes=Ct([],t.projectionAxes,!0),e.projectionAxes.forEach((function(t){return i.axes.some((function(e){return e.equals(t)}))?null:i.axes.push(t)}));for(var n=0;n<this.axes.length;n++){if(t.type===mt.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===mt.Circumference&&this.setCircumferenceVertices(e,this.axes[n]),this.projectShapeOntoAxis(this.projA,t,this.axes[n]),this.projectShapeOntoAxis(this.projB,e,this.axes[n]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;if(this.invertAxis=!0,this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){var o=Math.abs(this.projA.min-this.projB.min),r=Math.abs(this.projA.max-this.projB.max);o<r?this.currentOverlap+=o:(this.currentOverlap+=r,ct.scale(this.axes[n],this.axes[n],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[n]),this.invertAxis&&this.projA.max<this.projB.max&&ct.scale(this.smallestAxis,this.axes[n],-1))}return{direction:ct.scale(new ct,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}},t.prototype.projectShapeOntoAxis=function(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((function(e){t.min=Math.min(ct.dot(i,e),t.min),t.max=Math.max(ct.dot(i,e),t.max)})),t},t.prototype.setCircumferenceAxis=function(t,e){var i=this;this.distance.set(1/0,1/0),e.vertices.forEach((function(e){ct.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),ct.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){ct.add(t.vertices[0],t.position,ct.scale(this.cache,ct.unit(this.cache,e),-t.radius)),ct.add(t.vertices[1],t.position,ct.scale(this.cache,ct.unit(this.cache,e),t.radius))},t}(),Rt=function(){function t(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}return t.prototype.addCollider=function(t){var e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e},t.prototype.removeCollider=function(t){this.collisionManager.removeCollider(t)},t.prototype.getCollisionsForCollider=function(t){return this.collisionManager.getCollisionsForCollider(t)},t.prototype.addRigidBody=function(t){var e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e},t.prototype.removeRigidBody=function(t){this.rigidBodyManager.removeRigidBody(t)},t.prototype.resolve=function(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)},t.prototype.clear=function(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()},t}(),St=function(){function t(){}return t.prototype.create=function(t){var e=t.colliderIds,i=t.type,n=t.gravity,o=t.position,r=t.velocity,s=t.onResolve;if(0===e.length)throw new Error("RigidBody needs at least one collider");return{active:!0,colliderIds:e,type:i,gravity:null!=n?n:0,position:null!=o?o:new ct,velocity:null!=r?r:new ct,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Ot||(Ot={}));var Et=["x","y"],Tt=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new ct,this.displacement=new ct,this.cacheDisplacement=0}return t.prototype.addRigidBody=function(t){this.rigidBodies.push(t)},t.prototype.removeRigidBody=function(t){var e=this.rigidBodies.indexOf(t);e>=0&&this.rigidBodies.splice(e,1)},t.prototype.clearRigidBodies=function(){this.rigidBodies=[]},t.prototype.resolve=function(t){var e=this;this.activeRigidBodies=this.rigidBodies.filter((function(t){return t.active})),this.colliders=this.activeRigidBodies.reduce((function(t,e){return Ct(Ct([],t,!0),e.colliderIds,!0)}),[]),this.activeRigidBodies.forEach((function(i){i.type===Ot.Dynamic?e.dynamicUpdate(i,t):i.type===Ot.Kinematic&&e.kinematicUpdate(i,t),i.onResolve&&i.onResolve(i)}))},t.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),Et.forEach((function(n){i.applyVelocity(t,e,n),i.obtainDisplacement(t,n),i.applyReposition(t,n)}))},t.prototype.kinematicUpdate=function(t,e){var i=this;ct.add(t.position,t.position,ct.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){ct.add(t.position,t.position,i.velocity),i.collisionManager.refreshCollisionsForCollider(t)}))},t.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},t.prototype.applyVelocity=function(t,e,i){var n=this;this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((function(t){return n.collisionManager.getCollider(t)})).forEach((function(t){t.position[i]+=n.velocity[i],n.collisionManager.refreshCollisionsForCollider(t)})))},t.prototype.obtainDisplacement=function(t,e){var i=this;this.displacement[e]=0,this.getCollisions(t).forEach((function(t){i.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,i.displacement[e]=Math.abs(i.displacement[e])>Math.abs(i.cacheDisplacement)?i.displacement[e]:i.cacheDisplacement}))},t.prototype.applyReposition=function(t,e){var i=this;0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){t.position[e]+=i.displacement[e],i.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))},t.prototype.getCollisions=function(t){var e=this;return t.colliderIds.map((function(t){return e.collisionManager.getCollider(t)})).filter((function(t){return t.active&&t.physics})).reduce((function(t,i){return t.push.apply(t,e.collisionManager.getCollisionsForCollider(i).filter((function(t){return t.remoteCollider.physics&&e.colliders.includes(t.remoteCollider.id)}))),t}),[])},t}(),Dt=function(){function t(t){this.radius=t,this.type=mt.Circumference,this.boundingBox=new ut(0,0,0,0),this.vertices=[new ct,new ct],this.projectionAxes=[new ct],this._position=new ct}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},t}(),Bt=function(){function t(t){this.vertexModel=t,this.type=mt.Polygon,this.vertices=[new ct,new ct],this.projectionAxes=[new ct],this.boundingBox=new ut(0,0,0,0),this.rotation=0,this._position=new ct}return t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){ct.normal(this.projectionAxes[0],ct.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),Ft=function(){function t(t){this.vertexModel=t,this.type=mt.Polygon,this.vertices=[],this.boundingBox=new ut(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new ct,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(var e=0;e<this.vertexModel.length;e++)this.vertices.push(new ct),this._projectionAxes.push(new ct)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,e=0;e<this.vertices.length;e++)ct.normal(this._projectionAxes[e],ct.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),It=function(t){function e(e,i){var n=t.call(this,[new ct(-e/2,-i/2),new ct(-e/2,i/2),new ct(e/2,i/2),new ct(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new ct,new ct],n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}Pt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,t),e.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},e.prototype.updateProjectionAxes=function(){ct.unit(this.projectionAxes[0],ct.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),ct.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(Ft),Ut=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new Ut,this._center=new Ut,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof Ut&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Ut,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Lt,kt=function(){function t(){var t=this;this.gamepads=new Map,this.eventHandler=function(e){"gamepadconnected"===e.type?t.gamepadConnected(e.gamepad):"gamepaddisconnected"===e.type&&t.gamepadDisconected(e.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}return t.prototype.getGamepad=function(t){var e;return null!==(e=this.gamepads.get(t))&&void 0!==e?e:null},t.prototype.getGamepads=function(){return Array.from(this.gamepads.values())},t.prototype.gamepadConnected=function(t){this.gamepads.set(t.index,new Vt),this.gamepads.get(t.index).updateFromGamepad(t)},t.prototype.gamepadDisconected=function(t){this.gamepads.delete(t.index)},t.prototype.update=function(){for(var t=0,e=this.getGamepadsFromBrowser();t<e.length;t++){var i=e[t];null!==i&&(!1===this.gamepads.has(i.index)?this.gamepadConnected(i):this.gamepads.get(i.index).updateFromGamepad(i))}},t.prototype.getGamepadsFromBrowser=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),Vt=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Ut,this._leftStickAxes=new Ut,this._rightStickAxes=new Ut,this._vibrating=!1}return t.prototype.updateFromGamepad=function(t){var e=this;this._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){var o=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return o._vibrating=!1})).finally((function(){return o._vibrating=!1})))},t}(),Gt=function(){function t(t,e,i,n){this.mouse=t,this.keyboard=e,this.gamepad=i,this.touch=n}return t.prototype.update=function(){this.mouse.update(),this.gamepad.update()},t}(),Ht=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),Wt=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Ut,this._hasMoved=!1,this._wheelScroll=new Ut,this.lastPositionInViewport=new Ut,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),zt=function(){function t(t){var e=this;this._touching=!1,this._interactions=[],this.eventHandler=function(t){"touchstart"===t.type&&(e._touching=!0,e.updatePosition(t)),"touchmove"===t.type&&e.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(e._touching=!1)},this.canvas=t,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"interactions",{get:function(){return this._interactions},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){if(t.preventDefault(),t.stopPropagation(),this._interactions=[],0!==t.targetTouches.length)for(var e=0;e<t.targetTouches.length;e++)this._interactions[e]={positionInViewport:new Ut((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new Ut(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Lt||(Lt={}));var Xt,Yt=function(){function t(t){this.renderManager=t,this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.loadImage=function(t,e){var i=this;void 0===e&&(e=!1);var n=new Image;n.crossOrigin="",n.src=t;var o=this.createAsset(t,Lt.Image,n),r=function(){e&&i.renderManager.preloadTexture(n),o.loaded=!0};return n.naturalWidth?r():n.addEventListener("load",r),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,Lt.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url(".concat(e,")")),n=this.createAsset(e,Lt.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.loadVideo=function(t){var e=document.createElement("video");e.playsInline=!0,e.src=t;var i=this.createAsset(t,Lt.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Image&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getAudio=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Audio&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getFont=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Font&&e.family===t})))||void 0===e?void 0:e.element},t.prototype.getVideo=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===Lt.Video&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var n={type:e,url:t,element:i,loaded:!1};return this.assets.push(n),n},t}(),Nt=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return u(e,t),e}(Error),qt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Nt("containerNode cannot be empty or null.");this.containerNode=t,this.gameWidth=e,this.gameHeight=i,this.setupCanvas()}return Object.defineProperty(t.prototype,"canvas",{get:function(){return this._canvas},enumerable:!1,configurable:!0}),t.prototype.setupCanvas=function(){this._canvas=document.createElement("canvas"),this._canvas.id="angryPixelGameCanvas",this._canvas.width=Math.floor(this.gameWidth),this._canvas.height=Math.floor(this.gameHeight),this.canvas.tabIndex=0,this._canvas.addEventListener("contextmenu",(function(t){return t.preventDefault()})),this.containerNode.appendChild(this._canvas),this.canvas.focus()},t}(),Kt=function(){function t(t){this.container=t,this.gameObjects=[],this.lastId=0}return t.prototype.addGameObject=function(t,e,i,n){var o=new t(this.container,++this.lastId,n,i);return this.gameObjects.push(o),o.dispatch(l.Init,e),o},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):d([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(t){var e=this;void 0===t&&(t=!1),this.gameObjects.filter((function(e){return t||!e.keep})).forEach((function(t){return e.destroy(t,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var n=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(n),n.dispatch(l.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Qt=function(){function t(t,e,i,n){this.timeManager=t,this.physicsManager=e,this.gameObjectManager=i,this.sceneManager=n,this.running=!1,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[l.Start,l.Update,l.StopGame],this.gameObjectEvents=[l.Start,l.Update]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.dispatchFrameEvent(l.StopGame),this.physicsManager.clear()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.load(),this.dispatchFrameEvent(l.Start),this.dispatchFrameEvent(l.Update),this.dispatchFrameEvent(l.UpdateEngine),this.dispatchFrameEvent(l.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene())},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(l.UpdatePhysics),this.dispatchFrameEvent(l.UpdateCollider),this.dispatchFrameEvent(l.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),$t=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.sceneNamePendingToLoad=null}return t.prototype.addScene=function(t,e,i,n){var o=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new Nt("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(o.container,e,o.container.getConstant("Game"));return o.currentScene=n,n.dispatch(l.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new Nt("Scene with name ".concat(t," does not exists"));this.sceneNamePendingToLoad=t},t.prototype.getLoadedScene=function(){return this.currentScene},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new Nt("There is no opening scene");this.scenes.get(this.openingSceneName)()},t.prototype.pendingSceneToload=function(){return null!==this.sceneNamePendingToLoad},t.prototype.loadPendingScene=function(){this.sceneNamePendingToLoad&&(this.scenes.get(this.sceneNamePendingToLoad)(),this.sceneNamePendingToLoad=null)},t.prototype.unloadCurrentScene=function(){this.currentScene&&(this.currentScene.dispatch(l.Destroy),this.currentScene=void 0)},t}(),Jt=[60,120,180,240],Zt=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!Jt.includes(t))throw new Nt("Invalid Physics frame rate. Allowed: [".concat(Jt.join(", "),"]"));this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t.prototype.updateForGame=function(t){this.unscaledDeltaTime=Math.min(Math.max(this.minGameDeltatime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t},t.prototype.updateForBrowser=function(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForBrowser),this.maxDeltaTime),this.thenForBrowser=t},t.prototype.updateForPhysics=function(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t},t}(),te=function(){function t(){this.instances=new Map,this.constructors=new Map,this.constants=new Map}return t.prototype.add=function(t,e){if(this.constructors.has(t))throw new Nt("There is already an object constructor with the name ".concat(t));this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new Nt("Invalid object constructor name: ".concat(t));return!1===this.instances.has(t)&&this.instances.set(t,this.constructors.get(t)()),this.instances.get(t)},t.prototype.getTranscient=function(t){if(!1===this.constructors.has(t))throw new Nt("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Nt("There is already a constant value with the name ".concat(t));this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new Nt("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),ee=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),ie=function(){function t(t,e,i,n){this._position=new ee,this._center=new ee,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ee&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),ne=function(t,e,i){return t>=e&&t<=i},oe=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ee,t?this.radians=t:e&&(this.degrees=e)}return Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},t}(),re={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new ee(1,1),collisions:{collisionMethod:bt.SAT,collisionBroadPhaseMethod:pt.SpartialGrid}},se=function(){function t(t){this._config=p(p({},re),t),this._config.collisions=p(p({},re.collisions),t.collisions),this.container=new te,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){(function(t,e){if(t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new Zt(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new Kt(t)})),t.add("PhysicsManager",(function(){return function(t){var e=void 0===t?{}:t,i=e.collisionArea,n=e.collisionMatrix,o=e.collisionMethod,r=e.collisionBroadPhaseMethod,s=new jt,a=o===bt.AABB?new xt(new Mt,new wt,s):new _t(s,new At),h=new vt(a,r,i,n),c=new dt,u=new Tt(h),l=new St;return new Rt(h,c,u,l)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Qt(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new qt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new B(t),i=e.gl,n=e.contextVersion,o=new L(i,n,new U(i,new k(i))),r=new at(new st(i)),s=new ht(i,o,r,new Map([[y.Sprite,new J(i,o,r)],[y.Text,new nt(i,o,r,new F)],[y.Tilemap,new ot(i,o,r)],[y.Geometric,new K(i,o)],[y.Mask,new $(i,o)],[y.Video,new rt(i,o,r)]]));return new D(s,new O(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Gt(new Wt(t),new Ht(t),new kt,new zt(t))}(i)})),t.add("AssetManager",(function(){return new Yt(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new m(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))}t.add("SceneManager",(function(){return new $t(t,e.headless?void 0:t.getSingleton("RenderManager"))}))})(this.container,this._config),this.sceneManager=this.container.getSingleton("SceneManager"),this.iterationManager=this.container.getSingleton("IterationManager")},Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"running",{get:function(){return this.iterationManager.running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i,n){this.sceneManager.addScene(t,e,"object"==typeof i?i:void 0,"boolean"==typeof i?i:null!=n&&n)},t.prototype.run=function(){this.iterationManager.start()},t.prototype.stop=function(){this.iterationManager.stop()},t.prototype.pause=function(){this.iterationManager.pause()},t.prototype.resume=function(){this.iterationManager.resume()},t}(),ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.parentScale=!0,e.parentRotation=!0,e._position=new ee,e._scale=new ee(1,1),e._rotation=new oe,e._innerPosition=new ee,e._parent=null,e.cache=new ee,e.lastParentRadians=0,e.lastPosition=new ee,e.scaledInnerPosition=new ee,e}return u(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&ee.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),e.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},e.prototype.setPositionFromParent=function(){this._innerPosition.magnitude>0?(0!==this._parent.rotation.radians&&this.lastParentRadians!==this._parent.rotation.radians&&(this.translateInnerPosition(),this.lastParentRadians=this._parent.rotation.radians),this.parentScale?(this.updateScaledInnerPosition(),ee.add(this._position,this._parent.position,this.scaledInnerPosition)):ee.add(this._position,this._parent.position,this._innerPosition)):this._position.copy(this._parent.position),this._rotation.radians=this.parentRotation?this._parent.rotation.radians+this._rotation.radians:this._rotation.radians,this.parentScale&&this._scale.copy(this.parent._scale)},e.prototype.translateInnerPosition=function(){var t=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(t),Math.sin(t)),ee.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},e.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},e}(w),he=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return u(e,t),e.prototype.update=function(){this.activateColliders&&(this.colliders.forEach((function(t){return t.active=!0})),this.activateColliders=!1),this.updateRealSize(),this.updatePosition(),this.updateColliders()},e.prototype.collidesWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],o=0,r=this.physicsManager.getCollisionsForCollider(n);o<r.length;o++)if(r[o].remoteCollider.layer===t)return!0},e.prototype.collidesWithLayers=function(t,e){void 0===e&&(e="or");for(var i=0,n=0,o=this.colliders;n<o.length;n++)for(var r=o[n],s=0,a=this.physicsManager.getCollisionsForCollider(r);s<a.length;s++){var h=a[s];if(t.includes(h.remoteCollider.layer)){if("or"===e)return!0;i++}}return"and"===e&&i===t.length},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],o=0,r=this.physicsManager.getCollisionsForCollider(n);o<r.length;o++){var s=r[o];if(s.remoteCollider.layer===t)return this.createCollisionData(s)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var o=n[i],r=0,s=this.physicsManager.getCollisionsForCollider(o);r<s.length;r++){var a=s[r];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.getCollisionsWithLayers=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var o=n[i],r=0,s=this.physicsManager.getCollisionsForCollider(o);r<s.length;r++){var a=s[r];t.includes(a.remoteCollider.layer)&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(Number(t.remoteCollider.group)),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject},localCollider:t.localCollider}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(_),ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e}return u(e,t),Object.defineProperty(e.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBodyType",{get:function(){return this.rigidBody.type},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e,i=t.rigidBodyType,n=t.gravity;if(0===this.getColliderIds().length)throw new Nt("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:i,colliderIds:this.getColliderIds(),gravity:null!==(e=Math.abs(n))&&void 0!==e?e:0,velocity:new ee,position:new ee})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new Nt("RigidBody needs at least one Collider with physics");this.rigidBody.colliderIds=this.getColliderIds(),this.rigidBody.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position},e.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof he&&t.physics})).reduce((function(t,e){return d(d([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},e.prototype.onActiveChange=function(){this.rigidBody.active=this.active},e.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},e}(x),ue="Default",le=function(t){function e(e,i,n,o){void 0===n&&(n=""),void 0===o&&(o=null);var r=t.call(this,e)||this;return r.layer="Default",r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.id=i,r.name=n,r.addComponent(ae),o&&(r.transform.position=o.transform.position,r.parent=o),r}return u(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus(),this.onActiveChange())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(ae)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(ce)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getLoadedScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,o="string"==typeof e?e:i,r=new t(this.container,this,o);return this.checkMultipleComponent(r,t),this.components.push(r),r.dispatch(l.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new Nt("GameObject only allows one component of type ".concat(e.name))},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(l.Destroy)},e.prototype.addChild=function(t,e,i){var n=this.gameObjectManager.addGameObject(t,e,this,i);return n.transform.innerPosition.set(0,0),n.transform.position.copy(this.transform.position),n},e.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},e.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParent(this,t)},e.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},e.prototype._destroy=function(){var t=this;this.destroyComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype.destroyComponents=function(){for(var t=0;t<this.components.length;t++)this.components[t].dispatch(l.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(v),pe=["Default"],de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new ie(0,0,0,0),e.worldSpaceRect=new ie(0,0,0,0),e.depth=0,e.layers=pe,e._zoom=1,e}return u(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new Nt("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.layers.push(t)},e.prototype.init=function(){this.canvas=this.domManager.canvas,this.cameraData={position:new ee,layers:[],depth:1}},e.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},e.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},e.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},e.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},e}(P),fe=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(de)},Object.defineProperty(e.prototype,"layers",{get:function(){return this.camera.layers},set:function(t){this.camera.layers=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this.camera.depth},set:function(t){this.camera.depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this.camera.zoom},set:function(t){this.camera.zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this.camera.worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this.camera.viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.camera.layers.push(t)},e}(le),ge=function(t){function e(e,i,n){var o=t.call(this,e)||this;return o.name=i,o.game=n,o.game.config.headless||o.addGameObject(fe),o}return u(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(fe)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!1),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!0),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(v),ye=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.scaledVertexModel=[],e.scaledOffset=new ee,e.scaledPosition=new ee,e.finalRotation=0,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==bt.SAT)throw new Nt("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new Nt("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new ee);this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Ft(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},e.prototype.updatePosition=function(){ee.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.scaledPosition),this.colliders[0].rotation=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel},e}(he),me=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:y.Geometric,location:g.WorldSpace,layer:this.gameObject.layer,position:new ee,shape:f.Polygon,color:"#00FF00"},this.collider=e},e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.rotation=this.collider.shape.rotation,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},e}(C),ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.realWidth=0,e.realHeight=0,e.realOffset=new ee,e.realPosition=new ee,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===bt.SAT,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(o=t.debug)&&void 0!==o?o:this.debug)&&this.gameConfig.debugEnabled,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new It(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){this.realWidth=this.width*Math.abs(this.gameObject.transform.scale.x),this.realHeight=this.height*Math.abs(this.gameObject.transform.scale.y),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.realRotation=this.applyRotation?this.gameObject.transform.rotation.radians+this.rotation.radians:0},e.prototype.updatePosition=function(){ee.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].rotation=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight)},e}(he),be=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.realRadius=0,e.realOffset=new ee,e.realPosition=new ee,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r;this.radius=t.radius,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(o=t.debug)&&void 0!==o?o:this.debug)&&this.gameConfig.debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new Dt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(xe,{collider:this.colliders[0]}))},e.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},e.prototype.updatePosition=function(){ee.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].shape.radius=this.realRadius},e}(he),xe=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:y.Geometric,location:g.WorldSpace,layer:this.gameObject.layer,position:new ee,shape:f.Circumference,color:"#00FF00"},this.collider=e},e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},e}(C),_e=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i;this.tilemapRenderer=t.tilemapRenderer,this.layer=t.layer,this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.physics=!0,this.composite=null!==(i=t.composite)&&void 0!==i&&i,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===S.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([S.Center,S.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==S.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(Me,{colliders:this.colliders}))},e.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(e,i){var n;t.needsCollider(e,i)&&t.colliders.push(t.physicsManager.addCollider({layer:null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,position:new ee(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new It(t.scaledTileWidth,t.scaledTileHeight),updateCollisions:!1,physics:t.physics,group:t.gameObject.id.toString()}))}))},e.prototype.needsCollider=function(t,e){var i=this;return 0!==t&&this.getNeighbors(e).some((function(t){return!t||!i.tilemapRenderer.tiles[t]||0===i.tilemapRenderer.tiles[t]}))},e.prototype.useLineColliders=function(){var t,e,i=this,n=[],o=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var r=e%i.tilemapRenderer.width,s=Math.floor(e/i.tilemapRenderer.width);n[s]||(n[s]=[]),n[s+1]||(n[s+1]=[]),o[s]||(o[s]=[]),o[s+1]||(o[s+1]=[]);var a=i.getNeighbors(e);i.hasTile(a[0])||(n[s][r]=!0),i.hasTile(a[2])||(n[s+1][r]=!0),i.hasTile(a[1])||(o[s][r]=!0),i.hasTile(a[3])||(o[s][r+1]=!0)}}));for(var r=0;r<n.length;r++)if(n[r])for(var s=0;s<n[r].length;s++)!t||!e||r===e.y&&n[r][s]||(this.addLineCollider(t,e),t=void 0,e=void 0),n[r][s]&&(t||(t=new ee(s,r)),e=new ee(s+1,r));for(t&&e&&this.addLineCollider(t,e),t=void 0,e=void 0,s=0;s<=this.tilemapRenderer.width;s++)for(r=0;r<o.length;r++)o[r]&&(!t||!e||s===e.x&&o[r][s]||(this.addLineCollider(t,e),t=void 0,e=void 0),o[r][s]&&(t||(t=new ee(s,r)),e=new ee(s,r+1)));t&&e&&this.addLineCollider(t,e)},e.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},e.prototype.addLineCollider=function(t,e){var i,n=this.physicsManager.addCollider({layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,position:this.position.clone(),shape:new Bt([new ee(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new ee(e.x*this.scaledTileWidth,e.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id.toString()});this.colliders.push(n)},e.prototype.getNeighbors=function(t){return[t-this.tilemapRenderer.width>=0?t-this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width>0?t-1:void 0,t+this.tilemapRenderer.width<=this.tilemapRenderer.width*this.tilemapRenderer.height?t+this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width<this.tilemapRenderer.width-1?t+1:void 0]},e.prototype.updateRealSize=function(){},e.prototype.updatePosition=function(){},e.prototype.updateColliders=function(){var t=this;this.colliders.forEach((function(e){var i;return e.layer=null!==(i=t.layer)&&void 0!==i?i:t.gameObject.layer}))},e}(he),Me=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return u(e,t),e.prototype.init=function(t){var e=this,i=t.colliders;this.colliders=i,this.colliders.forEach((function(t,i){e.renderData[i]={type:y.Geometric,layer:e.gameObject.layer,location:g.WorldSpace,position:new ee,shape:f.Polygon,color:"#00FF00"}}))},e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},e}(C),we=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.scaledVertexModel=[],e.scaledOffset=new ee,e.scaledPosition=new ee,e.finalRotation=0,e.innerPosition=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==bt.SAT)throw new Nt("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new Nt("Edge Collider needs at least 2 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new oe,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new ee);for(a=0;a<this.scaledVertexModel.length-1;a++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Bt([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(je,{colliders:this.colliders}))},e.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},e.prototype.updatePosition=function(){ee.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){ee.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].position.copy(this.scaledPosition),this.colliders[e].rotation=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]]},e}(he),je=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return u(e,t),e.prototype.init=function(t){var e=this,i=t.colliders;this.colliders=i,this.colliders.forEach((function(t,i){e.renderData[i]={type:y.Geometric,layer:e.gameObject.layer,location:g.WorldSpace,position:new ee,shape:f.Line,color:"#00FF00"}}))},e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},e}(C),Pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.innerPosition=new ee,e.cachePosition=new ee,e.cacheRenderPosition=new ee,e.scaledOffset=new ee,e.cacheScale=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(e=t.offset)&&void 0!==e?e:new ee,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new oe,this.flipHorizontal=null!==(n=t.flipHorizontal)&&void 0!==n&&n,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:1,this._tiled=null!==(s=t.tiled)&&void 0!==s?s:new ee(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(a=t.maskColorMix)&&void 0!==a?a:0,this.tintColor=t.tintColor,this.layer=t.layer,this.scale=null!==(c=null!==(h=t.scale)&&void 0!==h?h:this.gameConfig.spriteDefaultScale.clone())&&void 0!==c?c:new ee(1,1),this.width=t.width,this.height=t.height},Object.defineProperty(e.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new Nt("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),e.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},e.prototype.updateRenderDataArray=function(){if(this.renderData.length!==this._tiled.x*this._tiled.y){this.renderData=[];for(var t=0;t<this._tiled.x*this._tiled.y;t++)this.renderData[t]={type:y.Sprite,location:g.WorldSpace,layer:"",position:new ee,image:this.sprite.image,width:0,height:0}}},e.prototype.updateRenderData=function(t,e,i){var n,o,r;this.renderData[t].location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData[t].layer=null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,this.renderData[t].image=this.sprite.image,this.renderData[t].width=(null!==(o=this.width)&&void 0!==o?o:this.sprite.width)*Math.abs(this.cacheScale.x),this.renderData[t].height=(null!==(r=this.height)&&void 0!==r?r:this.sprite.height)*Math.abs(this.cacheScale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.cacheScale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.cacheScale.y<0,this.renderData[t].rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData[t].smooth=this.sprite.smooth,this.renderData[t].alpha=this.opacity,this.renderData[t].maskColor=this.maskColor,this.renderData[t].maskColorMix=this.maskColorMix,this.renderData[t].tintColor=this.tintColor,this.calculateRenderPosition(t,e,i),this.renderManager.addRenderData(this.renderData[t])},e.prototype.calculateRenderPosition=function(t,e,i){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[t].width/2*(this._tiled.x-1),this.renderData[t].height/2*(this._tiled.y-1)),ee.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),ee.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){ee.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var e=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[t].position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},e}(C),Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.lastFrameText="",e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c,u,l,p,d;if(this.text=null!==(e=t.text)&&void 0!==e?e:"",this.font=null!==(i=t.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=t.fontSize)&&void 0!==n?n:12,this.width=null!==(o=t.width)&&void 0!==o?o:100,this.height=null!==(r=t.height)&&void 0!==r?r:100,this.offset=null!==(s=t.offset)&&void 0!==s?s:new ee,this.color=null!==(a=t.color)&&void 0!==a?a:"#000000",this.charRanges=null!==(h=t.charRanges)&&void 0!==h?h:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=t.letterSpacing)&&void 0!==u?u:0,this.smooth=null!==(l=t.smooth)&&void 0!==l&&l,this.rotation=null!==(p=t.rotation)&&void 0!==p?p:new oe,this.opacity=null!==(d=t.opacity)&&void 0!==d?d:1,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new Nt("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Nt("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:y.Text,location:g.WorldSpace,position:new ee,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},e.prototype.update=function(){var t,e;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.fontSize=this.fontSize,this.renderData.color=this.color,this.renderData.orientation=this.orientation,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.rotation=null!==(e=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==e?e:0,this.renderData.alpha=this.opacity,ee.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text)},e.prototype.crop=function(){var t=this;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,o=this.text.split("\n");n<o.length;n++)for(var r=o[n].split(" ").reduce((function(e,i){var n=e[e.length-1]+(e[e.length-1].length>0?" ":"")+i;return n.length*(t.fontSize+t.letterSpacing)>t.width?e.push(i):e[e.length-1]=n,e}),[""]),s=0,a=r;s<a.length;s++){var h=a[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(h)}return e.join("\n")},e}(C),Oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new ee,e.rotation=new oe,e.opacity=1,e.innerPosition=new ee,e.scaledOffset=new ee,e}return u(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a;this.shape=t.shape,this.color=t.color,this.width=null!==(e=t.width)&&void 0!==e?e:0,this.height=null!==(i=t.height)&&void 0!==i?i:0,this.radius=null!==(n=t.radius)&&void 0!==n?n:0,this.offset=null!==(o=t.offset)&&void 0!==o?o:this.offset,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:this.rotation,this.opacity=null!==(s=t.opacity)&&void 0!==s?s:this.opacity,this.layer=t.layer,this.renderData={type:y.Mask,layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,width:0,height:0,radius:0,color:"",shape:this.shape}},e.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.shape=this.shape,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.radius=this.radius*Math.abs(Math.max(this.gameObject.transform.scale.x,this.gameObject.transform.scale.y)),this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},e.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){ee.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e}(C),Ae=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Re=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.innerPosition=new ee,e.scaledOffset=new ee,e._playing=!1,e._paused=!1,e.videoEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e.video.removeEventListener("ended",e.videoEventHandler))},e.userInputEventHandler=function(){Ae.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.video&&e._playing&&e.video.play()},e}return u(e,t),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.video&&(this.video.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.video&&(this.video.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c,u;this.video=t.video,this.width=null!==(e=t.width)&&void 0!==e?e:this.video.videoWidth,this.height=null!==(i=t.height)&&void 0!==i?i:this.video.videoHeight,this.offset=null!==(n=t.offset)&&void 0!==n?n:new ee,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new oe,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(s=t.flipVertical)&&void 0!==s&&s,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this.maskColor=t.maskColor,this.maskColorMix=null!==(h=t.maskColorMix)&&void 0!==h?h:0,this.tintColor=t.tintColor,this.layer=t.layer,this.slice=t.slice,this._volume=null!==(c=t.volume)&&void 0!==c?c:1,this._loop=null!==(u=t.loop)&&void 0!==u&&u,this.renderData={type:y.Video,location:g.WorldSpace,layer:"",position:new ee,video:this.video,width:this.width,height:this.height}},e.prototype.play=function(){var t=this;if((this.video||!this.video.duration)&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.video.play();this.video.loop=this._loop,this.video.volume=this._volume,this.video.addEventListener("ended",this.videoEventHandler),this._playing=!0;var e=this.video.play();void 0!==e&&e.catch((function(){Ae.forEach((function(e){return window.addEventListener(e,t.userInputEventHandler)}))}))}},e.prototype.stop=function(){this._playing&&(this.video.pause(),this.video.currentTime=0,this.video.removeEventListener("ended",this.videoEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this.video.pause(),this._paused=!0)},e.prototype.update=function(){var t;this.video&&this.video.duration&&(this.renderData.location=this.gameObject.ui?g.ViewPort:g.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.video=this.video,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.slice=this.slice,this.renderData.flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData.flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.maskColor=this.maskColor,this.renderData.maskColorMix=this.maskColorMix,this.renderData.tintColor=this.tintColor,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData))},e.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),ee.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){ee.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop()},e}(C),Se=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return u(e,t),e.prototype.init=function(t){var e,i=this,n=t.tiles,o=t.tileset,r=t.tileWidth,s=t.tileHeight,a=t.width,h=t.layer,c=t.orientation,u=t.opacity,l=t.tintColor,p=t.smooth;n.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?i.tiles.push(Number(t)):null}))})),this.tileset=o,this.width=a,this.tileWidth=null!=r?r:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=h,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=null!=c?c:S.Center,this.opacity=u,this.tintColor=l,this.renderData={type:y.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},e.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},e.prototype.updateRenderData=function(){var t;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.position.copy(this.gameObject.transform.position),this.renderData.tintColor=this.tintColor,this.renderData.alpha=this.opacity,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},e}(C),Ee=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return u(e,t),e.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,o=t.tileWidth,r=t.tileHeight,s=t.layer,a=t.orientation,h=t.smooth;if(this.tiledData=e,this.tileset=n,this.tileWidth=null!=o?o:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=r?r:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=s,this.smooth=null!=h&&h,this.orientation=null!=a?a:S.Center,this.tiledLayer=this.tiledData.layers.find((function(t){return t.name===i})),!this.tiledLayer)throw new Nt("Invalid tilemap layer");this.width=this.tiledLayer.width,this.height=this.tiledLayer.height,this.processTilemap()},e.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},e.prototype.processTilemap=function(){var t=this;!0===this.tiledLayer.visible&&(this.opacity=this.tiledLayer.opacity,this.tintColor=this.tiledLayer.tintcolor,this.tiledData.infinite?this.tiledLayer.chunks.sort((function(t,e){return t.x-e.x})).sort((function(t,e){return t.y-e.y})).forEach((function(e){return t.processChunk(e)})):this.processChunk(this.tiledLayer)),this.updateRenderData(),this.tilesetTileIds=[]},e.prototype.processChunk=function(t){var e,i=this,n={type:y.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?g.ViewPort:g.WorldSpace,position:new ee,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:S.RightDown,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=n.tiles:n.tiles.forEach((function(e,n){i.tiles[i.tiledLayer.width*(t.y+Math.floor(n/t.width))+t.x+n%t.width]=e})),this.renderData.push(n),this.chunks.push(t)},e.prototype.getTilesetTileId=function(t){return this.tilesetTileIds[t]||(this.tilesetTileIds[t]=this.tiledData.tilesets.reduce((function(e,i){return t>=i.firstgid?t-i.firstgid+1:e}),0)),this.tilesetTileIds[t]},e.prototype.updateRenderData=function(){var t=this;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.tiledLayer.width*this.scaledTileWidth,this.realHeight=this.tiledLayer.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+(t.orientation===S.Center?-t.realWidth/2:0)+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+([S.Center,S.RightCenter].includes(t.orientation)?t.realHeight/2:t.orientation==S.RightUp?t.realHeight:0)-t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.opacity}))},e}(C),Te=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return u(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e="default"),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new De(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Nt("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null,this.paused=!1)},e.prototype.isPlayingAnimation=function(t){return void 0===t&&(t="default"),null!==this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e.prototype.isPaused=function(){return this.paused},e}(x),De=function(){function t(t){this._sprite=null,this._restarted=!1,this.currentFrame=0,this.frameTime=0,this._animation=t}return Object.defineProperty(t.prototype,"sprite",{get:function(){return this._sprite},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"restarted",{get:function(){return this._restarted},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){return this._animation.loop},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this.currentFrame=0,this.frameTime=0,this._restarted=!0},t.prototype.playFrame=function(t){this._restarted=!1,this.frameTime>=1/this._animation.framerate&&(this.frameTime=0,this.currentFrame=this.currentFrame+1===this._animation.sprites.length?0:this.currentFrame+1,this._restarted=0===this.currentFrame),this._sprite=this._animation.sprites[this.currentFrame],this.frameTime+=t},t}(),Be=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Fe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.tracks=[],e.audioSourceCache=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e._audioSource.removeEventListener("ended",e.audioEventHandler))},e.userInputEventHandler=function(){Be.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return u(e,t),Object.defineProperty(e.prototype,"audioSource",{get:function(){return this._audioSource},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this._audioSource&&(this._audioSource.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this._audioSource&&(this._audioSource.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e=this,i=void 0===t?{}:t,n=i.loop,o=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&Be.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=o?o:1,this._loop=null!=n&&n},e.prototype.playClip=function(t,e){t.currentTime>0&&(t.currentTime=0),t.volume=null!=e?e:this._volume,t.play()},e.prototype.addAudioSource=function(t,e){void 0===e&&(e="default");var i=t.cloneNode();this.audioSourceCache.set(e,i);var n=this.audioContext.createMediaElementSource(i);n.connect(this.audioContext.destination),this.tracks.push(n)},e.prototype.loadAudioSource=function(t,e,i){this.stop(),this._audioSource=this.audioSourceCache.get(t),this._loop=null!=e?e:this._loop,this._volume=null!=i?i:this._volume},e.prototype.play=function(){if(this._audioSource&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this._audioSource.play();this._audioSource.volume=this._volume,this._audioSource.loop=this._loop,this._audioSource.addEventListener("ended",this.audioEventHandler),this._playing=!0,"running"===this.audioContext.state&&this._audioSource.play()}},e.prototype.stop=function(){this._playing&&(this._audioSource.pause(),this._audioSource.currentTime=0,this._audioSource.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this._audioSource.pause(),this._paused=!0)},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop(),this.audioContext.close()},e}(x),Ie=function(){function t(t){var e,i=this;this._width=null,this._height=null,this._loaded=!1,this.image=t.image,this.smooth=null!==(e=t.smooth)&&void 0!==e&&e,this.slice=t.slice,this.slice&&(this._width=this.slice.width,this._height=this.slice.height);var n=function(){var t,e;i._width=null!==(t=i._width)&&void 0!==t?t:i.image.naturalWidth,i._height=null!==(e=i._height)&&void 0!==e?e:i.image.naturalHeight,i._loaded=!0};this.image.naturalWidth?n():this.image.addEventListener("load",(function(){return n()}))}return Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Xt||(Xt={}));var Ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.width=100,e.height=100,e.radius=50,e.touchEnabled=!0,e.offset=new ee,e.pressed=!1,e.mouse=e.inputManager.mouse,e.touch=e.inputManager.touch,e.position=new ee,e.distance=new ee,e.pressedLastFrame=!1,e.scaled={width:0,height:0,radius:0,offset:new ee},e}return u(e,t),e.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,o=t.touchEnabled,r=t.width,s=t.offset;this.type=e,this.width=null!=r?r:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=o?o:this.touchEnabled,this.offset=null!=s?s:this.offset},e.prototype.update=function(){this.scale(),ee.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},e.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this.offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this.offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y))},e.prototype.resolveMouseAndRectangle=function(){this.type===Xt.Rectangle&&(this.pressed=ne(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&ne(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2))},e.prototype.resolveMouseAndCircumference=function(){this.type===Xt.Circumference&&(ee.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},e.prototype.resolveTouchAndRectangle=function(){if(this.type===Xt.Rectangle)for(var t=0,e=this.touch.interactions;t<e.length;t++){var i=e[t],n=i.positionInViewport,o=i.radius;if(this.pressed)return;this.pressed=this.position.x+this.scaled.width/2>=n.x-o.x&&this.position.x-this.scaled.width/2<=n.x+o.x&&this.position.y+this.scaled.height/2>=n.y-o.y&&this.position.y-this.scaled.height/2<=n.y+o.y}},e.prototype.resolveTouchAndCircumference=function(){if(this.type===Xt.Circumference)for(var t=0,e=this.touch.interactions;t<e.length;t++){var i=e[t],n=i.positionInViewport,o=i.radius;if(this.pressed)return;ee.subtract(this.distance,this.position,n),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},e}(x),Le=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new ee,e}return u(e,t),e.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},e.prototype.update=function(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(ee.round(this.position,ee.add(this.position,this.camera.transform.position,ee.scale(this.position,this.inputManager.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=this.inputManager.mouse.leftButtonPressed},e}(le),ke=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new ke,this._center=new ke,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof ke&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new ke,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Ve=function(){function t(){var t=this;this.gamepads=new Map,this.eventHandler=function(e){"gamepadconnected"===e.type?t.gamepadConnected(e.gamepad):"gamepaddisconnected"===e.type&&t.gamepadDisconected(e.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}return t.prototype.getGamepad=function(t){var e;return null!==(e=this.gamepads.get(t))&&void 0!==e?e:null},t.prototype.getGamepads=function(){return Array.from(this.gamepads.values())},t.prototype.gamepadConnected=function(t){this.gamepads.set(t.index,new Ge),this.gamepads.get(t.index).updateFromGamepad(t)},t.prototype.gamepadDisconected=function(t){this.gamepads.delete(t.index)},t.prototype.update=function(){for(var t=0,e=this.getGamepadsFromBrowser();t<e.length;t++){var i=e[t];null!==i&&(!1===this.gamepads.has(i.index)?this.gamepadConnected(i):this.gamepads.get(i.index).updateFromGamepad(i))}},t.prototype.getGamepadsFromBrowser=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),Ge=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new ke,this._leftStickAxes=new ke,this._rightStickAxes=new ke,this._vibrating=!1}return t.prototype.updateFromGamepad=function(t){var e=this;this._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){var o=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return o._vibrating=!1})).finally((function(){return o._vibrating=!1})))},t}(),He=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),We=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new ke,this._hasMoved=!1,this._wheelScroll=new ke,this.lastPositionInViewport=new ke,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),ze=function(){function t(t){var e=this;this._touching=!1,this._interactions=[],this.eventHandler=function(t){"touchstart"===t.type&&(e._touching=!0,e.updatePosition(t)),"touchmove"===t.type&&e.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(e._touching=!1)},this.canvas=t,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"interactions",{get:function(){return this._interactions},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){if(t.preventDefault(),t.stopPropagation(),this._interactions=[],0!==t.targetTouches.length)for(var e=0;e<t.targetTouches.length;e++)this._interactions[e]={positionInViewport:new ke((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new ke(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Xe=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),Ye=function(){function t(t,e,i,n){this._position=new Xe,this._center=new Xe,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof Xe&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}();!function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Xe,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var Ne,qe,Ke,Qe=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)};!function(){function t(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}Object.defineProperty(t.prototype,"subdivisions",{get:function(){return this._subdivisions},set:function(t){this._subdivisions=function(t,e,i){return Math.min(i,Math.max(e,t))}(t,1,20)},enumerable:!1,configurable:!0}),t.prototype.resize=function(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(var e=0;e<this._subdivisions;e++){this.itemsInCells[e]=[];for(var i=0;i<this._subdivisions;i++)this.itemsInCells[e][i]=[]}},t.prototype.clear=function(){for(var t=0;t<this._subdivisions;t++)for(var e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]},t.prototype.insert=function(t,e){this.updateCoordinates(e);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].push(t)},t.prototype.retrieve=function(t){var e=[];this.updateCoordinates(t);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].forEach((function(t){return e.includes(t)?null:e.push(t)}));return e},t.prototype.updateCoordinates=function(t){this.coordinates.x0=Qe(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Qe(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Qe(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Qe(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}(),function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Ne||(Ne={})),function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(qe||(qe={})),function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(Ke||(Ke={}));var $e,Je=function(t,e){return Je=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},Je(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}($e||($e={})),function(){function t(t){this.radius=t,this.type=qe.Circumference,this.boundingBox=new Ye(0,0,0,0),this.vertices=[new Xe,new Xe],this.projectionAxes=[new Xe],this._position=new Xe}Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}(),function(){function t(t){this.vertexModel=t,this.type=qe.Polygon,this.vertices=[new Xe,new Xe],this.projectionAxes=[new Xe],this.boundingBox=new Ye(0,0,0,0),this.rotation=0,this._position=new Xe}t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){Xe.normal(this.projectionAxes[0],Xe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var Ze=function(){function t(t){this.vertexModel=t,this.type=qe.Polygon,this.vertices=[],this.boundingBox=new Ye(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Xe,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(var e=0;e<this.vertexModel.length;e++)this.vertices.push(new Xe),this._projectionAxes.push(new Xe)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,e=0;e<this.vertices.length;e++)Xe.normal(this._projectionAxes[e],Xe.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}();!function(t){function e(e,i){var n=t.call(this,[new Xe(-e/2,-i/2),new Xe(-e/2,i/2),new Xe(e/2,i/2),new Xe(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Xe,new Xe],n}(function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}Je(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)})(e,t),e.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},e.prototype.updateProjectionAxes=function(){Xe.unit(this.projectionAxes[0],Xe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Xe.normal(this.projectionAxes[1],this.projectionAxes[0])}}(Ze);export{Te as Animator,Fe as AudioPlayer,be as BallCollider,ve as BoxCollider,Ne as BroadPhaseMethods,Ue as Button,Xt as ButtonType,de as Camera,Ke as CollisionMethods,b as Component,we as EdgeCollider,se as Game,fe as GameCamera,le as GameObject,Ve as GamepadController,Ge as GamepadData,He as KeyboardController,ue as LAYER_DEFAULT,Oe as MaskRenderer,Y as MaskShape,We as MouseController,M as PhysicsComponent,ye as PolygonCollider,me as PolygonColliderRenderer,j as PreRenderComponent,e as Rectangle,ce as RigidBody,Ot as RigidBodyType,h as Rotation,ge as Scene,Le as SpacePointer,Ie as Sprite,Pe as SpriteRenderer,Q as TextOrientation,Ce as TextRenderer,Ee as TiledTilemapRenderer,_e as TilemapCollider,S as TilemapOrientation,Se as TilemapRenderer,ze as TouchController,ae as Transform,t as Vector2,Re as VideoRenderer,a as between,i as clamp,r as fixedRound,o as randomFloat,n as randomInt,s as range};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|