angry-pixel 1.2.7 → 1.2.9

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});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){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},n=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}(),o=function(t,e){return o=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])},o(t,e)};function r(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}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s,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 h(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"}(s||(s={}));var c,u,l,p=function(){function t(t,e,i,n,o,r,a){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=o,this.sceneManager=r,this.canvasColor=a,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[s.Start,s.Update,s.StopGame],this.gameObjectEvents=[s.Start,s.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(s.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(s.Start),this.inputManager.update(),this.dispatchFrameEvent(s.Update),this.dispatchFrameEvent(s.UpdateEngine),this.dispatchFrameEvent(s.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(s.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(s.UpdatePreRender),this.dispatchFrameEvent(s.UpdateCamera),this.dispatchFrameEvent(s.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(s.UpdatePhysics),this.dispatchFrameEvent(s.UpdateCollider),this.dispatchFrameEvent(s.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(){this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return h(h([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)})),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),d=function(){function t(t){this.updateEvent=s.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===s.Init&&this.init?this.init(e):t!==s.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===s.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===s.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}(),f=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 r(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}(d),g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateEngine,e}return r(e,t),e}(f),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateCollider,e}return r(e,t),e}(f),m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdatePhysics,e}return r(e,t),e}(f),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateTransform,e}return r(e,t),e}(f),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdatePreRender,e}return r(e,t),e}(f),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateCamera,e}return r(e,t),e}(f),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateRender,e}return r(e,t),e}(f);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(c||(c={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(u||(u={})),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"}(l||(l={}));var M=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===u.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===c.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 l.Video:case l.Mask:case l.Sprite:this.setObjectForResizeable(t);break;case l.Geometric:this.setObjectForGeometric(t);break;case l.Text:this.setObjectForText(t);break;case l.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===l.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),w=function(){return w=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},w.apply(this,arguments)};function P(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,exports.TilemapOrientation=void 0;var j=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 j,this._center=new j,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 j&&!(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 j,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"}(exports.TilemapOrientation||(exports.TilemapOrientation={}));var O,C=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===l.Tilemap?function(t){var e=w(w({},t),{culledTiles:[],tilemap:w(w({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new j});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==exports.TilemapOrientation.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===exports.TilemapOrientation.RightDown?-t.tilemap.realHeight/2:t.orientation===exports.TilemapOrientation.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"}(O||(O={}));var A=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(O.WebGL2)?O.WebGL2:null!==this.canvas.getContext(O.LegacyWebGL)?O.LegacyWebGL:void 0},t}(),R=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 S(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}(),S=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},T=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}(),E=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===O.WebGL2?this.programFactory.create("#version 300 es\nprecision mediump float;\n\nin vec2 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 * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision mediump 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}(),D=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}(),B="undefined"!=typeof Float32Array?Float32Array:Array;function F(){var t=new B(16);return B!=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 I(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 U(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 L(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 k(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)}),exports.TextOrientation=void 0;var G=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},V=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=I(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),U(t,t,[0,0,0]),n===u.WorldSpace&&L(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1])},H=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F();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 P(P([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case c.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case c.Line:this.renderLines(t,e,this.gl.LINES,i);break;case c.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===l.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=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.position,e.position):t.position),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),V(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=G(t.color),h=a.r,c=a.g,p=a.b,d=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,c,p,d),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=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.position,e.position):t.position),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),L(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),V(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=G(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}(),W=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=l.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}return t.prototype.render=function(t,e,i){var n,o;i!==l.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.position,e.position):t.position),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),V(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=G(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),this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),z=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F(),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=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.position,e.position):t.position),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),t.slice&&(U(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),L(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),V(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=G(t.tintColor),c=h.r,l=h.g,p=h.b,d=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,l,p,d)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var f=G(t.maskColor);c=f.r,l=f.g,p=f.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,l,p,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"}(exports.TextOrientation||(exports.TextOrientation={}));var X=new j,Y=new j,N=[32,126,161,255],q=exports.TextOrientation.Center,K=function(){function t(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=l.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new j,this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}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=I(this.modelMatrix),this.setPositionFromOrientation(t),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=I(this.textureMatrix),V(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===l.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=G(t.color),a=s.r,h=s.g,c=s.b,p=s.a;this.gl.uniform4f(this.programManager.maskColorUniform,a,h,c,p),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:X,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:Y,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:N):t.bitmap={margin:X,spacing:Y,fontSize:64,charRanges:N},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:q,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,x=(g+t.bitmapFontSize+o.spacing.y)/t.canvas.width;this.texVertices.push(y,x,v,x,y,m,y,m,v,x,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===exports.TextOrientation.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===exports.TextOrientation.Center||t.orientation===exports.TextOrientation.RightCenter?this.textSize.y/2:t.orientation===exports.TextOrientation.RightUp?this.textSize.y:0))},t}(),Q=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 j,texSpacing:new j,texWidth:0,texHeight:0,texCorrection:new j},this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}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=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),L(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),V(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===l.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=G(t.tintColor),c=h.r,p=h.g,d=h.b,f=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,p,d,f)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var g=G(t.maskColor);c=g.r,p=g.g,d=g.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,p,d,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 j,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new j,h.correction=null!==(n=h.correction)&&void 0!==n?n:new j,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}(),$=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new j,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F(),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=I(this.modelMatrix),j.round(this.modelPosition,t.location===u.WorldSpace?j.subtract(this.modelPosition,t.position,e.position):t.position),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),t.slice&&(U(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),L(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),V(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=G(t.tintColor),c=h.r,l=h.g,p=h.b,d=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,l,p,d)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var f=G(t.maskColor);c=f.r,l=f.g,p=f.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,l,p,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}(),J=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}(),Z=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}(),tt=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=G(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}(),et=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}(),it=function(){function t(t,e,i,n){this._position=new et,this._center=new et,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 et&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),nt=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 et,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 ot,rt=function(){function t(){this.lastId=0}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:++this.lastId,active:!0,layer:i,shape:e,updateCollisions:n,physics:o,position:null!=r?r:new et,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),st=function(){function t(t,e){void 0===e&&(e=0),this.area=new it(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 it(this.area.x,this.area.y,i,n),new it(this.area.x,this.area.y+n,i,n),new it(this.area.x+i,this.area.y+n,i,n),new it(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}(),at=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},ht=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=nt(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=at(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=at(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=at(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=at(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(ot||(ot={}));var ct,ut=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new et,this.maxArea=new et,this.newArea=new it(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:ot.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new it(0,0,0,0),this.fixedCollisionArea=!!e,t===ot.SpartialGrid?this.broadPhaseResolver=new ht(this.collisionArea):this.broadPhaseResolver=new st(this.collisionArea)},t.prototype.addCollider=function(t){this.colliders.push(t)},t.prototype.getCollider=function(t){return this.colliders.find((function(e){return e.id===t}))},t.prototype.removeCollider=function(t){var e=this.colliders.indexOf(t);e>=0&&this.colliders.splice(e,1)},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.getCollider(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 ht&&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.getCollider(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.getCollider(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"}(ct||(ct={}));var lt,pt=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===ct.Polygon&&e.type===ct.Polygon?this.AABBResolver.resolve(t,e):t.type===ct.Circumference&&e.type===ct.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===ct.Polygon&&e.type===ct.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===ct.Circumference&&e.type===ct.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(lt||(lt={}));var dt=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===ct.Circumference&&e.type===ct.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),ft=function(){function t(){this.direction=new et,this.displacementDirection=new et}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)),et.unit(this.displacementDirection,this.displacementDirection),{direction:et.scale(new et,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}(),gt=function(){function t(){this.closestPoint=new et,this.distance=new et,this.direction=new et}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(nt(t.position.x,e.boundingBox.x,e.boundingBox.x1),nt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),et.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(et.unit(this.direction,this.distance),{direction:i?et.scale(new et,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():et.scale(new et,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),yt=function(){function t(){this.distance=new et,this.direction=new et}return t.prototype.resolve=function(t,e){return et.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(et.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:et.scale(new et,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),mt=function(t,e){return mt=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])},mt(t,e)};function vt(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,exports.RigidBodyType=void 0;var xt=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new et,this.distance=new et(1/0,1/0),this.cache=new et}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===ct.Circumference?this.setCircumferenceAxis(t,e):e.type===ct.Circumference&&this.setCircumferenceAxis(e,t),this.axes=vt([],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===ct.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===ct.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,et.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&&et.scale(this.smallestAxis,this.axes[n],-1))}return{direction:et.scale(new et,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(et.dot(i,e),t.min),t.max=Math.max(et.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){et.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),et.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){et.add(t.vertices[0],t.position,et.scale(this.cache,et.unit(this.cache,e),-t.radius)),et.add(t.vertices[1],t.position,et.scale(this.cache,et.unit(this.cache,e),t.radius))},t}(),bt=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}(),_t=function(){function t(){this.lastId=0}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{id:++this.lastId,active:!0,colliderIds:e,type:i,gravity:null!=n?n:0,position:null!=o?o:new et,velocity:null!=r?r:new et,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(exports.RigidBodyType||(exports.RigidBodyType={}));var Mt=["x","y"],wt=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new et,this.displacement=new et,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 vt(vt([],t,!0),e.colliderIds,!0)}),[]),this.activeRigidBodies.forEach((function(i){i.type===exports.RigidBodyType.Dynamic?e.dynamicUpdate(i,t):i.type===exports.RigidBodyType.Kinematic&&e.kinematicUpdate(i,t),i.onResolve&&i.onResolve(i)}))},t.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),Mt.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;et.add(t.position,t.position,et.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){et.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}(),Pt=function(){function t(t){this.radius=t,this.type=ct.Circumference,this.boundingBox=new it(0,0,0,0),this.vertices=[new et,new et],this.projectionAxes=[new et],this._position=new et}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}(),jt=function(){function t(t){this.vertexModel=t,this.type=ct.Polygon,this.vertices=[new et,new et],this.projectionAxes=[new et],this.boundingBox=new it(0,0,0,0),this.rotation=0,this._position=new et}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(){et.normal(this.projectionAxes[0],et.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),Ot=function(){function t(t){this.vertexModel=t,this.type=ct.Polygon,this.vertices=[],this.boundingBox=new it(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new et,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 et),this._projectionAxes.push(new et)}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++)et.normal(this._projectionAxes[e],et.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),Ct=function(t){function e(e,i){var n=t.call(this,[new et(-e/2,-i/2),new et(-e/2,i/2),new et(e/2,i/2),new et(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new et,new et],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}mt(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(){et.unit(this.projectionAxes[0],et.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),et.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(Ot),At=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 At,this._center=new At,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 At&&!(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 At,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 Rt,St=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 Tt),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}(),Tt=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new At,this._leftStickAxes=new At,this._rightStickAxes=new At,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}(),Et=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}(),Dt=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}(),Bt=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new At(0,0),this._hasMoved=!1,this.lastPositionInViewport=new At(0,0),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}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},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)}))},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}(),Ft=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 At((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 At(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Rt||(Rt={})),exports.ButtonType=void 0;var It=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,Rt.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,Rt.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,Rt.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,Rt.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===Rt.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===Rt.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===Rt.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===Rt.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}(),Ut=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return r(e,t),e}(Error),Lt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Ut("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(s.Init,e),o},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):h([],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(s.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Gt=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=[s.Start,s.Update,s.StopGame],this.gameObjectEvents=[s.Start,s.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(s.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(s.Start),this.dispatchFrameEvent(s.Update),this.dispatchFrameEvent(s.UpdateEngine),this.dispatchFrameEvent(s.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(s.UpdatePhysics),this.dispatchFrameEvent(s.UpdateCollider),this.dispatchFrameEvent(s.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(){this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return h(h([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)?this.loadedScene.dispatch(t):this.gameObjectEvents.includes(t)&&this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)})),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),Vt=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 Ut("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(s.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new Ut("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 Ut("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(s.Destroy),this.currentScene=void 0)},t}(),Ht=[60,120,180,240],Wt=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,!Ht.includes(t))throw new Ut("Invalid Physics frame rate. Allowed: [".concat(Ht.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}(),zt=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 Ut("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 Ut("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 Ut("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Ut("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 Ut("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),Xt=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}(),Yt=function(){function t(t,e,i,n){this._position=new Xt,this._center=new Xt,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 Xt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),Nt=function(t,e,i){return t>=e&&t<=i},qt=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Xt,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}(),Kt={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new Xt(1,1),collisions:{collisionMethod:lt.SAT,collisionBroadPhaseMethod:ot.SpartialGrid}},Qt=function(){function t(t){this._config=a(a({},Kt),t),this._config.collisions=a(a({},Kt.collisions),t.collisions),this.container=new zt,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 Wt(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 yt,a=o===lt.AABB?new pt(new ft,new gt,s):new dt(s,new xt),h=new ut(a,r,i,n),c=new rt,u=new wt(h),l=new _t;return new bt(h,c,u,l)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Gt(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new Lt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new A(t),i=e.gl,n=e.contextVersion,o=new E(i,n,new T(i,new D(i))),r=new Z(new J(i)),s=new tt(i,o,r,new Map([[l.Sprite,new z(i,o,r)],[l.Text,new K(i,o,r,new R)],[l.Tilemap,new Q(i,o,r)],[l.Geometric,new H(i,o)],[l.Mask,new W(i,o)],[l.Video,new $(i,o,r)]]));return new C(s,new M(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Et(new Bt(t),new Dt(t),new St,new Ft(t))}(i)})),t.add("AssetManager",(function(){return new It(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new p(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 Vt(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}(),$t=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 Xt,e._scale=new Xt(1,1),e._rotation=new qt,e._innerPosition=new Xt,e._parent=null,e.cache=new Xt,e.lastParentRadians=0,e.lastPosition=new Xt,e.scaledInnerPosition=new Xt,e}return r(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&&Xt.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(),Xt.add(this._position,this._parent.position,this.scaledInnerPosition)):Xt.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)),Xt.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}(v),Jt=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 r(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}(y),Zt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e}return r(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 Ut("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 Xt,position:new Xt})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new Ut("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 Jt&&t.physics})).reduce((function(t,e){return h(h([],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}(g),te=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($t),r.parent=o,r}return r(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($t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(Zt)},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(s.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new Ut("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(s.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(s.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(d),ee=["Default"],ie=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new Yt(0,0,0,0),e.worldSpaceRect=new Yt(0,0,0,0),e.depth=0,e.layers=ee,e._zoom=1,e}return r(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new Ut("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 Xt,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}(b),ne=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(ie)},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}(te),oe=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(ne),o}return r(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ne)},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}(d),re=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 Xt,e.scaledPosition=new Xt,e.finalRotation=0,e.innerPosition=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==lt.SAT)throw new Ut("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new Ut("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 qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Xt);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 Ot(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(se,{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(){Xt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),se=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:l.Geometric,location:u.WorldSpace,layer:this.gameObject.layer,position:new Xt,shape:c.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}(_),ae=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 Xt,e.realPosition=new Xt,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===lt.SAT,e.innerPosition=new Xt,e}return r(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 qt,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 Ct(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(se,{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(){Xt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),he=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 Xt,e.realPosition=new Xt,e.innerPosition=new Xt,e}return r(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 Pt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(ce,{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(){Xt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),ce=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:l.Geometric,location:u.WorldSpace,layer:this.gameObject.layer,position:new Xt,shape:c.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}(_),ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new Xt,e}return r(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===exports.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([exports.TilemapOrientation.Center,exports.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==exports.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(le,{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 Xt(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new Ct(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 Xt(s,r)),e=new Xt(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 Xt(s,r)),e=new Xt(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 jt([new Xt(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new Xt(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}(Jt),le=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return r(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:l.Geometric,layer:e.gameObject.layer,location:u.WorldSpace,position:new Xt,shape:c.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}(_),pe=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 Xt,e.scaledPosition=new Xt,e.finalRotation=0,e.innerPosition=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==lt.SAT)throw new Ut("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new Ut("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 qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Xt);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 jt([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(de,{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(){Xt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return r(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:l.Geometric,layer:e.gameObject.layer,location:u.WorldSpace,position:new Xt,shape:c.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}(_),fe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.renderData=[],e.innerPosition=new Xt,e.cachePosition=new Xt,e.cacheRenderPosition=new Xt,e.scaledOffset=new Xt,e.cacheScale=new Xt,e}return r(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 Xt,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new qt,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 Xt(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.spriteDefaultScale)&&void 0!==c?c:new Xt(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 Ut("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),e.prototype.update=function(){var t;if(this.sprite&&!0===this.sprite.loaded){this.scale=null!==(t=this.scale)&&void 0!==t?t:this.spriteDefaultScale,this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var e=0,i=0;i<this._tiled.x;i++)for(var n=0;n<this._tiled.y;n++)this.updateRenderData(e,i,n),e++}},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:l.Sprite,location:u.WorldSpace,layer:"",position:new Xt,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?u.ViewPort:u.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),Xt.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)),Xt.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),Xt.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){Xt.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}(_),ge=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.lastFrameText="",e}return r(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 Xt,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 qt,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 Ut("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Ut("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:l.Text,location:u.WorldSpace,position:new Xt,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?u.ViewPort:u.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,Xt.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}(_),ye=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new Xt,e.rotation=new qt,e.opacity=1,e.innerPosition=new Xt,e.scaledOffset=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(e=t.offset)&&void 0!==e?e:this.offset,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:this.rotation,this.opacity=null!==(n=t.opacity)&&void 0!==n?n:this.opacity,this.layer=t.layer,this.renderData={type:l.Mask,layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,width:0,height:0,color:""}},e.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?u.ViewPort:u.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,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.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),Xt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Xt.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}(_),me=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.innerPosition=new Xt,e.scaledOffset=new Xt,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(){me.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.video&&e._playing&&e.video.play()},e}return r(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,p;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 Xt,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new qt,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!==(p=t.loop)&&void 0!==p&&p,this.renderData={type:l.Video,location:u.WorldSpace,layer:"",position:new Xt,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(){me.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?u.ViewPort:u.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),Xt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Xt.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}(_),xe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return r(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,p=t.opacity,d=t.tintColor,f=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.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.spriteDefaultScale.y,this.layer=h,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=null!=c?c:exports.TilemapOrientation.Center,this.opacity=p,this.tintColor=d,this.renderData={type:l.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:f},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}(_),be=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return r(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.spriteDefaultScale.x,this.tileHeight=null!=r?r:this.tileset.tileHeight*this.spriteDefaultScale.y,this.layer=s,this.smooth=null!=h&&h,this.orientation=null!=a?a:exports.TilemapOrientation.Center,this.tiledLayer=this.tiledData.layers.find((function(t){return t.name===i})),!this.tiledLayer)throw new Ut("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:l.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:exports.TilemapOrientation.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===exports.TilemapOrientation.Center?-t.realWidth/2:0)+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+([exports.TilemapOrientation.Center,exports.TilemapOrientation.RightCenter].includes(t.orientation)?t.realHeight/2:t.orientation==exports.TilemapOrientation.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}(_),_e=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 r(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 Me(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Ut("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)},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}(g),Me=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}(),we=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Pe=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(){we.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return r(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&&we.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}(g),je=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"}(exports.ButtonType||(exports.ButtonType={}));var Oe=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 Xt,e.pressed=!1,e.mouse=e.inputManager.mouse,e.touch=e.inputManager.touch,e.position=new Xt,e.distance=new Xt,e.pressedLastFrame=!1,e.scaled={width:0,height:0,radius:0,offset:new Xt},e}return r(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(),Xt.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===exports.ButtonType.Rectangle&&(this.pressed=Nt(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&Nt(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2))},e.prototype.resolveMouseAndCircumference=function(){this.type===exports.ButtonType.Circumference&&(Xt.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},e.prototype.resolveTouchAndRectangle=function(){if(this.type===exports.ButtonType.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===exports.ButtonType.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;Xt.subtract(this.distance,this.position,n),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},e}(g),Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new Xt,e}return r(e,t),e.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},e.prototype.update=function(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(Xt.round(this.position,Xt.add(this.position,this.camera.transform.position,Xt.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}(te),Ae=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 Ae,this._center=new Ae,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 Ae&&!(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 Ae,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 Re=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 Se),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}(),Se=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Ae,this._leftStickAxes=new Ae,this._rightStickAxes=new Ae,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}(),Te=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}(),Ee=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Ae(0,0),this._hasMoved=!1,this.lastPositionInViewport=new Ae(0,0),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}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},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)}))},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}(),De=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 Ae((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 Ae(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Be=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}(),Fe=function(){function t(t,e,i,n){this._position=new Be,this._center=new Be,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 Be&&!(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 Be,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))}}(),exports.BroadPhaseMethods=void 0;var Ie,Ue=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=Ue(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Ue(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Ue(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Ue(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}(),function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(exports.BroadPhaseMethods||(exports.BroadPhaseMethods={})),function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Ie||(Ie={})),exports.CollisionMethods=void 0,function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(exports.CollisionMethods||(exports.CollisionMethods={}));var Le,ke=function(t,e){return ke=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])},ke(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Le||(Le={})),function(){function t(t){this.radius=t,this.type=Ie.Circumference,this.boundingBox=new Fe(0,0,0,0),this.vertices=[new Be,new Be],this.projectionAxes=[new Be],this._position=new Be}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=Ie.Polygon,this.vertices=[new Be,new Be],this.projectionAxes=[new Be],this.boundingBox=new Fe(0,0,0,0),this.rotation=0,this._position=new Be}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(){Be.normal(this.projectionAxes[0],Be.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var Ge=function(){function t(t){this.vertexModel=t,this.type=Ie.Polygon,this.vertices=[],this.boundingBox=new Fe(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Be,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 Be),this._projectionAxes.push(new Be)}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++)Be.normal(this._projectionAxes[e],Be.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 Be(-e/2,-i/2),new Be(-e/2,i/2),new Be(e/2,i/2),new Be(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Be,new Be],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}ke(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(){Be.unit(this.projectionAxes[0],Be.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Be.normal(this.projectionAxes[1],this.projectionAxes[0])}}(Ge),exports.Animator=_e,exports.AudioPlayer=Pe,exports.BallCollider=he,exports.BoxCollider=ae,exports.Button=Oe,exports.Camera=ie,exports.Component=f,exports.EdgeCollider=pe,exports.Game=Qt,exports.GameCamera=ne,exports.GameObject=te,exports.GamepadController=Re,exports.GamepadData=Se,exports.KeyboardController=Te,exports.LAYER_DEFAULT="Default",exports.MaskRenderer=ye,exports.MouseController=Ee,exports.PhysicsComponent=m,exports.PolygonCollider=re,exports.PolygonColliderRenderer=se,exports.PreRenderComponent=x,exports.Rectangle=e,exports.RigidBody=Zt,exports.Rotation=n,exports.Scene=oe,exports.SpacePointer=Ce,exports.Sprite=je,exports.SpriteRenderer=fe,exports.TextRenderer=ge,exports.TiledTilemapRenderer=be,exports.TilemapCollider=ue,exports.TilemapRenderer=xe,exports.TouchController=De,exports.Transform=$t,exports.Vector2=t,exports.VideoRenderer=ve,exports.between=function(t,e,i){return t>=e&&t<=i},exports.clamp=function(t,e,i){return Math.min(i,Math.max(e,t))},exports.fixedRound=i,exports.randomFloat=function(t,e,n){return void 0===n&&(n=2),i(Math.random()*(e-t)+t,n)},exports.randomInt=function(t,e){return Math.round(Math.random()*(e-t))+t},exports.range=function(t,e,i){void 0===i&&(i=1);for(var n=[],o=t;o<=e;o+=i)n.push(o);return n};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});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){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},n=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}(),o=function(t,e){return o=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])},o(t,e)};function r(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}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s,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 h(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"}(s||(s={}));var c,u,l,p=function(){function t(t,e,i,n,o,r,a){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=o,this.sceneManager=r,this.canvasColor=a,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[s.Start,s.Update,s.StopGame],this.gameObjectEvents=[s.Start,s.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(s.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(s.Start),this.inputManager.update(),this.dispatchFrameEvent(s.Update),this.dispatchFrameEvent(s.UpdateEngine),this.dispatchFrameEvent(s.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(s.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(s.UpdatePreRender),this.dispatchFrameEvent(s.UpdateCamera),this.dispatchFrameEvent(s.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(s.UpdatePhysics),this.dispatchFrameEvent(s.UpdateCollider),this.dispatchFrameEvent(s.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.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)})),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),d=function(){function t(t){this.updateEvent=s.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===s.Init&&this.init?this.init(e):t!==s.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===s.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===s.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}(),f=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 r(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}(d),g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateEngine,e}return r(e,t),e}(f),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateCollider,e}return r(e,t),e}(f),m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdatePhysics,e}return r(e,t),e}(f),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateTransform,e}return r(e,t),e}(f),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdatePreRender,e}return r(e,t),e}(f),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateCamera,e}return r(e,t),e}(f),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=s.UpdateRender,e}return r(e,t),e}(f);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(c||(c={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(u||(u={})),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"}(l||(l={}));var M=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===u.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===c.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 l.Video:case l.Mask:case l.Sprite:this.setObjectForResizeable(t);break;case l.Geometric:this.setObjectForGeometric(t);break;case l.Text:this.setObjectForText(t);break;case l.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===l.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),w=function(){return w=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},w.apply(this,arguments)};function j(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,exports.TilemapOrientation=void 0;var P=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 P,this._center=new P,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 P&&!(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 P,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"}(exports.TilemapOrientation||(exports.TilemapOrientation={}));var O,C=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===l.Tilemap?function(t){var e=w(w({},t),{culledTiles:[],tilemap:w(w({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new P});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==exports.TilemapOrientation.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===exports.TilemapOrientation.RightDown?-t.tilemap.realHeight/2:t.orientation===exports.TilemapOrientation.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"}(O||(O={}));var A=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(O.WebGL2)?O.WebGL2:null!==this.canvas.getContext(O.LegacyWebGL)?O.LegacyWebGL:void 0},t}(),R=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 S(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}(),S=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},T=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}(),E=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===O.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}(),D=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}(),B="undefined"!=typeof Float32Array?Float32Array:Array;function F(){var t=new B(16);return B!=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 I(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 U(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 L(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 k(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)}),exports.TextOrientation=void 0;var G=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},V=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=I(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===u.WorldSpace&&(L(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1]),U(t,t,[-i.position.x,-i.position.y,0]))},H=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F();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 j(j([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case c.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case c.Line:this.renderLines(t,e,this.gl.LINES,i);break;case c.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===l.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=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),V(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=G(t.color),h=a.r,c=a.g,u=a.b,p=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,c,u,p),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=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),L(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),V(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=G(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}(),W=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=l.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}return t.prototype.render=function(t,e,i){var n,o;i!==l.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),V(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=G(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),this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),z=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F(),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=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),t.slice&&(U(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),L(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),V(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=G(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=G(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"}(exports.TextOrientation||(exports.TextOrientation={}));var X=new P,Y=new P,N=[32,126,161,255],q=exports.TextOrientation.Center,K=function(){function t(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=l.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new P,this.modelPosition=new P,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}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=I(this.modelMatrix),this.setPositionFromOrientation(t),U(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=I(this.textureMatrix),V(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===l.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=G(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:X,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:Y,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:N):t.bitmap={margin:X,spacing:Y,fontSize:64,charRanges:N},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:q,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,x=(g+t.bitmapFontSize+o.spacing.y)/t.canvas.width;this.texVertices.push(y,x,v,x,y,m,y,m,v,x,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===exports.TextOrientation.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===exports.TextOrientation.Center||t.orientation===exports.TextOrientation.RightCenter?this.textSize.y/2:t.orientation===exports.TextOrientation.RightUp?this.textSize.y:0))},t}(),Q=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 P,texSpacing:new P,texWidth:0,texHeight:0,texCorrection:new P},this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F()}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=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),L(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),V(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===l.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=G(t.tintColor),c=h.r,u=h.g,p=h.b,d=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,p,d)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var f=G(t.maskColor);c=f.r,u=f.g,p=f.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,p,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 P,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new P,h.correction=null!==(n=h.correction)&&void 0!==n?n:new P,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}(),$=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=F(),this.modelMatrix=F(),this.textureMatrix=F(),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=I(this.modelMatrix),U(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),k(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),L(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=I(this.textureMatrix),t.slice&&(U(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),L(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),V(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=G(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=G(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}(),J=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}(),Z=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}(),tt=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=G(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}(),et=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}(),it=function(){function t(t,e,i,n){this._position=new et,this._center=new et,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 et&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),nt=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 et,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 ot,rt=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 et,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),st=function(){function t(t,e){void 0===e&&(e=0),this.area=new it(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 it(this.area.x,this.area.y,i,n),new it(this.area.x,this.area.y+n,i,n),new it(this.area.x+i,this.area.y+n,i,n),new it(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}(),at=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},ht=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=nt(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=at(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=at(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=at(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=at(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(ot||(ot={}));var ct,ut=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new et,this.maxArea=new et,this.newArea=new it(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:ot.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new it(0,0,0,0),this.fixedCollisionArea=!!e,t===ot.SpartialGrid?this.broadPhaseResolver=new ht(this.collisionArea):this.broadPhaseResolver=new st(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 ht&&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"}(ct||(ct={}));var lt,pt=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===ct.Polygon&&e.type===ct.Polygon?this.AABBResolver.resolve(t,e):t.type===ct.Circumference&&e.type===ct.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===ct.Polygon&&e.type===ct.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===ct.Circumference&&e.type===ct.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(lt||(lt={}));var dt=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===ct.Circumference&&e.type===ct.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),ft=function(){function t(){this.direction=new et,this.displacementDirection=new et}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)),et.unit(this.displacementDirection,this.displacementDirection),{direction:et.scale(new et,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}(),gt=function(){function t(){this.closestPoint=new et,this.distance=new et,this.direction=new et}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(nt(t.position.x,e.boundingBox.x,e.boundingBox.x1),nt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),et.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(et.unit(this.direction,this.distance),{direction:i?et.scale(new et,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():et.scale(new et,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),yt=function(){function t(){this.distance=new et,this.direction=new et}return t.prototype.resolve=function(t,e){return et.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(et.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:et.scale(new et,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),mt=function(t,e){return mt=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])},mt(t,e)};function vt(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,exports.RigidBodyType=void 0;var xt=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new et,this.distance=new et(1/0,1/0),this.cache=new et}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===ct.Circumference?this.setCircumferenceAxis(t,e):e.type===ct.Circumference&&this.setCircumferenceAxis(e,t),this.axes=vt([],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===ct.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===ct.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,et.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&&et.scale(this.smallestAxis,this.axes[n],-1))}return{direction:et.scale(new et,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(et.dot(i,e),t.min),t.max=Math.max(et.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){et.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),et.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){et.add(t.vertices[0],t.position,et.scale(this.cache,et.unit(this.cache,e),-t.radius)),et.add(t.vertices[1],t.position,et.scale(this.cache,et.unit(this.cache,e),t.radius))},t}(),bt=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}(),_t=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 et,velocity:null!=r?r:new et,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(exports.RigidBodyType||(exports.RigidBodyType={}));var Mt=["x","y"],wt=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new et,this.displacement=new et,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 vt(vt([],t,!0),e.colliderIds,!0)}),[]),this.activeRigidBodies.forEach((function(i){i.type===exports.RigidBodyType.Dynamic?e.dynamicUpdate(i,t):i.type===exports.RigidBodyType.Kinematic&&e.kinematicUpdate(i,t),i.onResolve&&i.onResolve(i)}))},t.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),Mt.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;et.add(t.position,t.position,et.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){et.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}(),jt=function(){function t(t){this.radius=t,this.type=ct.Circumference,this.boundingBox=new it(0,0,0,0),this.vertices=[new et,new et],this.projectionAxes=[new et],this._position=new et}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}(),Pt=function(){function t(t){this.vertexModel=t,this.type=ct.Polygon,this.vertices=[new et,new et],this.projectionAxes=[new et],this.boundingBox=new it(0,0,0,0),this.rotation=0,this._position=new et}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(){et.normal(this.projectionAxes[0],et.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),Ot=function(){function t(t){this.vertexModel=t,this.type=ct.Polygon,this.vertices=[],this.boundingBox=new it(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new et,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 et),this._projectionAxes.push(new et)}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++)et.normal(this._projectionAxes[e],et.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),Ct=function(t){function e(e,i){var n=t.call(this,[new et(-e/2,-i/2),new et(-e/2,i/2),new et(e/2,i/2),new et(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new et,new et],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}mt(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(){et.unit(this.projectionAxes[0],et.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),et.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(Ot),At=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 At,this._center=new At,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 At&&!(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 At,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 Rt,St=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 Tt),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}(),Tt=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new At,this._leftStickAxes=new At,this._rightStickAxes=new At,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}(),Et=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}(),Dt=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}(),Bt=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new At,this._hasMoved=!1,this._wheelOffset=new At,this.lastPositionInViewport=new At,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,"wheelOffset",{get:function(){return this._wheelOffset},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._wheelOffset.set(this.wheelEvent.offsetX,this.wheelEvent.offsetY),this.wheelEvent=void 0):this._wheelOffset.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}(),Ft=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 At((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 At(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Rt||(Rt={})),exports.ButtonType=void 0;var It=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,Rt.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,Rt.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,Rt.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,Rt.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===Rt.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===Rt.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===Rt.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===Rt.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}(),Ut=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return r(e,t),e}(Error),Lt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Ut("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(s.Init,e),o},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):h([],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(s.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Gt=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=[s.Start,s.Update,s.StopGame],this.gameObjectEvents=[s.Start,s.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(s.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(s.Start),this.dispatchFrameEvent(s.Update),this.dispatchFrameEvent(s.UpdateEngine),this.dispatchFrameEvent(s.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(s.UpdatePhysics),this.dispatchFrameEvent(s.UpdateCollider),this.dispatchFrameEvent(s.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.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)})),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),Vt=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 Ut("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(s.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new Ut("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 Ut("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(s.Destroy),this.currentScene=void 0)},t}(),Ht=[60,120,180,240],Wt=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,!Ht.includes(t))throw new Ut("Invalid Physics frame rate. Allowed: [".concat(Ht.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}(),zt=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 Ut("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 Ut("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 Ut("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Ut("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 Ut("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),Xt=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}(),Yt=function(){function t(t,e,i,n){this._position=new Xt,this._center=new Xt,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 Xt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),Nt=function(t,e,i){return t>=e&&t<=i},qt=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Xt,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}(),Kt={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new Xt(1,1),collisions:{collisionMethod:lt.SAT,collisionBroadPhaseMethod:ot.SpartialGrid}},Qt=function(){function t(t){this._config=a(a({},Kt),t),this._config.collisions=a(a({},Kt.collisions),t.collisions),this.container=new zt,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 Wt(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 yt,a=o===lt.AABB?new pt(new ft,new gt,s):new dt(s,new xt),h=new ut(a,r,i,n),c=new rt,u=new wt(h),l=new _t;return new bt(h,c,u,l)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Gt(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new Lt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new A(t),i=e.gl,n=e.contextVersion,o=new E(i,n,new T(i,new D(i))),r=new Z(new J(i)),s=new tt(i,o,r,new Map([[l.Sprite,new z(i,o,r)],[l.Text,new K(i,o,r,new R)],[l.Tilemap,new Q(i,o,r)],[l.Geometric,new H(i,o)],[l.Mask,new W(i,o)],[l.Video,new $(i,o,r)]]));return new C(s,new M(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Et(new Bt(t),new Dt(t),new St,new Ft(t))}(i)})),t.add("AssetManager",(function(){return new It(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new p(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 Vt(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}(),$t=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 Xt,e._scale=new Xt(1,1),e._rotation=new qt,e._innerPosition=new Xt,e._parent=null,e.cache=new Xt,e.lastParentRadians=0,e.lastPosition=new Xt,e.scaledInnerPosition=new Xt,e}return r(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&&Xt.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(),Xt.add(this._position,this._parent.position,this.scaledInnerPosition)):Xt.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)),Xt.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}(v),Jt=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 r(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}(y),Zt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e}return r(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 Ut("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 Xt,position:new Xt})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new Ut("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 Jt&&t.physics})).reduce((function(t,e){return h(h([],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}(g),te=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($t),r.parent=o,r}return r(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($t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(Zt)},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(s.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new Ut("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(s.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(s.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(d),ee=["Default"],ie=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new Yt(0,0,0,0),e.worldSpaceRect=new Yt(0,0,0,0),e.depth=0,e.layers=ee,e._zoom=1,e}return r(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new Ut("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 Xt,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}(b),ne=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(ie)},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}(te),oe=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(ne),o}return r(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ne)},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}(d),re=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 Xt,e.scaledPosition=new Xt,e.finalRotation=0,e.innerPosition=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==lt.SAT)throw new Ut("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new Ut("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 qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Xt);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 Ot(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(se,{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(){Xt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),se=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:l.Geometric,location:u.WorldSpace,layer:this.gameObject.layer,position:new Xt,shape:c.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}(_),ae=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 Xt,e.realPosition=new Xt,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===lt.SAT,e.innerPosition=new Xt,e}return r(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 qt,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 Ct(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(se,{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(){Xt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),he=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 Xt,e.realPosition=new Xt,e.innerPosition=new Xt,e}return r(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 jt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(ce,{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(){Xt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),ce=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:l.Geometric,location:u.WorldSpace,layer:this.gameObject.layer,position:new Xt,shape:c.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}(_),ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new Xt,e}return r(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===exports.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([exports.TilemapOrientation.Center,exports.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==exports.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(le,{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 Xt(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new Ct(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 Xt(s,r)),e=new Xt(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 Xt(s,r)),e=new Xt(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 Pt([new Xt(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new Xt(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}(Jt),le=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return r(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:l.Geometric,layer:e.gameObject.layer,location:u.WorldSpace,position:new Xt,shape:c.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}(_),pe=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 Xt,e.scaledPosition=new Xt,e.finalRotation=0,e.innerPosition=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==lt.SAT)throw new Ut("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new Ut("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 qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Xt);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 Pt([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(de,{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(){Xt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Xt.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}(Jt),de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return r(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:l.Geometric,layer:e.gameObject.layer,location:u.WorldSpace,position:new Xt,shape:c.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}(_),fe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.renderData=[],e.innerPosition=new Xt,e.cachePosition=new Xt,e.cacheRenderPosition=new Xt,e.scaledOffset=new Xt,e.cacheScale=new Xt,e}return r(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 Xt,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new qt,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 Xt(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.spriteDefaultScale)&&void 0!==c?c:new Xt(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 Ut("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),e.prototype.update=function(){var t;if(this.sprite&&!0===this.sprite.loaded){this.scale=null!==(t=this.scale)&&void 0!==t?t:this.spriteDefaultScale,this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var e=0,i=0;i<this._tiled.x;i++)for(var n=0;n<this._tiled.y;n++)this.updateRenderData(e,i,n),e++}},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:l.Sprite,location:u.WorldSpace,layer:"",position:new Xt,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?u.ViewPort:u.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),Xt.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)),Xt.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),Xt.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){Xt.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}(_),ge=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.lastFrameText="",e}return r(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 Xt,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 qt,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 Ut("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Ut("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:l.Text,location:u.WorldSpace,position:new Xt,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?u.ViewPort:u.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,Xt.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}(_),ye=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new Xt,e.rotation=new qt,e.opacity=1,e.innerPosition=new Xt,e.scaledOffset=new Xt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(e=t.offset)&&void 0!==e?e:this.offset,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:this.rotation,this.opacity=null!==(n=t.opacity)&&void 0!==n?n:this.opacity,this.layer=t.layer,this.renderData={type:l.Mask,layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,width:0,height:0,color:""}},e.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?u.ViewPort:u.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,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.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),Xt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Xt.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}(_),me=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.innerPosition=new Xt,e.scaledOffset=new Xt,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(){me.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.video&&e._playing&&e.video.play()},e}return r(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,p;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 Xt,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new qt,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!==(p=t.loop)&&void 0!==p&&p,this.renderData={type:l.Video,location:u.WorldSpace,layer:"",position:new Xt,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(){me.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?u.ViewPort:u.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),Xt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Xt.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}(_),xe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return r(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,p=t.opacity,d=t.tintColor,f=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.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.spriteDefaultScale.y,this.layer=h,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=null!=c?c:exports.TilemapOrientation.Center,this.opacity=p,this.tintColor=d,this.renderData={type:l.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:f},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}(_),be=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteDefaultScale=e.gameConfig.spriteDefaultScale,e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return r(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.spriteDefaultScale.x,this.tileHeight=null!=r?r:this.tileset.tileHeight*this.spriteDefaultScale.y,this.layer=s,this.smooth=null!=h&&h,this.orientation=null!=a?a:exports.TilemapOrientation.Center,this.tiledLayer=this.tiledData.layers.find((function(t){return t.name===i})),!this.tiledLayer)throw new Ut("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:l.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Xt,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:exports.TilemapOrientation.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===exports.TilemapOrientation.Center?-t.realWidth/2:0)+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+([exports.TilemapOrientation.Center,exports.TilemapOrientation.RightCenter].includes(t.orientation)?t.realHeight/2:t.orientation==exports.TilemapOrientation.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}(_),_e=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 r(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 Me(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Ut("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}(g),Me=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}(),we=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],je=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(){we.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return r(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&&we.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}(g),Pe=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"}(exports.ButtonType||(exports.ButtonType={}));var Oe=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 Xt,e.pressed=!1,e.mouse=e.inputManager.mouse,e.touch=e.inputManager.touch,e.position=new Xt,e.distance=new Xt,e.pressedLastFrame=!1,e.scaled={width:0,height:0,radius:0,offset:new Xt},e}return r(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(),Xt.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===exports.ButtonType.Rectangle&&(this.pressed=Nt(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&Nt(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2))},e.prototype.resolveMouseAndCircumference=function(){this.type===exports.ButtonType.Circumference&&(Xt.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},e.prototype.resolveTouchAndRectangle=function(){if(this.type===exports.ButtonType.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===exports.ButtonType.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;Xt.subtract(this.distance,this.position,n),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},e}(g),Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new Xt,e}return r(e,t),e.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},e.prototype.update=function(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(Xt.round(this.position,Xt.add(this.position,this.camera.transform.position,Xt.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}(te),Ae=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 Ae,this._center=new Ae,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 Ae&&!(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 Ae,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 Re=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 Se),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}(),Se=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Ae,this._leftStickAxes=new Ae,this._rightStickAxes=new Ae,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}(),Te=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}(),Ee=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Ae,this._hasMoved=!1,this._wheelOffset=new Ae,this.lastPositionInViewport=new Ae,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,"wheelOffset",{get:function(){return this._wheelOffset},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._wheelOffset.set(this.wheelEvent.offsetX,this.wheelEvent.offsetY),this.wheelEvent=void 0):this._wheelOffset.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}(),De=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 Ae((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 Ae(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Be=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}(),Fe=function(){function t(t,e,i,n){this._position=new Be,this._center=new Be,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 Be&&!(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 Be,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))}}(),exports.BroadPhaseMethods=void 0;var Ie,Ue=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=Ue(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Ue(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Ue(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Ue(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}(),function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(exports.BroadPhaseMethods||(exports.BroadPhaseMethods={})),function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Ie||(Ie={})),exports.CollisionMethods=void 0,function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(exports.CollisionMethods||(exports.CollisionMethods={}));var Le,ke=function(t,e){return ke=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])},ke(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Le||(Le={})),function(){function t(t){this.radius=t,this.type=Ie.Circumference,this.boundingBox=new Fe(0,0,0,0),this.vertices=[new Be,new Be],this.projectionAxes=[new Be],this._position=new Be}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=Ie.Polygon,this.vertices=[new Be,new Be],this.projectionAxes=[new Be],this.boundingBox=new Fe(0,0,0,0),this.rotation=0,this._position=new Be}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(){Be.normal(this.projectionAxes[0],Be.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var Ge=function(){function t(t){this.vertexModel=t,this.type=Ie.Polygon,this.vertices=[],this.boundingBox=new Fe(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Be,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 Be),this._projectionAxes.push(new Be)}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++)Be.normal(this._projectionAxes[e],Be.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 Be(-e/2,-i/2),new Be(-e/2,i/2),new Be(e/2,i/2),new Be(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Be,new Be],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}ke(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(){Be.unit(this.projectionAxes[0],Be.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Be.normal(this.projectionAxes[1],this.projectionAxes[0])}}(Ge),exports.Animator=_e,exports.AudioPlayer=je,exports.BallCollider=he,exports.BoxCollider=ae,exports.Button=Oe,exports.Camera=ie,exports.Component=f,exports.EdgeCollider=pe,exports.Game=Qt,exports.GameCamera=ne,exports.GameObject=te,exports.GamepadController=Re,exports.GamepadData=Se,exports.KeyboardController=Te,exports.LAYER_DEFAULT="Default",exports.MaskRenderer=ye,exports.MouseController=Ee,exports.PhysicsComponent=m,exports.PolygonCollider=re,exports.PolygonColliderRenderer=se,exports.PreRenderComponent=x,exports.Rectangle=e,exports.RigidBody=Zt,exports.Rotation=n,exports.Scene=oe,exports.SpacePointer=Ce,exports.Sprite=Pe,exports.SpriteRenderer=fe,exports.TextRenderer=ge,exports.TiledTilemapRenderer=be,exports.TilemapCollider=ue,exports.TilemapRenderer=xe,exports.TouchController=De,exports.Transform=$t,exports.Vector2=t,exports.VideoRenderer=ve,exports.between=function(t,e,i){return t>=e&&t<=i},exports.clamp=function(t,e,i){return Math.min(i,Math.max(e,t))},exports.fixedRound=i,exports.randomFloat=function(t,e,n){return void 0===n&&(n=2),i(Math.random()*(e-t)+t,n)},exports.randomInt=function(t,e){return Math.round(Math.random()*(e-t))+t},exports.range=function(t,e,i){void 0===i&&(i=1);for(var n=[],o=t;o<=e;o+=i)n.push(o);return n};
2
2
  //# sourceMappingURL=index.cjs.js.map