angry-pixel 1.1.13 → 1.1.14

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.
Files changed (53) hide show
  1. package/lib/component/Animator.d.ts +33 -33
  2. package/lib/component/AudioPlayer.d.ts +59 -59
  3. package/lib/component/Button.d.ts +42 -42
  4. package/lib/component/Camera.d.ts +21 -21
  5. package/lib/component/RigidBody.d.ts +23 -23
  6. package/lib/component/Sprite.d.ts +22 -22
  7. package/lib/component/Transform.d.ts +30 -30
  8. package/lib/component/collider/BallCollider.d.ts +25 -25
  9. package/lib/component/collider/BoxCollider.d.ts +33 -33
  10. package/lib/component/collider/Collider.d.ts +35 -35
  11. package/lib/component/collider/EdgeCollider.d.ts +29 -29
  12. package/lib/component/collider/PolygonCollider.d.ts +40 -40
  13. package/lib/component/collider/TilemapCollider.d.ts +29 -29
  14. package/lib/component/rendering/MaskRenderer.d.ts +28 -28
  15. package/lib/component/rendering/SpriteRenderer.d.ts +44 -44
  16. package/lib/component/rendering/TextRenderer.d.ts +47 -47
  17. package/lib/component/rendering/TiledTilemapRenderer.d.ts +79 -79
  18. package/lib/component/rendering/TilemapRenderer.d.ts +55 -55
  19. package/lib/core/Component.d.ts +86 -86
  20. package/lib/core/Game.d.ts +44 -44
  21. package/lib/core/GameActor.d.ts +99 -99
  22. package/lib/core/GameConfig.d.ts +18 -18
  23. package/lib/core/GameObject.d.ts +133 -133
  24. package/lib/core/Scene.d.ts +13 -13
  25. package/lib/core/facades/AssetManagerFacade.d.ts +41 -41
  26. package/lib/core/facades/DomManagerFacade.d.ts +8 -8
  27. package/lib/core/facades/GameObjectManagerFacade.d.ts +70 -70
  28. package/lib/core/facades/InputManagerFacade.d.ts +13 -13
  29. package/lib/core/facades/SceneManagerFacade.d.ts +18 -18
  30. package/lib/core/facades/TimeManagerFacade.d.ts +11 -11
  31. package/lib/core/ioc/Config.d.ts +3 -3
  32. package/lib/core/managers/AssetManager.d.ts +28 -28
  33. package/lib/core/managers/DomManager.d.ts +9 -9
  34. package/lib/core/managers/GameObjectManager.d.ts +21 -21
  35. package/lib/core/managers/HeadlessIterationManager.d.ts +29 -29
  36. package/lib/core/managers/IterationManager.d.ts +56 -56
  37. package/lib/core/managers/SceneManager.d.ts +22 -22
  38. package/lib/core/managers/TimeManager.d.ts +24 -24
  39. package/lib/gameObject/GameCamera.d.ts +16 -16
  40. package/lib/gameObject/SpacePointer.d.ts +8 -8
  41. package/lib/index.cjs.js +1 -1
  42. package/lib/index.d.ts +38 -38
  43. package/lib/index.esm.js +1 -1
  44. package/lib/index.js +1 -1
  45. package/lib/input/GamepadController.d.ts +51 -63
  46. package/lib/input/InputManager.d.ts +12 -12
  47. package/lib/input/KeyboardController.d.ts +12 -12
  48. package/lib/input/MouseController.d.ts +21 -21
  49. package/lib/input/TouchController.d.ts +13 -13
  50. package/lib/utils/Container.d.ts +12 -12
  51. package/lib/utils/Exception.d.ts +4 -4
  52. package/lib/utils/UUID.d.ts +1 -1
  53. package/package.json +4 -4
