angry-pixel 1.2.16 → 2.0.0

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(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),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),M=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 _=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;var P,O=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 O,this._center=new O,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 O&&!(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 O,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"}(P||(P={}));var C,A=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 O});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==P.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===P.RightDown?-t.tilemap.realHeight/2:t.orientation===P.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"}(C||(C={}));var R=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(C.WebGL2)?C.WebGL2:null!==this.canvas.getContext(C.LegacyWebGL)?C.LegacyWebGL:void 0},t}(),S=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 E(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}(),E=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}(),D=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===C.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}(),B=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}(),F="undefined"!=typeof Float32Array?Float32Array:Array;function I(){var t=new F(16);return F!=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 U(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 L(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 k(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 V(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.MaskShape=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},H=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=U(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===u.WorldSpace&&(k(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1]),L(t,t,[-i.position.x,-i.position.y,0]))},W=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I();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=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),H(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=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),k(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),H(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}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(exports.MaskShape||(exports.MaskShape={})),exports.TextOrientation=void 0;var z=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=l.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I();for(var i=2*Math.PI/60,n=[0,0],o=0;o<=60;o++)n.push(Math.cos(o*i),Math.sin(o*i));this.circumferenceVertices=new Float32Array(n)}return t.prototype.render=function(t,e,i){var n,o;i===l.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===exports.MaskShape.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),k(this.modelMatrix,this.modelMatrix,t.shape===exports.MaskShape.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),H(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),t.shape===exports.MaskShape.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape},t}(),X=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I(),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=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),k(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=U(this.textureMatrix),t.slice&&(L(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),k(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),H(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 Y=new O,N=new O,q=[32,126,161,255],K=exports.TextOrientation.Center,Q=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 O,this.modelPosition=new O,this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I()}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=U(this.modelMatrix),this.setPositionFromOrientation(t),L(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),k(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=U(this.textureMatrix),H(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:Y,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:N,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:q):t.bitmap={margin:Y,spacing:N,fontSize:64,charRanges:q},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:K,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}(),$=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 O,texSpacing:new O,texWidth:0,texHeight:0,texCorrection:new O},this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I()}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=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),k(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=U(this.textureMatrix),k(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),H(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 O,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new O,h.correction=null!==(n=h.correction)&&void 0!==n?n:new O,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}(),J=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=I(),this.modelMatrix=I(),this.textureMatrix=I(),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=U(this.modelMatrix),L(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),V(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),k(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=U(this.textureMatrix),t.slice&&(L(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),k(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),H(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}(),Z=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}(),tt=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}(),et=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}(),it=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}(),nt=function(){function t(t,e,i,n){this._position=new it,this._center=new it,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 it&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),ot=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 it,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(){}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 it,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),at=function(){function t(t,e){void 0===e&&(e=0),this.area=new nt(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 nt(this.area.x,this.area.y,i,n),new nt(this.area.x,this.area.y+n,i,n),new nt(this.area.x+i,this.area.y+n,i,n),new nt(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}(),ht=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},ct=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=ot(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=ht(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=ht(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=ht(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=ht(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(rt||(rt={}));var ut,lt=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new it,this.maxArea=new it,this.newArea=new nt(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:rt.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new nt(0,0,0,0),this.fixedCollisionArea=!!e,t===rt.SpartialGrid?this.broadPhaseResolver=new ct(this.collisionArea):this.broadPhaseResolver=new at(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.getCollisionsForColliderAndLayer=function(t,e){return t.active?this.collisions.filter((function(i){return i.localCollider.id===t.id&&i.remoteCollider.layer===e})):[]},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 ct&&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"}(ut||(ut={}));var pt,dt=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===ut.Polygon&&e.type===ut.Polygon?this.AABBResolver.resolve(t,e):t.type===ut.Circumference&&e.type===ut.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===ut.Polygon&&e.type===ut.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===ut.Circumference&&e.type===ut.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(pt||(pt={}));var ft=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===ut.Circumference&&e.type===ut.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),gt=function(){function t(){this.direction=new it,this.displacementDirection=new it}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)),it.unit(this.displacementDirection,this.displacementDirection),{direction:it.scale(new it,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}(),yt=function(){function t(){this.closestPoint=new it,this.distance=new it,this.direction=new it}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(ot(t.position.x,e.boundingBox.x,e.boundingBox.x1),ot(t.position.y,e.boundingBox.y,e.boundingBox.y1)),it.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(it.unit(this.direction,this.distance),{direction:i?it.scale(new it,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():it.scale(new it,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),mt=function(){function t(){this.distance=new it,this.direction=new it}return t.prototype.resolve=function(t,e){return it.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(it.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:it.scale(new it,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),vt=function(t,e){return vt=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])},vt(t,e)};function xt(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 bt=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new it,this.distance=new it(1/0,1/0),this.cache=new it}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===ut.Circumference?this.setCircumferenceAxis(t,e):e.type===ut.Circumference&&this.setCircumferenceAxis(e,t),this.axes=xt([],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===ut.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===ut.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,it.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&&it.scale(this.smallestAxis,this.axes[n],-1))}return{direction:it.scale(new it,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(it.dot(i,e),t.min),t.max=Math.max(it.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){it.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),it.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){it.add(t.vertices[0],t.position,it.scale(this.cache,it.unit(this.cache,e),-t.radius)),it.add(t.vertices[1],t.position,it.scale(this.cache,it.unit(this.cache,e),t.radius))},t}(),Mt=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.getCollisionsForColliderAndLayer=function(t,e){return this.collisionManager.getCollisionsForColliderAndLayer(t,e)},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 it,velocity:null!=r?r:new it,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 wt=["x","y"],jt=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new it,this.displacement=new it,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 xt(xt([],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),wt.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;it.add(t.position,t.position,it.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){it.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=ut.Circumference,this.boundingBox=new nt(0,0,0,0),this.vertices=[new it,new it],this.projectionAxes=[new it],this._position=new it}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}(),Ot=function(){function t(t){this.vertexModel=t,this.type=ut.Polygon,this.vertices=[new it,new it],this.projectionAxes=[new it],this.boundingBox=new nt(0,0,0,0),this.rotation=0,this._position=new it}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(){it.normal(this.projectionAxes[0],it.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),Ct=function(){function t(t){this.vertexModel=t,this.type=ut.Polygon,this.vertices=[],this.boundingBox=new nt(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new it,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 it),this._projectionAxes.push(new it)}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++)it.normal(this._projectionAxes[e],it.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),At=function(t){function e(e,i){var n=t.call(this,[new it(-e/2,-i/2),new it(-e/2,i/2),new it(e/2,i/2),new it(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new it,new it],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}vt(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(){it.unit(this.projectionAxes[0],it.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),it.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(Ct),Rt=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 Rt,this._center=new Rt,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 Rt&&!(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 Rt,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 St,Et=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 Rt,this._leftStickAxes=new Rt,this._rightStickAxes=new Rt,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}(),Dt=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}(),Bt=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}(),Ft=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Rt,this._hasMoved=!1,this._wheelScroll=new Rt,this.lastPositionInViewport=new Rt,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),It=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 Rt((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 Rt(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(St||(St={})),exports.ButtonType=void 0;var Ut=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,St.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,St.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,St.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,St.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===St.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===St.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===St.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===St.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}(),Lt=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return r(e,t),e}(Error),kt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Lt("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}(),Vt=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.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),Ht=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 Lt("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 Lt("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 Lt("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}(),Wt=[60,120,180,240],zt=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!Wt.includes(t))throw new Lt("Invalid Physics frame rate. Allowed: [".concat(Wt.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}(),Xt=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 Lt("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 Lt("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 Lt("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Lt("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 Lt("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),Yt=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}(),Nt=function(){function t(t,e,i,n){this._position=new Yt,this._center=new Yt,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 Yt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),qt=function(t,e,i){return t>=e&&t<=i},Kt=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Yt,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}(),Qt={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new Yt(1,1),collisions:{collisionMethod:pt.SAT,collisionBroadPhaseMethod:rt.SpartialGrid}},$t=function(){function t(t){this._config=a(a({},Qt),t),this._config.collisions=a(a({},Qt.collisions),t.collisions),this.container=new Xt,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){(function(t,e){if(t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new zt(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new Vt(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 mt,a=o===pt.AABB?new dt(new gt,new yt,s):new ft(s,new bt),h=new lt(a,r,i,n),c=new st,u=new jt(h),l=new _t;return new Mt(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 kt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new R(t),i=e.gl,n=e.contextVersion,o=new D(i,n,new T(i,new B(i))),r=new tt(new Z(i)),s=new et(i,o,r,new Map([[l.Sprite,new X(i,o,r)],[l.Text,new Q(i,o,r,new S)],[l.Tilemap,new $(i,o,r)],[l.Geometric,new W(i,o)],[l.Mask,new z(i,o)],[l.Video,new J(i,o,r)]]));return new A(s,new _(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Dt(new Ft(t),new Bt(t),new Et,new It(t))}(i)})),t.add("AssetManager",(function(){return new Ut(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 Ht(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}(),Jt=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 Yt,e._scale=new Yt(1,1),e._rotation=new Kt,e._innerPosition=new Yt,e._parent=null,e.cache=new Yt,e.lastParentRadians=0,e.lastPosition=new Yt,e.scaledInnerPosition=new Yt,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&&Yt.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(),Yt.add(this._position,this._parent.position,this.scaledInnerPosition)):Yt.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)),Yt.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),Zt=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){for(var e=0,i=this.colliders;e<i.length;e++){var n=i[e];if(this.physicsManager.getCollisionsForColliderAndLayer(n,t).length>0)return!0}return!1},e.prototype.collidesWithLayers=function(t,e){void 0===e&&(e="or");for(var i=0,n=0,o=this.colliders;n<o.length;n++)for(var r=o[n],s=0,a=this.physicsManager.getCollisionsForCollider(r);s<a.length;s++){var h=a[s];if(t.includes(h.remoteCollider.layer)){if("or"===e)return!0;i++}}return"and"===e&&i===t.length},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++){var n=i[e],o=this.physicsManager.getCollisionsForColliderAndLayer(n,t);if(o.length>0)return this.createCollisionData(o[0])}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=this,i=[],n=0,o=this.colliders;n<o.length;n++){var r=o[n];this.physicsManager.getCollisionsForColliderAndLayer(r,t).forEach((function(t){return i.push(e.createCollisionData(t))}))}return i},e.prototype.getCollisionsWithLayers=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var o=n[i],r=0,s=this.physicsManager.getCollisionsForCollider(o);r<s.length;r++){var a=s[r];t.includes(a.remoteCollider.layer)&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(Number(t.remoteCollider.group)),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject},localCollider:t.localCollider}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(y),te=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 Lt("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 Yt,position:new Yt})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new Lt("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 Zt&&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),ee=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(Jt),o&&(r.transform.position=o.transform.position,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(Jt)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(te)},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 Lt("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),ie=["Default"],ne=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new Nt(0,0,0,0),e.worldSpaceRect=new Nt(0,0,0,0),e.depth=0,e.layers=ie,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 Lt("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 Yt,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),oe=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(ne)},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}(ee),re=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(oe),o}return r(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(oe)},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),se=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 Yt,e.scaledPosition=new Yt,e.finalRotation=0,e.innerPosition=new Yt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==pt.SAT)throw new Lt("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new Lt("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 Kt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Yt);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.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(ae,{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(){Yt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Yt.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}(Zt),ae=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 Yt,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}(M),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.realWidth=0,e.realHeight=0,e.realOffset=new Yt,e.realPosition=new Yt,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===pt.SAT,e.innerPosition=new Yt,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 Kt,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 At(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(ae,{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(){Yt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Yt.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}(Zt),ce=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 Yt,e.realPosition=new Yt,e.innerPosition=new Yt,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(ue,{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(){Yt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Yt.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}(Zt),ue=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 Yt,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}(M),le=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new Yt,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.scaledWidth/2,this.gameObject.transform.position.y+this.scaledHeight/2),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(pe,{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 Yt(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new At(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 Yt(s,r)),e=new Yt(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 Yt(s,r)),e=new Yt(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 Ot([new Yt(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new Yt(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}(Zt),pe=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 Yt,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}(M),de=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 Yt,e.scaledPosition=new Yt,e.finalRotation=0,e.innerPosition=new Yt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==pt.SAT)throw new Lt("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new Lt("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 Kt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Yt);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 Ot([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(fe,{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(){Yt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Yt.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}(Zt),fe=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 Yt,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}(M),ge=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.innerPosition=new Yt,e.cachePosition=new Yt,e.cacheRenderPosition=new Yt,e.scaledOffset=new Yt,e.cacheScale=new Yt,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 Yt,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new Kt,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 Yt(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(a=t.maskColorMix)&&void 0!==a?a:0,this.tintColor=t.tintColor,this.layer=t.layer,this.scale=null!==(c=null!==(h=t.scale)&&void 0!==h?h:this.gameConfig.spriteDefaultScale.clone())&&void 0!==c?c:new Yt(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 Lt("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),e.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},e.prototype.updateRenderDataArray=function(){if(this.renderData.length!==this._tiled.x*this._tiled.y){this.renderData=[];for(var t=0;t<this._tiled.x*this._tiled.y;t++)this.renderData[t]={type:l.Sprite,location:u.WorldSpace,layer:"",position:new Yt,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),Yt.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)),Yt.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),Yt.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){Yt.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}(M),ye=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 Yt,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 Kt,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 Lt("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Lt("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:l.Text,location:u.WorldSpace,position:new Yt,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,Yt.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}(M),me=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new Yt,e.rotation=new Kt,e.opacity=1,e.innerPosition=new Yt,e.scaledOffset=new Yt,e}return r(e,t),e.prototype.init=function(t){var e,i,n,o,r,s,a;this.shape=t.shape,this.color=t.color,this.width=null!==(e=t.width)&&void 0!==e?e:0,this.height=null!==(i=t.height)&&void 0!==i?i:0,this.radius=null!==(n=t.radius)&&void 0!==n?n:0,this.offset=null!==(o=t.offset)&&void 0!==o?o:this.offset,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:this.rotation,this.opacity=null!==(s=t.opacity)&&void 0!==s?s:this.opacity,this.layer=t.layer,this.renderData={type:l.Mask,layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Yt,width:0,height:0,radius:0,color:"",shape:this.shape}},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.shape=this.shape,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.radius=this.radius*Math.abs(Math.max(this.gameObject.transform.scale.x,this.gameObject.transform.scale.y)),this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},e.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),Yt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Yt.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}(M),ve=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],xe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.innerPosition=new Yt,e.scaledOffset=new Yt,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(){ve.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 Yt,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new Kt,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 Yt,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(){ve.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),Yt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Yt.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}(M),be=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.infinite=!1,e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return r(e,t),e.prototype.init=function(t){var e=this,i=t.tiledData,n=t.tilemapLayer,o=t.tileset,r=t.tileWidth,s=t.tileHeight,a=t.layer,h=t.smooth;if(this.tiledData=i,this.tileset=o,this.tileWidth=null!=r?r:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=a,this.smooth=null!=h&&h,this.tiledLayer=this.tiledData.layers.find((function(t){return t.name===n})),!this.tiledLayer)throw new Lt("Invalid tilemap layer");this.width=0,this.height=0,this.tiledData.layers.forEach((function(t){e.width=Math.max(e.width,t.width),e.height=Math.max(e.height,t.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.infinite=!0,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.processFixedLayer()),this.updateRenderData(),this.tilesetTileIds=[]},e.prototype.processFixedLayer=function(){var t,e=this;this.tiles=this.tiledLayer.data.map((function(t){return e.getTilesetTileId(t)})),this.renderData.push({type:l.Tilemap,layer:null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,location:this.gameObject.ui?u.ViewPort:u.WorldSpace,position:new Yt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:P.Center,smooth:this.smooth})},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 Yt,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:P.Center,smooth:this.smooth};n.tiles.forEach((function(e,n){i.tiles[i.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.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;if(e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,t.infinite){var o=t.chunks[i];e.position.set(t.gameObject.transform.position.x-t.realWidth/2+(o.x+o.width/2)*t.scaledTileWidth,t.gameObject.transform.position.y+t.realHeight/2-(o.y+o.height/2)*t.scaledTileHeight)}else e.position.copy(t.gameObject.transform.position);e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.opacity}))},e}(M),Me=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return 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.opacity,p=t.tintColor,d=t.smooth;n.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?i.tiles.push(Number(t)):null}))})),this.tileset=o,this.width=a,this.tileWidth=null!=r?r:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=h,this.height=Math.ceil(this.tiles.length/this.width),this.opacity=c,this.tintColor=p,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 Yt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:P.Center,smooth:d},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}(M),_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 we(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Lt("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),we=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}(),je=["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(){je.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&&je.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),Oe=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 Ce=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 Yt,e.pressed=!1,e.mouse=e.inputManager.mouse,e.touch=e.inputManager.touch,e.position=new Yt,e.distance=new Yt,e.pressedLastFrame=!1,e.scaled={width:0,height:0,radius:0,offset:new Yt},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(),Yt.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=qt(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&qt(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&&(Yt.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;Yt.subtract(this.distance,this.position,n),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},e}(g),Ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new Yt,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&&(Yt.round(this.position,Yt.add(this.position,this.camera.transform.position,Yt.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}(ee),Re=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 Re,this._center=new Re,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 Re&&!(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 Re,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 Se=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 Ee),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}(),Ee=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Re,this._leftStickAxes=new Re,this._rightStickAxes=new Re,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}(),De=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Re,this._hasMoved=!1,this._wheelScroll=new Re,this.lastPositionInViewport=new Re,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),Be=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 Re((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 Re(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Fe=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),Ie=function(){function t(t,e,i,n){this._position=new Fe,this._center=new Fe,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 Fe&&!(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 Fe,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 Ue,Le=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=Le(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Le(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Le(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Le(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"}(Ue||(Ue={})),exports.CollisionMethods=void 0,function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(exports.CollisionMethods||(exports.CollisionMethods={}));var ke,Ve=function(t,e){return Ve=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])},Ve(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(ke||(ke={})),function(){function t(t){this.radius=t,this.type=Ue.Circumference,this.boundingBox=new Ie(0,0,0,0),this.vertices=[new Fe,new Fe],this.projectionAxes=[new Fe],this._position=new Fe}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=Ue.Polygon,this.vertices=[new Fe,new Fe],this.projectionAxes=[new Fe],this.boundingBox=new Ie(0,0,0,0),this.rotation=0,this._position=new Fe}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(){Fe.normal(this.projectionAxes[0],Fe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var Ge=function(){function t(t){this.vertexModel=t,this.type=Ue.Polygon,this.vertices=[],this.boundingBox=new Ie(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Fe,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 Fe),this._projectionAxes.push(new Fe)}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++)Fe.normal(this._projectionAxes[e],Fe.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 Fe(-e/2,-i/2),new Fe(-e/2,i/2),new Fe(e/2,i/2),new Fe(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Fe,new Fe],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}Ve(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(){Fe.unit(this.projectionAxes[0],Fe.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Fe.normal(this.projectionAxes[1],this.projectionAxes[0])}}(Ge),exports.Animator=_e,exports.AudioPlayer=Pe,exports.BallCollider=ce,exports.BoxCollider=he,exports.Button=Ce,exports.Camera=ne,exports.Component=f,exports.EdgeCollider=de,exports.Game=$t,exports.GameCamera=oe,exports.GameObject=ee,exports.GamepadController=Se,exports.GamepadData=Ee,exports.KeyboardController=Te,exports.LAYER_DEFAULT="Default",exports.MaskRenderer=me,exports.MouseController=De,exports.PhysicsComponent=m,exports.PolygonCollider=se,exports.PolygonColliderRenderer=ae,exports.PreRenderComponent=x,exports.Rectangle=e,exports.RigidBody=te,exports.Rotation=n,exports.Scene=re,exports.SpacePointer=Ae,exports.Sprite=Oe,exports.SpriteRenderer=ge,exports.TextRenderer=ye,exports.TiledTilemapRenderer=be,exports.TilemapCollider=le,exports.TilemapRenderer=Me,exports.TouchController=Be,exports.Transform=Jt,exports.Vector2=t,exports.VideoRenderer=xe,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";const t={AssetManager:Symbol.for("AssetManager"),CanvasElement:Symbol.for("CanvasElement"),CollisionRepository:Symbol.for("CollisionRepository"),CollisionBroadphaseResolver:Symbol.for("CollisionBroadphaseResolver"),CollisionResolutionMethod:Symbol.for("CollisionResolutionMethod"),CollisionAABBResolver:Symbol.for("CollisionAABBResolver"),CollisionCircumferenceAABBResolver:Symbol.for("CollisionCircumferenceAABBResolver"),CollisionCircumferenceResolver:Symbol.for("CollisionCircumferenceResolver"),CollisionSatResolver:Symbol.for("CollisionSatResolver"),CollisionMatrix:Symbol.for("CollisionMatrix"),EntityManager:Symbol.for("EntityManager"),GameConfig:Symbol.for("GameConfig"),InputManager:Symbol.for("InputManager"),LoopManager:Symbol.for("LoopManager"),RenderManager:Symbol.for("RenderManager"),SceneManager:Symbol.for("SceneManager"),SystemFactory:Symbol.for("SystemFactory"),SystemManager:Symbol.for("SystemManager"),TimeManager:Symbol.for("TimeManager"),WebGLManager:Symbol.for("WebGLManager")};class e{constructor(){this.instances=new Map,this.types=new Map}add(t,e){if(!e&&!t.prototype.__ioc_injectable)throw new Error(`Type ${t.name} is not injectable`);return this.types.set(null!=e?e:t.prototype.__ioc_injectable,t),this}set(t,e){return this.instances.set(t,e),this}get(t){var e,i;if(!this.instances.has(t)){const s=this.types.get(t);if(!s)throw new Error(`${t.toString()} is not a valid type`);const o=new s(...(null!==(e=s.prototype.__ioc_inject_constructor)&&void 0!==e?e:[]).map((t=>this.get(t))));(null!==(i=s.prototype.__ioc_inject_prop)&&void 0!==i?i:[]).forEach((([t,e])=>o[t]=this.get(e))),this.instances.set(t,o)}return this.instances.get(t)}has(t){return this.types.has(t)||this.instances.has(t)}}function i(t){return function(e){e.prototype.__ioc_injectable&&e.prototype.__ioc_injectable===t||(e.prototype.__ioc_injectable=t)}}function s(t){return function(e,i,s){void 0!==s?(e.prototype.__ioc_inject_constructor||(e.prototype.__ioc_inject_constructor=[]),e.prototype.__ioc_inject_constructor[s]=t):void 0!==i&&(e.constructor.prototype.__ioc_inject_prop||(e.constructor.prototype.__ioc_inject_prop=[]),e.constructor.prototype.__ioc_inject_prop.push([i,t]))}}var o;function r(t,e,i,s){var o,r=arguments.length,a=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(o=t[n])&&(a=(r<3?o(a):r>3?o(e,i,a):o(e,i))||a);return r>3&&a&&Object.defineProperty(e,i,a),a}function a(t,e){return function(i,s){e(i,s,t)}}exports.BroadPhaseMethods=void 0,(o=exports.BroadPhaseMethods||(exports.BroadPhaseMethods={}))[o.QuadTree=0]="QuadTree",o[o.SpartialGrid=1]="SpartialGrid","function"==typeof SuppressedError&&SuppressedError;class n{constructor(t=0,e=0){this._x=t,this._y=e}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}get magnitude(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))}get direction(){return this._direction||(this._direction=new n),n.unit(this._direction,this)}set(t,e){this._x=t,this._y=e}copy(t){this.set(t.x,t.y)}equals(t){return this._x===t.x&&this._y===t.y}clone(){return new n(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}class h{constructor(t=0,e=0,i=0,s=0){this.width=0,this.height=0,this._position=new n,this._center=new n,this.set(t,e,i,s)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this.width}get y1(){return this._position.y+this.height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,s){this._position.set(t,e),this.width=i,this.height=s}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(t){return t instanceof h?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof n&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const l=(t,e,i)=>Math.min(i,Math.max(e,t)),c=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),d=(t,e,i=1)=>{const s=[];for(let o=t;o<=e;o+=i)s.push(o);return s},p=(t,e,i)=>t>=e&&t<=i;var m;let g=m=class{constructor(t=new h,e=0){this.children=[],this.shapes=[],this.minArea=new n,this.maxArea=new n,this.area=t,this.depth=e}clear(){this.shapes=[],this.children=[]}update(t){this.clear(),this.resizeArea(t),t.forEach((({id:t,boundingBox:e})=>this.insert(t,e)))}resizeArea(t){this.minArea.set(0,0),this.maxArea.set(0,0),t.forEach((({boundingBox:t})=>{this.minArea.set(Math.min(t.x,this.minArea.x),Math.min(t.y,this.minArea.y)),this.maxArea.set(Math.max(t.x1,this.maxArea.x),Math.max(t.y1,this.maxArea.y))})),this.area.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForBox(t).forEach((i=>e.push(...i.retrieve(t).filter((t=>!e.includes(t)))))):this.shapes.forEach((t=>e.push(t[0]))),e}insert(t,e){0===this.children.length&&this.shapes.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.shapes.push([t,e])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new h(this.area.x,this.area.y,t,e),new h(this.area.x,this.area.y+e,t,e),new h(this.area.x+t,this.area.y+e,t,e),new h(this.area.x+t,this.area.y,t,e)].map((t=>new m(t,this.depth+1))),this.shapes.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.shapes=[]}insertItemIntoChildren(t,e){this.getChildrenForBox(e).forEach((i=>i.insert(t,e)))}getChildrenForBox(t){const 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}};g=m=r([i(t.CollisionBroadphaseResolver)],g);const u=(t,e,i,s)=>Math.min((t-e)/i|0,s-1);let y=class{constructor(){this.area=new h,this.colliders=[],this.subdivisions=0,this.coordinates={x0:0,x1:0,y0:0,y1:0},this.minArea=new n,this.maxArea=new n}clear(){for(let t=0;t<this.subdivisions;t++)for(let e=0;e<this.subdivisions;e++)this.colliders[t][e]=[]}update(t){this.resizeArea(t),this.updateSubdivisions(t.length),t.forEach((({id:t,boundingBox:e})=>this.insert(t,e)))}resizeArea(t){this.minArea.set(0,0),this.maxArea.set(0,0),t.forEach((({boundingBox:t})=>{this.minArea.set(Math.min(t.x,this.minArea.x),Math.min(t.y,this.minArea.y)),this.maxArea.set(Math.max(t.x1,this.maxArea.x),Math.max(t.y1,this.maxArea.y))})),this.area.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}updateSubdivisions(t){this.subdivisions=1+(t/10|0),this.cellWidth=Math.ceil(this.area.width/this.subdivisions),this.cellHeight=Math.ceil(this.area.height/this.subdivisions),this.colliders=[];for(let t=0;t<this.subdivisions;t++){this.colliders[t]=[];for(let e=0;e<this.subdivisions;e++)this.colliders[t][e]=[]}}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.colliders[e][i].push(t)}retrieve(t){const e=[];this.updateCoordinates(t);for(let t=this.coordinates.x0;t<=this.coordinates.x1;t++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.colliders[t][i].forEach((t=>e.includes(t)?void 0:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=u(t.x,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.x1=u(t.x1,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.y0=u(t.y,this.area.y,this.cellHeight,this.subdivisions),this.coordinates.y1=u(t.y1,this.area.y,this.cellHeight,this.subdivisions)}};y=r([i(t.CollisionBroadphaseResolver)],y);class x{get vertexModel(){return this._vertexModel}set vertexModel(t){if(this._vertexModel=t,2===t.length)return this.vertices=[new n,new n],void(this.projectionAxes=[new n]);this.vertices=[],this.projectionAxes=[],this._vertexModel.forEach((()=>{this.vertices.push(new n),this.projectionAxes.push(new n)}))}constructor(t,e=0){this.rotation=e,this.boundingBox=new h,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new n,this.projectionAxes=[],this.radius=0,this.vertices=[],this.updateCollisions=!0,this._vertexModel=[],this.vertexModel=t}}class f{constructor(t){this.radius=t,this.boundingBox=new h,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new n,this.projectionAxes=[new n],this.rotation=0,this.vertexModel=[],this.vertices=[new n,new n],this.updateCollisions=!0}}let M=class{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}findCollision(t,e){return t instanceof x&&e instanceof x?this.AABBResolver.resolve(t,e):t instanceof f&&e instanceof x?this.circumferenceAABBResolver.resolve(t,e):t instanceof x&&e instanceof f?this.circumferenceAABBResolver.resolve(e,t,!0):t instanceof f&&e instanceof f?this.circumferenceResolver.resolve(t,e):void 0}};var v;M=r([i(t.CollisionResolutionMethod),a(0,s(t.CollisionAABBResolver)),a(1,s(t.CollisionCircumferenceAABBResolver)),a(2,s(t.CollisionCircumferenceResolver))],M),exports.CollisionMethods=void 0,(v=exports.CollisionMethods||(exports.CollisionMethods={}))[v.AABB=0]="AABB",v[v.SAT=1]="SAT";let S=class{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}findCollision(t,e){return t instanceof f&&e instanceof f?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}};S=r([i(t.CollisionResolutionMethod),a(0,s(t.CollisionCircumferenceResolver)),a(1,s(t.CollisionSatResolver))],S);let C=class{constructor(){this.direction=new n,this.resolutionDirection=new n}resolve({boundingBox:t},{boundingBox:e}){if(this.overlapX=Math.min(t.x1,e.x1)-Math.max(t.x,e.x),this.overlapY=Math.min(t.y1,e.y1)-Math.max(t.y,e.y),!(this.overlapX<0||this.overlapY<0))return this.checkOverlapForLines(t,e),this.direction.set(Math.sign(e.center.x-t.center.x),Math.sign(e.center.y-t.center.y)),this.preventContainment(t,e),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.resolutionDirection.set(0,this.direction.y)):(this.minOverlap=this.overlapX,this.resolutionDirection.set(this.direction.x,this.overlapY===this.overlapX?this.direction.y:0)),{direction:n.unit(new n,this.resolutionDirection),penetration:this.minOverlap}}checkOverlapForLines(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)))}preventContainment(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){const i=Math.abs(t.y-e.y),s=Math.abs(t.y1-e.y1);this.overlapY+=i<s?i:s}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),s=Math.abs(t.x1-e.x1);this.overlapX+=i<s?i:s}}};C=r([i(t.CollisionAABBResolver)],C);let b=class{constructor(){this.closestPoint=new n,this.distance=new n,this.direction=new n}resolve(t,e,i=!1){if(this.closestPoint.set(l(t.position.x,e.boundingBox.x,e.boundingBox.x1),l(t.position.y,e.boundingBox.y,e.boundingBox.y1)),n.subtract(this.distance,this.closestPoint,t.position),!(this.distance.magnitude>t.radius))return n.unit(this.direction,this.distance),{direction:i?n.scale(new n,this.direction,-1):this.direction.clone(),penetration:t.radius-this.distance.magnitude}}};b=r([i(t.CollisionCircumferenceAABBResolver)],b);let w=class{constructor(){this.distance=new n,this.direction=new n}resolve(t,e){if(n.subtract(this.distance,e.position,t.position),!(this.distance.magnitude>t.radius+e.radius))return n.unit(this.direction,this.distance),{direction:this.direction.clone(),penetration:t.radius+e.radius-this.distance.magnitude}}};w=r([i(t.CollisionCircumferenceResolver)],w);let E=class{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new n,this.distance=new n(1/0,1/0),this.cache=new n}resolve(t,e){this.minOverlap=1/0,t instanceof f?this.setCircumferenceAxis(t,e):e instanceof f&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?void 0:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t instanceof f?this.setCircumferenceVertices(t,this.axes[i]):e instanceof f&&this.setCircumferenceVertices(e,this.axes[i]),this.projectShapeOntoAxis(this.projA,t,this.axes[i]),this.projectShapeOntoAxis(this.projB,e,this.axes[i]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return;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){const t=Math.abs(this.projA.min-this.projB.min),e=Math.abs(this.projA.max-this.projB.max);t<e?this.currentOverlap+=t:(this.currentOverlap+=e,n.scale(this.axes[i],this.axes[i],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[i]),this.invertAxis&&this.projA.max<this.projB.max&&n.scale(this.smallestAxis,this.axes[i],-1))}return{direction:n.scale(new n,this.smallestAxis,-1),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(n.dot(i,e),t.min),t.max=Math.max(n.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{n.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),n.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){n.add(t.vertices[0],t.position,n.scale(this.cache,n.unit(this.cache,e),-t.radius)),n.add(t.vertices[1],t.position,n.scale(this.cache,n.unit(this.cache,e),t.radius))}};E=r([i(t.CollisionSatResolver)],E),exports.CollisionRepository=class{constructor(){this.collisions=[]}findCollisionsForCollider(t){return this.collisions.filter((e=>e.localCollider===t))}findCollisionsForColliderAndLayer(t,e){return this.collisions.filter((i=>i.localCollider===t&&i.remoteCollider.layer===e))}findAll(){return this.collisions}persist(t){this.collisions.push(t)}removeAll(){this.collisions=[]}},exports.CollisionRepository=r([i(t.CollisionRepository)],exports.CollisionRepository),exports.EntityManager=class{constructor(){this.lastEntityId=0,this.lastComponentTypeId=0,this.components=new Map,this.disabledEntities=new Set,this.disabledComponents=new Map}createEntity(t){return this.lastEntityId++,t&&t.forEach((t=>this.addComponent(this.lastEntityId,t))),this.lastEntityId}removeEntity(t){this.components.forEach((e=>{e.has(t)&&e.delete(t)})),this.disabledComponents.delete(t),this.disabledEntities.delete(t)}removeAllEntities(){this.components.clear(),this.disabledComponents.clear(),this.disabledEntities.clear(),this.lastEntityId=0}isEntityEnabled(t){return!this.disabledEntities.has(t)}enableEntity(t){this.disabledEntities.delete(t)}disableEntity(t){this.disabledEntities.add(t)}disableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.disableEntity(s)}enableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.enableEntity(s)}addComponent(t,e){const i=this.getComponentTypeId(e),s="object"==typeof e?e:new e;if(this.components.has(i)||this.components.set(i,new Map),this.components.get(i).has(t))throw new Error(`Entity ${t} already has a component of type ${i}`);return this.components.get(i).set(t,s),s}hasComponent(t,e){return void 0!==this.getComponent(t,e)}getComponent(t,e){var i;return null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.get(t)}getComponents(t){const e=[];return this.components.forEach((i=>i.forEach(((i,s)=>{t===s&&e.push(i)})))),e}getEntityForComponent(t){const e=this.getComponentTypeId(t);if(this.components.has(e))for(const[i,s]of this.components.get(e))if(s===t)return i}removeComponent(t,e){var i;const s=this.getComponentTypeId("object"==typeof t?t:e),o="number"==typeof t?t:this.getEntityForComponent(t);(null===(i=this.components.get(s))||void 0===i?void 0:i.has(o))&&this.components.get(s).delete(o)}isComponentEnabled(t,e){var i,s;const o=this.getComponentTypeId("object"==typeof t?t:e),r="number"==typeof t?t:this.getEntityForComponent(t);return null===(s=!(null===(i=this.disabledComponents.get(r))||void 0===i?void 0:i.has(o)))||void 0===s||s}disableComponent(t,e){const i="number"==typeof t?t:this.getEntityForComponent(t),s=this.getComponentTypeId("object"==typeof t?t:e);this.disabledComponents.has(i)?this.disabledComponents.get(i).has(s)||this.disabledComponents.get(i).add(s):this.disabledComponents.set(i,new Set([s]))}enableComponent(t,e){var i;const s="number"==typeof t?t:this.getEntityForComponent(t),o=this.getComponentTypeId("object"==typeof t?t:e);(null===(i=this.disabledComponents.get(s))||void 0===i?void 0:i.has(o))&&this.disabledComponents.get(s).delete(o)}search(t,e,i=!1){const s=[],o=this.getComponentTypeId(t);return this.components.has(o)&&this.components.get(o).forEach(((o,r)=>{e&&!Object.keys(e).every((t=>o[t]===e[t]))||!(i||this.isEntityEnabled(r)&&this.isComponentEnabled(r,t))||s.push({entity:r,component:o})})),s}searchEntitiesByComponents(t){const e=[];let i=!0;for(const s of t){const t=this.getComponentTypeId(s);if(!t||!this.components.has(t))return[];if(i){e.push(...this.components.get(t).keys()),i=!1;continue}const o=new Set(this.components.get(t).keys());e.forEach(((t,i)=>{o.has(t)||e.splice(i,1)}))}return e}getComponentTypeId(t){const e="object"==typeof t?t.constructor.prototype:t.prototype;return void 0===e.__ecs_type_id&&(e.__ecs_type_id=++this.lastComponentTypeId),e.__ecs_type_id}},exports.EntityManager=r([i(t.EntityManager)],exports.EntityManager),exports.SystemManager=class{constructor(){this.systems=[]}findSystemIndex(t){return this.systems.findIndex((e=>e[0]instanceof t))}addSystem(t,e){if(this.systems.some((t=>t[0]instanceof t.constructor)))throw new Error(`SystemManager already has an instance of ${t.constructor.name}.`);this.systems.push([t,e,!1,!1])}hasSystem(t){return this.systems.some((e=>e[0]instanceof t))}getSystem(t){const e=this.findSystemIndex(t);return-1!==e?this.systems[e][0]:void 0}enableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!0===this.systems[e][2])return;const i=this.systems[e];!1===i[3]&&(i[3]=!0,i[0].onCreate&&i[0].onCreate()),i[2]=!0,i[0].onEnabled&&i[0].onEnabled()}disableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!1===this.systems[e][2])return;const i=this.systems[e];i[2]=!1,i[0].onDisabled&&i[0].onDisabled()}setExecutionOrder(t,e){const i=this.findSystemIndex(t);if(-1===i)throw new Error(`Cannot set execution order because ${t.name} is not a system.`);this.systems.splice(e,0,this.systems.splice(i,1)[0])}removeSystem(t){const e=this.findSystemIndex(t);if(-1===e)return;const i=this.systems.splice(e,1)[0][0];i.onDestroy&&i.onDestroy()}update(t){this.systems.filter((e=>e[1]===t&&!0===e[2])).forEach((t=>t[0].onUpdate()))}},exports.SystemManager=r([i(t.SystemManager)],exports.SystemManager);class R{constructor(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new n,this._leftStickAxes=new n,this._rightStickAxes=new n}get dpadAxes(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes}get leftStickAxes(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes}get rightStickAxes(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes}get dpadUp(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t}get dpadDown(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t}get dpadLeft(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t}get dpadRight(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t}get bottomFace(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t}get rightFace(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t}get leftFace(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t}get topFace(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t}get leftShoulder(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t}get rightShoulder(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t}get leftTrigger(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t}get rightTrigger(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t}get back(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t}get start(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t}get leftStickButton(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t}get rightStickButton(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t}get leftStickHorizontal(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0}get leftStickVertical(){var t;return-(null!==(t=this.axes.get(1))&&void 0!==t?t:0)}get rightStickHorizontal(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0}get rightStickVertical(){var t;return-(null!==(t=this.axes.get(3))&&void 0!==t?t:0)}get anyButtonPressed(){var t;return null!==(t=Array.from(this.buttons.values()).find((t=>t)))&&void 0!==t&&t}vibrate(t=200,e=.2,i=.2,s=0){this.vibrationInput={duration:t,weakMagnitude:e,startDelay:s,strongMagnitude:i}}}class _{constructor(){this.pressedKeys=[]}isPressed(t){return this.pressedKeys.includes(t)}orPressed(t){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)}andPressed(t){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)}isPressedReturn(t,e,i){return this.pressedKeys.includes(t)?e:i}orPressedReturn(t,e,i){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)?e:i}andPressedReturn(t,e,i){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)?e:i}}class A{constructor(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new n,this.hasMoved=!1,this.wheelScroll=new n}}class T{constructor(){this.touching=!1,this.interactions=[]}}exports.InputManager=class{constructor(){this.keyboard=new _,this.mouse=new A,this.touchScreen=new T,this.gamepads=[]}},exports.InputManager=r([i(t.InputManager)],exports.InputManager);const B=[60,120,180,240];var D;exports.TimeManager=class{get deltaTime(){return this.unscaledDeltaTime*this.timeScale}get physicsDeltaTime(){return this.unscaledPhysicsDeltaTime*this.timeScale}get renderDeltaTime(){return this.browserDeltaTime*this.timeScale}constructor({physicsFramerate:t}){if(this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForRender=0,t&&!B.includes(t))throw new Error(`Invalid Physics frame rate. Allowed: [${B.join(", ")}]`);this.fixedGameFramerate=60,this.fixedGameDeltaTime=parseFloat((1/this.fixedGameFramerate).toFixed(6)),this.fixedPhysicsFramerate=null!=t?t:180,this.fixedPhysicsDeltaTime=parseFloat((1/this.fixedPhysicsFramerate).toFixed(6))}updateForRender(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForRender),this.maxDeltaTime),this.thenForRender=t}updateForGame(t){this.unscaledDeltaTime=Math.min(Math.max(this.fixedGameDeltaTime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t}updateForPhysics(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t}},exports.TimeManager=r([i(t.TimeManager),a(0,s(t.GameConfig))],exports.TimeManager),function(t){t[t.Image=0]="Image",t[t.Audio=1]="Audio",t[t.Font=2]="Font",t[t.Video=3]="Video"}(D||(D={})),exports.AssetManager=class{constructor(){this.assets=[]}getAssetsLoaded(){return this.assets.reduce(((t,e)=>t&&e.loaded),!0)}loadImage(t){const e=new Image;e.crossOrigin="",e.src=t;const i=this.createAsset(t,D.Image,e),s=()=>i.loaded=!0;return e.complete?s():e.addEventListener("load",s),e}loadAudio(t){const e=new Audio;e.src=t;const i=this.createAsset(t,D.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(()=>i.loaded=!0)),e}loadFont(t,e){const i=new FontFace(t,`url(${e})`),s=this.createAsset(e,D.Font,i);return s.family=t,document.fonts.add(i),i.load().then((()=>s.loaded=!0)),i}loadVideo(t){const e=document.createElement("video");e.playsInline=!0,e.src=t;const i=this.createAsset(t,D.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(()=>i.loaded=!0)),e}getImage(t){var e;return null===(e=this.assets.find((e=>e.type===D.Image&&e.url===t)))||void 0===e?void 0:e.element}getAudio(t){var e;return null===(e=this.assets.find((e=>e.type===D.Audio&&e.url===t)))||void 0===e?void 0:e.element}getFont(t){var e;return null===(e=this.assets.find((e=>e.type===D.Font&&e.family===t)))||void 0===e?void 0:e.element}getVideo(t){var e;return null===(e=this.assets.find((e=>e.type===D.Video&&e.url===t)))||void 0===e?void 0:e.element}createAsset(t,e,i){const s={type:e,url:t,element:i,loaded:!1};return this.assets.push(s),s}},exports.AssetManager=r([i(t.AssetManager)],exports.AssetManager);class P{constructor(t){this.action="stop",this.loop=!1,this.playing=!1,this.volume=1,this._currentAudio=void 0,Object.assign(this,t)}}const U={AudioPlayerSystem:Symbol.for("AudioPlayerSystem"),ButtonSystem:Symbol.for("ButtonSystem"),ChildrenSystem:Symbol.for("ChildrenSystem"),ParentSystem:Symbol.for("ParentSystem"),TiledWrapperSystem:Symbol.for("TiledWrapperSystem"),TilemapPreProcessingSystem:Symbol.for("TilemapPreProcessingSystem"),TransformSystem:Symbol.for("TransformSystem"),GamepadSystem:Symbol.for("GamepadSystem"),KeyboardSystem:Symbol.for("KeyboardSystem"),MouseSystem:Symbol.for("MouseSystem"),TouchScreenSystem:Symbol.for("TouchScreenSystem"),UpdateBallColliderShapeSystem:Symbol.for("UpdateBallColliderShapeSystem"),UpdateBoxColliderShapeSystem:Symbol.for("UpdateBoxColliderShapeSystem"),UpdateEdgeColliderShapeSystem:Symbol.for("UpdateEdgeColliderShapeSystem"),UpdatePolygonColliderShapeSystem:Symbol.for("UpdatePolygonColliderShapeSystem"),UpdateTilemapColliderShapeSystem:Symbol.for("UpdateTilemapColliderShapeSystem"),UpdateCollidersAfterRepositionSystem:Symbol.for("UpdateCollidersAfterRepositionSystem"),ApplyRepositionSystem:Symbol.for("ApplyRepositionSystem"),ApplyVelocitySystem:Symbol.for("ApplyVelocitySystem"),ResolveCollisionSystem:Symbol.for("ResolveCollisionSystem"),AnimatorSystem:Symbol.for("AnimatorSystem"),CameraSystem:Symbol.for("CameraSystem"),ClearScreenSystem:Symbol.for("ClearScreenSystem"),ColliderRenderSystem:Symbol.for("ColliderRenderSystem"),CullingSystem:Symbol.for("CullingSystem"),MaskRendererSystem:Symbol.for("MaskRendererSystem"),RenderSystem:Symbol.for("RenderSystem"),ShadowLightRendererSystem:Symbol.for("ShadowLightRendererSystem"),SpriteRendererSystem:Symbol.for("SpriteRendererSystem"),TextRendererSystem:Symbol.for("TextRendererSystem"),TilemapRendererSystem:Symbol.for("TilemapRendererSystem"),VideoRendererSystem:Symbol.for("VideoRendererSystem")},F=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let L=class{constructor(t,e,i){this.entityManager=t,this.inputManager=e,this.timeManager=i,this.canPlay=!1,this.userInputEventHandler=()=>{F.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,F.forEach((t=>window.addEventListener(t,this.userInputEventHandler))),document.addEventListener("visibilitychange",(()=>{this.entityManager.search(P).forEach((({component:{audioSource:t,playing:e}})=>{document.hidden&&t?t.pause():!document.hidden&&t&&e&&t.play()}))}))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(P).forEach((({component:t})=>{t.audioSource&&t.audioSource.duration&&(t.audioSource.loop=t.loop,t.audioSource.volume=t.volume,t.audioSource.src!==t._currentAudio&&(t._currentAudio=t.audioSource.src,t.playing=!1,t.audioSource.currentTime=0),"play"!==t.action||t.playing?"pause"===t.action&&t.playing?(t.audioSource.pause(),t.playing=!1):"stop"!==t.action||t.audioSource.paused&&0===t.audioSource.currentTime?t.playing&&t.audioSource.paused&&(t.action="stop",t.playing=!1):(t.audioSource.pause(),t.audioSource.currentTime=0,t.playing=!1):(t.audioSource.playbackRate=this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16),t.audioSource.play().then((()=>t.playing=!0)).catch((()=>{}))))}))}onDisable(){this.entityManager.search(P).forEach((({component:{audioSource:t}})=>{t&&(t.pause(),t.currentTime=0)}))}onDestroy(){this.onDisable()}};var I;L=r([i(U.AudioPlayerSystem),a(0,s(t.EntityManager)),a(1,s(t.InputManager)),a(2,s(t.TimeManager))],L),function(t){t[t.GameLogic=0]="GameLogic",t[t.GamePhysics=1]="GamePhysics",t[t.GamePreRender=2]="GamePreRender",t[t.Physics=3]="Physics",t[t.PostGameLogic=4]="PostGameLogic",t[t.PreGameLogic=5]="PreGameLogic",t[t.Render=6]="Render"}(I||(I={}));const j=(t,e)=>{t.prototype.__system_group||(t.prototype.__system_group=e)};class k{get parent(){return this._parent}set parent(t){this._parent!==t&&(this._parent=t,this._parent?(this.localPosition.copy(this.position),n.subtract(this.position,this.position,this._parent.position)):this.position.copy(this.localPosition))}constructor(t){this.position=new n,this.scale=new n(1,1),this.rotation=0,this.localPosition=new n,this.localScale=new n(1,1),this.localRotation=0,this._childEntities=[],this._parent=void 0,t&&t.parent&&(this.position=t.parent.position.clone(),this.parent=t.parent,delete t.parent),Object.assign(this,t)}}const O="Default";class V{constructor(t){this.layers=[O],this.zoom=1,this.depth=0,this._renderData={position:new n,depth:0,zoom:1,layers:[]},Object.assign(this,t)}}var G;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(G||(G={}));class W{constructor(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)}getContextVersion(){return null!==this.canvas.getContext(G.WebGL2)?G.WebGL2:null!==this.canvas.getContext(G.LegacyWebGL)?G.LegacyWebGL:void 0}}class z{constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(this.symbol(t))}getFontAtlas(t){return this.fontAtlas.get(this.symbol(t))}getOrCreate(t,e,i){var s;return null!==(s=this.getFontAtlas(e))&&void 0!==s?s:this.create(t,e,i)}create(t,e,i){this.bitmapSize=i,this.chars=[];for(let e=0;e<t.length;e+=2)for(let i=t[e];i<=t[e+1];i++)this.chars.push(String.fromCharCode(i));const s=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),s),s}symbol(t){return Symbol.for(t instanceof FontFace?t.family:t)}renderAtlas(t){const e=new H(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=`${this.bitmapSize}px ${t}`;let s=0,o=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],s,o),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(s+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(s=0,o+=this.bitmapSize);return e}}class H{constructor(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}}class N{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),s=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,s),this.gl.attachShader(i,o),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class Y{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===G.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nout vec2 texCoords;\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\nin vec2 texCoords;\n\n// texture, mask and shadow\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[64];\nuniform int u_numLights;\n\nout vec4 fragColor;\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 if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < u_numLights; i++) {\n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n fragColor = vec4(u_solidColor.rgb, alpha);\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\n// texture, mask and shadow\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[10];\nuniform int u_numLights;\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 if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < u_numLights; i++) {\n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n gl_FragColor = vec4(u_solidColor.rgb, alpha);\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.renderLightUniform=this.gl.getUniformLocation(this.program,"u_renderLight"),this.numLightsUniform=this.gl.getUniformLocation(this.program,"u_numLights"),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)}}class X{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const s=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,s)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var $="undefined"!=typeof Float32Array?Float32Array:Array;function K(){var t=new $(16);return $!=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 q(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 Q(t,e,i){var s,o,r,a,n,h,l,c,d,p,m,g,u=i[0],y=i[1],x=i[2];return e===t?(t[12]=e[0]*u+e[4]*y+e[8]*x+e[12],t[13]=e[1]*u+e[5]*y+e[9]*x+e[13],t[14]=e[2]*u+e[6]*y+e[10]*x+e[14],t[15]=e[3]*u+e[7]*y+e[11]*x+e[15]):(s=e[0],o=e[1],r=e[2],a=e[3],n=e[4],h=e[5],l=e[6],c=e[7],d=e[8],p=e[9],m=e[10],g=e[11],t[0]=s,t[1]=o,t[2]=r,t[3]=a,t[4]=n,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=p,t[10]=m,t[11]=g,t[12]=s*u+n*y+d*x+e[12],t[13]=o*u+h*y+p*x+e[13],t[14]=r*u+l*y+m*x+e[14],t[15]=a*u+c*y+g*x+e[15]),t}function J(t,e,i){var s=i[0],o=i[1],r=i[2];return t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s,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 Z(t,e,i){var s=Math.sin(i),o=Math.cos(i),r=e[0],a=e[1],n=e[2],h=e[3],l=e[4],c=e[5],d=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+l*s,t[1]=a*o+c*s,t[2]=n*o+d*s,t[3]=h*o+p*s,t[4]=l*o-r*s,t[5]=c*o-a*s,t[6]=d*o-n*s,t[7]=p*o-h*s,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var tt=function(t,e,i,s,o,r,a){var n=1/(e-i),h=1/(s-o),l=1/(r-a);return t[0]=-2*n,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]=2*l,t[11]=0,t[12]=(e+i)*n,t[13]=(o+s)*h,t[14]=(a+r)*l,t[15]=1,t};const et=(t,e,i,s)=>{t=q(t),tt(t,-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),J(t,t,[null!=i?i:1,null!=i?i:1,1]),Q(t,t,[-s.x,-s.y,0])},it=t=>{const 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};class st{constructor(t){this.gl=t}render(t){const e=it(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var ot,rt,at;!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(ot||(ot={}));class nt{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(d(1,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e){switch(t.shape){case ot.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP);break;case ot.Line:this.renderLines(t,e,this.gl.LINES);break;case ot.Circumference:this.renderCircumference(t,e);break;default:return!1}return!0}renderLines(t,e,i){var s;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertexModel.reduce(((t,e)=>[...t,e.x,e.y]),[])),this.gl.DYNAMIC_DRAW),this.modelMatrix=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),et(this.projectionMatrix,this.gl,e.zoom,e.position),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);const{r:o,g:r,b:a,a:n}=it(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,a,n),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,t.vertexModel.length)}renderCircumference(t,e){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),J(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),et(this.projectionMatrix,this.gl,e.zoom,e.position),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);const{r:i,g:s,b:o,a:r}=it(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,s,o,r),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}!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",t[t.Shadow=6]="Shadow"}(rt||(rt={})),exports.MaskShape=void 0,(at=exports.MaskShape||(exports.MaskShape={}))[at.Rectangle=0]="Rectangle",at[at.Circumference=1]="Circumference";let ht=class{constructor(t,e){this.gl=t,this.programManager=e,this.type=rt.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K();const i=2*Math.PI/60,s=[0,0];for(let t=0;t<=60;t++)s.push(Math.cos(t*i),Math.sin(t*i));this.circumferenceVertices=new Float32Array(s)}render(t,e,i){var s,o;i===rt.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===exports.MaskShape.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),J(this.modelMatrix,this.modelMatrix,t.shape===exports.MaskShape.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),et(this.projectionMatrix,this.gl,e.zoom,e.position),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.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:a,b:n,a:h}=it(t.color);return this.gl.uniform4f(this.programManager.solidColorUniform,r,a,n,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),t.shape===exports.MaskShape.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape,!0}},lt=class{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K()}render(t,e){var i,s;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=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(i=t.rotation)&&void 0!==i?i:0),J(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),et(this.projectionMatrix,this.gl,e.zoom,e.position),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),this.gl.uniform1i(this.programManager.renderTextureUniform,0),this.gl.uniform1i(this.programManager.renderLightUniform,1);const{r:o,g:r,b:a,a:n}=it(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,a,n),this.gl.uniform1f(this.programManager.alphaUniform,null!==(s=t.opacity)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.numLightsUniform,t.lights.length);for(const[i,s]of t.lights.entries()){if(i>=64)break;this.gl.uniform2f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].position`),this.gl.canvas.width/2+(s.position.x-e.position.x)*e.zoom,this.gl.canvas.height/2+(s.position.y-e.position.y)*e.zoom),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].radius`),s.radius*e.zoom),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].smoothMode`),s.smooth?1:0),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].intensity`),Math.max(0,Math.min(1,s.intensity)))}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.gl.uniform1i(this.programManager.renderLightUniform,0),!0}},ct=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K(),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])}render(t,e,i){var s,o,r,a;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=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),J(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontally?-1:1),t.height*(t.flipVertically?-1:1),1]),this.textureMatrix=q(this.textureMatrix),t.slice&&(Q(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),J(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),et(this.projectionMatrix,this.gl,e.zoom,e.position),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);const n=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===n&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=it(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=it(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};var dt;exports.TextOrientation=void 0,(dt=exports.TextOrientation||(exports.TextOrientation={}))[dt.Center=0]="Center",dt[dt.RightUp=1]="RightUp",dt[dt.RightDown=2]="RightDown",dt[dt.RightCenter=3]="RightCenter";let pt=class{constructor(t,e,i,s){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=s,this.type=rt.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new n,this.modelPosition=new n,this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K()}render(t,e,i){var s;if(!t.text)return!1;const 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=q(this.modelMatrix),this.setPositionFromOrientation(t),Q(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),J(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=q(this.textureMatrix),et(this.projectionMatrix,this.gl,e.zoom,e.position),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.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);const r=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+o.fontFaceFamily,o.canvas,t.smooth);this.lastTexture===r&&i===rt.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.opacity);const{r:a,g:n,b:h,a:l}=it(t.color);return this.gl.uniform4f(this.programManager.maskColorUniform,a,n,h,l),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),!0}generateTextVertices(t,{text:e,fontSize:i,bitmap:s,letterSpacing:o,lineSeparation:r}){this.posVertices=[],this.texVertices=[];let a=0,n=0,h=0;o/=i,r/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,a),a=0,n-=1+r;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(a,n-1,a+e,n-1,a,n,a,n,a+e,n-1,a+e,n);const i=c.id%t.gridSize*t.bitmapFontSize,r=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+s.margin.x)/t.canvas.width,l=(r+s.margin.y)/t.canvas.width,d=(i+c.width+s.spacing.x)/t.canvas.width,p=(r+t.bitmapFontSize+s.spacing.y)/t.canvas.width;this.texVertices.push(h,p,d,p,h,l,h,l,d,p,d,l),a+=e+o}}this.textSize.set(Math.max(h,a)*i,Math.abs(n-1)*i)}setPositionFromOrientation(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))}};var mt;exports.TilemapOrientation=void 0,(mt=exports.TilemapOrientation||(exports.TilemapOrientation={}))[mt.Center=0]="Center",mt[mt.RightUp=1]="RightUp",mt[mt.RightDown=2]="RightDown",mt[mt.RightCenter=3]="RightCenter";let gt=class{constructor(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 n,texSpacing:new n,texWidth:0,texHeight:0,texCorrection:new n},this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K()}render(t,e,i){var s,o,r,a;if(0===t.tiles.reduce(((t,e)=>t+e),0))return!1;if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)return!1;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=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),J(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=q(this.textureMatrix),J(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),et(this.projectionMatrix,this.gl,e.zoom,e.position),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);const n=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===n&&i===rt.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=it(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=it(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}processTileset({tileset:t}){var e,i,s,o,r,a,h;t.margin=null!==(e=t.margin)&&void 0!==e?e:new n,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new n,t.correction=null!==(s=t.correction)&&void 0!==s?s:new n,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(o=t.margin.x)&&void 0!==o?o:0)+(null!==(r=t.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=t.tileHeight+(null!==(a=t.margin.y)&&void 0!==a?a:0)+(null!==(h=t.spacing.y)&&void 0!==h?h:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.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}generateVertices({tiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,s)=>{if(0===t)return;const o=s%e.width-e.width/2,r=i/2-Math.floor(s/e.width);this.posVertices.push(o,r-1,o+1,r-1,o,r,o,r,o+1,r-1,o+1,r);const a=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,n=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(a,n+this.tileset.texHeight,a+this.tileset.texWidth,n+this.tileset.texHeight,a,n,a,n,a+this.tileset.texWidth,n+this.tileset.texHeight,a+this.tileset.texWidth,n)}))}},ut=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=K(),this.modelMatrix=K(),this.textureMatrix=K(),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])}render(t,e,i){var s,o,r,a;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=q(this.modelMatrix),Q(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),J(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=q(this.textureMatrix),t.slice&&(Q(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),J(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),et(this.projectionMatrix,this.gl,e.zoom,e.position),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);const n=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===n&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),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.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=it(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=it(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};class yt{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(()=>this.createFromSource(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i}createPixelTexture(){const 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}createFromSource(t,e,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)}}class xt{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!0){var i;return null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!0){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i}getOrCreateTextureFromCanvas(t,e,i=!0){var s;return null!==(s=this.textures.get(Symbol.for(t)))&&void 0!==s?s:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const s=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),s),s}getOrCreateTextureFromVideo(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)}createTextureFromVideo(t){const e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e}}let ft=class{constructor(t){this.renderers=new Map;const e=new W(t),i=e.gl,s=e.contextVersion,o=new Y(i,s,new N(i,new X(i))),r=new xt(new yt(i)),a=new z;this.renderers.set(rt.Sprite,new ct(i,o,r)),this.renderers.set(rt.Text,new pt(i,o,r,a)),this.renderers.set(rt.Tilemap,new gt(i,o,r)),this.renderers.set(rt.Geometric,new nt(i,o)),this.renderers.set(rt.Mask,new ht(i,o)),this.renderers.set(rt.Video,new ut(i,o,r)),this.renderers.set(rt.Shadow,new lt(i,o)),this.canvasColorRenderer=new st(i),o.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender)&&(this.lastRender=t.type)}renderCanvasColor(t){this.canvasColorRenderer.render(t)}};ft=r([i(t.WebGLManager),a(0,s(t.CanvasElement))],ft);class Mt{constructor(t){this.offset=new n,this.rotation=0,this.layer=O,this.loop=!1,this.volume=1,this.play=!1,this.pause=!1,this._renderData={type:rt.Video,height:void 0,layer:void 0,position:new n,video:void 0,width:void 0,flipHorizontal:void 0,flipVertical:void 0,maskColor:void 0,maskColorMix:void 0,opacity:void 0,rotation:void 0,slice:void 0,tintColor:void 0},Object.assign(this,t)}}const vt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let St=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.timeManager=i,this.scaledOffset=new n,this.userInputEventHandler=()=>{vt.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,vt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}onUpdate(){this.entityManager.search(Mt).forEach((({entity:t,component:e})=>{var i,s;const o=this.entityManager.getComponent(t,k);if(!o)throw new Error("VideoRenderer component needs a Transform");e.video&&e.video.duration&&(this.checkVideoState(e),this.scaledOffset.set(e.offset.x*o.localScale.x,e.offset.y*o.localScale.y),n.add(e._renderData.position,o.localPosition,this.scaledOffset),e._renderData.layer=e.layer,e._renderData.video=e.video,e._renderData.width=(null!==(i=e.width)&&void 0!==i?i:e.video.videoWidth)*Math.abs(o.localScale.x),e._renderData.height=(null!==(s=e.height)&&void 0!==s?s:e.video.videoHeight)*Math.abs(o.localScale.y),e._renderData.rotation=o.localRotation+e.rotation,e._renderData.slice=e.slice,e._renderData.flipHorizontal=e.flipHorizontally,e._renderData.flipVertical=e.flipVertically,e._renderData.opacity=e.opacity,e._renderData.maskColor=e.maskColor,e._renderData.maskColorMix=e.maskColorMix,e._renderData.tintColor=e.tintColor,0!==o.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,o),this.renderManager.addRenderData(e._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}checkVideoState(t){const{video:e,play:i,pause:s,loop:o,volume:r}=t;e.loop=o,e.volume=r,e.playbackRate=this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16),i&&e.ended&&(t.play=!1),i&&e.paused&&this.canPlay&&e.play(),!i&&e.currentTime>0&&(e.pause(),e.currentTime=0),s&&!e.paused&&e.pause(),!s&&e.paused&&i&&this.canPlay&&e.play()}onDisable(){this.entityManager.search(Mt).forEach((({component:t})=>{t.video&&(t.video.pause(),t.video.currentTime=0)}))}onDestroy(){this.onDisable()}};St=r([i(U.VideoRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager)),a(2,s(t.TimeManager))],St);exports.SceneManager=class{constructor(t,e,i,s){this.systemManager=t,this.systemFactory=e,this.entityManager=i,this.assetManager=s,this.scenes=new Map,this.loadingScene=!1}addScene(t,e,i=!1){const s=new t(this.entityManager,this.assetManager);this.scenes.set(e,s),i&&(this.openingSceneName=e)}loadScene(t){if(!this.scenes.has(t))throw new Error(`Invalid scene name: '${t}'`);this.sceneNameToBeLoaded=t}loadOpeningScene(){if(!this.openingSceneName)throw new Error("There is no opening scene");this.sceneNameToBeLoaded=this.openingSceneName}update(){this.sceneNameToBeLoaded&&(this.currentSceneName&&this.destroyCurrentScene(),this.currentSceneName=this.sceneNameToBeLoaded,this.sceneNameToBeLoaded=void 0,this.scenes.get(this.currentSceneName).loadAssets(),this.loadingScene=!0),this.loadingScene&&this.assetManager.getAssetsLoaded()&&(this.loadingScene=!1,this.scenes.get(this.currentSceneName).setup(),this.systemManager.update(I.PostGameLogic),this.scenes.get(this.currentSceneName).systems.forEach(((t,e)=>{this.systemFactory.createSystemIfNotExists(t),this.systemManager.enableSystem(t),this.systemManager.setExecutionOrder(t,e)})))}destroyCurrentScene(){this.systemManager.disableSystem(L),this.systemManager.disableSystem(St),this.entityManager.removeAllEntities(),this.scenes.get(this.currentSceneName).systems.forEach((t=>this.systemManager.disableSystem(t))),this.systemManager.enableSystem(L),this.systemManager.enableSystem(St)}},exports.SceneManager=r([i(t.SceneManager),a(0,s(t.SystemManager)),a(1,s(t.SystemFactory)),a(2,s(t.EntityManager)),a(3,s(t.AssetManager))],exports.SceneManager);class Ct{constructor(t){this.width=0,this.height=0,this.radius=0,this.touchEnabled=!0,this.offset=new n,this.pressed=!1,Object.assign(this,t)}}var bt;exports.ButtonShape=void 0,(bt=exports.ButtonShape||(exports.ButtonShape={}))[bt.Rectangle=0]="Rectangle",bt[bt.Circumference=1]="Circumference";let wt=class{constructor(t,e){this.entityManager=t,this.scaled={position:new n,width:0,height:0,radius:0},this.distance=new n,this.pressedLastFrame=!1,this.mouse=e.mouse,this.touchScreen=e.touchScreen}onUpdate(){this.entityManager.search(Ct).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("Button component needs a Transform");this.pressedLastFrame=e.pressed,e.pressed=!1,this.scale(e,i),this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(e),this.resolveMouseAndCircumference(e)),e.touchEnabled&&this.touchScreen.touching&&(this.resolveTouchAndRectangle(e),this.resolveTouchAndCircumference(e)),e.onClick&&!this.pressedLastFrame&&e.pressed&&e.onClick(),e.onPressed&&e.pressed&&e.onPressed()}))}scale(t,{localPosition:e,localScale:i}){this.scaled.width=t.width*i.x,this.scaled.height=t.width*i.y,this.scaled.position.x=e.x+t.offset.x*i.x,this.scaled.position.y=e.y+t.offset.y*i.y,this.scaled.radius=t.radius*Math.max(Math.abs(i.x),Math.abs(i.y))}resolveMouseAndRectangle(t){t.shape===exports.ButtonShape.Rectangle&&(t.pressed=p(this.mouse.positionInViewport.x,this.scaled.position.x-this.scaled.width/2,this.scaled.position.x+this.scaled.width/2)&&p(this.mouse.positionInViewport.y,this.scaled.position.y-this.scaled.height/2,this.scaled.position.y+this.scaled.height/2))}resolveMouseAndCircumference(t){t.shape===exports.ButtonShape.Circumference&&(n.subtract(this.distance,this.scaled.position,this.mouse.positionInViewport),t.pressed=this.distance.magnitude<=this.scaled.radius)}resolveTouchAndRectangle(t){if(t.shape===exports.ButtonShape.Rectangle)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;t.pressed=this.scaled.position.x+this.scaled.width/2>=e.x-i.x&&this.scaled.position.x-this.scaled.width/2<=e.x+i.x&&this.scaled.position.y+this.scaled.height/2>=e.y-i.y&&this.scaled.position.y-this.scaled.height/2<=e.y+i.y}}resolveTouchAndCircumference(t){if(t.shape===exports.ButtonShape.Circumference)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;n.subtract(this.distance,this.scaled.position,e),t.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(i.x,i.y)}}};wt=r([i(U.ButtonSystem),a(0,s(t.EntityManager)),a(1,s(t.InputManager))],wt);class Et{constructor(){this.entities=[]}}let Rt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Et).forEach((({entity:t,component:e})=>{e.entities=this.entityManager.getComponent(t,k)._childEntities}))}};Rt=r([i(U.ChildrenSystem),a(0,s(t.EntityManager))],Rt);class _t{}let At=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(_t).forEach((({entity:t,component:e})=>{e.entity=this.entityManager.getComponent(t,k)._parentEntity}))}};At=r([i(U.ParentSystem),a(0,s(t.EntityManager))],At);class Tt{constructor(t){Object.assign(this,t)}}class Bt{constructor(t){this.layer=O,this.tileset=void 0,this.data=[],this.chunks=[],this.width=0,this.height=0,this.tileWidth=void 0,this.tileHeight=void 0,this.tintColor=void 0,this.opacity=1,this.smooth=!1,this._processed=!1,this._renderData=[],Object.assign(this,t)}}let Dt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Tt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,Bt);if(!i)return;const s=e.tilemap.layers.find((t=>t.name===e.layerToRender&&"tilelayer"===t.type));s&&(e.tilemap.infinite?i.chunks=s.chunks:i.data=s.data,i.width=e.tilemap.width)}))}};Dt=r([i(U.TiledWrapperSystem),a(0,s(t.EntityManager))],Dt);const Pt=16;let Ut=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Bt).forEach((({component:t})=>{var e,i;t._processed||(t.chunks&&t.chunks.length>0?this.chunksToData(t):t.data&&t.data.length>0&&this.dataToChunks(t),t.tileWidth=null!==(e=t.tileWidth)&&void 0!==e?e:t.tileset.tileWidth,t.tileHeight=null!==(i=t.tileHeight)&&void 0!==i?i:t.tileset.tileHeight,t._processed=!0)}))}dataToChunks(t){t.height=Math.ceil(t.data.length/t.width);const e=Math.ceil(t.width/Pt),i=Math.ceil(t.height/Pt);for(let s=0;s<i;s++)for(let i=0;i<e;i++){const e={x:i*Pt,y:s*Pt,width:Pt,height:Pt,data:[]};for(let i=0;i<e.width*e.height;i++){const s=e.x+i%e.width,o=t.width*(e.y+Math.floor(i/e.width));e.data[i]=s<t.width&&o<t.height*t.width?t.data[o+s]:0}t.chunks.push(e)}}chunksToData(t){t.data=[],t.chunks.forEach((e=>e.data.forEach(((i,s)=>{t.data[t.width*(e.y+Math.floor(s/e.width))+e.x+s%e.width]=i})))),t.height=Math.ceil(t.data.length/t.width)}};Ut=r([i(U.TilemapPreProcessingSystem),a(0,s(t.EntityManager))],Ut);const Ft=t=>t.parent?1+Ft(t.parent):0;let Lt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(k).sort(((t,e)=>Ft(t.component)-Ft(e.component))).forEach((({component:t,entity:e})=>{t.parent&&this.entityManager.getEntityForComponent(t.parent)?(t._childEntities=[],t._parentEntity=this.entityManager.getEntityForComponent(t.parent),t.parent._childEntities.push(e),this.translateChild(t.parent,t)):this.updateTransform(t)}))}updateTransform(t){t.parent=void 0,t._parentEntity=void 0,t._childEntities=[],t.localPosition.copy(t.position),t.localScale.copy(t.scale),t.localRotation=t.rotation}translateChild(t,e){e.localRotation=e.rotation+t.localRotation,e.localScale.x=e.scale.x*t.scale.x,e.localScale.y=e.scale.y*t.scale.y;const i=Math.atan2(e.position.y,e.position.x)+t.localRotation;e.localPosition.set(t.localPosition.x+e.position.magnitude*Math.cos(i),t.localPosition.y+e.position.magnitude*Math.sin(i))}};Lt=r([i(U.TransformSystem),a(0,s(t.EntityManager))],Lt);let It=class{constructor(t){this.inputManager=t,this.gamepads=new Map,this.eventHandler=t=>{"gamepadconnected"===t.type?this.gamepadConnected(t.gamepad):"gamepaddisconnected"===t.type&&this.gamepadDisconected(t.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}gamepadConnected(t){this.gamepads.set(t.index,t),this.inputManager.gamepads[t.index]||(this.inputManager.gamepads[t.index]=new R,this.inputManager.gamepads[t.index].index=t.index),this.inputManager.gamepads[t.index].id=t.id,this.inputManager.gamepads[t.index].connected=!0}gamepadDisconected(t){this.gamepads.delete(t.index),this.inputManager.gamepads[t.index].connected=!1}onUpdate(){for(const t of this.getGamepadsFromBrowser())t&&(!1===this.gamepads.has(t.index)?this.gamepadConnected(t):this.gamepads.set(t.index,t));this.gamepads.forEach((t=>{const e=this.inputManager.gamepads[t.index];t.buttons.forEach(((t,i)=>e.buttons.set(i,t.pressed))),t.axes.forEach(((t,i)=>e.axes.set(i,t))),e.vibrationInput&&(t.vibrationActuator.playEffect(t.vibrationActuator.type,{duration:e.vibrationInput.duration,weakMagnitude:e.vibrationInput.weakMagnitude,strongMagnitude:e.vibrationInput.strongMagnitude,startDelay:e.vibrationInput.startDelay}).catch((()=>e.vibrating=!1)).finally((()=>e.vibrating=!1)),e.vibrating=!0,e.vibrationInput=void 0)}))}getGamepadsFromBrowser(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]}};It=r([i(U.GamepadSystem),a(0,s(t.InputManager))],It);let jt=class{constructor(t,{keyboard:e}){this.pressedKeys=[],this.eventHandler=t=>{"keydown"!==t.type||this.pressedKeys.includes(t.code)||this.pressedKeys.push(t.code),"keyup"===t.type&&this.pressedKeys.includes(t.code)&&this.pressedKeys.splice(this.pressedKeys.indexOf(t.code),1)},this.keyboard=e,t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler),t.addEventListener("focusout",(()=>this.pressedKeys=[]))}onUpdate(){this.keyboard.pressedKeys=[...this.pressedKeys]}};jt=r([i(U.KeyboardSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],jt);let kt=class{constructor(t,{mouse:e}){this.canvas=t,this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new n,this.lastPositionInViewport=new n,this.mouse=e,this.canvas.addEventListener("mousemove",(t=>this.updatePosition(t))),this.canvas.addEventListener("mousedown",(t=>this.updateButtonDown(t))),this.canvas.addEventListener("mouseup",(t=>this.updateButtonUp(t))),this.canvas.addEventListener("wheel",(t=>this.handleWheelEvent(t))),this.canvas.addEventListener("focusout",(()=>this.onFocusOut()))}updateButtonDown(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0===t.button,this.scrollButtonPressed=1===t.button,this.rightButtonPressed=2===t.button}updateButtonUp(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}updatePosition(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)}handleWheelEvent(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t}onFocusOut(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1}onUpdate(){this.mouse.leftButtonPressed=this.leftButtonPressed,this.mouse.rightButtonPressed=this.rightButtonPressed,this.mouse.scrollButtonPressed=this.scrollButtonPressed,this.mouse.positionInViewport.copy(this.positionInViewport),this.positionInViewport.equals(this.lastPositionInViewport)?this.mouse.hasMoved=!1:(this.mouse.hasMoved=!0,this.lastPositionInViewport.copy(this.positionInViewport)),this.wheelEvent?(this.mouse.wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this.mouse.wheelScroll.set(0,0)}};kt=r([i(U.MouseSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],kt);let Ot=class{constructor(t,{touchScreen:e}){this.canvas=t,this.touching=!1,this.interactions=[],this.eventHandler=t=>{"touchstart"===t.type&&(this.touching=!0,this.updatePosition(t)),"touchmove"===t.type&&this.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(this.touching=!1)},this.touchScreen=e,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}updatePosition(t){if(t.preventDefault(),t.stopPropagation(),this.interactions=[],0!==t.targetTouches.length)for(let e=0;e<t.targetTouches.length;e++)this.interactions[e]={positionInViewport:new n((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 n(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}}onUpdate(){this.touchScreen.touching=this.touching,this.touchScreen.interactions=[...this.touchScreen.interactions]}};Ot=r([i(U.TouchScreenSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],Ot);class Vt{constructor(t){this.animations=new Map,this.speed=1,this.reset=!1,this.playing=!1,this.currentFrame=0,this.currentTime=0,this._currentAnimation=void 0,Object.assign(this,t)}}class Gt{constructor(t){this.layer=O,this.smooth=!1,this.offset=new n,this.flipHorizontally=!1,this.flipVertically=!1,this.rotation=0,this.opacity=1,this.scale=new n(1,1),this._renderData={type:rt.Sprite,position:new n,layer:void 0,image:void 0,width:void 0,height:void 0},Object.assign(this,t)}}let Wt=class{constructor(t,e){this.entityManager=t,this.timeManager=e}onUpdate(){this.entityManager.search(Vt).forEach((({entity:t,component:e})=>{if(this.reset(e),this.animation=e.animations.get(e.animation),!this.animation)return;this.play(e),e._currentAnimation=e.animation;const i=this.entityManager.getComponent(t,Gt);i&&this.renderSprite(e,i)}))}reset(t){t.reset&&(t.currentFrame=0,t.currentTime=0,t.playing=void 0!==t.animation,t.reset=!1)}play(t){t.animation!==t._currentAnimation&&(t._currentAnimation=t.animation,t.currentFrame=0,t.currentTime=0,t.playing=!0),t.playing&&(t.currentTime>=1/this.animation.fps*(t.currentFrame+1)&&(t.currentFrame===this.animation.frames.length-1?this.animation.loop?(t.currentFrame=0,t.currentTime=0):t.playing=!1:t.currentFrame++),t.currentTime+=this.timeManager.renderDeltaTime*t.speed)}renderSprite(t,e){if(Array.isArray(this.animation.image))e.image=this.animation.image[t.currentFrame];else{const i=this.animation.frames[t.currentFrame],s=Math.floor(this.animation.image.naturalWidth/this.animation.slice.size.x);e.image=this.animation.image,e.slice={x:i%s*this.animation.slice.size.x+this.animation.slice.offset.x,y:Math.floor(i/s)*this.animation.slice.size.y+this.animation.slice.offset.y,width:this.animation.slice.size.x-this.animation.slice.padding.y,height:this.animation.slice.size.y-this.animation.slice.padding.y}}}};Wt=r([i(U.AnimatorSystem),a(0,s(t.EntityManager)),a(1,s(t.TimeManager))],Wt);let zt=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(V).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("Camera component needs a Transform");e._renderData.position.copy(i.localPosition),e._renderData.layers=e.layers,e._renderData.depth=e.depth,e._renderData.zoom=e.zoom,this.renderManager.addCameraData(e._renderData)}))}};zt=r([i(U.CameraSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],zt);let Ht=class{constructor(t,e){this.webGLManager=t,this.gameConfig=e}onUpdate(){this.webGLManager.renderCanvasColor(this.gameConfig.canvasColor)}};Ht=r([i(U.ClearScreenSystem),a(0,s(t.WebGLManager)),a(1,s(t.GameConfig))],Ht);class Nt{constructor(t){this.radius=0,this.offset=new n,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class Yt{constructor(t){this.layer="",this.physics=!0,this.width=0,this.height=0,this.offset=new n,this.rotation=0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class Xt{constructor(t){this.vertexModel=[],this.offset=new n,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class $t{constructor(t){this.vertexModel=[],this.offset=new n,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class Kt{constructor(t){this.composite=!0,this.layer="",this.ignoreCollisionsWithLayers=[],this.offset=new n,this.physics=!0,this.shapes=[],Object.assign(this,t)}}let qt=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.collisionMethod=i.collisions.collisionMethod,this.debugEnabled=i.debugEnabled}onUpdate(){this.debugEnabled&&[Nt,Yt,$t,Xt,Kt].forEach((t=>this.entityManager.search(t).forEach((({component:t})=>t.shapes.forEach((t=>{const e={type:rt.Geometric,position:new n,layer:O,color:"#00FF00",shape:void 0,radius:void 0,rotation:void 0,vertexModel:void 0};t instanceof x?this.collisionMethod===exports.CollisionMethods.SAT?(e.shape=t.vertices.length>2?ot.Polygon:ot.Line,e.vertexModel=t.vertices):this.collisionMethod===exports.CollisionMethods.AABB&&(e.shape=ot.Polygon,e.vertexModel=[new n(t.boundingBox.x,t.boundingBox.y),new n(t.boundingBox.x,t.boundingBox.y1),new n(t.boundingBox.x1,t.boundingBox.y1),new n(t.boundingBox.x1,t.boundingBox.y)]):t instanceof f&&(e.shape=ot.Circumference,e.position.copy(t.position),e.radius=t.radius),this.renderManager.addRenderData(e)}))))))}};qt=r([i(U.ColliderRenderSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager)),a(2,s(t.GameConfig))],qt);let Qt=class{constructor(t,e){this.renderManager=t,this.canvas=e,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0},this.culledRenderData=[]}onUpdate(){this.culledRenderData=[],this.renderManager.getCameraData().forEach((t=>{this.setViewport(t),this.renderManager.getRenderData().filter((e=>t.layers.includes(e.layer))).forEach((t=>{this.isInViewPort(t)&&(t.type===rt.Tilemap&&this.applyCullingInTiles(t),this.culledRenderData.push(t))}))})),this.renderManager.setRenderData(this.culledRenderData)}isInViewPort(t){switch(t.type){case rt.Video:case rt.Mask:case rt.Shadow:case rt.Sprite:this.setObjectForResizeable(t);break;case rt.Geometric:this.setObjectForGeometric(t);break;case rt.Text:this.setObjectForText(t);break;case rt.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}setViewport({position:t,zoom:e}){this.viewport.x=t.x-this.canvas.width/e/2,this.viewport.x1=t.x+this.canvas.width/e/2,this.viewport.y=t.y-this.canvas.height/e/2,this.viewport.y1=t.y+this.canvas.height/e/2}setObjectForResizeable({position:t,width:e,height:i,rotation:s=0}){const o=Math.abs(Math.sin(s)),r=Math.abs(Math.cos(s)),a=o*i+r*e,n=o*e+r*i;this.object.x=t.x-a/2,this.object.x1=t.x+a/2,this.object.y=t.y-n/2,this.object.y1=t.y+n/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:s,letterSpacing:o,rotation:r}){const a=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=o?o:0))*2,n=e.split("\n").length*(i+(null!=s?s:0));this.setObjectForResizeable({position:t,width:a,height:n,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:s}){i===ot.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):(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,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForTilemap(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.position,width:t.tilemap.width*t.tilemap.tileWidth,height:t.tilemap.height*t.tilemap.tileHeight,rotation:t.rotation})}applyCullingInTiles(t){const{tiles:e,tilemap:{width:i,tileWidth:s,tileHeight:o}}=t;t.tiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*s&&this.viewport.x<=this.object.x+e%i*s+s&&this.viewport.y1>=this.object.y1-((e/i|0)*o+o)&&this.viewport.y<=this.object.y1-(e/i|0)*o?t:0))}};Qt=r([i(U.CullingSystem),a(0,s(t.RenderManager)),a(1,s(t.CanvasElement))],Qt);class Jt{constructor(t){this.width=0,this.height=0,this.radius=0,this.offset=new n,this.rotation=0,this.opacity=1,this.layer=O,this._renderData={type:rt.Mask,color:void 0,height:void 0,layer:void 0,opacity:void 0,position:new n,radius:void 0,rotation:void 0,shape:void 0,width:void 0},Object.assign(this,t)}}let Zt=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(Jt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("MaskRenderer component needs a Transform");this.scaledOffset.set(e.offset.x*i.localScale.x,e.offset.y*i.localScale.y),n.add(e._renderData.position,i.localPosition,this.scaledOffset),e._renderData.width=e.width*Math.abs(i.localScale.x),e._renderData.height=e.height*Math.abs(i.localScale.y),e._renderData.rotation=i.localRotation+e.rotation,e._renderData.color=e.color,e._renderData.layer=e.layer,e._renderData.opacity=e.opacity,e._renderData.radius=e.radius*Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)),e._renderData.shape=e.shape,0!==i.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,i),this.renderManager.addRenderData(e._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Zt=r([i(U.MaskRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],Zt);let te=class{constructor(t){this.renderManager=t}onUpdate(){this.renderManager.render(),this.renderManager.removeCameraData(),this.renderManager.removeRenderData()}};te=r([i(U.RenderSystem),a(0,s(t.RenderManager))],te);class ee{constructor(t){this.radius=0,this.smooth=!1,this.layer="",this.intensity=1,this._boundingBox=new h,Object.assign(this,t)}}class ie{constructor(t){this.width=0,this.height=0,this.color="#000000",this.opacity=1,this.layer="",this._boundingBox=new h,this._renderData={type:rt.Shadow,layer:void 0,color:void 0,opacity:void 0,width:void 0,height:void 0,position:void 0,rotation:void 0,lights:[]},Object.assign(this,t)}}let se=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){const t=this.entityManager.search(ee);t.forEach((({entity:t,component:e})=>this.updateLightRendererBoundingBox(t,e))),this.entityManager.search(ie).forEach((({entity:e,component:i})=>{this.updatShadowRendererBoundingBox(e,i),i._renderData.layer=i.layer,i._renderData.color=i.color,i._renderData.opacity=i.opacity,i._renderData.width=i._boundingBox.width,i._renderData.height=i._boundingBox.height,i._renderData.position=i._boundingBox.center,i._renderData.rotation=0,i._renderData.lights=[],i._renderData.lights=t.filter((({component:t})=>t.layer===i.layer&&t._boundingBox.overlaps(i._boundingBox))).map((({component:{_boundingBox:t,smooth:e,intensity:i}})=>({position:t.center,radius:t.width/2,smooth:e,intensity:i}))),this.renderManager.addRenderData(i._renderData)}))}updateLightRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("LightRenderer component needs a Transform");const s=e.radius*Math.abs(Math.max(i.localScale.x,i.localScale.y));e._boundingBox.set(i.localPosition.x-s,i.localPosition.y-s,2*s,2*s)}updatShadowRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("ShadowRenderer component needs a Transform");const s=e.width*Math.abs(i.localScale.x),o=e.height*Math.abs(i.localScale.y);e._boundingBox.set(i.localPosition.x-s/2,i.localPosition.y-o/2,s,o)}};se=r([i(U.ShadowLightRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],se);let oe=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(Gt).forEach((({component:t,entity:e})=>{var i,s,o,r,a,h;const l=this.entityManager.getComponent(e,k);if(!l)throw new Error("SpriteRenderer component needs a Transform");t.image&&t.image.complete&&(this.scaledOffset.set(t.offset.x*l.localScale.x,t.offset.y*l.localScale.y),n.add(t._renderData.position,l.localPosition,this.scaledOffset),t._renderData.width=(null!==(o=null!==(i=t.width)&&void 0!==i?i:null===(s=t.slice)||void 0===s?void 0:s.width)&&void 0!==o?o:t.image.naturalWidth)*Math.abs(t.scale.x*l.localScale.x),t._renderData.height=(null!==(h=null!==(r=t.height)&&void 0!==r?r:null===(a=t.slice)||void 0===a?void 0:a.height)&&void 0!==h?h:t.image.naturalHeight)*Math.abs(t.scale.y*l.localScale.y),t._renderData.flipHorizontally=t.flipHorizontally!==l.scale.x<0,t._renderData.flipVertically=t.flipVertically!==l.scale.y<0,t._renderData.rotation=l.localRotation+t.rotation,0!==l.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,l),t._renderData.image=t.image,t._renderData.layer=t.layer,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.opacity=t.opacity,t._renderData.slice=t.slice,t._renderData.smooth=t.smooth,t._renderData.tintColor=t.tintColor,this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};oe=r([i(U.SpriteRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],oe);class re{constructor(t){this.layer=O,this.text="Hello World!",this.font="Arial",this.fontSize=16,this.width=160,this.height=16,this.offset=new n,this.color="#000000",this.lineSeparation=0,this.letterSpacing=0,this.charRanges=[32,126,161,255],this.smooth=!1,this.rotation=0,this.opacity=1,this.orientation=exports.TextOrientation.Center,this.bitmapMargin=new n,this.bitmapSpacing=new n,this._renderData={type:rt.Text,position:new n,layer:void 0,text:void 0,color:void 0,font:void 0,fontSize:void 0,opacity:void 0,smooth:void 0,rotation:void 0,orientation:void 0,letterSpacing:void 0,lineSeparation:void 0,bitmap:{charRanges:void 0,fontSize:64,margin:void 0,spacing:void 0}},Object.assign(this,t)}}let ae=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(re).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("TextRenderer component needs a Transform");0===e.text.length||e.font instanceof FontFace&&"loaded"!==e.font.status||(this.scaledOffset.set(e.offset.x*i.localScale.x,e.offset.y*i.localScale.y),n.add(e._renderData.position,i.localPosition,this.scaledOffset),e._renderData.layer=e.layer,e._renderData.font=e.font,e._renderData.fontSize=e.fontSize,e._renderData.text=this.crop(e),e._renderData.orientation=e.orientation,e._renderData.color=e.color,e._renderData.lineSeparation=e.lineSeparation,e._renderData.letterSpacing=e.letterSpacing,e._renderData.smooth=e.smooth,e._renderData.rotation=i.localRotation+e.rotation,e._renderData.opacity=e.opacity,e._renderData.bitmap.charRanges=e.charRanges,e._renderData.bitmap.margin=e.bitmapMargin,e._renderData.bitmap.spacing=e.bitmapSpacing,0!==i.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,i),this.renderManager.addRenderData(e._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}crop({fontSize:t,height:e,text:i,letterSpacing:s,width:o,lineSeparation:r}){if(t>e)return"";const a=[];let n=0;for(const h of i.split("\n")){const i=h.split(/(\s+)/).reduce(((e,i)=>{const r=e.length-1,a=e[r]+i;return a.length*(t+s)>o?e.push(i):e[r]=a,e}),[""]);for(const s of i){if(n+=t+r,n>e)return a.join("\n");a.push(s)}}return a.join("\n")}};ae=r([i(U.TextRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],ae);let ne=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(Bt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,k);if(!i)throw new Error("TilemapRenderer component needs a Transform");e._processed&&e.tileset.image&&e.tileset.image.complete&&e.chunks.forEach(((t,s)=>{e._renderData[s]||(e._renderData[s]=he());const o=e._renderData[s];o.type=rt.Tilemap,o.orientation=exports.TilemapOrientation.Center,o.position=new n,o.layer=e.layer,o.tilemap.width=t.width,o.tilemap.height=Math.ceil(e.data.length/t.width),o.tilemap.tileWidth=e.tileWidth*Math.abs(i.localScale.x),o.tilemap.tileHeight=e.tileHeight*Math.abs(i.localScale.y),o.tilemap.realWidth=o.tilemap.width*o.tilemap.tileWidth,o.tilemap.realHeight=o.tilemap.height*o.tilemap.tileHeight,o.tiles=t.data,o.tileset=e.tileset,o.opacity=e.opacity,o.rotation=i.localRotation,o.tintColor=e.tintColor,o.smooth=e.smooth,o.position.x=i.localPosition.x+(t.x-e.width/2+t.width/2)*o.tilemap.tileWidth,o.position.y=i.localPosition.y+(e.height/2-t.y-t.height/2)*o.tilemap.tileHeight,this.renderManager.addRenderData(o)}))}))}};ne=r([i(U.TilemapRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],ne);const he=()=>({type:rt.Tilemap,layer:void 0,position:new n,tilemap:{height:void 0,realHeight:void 0,realWidth:void 0,tileHeight:void 0,tileWidth:void 0,width:void 0},tiles:void 0,tileset:void 0});var le;exports.RigidBodyType=void 0,(le=exports.RigidBodyType||(exports.RigidBodyType={}))[le.Dynamic=0]="Dynamic",le[le.Static=1]="Static";class ce{constructor(t){this.type=exports.RigidBodyType.Dynamic,this.velocity=new n,this.gravity=0,this.acceleration=new n,Object.assign(this,t)}}let de=class{constructor(t,e,i){this.entityManager=t,this.timeManager=e,this.transformSystem=i,this.distance=new n}onUpdate(){this.entityManager.search(ce,{type:exports.RigidBodyType.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,k);t.velocity.y-=t.gravity*this.timeManager.physicsDeltaTime,n.add(i.position,i.position,n.scale(this.distance,n.add(t.velocity,t.velocity,t.acceleration),this.timeManager.physicsDeltaTime))})),this.transformSystem.onUpdate()}};de=r([i(U.ApplyVelocitySystem),a(0,s(t.EntityManager)),a(1,s(t.TimeManager)),a(2,s(U.TransformSystem))],de);class pe{constructor(){this.auxMin=new n,this.auxMax=new n,this.auxScaledOffset=new n}updatePositionAndVertices(t,e,i){this.translatePosition(t,e,i),t instanceof x?(this.auxAngle=t.rotation+i.localRotation,t.vertexModel.forEach(((e,s)=>t.vertices[s].set(e.x*i.localScale.x,e.y*i.localScale.y))),t.vertices.forEach((e=>e.set(e.x*Math.cos(this.auxAngle)-e.y*Math.sin(this.auxAngle)+t.position.x,e.x*Math.sin(this.auxAngle)+e.y*Math.cos(this.auxAngle)+t.position.y)))):t instanceof f&&(t.radius*=Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)))}translatePosition(t,e,{localPosition:i,localScale:s,localRotation:o}){if(this.auxScaledOffset.set(e.x*s.x,e.y*s.y),0!==o){const e=Math.atan2(this.auxScaledOffset.y,this.auxScaledOffset.x)+o;t.position.set(i.x+this.auxScaledOffset.magnitude*Math.cos(e),i.y+this.auxScaledOffset.magnitude*Math.sin(e))}else n.add(t.position,i,this.auxScaledOffset)}updateBoundingBox(t){t instanceof f?this.updateCircumferenceBoundingBox(t):t instanceof x&&this.updatePolygonBoundingBox(t)}updateCircumferenceBoundingBox(t){t.boundingBox.set(t.position.x-t.radius,t.position.y-t.radius,2*t.radius,2*t.radius)}updatePolygonBoundingBox(t){this.auxMin.x=t.vertices[0].x,this.auxMin.y=t.vertices[0].y,this.auxMax.x=t.vertices[0].x,this.auxMax.y=t.vertices[0].y,t.vertices.forEach((t=>{this.auxMin.x=Math.min(t.x,this.auxMin.x),this.auxMin.y=Math.min(t.y,this.auxMin.y),this.auxMax.x=Math.max(t.x,this.auxMax.x),this.auxMax.y=Math.max(t.y,this.auxMax.y)})),t.boundingBox.set(this.auxMin.x,this.auxMin.y,this.auxMax.x-this.auxMin.x,this.auxMax.y-this.auxMin.y)}updateProjectionAxes(t){var e;if(t.vertices.length>2)for(let i=0;i<t.vertices.length;i++)n.normal(t.projectionAxes[i],n.subtract(t.projectionAxes[i],null!==(e=t.vertices[i+1])&&void 0!==e?e:t.vertices[0],t.vertices[i]));else n.normal(t.projectionAxes[0],n.subtract(t.projectionAxes[0],t.vertices[1],t.vertices[0]))}}let me=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Nt).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new f(t.radius)),t.shapes[0].radius=t.radius,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};me=r([i(U.UpdateBallColliderShapeSystem),a(0,s(t.EntityManager))],me);let ge=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Yt).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new x([new n,new n,new n,new n])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel[0].set(-t.width/2,-t.height/2),t.shapes[0].vertexModel[1].set(-t.width/2,t.height/2),t.shapes[0].vertexModel[2].set(t.width/2,t.height/2),t.shapes[0].vertexModel[3].set(t.width/2,-t.height/2),this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};ge=r([i(U.UpdateBoxColliderShapeSystem),a(0,s(t.EntityManager))],ge);let ue=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Xt).forEach((({component:t,entity:e})=>{for(let i=0;i<t.vertexModel.length-1;i++)t.shapes[i]||(t.shapes[i]=new x([new n,new n])),t.shapes[i].rotation=t.rotation,t.shapes[i].vertexModel=[t.vertexModel[i],t.vertexModel[i+1]],this.updatePositionAndVertices(t.shapes[i],t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(t.shapes[i]),this.updateProjectionAxes(t.shapes[i])}))}};ue=r([i(U.UpdateEdgeColliderShapeSystem),a(0,s(t.EntityManager))],ue);let ye=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search($t).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new x([])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel=t.vertexModel,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};ye=r([i(U.UpdatePolygonColliderShapeSystem),a(0,s(t.EntityManager))],ye);let xe=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Kt).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,Bt);if(i&&0!==i.data.length){0===t.shapes.length&&(t.composite?this.useEdges(t,i):this.useBoxes(t,i));for(const i of t.shapes)this.updatePositionAndVertices(i,t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(i),this.updateProjectionAxes(i)}}))}useBoxes(t,e){t.shapes=[],e.data.forEach(((i,s)=>{if(!this.needsCollider(i,s,e))return;const o=new x(this.generateRectangleVertices(s,e));o.updateCollisions=!1,t.shapes.push(o)}))}generateRectangleVertices(t,{width:e,height:i,tileWidth:s,tileHeight:o}){const r=-e*s/2+t%e*s,a=i*o/2-Math.floor(t/e)*o;return[new n(r,a-o),new n(r,a),new n(r+s,a),new n(r+s,a-o)]}needsCollider(t,e,{data:i,width:s,height:o}){return 0!==t&&this.getNeighbors(e,s,o).some((t=>!t||!i[t]||0===i[t]))}useEdges(t,e){t.shapes=[];const i=[],s=[];let o,r;e.data.forEach(((t,o)=>{if(0===t)return;const r=o%e.width,a=Math.floor(o/e.width);i[a]||(i[a]=[]),i[a+1]||(i[a+1]=[]),s[a]||(s[a]=[]),s[a+1]||(s[a+1]=[]);const n=this.getNeighbors(o,e.width,e.height);this.hasTile(n[0],e)||(i[a][r]=!0),this.hasTile(n[2],e)||(i[a+1][r]=!0),this.hasTile(n[1],e)||(s[a][r]=!0),this.hasTile(n[3],e)||(s[a][r+1]=!0)}));for(let s=0;s<i.length;s++)if(i[s])for(let a=0;a<i[s].length;a++)!o||!r||s===r.y&&i[s][a]||(t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0),i[s][a]&&(o||(o=new n(a,s)),r=new n(a+1,s));o&&r&&t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0;for(let i=0;i<=e.width;i++)for(let a=0;a<s.length;a++)s[a]&&(!o||!r||i===r.x&&s[a][i]||(t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0),s[a][i]&&(o||(o=new n(i,a)),r=new n(i,a+1)));o&&r&&t.shapes.push(this.createEdge(o,r,e))}hasTile(t,{data:e}){return void 0!==t&&e[t]&&e[t]>0}createEdge(t,e,{width:i,height:s,tileWidth:o,tileHeight:r}){t.x=-i*o/2+t.x*o,t.y=s*r/2-t.y*r,e.x=-i*o/2+e.x*o,e.y=s*r/2-e.y*r;const a=new x([new n(t.x,t.y),new n(e.x,e.y)]);return a.updateCollisions=!1,a}getNeighbors(t,e,i){return[t-e>=0?t-e:void 0,t%e>0?t-1:void 0,t+e<=e*i?t+e:void 0,t%e<e-1?t+1:void 0]}};xe=r([i(U.UpdateTilemapColliderShapeSystem),a(0,s(t.EntityManager))],xe);let fe=class{constructor(t,e,i,s,o){this.entityManager=t,this.broadPhaseResolver=e,this.collisionMatrix=i,this.collisionResolutionMethod=s,this.collisionRepository=o,this.colliders=[],this.collisions=new Set,this.shapes=[]}onUpdate(){this.collisionRepository.removeAll(),this.colliders=[],this.collisions.clear(),this.shapes=[],[Nt,Yt,$t,Xt,Kt].forEach((t=>this.entityManager.search(t).forEach((({component:t,entity:e})=>{this.colliders.push(t),t.shapes.forEach((i=>{var s;i.entity=e,i.collider=this.colliders.length-1,i.id=this.shapes.length,i.ignoreCollisionsWithLayers=null!==(s=t.ignoreCollisionsWithLayers)&&void 0!==s?s:[],i.layer=t.layer,this.shapes.push(i)}))})))),this.broadPhaseResolver.update(this.shapes),this.shapes.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase({boundingBox:t,layer:e}){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t).map((t=>this.shapes[t])).filter((t=>this.collisionMatrix.some((i=>i[0]===e&&i[1]===t.layer||i[1]===e&&i[0]===t.layer)))):this.broadPhaseResolver.retrieve(t).map((t=>this.shapes[t]))}narrowPhase(t,e){e.filter((e=>t.entity!==e.entity&&t.id!==e.id&&!t.ignoreCollisionsWithLayers.includes(e.layer)&&!e.ignoreCollisionsWithLayers.includes(t.layer)&&!this.isResolved(t,e))).forEach((e=>{const i=this.collisionResolutionMethod.findCollision(t,e);i&&(this.collisionRepository.persist({localCollider:this.colliders[t.collider],localEntity:t.entity,remoteCollider:this.colliders[e.collider],remoteEntity:e.entity,resolution:i}),this.collisionRepository.persist({localCollider:this.colliders[e.collider],localEntity:e.entity,remoteCollider:this.colliders[t.collider],remoteEntity:t.entity,resolution:{direction:n.scale(new n,i.direction,-1),penetration:i.penetration}}),this.collisions.add(`${t.id}-${e.id}`),this.collisions.add(`${e.id}-${t.id}`))}))}isResolved(t,e){return this.collisions.has(`${t.id}-${e.id}`)}};fe=r([i(U.ResolveCollisionSystem),a(0,s(t.EntityManager)),a(1,s(t.CollisionBroadphaseResolver)),a(2,s(t.CollisionMatrix)),a(3,s(t.CollisionResolutionMethod)),a(4,s(t.CollisionRepository))],fe);let Me=class{constructor(t,e,i){this.entityManager=t,this.collisionRepository=e,this.transformSystem=i,this.displacement=new n}onUpdate(){this.entityManager.search(ce,{type:exports.RigidBodyType.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,k),s=[e,...i._childEntities];this.displacement.set(0,0),this.collisionRepository.findAll().filter((({localCollider:t,localEntity:e})=>s.includes(e)&&t.physics)).forEach((({resolution:{direction:t,penetration:e}})=>{e>this.displacement.magnitude&&n.scale(this.displacement,t,-e)})),0!==this.displacement.magnitude&&(n.add(i.position,i.position,this.displacement),this.displacement.x*t.velocity.x<0&&(t.velocity.x=0),this.displacement.y*t.velocity.y<0&&(t.velocity.y=0))})),this.transformSystem.onUpdate()}};Me=r([i(U.ApplyRepositionSystem),a(0,s(t.EntityManager)),a(1,s(t.CollisionRepository)),a(2,s(U.TransformSystem))],Me);let ve=class extends pe{constructor(t){super(),this.entityManager=t}onUpdate(){[Nt,Yt,$t,Xt,Kt].forEach((t=>this.entityManager.search(t,{updateCollisions:!0}).forEach((({component:t,entity:e})=>t.shapes.forEach((i=>{this.updatePositionAndVertices(i,t.offset,this.entityManager.getComponent(e,k)),this.updateBoundingBox(i)}))))))}};ve=r([i(U.UpdateCollidersAfterRepositionSystem),a(0,s(t.EntityManager))],ve);const Se=new Map([[I.PreGameLogic,[{name:U.KeyboardSystem,type:jt},{name:U.MouseSystem,type:kt},{name:U.TouchScreenSystem,type:Ot},{name:U.GamepadSystem,type:It},{name:U.ButtonSystem,type:wt},{name:U.AudioPlayerSystem,type:L},{name:U.TiledWrapperSystem,type:Dt},{name:U.TilemapPreProcessingSystem,type:Ut}]],[I.PostGameLogic,[{name:U.TransformSystem,type:Lt},{name:U.ChildrenSystem,type:Rt},{name:U.ParentSystem,type:At}]],[I.Physics,[{name:U.ApplyVelocitySystem,type:de},{name:U.UpdateBallColliderShapeSystem,type:me},{name:U.UpdateBoxColliderShapeSystem,type:ge},{name:U.UpdateEdgeColliderShapeSystem,type:ue},{name:U.UpdatePolygonColliderShapeSystem,type:ye},{name:U.UpdateTilemapColliderShapeSystem,type:xe},{name:U.ResolveCollisionSystem,type:fe},{name:U.ApplyRepositionSystem,type:Me},{name:U.UpdateCollidersAfterRepositionSystem,type:ve}]],[I.Render,[{name:U.AnimatorSystem,type:Wt},{name:U.CameraSystem,type:zt},{name:U.TilemapRendererSystem,type:ne},{name:U.SpriteRendererSystem,type:oe},{name:U.MaskRendererSystem,type:Zt},{name:U.ShadowLightRendererSystem,type:se},{name:U.TextRendererSystem,type:ae},{name:U.VideoRendererSystem,type:St},{name:U.ColliderRenderSystem,type:qt},{name:U.CullingSystem,type:Qt},{name:U.ClearScreenSystem,type:Ht},{name:U.RenderSystem,type:te}]]]);let Ce=class{constructor(t,e,i){this.timeManager=t,this.systemManager=e,this.sceneManager=i,this.running=!1,this.gameLoopAccumulator=0}start(){this.running||(this.running=!0,this.gameLoopAccumulator=0,this.enableSystems(),this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.asyncPhysicsLoop())}enableSystems(){Se.forEach((t=>{t.forEach((t=>this.systemManager.enableSystem(t.type)))}))}stop(){this.running=!1}requestAnimationLoop(t){this.running&&(this.timeManager.updateForRender(.001*t),this.sceneManager.update(),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.fixedGameDeltaTime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.fixedGameDeltaTime),this.renderIteration(),window.requestAnimationFrame((t=>this.requestAnimationLoop(t))))}gameLogicIteration(t){this.timeManager.updateForGame(t),this.systemManager.update(I.PreGameLogic),this.systemManager.update(I.GameLogic),this.systemManager.update(I.PostGameLogic)}renderIteration(){this.systemManager.update(I.GamePreRender),this.systemManager.update(I.Render)}asyncPhysicsLoop(){this.physicsIntervalId=window.setInterval((()=>{if(!this.running)return window.clearInterval(this.physicsIntervalId);this.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||this.physicsIteration()}),1e3/this.timeManager.fixedPhysicsFramerate)}physicsIteration(){this.timeManager.timeScale<=0||(this.systemManager.update(I.GamePhysics),this.systemManager.update(I.Physics))}};Ce=r([i(t.LoopManager),a(0,s(t.TimeManager)),a(1,s(t.SystemManager)),a(2,s(t.SceneManager))],Ce);class be{constructor(t,e){this.container=t,this.systemManager=e,this.lastSystemTypeId=0}createSystemIfNotExists(t){if(this.systemManager.hasSystem(t))return;const e="__system_"+this.lastSystemTypeId++;var i;this.container.add(t,e),this.systemManager.addSystem(this.container.get(e),null!==(i=t.prototype.__system_group)&&void 0!==i?i:I.GameLogic)}}let we=class{constructor(t){this.webGLManager=t,this.renderData=[],this.cameraData=[]}addCameraData(t){this.cameraData.push(t)}addRenderData(t){this.renderData.push(t)}setRenderData(t){this.renderData=t}getCameraData(){return this.cameraData}getRenderData(){return this.renderData}removeCameraData(){this.cameraData=[]}removeRenderData(){this.renderData=[]}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).forEach((e=>this.webGLManager.render(e,t)))))}};we=r([i(t.RenderManager),a(0,s(t.WebGLManager))],we);const Ee=t=>{var e,i,s,o,r,a,n,h;if(!(t.containerNode instanceof HTMLElement))throw new Error("GameConfig Error: Invalid containerNode");if("number"!=typeof t.width)throw new Error("GameConfig Error: Invalid width");if("number"!=typeof t.height)throw new Error("GameConfig Error: Invalid height");t.debugEnabled=null!==(e=t.debugEnabled)&&void 0!==e&&e,t.canvasColor=null!==(i=t.canvasColor)&&void 0!==i?i:"#000000",t.physicsFramerate=null!==(s=t.physicsFramerate)&&void 0!==s?s:180,t.headless=null!==(o=t.headless)&&void 0!==o&&o,t.collisions=null!==(r=t.collisions)&&void 0!==r?r:{},t.collisions.collisionBroadPhaseMethod=null!==(a=t.collisions.collisionBroadPhaseMethod)&&void 0!==a?a:exports.BroadPhaseMethods.SpartialGrid,t.collisions.collisionMatrix=null!==(n=t.collisions.collisionMatrix)&&void 0!==n?n:void 0,t.collisions.collisionMethod=null!==(h=t.collisions.collisionMethod)&&void 0!==h?h:exports.CollisionMethods.SAT},Re=({containerNode:t,width:e,height:i})=>{const s=document.createElement("canvas");return s.id="angryPixelGameCanvas",s.width=Math.floor(e),s.height=Math.floor(i),s.tabIndex=0,s.addEventListener("contextmenu",(t=>t.preventDefault())),t.appendChild(s),s.focus(),s},_e=e=>{e.add(exports.EntityManager),e.add(exports.SystemManager),e.set(t.SystemFactory,new be(e,e.get(t.SystemManager))),e.add(exports.TimeManager),e.add(exports.AssetManager),e.add(exports.InputManager),e.add(exports.SceneManager),e.add(exports.InputManager),e.add(Ce),e.add(ft),e.add(we)},Ae=e=>{e.get(t.GameConfig).headless&&Te(Se),Se.forEach(((i,s)=>i.forEach((({type:i,name:o})=>{e.add(i),e.get(t.SystemManager).addSystem(e.get(o),s)}))))},Te=t=>{t.delete(I.Render),t.set(I.PreGameLogic,t.get(I.PreGameLogic).filter((({name:t})=>![U.AudioPlayerSystem,U.ButtonSystem,U.GamepadSystem,U.KeyboardSystem,U.MouseSystem,U.TouchScreenSystem].includes(t))))},Be=e=>{const{collisions:{collisionBroadPhaseMethod:i,collisionMatrix:s,collisionMethod:o}}=e.get(t.GameConfig);e.add(exports.CollisionRepository),e.add(w),o===exports.CollisionMethods.AABB?(e.add(C),e.add(b)):e.add(E),e.add(i===exports.BroadPhaseMethods.QuadTree?g:y),e.add(o===exports.CollisionMethods.AABB?M:S),e.set(t.CollisionMatrix,s)};class De{onUpdate(){}}r([s(t.EntityManager)],De.prototype,"entityManager",void 0),r([s(t.AssetManager)],De.prototype,"assetManager",void 0),r([s(t.SceneManager)],De.prototype,"sceneManager",void 0),r([s(t.TimeManager)],De.prototype,"timeManager",void 0),r([s(t.InputManager)],De.prototype,"inputManager",void 0),r([s(t.CollisionRepository)],De.prototype,"collisionRepository",void 0);const Pe={AssetManager:t.AssetManager,CanvasElement:t.CanvasElement,CollisionRepository:t.CollisionRepository,EntityManager:t.EntityManager,GameConfig:t.GameConfig,InputManager:t.InputManager,SceneManager:t.SceneManager,SystemManager:t.SystemManager,TimeManager:t.TimeManager};exports.Animation=class{constructor(t){this.slice={size:new n,offset:new n,padding:new n},this.frames=[],this.fps=12,this.loop=!1,Object.assign(this,t)}},exports.Animator=Vt,exports.AudioPlayer=P,exports.BallCollider=Nt,exports.BoxCollider=Yt,exports.Button=Ct,exports.Camera=V,exports.Children=Et,exports.Circumference=f,exports.EdgeCollider=Xt,exports.Game=class{constructor(i){this.container=(i=>{Ee(i);const s=new e;return s.set(t.GameConfig,i),s.set(t.CanvasElement,Re(i)),Be(s),_e(s),Ae(s),s})(i)}get running(){return this.container.get(t.LoopManager).running}addScene(e,i,s=!1){this.container.get(t.SceneManager).addScene(e,i,s)}addDependencyType(t,e){this.container.add(t,e)}addDependencyInstance(t,e){this.container.set(e,t)}start(){this.container.get(t.LoopManager).start()}stop(){this.container.get(t.LoopManager).stop()}},exports.GameSystem=De,exports.GamepadController=R,exports.Keyboard=_,exports.LightRenderer=ee,exports.MaskRenderer=Jt,exports.Mouse=A,exports.Parent=_t,exports.Polygon=x,exports.PolygonCollider=$t,exports.Rectangle=h,exports.RigidBody=ce,exports.Scene=class{constructor(t,e){this.entityManager=t,this.assetManager=e}loadAssets(){}setup(){}},exports.ShadowRenderer=ie,exports.SpriteRenderer=Gt,exports.Symbols=Pe,exports.TextRenderer=re,exports.TiledWrapper=Tt,exports.TilemapCollider=Kt,exports.TilemapRenderer=Bt,exports.TouchScreen=T,exports.Transform=k,exports.Vector2=n,exports.VideoRenderer=Mt,exports.between=p,exports.clamp=l,exports.defaultRenderLayer=O,exports.fixedRound=c,exports.gameLogicSystem=function(){return function(t){j(t,I.GameLogic)}},exports.gamePhysicsSystem=function(){return function(t){j(t,I.GamePhysics)}},exports.gamePreRenderSystem=function(){return function(t){j(t,I.GamePreRender)}},exports.inject=s,exports.injectable=i,exports.randomFloat=(t,e,i=2)=>c(Math.random()*(e-t)+t,i),exports.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,exports.range=d;
2
2
  //# sourceMappingURL=index.cjs.js.map