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/README.md +94 -86
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2218 -5
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -12
- package/package.dev.json +0 -36
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).AngryPixel={})}(this,(function(t){"use strict";var e=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),i=function(){function t(t,i,n,o){this._position=new e,this._center=new e,this._width=0,this._height=0,this.set(t,i,n,o)}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(i){return i instanceof t?i.x1<=this.x1&&i.x>=this.x&&i.y1<=this.y1&&i.y>=this.y:i instanceof e&&!(i.x<this.x||i.y<this.y||i.x>=this.x1||i.y>=this.y1)},t}(),n=function(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},o=function(){function t(t,i){void 0===t&&(t=null),void 0===i&&(i=null),this._degrees=0,this._radians=0,this._direction=new e,t?this.radians=t:i&&(this.degrees=i)}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}(),r=function(t,e){return r=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])},r(t,e)};function s(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}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var a,h=function(){return h=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},h.apply(this,arguments)};function c(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"}(a||(a={}));var u,l,p,d=function(){function t(t,e,i,n,o,r,s){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=o,this.sceneManager=r,this.canvasColor=s,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[a.Start,a.Update,a.StopGame],this.gameObjectEvents=[a.Start,a.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(a.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(a.Start),this.inputManager.update(),this.dispatchFrameEvent(a.Update),this.dispatchFrameEvent(a.UpdateEngine),this.dispatchFrameEvent(a.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(a.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(a.UpdatePreRender),this.dispatchFrameEvent(a.UpdateCamera),this.dispatchFrameEvent(a.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(a.UpdatePhysics),this.dispatchFrameEvent(a.UpdateCollider),this.dispatchFrameEvent(a.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}(),f=function(){function t(t){this.updateEvent=a.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===a.Init&&this.init?this.init(e):t!==a.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===a.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===a.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}(),g=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 s(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}(f),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdateEngine,e}return s(e,t),e}(g),m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdateCollider,e}return s(e,t),e}(g),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdatePhysics,e}return s(e,t),e}(g),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdateTransform,e}return s(e,t),e}(g),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdatePreRender,e}return s(e,t),e}(g),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdateCamera,e}return s(e,t),e}(g),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=a.UpdateRender,e}return s(e,t),e}(g);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(u||(u={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(l||(l={})),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"}(p||(p={}));var w=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===l.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===u.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 p.Video:case p.Mask:case p.Sprite:this.setObjectForResizeable(t);break;case p.Geometric:this.setObjectForGeometric(t);break;case p.Text:this.setObjectForText(t);break;case p.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===p.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),j=function(){return j=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},j.apply(this,arguments)};function P(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var O,C=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 C,this._center=new C,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 C&&!(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 C,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"}(O||(O={}));var A,R=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===p.Tilemap?function(t){var e=j(j({},t),{culledTiles:[],tilemap:j(j({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new C});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==O.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===O.RightDown?-t.tilemap.realHeight/2:t.orientation===O.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"}(A||(A={}));var S=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(A.WebGL2)?A.WebGL2:null!==this.canvas.getContext(A.LegacyWebGL)?A.LegacyWebGL:void 0},t}(),E=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 T(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}(),T=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},D=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}(),B=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===A.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}(),F=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}(),I="undefined"!=typeof Float32Array?Float32Array:Array;function U(){var t=new I(16);return I!=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 L(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 k(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 V(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 G(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)}),t.MaskShape=void 0;var H=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},W=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=L(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===l.WorldSpace&&(V(t,t,[null!==(o=i.zoom)&&void 0!==o?o:1,null!==(r=i.zoom)&&void 0!==r?r:1,1]),k(t,t,[-i.position.x,-i.position.y,0]))},z=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U();var i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(function(t,e,i){void 0===i&&(i=1);for(var n=[],o=1;o<=60;o+=i)n.push(o);return n}(0,0,1).reduce((function(t,e){return P(P([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case u.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case u.Line:this.renderLines(t,e,this.gl.LINES,i);break;case u.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===p.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=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(o=t.rotation)&&void 0!==o?o:0),W(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=H(t.color),h=a.r,c=a.g,u=a.b,l=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,c,u,l),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)},t.prototype.generateVerticesKey=function(t){return Symbol.for(t.reduce((function(t,e){return"".concat(t).concat(e.x).concat(e.y)}),t.length.toString()))},t.prototype.generatePolygonVertices=function(t){for(var e=[],i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e},t.prototype.renderCircumference=function(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),V(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),W(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=H(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"}(t.MaskShape||(t.MaskShape={})),t.TextOrientation=void 0;var X=function(){function e(t,e){this.gl=t,this.programManager=e,this.type=p.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U();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 e.prototype.render=function(e,i,n){var o,r;n===p.Mask&&this.lastShape===e.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,e.shape===t.MaskShape.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[e.position.x,e.position.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(o=e.rotation)&&void 0!==o?o:0),V(this.modelMatrix,this.modelMatrix,e.shape===t.MaskShape.Rectangle?[e.width,e.height,1]:[e.radius,e.radius,1]),W(this.projectionMatrix,this.gl,i,e.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),e.alpha>=0&&e.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var s=H(e.color),a=s.r,h=s.g,c=s.b,u=s.a;this.gl.uniform4f(this.programManager.solidColorUniform,a,h,c,u),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=e.alpha)&&void 0!==r?r:1),e.shape===t.MaskShape.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=e.shape},e}(),Y=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U(),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=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),V(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=L(this.textureMatrix),t.slice&&(k(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),V(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),W(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=H(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=H(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"}(t.TextOrientation||(t.TextOrientation={}));var N=new C,q=new C,K=[32,126,161,255],Q=t.TextOrientation.Center,$=function(){function e(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=p.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new C,this.modelPosition=new C,this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U()}return e.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=L(this.modelMatrix),this.setPositionFromOrientation(t),k(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),V(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=L(this.textureMatrix),W(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===p.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=H(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)},e.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:N,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:q,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:K):t.bitmap={margin:N,spacing:q,fontSize:64,charRanges:K},t.color=null!==(r=t.color)&&void 0!==r?r:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(c=t.orientation)&&void 0!==c?c:Q,t.rotation=null!==(u=t.rotation)&&void 0!==u?u:0},e.prototype.generateTextVertices=function(t,e){var i=e.text,n=e.fontSize,o=e.bitmap,r=e.letterSpacing,s=e.lineSeparation;this.posVertices=[],this.texVertices=[];var a=0,h=0,c=0;r/=n,s/=n;for(var u=0;u<i.length;u++){var l=i[u];if("\n"!==l){var p=t.glyphs.get(l);if(p){var d=p.width/t.bitmapFontSize;this.posVertices.push(a,h-1,a+d,h-1,a,h,a,h,a+d,h-1,a+d,h);var f=p.id%t.gridSize*t.bitmapFontSize,g=(p.id/t.gridSize|0)*t.bitmapFontSize,y=(f+o.margin.x)/t.canvas.width,m=(g+o.margin.y)/t.canvas.width,v=(f+p.width+o.spacing.x)/t.canvas.width,b=(g+t.bitmapFontSize+o.spacing.y)/t.canvas.width;this.texVertices.push(y,b,v,b,y,m,y,m,v,b,v,m),a+=d+r}}else c=Math.max(c,a),a=0,h-=1+s}this.textSize.set(Math.max(c,a)*n,Math.abs(h-1)*n)},e.prototype.setPositionFromOrientation=function(e){this.modelPosition.set(e.position.x+(e.orientation===t.TextOrientation.Center?-this.textSize.x/2:0),e.position.y+(e.orientation===t.TextOrientation.Center||e.orientation===t.TextOrientation.RightCenter?this.textSize.y/2:e.orientation===t.TextOrientation.RightUp?this.textSize.y:0))},e}(),J=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 C,texSpacing:new C,texWidth:0,texHeight:0,texCorrection:new C},this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U()}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=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),V(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=L(this.textureMatrix),V(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),W(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===p.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=H(t.tintColor),c=h.r,u=h.g,l=h.b,d=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,c,u,l,d)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var f=H(t.maskColor);c=f.r,u=f.g,l=f.b,this.gl.uniform4f(this.programManager.maskColorUniform,c,u,l,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.processTileset=function(t){var e,i,n,o,r,s,a,h=t.tileset;h.margin=null!==(e=h.margin)&&void 0!==e?e:new C,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new C,h.correction=null!==(n=h.correction)&&void 0!==n?n:new C,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}(),Z=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=U(),this.modelMatrix=U(),this.textureMatrix=U(),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=L(this.modelMatrix),k(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),G(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),V(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=L(this.textureMatrix),t.slice&&(k(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),V(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),W(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=H(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=H(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}(),tt=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}(),et=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}(),it=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=H(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}(),nt=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}(),ot=function(){function t(t,e,i,n){this._position=new nt,this._center=new nt,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 nt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),rt=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 nt,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,at=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 nt,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),ht=function(){function t(t,e){void 0===e&&(e=0),this.area=new ot(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 ot(this.area.x,this.area.y,i,n),new ot(this.area.x,this.area.y+n,i,n),new ot(this.area.x+i,this.area.y+n,i,n),new ot(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}(),ct=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},ut=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=rt(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=ct(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=ct(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=ct(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=ct(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(st||(st={}));var lt,pt=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new nt,this.maxArea=new nt,this.newArea=new ot(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:st.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new ot(0,0,0,0),this.fixedCollisionArea=!!e,t===st.SpartialGrid?this.broadPhaseResolver=new ut(this.collisionArea):this.broadPhaseResolver=new ht(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 ut&&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"}(lt||(lt={}));var dt,ft=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===lt.Polygon&&e.type===lt.Polygon?this.AABBResolver.resolve(t,e):t.type===lt.Circumference&&e.type===lt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===lt.Polygon&&e.type===lt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===lt.Circumference&&e.type===lt.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(dt||(dt={}));var gt=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===lt.Circumference&&e.type===lt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),yt=function(){function t(){this.direction=new nt,this.displacementDirection=new nt}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)),nt.unit(this.displacementDirection,this.displacementDirection),{direction:nt.scale(new nt,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}(),mt=function(){function t(){this.closestPoint=new nt,this.distance=new nt,this.direction=new nt}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(rt(t.position.x,e.boundingBox.x,e.boundingBox.x1),rt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),nt.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(nt.unit(this.direction,this.distance),{direction:i?nt.scale(new nt,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():nt.scale(new nt,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),vt=function(){function t(){this.distance=new nt,this.direction=new nt}return t.prototype.resolve=function(t,e){return nt.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(nt.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:nt.scale(new nt,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),bt=function(t,e){return bt=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])},bt(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,t.RigidBodyType=void 0;var Mt=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new nt,this.distance=new nt(1/0,1/0),this.cache=new nt}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===lt.Circumference?this.setCircumferenceAxis(t,e):e.type===lt.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===lt.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===lt.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,nt.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&&nt.scale(this.smallestAxis,this.axes[n],-1))}return{direction:nt.scale(new nt,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(nt.dot(i,e),t.min),t.max=Math.max(nt.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){nt.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),nt.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){nt.add(t.vertices[0],t.position,nt.scale(this.cache,nt.unit(this.cache,e),-t.radius)),nt.add(t.vertices[1],t.position,nt.scale(this.cache,nt.unit(this.cache,e),t.radius))},t}(),_t=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}(),wt=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 nt,velocity:null!=r?r:new nt,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(t.RigidBodyType||(t.RigidBodyType={}));var jt=["x","y"],Pt=function(){function e(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new nt,this.displacement=new nt,this.cacheDisplacement=0}return e.prototype.addRigidBody=function(t){this.rigidBodies.push(t)},e.prototype.removeRigidBody=function(t){var e=this.rigidBodies.indexOf(t);e>=0&&this.rigidBodies.splice(e,1)},e.prototype.clearRigidBodies=function(){this.rigidBodies=[]},e.prototype.resolve=function(e){var i=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(n){n.type===t.RigidBodyType.Dynamic?i.dynamicUpdate(n,e):n.type===t.RigidBodyType.Kinematic&&i.kinematicUpdate(n,e),n.onResolve&&n.onResolve(n)}))},e.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),jt.forEach((function(n){i.applyVelocity(t,e,n),i.obtainDisplacement(t,n),i.applyReposition(t,n)}))},e.prototype.kinematicUpdate=function(t,e){var i=this;nt.add(t.position,t.position,nt.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){nt.add(t.position,t.position,i.velocity),i.collisionManager.refreshCollisionsForCollider(t)}))},e.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},e.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)})))},e.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}))},e.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))},e.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}),[])},e}(),Ot=function(){function t(t){this.radius=t,this.type=lt.Circumference,this.boundingBox=new ot(0,0,0,0),this.vertices=[new nt,new nt],this.projectionAxes=[new nt],this._position=new nt}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}(),Ct=function(){function t(t){this.vertexModel=t,this.type=lt.Polygon,this.vertices=[new nt,new nt],this.projectionAxes=[new nt],this.boundingBox=new ot(0,0,0,0),this.rotation=0,this._position=new nt}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(){nt.normal(this.projectionAxes[0],nt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),At=function(){function t(t){this.vertexModel=t,this.type=lt.Polygon,this.vertices=[],this.boundingBox=new ot(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new nt,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 nt),this._projectionAxes.push(new nt)}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++)nt.normal(this._projectionAxes[e],nt.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),Rt=function(t){function e(e,i){var n=t.call(this,[new nt(-e/2,-i/2),new nt(-e/2,i/2),new nt(e/2,i/2),new nt(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new nt,new nt],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}bt(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(){nt.unit(this.projectionAxes[0],nt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),nt.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(At),St=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 St,this._center=new St,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 St&&!(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 St,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 Et,Tt=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 Dt),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}(),Dt=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new St,this._leftStickAxes=new St,this._rightStickAxes=new St,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}(),Bt=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}(),Ft=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}(),It=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new St,this._hasMoved=!1,this._wheelScroll=new St,this.lastPositionInViewport=new St,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}(),Ut=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 St((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 St(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Et||(Et={})),t.ButtonType=void 0;var Lt=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,Et.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,Et.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,Et.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,Et.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===Et.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===Et.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===Et.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===Et.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}(),kt=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return s(e,t),e}(Error),Vt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new kt("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}(),Gt=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(a.Init,e),o},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):c([],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(a.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Ht=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=[a.Start,a.Update,a.StopGame],this.gameObjectEvents=[a.Start,a.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(a.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(a.Start),this.dispatchFrameEvent(a.Update),this.dispatchFrameEvent(a.UpdateEngine),this.dispatchFrameEvent(a.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(a.UpdatePhysics),this.dispatchFrameEvent(a.UpdateCollider),this.dispatchFrameEvent(a.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}(),Wt=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 kt("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(a.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new kt("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 kt("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(a.Destroy),this.currentScene=void 0)},t}(),zt=[60,120,180,240],Xt=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,!zt.includes(t))throw new kt("Invalid Physics frame rate. Allowed: [".concat(zt.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}(),Yt=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 kt("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 kt("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 kt("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new kt("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 kt("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),Nt=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}(),qt=function(){function t(t,e,i,n){this._position=new Nt,this._center=new Nt,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 Nt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),Kt=function(t,e,i){return t>=e&&t<=i},Qt=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new Nt,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}(),$t={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new Nt(1,1),collisions:{collisionMethod:dt.SAT,collisionBroadPhaseMethod:st.SpartialGrid}},Jt=function(){function t(t){this._config=h(h({},$t),t),this._config.collisions=h(h({},$t.collisions),t.collisions),this.container=new Yt,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 Xt(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new Gt(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 vt,a=o===dt.AABB?new ft(new yt,new mt,s):new gt(s,new Mt),h=new pt(a,r,i,n),c=new at,u=new Pt(h),l=new wt;return new _t(h,c,u,l)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Ht(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new Vt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new S(t),i=e.gl,n=e.contextVersion,o=new B(i,n,new D(i,new F(i))),r=new et(new tt(i)),s=new it(i,o,r,new Map([[p.Sprite,new Y(i,o,r)],[p.Text,new $(i,o,r,new E)],[p.Tilemap,new J(i,o,r)],[p.Geometric,new z(i,o)],[p.Mask,new X(i,o)],[p.Video,new Z(i,o,r)]]));return new R(s,new w(i))}(i)})),t.add("InputManager",(function(){return function(t){return new Bt(new It(t),new Ft(t),new Tt,new Ut(t))}(i)})),t.add("AssetManager",(function(){return new Lt(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new d(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 Wt(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}(),Zt=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 Nt,e._scale=new Nt(1,1),e._rotation=new Qt,e._innerPosition=new Nt,e._parent=null,e.cache=new Nt,e.lastParentRadians=0,e.lastPosition=new Nt,e.scaledInnerPosition=new Nt,e}return s(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&&Nt.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(),Nt.add(this._position,this._parent.position,this.scaledInnerPosition)):Nt.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)),Nt.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}(b),te=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 s(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}(m),ee=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e}return s(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 kt("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 Nt,position:new Nt})},e.prototype.update=function(){if(0===this.getColliderIds().length)throw new kt("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 te&&t.physics})).reduce((function(t,e){return c(c([],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}(y),ie=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(Zt),o&&(r.transform.position=o.transform.position,r.parent=o),r}return s(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(Zt)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(ee)},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(a.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new kt("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(a.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(a.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(f),ne=["Default"],oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.viewportRect=new qt(0,0,0,0),e.worldSpaceRect=new qt(0,0,0,0),e.depth=0,e.layers=ne,e._zoom=1,e}return s(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new kt("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 Nt,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}(M),re=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(oe)},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}(ie),se=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(re),o}return s(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(re)},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}(f),ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.offsetX=0,e.offsetY=0,e.scaledVertexModel=[],e.scaledOffset=new Nt,e.scaledPosition=new Nt,e.finalRotation=0,e.innerPosition=new Nt,e}return s(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==dt.SAT)throw new kt("Polygon Colliders need SAT collision method.");if(t.vertexModel.length<3)throw new kt("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new Qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Nt);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.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(he,{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(){Nt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Nt.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}(te),he=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:p.Geometric,location:l.WorldSpace,layer:this.gameObject.layer,position:new Nt,shape:u.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}(_),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.realWidth=0,e.realHeight=0,e.realOffset=new Nt,e.realPosition=new Nt,e.realRotation=0,e.applyRotation=e.gameConfig.collisions.collisionMethod===dt.SAT,e.innerPosition=new Nt,e}return s(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(o=t.debug)&&void 0!==o?o:this.debug)&&this.gameConfig.debugEnabled,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new Qt,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Rt(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(he,{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(){Nt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Nt.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}(te),ue=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 Nt,e.realPosition=new Nt,e.innerPosition=new Nt,e}return s(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 Ot(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(le,{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(){Nt.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Nt.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}(te),le=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.init=function(t){var e=t.collider;this.renderData={type:p.Geometric,location:l.WorldSpace,layer:this.gameObject.layer,position:new Nt,shape:u.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}(_),pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.debug=!1,e.position=new Nt,e}return s(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(de,{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 Nt(t.position.x+(i%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(i/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new Rt(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 Nt(s,r)),e=new Nt(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 Nt(s,r)),e=new Nt(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 Ct([new Nt(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new Nt(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}(te),de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return s(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:p.Geometric,layer:e.gameObject.layer,location:l.WorldSpace,position:new Nt,shape:u.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}(_),fe=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 Nt,e.scaledPosition=new Nt,e.finalRotation=0,e.innerPosition=new Nt,e}return s(e,t),e.prototype.init=function(t){var e,i,n,o,r,s;if(this.gameConfig.collisions.collisionMethod!==dt.SAT)throw new kt("Edge Colliders need SAT collision method.");if(t.vertexModel.length<2)throw new kt("Edge Collider needs at least 2 vertices.");this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.gameConfig.debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(i=t.offsetX)&&void 0!==i?i:this.offsetX,this.offsetY=null!==(n=t.offsetY)&&void 0!==n?n:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new Qt,this.layer=t.layer;for(var a=0;a<this.vertexModel.length;a++)this.scaledVertexModel.push(new Nt);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 Ct([this.scaledVertexModel[a],this.scaledVertexModel[a+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(ge,{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(){Nt.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},e.prototype.translate=function(){Nt.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}(te),ge=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.colliders=[],e}return s(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:p.Geometric,layer:e.gameObject.layer,location:l.WorldSpace,position:new Nt,shape:u.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}(_),ye=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderData=[],e.innerPosition=new Nt,e.cachePosition=new Nt,e.cacheRenderPosition=new Nt,e.scaledOffset=new Nt,e.cacheScale=new Nt,e}return s(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 Nt,this.rotation=null!==(i=t.rotation)&&void 0!==i?i:new Qt,this.flipHorizontal=null!==(n=t.flipHorizontal)&&void 0!==n&&n,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:1,this._tiled=null!==(s=t.tiled)&&void 0!==s?s:new Nt(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 Nt(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 kt("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:p.Sprite,location:l.WorldSpace,layer:"",position:new Nt,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?l.ViewPort:l.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),Nt.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)),Nt.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(e*this.renderData[t].width,i*this.renderData[t].height),Nt.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},e.prototype.translateRenderPosition=function(t){Nt.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}(_),me=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.lastFrameText="",e}return s(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 Nt,this.color=null!==(a=t.color)&&void 0!==a?a:"#000000",this.charRanges=null!==(h=t.charRanges)&&void 0!==h?h:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=t.letterSpacing)&&void 0!==u?u:0,this.smooth=null!==(l=t.smooth)&&void 0!==l&&l,this.rotation=null!==(p=t.rotation)&&void 0!==p?p:new Qt,this.opacity=null!==(d=t.opacity)&&void 0!==d?d:1,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new kt("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new kt("TextRenderer.lineSeparation must be multiple of 2")},e.prototype.start=function(){this.renderData={type:p.Text,location:l.WorldSpace,position:new Nt,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?l.ViewPort:l.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,Nt.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}(_),ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.offset=new Nt,e.rotation=new Qt,e.opacity=1,e.innerPosition=new Nt,e.scaledOffset=new Nt,e}return s(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:p.Mask,layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,location:this.gameObject.ui?l.ViewPort:l.WorldSpace,position:new Nt,width:0,height:0,radius:0,color:"",shape:this.shape}},e.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?l.ViewPort:l.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),Nt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Nt.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}(_),be=["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 Nt,e.scaledOffset=new Nt,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(){be.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.video&&e._playing&&e.video.play()},e}return s(e,t),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.video&&(this.video.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.video&&(this.video.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e,i,n,o,r,s,a,h,c,u;this.video=t.video,this.width=null!==(e=t.width)&&void 0!==e?e:this.video.videoWidth,this.height=null!==(i=t.height)&&void 0!==i?i:this.video.videoHeight,this.offset=null!==(n=t.offset)&&void 0!==n?n:new Nt,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new Qt,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(s=t.flipVertical)&&void 0!==s&&s,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this.maskColor=t.maskColor,this.maskColorMix=null!==(h=t.maskColorMix)&&void 0!==h?h:0,this.tintColor=t.tintColor,this.layer=t.layer,this.slice=t.slice,this._volume=null!==(c=t.volume)&&void 0!==c?c:1,this._loop=null!==(u=t.loop)&&void 0!==u&&u,this.renderData={type:p.Video,location:l.WorldSpace,layer:"",position:new Nt,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(){be.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?l.ViewPort:l.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),Nt.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},e.prototype.translateRenderPosition=function(){Nt.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}(_),Me=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 s(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 kt("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:p.Tilemap,layer:null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,location:this.gameObject.ui?l.ViewPort:l.WorldSpace,position:new Nt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:O.Center,smooth:this.smooth})},e.prototype.processChunk=function(t){var e,i=this,n={type:p.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?l.ViewPort:l.WorldSpace,position:new Nt,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return i.getTilesetTileId(t)})),orientation:O.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}(_),_e=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return s(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,u=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=u,this.renderData={type:p.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?l.ViewPort:l.WorldSpace,position:new Nt,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:O.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}(_),we=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 s(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 je(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new kt("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}(y),je=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}(),Pe=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Oe=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(){Pe.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return s(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&&Pe.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}(y),Ce=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"}(t.ButtonType||(t.ButtonType={}));var Ae=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMultiple=!1,t.width=100,t.height=100,t.radius=50,t.touchEnabled=!0,t.offset=new Nt,t.pressed=!1,t.mouse=t.inputManager.mouse,t.touch=t.inputManager.touch,t.position=new Nt,t.distance=new Nt,t.pressedLastFrame=!1,t.scaled={width:0,height:0,radius:0,offset:new Nt},t}return s(i,e),i.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},i.prototype.update=function(){this.scale(),Nt.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()},i.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))},i.prototype.resolveMouseAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed=Kt(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&Kt(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2))},i.prototype.resolveMouseAndCircumference=function(){this.type===t.ButtonType.Circumference&&(Nt.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},i.prototype.resolveTouchAndRectangle=function(){if(this.type===t.ButtonType.Rectangle)for(var e=0,i=this.touch.interactions;e<i.length;e++){var n=i[e],o=n.positionInViewport,r=n.radius;if(this.pressed)return;this.pressed=this.position.x+this.scaled.width/2>=o.x-r.x&&this.position.x-this.scaled.width/2<=o.x+r.x&&this.position.y+this.scaled.height/2>=o.y-r.y&&this.position.y-this.scaled.height/2<=o.y+r.y}},i.prototype.resolveTouchAndCircumference=function(){if(this.type===t.ButtonType.Circumference)for(var e=0,i=this.touch.interactions;e<i.length;e++){var n=i[e],o=n.positionInViewport,r=n.radius;if(this.pressed)return;Nt.subtract(this.distance,this.position,o),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(r.x,r.y)}},i}(y),Re=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.mousePressed=!1,e.position=new Nt,e}return s(e,t),e.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},e.prototype.update=function(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(Nt.round(this.position,Nt.add(this.position,this.camera.transform.position,Nt.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}(ie),Se=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 Se,this._center=new Se,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 Se&&!(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 Se,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 Ee=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 Te),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}(),Te=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new Se,this._leftStickAxes=new Se,this._rightStickAxes=new Se,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}(),De=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}(),Be=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new Se,this._hasMoved=!1,this._wheelScroll=new Se,this.lastPositionInViewport=new Se,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}(),Fe=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 Se((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 Se(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),Ie=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}(),Ue=function(){function t(t,e,i,n){this._position=new Ie,this._center=new Ie,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 Ie&&!(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 Ie,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))}}(),t.BroadPhaseMethods=void 0;var Le,ke=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=ke(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=ke(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=ke(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=ke(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}(),function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(t.BroadPhaseMethods||(t.BroadPhaseMethods={})),function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Le||(Le={})),t.CollisionMethods=void 0,function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(t.CollisionMethods||(t.CollisionMethods={}));var Ve,Ge=function(t,e){return Ge=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])},Ge(t,e)};"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Ve||(Ve={})),function(){function t(t){this.radius=t,this.type=Le.Circumference,this.boundingBox=new Ue(0,0,0,0),this.vertices=[new Ie,new Ie],this.projectionAxes=[new Ie],this._position=new Ie}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=Le.Polygon,this.vertices=[new Ie,new Ie],this.projectionAxes=[new Ie],this.boundingBox=new Ue(0,0,0,0),this.rotation=0,this._position=new Ie}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(){Ie.normal(this.projectionAxes[0],Ie.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}();var He=function(){function t(t){this.vertexModel=t,this.type=Le.Polygon,this.vertices=[],this.boundingBox=new Ue(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Ie,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 Ie),this._projectionAxes.push(new Ie)}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++)Ie.normal(this._projectionAxes[e],Ie.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 Ie(-e/2,-i/2),new Ie(-e/2,i/2),new Ie(e/2,i/2),new Ie(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new Ie,new Ie],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}Ge(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(){Ie.unit(this.projectionAxes[0],Ie.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Ie.normal(this.projectionAxes[1],this.projectionAxes[0])}}(He),t.Animator=we,t.AudioPlayer=Oe,t.BallCollider=ue,t.BoxCollider=ce,t.Button=Ae,t.Camera=oe,t.Component=g,t.EdgeCollider=fe,t.Game=Jt,t.GameCamera=re,t.GameObject=ie,t.GamepadController=Ee,t.GamepadData=Te,t.KeyboardController=De,t.LAYER_DEFAULT="Default",t.MaskRenderer=ve,t.MouseController=Be,t.PhysicsComponent=v,t.PolygonCollider=ae,t.PolygonColliderRenderer=he,t.PreRenderComponent=x,t.Rectangle=i,t.RigidBody=ee,t.Rotation=o,t.Scene=se,t.SpacePointer=Re,t.Sprite=Ce,t.SpriteRenderer=ye,t.TextRenderer=me,t.TiledTilemapRenderer=Me,t.TilemapCollider=pe,t.TilemapRenderer=_e,t.TouchController=Fe,t.Transform=Zt,t.Vector2=e,t.VideoRenderer=xe,t.between=function(t,e,i){return t>=e&&t<=i},t.clamp=function(t,e,i){return Math.min(i,Math.max(e,t))},t.fixedRound=n,t.randomFloat=function(t,e,i){return void 0===i&&(i=2),n(Math.random()*(e-t)+t,i)},t.randomInt=function(t,e){return Math.round(Math.random()*(e-t))+t},t.range=function(t,e,i){void 0===i&&(i=1);for(var n=[],o=t;o<=e;o+=i)n.push(o);return n},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["angry-pixel"]={})}(this,(function(t){"use strict";const e={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 i{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 s(t){return function(e){e.prototype.__ioc_injectable&&e.prototype.__ioc_injectable===t||(e.prototype.__ioc_injectable=t)}}function o(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 r;function a(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 n(t,e){return function(i,s){e(i,s,t)}}t.BroadPhaseMethods=void 0,(r=t.BroadPhaseMethods||(t.BroadPhaseMethods={}))[r.QuadTree=0]="QuadTree",r[r.SpartialGrid=1]="SpartialGrid","function"==typeof SuppressedError&&SuppressedError;class h{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 h),h.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 h(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 l{constructor(t=0,e=0,i=0,s=0){this.width=0,this.height=0,this._position=new h,this._center=new h,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 l?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof h&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const c=(t,e,i)=>Math.min(i,Math.max(e,t)),d=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),m=(t,e,i=1)=>{const s=[];for(let o=t;o<=e;o+=i)s.push(o);return s},g=(t,e,i)=>t>=e&&t<=i;var p;let u=p=class{constructor(t=new l,e=0){this.children=[],this.shapes=[],this.minArea=new h,this.maxArea=new h,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 l(this.area.x,this.area.y,t,e),new l(this.area.x,this.area.y+e,t,e),new l(this.area.x+t,this.area.y+e,t,e),new l(this.area.x+t,this.area.y,t,e)].map((t=>new p(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}};u=p=a([s(e.CollisionBroadphaseResolver)],u);const y=(t,e,i,s)=>Math.min((t-e)/i|0,s-1);let f=class{constructor(){this.area=new l,this.colliders=[],this.subdivisions=0,this.coordinates={x0:0,x1:0,y0:0,y1:0},this.minArea=new h,this.maxArea=new h}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=y(t.x,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.x1=y(t.x1,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.y0=y(t.y,this.area.y,this.cellHeight,this.subdivisions),this.coordinates.y1=y(t.y1,this.area.y,this.cellHeight,this.subdivisions)}};f=a([s(e.CollisionBroadphaseResolver)],f);class x{get vertexModel(){return this._vertexModel}set vertexModel(t){if(this._vertexModel=t,2===t.length)return this.vertices=[new h,new h],void(this.projectionAxes=[new h]);this.vertices=[],this.projectionAxes=[],this._vertexModel.forEach((()=>{this.vertices.push(new h),this.projectionAxes.push(new h)}))}constructor(t,e=0){this.rotation=e,this.boundingBox=new l,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new h,this.projectionAxes=[],this.radius=0,this.vertices=[],this.updateCollisions=!0,this._vertexModel=[],this.vertexModel=t}}class M{constructor(t){this.radius=t,this.boundingBox=new l,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new h,this.projectionAxes=[new h],this.rotation=0,this.vertexModel=[],this.vertices=[new h,new h],this.updateCollisions=!0}}let v=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 M&&e instanceof x?this.circumferenceAABBResolver.resolve(t,e):t instanceof x&&e instanceof M?this.circumferenceAABBResolver.resolve(e,t,!0):t instanceof M&&e instanceof M?this.circumferenceResolver.resolve(t,e):void 0}};var S;v=a([s(e.CollisionResolutionMethod),n(0,o(e.CollisionAABBResolver)),n(1,o(e.CollisionCircumferenceAABBResolver)),n(2,o(e.CollisionCircumferenceResolver))],v),t.CollisionMethods=void 0,(S=t.CollisionMethods||(t.CollisionMethods={}))[S.AABB=0]="AABB",S[S.SAT=1]="SAT";let C=class{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}findCollision(t,e){return t instanceof M&&e instanceof M?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}};C=a([s(e.CollisionResolutionMethod),n(0,o(e.CollisionCircumferenceResolver)),n(1,o(e.CollisionSatResolver))],C);let b=class{constructor(){this.direction=new h,this.resolutionDirection=new h}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:h.unit(new h,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}}};b=a([s(e.CollisionAABBResolver)],b);let w=class{constructor(){this.closestPoint=new h,this.distance=new h,this.direction=new h}resolve(t,e,i=!1){if(this.closestPoint.set(c(t.position.x,e.boundingBox.x,e.boundingBox.x1),c(t.position.y,e.boundingBox.y,e.boundingBox.y1)),h.subtract(this.distance,this.closestPoint,t.position),!(this.distance.magnitude>t.radius))return h.unit(this.direction,this.distance),{direction:i?h.scale(new h,this.direction,-1):this.direction.clone(),penetration:t.radius-this.distance.magnitude}}};w=a([s(e.CollisionCircumferenceAABBResolver)],w);let E=class{constructor(){this.distance=new h,this.direction=new h}resolve(t,e){if(h.subtract(this.distance,e.position,t.position),!(this.distance.magnitude>t.radius+e.radius))return h.unit(this.direction,this.distance),{direction:this.direction.clone(),penetration:t.radius+e.radius-this.distance.magnitude}}};E=a([s(e.CollisionCircumferenceResolver)],E);let R=class{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new h,this.distance=new h(1/0,1/0),this.cache=new h}resolve(t,e){this.minOverlap=1/0,t instanceof M?this.setCircumferenceAxis(t,e):e instanceof M&&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 M?this.setCircumferenceVertices(t,this.axes[i]):e instanceof M&&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,h.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&&h.scale(this.smallestAxis,this.axes[i],-1))}return{direction:h.scale(new h,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(h.dot(i,e),t.min),t.max=Math.max(h.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{h.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),h.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){h.add(t.vertices[0],t.position,h.scale(this.cache,h.unit(this.cache,e),-t.radius)),h.add(t.vertices[1],t.position,h.scale(this.cache,h.unit(this.cache,e),t.radius))}};R=a([s(e.CollisionSatResolver)],R),t.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=[]}},t.CollisionRepository=a([s(e.CollisionRepository)],t.CollisionRepository),t.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}},t.EntityManager=a([s(e.EntityManager)],t.EntityManager),t.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()))}},t.SystemManager=a([s(e.SystemManager)],t.SystemManager);class _{constructor(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new h,this._leftStickAxes=new h,this._rightStickAxes=new h}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 A{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 T{constructor(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new h,this.hasMoved=!1,this.wheelScroll=new h}}class B{constructor(){this.touching=!1,this.interactions=[]}}t.InputManager=class{constructor(){this.keyboard=new A,this.mouse=new T,this.touchScreen=new B,this.gamepads=[]}},t.InputManager=a([s(e.InputManager)],t.InputManager);const D=[60,120,180,240];var P;t.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&&!D.includes(t))throw new Error(`Invalid Physics frame rate. Allowed: [${D.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}},t.TimeManager=a([s(e.TimeManager),n(0,o(e.GameConfig))],t.TimeManager),function(t){t[t.Image=0]="Image",t[t.Audio=1]="Audio",t[t.Font=2]="Font",t[t.Video=3]="Video"}(P||(P={})),t.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,P.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,P.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,P.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,P.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===P.Image&&e.url===t)))||void 0===e?void 0:e.element}getAudio(t){var e;return null===(e=this.assets.find((e=>e.type===P.Audio&&e.url===t)))||void 0===e?void 0:e.element}getFont(t){var e;return null===(e=this.assets.find((e=>e.type===P.Font&&e.family===t)))||void 0===e?void 0:e.element}getVideo(t){var e;return null===(e=this.assets.find((e=>e.type===P.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}},t.AssetManager=a([s(e.AssetManager)],t.AssetManager);class U{constructor(t){this.action="stop",this.loop=!1,this.playing=!1,this.volume=1,this._currentAudio=void 0,Object.assign(this,t)}}const F={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")},L=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let I=class{constructor(t,e,i){this.entityManager=t,this.inputManager=e,this.timeManager=i,this.canPlay=!1,this.userInputEventHandler=()=>{L.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,L.forEach((t=>window.addEventListener(t,this.userInputEventHandler))),document.addEventListener("visibilitychange",(()=>{this.entityManager.search(U).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(U).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(U).forEach((({component:{audioSource:t}})=>{t&&(t.pause(),t.currentTime=0)}))}onDestroy(){this.onDisable()}};var j;I=a([s(F.AudioPlayerSystem),n(0,o(e.EntityManager)),n(1,o(e.InputManager)),n(2,o(e.TimeManager))],I),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"}(j||(j={}));const k=(t,e)=>{t.prototype.__system_group||(t.prototype.__system_group=e)};class O{get parent(){return this._parent}set parent(t){this._parent!==t&&(this._parent=t,this._parent?(this.localPosition.copy(this.position),h.subtract(this.position,this.position,this._parent.position)):this.position.copy(this.localPosition))}constructor(t){this.position=new h,this.scale=new h(1,1),this.rotation=0,this.localPosition=new h,this.localScale=new h(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 V="Default";class G{constructor(t){this.layers=[V],this.zoom=1,this.depth=0,this._renderData={position:new h,depth:0,zoom:1,layers:[]},Object.assign(this,t)}}var W;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(W||(W={}));class z{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(W.WebGL2)?W.WebGL2:null!==this.canvas.getContext(W.LegacyWebGL)?W.LegacyWebGL:void 0}}class H{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 N(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 N{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 Y{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 X{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===W.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 ${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 K="undefined"!=typeof Float32Array?Float32Array:Array;function q(){var t=new K(16);return K!=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 J(t,e,i){var s,o,r,a,n,h,l,c,d,m,g,p,u=i[0],y=i[1],f=i[2];return e===t?(t[12]=e[0]*u+e[4]*y+e[8]*f+e[12],t[13]=e[1]*u+e[5]*y+e[9]*f+e[13],t[14]=e[2]*u+e[6]*y+e[10]*f+e[14],t[15]=e[3]*u+e[7]*y+e[11]*f+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],m=e[9],g=e[10],p=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]=m,t[10]=g,t[11]=p,t[12]=s*u+n*y+d*f+e[12],t[13]=o*u+h*y+m*f+e[13],t[14]=r*u+l*y+g*f+e[14],t[15]=a*u+c*y+p*f+e[15]),t}function Z(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 tt(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],m=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+m*s,t[4]=l*o-r*s,t[5]=c*o-a*s,t[6]=d*o-n*s,t[7]=m*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 et=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 it=(t,e,i,s)=>{t=Q(t),et(t,-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),Z(t,t,[null!=i?i:1,null!=i?i:1,1]),J(t,t,[-s.x,-s.y,0])},st=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 ot{constructor(t){this.gl=t}render(t){const e=st(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var rt,at,nt;!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(rt||(rt={}));class ht{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(m(1,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e){switch(t.shape){case rt.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP);break;case rt.Line:this.renderLines(t,e,this.gl.LINES);break;case rt.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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(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}=st(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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Z(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),it(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}=st(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"}(at||(at={})),t.MaskShape=void 0,(nt=t.MaskShape||(t.MaskShape={}))[nt.Rectangle=0]="Rectangle",nt[nt.Circumference=1]="Circumference";let lt=class{constructor(t,e){this.gl=t,this.programManager=e,this.type=at.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q();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(e,i,s){var o,r;s===at.Mask&&this.lastShape===e.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,e.shape===t.MaskShape.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=Q(this.modelMatrix),J(this.modelMatrix,this.modelMatrix,[e.position.x,e.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(o=e.rotation)&&void 0!==o?o:0),Z(this.modelMatrix,this.modelMatrix,e.shape===t.MaskShape.Rectangle?[e.width,e.height,1]:[e.radius,e.radius,1]),it(this.projectionMatrix,this.gl,i.zoom,i.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),e.opacity>=0&&e.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:a,g:n,b:h,a:l}=st(e.color);return this.gl.uniform4f(this.programManager.solidColorUniform,a,n,h,l),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=e.opacity)&&void 0!==r?r:1),e.shape===t.MaskShape.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=e.shape,!0}},ct=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=q(),this.modelMatrix=q(),this.textureMatrix=q()}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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(i=t.rotation)&&void 0!==i?i:0),Z(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),it(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}=st(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}},dt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q(),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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),Z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontally?-1:1),t.height*(t.flipVertically?-1:1),1]),this.textureMatrix=Q(this.textureMatrix),t.slice&&(J(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),Z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),it(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}=st(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}=st(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 mt;t.TextOrientation=void 0,(mt=t.TextOrientation||(t.TextOrientation={}))[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,s){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=s,this.type=at.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new h,this.modelPosition=new h,this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q()}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),J(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),Z(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=Q(this.textureMatrix),it(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===at.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}=st(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,m=(r+t.bitmapFontSize+s.spacing.y)/t.canvas.width;this.texVertices.push(h,m,d,m,h,l,h,l,d,m,d,l),a+=e+o}}this.textSize.set(Math.max(h,a)*i,Math.abs(n-1)*i)}setPositionFromOrientation(e){this.modelPosition.set(e.position.x+(e.orientation===t.TextOrientation.Center?-this.textSize.x/2:0),e.position.y+(e.orientation===t.TextOrientation.Center||e.orientation===t.TextOrientation.RightCenter?this.textSize.y/2:e.orientation===t.TextOrientation.RightUp?this.textSize.y:0))}};var pt;t.TilemapOrientation=void 0,(pt=t.TilemapOrientation||(t.TilemapOrientation={}))[pt.Center=0]="Center",pt[pt.RightUp=1]="RightUp",pt[pt.RightDown=2]="RightDown",pt[pt.RightCenter=3]="RightCenter";let ut=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 h,texSpacing:new h,texWidth:0,texHeight:0,texCorrection:new h},this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q()}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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),Z(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=Q(this.textureMatrix),Z(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),it(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===at.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}=st(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}=st(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,n;t.margin=null!==(e=t.margin)&&void 0!==e?e:new h,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new h,t.correction=null!==(s=t.correction)&&void 0!==s?s:new h,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!==(n=t.spacing.y)&&void 0!==n?n: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)}))}},yt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=q(),this.modelMatrix=q(),this.textureMatrix=q(),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),J(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),tt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),Z(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=Q(this.textureMatrix),t.slice&&(J(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),Z(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),it(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}=st(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}=st(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 ft{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 Mt=class{constructor(t){this.renderers=new Map;const e=new z(t),i=e.gl,s=e.contextVersion,o=new X(i,s,new Y(i,new $(i))),r=new xt(new ft(i)),a=new H;this.renderers.set(at.Sprite,new dt(i,o,r)),this.renderers.set(at.Text,new gt(i,o,r,a)),this.renderers.set(at.Tilemap,new ut(i,o,r)),this.renderers.set(at.Geometric,new ht(i,o)),this.renderers.set(at.Mask,new lt(i,o)),this.renderers.set(at.Video,new yt(i,o,r)),this.renderers.set(at.Shadow,new ct(i,o)),this.canvasColorRenderer=new ot(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)}};Mt=a([s(e.WebGLManager),n(0,o(e.CanvasElement))],Mt);class vt{constructor(t){this.offset=new h,this.rotation=0,this.layer=V,this.loop=!1,this.volume=1,this.play=!1,this.pause=!1,this._renderData={type:at.Video,height:void 0,layer:void 0,position:new h,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 St=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Ct=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.timeManager=i,this.scaledOffset=new h,this.userInputEventHandler=()=>{St.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,St.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}onUpdate(){this.entityManager.search(vt).forEach((({entity:t,component:e})=>{var i,s;const o=this.entityManager.getComponent(t,O);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),h.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(vt).forEach((({component:t})=>{t.video&&(t.video.pause(),t.video.currentTime=0)}))}onDestroy(){this.onDisable()}};Ct=a([s(F.VideoRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager)),n(2,o(e.TimeManager))],Ct);t.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(j.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(I),this.systemManager.disableSystem(Ct),this.entityManager.removeAllEntities(),this.scenes.get(this.currentSceneName).systems.forEach((t=>this.systemManager.disableSystem(t))),this.systemManager.enableSystem(I),this.systemManager.enableSystem(Ct)}},t.SceneManager=a([s(e.SceneManager),n(0,o(e.SystemManager)),n(1,o(e.SystemFactory)),n(2,o(e.EntityManager)),n(3,o(e.AssetManager))],t.SceneManager);class bt{constructor(t){this.width=0,this.height=0,this.radius=0,this.touchEnabled=!0,this.offset=new h,this.pressed=!1,Object.assign(this,t)}}var wt;t.ButtonShape=void 0,(wt=t.ButtonShape||(t.ButtonShape={}))[wt.Rectangle=0]="Rectangle",wt[wt.Circumference=1]="Circumference";let Et=class{constructor(t,e){this.entityManager=t,this.scaled={position:new h,width:0,height:0,radius:0},this.distance=new h,this.pressedLastFrame=!1,this.mouse=e.mouse,this.touchScreen=e.touchScreen}onUpdate(){this.entityManager.search(bt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,O);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(e){e.shape===t.ButtonShape.Rectangle&&(e.pressed=g(this.mouse.positionInViewport.x,this.scaled.position.x-this.scaled.width/2,this.scaled.position.x+this.scaled.width/2)&&g(this.mouse.positionInViewport.y,this.scaled.position.y-this.scaled.height/2,this.scaled.position.y+this.scaled.height/2))}resolveMouseAndCircumference(e){e.shape===t.ButtonShape.Circumference&&(h.subtract(this.distance,this.scaled.position,this.mouse.positionInViewport),e.pressed=this.distance.magnitude<=this.scaled.radius)}resolveTouchAndRectangle(e){if(e.shape===t.ButtonShape.Rectangle)for(const{positionInViewport:t,radius:i}of this.touchScreen.interactions){if(e.pressed)return;e.pressed=this.scaled.position.x+this.scaled.width/2>=t.x-i.x&&this.scaled.position.x-this.scaled.width/2<=t.x+i.x&&this.scaled.position.y+this.scaled.height/2>=t.y-i.y&&this.scaled.position.y-this.scaled.height/2<=t.y+i.y}}resolveTouchAndCircumference(e){if(e.shape===t.ButtonShape.Circumference)for(const{positionInViewport:t,radius:i}of this.touchScreen.interactions){if(e.pressed)return;h.subtract(this.distance,this.scaled.position,t),e.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(i.x,i.y)}}};Et=a([s(F.ButtonSystem),n(0,o(e.EntityManager)),n(1,o(e.InputManager))],Et);class Rt{constructor(){this.entities=[]}}let _t=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Rt).forEach((({entity:t,component:e})=>{e.entities=this.entityManager.getComponent(t,O)._childEntities}))}};_t=a([s(F.ChildrenSystem),n(0,o(e.EntityManager))],_t);class At{}let Tt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(At).forEach((({entity:t,component:e})=>{e.entity=this.entityManager.getComponent(t,O)._parentEntity}))}};Tt=a([s(F.ParentSystem),n(0,o(e.EntityManager))],Tt);class Bt{constructor(t){Object.assign(this,t)}}class Dt{constructor(t){this.layer=V,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 Pt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Bt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,Dt);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)}))}};Pt=a([s(F.TiledWrapperSystem),n(0,o(e.EntityManager))],Pt);const Ut=16;let Ft=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Dt).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/Ut),i=Math.ceil(t.height/Ut);for(let s=0;s<i;s++)for(let i=0;i<e;i++){const e={x:i*Ut,y:s*Ut,width:Ut,height:Ut,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)}};Ft=a([s(F.TilemapPreProcessingSystem),n(0,o(e.EntityManager))],Ft);const Lt=t=>t.parent?1+Lt(t.parent):0;let It=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(O).sort(((t,e)=>Lt(t.component)-Lt(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))}};It=a([s(F.TransformSystem),n(0,o(e.EntityManager))],It);let jt=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 _,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:[]}};jt=a([s(F.GamepadSystem),n(0,o(e.InputManager))],jt);let kt=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]}};kt=a([s(F.KeyboardSystem),n(0,o(e.CanvasElement)),n(1,o(e.InputManager))],kt);let Ot=class{constructor(t,{mouse:e}){this.canvas=t,this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new h,this.lastPositionInViewport=new h,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)}};Ot=a([s(F.MouseSystem),n(0,o(e.CanvasElement)),n(1,o(e.InputManager))],Ot);let Vt=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 h((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 h(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}}onUpdate(){this.touchScreen.touching=this.touching,this.touchScreen.interactions=[...this.touchScreen.interactions]}};Vt=a([s(F.TouchScreenSystem),n(0,o(e.CanvasElement)),n(1,o(e.InputManager))],Vt);class Gt{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 Wt{constructor(t){this.layer=V,this.smooth=!1,this.offset=new h,this.flipHorizontally=!1,this.flipVertically=!1,this.rotation=0,this.opacity=1,this.scale=new h(1,1),this._renderData={type:at.Sprite,position:new h,layer:void 0,image:void 0,width:void 0,height:void 0},Object.assign(this,t)}}let zt=class{constructor(t,e){this.entityManager=t,this.timeManager=e}onUpdate(){this.entityManager.search(Gt).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,Wt);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}}}};zt=a([s(F.AnimatorSystem),n(0,o(e.EntityManager)),n(1,o(e.TimeManager))],zt);let Ht=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(G).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,O);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)}))}};Ht=a([s(F.CameraSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],Ht);let Nt=class{constructor(t,e){this.webGLManager=t,this.gameConfig=e}onUpdate(){this.webGLManager.renderCanvasColor(this.gameConfig.canvasColor)}};Nt=a([s(F.ClearScreenSystem),n(0,o(e.WebGLManager)),n(1,o(e.GameConfig))],Nt);class Yt{constructor(t){this.radius=0,this.offset=new h,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class Xt{constructor(t){this.layer="",this.physics=!0,this.width=0,this.height=0,this.offset=new h,this.rotation=0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class $t{constructor(t){this.vertexModel=[],this.offset=new h,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class Kt{constructor(t){this.vertexModel=[],this.offset=new h,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class qt{constructor(t){this.composite=!0,this.layer="",this.ignoreCollisionsWithLayers=[],this.offset=new h,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&&[Yt,Xt,Kt,$t,qt].forEach((e=>this.entityManager.search(e).forEach((({component:e})=>e.shapes.forEach((e=>{const i={type:at.Geometric,position:new h,layer:V,color:"#00FF00",shape:void 0,radius:void 0,rotation:void 0,vertexModel:void 0};e instanceof x?this.collisionMethod===t.CollisionMethods.SAT?(i.shape=e.vertices.length>2?rt.Polygon:rt.Line,i.vertexModel=e.vertices):this.collisionMethod===t.CollisionMethods.AABB&&(i.shape=rt.Polygon,i.vertexModel=[new h(e.boundingBox.x,e.boundingBox.y),new h(e.boundingBox.x,e.boundingBox.y1),new h(e.boundingBox.x1,e.boundingBox.y1),new h(e.boundingBox.x1,e.boundingBox.y)]):e instanceof M&&(i.shape=rt.Circumference,i.position.copy(e.position),i.radius=e.radius),this.renderManager.addRenderData(i)}))))))}};Qt=a([s(F.ColliderRenderSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager)),n(2,o(e.GameConfig))],Qt);let Jt=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===at.Tilemap&&this.applyCullingInTiles(t),this.culledRenderData.push(t))}))})),this.renderManager.setRenderData(this.culledRenderData)}isInViewPort(t){switch(t.type){case at.Video:case at.Mask:case at.Shadow:case at.Sprite:this.setObjectForResizeable(t);break;case at.Geometric:this.setObjectForGeometric(t);break;case at.Text:this.setObjectForText(t);break;case at.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===rt.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))}};Jt=a([s(F.CullingSystem),n(0,o(e.RenderManager)),n(1,o(e.CanvasElement))],Jt);class Zt{constructor(t){this.width=0,this.height=0,this.radius=0,this.offset=new h,this.rotation=0,this.opacity=1,this.layer=V,this._renderData={type:at.Mask,color:void 0,height:void 0,layer:void 0,opacity:void 0,position:new h,radius:void 0,rotation:void 0,shape:void 0,width:void 0},Object.assign(this,t)}}let te=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new h}onUpdate(){this.entityManager.search(Zt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,O);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),h.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))}};te=a([s(F.MaskRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],te);let ee=class{constructor(t){this.renderManager=t}onUpdate(){this.renderManager.render(),this.renderManager.removeCameraData(),this.renderManager.removeRenderData()}};ee=a([s(F.RenderSystem),n(0,o(e.RenderManager))],ee);class ie{constructor(t){this.radius=0,this.smooth=!1,this.layer="",this.intensity=1,this._boundingBox=new l,Object.assign(this,t)}}class se{constructor(t){this.width=0,this.height=0,this.color="#000000",this.opacity=1,this.layer="",this._boundingBox=new l,this._renderData={type:at.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 oe=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){const t=this.entityManager.search(ie);t.forEach((({entity:t,component:e})=>this.updateLightRendererBoundingBox(t,e))),this.entityManager.search(se).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,O);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,O);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)}};oe=a([s(F.ShadowLightRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],oe);let re=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new h}onUpdate(){this.entityManager.search(Wt).forEach((({component:t,entity:e})=>{var i,s,o,r,a,n;const l=this.entityManager.getComponent(e,O);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),h.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!==(n=null!==(r=t.height)&&void 0!==r?r:null===(a=t.slice)||void 0===a?void 0:a.height)&&void 0!==n?n: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))}};re=a([s(F.SpriteRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],re);class ae{constructor(e){this.layer=V,this.text="Hello World!",this.font="Arial",this.fontSize=16,this.width=160,this.height=16,this.offset=new h,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=t.TextOrientation.Center,this.bitmapMargin=new h,this.bitmapSpacing=new h,this._renderData={type:at.Text,position:new h,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,e)}}let ne=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new h}onUpdate(){this.entityManager.search(ae).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,O);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),h.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")}};ne=a([s(F.TextRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],ne);let he=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(Dt).forEach((({entity:e,component:i})=>{const s=this.entityManager.getComponent(e,O);if(!s)throw new Error("TilemapRenderer component needs a Transform");i._processed&&i.tileset.image&&i.tileset.image.complete&&i.chunks.forEach(((e,o)=>{i._renderData[o]||(i._renderData[o]=le());const r=i._renderData[o];r.type=at.Tilemap,r.orientation=t.TilemapOrientation.Center,r.position=new h,r.layer=i.layer,r.tilemap.width=e.width,r.tilemap.height=Math.ceil(i.data.length/e.width),r.tilemap.tileWidth=i.tileWidth*Math.abs(s.localScale.x),r.tilemap.tileHeight=i.tileHeight*Math.abs(s.localScale.y),r.tilemap.realWidth=r.tilemap.width*r.tilemap.tileWidth,r.tilemap.realHeight=r.tilemap.height*r.tilemap.tileHeight,r.tiles=e.data,r.tileset=i.tileset,r.opacity=i.opacity,r.rotation=s.localRotation,r.tintColor=i.tintColor,r.smooth=i.smooth,r.position.x=s.localPosition.x+(e.x-i.width/2+e.width/2)*r.tilemap.tileWidth,r.position.y=s.localPosition.y+(i.height/2-e.y-e.height/2)*r.tilemap.tileHeight,this.renderManager.addRenderData(r)}))}))}};he=a([s(F.TilemapRendererSystem),n(0,o(e.EntityManager)),n(1,o(e.RenderManager))],he);const le=()=>({type:at.Tilemap,layer:void 0,position:new h,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 ce;t.RigidBodyType=void 0,(ce=t.RigidBodyType||(t.RigidBodyType={}))[ce.Dynamic=0]="Dynamic",ce[ce.Static=1]="Static";class de{constructor(e){this.type=t.RigidBodyType.Dynamic,this.velocity=new h,this.gravity=0,this.acceleration=new h,Object.assign(this,e)}}let me=class{constructor(t,e,i){this.entityManager=t,this.timeManager=e,this.transformSystem=i,this.distance=new h}onUpdate(){this.entityManager.search(de,{type:t.RigidBodyType.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,O);t.velocity.y-=t.gravity*this.timeManager.physicsDeltaTime,h.add(i.position,i.position,h.scale(this.distance,h.add(t.velocity,t.velocity,t.acceleration),this.timeManager.physicsDeltaTime))})),this.transformSystem.onUpdate()}};me=a([s(F.ApplyVelocitySystem),n(0,o(e.EntityManager)),n(1,o(e.TimeManager)),n(2,o(F.TransformSystem))],me);class ge{constructor(){this.auxMin=new h,this.auxMax=new h,this.auxScaledOffset=new h}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 M&&(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 h.add(t.position,i,this.auxScaledOffset)}updateBoundingBox(t){t instanceof M?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++)h.normal(t.projectionAxes[i],h.subtract(t.projectionAxes[i],null!==(e=t.vertices[i+1])&&void 0!==e?e:t.vertices[0],t.vertices[i]));else h.normal(t.projectionAxes[0],h.subtract(t.projectionAxes[0],t.vertices[1],t.vertices[0]))}}let pe=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Yt).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new M(t.radius)),t.shapes[0].radius=t.radius,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,O)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};pe=a([s(F.UpdateBallColliderShapeSystem),n(0,o(e.EntityManager))],pe);let ue=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Xt).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new x([new h,new h,new h,new h])),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,O)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};ue=a([s(F.UpdateBoxColliderShapeSystem),n(0,o(e.EntityManager))],ue);let ye=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search($t).forEach((({component:t,entity:e})=>{for(let i=0;i<t.vertexModel.length-1;i++)t.shapes[i]||(t.shapes[i]=new x([new h,new h])),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,O)),this.updateBoundingBox(t.shapes[i]),this.updateProjectionAxes(t.shapes[i])}))}};ye=a([s(F.UpdateEdgeColliderShapeSystem),n(0,o(e.EntityManager))],ye);let fe=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Kt).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,O)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};fe=a([s(F.UpdatePolygonColliderShapeSystem),n(0,o(e.EntityManager))],fe);let xe=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(qt).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,Dt);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,O)),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 h(r,a-o),new h(r,a),new h(r+s,a),new h(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 h(a,s)),r=new h(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 h(i,a)),r=new h(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 h(t.x,t.y),new h(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=a([s(F.UpdateTilemapColliderShapeSystem),n(0,o(e.EntityManager))],xe);let Me=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=[],[Yt,Xt,Kt,$t,qt].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:h.scale(new h,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}`)}};Me=a([s(F.ResolveCollisionSystem),n(0,o(e.EntityManager)),n(1,o(e.CollisionBroadphaseResolver)),n(2,o(e.CollisionMatrix)),n(3,o(e.CollisionResolutionMethod)),n(4,o(e.CollisionRepository))],Me);let ve=class{constructor(t,e,i){this.entityManager=t,this.collisionRepository=e,this.transformSystem=i,this.displacement=new h}onUpdate(){this.entityManager.search(de,{type:t.RigidBodyType.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,O),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&&h.scale(this.displacement,t,-e)})),0!==this.displacement.magnitude&&(h.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()}};ve=a([s(F.ApplyRepositionSystem),n(0,o(e.EntityManager)),n(1,o(e.CollisionRepository)),n(2,o(F.TransformSystem))],ve);let Se=class extends ge{constructor(t){super(),this.entityManager=t}onUpdate(){[Yt,Xt,Kt,$t,qt].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,O)),this.updateBoundingBox(i)}))))))}};Se=a([s(F.UpdateCollidersAfterRepositionSystem),n(0,o(e.EntityManager))],Se);const Ce=new Map([[j.PreGameLogic,[{name:F.KeyboardSystem,type:kt},{name:F.MouseSystem,type:Ot},{name:F.TouchScreenSystem,type:Vt},{name:F.GamepadSystem,type:jt},{name:F.ButtonSystem,type:Et},{name:F.AudioPlayerSystem,type:I},{name:F.TiledWrapperSystem,type:Pt},{name:F.TilemapPreProcessingSystem,type:Ft}]],[j.PostGameLogic,[{name:F.TransformSystem,type:It},{name:F.ChildrenSystem,type:_t},{name:F.ParentSystem,type:Tt}]],[j.Physics,[{name:F.ApplyVelocitySystem,type:me},{name:F.UpdateBallColliderShapeSystem,type:pe},{name:F.UpdateBoxColliderShapeSystem,type:ue},{name:F.UpdateEdgeColliderShapeSystem,type:ye},{name:F.UpdatePolygonColliderShapeSystem,type:fe},{name:F.UpdateTilemapColliderShapeSystem,type:xe},{name:F.ResolveCollisionSystem,type:Me},{name:F.ApplyRepositionSystem,type:ve},{name:F.UpdateCollidersAfterRepositionSystem,type:Se}]],[j.Render,[{name:F.AnimatorSystem,type:zt},{name:F.CameraSystem,type:Ht},{name:F.TilemapRendererSystem,type:he},{name:F.SpriteRendererSystem,type:re},{name:F.MaskRendererSystem,type:te},{name:F.ShadowLightRendererSystem,type:oe},{name:F.TextRendererSystem,type:ne},{name:F.VideoRendererSystem,type:Ct},{name:F.ColliderRenderSystem,type:Qt},{name:F.CullingSystem,type:Jt},{name:F.ClearScreenSystem,type:Nt},{name:F.RenderSystem,type:ee}]]]);let be=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(){Ce.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(j.PreGameLogic),this.systemManager.update(j.GameLogic),this.systemManager.update(j.PostGameLogic)}renderIteration(){this.systemManager.update(j.GamePreRender),this.systemManager.update(j.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(j.GamePhysics),this.systemManager.update(j.Physics))}};be=a([s(e.LoopManager),n(0,o(e.TimeManager)),n(1,o(e.SystemManager)),n(2,o(e.SceneManager))],be);class we{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:j.GameLogic)}}let Ee=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)))))}};Ee=a([s(e.RenderManager),n(0,o(e.WebGLManager))],Ee);const Re=e=>{var i,s,o,r,a,n,h,l;if(!(e.containerNode instanceof HTMLElement))throw new Error("GameConfig Error: Invalid containerNode");if("number"!=typeof e.width)throw new Error("GameConfig Error: Invalid width");if("number"!=typeof e.height)throw new Error("GameConfig Error: Invalid height");e.debugEnabled=null!==(i=e.debugEnabled)&&void 0!==i&&i,e.canvasColor=null!==(s=e.canvasColor)&&void 0!==s?s:"#000000",e.physicsFramerate=null!==(o=e.physicsFramerate)&&void 0!==o?o:180,e.headless=null!==(r=e.headless)&&void 0!==r&&r,e.collisions=null!==(a=e.collisions)&&void 0!==a?a:{},e.collisions.collisionBroadPhaseMethod=null!==(n=e.collisions.collisionBroadPhaseMethod)&&void 0!==n?n:t.BroadPhaseMethods.SpartialGrid,e.collisions.collisionMatrix=null!==(h=e.collisions.collisionMatrix)&&void 0!==h?h:void 0,e.collisions.collisionMethod=null!==(l=e.collisions.collisionMethod)&&void 0!==l?l:t.CollisionMethods.SAT},_e=({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},Ae=i=>{i.add(t.EntityManager),i.add(t.SystemManager),i.set(e.SystemFactory,new we(i,i.get(e.SystemManager))),i.add(t.TimeManager),i.add(t.AssetManager),i.add(t.InputManager),i.add(t.SceneManager),i.add(t.InputManager),i.add(be),i.add(Mt),i.add(Ee)},Te=t=>{t.get(e.GameConfig).headless&&Be(Ce),Ce.forEach(((i,s)=>i.forEach((({type:i,name:o})=>{t.add(i),t.get(e.SystemManager).addSystem(t.get(o),s)}))))},Be=t=>{t.delete(j.Render),t.set(j.PreGameLogic,t.get(j.PreGameLogic).filter((({name:t})=>![F.AudioPlayerSystem,F.ButtonSystem,F.GamepadSystem,F.KeyboardSystem,F.MouseSystem,F.TouchScreenSystem].includes(t))))},De=i=>{const{collisions:{collisionBroadPhaseMethod:s,collisionMatrix:o,collisionMethod:r}}=i.get(e.GameConfig);i.add(t.CollisionRepository),i.add(E),r===t.CollisionMethods.AABB?(i.add(b),i.add(w)):i.add(R),i.add(s===t.BroadPhaseMethods.QuadTree?u:f),i.add(r===t.CollisionMethods.AABB?v:C),i.set(e.CollisionMatrix,o)};class Pe{onUpdate(){}}a([o(e.EntityManager)],Pe.prototype,"entityManager",void 0),a([o(e.AssetManager)],Pe.prototype,"assetManager",void 0),a([o(e.SceneManager)],Pe.prototype,"sceneManager",void 0),a([o(e.TimeManager)],Pe.prototype,"timeManager",void 0),a([o(e.InputManager)],Pe.prototype,"inputManager",void 0),a([o(e.CollisionRepository)],Pe.prototype,"collisionRepository",void 0);const Ue={AssetManager:e.AssetManager,CanvasElement:e.CanvasElement,CollisionRepository:e.CollisionRepository,EntityManager:e.EntityManager,GameConfig:e.GameConfig,InputManager:e.InputManager,SceneManager:e.SceneManager,SystemManager:e.SystemManager,TimeManager:e.TimeManager};t.Animation=class{constructor(t){this.slice={size:new h,offset:new h,padding:new h},this.frames=[],this.fps=12,this.loop=!1,Object.assign(this,t)}},t.Animator=Gt,t.AudioPlayer=U,t.BallCollider=Yt,t.BoxCollider=Xt,t.Button=bt,t.Camera=G,t.Children=Rt,t.Circumference=M,t.EdgeCollider=$t,t.Game=class{constructor(t){this.container=(t=>{Re(t);const s=new i;return s.set(e.GameConfig,t),s.set(e.CanvasElement,_e(t)),De(s),Ae(s),Te(s),s})(t)}get running(){return this.container.get(e.LoopManager).running}addScene(t,i,s=!1){this.container.get(e.SceneManager).addScene(t,i,s)}addDependencyType(t,e){this.container.add(t,e)}addDependencyInstance(t,e){this.container.set(e,t)}start(){this.container.get(e.LoopManager).start()}stop(){this.container.get(e.LoopManager).stop()}},t.GameSystem=Pe,t.GamepadController=_,t.Keyboard=A,t.LightRenderer=ie,t.MaskRenderer=Zt,t.Mouse=T,t.Parent=At,t.Polygon=x,t.PolygonCollider=Kt,t.Rectangle=l,t.RigidBody=de,t.Scene=class{constructor(t,e){this.entityManager=t,this.assetManager=e}loadAssets(){}setup(){}},t.ShadowRenderer=se,t.SpriteRenderer=Wt,t.Symbols=Ue,t.TextRenderer=ae,t.TiledWrapper=Bt,t.TilemapCollider=qt,t.TilemapRenderer=Dt,t.TouchScreen=B,t.Transform=O,t.Vector2=h,t.VideoRenderer=vt,t.between=g,t.clamp=c,t.defaultRenderLayer=V,t.fixedRound=d,t.gameLogicSystem=function(){return function(t){k(t,j.GameLogic)}},t.gamePhysicsSystem=function(){return function(t){k(t,j.GamePhysics)}},t.gamePreRenderSystem=function(){return function(t){k(t,j.GamePreRender)}},t.inject=o,t.injectable=s,t.randomFloat=(t,e,i=2)=>d(Math.random()*(e-t)+t,i),t.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,t.range=m}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|