package/lib/index.js CHANGED
@@ -1 +1 @@
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";class e{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))}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 e(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 i{constructor(t,i,n,r){this._position=new e,this._center=new e,this._width=0,this._height=0,this.set(t,i,n,r)}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 width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}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 i?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof e&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const n=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),r=(t,e,i)=>t>=e&&t<=i;class s{constructor(t=null,i=null){this._degrees=0,this._radians=0,this._direction=new e,t?this.radians=t:i&&(this.degrees=i)}set degrees(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()}get degrees(){return this._degrees}set radians(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()}get radians(){return this._radians}get direction(){return this._direction}updateDirection(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var h=function(){return h=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},h.apply(this,arguments)};function l(t,e,i){if(i||2===arguments.length)for(var n,r=0,s=e.length;r<s;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}var c,d=function(){var t=(new Date).getTime(),e="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),("x"==i?n:7&n|8).toString(16)}))};!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"}(c||(c={}));var u,p=function(){function t(t,e,i,n,r,s,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=r,this.sceneManager=s,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}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.sceneManager.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.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(c.Start),this.inputManager.update(),this.dispatchFrameEvent(c.Update),this.dispatchFrameEvent(c.UpdateEngine),this.dispatchFrameEvent(c.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(c.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(c.UpdatePreRender),this.dispatchFrameEvent(c.UpdateCamera),this.dispatchFrameEvent(c.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(c.UpdatePhysics),this.dispatchFrameEvent(c.UpdateCollider),this.dispatchFrameEvent(c.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return l(l([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==c.Start&&t!==c.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),g=function(){function t(t){this.updateEvent=c.Update,this.started=!1,this.container=t,this.gameObjectManager=this.container.getSingleton("GameObjectManager")}return t.prototype.dispatch=function(t,e){t===c.Init&&this.init?this.init(e):t!==c.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===c.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===c.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}(),m=function(t){function e(e,i,n){void 0===n&&(n="");var r=t.call(this,e)||this;return r.id=d(),r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=n,r}return a(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.container.getSingleton("SceneManager").getCurrentScene()},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}(g),f=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateEngine,e}return a(e,t),e}(m),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateCollider,e}return a(e,t),e}(m),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdatePhysics,e}return a(e,t),e}(m),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateTransform,e}return a(e,t),e}(m),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdatePreRender,e}return a(e,t),e}(m),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateCamera,e}return a(e,t),e}(m),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateRender,e}return a(e,t),e}(m);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font"}(u||(u={}));var C,_,j,O=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 r=this.createAsset(t,u.Image,n),s=function(){e&&i.renderManager.preloadTexture(n),r.loaded=!0};return n.naturalWidth?s():n.addEventListener("load",s),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,u.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,u.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===u.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===u.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===u.Font&&e.family===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}(),P=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return a(e,t),e}(Error),R=function(){function t(t,e,i){if(this._canvas=null,!t)throw new P("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}(),A=function(){function t(t){this.container=t,this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var r=new t(this.container,n,i);return this.gameObjects.push(r),r.dispatch(c.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):l([],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(c.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),S=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.gamepadConnected=function(t){this.gamepads.set(t.index,new T),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.getGamepads();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.getGamepads=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),T=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new e,this._leftStickAxes=new e,this._rightStickAxes=new e,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(){return Array.from(this.buttons.values()).find((function(t){return 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 r=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 r._vibrating=!1})).finally((function(){return r._vibrating=!1})))},t}(),D=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}(),E=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}(),F=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new e(0,0),this._hasMoved=!1,this.lastPositionInViewport=new e(0,0),this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t}(),B=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var r=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new P("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(r.container,e,r.container.getConstant("Game"));return r.currentScene=n,n.dispatch(c.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new P("There is no opening scene");this._loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new P("Scene with name ".concat(t," does not exists"));this.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(c.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t.prototype.stopGame=function(){null!==this.currentScene&&(this.currentScene.dispatch(c.StopGame),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),I=[60,120,180,240],U=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!I.includes(t))throw new P("Invalid Physics frame rate. Allowed: [".concat(I.join(", "),"]"));this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return t.prototype.updateForGame=function(t){this.unscaledGameDeltaTime=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},Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledGameDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t}(),G=function(){function t(t){var i=this;this._touching=!1,this._positionInViewport=new e(0,0),this._radius=new e(0,0),this.eventHandler=function(t){"touchstart"===t.type&&(i._touching=!0,i.updatePosition(t)),"touchmove"===t.type&&i.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(i._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,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radius",{get:function(){return this._radius},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),0!==t.targetTouches.length&&(this._positionInViewport.set((t.targetTouches[0].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[0].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),this._radius.set(t.targetTouches[0].radiusX,t.targetTouches[0].radiusY))},t}(),L=function(){function t(){}return t.initialize=function(t){this.assetManager=t},t.getAssetsLoaded=function(){return this.assetManager.getAssetsLoaded()},t.loadImage=function(t,e){return this.assetManager.loadImage(t,e)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.loadFont=function(t,e){return this.assetManager.loadFont(t,e)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.getFont=function(t){return this.assetManager.getFont(t)},t.assetManager=null,t}(),k=function(){function t(){}return t.initialize=function(t){this.domManager=t},Object.defineProperty(t,"gameWidth",{get:function(){return this.domManager.canvas.width},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gameHeight",{get:function(){return this.domManager.canvas.height},enumerable:!1,configurable:!0}),Object.defineProperty(t,"canvas",{get:function(){return this.domManager.canvas},enumerable:!1,configurable:!0}),t.domManager=null,t}(),V=function(){function t(){}return t.initialize=function(t){this.inputManager=t},Object.defineProperty(t,"mouse",{get:function(){return this.inputManager.mouse},enumerable:!1,configurable:!0}),Object.defineProperty(t,"keyboard",{get:function(){return this.inputManager.keyboard},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gamepad",{get:function(){return this.inputManager.gamepad},enumerable:!1,configurable:!0}),Object.defineProperty(t,"touch",{get:function(){return this.inputManager.touch},enumerable:!1,configurable:!0}),t.inputManager=null,t}(),W=function(){function t(){}return t.initialize=function(t){this.sceneManager=t},t.loadScene=function(t){this.sceneManager.loadScene(t)},t.getCurrentSceneName=function(){return this.sceneManager.currentSceneName},t.loadOpeningScene=function(){this.sceneManager.loadOpeningScene()},t.sceneManager=null,t}(),H=function(){function t(){}return t.initialize=function(t){this.timeManager=t},Object.defineProperty(t,"deltaTime",{get:function(){return this.timeManager.deltaTime},enumerable:!1,configurable:!0}),t.getTimeScale=function(){return this.timeManager.timeScale},t.setTimeScale=function(t){this.timeManager.timeScale=t},Object.defineProperty(t,"unscaledDeltaTime",{get:function(){return this.timeManager.unscaledGameDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"physicsDeltaTime",{get:function(){return this.timeManager.physicsDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"browserDeltaTime",{get:function(){return this.timeManager.browserDeltaTime},enumerable:!1,configurable:!0}),t.timeManager=null,t}(),z=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i,n){return this.manager.addGameObject(t,e,i,n)},t.findAllGameObjects=function(){return this.manager.findGameObjects()},t.findGameObjects=function(t){return this.manager.findGameObjects(t)},t.findGameObject=function(t){return this.manager.findGameObject(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParent=function(t,e){return this.manager.findGameObjectByParent(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t}(),Y=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=[]}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.sceneManager.unloadCurrentScene(),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.load(),this.dispatchFrameEvent(c.Start),this.dispatchFrameEvent(c.Update),this.dispatchFrameEvent(c.UpdateEngine),this.dispatchFrameEvent(c.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.update()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(c.UpdatePhysics),this.dispatchFrameEvent(c.UpdateCollider),this.dispatchFrameEvent(c.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return l(l([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==c.Start&&t!==c.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(C||(C={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(_||(_={})),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"}(j||(j={}));class N{constructor(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}setViewport({position:t,zoom:e},i){i===_.WorldSpace?(this.viewport.x=t.x-this.gl.canvas.width/e/2,this.viewport.x1=t.x+this.gl.canvas.width/e/2,this.viewport.y=t.y-this.gl.canvas.height/e/2,this.viewport.y1=t.y+this.gl.canvas.height/e/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)}setObjectForResizeable({position:t,width:e,height:i,rotation:n=0}){const r=Math.abs(Math.sin(n)),s=Math.abs(Math.cos(n)),o=r*i+s*e,a=r*e+s*i;this.object.x=t.x-o/2,this.object.x1=t.x+o/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:r,rotation:s}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:s})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===C.Circumference?(this.object.x=t.x-n,this.object.y=t.y-n,this.object.x1=t.x+n,this.object.y1=t.y+n):(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.renderPosition,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:n,tileHeight:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*n&&this.viewport.x<=this.object.x+e%i*n+n&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case j.Mask:case j.Sprite:this.setObjectForResizeable(t);break;case j.Geometric:this.setObjectForGeometric(t);break;case j.Text:this.setObjectForText(t);break;case j.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}applyCulling(t,e){return e.filter((e=>!!this.isInViewPort(e,t)&&(e.type===j.Tilemap&&this.applyCullingInTiles(e),!0)))}}class X{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))}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 X(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}}t.TilemapOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TilemapOrientation||(t.TilemapOrientation={}));class q{constructor(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}addRenderData(t){this.renderData.push(t)}addCameraData(t){this.cameraData.push(t)}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderByCamera(t)))}renderByCamera(e){this.cullingManager.applyCulling(e,this.renderData.filter((t=>e.layers.includes(t.layer))).sort(((t,i)=>e.layers.indexOf(t.layer)-e.layers.indexOf(i.layer))).map((e=>e.type===j.Tilemap?(e=>{const i=Object.assign(Object.assign({},e),{culledTiles:[],tilemap:Object.assign(Object.assign({},e.tilemap),{height:Math.ceil(e.tiles.length/e.tilemap.width),realWidth:e.tilemap.width*e.tilemap.tileWidth,realHeight:0}),renderPosition:new X});return i.tilemap.realHeight=i.tilemap.height*i.tilemap.tileHeight,(e=>{e.renderPosition.set(e.position.x+(e.orientation!==t.TilemapOrientation.Center?e.tilemap.realWidth/2:0),e.position.y+(e.orientation===t.TilemapOrientation.RightDown?-e.tilemap.realHeight/2:e.orientation===t.TilemapOrientation.RightUp?e.tilemap.realHeight/2:0))})(i),i})(e):e))).forEach((t=>this.webglManager.render(t,e)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}preloadTexture(t){this.webglManager.createTexture(t)}}var K;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(K||(K={}));class ${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(K.WebGL2)?K.WebGL2:null!==this.canvas.getContext(K.LegacyWebGL)?K.LegacyWebGL:void 0}}class Q{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 n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n: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 n=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),n),n}symbol(t){return Symbol.for(t instanceof FontFace?t.family:t)}renderAtlas(t){const e=new J(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 n=0,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e}}class J{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 Z{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i);const s=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,s)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class tt{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===K.WebGL2?this.programFactory.create("#version 300 es\nprecision mediump float;\n\nin vec2 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision mediump float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)}}class et{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var it="undefined"!=typeof Float32Array?Float32Array:Array;function nt(){var t=new it(16);return it!=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 rt(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 st(t,e,i){var n,r,s,o,a,h,l,c,d,u,p,g,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(n=e[0],r=e[1],s=e[2],o=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],u=e[9],p=e[10],g=e[11],t[0]=n,t[1]=r,t[2]=s,t[3]=o,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=u,t[10]=p,t[11]=g,t[12]=n*m+a*f+d*y+e[12],t[13]=r*m+h*f+u*y+e[13],t[14]=s*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function ot(t,e,i){var n=i[0],r=i[1],s=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]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function at(t,e,i){var n=Math.sin(i),r=Math.cos(i),s=e[0],o=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],u=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]=s*r+l*n,t[1]=o*r+c*n,t[2]=a*r+d*n,t[3]=h*r+u*n,t[4]=l*r-s*n,t[5]=c*r-o*n,t[6]=d*r-a*n,t[7]=u*r-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ht;function lt(){var t=new it(3);return it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ct(t,e,i){var n=new it(3);return n[0]=t,n[1]=e,n[2]=i,n}function dt(){var t=new it(4);return it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}lt(),function(){var t;t=new it(4),it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),lt(),ct(1,0,0),ct(0,1,0),dt(),dt(),ht=new it(9),it!=Float32Array&&(ht[1]=0,ht[2]=0,ht[3]=0,ht[5]=0,ht[6]=0,ht[7]=0),ht[0]=1,ht[4]=1,ht[8]=1,function(){var t=new it(2);it!=Float32Array&&(t[0]=0,t[1]=0)}();const ut=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},pt=(t,e,i,n)=>{var r,s;(function(t,e,i,n,r,s,o){var a=1/(e-i),h=1/(n-r),l=1/(s-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]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=(o+s)*l,t[15]=1})(t=rt(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),st(t,t,[0,0,0]),n===_.WorldSpace&&ot(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(s=i.zoom)&&void 0!==s?s:1,1])};class gt{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(((t,e,i=1)=>{const n=[];for(let t=1;t<=e;t+=i)n.push(t);return n})(0,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e,i){switch(t.shape){case C.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case C.Line:this.renderLines(t,e,this.gl.LINES,i);break;case C.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var r;const s=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(s)&&this.vertices.set(s,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(s);this.lastVertices===s&&n===j.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW)),this.lastVertices=s,this.modelMatrix=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),pt(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);const{r:a,g:h,b:l,a:c}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,o.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ot(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),pt(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);const{r:i,g:n,b:r,a:s}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,r,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class mt{constructor(t,e){this.gl=t,this.programManager=e,this.type=j.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n,r;i!==j.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),pt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha>=0&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:s,g:o,b:a,a:h}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,s,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class ft{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt(),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 n,r,s,o;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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=rt(this.textureMatrix),t.slice&&(st(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),ot(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),pt(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);const 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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ut(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ut(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}t.TextOrientation=void 0,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={}));const yt=new X,xt=new X,vt=[32,126,161,255],bt=t.TextOrientation.Center;class Mt{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=j.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new X,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,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=rt(this.modelMatrix),this.setPositionFromOrientation(t),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=rt(this.textureMatrix),pt(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);const s=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===s&&i===j.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,s),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=s),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:o,g:a,b:h,a:l}=ut(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,o,a,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)}setDefaultValues(t){var e,i,n,r,s,o,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:yt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:xt,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:vt):t.bitmap={margin:yt,spacing:xt,fontSize:64,charRanges:vt},t.color=null!==(s=t.color)&&void 0!==s?s:"#000000",t.letterSpacing=null!==(o=t.letterSpacing)&&void 0!==o?o: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!==(l=t.orientation)&&void 0!==l?l:bt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:r,lineSeparation:s}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;r/=i,s/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,o),o=0,a-=1+s;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(o,a-1,o+e,a-1,o,a,o,a,o+e,a-1,o+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,s=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(s+n.margin.y)/t.canvas.width,d=(i+c.width+n.spacing.x)/t.canvas.width,u=(s+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,u,d,u,h,l,h,l,d,u,d,l),o+=e+r}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-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))}}class wt{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 X,texSpacing:new X,texWidth:0,texHeight:0,texCorrection:new X},this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n,r,s,o;if(0===t.culledTiles.reduce(((t,e)=>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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=rt(this.textureMatrix),ot(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),pt(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);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===j.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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ut(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ut(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,r,s,o,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new X,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new X,t.correction=null!==(n=t.correction)&&void 0!==n?n:new X,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(s=t.spacing.x)&&void 0!==s?s:0),this.tileset.tileHeight=t.tileHeight+(null!==(o=t.margin.y)&&void 0!==o?o:0)+(null!==(a=t.spacing.y)&&void 0!==a?a: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({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const r=n%e.width-e.width/2,s=i/2-Math.floor(n/e.width);this.posVertices.push(r,s-1,r+1,s-1,r,s,r,s,r+1,s-1,r+1,s);const o=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(o,a+this.tileset.texHeight,o+this.tileset.texWidth,a+this.tileset.texHeight,o,a,o,a,o+this.tileset.texWidth,a+this.tileset.texHeight,o+this.tileset.texWidth,a)}))}}class Ct{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(()=>this.create(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i}create(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 _t{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 n;return null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n}}class jt{constructor(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}render(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}}clearCanvas(t){const e=ut(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}createTexture(t,e=!1){this.textureManager.createTextureFromImage(t,e)}}class Ot{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))}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 Ot(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 Pt{constructor(t,e,i,n){this._position=new Ot,this._center=new Ot,this._width=0,this._height=0,this.set(t,e,i,n)}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 width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}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 Pt?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Ot&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const Rt=(t,e,i)=>Math.min(i,Math.max(e,t));class At{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:n,position:r,rotation:s,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:n,position:null!=r?r:new Ot,rotation:null!=s?s:0,group:o,onCollision:a}}}class St{constructor(t,e=0){this.area=new Pt(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}resize(t){this.clear(),this.area.copy(t)}clear(){this.items=[],this.children.forEach((t=>t.clear())),this.children=[]}insert(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])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new Pt(this.area.x,this.area.y,t,e),new Pt(this.area.x,this.area.y+e,t,e),new Pt(this.area.x+t,this.area.y+e,t,e),new Pt(this.area.x+t,this.area.y,t,e)].map((t=>new St(t,this.depth+1))),this.items.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.items=[]}insertItemIntoChildren(t,e){this.getChildrenForArea(e).forEach((i=>i.insert(t,e)))}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((i=>e.push(...i.retrieve(t)))):this.items.forEach((t=>e.push(t[0]))),e}getChildrenForArea(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}}const Tt=(t,e,i,n)=>Math.min((t-e)/i|0,n-1);class Dt{constructor(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}get subdivisions(){return this._subdivisions}set subdivisions(t){this._subdivisions=Rt(t,1,20)}resize(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(let t=0;t<this._subdivisions;t++){this.itemsInCells[t]=[];for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}}clear(){for(let t=0;t<this._subdivisions;t++)for(let e=0;e<this._subdivisions;e++)this.itemsInCells[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.itemsInCells[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.itemsInCells[t][i].forEach((t=>e.includes(t)?null:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=Tt(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Tt(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Tt(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Tt(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}t.BroadPhaseMethods=void 0,function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(t.BroadPhaseMethods||(t.BroadPhaseMethods={}));class Et{constructor(e,i,n,r){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Ot,this.maxArea=new Ot,this.newArea=new Pt(0,0,0,0),this.method=e,this.colliders=[],this.activeColliders=[],this.collisionMatrix=r,this.setupBroadPhaseResolver(null!=i?i:t.BroadPhaseMethods.QuadTree,n)}setupBroadPhaseResolver(e,i){this.collisionArea=null!=i?i:new Pt(0,0,0,0),this.fixedCollisionArea=!!i,e===t.BroadPhaseMethods.SpartialGrid?this.broadPhaseResolver=new Dt(this.collisionArea):this.broadPhaseResolver=new St(this.collisionArea)}addCollider(t){this.colliders[t.id]=t}getCollider(t){return this.colliders[t]}removeCollider(t){delete this.colliders[t.id]}clearColliders(){this.colliders=[]}getCollisionsForCollider(t){return t.active?this.collisions.filter((e=>e.localCollider.id===t.id)):[]}refreshCollisionsForCollider(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((e=>e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id)),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))}resolve(){this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((t=>t.active)),this.broadPhaseResolver.clear(),this.activeColliders.forEach((t=>{this.updateShape(t)})),!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((({id:t,shape:{boundingBox:e}})=>this.broadPhaseResolver.insert(t,e))),this.updateCollisions())}updateShape(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()}updateNewArea(){this.activeColliders.forEach((({shape:{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.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}checkForSpartialGridResize(){this.broadPhaseResolver instanceof Dt&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)}updateCollisions(){this.activeColliders.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase(t){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t])).filter((e=>this.collisionMatrix.some((i=>i[0]===t.layer&&i[1]===e.layer||i[1]===t.layer&&i[0]===e.layer)))):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t]))}narrowPhase(t,e){e.filter((e=>!(t.group&&e.group&&e.group===t.group||t.id===e.id))).forEach((e=>{if(this.isResolved(t,e))return;const i=this.method.getCollisionResolution(t.shape,e.shape);null!==i&&(this.collisions.push({localCollider:t,remoteCollider:e,resolution:i},{localCollider:e,remoteCollider:t,resolution:{direction:i.displacementDirection,displacementDirection:i.direction,penetration:i.penetration}}),t.onCollision&&t.onCollision(i))}))}isResolved(t,e){for(const i of this.collisions)if(i.localCollider.id===t.id&&i.remoteCollider.id===e.id)return!0;return!1}}var Ft;t.CollisionMethods=void 0,t.RigidBodyType=void 0,function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Ft||(Ft={}));class Bt{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Ft.Polygon&&e.type===Ft.Polygon?this.AABBResolver.resolve(t,e):t.type===Ft.Circumference&&e.type===Ft.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Ft.Polygon&&e.type===Ft.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(t.CollisionMethods||(t.CollisionMethods={}));class It{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class Ut{constructor(){this.direction=new Ot,this.displacementDirection=new Ot}resolve({boundingBox:t},{boundingBox:e}){return 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?null:(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.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),Ot.unit(this.displacementDirection,this.displacementDirection),{direction:Ot.scale(new Ot,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),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),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}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),n=Math.abs(t.x1-e.x1);this.overlapX+=i<n?i:n}}}class Gt{constructor(){this.closestPoint=new Ot,this.distance=new Ot,this.direction=new Ot}resolve(t,e,i=!1){return this.closestPoint.set(Rt(t.position.x,e.boundingBox.x,e.boundingBox.x1),Rt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),Ot.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Ot.unit(this.direction,this.distance),{direction:i?Ot.scale(new Ot,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Ot.scale(new Ot,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class Lt{constructor(){this.distance=new Ot,this.direction=new Ot}resolve(t,e){return Ot.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Ot.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Ot.scale(new Ot,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class kt{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Ot,this.distance=new Ot(1/0,1/0),this.cache=new Ot}resolve(t,e){this.minOverlap=1/0,t.type===Ft.Circumference?this.setCircumferenceAxis(t,e):e.type===Ft.Circumference&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?null:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t.type===Ft.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Ft.Circumference&&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 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){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,Ot.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&&Ot.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Ot.scale(new Ot,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(Ot.dot(i,e),t.min),t.max=Math.max(Ot.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Ot.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Ot.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Ot.add(t.vertices[0],t.position,Ot.scale(this.cache,Ot.unit(this.cache,e),-t.radius)),Ot.add(t.vertices[1],t.position,Ot.scale(this.cache,Ot.unit(this.cache,e),t.radius))}}class Vt{constructor(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}addCollider(t){const e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e}removeCollider(t){this.collisionManager.removeCollider(t)}getCollisionsForCollider(t){return this.collisionManager.getCollisionsForCollider(t)}addRigidBody(t){const e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e}removeRigidBody(t){this.rigidBodyManager.removeRigidBody(t)}resolve(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)}clear(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()}}class Wt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:n,velocity:r,onResolve:s}){if(0===t.length)throw new Error("RigidBody needs at least one collider");return{id:++this.lastId,active:!0,colliderIds:t,type:e,gravity:null!=i?i:0,position:null!=n?n:new Ot,velocity:null!=r?r:new Ot,onResolve:s}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(t.RigidBodyType||(t.RigidBodyType={}));const Ht=["x","y"];class zt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Ot,this.displacement=new Ot,this.cacheDisplacement=0}addRigidBody(t){this.rigidBodies[t.id]=t}removeRigidBody(t){delete this.rigidBodies[t.id]}clearRigidBodies(){this.rigidBodies=[]}resolve(e){this.activeRigidBodies=this.rigidBodies.filter((t=>t.active)),this.colliders=this.activeRigidBodies.reduce(((t,e)=>[...t,...e.colliderIds]),[]),this.activeRigidBodies.forEach((i=>{i.type===t.RigidBodyType.Dynamic?this.dynamicUpdate(i,e):i.type===t.RigidBodyType.Kinematic&&this.kinematicUpdate(i,e),i.onResolve&&i.onResolve(i)}))}dynamicUpdate(t,e){this.applyGravity(t,e),Ht.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Ot.add(t.position,t.position,Ot.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Ot.add(t.position,t.position,this.velocity),this.collisionManager.refreshCollisionsForCollider(t)}))}applyGravity(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)}applyVelocity(t,e,i){this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[i]+=this.velocity[i],this.collisionManager.refreshCollisionsForCollider(t)})))}obtainDisplacement(t,e){this.displacement[e]=0,this.getCollisions(t).forEach((t=>{this.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,this.displacement[e]=Math.abs(this.displacement[e])>Math.abs(this.cacheDisplacement)?this.displacement[e]:this.cacheDisplacement}))}applyReposition(t,e){0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[e]+=this.displacement[e],this.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))}getCollisions(t){return t.colliderIds.map((t=>this.collisionManager.getCollider(t))).filter((t=>t.active&&t.physics)).reduce(((t,e)=>(t.push(...this.collisionManager.getCollisionsForCollider(e).filter((t=>t.remoteCollider.physics&&this.colliders.includes(t.remoteCollider.id)))),t)),[])}}class Yt{constructor(t){this.radius=t,this.type=Ft.Circumference,this.boundingBox=new Pt(0,0,0,0),this.vertices=[new Ot,new Ot],this.projectionAxes=[new Ot],this._position=new Ot}set position(t){this._position.copy(t)}get position(){return this._position}update(){this.updateBoundingBox()}updateBoundingBox(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}class Nt{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[new Ot,new Ot],this.projectionAxes=[new Ot],this.boundingBox=new Pt(0,0,0,0),this.rotation=0,this._position=new Ot}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}set position(t){this._position.copy(t)}get position(){return this._position}updateVertices(){for(let 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)}updateBoundingBox(){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}updateProjectionAxes(){Ot.normal(this.projectionAxes[0],Ot.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class Xt{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[],this.boundingBox=new Pt(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Ot,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(let t=0;t<this.vertexModel.length;t++)this.vertices.push(new Ot),this._projectionAxes.push(new Ot)}set position(t){this._position.copy(t)}get position(){return this._position}get projectionAxes(){return this._projectionAxes}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}updateVertices(){for(let 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)}updateBoundingBox(){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((t=>{this.boxMinX=Math.min(t.x,this.boxMinX),this.boxMinY=Math.min(t.y,this.boxMinY),this.boxMaxX=Math.max(t.x,this.boxMaxX),this.boxMaxY=Math.max(t.y,this.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)}updateProjectionAxes(){var t;for(let e=0;e<this.vertices.length;e++)Ot.normal(this._projectionAxes[e],Ot.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class qt extends Xt{constructor(t,e){super([new Ot(-t/2,-e/2),new Ot(-t/2,e/2),new Ot(t/2,e/2),new Ot(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Ot,new Ot]}updateSize(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)}updateProjectionAxes(){Ot.unit(this.projectionAxes[0],Ot.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Ot.normal(this.projectionAxes[1],this.projectionAxes[0])}}var Kt,$t=function(e,i){e.addConstant("GameConfig",i),e.add("TimeManager",(function(){return new U(i.physicsFramerate)})),e.add("GameObjectManager",(function(){return new A(e)})),e.add("PhysicsManager",(function(){return(({collisionArea:e,collisionMatrix:i,collisionMethod:n,collisionBroadPhaseMethod:r}={})=>{const s=new Lt,o=n===t.CollisionMethods.AABB?new Bt(new Ut,new Gt,s):new It(s,new kt),a=new Et(o,r,e,i),h=new At,l=new zt(a),c=new Wt;return new Vt(a,h,l,c)})(i.collisions)})),i.headless?e.add("IterationManager",(function(){return new Y(e.getSingleton("TimeManager"),e.getSingleton("PhysicsManager"),e.getSingleton("GameObjectManager"),e.getSingleton("SceneManager"))})):(e.add("DomManager",(function(){return new R(i.containerNode,i.gameWidth,i.gameHeight)})),e.add("RenderManager",(function(){return(t=>{const e=new $(t),i=e.gl,n=e.contextVersion,r=new tt(i,n,new Z(i,new et(i))),s=new _t(new Ct(i)),o=new jt(i,r,s,new Map([[j.Sprite,new ft(i,r,s)],[j.Text,new Mt(i,r,s,new Q)],[j.Tilemap,new wt(i,r,s)],[j.Geometric,new gt(i,r)],[j.Mask,new mt(i,r)]]));return new q(o,new N(i))})(e.getSingleton("DomManager").canvas)})),Qt(e),e.add("AssetManager",(function(){return new O(e.getSingleton("RenderManager"))})),e.add("IterationManager",(function(){return new p(e.getSingleton("TimeManager"),e.getSingleton("PhysicsManager"),e.getSingleton("RenderManager"),e.getSingleton("InputManager"),e.getSingleton("GameObjectManager"),e.getSingleton("SceneManager"),i.canvasColor)}))),e.add("SceneManager",(function(){return new B(e,i.headless?void 0:e.getSingleton("RenderManager"))})),Jt(e,i)},Qt=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new D(new F(e.canvas),new E(e.canvas),new S,new G(e.canvas))}))},Jt=function(t,e){e.headless||(L.initialize(t.getSingleton("AssetManager")),k.initialize(t.getSingleton("DomManager")),V.initialize(t.getSingleton("InputManager"))),W.initialize(t.getSingleton("SceneManager")),H.initialize(t.getSingleton("TimeManager")),z.initialize(t.getSingleton("GameObjectManager"))},Zt=function(){function t(){this.instances=new Map,this.constructors=new Map,this.constants=new Map}return t.prototype.add=function(t,e){if(this.constructors.has(t))throw new P("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 P("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 P("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new P("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 P("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),te={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new e(1,1),collisions:{collisionMethod:t.CollisionMethods.SAT,collisionBroadPhaseMethod:t.BroadPhaseMethods.SpartialGrid}},ee=function(){function t(t){this._config=h(h({},te),t),this._config.collisions=h(h({},te.collisions),t.collisions),this.container=new Zt,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){$t(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){void 0===n&&(n=!1),this.sceneManager.addScene(t,e,i,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}(),ie=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new e,i._scale=new e(1,1),i._rotation=new s,i._innerPosition=new e,i._parent=null,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.scaledInnerPosition=new e,i}return a(i,t),Object.defineProperty(i.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&e.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},i.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(),e.add(this._position,this._parent.position,this.scaledInnerPosition)):e.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)},i.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)),e.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},i.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},i}(v),ne=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.physicsManager=e.container.getSingleton("PhysicsManager"),e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return a(e,t),e.prototype.update=function(){this.activateColliders&&(this.colliders.forEach((function(t){return t.active=!0})),this.activateColliders=!1),this.updateRealSize(),this.updatePosition(),this.updateColliders()},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,s=this.physicsManager.getCollisionsForCollider(n);r<s.length;r++){var o=s[r];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],s=0,o=this.physicsManager.getCollisionsForCollider(r);s<o.length;s++){var a=o[s];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.group),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(y),re=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.physicsManager=e.container.getSingleton("PhysicsManager"),e}return a(i,t),Object.defineProperty(i.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),i.prototype.init=function(t){var i,n=t.rigidBodyType,r=t.gravity;if(0===this.getColliderIds().length)throw new P("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:n,colliderIds:this.getColliderIds(),gravity:null!==(i=Math.abs(r))&&void 0!==i?i:0,velocity:new e,position:new e})},i.prototype.update=function(){if(0===this.getColliderIds().length)throw new P("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},i.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof ne&&t.physics})).reduce((function(t,e){return l(l([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},i.prototype.onActiveChange=function(){this.rigidBody.active=this.active},i.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},i}(f),se="Default",oe=function(t){function e(e,i,n){void 0===i&&(i="");var r=t.call(this,e)||this;return r.id=d(),r.layer=se,r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.name=i,r.addComponent(ie),r.parent=null!=n?n:null,r}return a(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChange(),this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus())},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(ie)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(re)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r="string"==typeof e?e:i,s=new t(this.container,this,r);return this.checkMultipleComponent(s,t),this.components.push(s),s.dispatch(c.Init,n),s},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new P("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(c.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(c.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(g),ae=[se],he=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.renderManager=e.container.getSingleton("RenderManager"),e.canvas=e.container.getSingleton("DomManager").canvas,e.viewportRect=new i(0,0,0,0),e.worldSpaceRect=new i(0,0,0,0),e.depth=0,e.layers=ae,e._zoom=1,e}return a(n,t),Object.defineProperty(n.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new P("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),n.prototype.addLayer=function(t){this.layers.push(t)},n.prototype.init=function(){this.cameraData={position:new e,layers:[],depth:1}},n.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},n.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},n.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},n.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)},n}(M),le=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(he)},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}(oe),ce=function(t){function e(e,i,n){var r=t.call(this,e)||this;return r.name=i,r.game=n,r.game.config.headless||r.addGameObject(le),r}return a(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(le)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(),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}(g),de=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return a(n,i),n.prototype.init=function(i){var n,r,o,a,h,l;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==t.CollisionMethods.SAT)throw new P("Polygon Colliders need SAT collision method.");if(i.vertexModel.length<3)throw new P("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var c=0;c<this.vertexModel.length;c++)this.scaledVertexModel.push(new e);this.colliders.push(this.physicsManager.addCollider({layer:null!==(l=this.layer)&&void 0!==l?l:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Xt(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ue,{collider:this.colliders[0]}))},n.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},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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},n}(ne),ue=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return a(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:j.Geometric,location:_.WorldSpace,layer:this.gameObject.layer,position:new e,shape:C.Polygon,color:"#00FF00"},this.collider=i},i.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)},i}(w),pe=function(i){function n(){var n=null!==i&&i.apply(this,arguments)||this;return n.debug=!1,n.offsetX=0,n.offsetY=0,n.realWidth=0,n.realHeight=0,n.realOffset=new e,n.realPosition=new e,n.realRotation=0,n.applyRotation=n.container.getConstant("GameConfig").collisions.collisionMethod===t.CollisionMethods.SAT,n.innerPosition=new e,n}return a(n,i),n.prototype.init=function(t){var e,i,n,r,o,a;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!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new s,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new qt(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ue,{collider:this.colliders[0]}))},n.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},n.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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)},n}(ne),ge=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new e,i.realPosition=new e,i.innerPosition=new e,i}return a(i,t),i.prototype.init=function(t){var e,i,n,r,s;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!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,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(),shape:new Yt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},i.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},i.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){e.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))},i.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},i}(ne),me=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return a(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:j.Geometric,location:_.WorldSpace,layer:this.gameObject.layer,position:new e,shape:C.Circumference,color:"#00FF00"},this.collider=i},i.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)},i}(w),fe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.position=new e,t}return a(n,i),n.prototype.init=function(e){var i,n;this.tilemapRenderer=e.tilemapRenderer,this.layer=e.layer,this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.physics=!0,this.composite=null!==(n=e.composite)&&void 0!==n&&n,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===t.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([t.TilemapOrientation.Center,t.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==t.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(ye,{colliders:this.colliders}))},n.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(i,n){var r;t.needsCollider(i,n)&&t.colliders.push(t.physicsManager.addCollider({layer:null!==(r=t.layer)&&void 0!==r?r:t.gameObject.layer,position:new e(t.position.x+(n%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(n/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new qt(t.scaledTileWidth,t.scaledTileHeight),updateCollisions:!1,physics:t.physics,group:t.gameObject.id}))}))},n.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]}))},n.prototype.useLineColliders=function(){var t,i,n=this,r=[],s=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,o=Math.floor(e/n.tilemapRenderer.width);r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]),s[o]||(s[o]=[]),s[o+1]||(s[o+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[o][i]=!0),n.hasTile(a[2])||(r[o+1][i]=!0),n.hasTile(a[1])||(s[o][i]=!0),n.hasTile(a[3])||(s[o][i+1]=!0)}}));for(var o=0;o<r.length;o++)if(r[o])for(var a=0;a<r[o].length;a++)!t||!i||o===i.y&&r[o][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),r[o][a]&&(t||(t=new e(a,o)),i=new e(a+1,o));t&&i&&this.addLineCollider(t,i),t=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<s.length;o++)s[o]&&(!t||!i||a===i.x&&s[o][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),s[o][a]&&(t||(t=new e(a,o)),i=new e(a,o+1)));t&&i&&this.addLineCollider(t,i)},n.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},n.prototype.addLineCollider=function(t,i){var n,r=this.physicsManager.addCollider({layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,position:this.position.clone(),shape:new Nt([new e(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new e(i.x*this.scaledTileWidth,i.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id});this.colliders.push(r)},n.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]},n.prototype.updateRealSize=function(){},n.prototype.updatePosition=function(){},n.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}))},n}(ne),ye=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return a(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:j.Geometric,layer:i.gameObject.layer,location:_.WorldSpace,position:new e,shape:C.Polygon,color:"#00FF00"}}))},i.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])}))},i}(w),xe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return a(n,i),n.prototype.init=function(i){var n,r,o,a,h,l;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==t.CollisionMethods.SAT)throw new P("Edge Colliders need SAT collision method.");if(i.vertexModel.length<2)throw new P("Edge Collider needs at least 2 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var c=0;c<this.vertexModel.length;c++)this.scaledVertexModel.push(new e);for(c=0;c<this.scaledVertexModel.length-1;c++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(l=this.layer)&&void 0!==l?l:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Nt([this.scaledVertexModel[c],this.scaledVertexModel[c+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(ve,{colliders:this.colliders}))},n.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},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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]]},n}(ne),ve=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return a(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:j.Geometric,layer:i.gameObject.layer,location:_.WorldSpace,position:new e,shape:C.Line,color:"#00FF00"}}))},i.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])}))},i}(w),be=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.spriteDefaultScale=i.container.getConstant("GameConfig").spriteDefaultScale,i.renderData=[],i.innerPosition=new e,i.cachePosition=new e,i.cacheRenderPosition=new e,i.scaledOffset=new e,i}return a(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(i=t.offset)&&void 0!==i?i:new e,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:new s,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this._tiled=null!==(h=t.tiled)&&void 0!==h?h:new e(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(l=t.maskColorMix)&&void 0!==l?l:0,this.tintColor=t.tintColor,this.layer=t.layer},Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new P("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){var t;if(this.sprite&&!0===this.sprite.loaded){this.sprite.scale=null!==(t=this.sprite.scale)&&void 0!==t?t:this.spriteDefaultScale,this.updateRenderDataArray();for(var e=0,i=0;i<this._tiled.x;i++)for(var n=0;n<this._tiled.y;n++)this.updateRenderData(e,i,n),e++}},i.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:j.Sprite,location:_.WorldSpace,layer:"",position:new e,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?_.ViewPort:_.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=this.sprite.width*Math.abs(this.gameObject.transform.scale.x),this.renderData[t].height=this.sprite.height*Math.abs(this.gameObject.transform.scale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.gameObject.transform.scale.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])},i.prototype.calculateRenderPosition=function(t,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.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)),e.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[t].width,n*this.renderData[t].height),e.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},i.prototype.translateRenderPosition=function(t){e.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var i=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(i),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(i))},i}(w),Me=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.lastFrameText="",e}return a(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l,c,d,u,p,g;if(this.text=t.text,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!==(r=t.width)&&void 0!==r?r:100,this.height=null!==(o=t.height)&&void 0!==o?o:100,this.offset=null!==(a=t.offset)&&void 0!==a?a:new e,this.color=null!==(h=t.color)&&void 0!==h?h:"#000000",this.charRanges=null!==(l=t.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(d=t.letterSpacing)&&void 0!==d?d:0,this.smooth=null!==(u=t.smooth)&&void 0!==u&&u,this.rotation=null!==(p=t.rotation)&&void 0!==p?p:new s,this.opacity=null!==(g=t.opacity)&&void 0!==g?g:1,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new P("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new P("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:j.Text,location:_.WorldSpace,position:new e,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},i.prototype.update=function(){var t,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?_.ViewPort:_.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!==(i=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==i?i:0,this.renderData.alpha=this.opacity,e.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text)},i.prototype.crop=function(){var t;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,r=this.text.split("\n");n<r.length;n++)for(var s=0,o=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];s<o.length;s++){var a=o[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(w),we=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.offset=new e,i.rotation=new s,i.opacity=1,i.innerPosition=new e,i.scaledOffset=new e,i}return a(i,t),i.prototype.init=function(t){var i,n,r,s;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:this.opacity,this.layer=t.layer,this.renderData={type:j.Mask,layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?_.ViewPort:_.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},i.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){e.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))},i}(w),Ce=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return a(i,t),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,r=t.tileWidth,s=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=r,this.tileHeight=s,this.layer=o,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(e){return t.processChunk(e)})):t.processChunk(e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(t){var i,n=this,r={type:j.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return n.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=r.tiles:r.tiles.forEach((function(e,i){n.tiles[n.tiledData.width*(t.y+Math.floor(i/t.width))+t.x+i%t.width]=e})),this.renderData.push(r),this.chunks.push(t)},i.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]},i.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.tiledData.width*this.scaledTileWidth,this.realHeight=this.tiledData.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.alpha}))},i}(w),_e=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return a(i,t),i.prototype.init=function(t){var i,n=this,r=t.tiles,s=t.tileset,o=t.tileWidth,a=t.tileHeight,h=t.width,l=t.layer,c=t.orientation,d=t.alpha,u=t.tintColor,p=t.smooth;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=s,this.width=h,this.tileWidth=o,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=d,this.tintColor=u,this.renderData={type:j.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},i.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},i.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.alpha,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},i}(w),je=function(t){var e,i;this.sprites=[],this.framerate=10,this.loop=!1,this.sprites=t.sprites,this.framerate=null!==(e=t.framerate)&&void 0!==e?e:this.framerate,this.loop=null!==(i=t.loop)&&void 0!==i?i:this.loop},Oe="default",Pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.timeManager=e.container.getSingleton("TimeManager"),e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return a(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=Oe),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new Re(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t=Oe),!1!==this.active){if(!1===this.animations.has(t))throw new P("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return void 0===t&&(t=Oe),this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(f),Re=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}(),Ae=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Se=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(){Ae.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return a(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,r=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&Ae.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=r?r: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}(f),Te=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.scale=t.scale,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(){var t,e;return null!==(e=this._width*(null===(t=this.scale)||void 0===t?void 0:t.x))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){var t,e;return null!==(e=this._height*(null===(t=this.scale)||void 0===t?void 0:t.y))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();t.ButtonType=void 0,(Kt=t.ButtonType||(t.ButtonType={}))[Kt.Rectangle=0]="Rectangle",Kt[Kt.Circumference=1]="Circumference";var De=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.width=100,t.height=100,t.radius=50,t.touchEnabled=!0,t._offset=new e,t.pressed=!1,t.mouse=t.container.getSingleton("InputManager").mouse,t.touch=t.container.getSingleton("InputManager").touch,t.position=new e,t.distance=new e,t.pressedLastFrame=!1,t.scaled={width:0,height:0,radius:0,offset:new e},t}return a(n,i),Object.defineProperty(n.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,r=t.touchEnabled,s=t.width,o=t.offset;this.type=e,this.width=null!=s?s:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this._offset=null!=o?o:this._offset},n.prototype.update=function(){this.scale(),e.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()},n.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))},n.prototype.resolveMouseAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=r(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&r(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},n.prototype.resolveMouseAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},n.prototype.resolveTouchAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=this.position.x+this.scaled.width/2>=this.touch.positionInViewport.x-this.touch.radius.x&&this.position.x-this.scaled.width/2<=this.touch.positionInViewport.x+this.touch.radius.x&&this.position.y+this.scaled.height/2>=this.touch.positionInViewport.y-this.touch.radius.y&&this.position.y-this.scaled.height/2<=this.touch.positionInViewport.y+this.touch.radius.y))},n.prototype.resolveTouchAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},n}(m),Ee=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return a(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){V.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.round(this.position,e.add(this.position,this.camera.transform.position,e.scale(this.position,V.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=V.mouse.leftButtonPressed},i}(oe);t.Animation=je,t.Animator=Pe,t.AssetManager=L,t.AudioPlayer=Se,t.BallCollider=ge,t.BoxCollider=pe,t.Button=De,t.Camera=he,t.Component=m,t.DomManager=k,t.EdgeCollider=xe,t.Game=ee,t.GameCamera=le,t.GameObject=oe,t.GameObjectManager=z,t.GamepadController=S,t.GamepadData=T,t.InputManager=V,t.KeyboardController=E,t.LAYER_DEFAULT=se,t.MaskRenderer=we,t.MouseController=F,t.PhysicsComponent=x,t.PolygonCollider=de,t.PolygonColliderRenderer=ue,t.PreRenderComponent=b,t.Rectangle=i,t.RigidBody=re,t.Rotation=s,t.Scene=ce,t.SceneManager=W,t.SpacePointer=Ee,t.Sprite=Te,t.SpriteRenderer=be,t.TextRenderer=Me,t.TiledTilemapRenderer=Ce,t.TilemapCollider=fe,t.TilemapRenderer=_e,t.TimeManager=H,t.TouchController=G,t.Transform=ie,t.Vector2=e,t.between=r,t.clamp=(t,e,i)=>Math.min(i,Math.max(e,t)),t.fixedRound=n,t.randomFloat=(t,e,i=2)=>n(Math.random()*(e-t)+t,i),t.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,t.range=(t,e,i=1)=>{const n=[];for(let r=t;r<=e;r+=i)n.push(r);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).AngryPixel={})}(this,(function(t){"use strict";class e{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))}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 e(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 i{constructor(t,i,n,r){this._position=new e,this._center=new e,this._width=0,this._height=0,this.set(t,i,n,r)}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 width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}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 i?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof e&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const n=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),r=(t,e,i)=>t>=e&&t<=i;class s{constructor(t=null,i=null){this._degrees=0,this._radians=0,this._direction=new e,t?this.radians=t:i&&(this.degrees=i)}set degrees(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()}get degrees(){return this._degrees}set radians(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()}get radians(){return this._radians}get direction(){return this._direction}updateDirection(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var h=function(){return h=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},h.apply(this,arguments)};function l(t,e,i){if(i||2===arguments.length)for(var n,r=0,s=e.length;r<s;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var c,d=function(){var t=(new Date).getTime(),e="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),("x"==i?n:7&n|8).toString(16)}))};!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"}(c||(c={}));var u,p=function(){function t(t,e,i,n,r,s,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=r,this.sceneManager=s,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}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.sceneManager.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.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(c.Start),this.inputManager.update(),this.dispatchFrameEvent(c.Update),this.dispatchFrameEvent(c.UpdateEngine),this.dispatchFrameEvent(c.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(c.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(c.UpdatePreRender),this.dispatchFrameEvent(c.UpdateCamera),this.dispatchFrameEvent(c.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(c.UpdatePhysics),this.dispatchFrameEvent(c.UpdateCollider),this.dispatchFrameEvent(c.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return l(l([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==c.Start&&t!==c.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),g=function(){function t(t){this.updateEvent=c.Update,this.started=!1,this.container=t,this.gameObjectManager=this.container.getSingleton("GameObjectManager")}return t.prototype.dispatch=function(t,e){t===c.Init&&this.init?this.init(e):t!==c.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===c.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===c.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}(),m=function(t){function e(e,i,n){void 0===n&&(n="");var r=t.call(this,e)||this;return r.id=d(),r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=n,r}return a(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.container.getSingleton("SceneManager").getCurrentScene()},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}(g),f=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateEngine,e}return a(e,t),e}(m),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateCollider,e}return a(e,t),e}(m),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdatePhysics,e}return a(e,t),e}(m),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateTransform,e}return a(e,t),e}(m),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdatePreRender,e}return a(e,t),e}(m),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateCamera,e}return a(e,t),e}(m),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=c.UpdateRender,e}return a(e,t),e}(m);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font"}(u||(u={}));var C,_,j,O=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 r=this.createAsset(t,u.Image,n),s=function(){e&&i.renderManager.preloadTexture(n),r.loaded=!0};return n.naturalWidth?s():n.addEventListener("load",s),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,u.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,u.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===u.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===u.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===u.Font&&e.family===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}(),P=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return a(e,t),e}(Error),R=function(){function t(t,e,i){if(this._canvas=null,!t)throw new P("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}(),A=function(){function t(t){this.container=t,this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var r=new t(this.container,n,i);return this.gameObjects.push(r),r.dispatch(c.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):l([],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(c.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),S=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.gamepadConnected=function(t){this.gamepads.set(t.index,new T),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.getGamepads();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.getGamepads=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),T=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new e,this._leftStickAxes=new e,this._rightStickAxes=new e,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 r=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 r._vibrating=!1})).finally((function(){return r._vibrating=!1})))},t}(),D=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}(),E=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}(),F=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new e(0,0),this._hasMoved=!1,this.lastPositionInViewport=new e(0,0),this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t}(),B=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var r=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new P("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(r.container,e,r.container.getConstant("Game"));return r.currentScene=n,n.dispatch(c.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new P("There is no opening scene");this._loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new P("Scene with name ".concat(t," does not exists"));this.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(c.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t.prototype.stopGame=function(){null!==this.currentScene&&(this.currentScene.dispatch(c.StopGame),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),I=[60,120,180,240],U=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!I.includes(t))throw new P("Invalid Physics frame rate. Allowed: [".concat(I.join(", "),"]"));this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return t.prototype.updateForGame=function(t){this.unscaledGameDeltaTime=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},Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledGameDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t}(),G=function(){function t(t){var i=this;this._touching=!1,this._positionInViewport=new e(0,0),this._radius=new e(0,0),this.eventHandler=function(t){"touchstart"===t.type&&(i._touching=!0,i.updatePosition(t)),"touchmove"===t.type&&i.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(i._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,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radius",{get:function(){return this._radius},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),0!==t.targetTouches.length&&(this._positionInViewport.set((t.targetTouches[0].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[0].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),this._radius.set(t.targetTouches[0].radiusX,t.targetTouches[0].radiusY))},t}(),L=function(){function t(){}return t.initialize=function(t){this.assetManager=t},t.getAssetsLoaded=function(){return this.assetManager.getAssetsLoaded()},t.loadImage=function(t,e){return this.assetManager.loadImage(t,e)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.loadFont=function(t,e){return this.assetManager.loadFont(t,e)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.getFont=function(t){return this.assetManager.getFont(t)},t.assetManager=null,t}(),k=function(){function t(){}return t.initialize=function(t){this.domManager=t},Object.defineProperty(t,"gameWidth",{get:function(){return this.domManager.canvas.width},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gameHeight",{get:function(){return this.domManager.canvas.height},enumerable:!1,configurable:!0}),Object.defineProperty(t,"canvas",{get:function(){return this.domManager.canvas},enumerable:!1,configurable:!0}),t.domManager=null,t}(),V=function(){function t(){}return t.initialize=function(t){this.inputManager=t},Object.defineProperty(t,"mouse",{get:function(){return this.inputManager.mouse},enumerable:!1,configurable:!0}),Object.defineProperty(t,"keyboard",{get:function(){return this.inputManager.keyboard},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gamepad",{get:function(){return this.inputManager.gamepad},enumerable:!1,configurable:!0}),Object.defineProperty(t,"touch",{get:function(){return this.inputManager.touch},enumerable:!1,configurable:!0}),t.inputManager=null,t}(),W=function(){function t(){}return t.initialize=function(t){this.sceneManager=t},t.loadScene=function(t){this.sceneManager.loadScene(t)},t.getCurrentSceneName=function(){return this.sceneManager.currentSceneName},t.loadOpeningScene=function(){this.sceneManager.loadOpeningScene()},t.sceneManager=null,t}(),H=function(){function t(){}return t.initialize=function(t){this.timeManager=t},Object.defineProperty(t,"deltaTime",{get:function(){return this.timeManager.deltaTime},enumerable:!1,configurable:!0}),t.getTimeScale=function(){return this.timeManager.timeScale},t.setTimeScale=function(t){this.timeManager.timeScale=t},Object.defineProperty(t,"unscaledDeltaTime",{get:function(){return this.timeManager.unscaledGameDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"physicsDeltaTime",{get:function(){return this.timeManager.physicsDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"browserDeltaTime",{get:function(){return this.timeManager.browserDeltaTime},enumerable:!1,configurable:!0}),t.timeManager=null,t}(),z=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i,n){return this.manager.addGameObject(t,e,i,n)},t.findAllGameObjects=function(){return this.manager.findGameObjects()},t.findGameObjects=function(t){return this.manager.findGameObjects(t)},t.findGameObject=function(t){return this.manager.findGameObject(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParent=function(t,e){return this.manager.findGameObjectByParent(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t}(),Y=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=[]}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.sceneManager.unloadCurrentScene(),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.load(),this.dispatchFrameEvent(c.Start),this.dispatchFrameEvent(c.Update),this.dispatchFrameEvent(c.UpdateEngine),this.dispatchFrameEvent(c.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.update()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(c.UpdatePhysics),this.dispatchFrameEvent(c.UpdateCollider),this.dispatchFrameEvent(c.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return l(l([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==c.Start&&t!==c.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(C||(C={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(_||(_={})),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"}(j||(j={}));class N{constructor(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}setViewport({position:t,zoom:e},i){i===_.WorldSpace?(this.viewport.x=t.x-this.gl.canvas.width/e/2,this.viewport.x1=t.x+this.gl.canvas.width/e/2,this.viewport.y=t.y-this.gl.canvas.height/e/2,this.viewport.y1=t.y+this.gl.canvas.height/e/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)}setObjectForResizeable({position:t,width:e,height:i,rotation:n=0}){const r=Math.abs(Math.sin(n)),s=Math.abs(Math.cos(n)),o=r*i+s*e,a=r*e+s*i;this.object.x=t.x-o/2,this.object.x1=t.x+o/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:r,rotation:s}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:s})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===C.Circumference?(this.object.x=t.x-n,this.object.y=t.y-n,this.object.x1=t.x+n,this.object.y1=t.y+n):(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.renderPosition,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:n,tileHeight:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*n&&this.viewport.x<=this.object.x+e%i*n+n&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case j.Mask:case j.Sprite:this.setObjectForResizeable(t);break;case j.Geometric:this.setObjectForGeometric(t);break;case j.Text:this.setObjectForText(t);break;case j.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}applyCulling(t,e){return e.filter((e=>!!this.isInViewPort(e,t)&&(e.type===j.Tilemap&&this.applyCullingInTiles(e),!0)))}}class X{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))}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 X(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}}t.TilemapOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TilemapOrientation||(t.TilemapOrientation={}));class q{constructor(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}addRenderData(t){this.renderData.push(t)}addCameraData(t){this.cameraData.push(t)}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderByCamera(t)))}renderByCamera(e){this.cullingManager.applyCulling(e,this.renderData.filter((t=>e.layers.includes(t.layer))).sort(((t,i)=>e.layers.indexOf(t.layer)-e.layers.indexOf(i.layer))).map((e=>e.type===j.Tilemap?(e=>{const i=Object.assign(Object.assign({},e),{culledTiles:[],tilemap:Object.assign(Object.assign({},e.tilemap),{height:Math.ceil(e.tiles.length/e.tilemap.width),realWidth:e.tilemap.width*e.tilemap.tileWidth,realHeight:0}),renderPosition:new X});return i.tilemap.realHeight=i.tilemap.height*i.tilemap.tileHeight,(e=>{e.renderPosition.set(e.position.x+(e.orientation!==t.TilemapOrientation.Center?e.tilemap.realWidth/2:0),e.position.y+(e.orientation===t.TilemapOrientation.RightDown?-e.tilemap.realHeight/2:e.orientation===t.TilemapOrientation.RightUp?e.tilemap.realHeight/2:0))})(i),i})(e):e))).forEach((t=>this.webglManager.render(t,e)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}preloadTexture(t){this.webglManager.createTexture(t)}}var K;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(K||(K={}));class ${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(K.WebGL2)?K.WebGL2:null!==this.canvas.getContext(K.LegacyWebGL)?K.LegacyWebGL:void 0}}class Q{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 n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n: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 n=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),n),n}symbol(t){return Symbol.for(t instanceof FontFace?t.family:t)}renderAtlas(t){const e=new J(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 n=0,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e}}class J{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 Z{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i);const s=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,s)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class tt{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===K.WebGL2?this.programFactory.create("#version 300 es\nprecision mediump float;\n\nin vec2 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision mediump float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)}}class et{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var it="undefined"!=typeof Float32Array?Float32Array:Array;function nt(){var t=new it(16);return it!=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 rt(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 st(t,e,i){var n,r,s,o,a,h,l,c,d,u,p,g,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(n=e[0],r=e[1],s=e[2],o=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],u=e[9],p=e[10],g=e[11],t[0]=n,t[1]=r,t[2]=s,t[3]=o,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=u,t[10]=p,t[11]=g,t[12]=n*m+a*f+d*y+e[12],t[13]=r*m+h*f+u*y+e[13],t[14]=s*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function ot(t,e,i){var n=i[0],r=i[1],s=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]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function at(t,e,i){var n=Math.sin(i),r=Math.cos(i),s=e[0],o=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],u=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]=s*r+l*n,t[1]=o*r+c*n,t[2]=a*r+d*n,t[3]=h*r+u*n,t[4]=l*r-s*n,t[5]=c*r-o*n,t[6]=d*r-a*n,t[7]=u*r-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ht;function lt(){var t=new it(3);return it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ct(t,e,i){var n=new it(3);return n[0]=t,n[1]=e,n[2]=i,n}function dt(){var t=new it(4);return it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}lt(),function(){var t;t=new it(4),it!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),lt(),ct(1,0,0),ct(0,1,0),dt(),dt(),ht=new it(9),it!=Float32Array&&(ht[1]=0,ht[2]=0,ht[3]=0,ht[5]=0,ht[6]=0,ht[7]=0),ht[0]=1,ht[4]=1,ht[8]=1,function(){var t=new it(2);it!=Float32Array&&(t[0]=0,t[1]=0)}();const ut=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},pt=(t,e,i,n)=>{var r,s;(function(t,e,i,n,r,s,o){var a=1/(e-i),h=1/(n-r),l=1/(s-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]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=(o+s)*l,t[15]=1})(t=rt(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),st(t,t,[0,0,0]),n===_.WorldSpace&&ot(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(s=i.zoom)&&void 0!==s?s:1,1])};class gt{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(((t,e,i=1)=>{const n=[];for(let t=1;t<=e;t+=i)n.push(t);return n})(0,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e,i){switch(t.shape){case C.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case C.Line:this.renderLines(t,e,this.gl.LINES,i);break;case C.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var r;const s=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(s)&&this.vertices.set(s,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(s);this.lastVertices===s&&n===j.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW)),this.lastVertices=s,this.modelMatrix=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),pt(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);const{r:a,g:h,b:l,a:c}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,o.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ot(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),pt(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);const{r:i,g:n,b:r,a:s}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,r,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class mt{constructor(t,e){this.gl=t,this.programManager=e,this.type=j.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n,r;i!==j.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),pt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha>=0&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:s,g:o,b:a,a:h}=ut(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,s,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class ft{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt(),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 n,r,s,o;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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=rt(this.textureMatrix),t.slice&&(st(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),ot(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),pt(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);const 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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ut(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ut(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}t.TextOrientation=void 0,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={}));const yt=new X,xt=new X,vt=[32,126,161,255],bt=t.TextOrientation.Center;class Mt{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=j.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new X,this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,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=rt(this.modelMatrix),this.setPositionFromOrientation(t),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=rt(this.textureMatrix),pt(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);const s=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===s&&i===j.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,s),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=s),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:o,g:a,b:h,a:l}=ut(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,o,a,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)}setDefaultValues(t){var e,i,n,r,s,o,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:yt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:xt,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:vt):t.bitmap={margin:yt,spacing:xt,fontSize:64,charRanges:vt},t.color=null!==(s=t.color)&&void 0!==s?s:"#000000",t.letterSpacing=null!==(o=t.letterSpacing)&&void 0!==o?o: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!==(l=t.orientation)&&void 0!==l?l:bt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:r,lineSeparation:s}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;r/=i,s/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,o),o=0,a-=1+s;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(o,a-1,o+e,a-1,o,a,o,a,o+e,a-1,o+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,s=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(s+n.margin.y)/t.canvas.width,d=(i+c.width+n.spacing.x)/t.canvas.width,u=(s+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,u,d,u,h,l,h,l,d,u,d,l),o+=e+r}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-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))}}class wt{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 X,texSpacing:new X,texWidth:0,texHeight:0,texCorrection:new X},this.modelPosition=new X,this.projectionMatrix=nt(),this.modelMatrix=nt(),this.textureMatrix=nt()}render(t,e,i){var n,r,s,o;if(0===t.culledTiles.reduce(((t,e)=>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=rt(this.modelMatrix),X.round(this.modelPosition,t.location===_.WorldSpace?X.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),at(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ot(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=rt(this.textureMatrix),ot(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),pt(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);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===j.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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ut(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ut(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,r,s,o,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new X,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new X,t.correction=null!==(n=t.correction)&&void 0!==n?n:new X,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(s=t.spacing.x)&&void 0!==s?s:0),this.tileset.tileHeight=t.tileHeight+(null!==(o=t.margin.y)&&void 0!==o?o:0)+(null!==(a=t.spacing.y)&&void 0!==a?a: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({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const r=n%e.width-e.width/2,s=i/2-Math.floor(n/e.width);this.posVertices.push(r,s-1,r+1,s-1,r,s,r,s,r+1,s-1,r+1,s);const o=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(o,a+this.tileset.texHeight,o+this.tileset.texWidth,a+this.tileset.texHeight,o,a,o,a,o+this.tileset.texWidth,a+this.tileset.texHeight,o+this.tileset.texWidth,a)}))}}class Ct{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(()=>this.create(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i}create(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 _t{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 n;return null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n}}class jt{constructor(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}render(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}}clearCanvas(t){const e=ut(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}createTexture(t,e=!1){this.textureManager.createTextureFromImage(t,e)}}class Ot{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))}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 Ot(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 Pt{constructor(t,e,i,n){this._position=new Ot,this._center=new Ot,this._width=0,this._height=0,this.set(t,e,i,n)}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 width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}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 Pt?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Ot&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const Rt=(t,e,i)=>Math.min(i,Math.max(e,t));class At{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:n,position:r,rotation:s,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:n,position:null!=r?r:new Ot,rotation:null!=s?s:0,group:o,onCollision:a}}}class St{constructor(t,e=0){this.area=new Pt(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}resize(t){this.clear(),this.area.copy(t)}clear(){this.items=[],this.children.forEach((t=>t.clear())),this.children=[]}insert(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])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new Pt(this.area.x,this.area.y,t,e),new Pt(this.area.x,this.area.y+e,t,e),new Pt(this.area.x+t,this.area.y+e,t,e),new Pt(this.area.x+t,this.area.y,t,e)].map((t=>new St(t,this.depth+1))),this.items.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.items=[]}insertItemIntoChildren(t,e){this.getChildrenForArea(e).forEach((i=>i.insert(t,e)))}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((i=>e.push(...i.retrieve(t)))):this.items.forEach((t=>e.push(t[0]))),e}getChildrenForArea(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}}const Tt=(t,e,i,n)=>Math.min((t-e)/i|0,n-1);class Dt{constructor(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}get subdivisions(){return this._subdivisions}set subdivisions(t){this._subdivisions=Rt(t,1,20)}resize(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(let t=0;t<this._subdivisions;t++){this.itemsInCells[t]=[];for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}}clear(){for(let t=0;t<this._subdivisions;t++)for(let e=0;e<this._subdivisions;e++)this.itemsInCells[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.itemsInCells[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.itemsInCells[t][i].forEach((t=>e.includes(t)?null:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=Tt(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Tt(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Tt(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Tt(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}t.BroadPhaseMethods=void 0,function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(t.BroadPhaseMethods||(t.BroadPhaseMethods={}));class Et{constructor(e,i,n,r){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Ot,this.maxArea=new Ot,this.newArea=new Pt(0,0,0,0),this.method=e,this.colliders=[],this.activeColliders=[],this.collisionMatrix=r,this.setupBroadPhaseResolver(null!=i?i:t.BroadPhaseMethods.QuadTree,n)}setupBroadPhaseResolver(e,i){this.collisionArea=null!=i?i:new Pt(0,0,0,0),this.fixedCollisionArea=!!i,e===t.BroadPhaseMethods.SpartialGrid?this.broadPhaseResolver=new Dt(this.collisionArea):this.broadPhaseResolver=new St(this.collisionArea)}addCollider(t){this.colliders[t.id]=t}getCollider(t){return this.colliders[t]}removeCollider(t){delete this.colliders[t.id]}clearColliders(){this.colliders=[]}getCollisionsForCollider(t){return t.active?this.collisions.filter((e=>e.localCollider.id===t.id)):[]}refreshCollisionsForCollider(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((e=>e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id)),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))}resolve(){this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((t=>t.active)),this.broadPhaseResolver.clear(),this.activeColliders.forEach((t=>{this.updateShape(t)})),!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((({id:t,shape:{boundingBox:e}})=>this.broadPhaseResolver.insert(t,e))),this.updateCollisions())}updateShape(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()}updateNewArea(){this.activeColliders.forEach((({shape:{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.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}checkForSpartialGridResize(){this.broadPhaseResolver instanceof Dt&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)}updateCollisions(){this.activeColliders.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase(t){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t])).filter((e=>this.collisionMatrix.some((i=>i[0]===t.layer&&i[1]===e.layer||i[1]===t.layer&&i[0]===e.layer)))):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t]))}narrowPhase(t,e){e.filter((e=>!(t.group&&e.group&&e.group===t.group||t.id===e.id))).forEach((e=>{if(this.isResolved(t,e))return;const i=this.method.getCollisionResolution(t.shape,e.shape);null!==i&&(this.collisions.push({localCollider:t,remoteCollider:e,resolution:i},{localCollider:e,remoteCollider:t,resolution:{direction:i.displacementDirection,displacementDirection:i.direction,penetration:i.penetration}}),t.onCollision&&t.onCollision(i))}))}isResolved(t,e){for(const i of this.collisions)if(i.localCollider.id===t.id&&i.remoteCollider.id===e.id)return!0;return!1}}var Ft;t.CollisionMethods=void 0,t.RigidBodyType=void 0,function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Ft||(Ft={}));class Bt{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Ft.Polygon&&e.type===Ft.Polygon?this.AABBResolver.resolve(t,e):t.type===Ft.Circumference&&e.type===Ft.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Ft.Polygon&&e.type===Ft.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(t.CollisionMethods||(t.CollisionMethods={}));class It{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class Ut{constructor(){this.direction=new Ot,this.displacementDirection=new Ot}resolve({boundingBox:t},{boundingBox:e}){return 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?null:(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.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),Ot.unit(this.displacementDirection,this.displacementDirection),{direction:Ot.scale(new Ot,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),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),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}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),n=Math.abs(t.x1-e.x1);this.overlapX+=i<n?i:n}}}class Gt{constructor(){this.closestPoint=new Ot,this.distance=new Ot,this.direction=new Ot}resolve(t,e,i=!1){return this.closestPoint.set(Rt(t.position.x,e.boundingBox.x,e.boundingBox.x1),Rt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),Ot.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Ot.unit(this.direction,this.distance),{direction:i?Ot.scale(new Ot,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Ot.scale(new Ot,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class Lt{constructor(){this.distance=new Ot,this.direction=new Ot}resolve(t,e){return Ot.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Ot.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Ot.scale(new Ot,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class kt{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Ot,this.distance=new Ot(1/0,1/0),this.cache=new Ot}resolve(t,e){this.minOverlap=1/0,t.type===Ft.Circumference?this.setCircumferenceAxis(t,e):e.type===Ft.Circumference&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?null:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t.type===Ft.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Ft.Circumference&&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 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){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,Ot.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&&Ot.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Ot.scale(new Ot,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(Ot.dot(i,e),t.min),t.max=Math.max(Ot.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Ot.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Ot.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Ot.add(t.vertices[0],t.position,Ot.scale(this.cache,Ot.unit(this.cache,e),-t.radius)),Ot.add(t.vertices[1],t.position,Ot.scale(this.cache,Ot.unit(this.cache,e),t.radius))}}class Vt{constructor(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}addCollider(t){const e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e}removeCollider(t){this.collisionManager.removeCollider(t)}getCollisionsForCollider(t){return this.collisionManager.getCollisionsForCollider(t)}addRigidBody(t){const e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e}removeRigidBody(t){this.rigidBodyManager.removeRigidBody(t)}resolve(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)}clear(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()}}class Wt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:n,velocity:r,onResolve:s}){if(0===t.length)throw new Error("RigidBody needs at least one collider");return{id:++this.lastId,active:!0,colliderIds:t,type:e,gravity:null!=i?i:0,position:null!=n?n:new Ot,velocity:null!=r?r:new Ot,onResolve:s}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(t.RigidBodyType||(t.RigidBodyType={}));const Ht=["x","y"];class zt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Ot,this.displacement=new Ot,this.cacheDisplacement=0}addRigidBody(t){this.rigidBodies[t.id]=t}removeRigidBody(t){delete this.rigidBodies[t.id]}clearRigidBodies(){this.rigidBodies=[]}resolve(e){this.activeRigidBodies=this.rigidBodies.filter((t=>t.active)),this.colliders=this.activeRigidBodies.reduce(((t,e)=>[...t,...e.colliderIds]),[]),this.activeRigidBodies.forEach((i=>{i.type===t.RigidBodyType.Dynamic?this.dynamicUpdate(i,e):i.type===t.RigidBodyType.Kinematic&&this.kinematicUpdate(i,e),i.onResolve&&i.onResolve(i)}))}dynamicUpdate(t,e){this.applyGravity(t,e),Ht.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Ot.add(t.position,t.position,Ot.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Ot.add(t.position,t.position,this.velocity),this.collisionManager.refreshCollisionsForCollider(t)}))}applyGravity(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)}applyVelocity(t,e,i){this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[i]+=this.velocity[i],this.collisionManager.refreshCollisionsForCollider(t)})))}obtainDisplacement(t,e){this.displacement[e]=0,this.getCollisions(t).forEach((t=>{this.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,this.displacement[e]=Math.abs(this.displacement[e])>Math.abs(this.cacheDisplacement)?this.displacement[e]:this.cacheDisplacement}))}applyReposition(t,e){0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[e]+=this.displacement[e],this.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))}getCollisions(t){return t.colliderIds.map((t=>this.collisionManager.getCollider(t))).filter((t=>t.active&&t.physics)).reduce(((t,e)=>(t.push(...this.collisionManager.getCollisionsForCollider(e).filter((t=>t.remoteCollider.physics&&this.colliders.includes(t.remoteCollider.id)))),t)),[])}}class Yt{constructor(t){this.radius=t,this.type=Ft.Circumference,this.boundingBox=new Pt(0,0,0,0),this.vertices=[new Ot,new Ot],this.projectionAxes=[new Ot],this._position=new Ot}set position(t){this._position.copy(t)}get position(){return this._position}update(){this.updateBoundingBox()}updateBoundingBox(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}class Nt{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[new Ot,new Ot],this.projectionAxes=[new Ot],this.boundingBox=new Pt(0,0,0,0),this.rotation=0,this._position=new Ot}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}set position(t){this._position.copy(t)}get position(){return this._position}updateVertices(){for(let 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)}updateBoundingBox(){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}updateProjectionAxes(){Ot.normal(this.projectionAxes[0],Ot.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class Xt{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[],this.boundingBox=new Pt(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Ot,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(let t=0;t<this.vertexModel.length;t++)this.vertices.push(new Ot),this._projectionAxes.push(new Ot)}set position(t){this._position.copy(t)}get position(){return this._position}get projectionAxes(){return this._projectionAxes}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}updateVertices(){for(let 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)}updateBoundingBox(){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((t=>{this.boxMinX=Math.min(t.x,this.boxMinX),this.boxMinY=Math.min(t.y,this.boxMinY),this.boxMaxX=Math.max(t.x,this.boxMaxX),this.boxMaxY=Math.max(t.y,this.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)}updateProjectionAxes(){var t;for(let e=0;e<this.vertices.length;e++)Ot.normal(this._projectionAxes[e],Ot.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class qt extends Xt{constructor(t,e){super([new Ot(-t/2,-e/2),new Ot(-t/2,e/2),new Ot(t/2,e/2),new Ot(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Ot,new Ot]}updateSize(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)}updateProjectionAxes(){Ot.unit(this.projectionAxes[0],Ot.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Ot.normal(this.projectionAxes[1],this.projectionAxes[0])}}var Kt,$t=function(e,i){e.addConstant("GameConfig",i),e.add("TimeManager",(function(){return new U(i.physicsFramerate)})),e.add("GameObjectManager",(function(){return new A(e)})),e.add("PhysicsManager",(function(){return(({collisionArea:e,collisionMatrix:i,collisionMethod:n,collisionBroadPhaseMethod:r}={})=>{const s=new Lt,o=n===t.CollisionMethods.AABB?new Bt(new Ut,new Gt,s):new It(s,new kt),a=new Et(o,r,e,i),h=new At,l=new zt(a),c=new Wt;return new Vt(a,h,l,c)})(i.collisions)})),i.headless?e.add("IterationManager",(function(){return new Y(e.getSingleton("TimeManager"),e.getSingleton("PhysicsManager"),e.getSingleton("GameObjectManager"),e.getSingleton("SceneManager"))})):(e.add("DomManager",(function(){return new R(i.containerNode,i.gameWidth,i.gameHeight)})),e.add("RenderManager",(function(){return(t=>{const e=new $(t),i=e.gl,n=e.contextVersion,r=new tt(i,n,new Z(i,new et(i))),s=new _t(new Ct(i)),o=new jt(i,r,s,new Map([[j.Sprite,new ft(i,r,s)],[j.Text,new Mt(i,r,s,new Q)],[j.Tilemap,new wt(i,r,s)],[j.Geometric,new gt(i,r)],[j.Mask,new mt(i,r)]]));return new q(o,new N(i))})(e.getSingleton("DomManager").canvas)})),Qt(e),e.add("AssetManager",(function(){return new O(e.getSingleton("RenderManager"))})),e.add("IterationManager",(function(){return new p(e.getSingleton("TimeManager"),e.getSingleton("PhysicsManager"),e.getSingleton("RenderManager"),e.getSingleton("InputManager"),e.getSingleton("GameObjectManager"),e.getSingleton("SceneManager"),i.canvasColor)}))),e.add("SceneManager",(function(){return new B(e,i.headless?void 0:e.getSingleton("RenderManager"))})),Jt(e,i)},Qt=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new D(new F(e.canvas),new E(e.canvas),new S,new G(e.canvas))}))},Jt=function(t,e){e.headless||(L.initialize(t.getSingleton("AssetManager")),k.initialize(t.getSingleton("DomManager")),V.initialize(t.getSingleton("InputManager"))),W.initialize(t.getSingleton("SceneManager")),H.initialize(t.getSingleton("TimeManager")),z.initialize(t.getSingleton("GameObjectManager"))},Zt=function(){function t(){this.instances=new Map,this.constructors=new Map,this.constants=new Map}return t.prototype.add=function(t,e){if(this.constructors.has(t))throw new P("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 P("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 P("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new P("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 P("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),te={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new e(1,1),collisions:{collisionMethod:t.CollisionMethods.SAT,collisionBroadPhaseMethod:t.BroadPhaseMethods.SpartialGrid}},ee=function(){function t(t){this._config=h(h({},te),t),this._config.collisions=h(h({},te.collisions),t.collisions),this.container=new Zt,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){$t(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){void 0===n&&(n=!1),this.sceneManager.addScene(t,e,i,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}(),ie=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new e,i._scale=new e(1,1),i._rotation=new s,i._innerPosition=new e,i._parent=null,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.scaledInnerPosition=new e,i}return a(i,t),Object.defineProperty(i.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&e.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},i.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(),e.add(this._position,this._parent.position,this.scaledInnerPosition)):e.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)},i.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)),e.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},i.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},i}(v),ne=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.physicsManager=e.container.getSingleton("PhysicsManager"),e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return a(e,t),e.prototype.update=function(){this.activateColliders&&(this.colliders.forEach((function(t){return t.active=!0})),this.activateColliders=!1),this.updateRealSize(),this.updatePosition(),this.updateColliders()},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,s=this.physicsManager.getCollisionsForCollider(n);r<s.length;r++){var o=s[r];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],s=0,o=this.physicsManager.getCollisionsForCollider(r);s<o.length;s++){var a=o[s];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.group),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(y),re=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.physicsManager=e.container.getSingleton("PhysicsManager"),e}return a(i,t),Object.defineProperty(i.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),i.prototype.init=function(t){var i,n=t.rigidBodyType,r=t.gravity;if(0===this.getColliderIds().length)throw new P("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:n,colliderIds:this.getColliderIds(),gravity:null!==(i=Math.abs(r))&&void 0!==i?i:0,velocity:new e,position:new e})},i.prototype.update=function(){if(0===this.getColliderIds().length)throw new P("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},i.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof ne&&t.physics})).reduce((function(t,e){return l(l([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},i.prototype.onActiveChange=function(){this.rigidBody.active=this.active},i.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},i}(f),se="Default",oe=function(t){function e(e,i,n){void 0===i&&(i="");var r=t.call(this,e)||this;return r.id=d(),r.layer=se,r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.name=i,r.addComponent(ie),r.parent=null!=n?n:null,r}return a(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(ie)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(re)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r="string"==typeof e?e:i,s=new t(this.container,this,r);return this.checkMultipleComponent(s,t),this.components.push(s),s.dispatch(c.Init,n),s},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new P("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(c.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(c.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(g),ae=[se],he=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.renderManager=e.container.getSingleton("RenderManager"),e.canvas=e.container.getSingleton("DomManager").canvas,e.viewportRect=new i(0,0,0,0),e.worldSpaceRect=new i(0,0,0,0),e.depth=0,e.layers=ae,e._zoom=1,e}return a(n,t),Object.defineProperty(n.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new P("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),n.prototype.addLayer=function(t){this.layers.push(t)},n.prototype.init=function(){this.cameraData={position:new e,layers:[],depth:1}},n.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},n.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},n.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},n.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)},n}(M),le=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(he)},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}(oe),ce=function(t){function e(e,i,n){var r=t.call(this,e)||this;return r.name=i,r.game=n,r.game.config.headless||r.addGameObject(le),r}return a(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(le)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(),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}(g),de=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return a(n,i),n.prototype.init=function(i){var n,r,o,a,h,l;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==t.CollisionMethods.SAT)throw new P("Polygon Colliders need SAT collision method.");if(i.vertexModel.length<3)throw new P("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var c=0;c<this.vertexModel.length;c++)this.scaledVertexModel.push(new e);this.colliders.push(this.physicsManager.addCollider({layer:null!==(l=this.layer)&&void 0!==l?l:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Xt(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ue,{collider:this.colliders[0]}))},n.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},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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},n}(ne),ue=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return a(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:j.Geometric,location:_.WorldSpace,layer:this.gameObject.layer,position:new e,shape:C.Polygon,color:"#00FF00"},this.collider=i},i.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)},i}(w),pe=function(i){function n(){var n=null!==i&&i.apply(this,arguments)||this;return n.debug=!1,n.offsetX=0,n.offsetY=0,n.realWidth=0,n.realHeight=0,n.realOffset=new e,n.realPosition=new e,n.realRotation=0,n.applyRotation=n.container.getConstant("GameConfig").collisions.collisionMethod===t.CollisionMethods.SAT,n.innerPosition=new e,n}return a(n,i),n.prototype.init=function(t){var e,i,n,r,o,a;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!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new s,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new qt(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ue,{collider:this.colliders[0]}))},n.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},n.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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)},n}(ne),ge=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new e,i.realPosition=new e,i.innerPosition=new e,i}return a(i,t),i.prototype.init=function(t){var e,i,n,r,s;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!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,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(),shape:new Yt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},i.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},i.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){e.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))},i.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},i}(ne),me=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return a(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:j.Geometric,location:_.WorldSpace,layer:this.gameObject.layer,position:new e,shape:C.Circumference,color:"#00FF00"},this.collider=i},i.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)},i}(w),fe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.position=new e,t}return a(n,i),n.prototype.init=function(e){var i,n;this.tilemapRenderer=e.tilemapRenderer,this.layer=e.layer,this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.physics=!0,this.composite=null!==(n=e.composite)&&void 0!==n&&n,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===t.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([t.TilemapOrientation.Center,t.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==t.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(ye,{colliders:this.colliders}))},n.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(i,n){var r;t.needsCollider(i,n)&&t.colliders.push(t.physicsManager.addCollider({layer:null!==(r=t.layer)&&void 0!==r?r:t.gameObject.layer,position:new e(t.position.x+(n%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(n/t.tilemapRenderer.width)+.5)*t.scaledTileHeight),shape:new qt(t.scaledTileWidth,t.scaledTileHeight),updateCollisions:!1,physics:t.physics,group:t.gameObject.id}))}))},n.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]}))},n.prototype.useLineColliders=function(){var t,i,n=this,r=[],s=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,o=Math.floor(e/n.tilemapRenderer.width);r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]),s[o]||(s[o]=[]),s[o+1]||(s[o+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[o][i]=!0),n.hasTile(a[2])||(r[o+1][i]=!0),n.hasTile(a[1])||(s[o][i]=!0),n.hasTile(a[3])||(s[o][i+1]=!0)}}));for(var o=0;o<r.length;o++)if(r[o])for(var a=0;a<r[o].length;a++)!t||!i||o===i.y&&r[o][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),r[o][a]&&(t||(t=new e(a,o)),i=new e(a+1,o));t&&i&&this.addLineCollider(t,i),t=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<s.length;o++)s[o]&&(!t||!i||a===i.x&&s[o][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),s[o][a]&&(t||(t=new e(a,o)),i=new e(a,o+1)));t&&i&&this.addLineCollider(t,i)},n.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},n.prototype.addLineCollider=function(t,i){var n,r=this.physicsManager.addCollider({layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,position:this.position.clone(),shape:new Nt([new e(t.x*this.scaledTileWidth,t.y*-this.scaledTileHeight),new e(i.x*this.scaledTileWidth,i.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id});this.colliders.push(r)},n.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]},n.prototype.updateRealSize=function(){},n.prototype.updatePosition=function(){},n.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}))},n}(ne),ye=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return a(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:j.Geometric,layer:i.gameObject.layer,location:_.WorldSpace,position:new e,shape:C.Polygon,color:"#00FF00"}}))},i.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])}))},i}(w),xe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return a(n,i),n.prototype.init=function(i){var n,r,o,a,h,l;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==t.CollisionMethods.SAT)throw new P("Edge Colliders need SAT collision method.");if(i.vertexModel.length<2)throw new P("Edge Collider needs at least 2 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var c=0;c<this.vertexModel.length;c++)this.scaledVertexModel.push(new e);for(c=0;c<this.scaledVertexModel.length-1;c++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(l=this.layer)&&void 0!==l?l:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new Nt([this.scaledVertexModel[c],this.scaledVertexModel[c+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(ve,{colliders:this.colliders}))},n.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},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.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))},n.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]]},n}(ne),ve=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return a(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:j.Geometric,layer:i.gameObject.layer,location:_.WorldSpace,position:new e,shape:C.Line,color:"#00FF00"}}))},i.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])}))},i}(w),be=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.spriteDefaultScale=i.container.getConstant("GameConfig").spriteDefaultScale,i.renderData=[],i.innerPosition=new e,i.cachePosition=new e,i.cacheRenderPosition=new e,i.scaledOffset=new e,i}return a(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(i=t.offset)&&void 0!==i?i:new e,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:new s,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this._tiled=null!==(h=t.tiled)&&void 0!==h?h:new e(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(l=t.maskColorMix)&&void 0!==l?l:0,this.tintColor=t.tintColor,this.layer=t.layer},Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new P("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){var t;if(this.sprite&&!0===this.sprite.loaded){this.sprite.scale=null!==(t=this.sprite.scale)&&void 0!==t?t:this.spriteDefaultScale,this.updateRenderDataArray();for(var e=0,i=0;i<this._tiled.x;i++)for(var n=0;n<this._tiled.y;n++)this.updateRenderData(e,i,n),e++}},i.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:j.Sprite,location:_.WorldSpace,layer:"",position:new e,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?_.ViewPort:_.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=this.sprite.width*Math.abs(this.gameObject.transform.scale.x),this.renderData[t].height=this.sprite.height*Math.abs(this.gameObject.transform.scale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.gameObject.transform.scale.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])},i.prototype.calculateRenderPosition=function(t,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.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)),e.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[t].width,n*this.renderData[t].height),e.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},i.prototype.translateRenderPosition=function(t){e.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var i=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(i),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(i))},i}(w),Me=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.lastFrameText="",e}return a(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l,c,d,u,p,g;if(this.text=t.text,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!==(r=t.width)&&void 0!==r?r:100,this.height=null!==(o=t.height)&&void 0!==o?o:100,this.offset=null!==(a=t.offset)&&void 0!==a?a:new e,this.color=null!==(h=t.color)&&void 0!==h?h:"#000000",this.charRanges=null!==(l=t.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(d=t.letterSpacing)&&void 0!==d?d:0,this.smooth=null!==(u=t.smooth)&&void 0!==u&&u,this.rotation=null!==(p=t.rotation)&&void 0!==p?p:new s,this.opacity=null!==(g=t.opacity)&&void 0!==g?g:1,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new P("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new P("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:j.Text,location:_.WorldSpace,position:new e,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},i.prototype.update=function(){var t,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?_.ViewPort:_.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!==(i=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==i?i:0,this.renderData.alpha=this.opacity,e.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text)},i.prototype.crop=function(){var t;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,r=this.text.split("\n");n<r.length;n++)for(var s=0,o=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];s<o.length;s++){var a=o[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(w),we=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.offset=new e,i.rotation=new s,i.opacity=1,i.innerPosition=new e,i.scaledOffset=new e,i}return a(i,t),i.prototype.init=function(t){var i,n,r,s;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:this.opacity,this.layer=t.layer,this.renderData={type:j.Mask,layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?_.ViewPort:_.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},i.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){e.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))},i}(w),Ce=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return a(i,t),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,r=t.tileWidth,s=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=r,this.tileHeight=s,this.layer=o,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(e){return t.processChunk(e)})):t.processChunk(e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(t){var i,n=this,r={type:j.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return n.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=r.tiles:r.tiles.forEach((function(e,i){n.tiles[n.tiledData.width*(t.y+Math.floor(i/t.width))+t.x+i%t.width]=e})),this.renderData.push(r),this.chunks.push(t)},i.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]},i.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.tiledData.width*this.scaledTileWidth,this.realHeight=this.tiledData.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.alpha}))},i}(w),_e=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return a(i,t),i.prototype.init=function(t){var i,n=this,r=t.tiles,s=t.tileset,o=t.tileWidth,a=t.tileHeight,h=t.width,l=t.layer,c=t.orientation,d=t.alpha,u=t.tintColor,p=t.smooth;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=s,this.width=h,this.tileWidth=o,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=d,this.tintColor=u,this.renderData={type:j.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?_.ViewPort:_.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},i.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},i.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.alpha,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},i}(w),je=function(t){var e,i;this.sprites=[],this.framerate=10,this.loop=!1,this.sprites=t.sprites,this.framerate=null!==(e=t.framerate)&&void 0!==e?e:this.framerate,this.loop=null!==(i=t.loop)&&void 0!==i?i:this.loop},Oe="default",Pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.timeManager=e.container.getSingleton("TimeManager"),e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return a(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=Oe),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new Re(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t=Oe),!1!==this.active){if(!1===this.animations.has(t))throw new P("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return void 0===t&&(t=Oe),null!==this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(f),Re=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}(),Ae=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Se=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(){Ae.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return a(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,r=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&Ae.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=r?r: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}(f),Te=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.scale=t.scale,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(){var t,e;return null!==(e=this._width*(null===(t=this.scale)||void 0===t?void 0:t.x))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){var t,e;return null!==(e=this._height*(null===(t=this.scale)||void 0===t?void 0:t.y))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();t.ButtonType=void 0,(Kt=t.ButtonType||(t.ButtonType={}))[Kt.Rectangle=0]="Rectangle",Kt[Kt.Circumference=1]="Circumference";var De=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.width=100,t.height=100,t.radius=50,t.touchEnabled=!0,t._offset=new e,t.pressed=!1,t.mouse=t.container.getSingleton("InputManager").mouse,t.touch=t.container.getSingleton("InputManager").touch,t.position=new e,t.distance=new e,t.pressedLastFrame=!1,t.scaled={width:0,height:0,radius:0,offset:new e},t}return a(n,i),Object.defineProperty(n.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,r=t.touchEnabled,s=t.width,o=t.offset;this.type=e,this.width=null!=s?s:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this._offset=null!=o?o:this._offset},n.prototype.update=function(){this.scale(),e.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()},n.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))},n.prototype.resolveMouseAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=r(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&r(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},n.prototype.resolveMouseAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},n.prototype.resolveTouchAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=this.position.x+this.scaled.width/2>=this.touch.positionInViewport.x-this.touch.radius.x&&this.position.x-this.scaled.width/2<=this.touch.positionInViewport.x+this.touch.radius.x&&this.position.y+this.scaled.height/2>=this.touch.positionInViewport.y-this.touch.radius.y&&this.position.y-this.scaled.height/2<=this.touch.positionInViewport.y+this.touch.radius.y))},n.prototype.resolveTouchAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},n}(m),Ee=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return a(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){V.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.round(this.position,e.add(this.position,this.camera.transform.position,e.scale(this.position,V.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=V.mouse.leftButtonPressed},i}(oe);t.Animation=je,t.Animator=Pe,t.AssetManager=L,t.AudioPlayer=Se,t.BallCollider=ge,t.BoxCollider=pe,t.Button=De,t.Camera=he,t.Component=m,t.DomManager=k,t.EdgeCollider=xe,t.Game=ee,t.GameCamera=le,t.GameObject=oe,t.GameObjectManager=z,t.GamepadController=S,t.GamepadData=T,t.InputManager=V,t.KeyboardController=E,t.LAYER_DEFAULT=se,t.MaskRenderer=we,t.MouseController=F,t.PhysicsComponent=x,t.PolygonCollider=de,t.PolygonColliderRenderer=ue,t.PreRenderComponent=b,t.Rectangle=i,t.RigidBody=re,t.Rotation=s,t.Scene=ce,t.SceneManager=W,t.SpacePointer=Ee,t.Sprite=Te,t.SpriteRenderer=be,t.TextRenderer=Me,t.TiledTilemapRenderer=Ce,t.TilemapCollider=fe,t.TilemapRenderer=_e,t.TimeManager=H,t.TouchController=G,t.Transform=ie,t.Vector2=e,t.between=r,t.clamp=(t,e,i)=>Math.min(i,Math.max(e,t)),t.fixedRound=n,t.randomFloat=(t,e,i=2)=>n(Math.random()*(e-t)+t,i),t.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,t.range=(t,e,i=1)=>{const n=[];for(let r=t;r<=e;r+=i)n.push(r);return n},Object.defineProperty(t,"__esModule",{value:!0})}));