angry-pixel 1.0.5 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/lib/Engine/Component.d.ts +15 -4
  2. package/lib/Engine/Components/Animator.d.ts +0 -1
  3. package/lib/Engine/Components/AudioPlayer.d.ts +0 -1
  4. package/lib/Engine/Components/Camera.d.ts +0 -1
  5. package/lib/Engine/Components/Colliders/BoxCollider.d.ts +0 -1
  6. package/lib/Engine/Components/Colliders/TilemapCollider.d.ts +0 -1
  7. package/lib/Engine/Components/ComponentTypes.d.ts +13 -0
  8. package/lib/Engine/Components/Renderer/CsvTilemapRenderer.d.ts +2 -1
  9. package/lib/Engine/Components/Renderer/SpriteRenderer.d.ts +2 -1
  10. package/lib/Engine/Components/Renderer/TextRenderer.d.ts +8 -1
  11. package/lib/Engine/Components/Renderer/TiledTilemapRenderer.d.ts +1 -1
  12. package/lib/Engine/Components/Renderer/TilemapRenderer.d.ts +16 -3
  13. package/lib/Engine/Components/RigidBody.d.ts +0 -1
  14. package/lib/Engine/Components/Transform.d.ts +0 -1
  15. package/lib/Engine/Core/GameObject/GameObjectManager.d.ts +5 -5
  16. package/lib/Engine/Core/Input/GamepadController.d.ts +1 -1
  17. package/lib/Engine/Core/Rendering/RenderData/ImageRenderData.d.ts +1 -0
  18. package/lib/Engine/Core/Rendering/RenderData/TextRenderData.d.ts +4 -0
  19. package/lib/Engine/Core/Rendering/RenderData/TilemapRenderData.d.ts +1 -0
  20. package/lib/Engine/Core/Rendering/WebGL/ProgramManager.d.ts +7 -3
  21. package/lib/Engine/Core/Rendering/WebGL/Renderer/GeometricRenderer.d.ts +0 -1
  22. package/lib/Engine/Core/Rendering/WebGL/Renderer/ImageRenderer.d.ts +0 -1
  23. package/lib/Engine/Core/Rendering/WebGL/Renderer/TextRenderer.d.ts +2 -1
  24. package/lib/Engine/Core/Rendering/WebGL/Renderer/TilemapRenderer.d.ts +0 -1
  25. package/lib/Engine/Core/Rendering/WebGL/Shader/Legacy/imageFragmentShader.d.ts +1 -1
  26. package/lib/Engine/Core/Rendering/WebGL/Shader/imageFragmentShader.d.ts +1 -1
  27. package/lib/Engine/Core/Rendering/WebGL/Utils.d.ts +3 -2
  28. package/lib/Engine/Facades/GameObjectManagerFacade.d.ts +4 -4
  29. package/lib/Engine/GameObject.d.ts +12 -7
  30. package/lib/Engine/Math/Rotation.d.ts +4 -0
  31. package/lib/Engine/Scene.d.ts +10 -5
  32. package/lib/component/Animation.d.ts +12 -0
  33. package/lib/component/Animator.d.ts +18 -0
  34. package/lib/component/AudioPlayer.d.ts +27 -0
  35. package/lib/component/Camera.d.ts +30 -0
  36. package/lib/component/ComponentTypes.d.ts +14 -0
  37. package/lib/component/RigidBody.d.ts +39 -0
  38. package/lib/component/Sprite.d.ts +31 -0
  39. package/lib/component/Transform.d.ts +32 -0
  40. package/lib/component/colliderComponent/AbstractColliderComponent.d.ts +22 -0
  41. package/lib/component/colliderComponent/BoxCollider.d.ts +32 -0
  42. package/lib/component/colliderComponent/TilemapCollider.d.ts +15 -0
  43. package/lib/component/renderingComponent/MaskRenderer.d.ts +29 -0
  44. package/lib/component/renderingComponent/SpriteRenderer.d.ts +46 -0
  45. package/lib/component/renderingComponent/TextRenderer.d.ts +49 -0
  46. package/lib/component/renderingComponent/tilemap/CsvTilemapRenderer.d.ts +13 -0
  47. package/lib/component/renderingComponent/tilemap/Tile.d.ts +7 -0
  48. package/lib/component/renderingComponent/tilemap/TileData.d.ts +10 -0
  49. package/lib/component/renderingComponent/tilemap/TiledTilemapRenderer.d.ts +43 -0
  50. package/lib/component/renderingComponent/tilemap/TilemapRenderer.d.ts +72 -0
  51. package/lib/component/renderingComponent/tilemap/Tileset.d.ts +25 -0
  52. package/lib/core/Component.d.ts +130 -0
  53. package/lib/core/Game.d.ts +77 -0
  54. package/lib/core/GameObject.d.ts +158 -0
  55. package/lib/core/Scene.d.ts +67 -0
  56. package/lib/core/facades/AssetManagerFacade.d.ts +29 -0
  57. package/lib/core/facades/DomManagerFacade.d.ts +8 -0
  58. package/lib/core/facades/GameObjectManagerFacade.d.ts +54 -0
  59. package/lib/core/facades/InputManagerFacade.d.ts +13 -0
  60. package/lib/core/facades/SceneManagerFacade.d.ts +18 -0
  61. package/lib/core/facades/TimeManagerFacade.d.ts +10 -0
  62. package/lib/core/ioc/Config.d.ts +3 -0
  63. package/lib/core/managers/AssetManager.d.ts +16 -0
  64. package/lib/core/managers/DomManager.d.ts +9 -0
  65. package/lib/core/managers/GameObjectManager.d.ts +17 -0
  66. package/lib/core/managers/IterationManager.d.ts +29 -0
  67. package/lib/core/managers/SceneManager.d.ts +18 -0
  68. package/lib/core/managers/TimeManager.d.ts +18 -0
  69. package/lib/gameObject/GameCamera.d.ts +17 -0
  70. package/lib/gameObject/SpacePointer.d.ts +8 -0
  71. package/lib/index.cjs.js +1 -1
  72. package/lib/index.d.ts +39 -36
  73. package/lib/index.esm.js +1 -1
  74. package/lib/index.js +1 -1
  75. package/lib/input/GamepadController.d.ts +48 -0
  76. package/lib/input/InputManager.d.ts +12 -0
  77. package/lib/input/KeyboardController.d.ts +12 -0
  78. package/lib/input/MouseController.d.ts +21 -0
  79. package/lib/input/TouchController.d.ts +13 -0
  80. package/lib/math/Rectangle.d.ts +50 -0
  81. package/lib/math/Rotation.d.ts +16 -0
  82. package/lib/math/Utils.d.ts +33 -0
  83. package/lib/math/Vector2.d.ts +114 -0
  84. package/lib/physics/collision/CollisionData.d.ts +8 -0
  85. package/lib/physics/collision/CollisionManager.d.ts +27 -0
  86. package/lib/physics/collision/QuadTree.d.ts +32 -0
  87. package/lib/physics/collision/collider/ICollider.d.ts +13 -0
  88. package/lib/physics/collision/collider/RectangleCollider.d.ts +31 -0
  89. package/lib/physics/collision/resolver/AABBResolver.d.ts +14 -0
  90. package/lib/physics/collision/resolver/ICollisionResolver.d.ts +5 -0
  91. package/lib/physics/collision/resolver/SatResolver.d.ts +14 -0
  92. package/lib/physics/collision/shape/Rectangle.d.ts +13 -0
  93. package/lib/physics/collision/shape/Shape.d.ts +28 -0
  94. package/lib/rendering/CameraData.d.ts +9 -0
  95. package/lib/rendering/ContextRenderer.d.ts +6 -0
  96. package/lib/rendering/CullingService.d.ts +11 -0
  97. package/lib/rendering/FontAtlasFactory.d.ts +24 -0
  98. package/lib/rendering/RenderManager.d.ts +22 -0
  99. package/lib/rendering/context2D/Context2DRenderer.d.ts +19 -0
  100. package/lib/rendering/renderData/ColliderRenderData.d.ts +7 -0
  101. package/lib/rendering/renderData/GeometricRenderData.d.ts +12 -0
  102. package/lib/rendering/renderData/ImageRenderData.d.ts +22 -0
  103. package/lib/rendering/renderData/MaskRenderData.d.ts +9 -0
  104. package/lib/rendering/renderData/RenderData.d.ts +23 -0
  105. package/lib/rendering/renderData/TextRenderData.d.ts +22 -0
  106. package/lib/rendering/renderData/TilemapRenderData.d.ts +22 -0
  107. package/lib/rendering/webGL/ProgramFactory.d.ts +7 -0
  108. package/lib/rendering/webGL/ProgramManager.d.ts +26 -0
  109. package/lib/rendering/webGL/ShaderLoader.d.ts +3 -0
  110. package/lib/rendering/webGL/TextureFactory.d.ts +8 -0
  111. package/lib/rendering/webGL/TextureManager.d.ts +11 -0
  112. package/lib/rendering/webGL/Utils.d.ts +7 -0
  113. package/lib/rendering/webGL/WebGLRenderer.d.ts +36 -0
  114. package/lib/rendering/webGL/renderer/GeometricRenderer.d.ts +22 -0
  115. package/lib/rendering/webGL/renderer/ImageRenderer.d.ts +16 -0
  116. package/lib/rendering/webGL/renderer/MaskRenderer.d.ts +14 -0
  117. package/lib/rendering/webGL/renderer/TextRenderer.d.ts +21 -0
  118. package/lib/rendering/webGL/renderer/TilemapRenderer.d.ts +19 -0
  119. package/lib/rendering/webGL/shader/imageFragmentShader.d.ts +1 -0
  120. package/lib/rendering/webGL/shader/imageVertexShader.d.ts +1 -0
  121. package/lib/rendering/webGL/shader/legacy/imageFragmentShader.d.ts +1 -0
  122. package/lib/rendering/webGL/shader/legacy/imageVertexShader.d.ts +1 -0
  123. package/lib/utils/Container.d.ts +12 -0
  124. package/lib/utils/Exception.d.ts +4 -0
  125. package/lib/utils/UUID.d.ts +1 -0
  126. package/package.json +1 -1
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";var e=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),i=function(){function t(t,i,n,r){this._position=new e,this._center=new e,this._width=0,this._height=0,this.set(t,i,n,r)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.updateFromRect=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlappingRectangle=function(t){return this.x1>=t.x&&this.x<=t.x1&&this.y1>=t.y&&this.y<=t.y1},t}(),n=function(t,e){return n=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])},n(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var o,a=function(){return a=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},a.apply(this,arguments)};function s(t,e,i,n){return new(i||(i=Promise))((function(r,o){function a(t){try{h(n.next(t))}catch(t){o(t)}}function s(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((n=n.apply(t,e||[])).next())}))}function h(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r<o;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(t){t.Image="Image",t.Audio="Audio",t.Video="Video"}(o||(o={}));var l,u=function(){this.type=null,this.url=null,this.loaded=!1,this.element=null},p=function(){function t(){this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.createImage=function(t){var e=this.createAsset(t,o.Image);return e.element=new Image,e.element.src=t,e.element.naturalWidth?e.loaded=!0:e.element.addEventListener("load",(function(){return e.loaded=!0})),e.element},t.prototype.createAudio=function(t){var e=this.createAsset(t,o.Audio);return e.element=new Audio,e.element.src=t,e.element.duration?e.loaded=!0:e.element.addEventListener("canplaythrough",(function(){return e.loaded=!0})),e.element},t.prototype.createVideo=function(t){var e=this.createAsset(t,o.Video);return e.element=document.createElement("video"),e.element.src=t,e.element.duration?e.loaded=!0:e.element.addEventListener("canplaythrough",(function(){return e.loaded=!0})),e.element},t.prototype.getImage=function(t){return this.getAsset(t,o.Image)},t.prototype.getVideo=function(t){return this.getAsset(t,o.Video)},t.prototype.getAudio=function(t){return this.getAsset(t,o.Audio)},t.prototype.getAsset=function(t,e){return void 0===e&&(e=null),this.assets.reduce((function(i,n){return n.url!==t||null!==e&&e!==n.type?i:n}),null).element},t.prototype.createAsset=function(t,e){var i=new u;return i.type=e,i.url=t,this.assets.push(i),i},t}();!function(t){t[t.Image=0]="Image",t[t.Text=1]="Text",t[t.Geometric=2]="Geometric",t[t.Collider=3]="Collider",t[t.Tilemap=4]="Tilemap"}(l||(l={}));var d,f=function(){function t(){this.ui=!1,this.debug=!1,this.layer=null,this._position=new e(0,0),this._positionInViewport=new e(0,0)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},set:function(t){this._positionInViewport.set(t.x,t.y)},enumerable:!1,configurable:!0}),t}(),g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=l.Geometric,e.color=null,e.geometricType=null,e.geometric=null,e}return r(e,t),e.prototype.getGeometric=function(){return this.geometric},e}(f),m=function(t){function e(i){var n=t.call(this,e.messagePrefix+": "+i)||this;return n.name="GameEngineException",n}return r(e,t),e.messagePrefix="Angry Pixel Exception",e}(Error),y=function(){function t(t,n,r,o){void 0===r&&(r=6),void 0===o&&(o=15),this._bounds=new i(0,0,0,0),this._quadrants=[],this.colliders=[],this.sw=0,this.se=1,this.nw=2,this.ne=3,this.center=new e,this.childrenWidth=0,this.childrenHeight=0,this.quadrantsForCollider=[],this.level=t,this._bounds.updateFromRect(n),this.maxLevels=r,this.maxColliders=o,this.updateCache()}return Object.defineProperty(t.prototype,"bounds",{get:function(){return this._bounds},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"quadrants",{get:function(){return this._quadrants},enumerable:!1,configurable:!0}),t.prototype.updateBounds=function(t){this._bounds.updateFromRect(t),this.updateCache()},t.prototype.clearColliders=function(){this.colliders=[],this._quadrants.forEach((function(t){return t.clearColliders()}))},t.prototype.clearQuadrants=function(){this._quadrants.forEach((function(t){return t.clearQuadrants()})),this._quadrants=[]},t.prototype.addCollider=function(t){this._quadrants.length>0?this.insertColliderIntoChildrenQuads(t):(this.colliders.push(t),this.colliders.length>this.maxColliders&&this.level<this.maxLevels&&this.splitQuad())},t.prototype.retrieve=function(t){var e=[];this._quadrants.length>0&&this.getChildrenQuadrantForCollider(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})),e.push.apply(e,this.colliders);var i=e.indexOf(t);return-1!==i&&e.splice(i,1),e},t.prototype.splitQuad=function(){var e=this;this._quadrants=[new i(this.center.x-this.childrenWidth,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new i(this.center.x,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new i(this.center.x-this.childrenWidth,this.center.y,this.childrenWidth,this.childrenHeight),new i(this.center.x,this.center.y,this.childrenWidth,this.childrenHeight)].map((function(i){return new t(e.level+1,i,e.maxLevels,e.maxColliders)}));for(var n=0,r=this.colliders;n<r.length;n++){var o=r[n];this.insertColliderIntoChildrenQuads(o)}this.colliders=[]},t.prototype.getChildrenQuadrantForCollider=function(t){if(0===this._quadrants.length)throw new m("Current quadrant does not have quadrant children.");if(this.quadrantsForCollider=[],t.bottomLeftQuadVertex.x<=this.center.x&&t.bottomLeftQuadVertex.y<=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.sw]),t.bottomRightQuadVertex.x>=this.center.x&&t.bottomRightQuadVertex.y<=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.se]),t.topLeftQuadVertex.x<=this.center.x&&t.topLeftQuadVertex.y>=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.nw]),t.topRightQuadVertex.x>=this.center.x&&t.topRightQuadVertex.y>=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.ne]),0===this.quadrantsForCollider.length)throw new m("Children does not fit in any children quadrant");return this.quadrantsForCollider},t.prototype.insertColliderIntoChildrenQuads=function(t){this.getChildrenQuadrantForCollider(t).forEach((function(e){return e.addCollider(t)}))},t.prototype.updateCache=function(){this.center.set(this._bounds.width/2+this._bounds.x,this._bounds.height/2+this._bounds.y),this.childrenWidth=this._bounds.width/2,this.childrenHeight=this._bounds.height/2},t}(),b=function(){function t(t,n,r,o,a,s){void 0===r&&(r=null),void 0===s&&(s=!1),this.minBounds=new e,this.maxBounds=new e,this.newBounds=new i(0,0,0,0),this.fixedQuadTree=null!==r,this.resolver=t,this.debug=s,this.renderManager=n,this.colliders=[],this.fixedQuadTree?this.bounds=r:this.bounds=new i(0,0,0,0),this.quadTree=new y(0,this.bounds,o,a)}return t.prototype.addCollider=function(t){this.colliders.push(t)},t.prototype.removeCollider=function(t){var e=this.colliders.indexOf(t);-1!==e&&(delete this.colliders[e],this.colliders.splice(e,1))},t.prototype.getCollisionsForCollider=function(t){return-1===this.colliders.indexOf(t)?[]:this.narrowPhase(t,this.broadPhase(t))},t.prototype.broadPhase=function(t){return this.quadTree.retrieve(t)},t.prototype.narrowPhase=function(t,e){var i=this,n=[];return e.filter((function(e){return e.gameObject!==t.gameObject})).forEach((function(e){var r=i.resolver.getCollisionData(t.shape,e.shape);null!==r&&n.push({localCollider:t,remoteCollider:e,collisionData:r})})),n},t.prototype.update=function(){if(0!==this.colliders.length){this.quadTree.clearColliders(),this.quadTree.clearQuadrants(),!1===this.fixedQuadTree&&(this.updateNewBounds(),!1===this.newBounds.equals(this.bounds)&&(this.bounds.updateFromRect(this.newBounds),this.quadTree.updateBounds(this.bounds)));for(var t=0,e=this.colliders;t<e.length;t++){var i=e[t];this.quadTree.addCollider(i)}this.debug&&this.debugQuads(this.quadTree)}},t.prototype.updateNewBounds=function(){var t=this;this.colliders.forEach((function(e){t.minBounds.set(Math.min(e.bottomLeftQuadVertex.x,t.minBounds.x),Math.min(e.bottomLeftQuadVertex.y,t.minBounds.y)),t.maxBounds.set(Math.max(e.topRightQuadVertex.x,t.maxBounds.x),Math.max(e.topRightQuadVertex.y,t.maxBounds.y))})),this.newBounds.set(this.minBounds.x,this.minBounds.y,this.maxBounds.x-this.minBounds.x,this.maxBounds.y-this.minBounds.y)},t.prototype.debugQuads=function(t){for(var i=0,n=t.quadrants;i<n.length;i++){var r=n[i];this.debugQuads(r)}if(!(t.quadrants.length>0)){var o=new g;o.debug=!0,o.position=new e(t.bounds.x+t.bounds.width/2,t.bounds.y+t.bounds.height/2),o.layer="QuadTree",o.geometric=t.bounds,o.geometricType="Rectangle",o.color="#0000FF",this.renderManager.addRenderData(o)}},t}(),x=function(){function t(t,e,i){if(this._canvas=null,!t)throw new m("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}(),v=function(){function t(){this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i){if(void 0===i&&(i=null),this.findGameObjectByName(e))throw new m("There is already a GameObject with the name "+e);var n=t();return n.name=e,n.parent=i,this.gameObjects.push(n),n},t.prototype.getGameObjects=function(){return this.gameObjects},t.prototype.findGameObjectById=function(t){return this.gameObjects.reduce((function(e,i){return i.id===t?i:e}),null)},t.prototype.findGameObjectByName=function(t){return this.gameObjects.reduce((function(e,i){return i.name===t?i:e}),null)},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParentAndName=function(t,e){return this.gameObjects.reduce((function(i,n){return n.name===e&&n.parent===t?n:i}),null)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.findGameObjectByTag=function(t){var e;return null!==(e=this.findGameObjectsByTag(t)[0])&&void 0!==e?e:null},t.prototype.destroyAllGameObjects=function(){var t=this;this.gameObjects.forEach((function(e){return t._destroyGameObject(e,!1)})),this.gameObjects=[]},t.prototype.destroyGameObject=function(t){this._destroyGameObject(t,!0)},t.prototype._destroyGameObject=function(t,e){var i=this.gameObjects.indexOf(t);-1!==i&&(e&&this.destroyChildren(t),t.destroy(),delete this.gameObjects[i])},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){e.destroyChildren(t),e.destroyGameObject(t)}))},t}(),_=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),window.addEventListener(xt,(function(){return t.update()}))}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 w),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=navigator.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}(),w=function(){function t(){this._connected=!1,this._id=null,this.buttons=new Map,this.axes=new Map}return t.prototype.updateFromGamepad=function(t){var e=this;this._id=t.id,this._connected=t.connected,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)}))},t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"connected",{get:function(){return this._connected},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this._id},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}),t}(),M=function(t,e,i,n){this.mouse=t,this.keyboard=e,this.gamepad=i,this.touch=n},O=function(){function t(t){var e=this;this.keyPresses=new Map,this.eventHandler=function(t){"keydown"===t.type&&e.keyPresses.set(t.code,!0),"keyup"===t.type&&e.keyPresses.set(t.code,!1)},this.canvas=t,this.canvas.addEventListener("keydown",this.eventHandler),this.canvas.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyPresses.get(t))&&void 0!==e&&e},t}(),C=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.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)})),window.addEventListener(xt,(function(){return t.update()}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},t}();!function(t){t[t.Rectangle=0]="Rectangle"}(d||(d={}));var R=function(){function t(){this._model=[],this._vertices=[],this._position=new e,this._direction=new e,this._height=0,this._width=0,this._angle=0}return Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertices",{get:function(){return this._vertices},enumerable:!1,configurable:!0}),t}(),j=function(){function t(t){this.canvas=null,this.canvasContext=null,this.imagePosition=new e(0,0),this.canvas=t,this.canvasContext=t.getContext("2d")}return t.prototype.clearCanvas=function(t){void 0===t&&(t=null),this.canvasContext.clearRect(0,0,this.canvas.width,this.canvas.height),null!==t&&(this.canvasContext.fillStyle=t,this.canvasContext.fillRect(0,0,this.canvas.width,this.canvas.height))},t.prototype.render=function(t,e){switch(e.type){case l.Image:this.renderImage(e,t.zoom);break;case l.Tilemap:this.renderTilemap(e,t.zoom);break;case l.Text:this.renderText(e);break;case l.Geometric:this.renderGeometric(e,t.zoom);break;case l.Collider:this.renderCollider(e,t.zoom)}},t.prototype.renderImage=function(t,e){this.updateRenderPosition(t),this.imagePosition.set(0,0),this.canvasContext.save(),this.applyZoom(t,e),0!==t.rotation?(this.canvasContext.translate(t.positionInViewport.x+t.width/2,t.positionInViewport.y+t.height/2),this.imagePosition.set(-t.width/2,-t.height/2),this.canvasContext.rotate(-t.rotation)):(this.canvasContext.translate(t.positionInViewport.x,t.positionInViewport.y),this.imagePosition.set(t.flipHorizontal?-t.width:this.imagePosition.x,t.flipVertical?-t.height:this.imagePosition.y)),this.canvasContext.globalAlpha=t.alpha,this.canvasContext.imageSmoothingEnabled=t.smooth,this.canvasContext.scale(t.flipHorizontal?-1:1,t.flipVertical?-1:1),void 0!==t.slice&&null!==t.slice?this.canvasContext.drawImage(t.image,t.slice.x,t.slice.y,t.slice.width,t.slice.height,this.imagePosition.x,this.imagePosition.y,t.width,t.height):this.canvasContext.drawImage(t.image,this.imagePosition.x,this.imagePosition.y,t.width,t.height),this.canvasContext.restore()},t.prototype.renderTilemap=function(t,e){var i=this;t.tilesToRender.forEach((function(n){i.canvasContext.save(),i.applyZoom(t,e),i.imagePosition.set(0,0),i.canvasContext.translate(i.canvas.width/2+n.positionInViewport.x-t.tileWidth/2,i.canvas.height/2-n.positionInViewport.y-t.tileHeight/2),i.imagePosition.set(n.flipHorizontal?-n.tile.width:i.imagePosition.x,n.flipVertical?-n.tile.height:i.imagePosition.y),i.canvasContext.globalAlpha=t.alpha,i.canvasContext.imageSmoothingEnabled=t.smooth,i.canvasContext.scale(n.flipHorizontal?-1:1,n.flipVertical?-1:1),i.canvasContext.drawImage(t.image,n.tile.x,n.tile.y,n.tile.width,n.tile.height,i.imagePosition.x,i.imagePosition.y,t.tileWidth,t.tileHeight),i.canvasContext.restore()}))},t.prototype.renderText=function(t){var e=this;this.updateRenderPosition(t),this.canvasContext.save(),this.canvasContext.font=t.fontSize+"px "+t.fontFamily,this.canvasContext.fillStyle=t.color,this.canvasContext.textBaseline="middle",t.text.split("\n").length>1?t.text.split("\n").forEach((function(i,n){e.canvasContext.fillText(i,t.positionInViewport.x,t.positionInViewport.y+(t.lineSeparation+t.fontSize)*n)})):this.canvasContext.fillText(t.text,t.positionInViewport.x,t.positionInViewport.y),this.canvasContext.restore()},t.prototype.renderGeometric=function(t,e){this.canvasContext.save(),this.applyZoom(t,e),this.updateRenderPosition(t),"Rectangle"===t.geometricType&&(this.canvasContext.strokeStyle=t.color,this.canvasContext.strokeRect(t.positionInViewport.x-t.getGeometric().width/2,t.positionInViewport.y-t.getGeometric().height/2,t.getGeometric().width,t.getGeometric().height)),this.canvasContext.restore()},t.prototype.renderCollider=function(t,e){if(this.canvasContext.save(),this.applyZoom(t,e),this.updateRenderPosition(t),this.canvasContext.beginPath(),this.canvasContext.strokeStyle=t.color,0!==t.shape.angle?(this.canvasContext.translate(t.positionInViewport.x,t.positionInViewport.y),this.canvasContext.rotate(-t.shape.angle),this.imagePosition.set(-t.shape.width/2,-t.shape.height/2)):(this.canvasContext.translate(t.positionInViewport.x-t.shape.width/2,t.positionInViewport.y-t.shape.height/2),this.imagePosition.set(0,0)),t.shape.type===d.Rectangle)this.canvasContext.strokeRect(this.imagePosition.x,this.imagePosition.y,t.shape.width,t.shape.height);this.canvasContext.restore()},t.prototype.applyZoom=function(t,e){t.ui||this.canvasContext.setTransform(e,0,0,e,this.canvas.width*(1-e)/2,this.canvas.height*(1-e)/2)},t.prototype.updateRenderPosition=function(t){t.type===l.Image&&this.centerImage(t),t.positionInViewport.set(Number((t.positionInViewport.x+this.canvas.width/2).toFixed(0)),Number((this.canvas.height/2-t.positionInViewport.y).toFixed(0)))},t.prototype.centerImage=function(t){t.positionInViewport.set(t.positionInViewport.x-Math.floor(t.width/2),t.positionInViewport.y+Math.floor(t.height/2))},t}(),P=function(){function t(t,e,i,n){void 0===n&&(n=!1),this.debug=!1,this.renderData=[],this.cameraData=[],this.renderer=t,this.cullingService=e,this.canvasColor=i,this.debug=n}return t.prototype.clearCanvas=function(){this.renderer.clearCanvas(this.canvasColor)},t.prototype.addRenderData=function(t){!1===this.debug&&t.debug||this.renderData.push(t)},t.prototype.addCameraData=function(t){this.cameraData.push(t)},t.prototype.render=function(){var t=this;this.cameraData.sort((function(t,e){return t.depth-e.depth})).forEach((function(e){return t.renderByCamera(e)})),this.clearData()},t.prototype.clearData=function(){this.renderData=[],this.cameraData=[]},t.prototype.renderByCamera=function(t){var e=this;this.orderRendeData(t),this.cullingService.applyCulling(t,this.renderData).forEach((function(i){e.updateFromCameraViewport(t,i),e.renderer.render(t,i)}))},t.prototype.orderRendeData=function(t){this.renderData.sort((function(e,i){return t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer)}))},t.prototype.updateFromCameraViewport=function(t,e){var i=this;!0!==e.ui?e.type===l.Tilemap?e.tilesToRender.forEach((function(e){return i.setPositionInViewport(t,e)})):this.setPositionInViewport(t,e):e.positionInViewport=e.position},t.prototype.setPositionInViewport=function(t,e){e.positionInViewport.set(Math.round(e.position.x-t.worldSpaceRect.x-t.worldSpaceRect.width/2),Math.round(e.position.y-t.worldSpaceRect.y-t.worldSpaceRect.height/2))},t}(),T="undefined"!=typeof Float32Array?Float32Array:Array;function S(){var t=new T(16);return T!=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 D(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 E(t,e,i){var n,r,o,a,s,h,c,l,u,p,d,f,g=i[0],m=i[1],y=i[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*y+e[12],t[13]=e[1]*g+e[5]*m+e[9]*y+e[13],t[14]=e[2]*g+e[6]*m+e[10]*y+e[14],t[15]=e[3]*g+e[7]*m+e[11]*y+e[15]):(n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],h=e[5],c=e[6],l=e[7],u=e[8],p=e[9],d=e[10],f=e[11],t[0]=n,t[1]=r,t[2]=o,t[3]=a,t[4]=s,t[5]=h,t[6]=c,t[7]=l,t[8]=u,t[9]=p,t[10]=d,t[11]=f,t[12]=n*g+s*m+u*y+e[12],t[13]=r*g+h*m+p*y+e[13],t[14]=o*g+c*m+d*y+e[14],t[15]=a*g+l*m+f*y+e[15]),t}function A(t,e,i){var n=i[0],r=i[1],o=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]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function B(t,e,i){var n=Math.sin(i),r=Math.cos(i),o=e[0],a=e[1],s=e[2],h=e[3],c=e[4],l=e[5],u=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*r+c*n,t[1]=a*r+l*n,t[2]=s*r+u*n,t[3]=h*r+p*n,t[4]=c*r-o*n,t[5]=l*r-a*n,t[6]=u*r-s*n,t[7]=p*r-h*n,t}function V(t,e,i,n,r,o,a){var s=1/(e-i),h=1/(n-r),c=1/(o-a);return t[0]=-2*s,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*c,t[11]=0,t[12]=(e+i)*s,t[13]=(r+n)*h,t[14]=(a+o)*c,t[15]=1,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var F,G=function(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16)/256,g:parseInt(e[2],16)/256,b:parseInt(e[3],16)/256}:null},I=function(){function t(t,e,i){this.lastTexture=null,this.maskColor=null,this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=S(),this.modelMatrix=S(),this.textureMatrix=S(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i,n){"image"!==n&&(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=D(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[i.positionInViewport.x,i.positionInViewport.y,0]),B(this.modelMatrix,this.modelMatrix,i.rotation),A(this.modelMatrix,this.modelMatrix,[i.width*(i.flipHorizontal?-1:1),i.height*(i.flipVertical?-1:1),1]),this.textureMatrix=D(this.textureMatrix),null!==i.slice&&(E(this.textureMatrix,this.textureMatrix,[i.slice.x/i.image.naturalWidth,i.slice.y/i.image.naturalHeight,0]),A(this.textureMatrix,this.textureMatrix,[i.slice.width/i.image.naturalWidth,i.slice.height/i.image.naturalHeight,1])),this.projectionMatrix=D(this.projectionMatrix),V(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),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),i.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.lastTexture===e&&"image"===n||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,i.alpha),this.maskColor=null!==i.maskColor?G(i.maskColor):{r:1,g:1,b:1},this.gl.uniform4f(this.programManager.colorUniform,this.maskColor.r,this.maskColor.g,this.maskColor.b,1),this.gl.uniform1f(this.programManager.colorMixUniform,i.maskColorMix),this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),L=function(){function t(t){this.shaderLoader=t}return t.prototype.create=function(t,e,i){var n=t.createProgram(),r=this.shaderLoader.load(t,t.VERTEX_SHADER,e),o=this.shaderLoader.load(t,t.FRAGMENT_SHADER,i);return this.link(t,n,r,o),n},t.prototype.link=function(t,e,i,n){t.attachShader(e,i),t.attachShader(e,n),t.linkProgram(e);var r=t.LINK_STATUS;if(!t.getProgramParameter(e,r)){var o=t.getProgramInfoLog(e);throw t.deleteProgram(e),new m("Unable to initialize the Program: "+o)}},t}(),H=function(){function t(){}return t.prototype.load=function(t,e,i){var n=t.createShader(e);t.shaderSource(n,i),t.compileShader(n);var r=t.COMPILE_STATUS;if(!t.getShaderParameter(n,r)){var o=t.getShaderInfoLog(n);throw t.deleteShader(n),new m("Unable to initialize the shader program: "+o)}return n},t}(),U=function(){function t(t,e){this.gl=e.getContext(t)}return t.prototype.createFromImage=function(t,e,i){var n=this;return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(function(){return n.create(t,i,e)})),i},t.prototype.createFromCanvas=function(t,e,i){return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i},t.prototype.create=function(t,e,i){void 0===i&&(i=!0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)},t}();!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(F||(F={}));var z,N,W=function(){function t(t,e,i,n,r,o,a,s,h){this.fontAtlas=new Map,this.canvas=e,this.gl=this.canvas.getContext(t),i.loadProgram(),this.textureManager=n,this.imageRenderer=o,this.tilemapRenderer=a,this.textRenderer=s,this.geometricRenderer=h,this.fontAtlasFactory=r}return t.prototype.clearCanvas=function(t){var e=G(t);this.gl.clearColor(e.r,e.g,e.b,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.render=function(t,e){e.type===l.Image&&(this.renderImage(t,e),this.lastRender="image"),e.type===l.Tilemap&&(this.renderTilemap(t,e),this.lastRender="tilemap"),e.type===l.Text&&(this.renderText(t,e),this.lastRender="text"),e.type===l.Collider&&(this.geometricRenderer.renderCollider(t.viewportRect,e,this.lastRender),this.lastRender="geometric"),e.type===l.Geometric&&(this.geometricRenderer.renderGeometric(t.viewportRect,e,this.lastRender),this.lastRender="geometric")},t.prototype.renderImage=function(t,e){this.imageRenderer.render(!0===e.ui?t.originalViewportRect:t.viewportRect,this.textureManager.getOrCreateTextureFromImage(e.image,e.smooth),e,this.lastRender)},t.prototype.renderTilemap=function(t,e){this.tilemapRenderer.render(!0===e.ui?t.originalViewportRect:t.viewportRect,this.textureManager.getOrCreateTextureFromImage(e.image,e.smooth),e,this.lastRender)},t.prototype.renderText=function(t,e){var i=this,n=Symbol.for(e.fontFamily);!1===this.fontAtlas.has(n)?this.fontAtlasFactory.create(e.charRanges,e.fontFamily,e.fontUrl,e.bitmapSize).then((function(r){i.fontAtlas.set(n,r),i.fontAtlasLoaded(r,t,e)})):this.fontAtlasLoaded(this.fontAtlas.get(n),t,e)},t.prototype.fontAtlasLoaded=function(t,e,i){this.textRenderer.render(!0===i.ui?e.originalViewportRect:e.viewportRect,this.textureManager.getOrCreateTextureFromCanvas(i.fontFamily,t.canvas,i.smooth),t,i,this.lastRender)},t}(),q=function(){function t(t,e){this.game=null,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.game=t,this.renderManager=e}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i){if(void 0===i&&(i=!1),this.scenes.has(t))throw new m("There is already a scene with the name '"+t+"'");this.scenes.set(t,e),!0!==i&&null!==this.openingSceneName||(this.openingSceneName=t)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new m("There is no opening scene");this.loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(null===this.game)throw new m("Game not initialized.");if(!1===this.scenes.has(t))throw new m("Scene with name "+t+" does not exists");this.unloadCurrentScene(),this.currentScene=this.scenes.get(t)(),this.currentScene.name=t,this.currentScene.game=this.game},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.destroy(),this.currentScene=null,this.currentSceneName=null,this.renderManager.clearData())},t}(),k=function(){function t(t,e){if(this.maxGameDeltatime=0,this.maxPhysicsDeltaTime=0,this.timeScale=1,this.browserDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.max=1/15,this.then=0,t<15)throw new m("Game framerate cannot be less than 15");if(e<60)throw new m("Physics framerate cannot be less than 60");if(e<t)throw new m("Physics framerate cannot be less than game framerate");this.maxGameDeltatime=parseFloat((1/t).toFixed(6)),this.maxPhysicsDeltaTime=parseFloat((1/e).toFixed(6))}return t.prototype.update=function(t){var e=.001*t;this.browserDeltaTime=Math.min(Math.max(0,e-this.then),this.max),this.then=e},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}(),Y=function(){function t(t){this.textures=new Map,this.textureFactory=t}return t.prototype.getTexture=function(t){var e;return null!==(e=this.textures.get(Symbol.for(t)))&&void 0!==e?e:null},t.prototype.getOrCreateTextureFromImage=function(t,e){var i;return void 0===e&&(e=!0),null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)},t.prototype.createTextureFromImage=function(t,e){void 0===e&&(e=!0);var i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i},t.prototype.getOrCreateTextureFromCanvas=function(t,e,i){var n;return void 0===i&&(i=!0),null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)},t.prototype.createTextureFromCanvas=function(t,e,i){void 0===i&&(i=!0);var n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n},t}(),Q=function(){function t(t,e,i){this.gl=i.getContext(e),this.programFactory=t,this.contextVersion=e}return t.prototype.loadProgram=function(){this.program=this.contextVersion===F.WebGL2?this.programFactory.create(this.gl,"#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 float u_alpha;\nuniform vec4 u_color;\nuniform float u_colorMix;\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 fragColor = mix(vec4(texColor.rgb, u_alpha), vec4(u_color.rgb, u_alpha), clamp(u_colorMix, 0.0, 1.0));\n } else {\n fragColor = u_color;\n }\n}"):this.programFactory.create(this.gl,"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 float u_alpha;\nuniform vec4 u_color;\nuniform float u_colorMix;\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 gl_FragColor = mix(vec4(texColor.rgb, u_alpha), vec4(u_color.rgb, u_alpha), clamp(u_colorMix, 0.0, 1.0));\n \n } else {\n gl_FragColor = u_color;\n }\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.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.colorUniform=this.gl.getUniformLocation(this.program,"u_color"),this.colorMixUniform=this.gl.getUniformLocation(this.program,"u_colorMix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)},t}(),X=function(){function t(){this.bitmapSize=64}return t.prototype.create=function(t,e,i,n){return void 0===i&&(i=null),void 0===n&&(n=null),s(this,void 0,void 0,(function(){var r,o,a;return h(this,(function(s){switch(s.label){case 0:for(this.bitmapSize=null!=n?n:this.bitmapSize,r=new Z(e),this.chars=[],o=0;o<t.length;o+=2)for(a=t[o];a<=t[o+1];a++)this.chars.push(String.fromCharCode(a));return r.canvas.width=Math.round(Math.sqrt(this.chars.length))*this.bitmapSize,r.canvas.height=r.canvas.width,null===i?[3,2]:[4,this.loadFont(r,e,i)];case 1:return s.sent(),[3,3];case 2:this.renderAtlas(r,e),s.label=3;case 3:return[2,r]}}))}))},t.prototype.loadFont=function(t,e,i){return s(this,void 0,void 0,(function(){var n,r;return h(this,(function(o){switch(o.label){case 0:return[4,(n=new FontFace(e,"url("+i+")")).load()];case 1:return r=o.sent(),document.fonts.add(n),this.renderAtlas(t,r.family),[2]}}))}))},t.prototype.renderAtlas=function(t,e){var i=t.canvas.getContext("2d");i.clearRect(0,0,t.canvas.width,t.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font=this.bitmapSize+"px "+e;for(var n=0,r=0,o=0;o<this.chars.length;o++)i.fillText(this.chars[o],n,r),t.glyphsData.set(this.chars[o],{x:n,y:r,width:this.bitmapSize,height:this.bitmapSize}),(n+=this.bitmapSize)>t.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize)},t}(),Z=function(t){this.canvas=document.createElement("canvas"),this.glyphsData=new Map,this.name=t},K=function(){function t(t,i,n){this.posVertices=[],this.texVertices=[],this.posVerticesSize=new e,this.lastTexture=null,this.maskColor=null,this.gl=i.getContext(t),this.programManager=n,this.projectionMatrix=S(),this.modelMatrix=S(),this.textureMatrix=S()}return t.prototype.render=function(t,e,i,n,r){this.generateTextVertices(i,n),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=D(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[n.positionInViewport.x-this.posVerticesSize.x/2,n.positionInViewport.y+this.posVerticesSize.y/2,0]),this.textureMatrix=D(this.textureMatrix),A(this.textureMatrix,this.textureMatrix,[1/i.canvas.width,1/i.canvas.height,1]),this.projectionMatrix=D(this.projectionMatrix),V(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),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.disable(this.gl.BLEND),this.lastTexture===e&&"text"===r||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,1),this.maskColor=G(n.color),this.gl.uniform4f(this.programManager.colorUniform,this.maskColor.r,this.maskColor.g,this.maskColor.b,1),this.gl.uniform1f(this.programManager.colorMixUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.generateTextVertices=function(t,e){this.posVertices=[],this.texVertices=[];for(var i={x1:0,y1:-e.fontSize,x2:0,y2:0},n={x1:0,y1:0,x2:0,y2:0},r=0,o=1,a=0;a<e.text.length;a++){var s=e.text[a];if("\n"!==s)if(" "!==s){var h=t.glyphsData.get(s);h&&(i.x2=i.x1+e.fontSize,r=Math.max(i.x2,r),n.x1=h.x+e.bitmapOffset.x,n.y1=h.y+e.bitmapOffset.y,n.x2=h.x+h.width-1,n.y2=h.y+h.height-1,this.posVertices.push(i.x1,i.y1,i.x2,i.y1,i.x1,i.y2,i.x1,i.y2,i.x2,i.y1,i.x2,i.y2),this.texVertices.push(n.x1,n.y2,n.x2,n.y2,n.x1,n.y1,n.x1,n.y1,n.x2,n.y2,n.x2,n.y1)),i.x1+=e.fontSize+e.letterSpacing}else i.x1+=e.fontSize+e.letterSpacing;else i.y1-=e.fontSize+e.lineSeparation,i.y2=i.y1+e.fontSize,i.x1=0,o++}this.posVerticesSize.set(r,o*e.fontSize+(o-1)*e.lineSeparation)},t}(),$=function(){function t(t,e,i){this.vertices=new Map,this.texVertices=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),this.lastVertices=null,this.lastRender=null,this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=S(),this.modelMatrix=S(),this.textureMatrix=S()}return t.prototype.renderCollider=function(t,e,i){this.lastRender=i,e.shape.type===d.Rectangle&&this.renderRectangle(t,e.positionInViewport,{width:e.shape.width,height:e.shape.height},e.color,e.shape.angle)},t.prototype.renderGeometric=function(t,e,i){this.lastRender=i,"Rectangle"===e.geometricType&&this.renderRectangle(t,e.positionInViewport,{width:e.getGeometric().width,height:e.getGeometric().height},e.color)},t.prototype.renderRectangle=function(t,e,i,n,r){void 0===r&&(r=0);var o=Symbol.for("RW"+i.width+"H"+i.height);!1===this.vertices.has(o)&&this.vertices.set(o,new Float32Array(this.generateRectangleVertices(i.width,i.height,1)));var a=this.vertices.get(o);this.lastVertices===o&&"geometric"===this.lastRender||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,a,this.gl.DYNAMIC_DRAW)),this.lastVertices=o,"geometric"!==this.lastRender&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.DYNAMIC_DRAW)),this.modelMatrix=D(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[e.x,e.y,0]),B(this.modelMatrix,this.modelMatrix,r),this.projectionMatrix=D(this.projectionMatrix),V(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),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),this.rgbColor=G(n),this.gl.uniform4f(this.programManager.colorUniform,this.rgbColor.r,this.rgbColor.g,this.rgbColor.b,1),this.gl.drawArrays(this.gl.TRIANGLES,0,a.length/2)},t.prototype.generateRectangleVertices=function(t,e,i){var n=e/2,r=t/2;return c(c(c(c([],this.generateLineVertices(-r,-n,r,-n+i),!0),this.generateLineVertices(r-i,-n,r,n),!0),this.generateLineVertices(-r,n-i,r,n),!0),this.generateLineVertices(-r,-n,-r+i,n),!0)},t.prototype.generateLineVertices=function(t,e,i,n){return[t,e,i,e,t,n,t,n,i,e,i,n]},t}(),J=function(){function t(t,i){this._displacementDirection=new e,this._penetration=t,this._displacementDirection.set(i.x,i.y)}return Object.defineProperty(t.prototype,"penetration",{get:function(){return this._penetration},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"displacementDirection",{get:function(){return this._displacementDirection},enumerable:!1,configurable:!0}),t}(),tt=function(){function t(){this.proj1={min:0,max:0},this.proj2={min:0,max:0}}return t.prototype.getCollisionData=function(t,i){this.currentOverlap=null,this.minOverlap=null,this.displaceDirection=null,this.axes=c(c([],t.getAxes(),!0),i.getAxes(),!0);for(var n=0;n<this.axes.length;n++){if(this.projectShapeOntoAxis(this.proj1,this.axes[n],t),this.projectShapeOntoAxis(this.proj2,this.axes[n],i),this.currentOverlap=Math.min(this.proj1.max,this.proj2.max)-Math.max(this.proj1.min,this.proj2.min),this.currentOverlap<0)return null;this.preventContainment(n),(this.currentOverlap<this.minOverlap||null===this.minOverlap)&&(this.minOverlap=this.currentOverlap,this.displaceDirection=this.axes[n],this.proj1.max<this.proj2.max&&e.scale(this.displaceDirection,this.displaceDirection,-1))}return new J(this.minOverlap,this.displaceDirection)},t.prototype.projectShapeOntoAxis=function(t,i,n){return t.min=e.dot(i,n.vertices[0]),t.max=t.min,n.vertices.forEach((function(n){t.min=Math.min(e.dot(i,n),t.min),t.max=Math.max(e.dot(i,n),t.max)})),t},t.prototype.preventContainment=function(t){if(this.proj1.max>this.proj2.max&&this.proj1.min<this.proj2.min||this.proj1.max<this.proj2.max&&this.proj1.min>this.proj2.min){var i=Math.abs(this.proj1.min-this.proj2.min),n=Math.abs(this.proj1.max-this.proj2.max);i<n?this.currentOverlap+=i:(this.currentOverlap+=n,e.scale(this.axes[t],this.axes[t],-1))}},t}(),et=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}(),it=function(){function t(){this.shape1Rect=new i(0,0,0,0),this.shape2Rect=new i(0,0,0,0),this.displaceDirection=new e}return t.prototype.getCollisionData=function(t,e){return this.setShapeRect(t,this.shape1Rect),this.setShapeRect(e,this.shape2Rect),this.overlapX=Math.min(this.shape1Rect.x1,this.shape2Rect.x1)-Math.max(this.shape1Rect.x,this.shape2Rect.x),this.overlapY=Math.min(this.shape1Rect.y1,this.shape2Rect.y1)-Math.max(this.shape1Rect.y,this.shape2Rect.y),this.overlapX<0||this.overlapY<0?null:(this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displaceDirection.set(0,Math.sign(this.shape1Rect.y1-this.shape2Rect.y1)),this.preventContainment(this.shape1Rect.y,this.shape2Rect.y,this.shape1Rect.y1,this.shape2Rect.y1)):(this.minOverlap=this.overlapX,this.displaceDirection.set(Math.sign(this.shape1Rect.x1-this.shape2Rect.x1),this.overlapY===this.overlapX?Math.sign(this.shape1Rect.y1-this.shape2Rect.y1):0),this.preventContainment(this.shape1Rect.x,this.shape2Rect.x,this.shape1Rect.x1,this.shape2Rect.x1)),new J(this.minOverlap,this.displaceDirection))},t.prototype.setShapeRect=function(t,e){e.set(t.position.x-t.width/2,t.position.y-t.height/2,t.width,t.height)},t.prototype.preventContainment=function(t,i,n,r){if(t>n&&i<r||n>t&&r<i){var o=Math.abs(t-n),a=Math.abs(i-r);o<a?this.minOverlap+=o:(this.minOverlap+=a,e.scale(this.displaceDirection,this.displaceDirection,-1))}},t}(),nt=function(){function t(){}return t.prototype.applyCulling=function(t,e){var i=this;return e.filter((function(e){if(!1===t.layers.includes(e.layer))return!1;var n=e.ui?t.viewportRect:t.worldSpaceRect;switch(e.type){case l.Image:return i.cullSprite(n,e);case l.Tilemap:return i.cullTilemap(n,e);case l.Collider:return i.cullCollider(n,e);case l.Geometric:return i.cullGeometric(n,e);case l.Text:return i.cullText(n,e)}}))},t.prototype.cullSprite=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.width/2,x1:e.position.x+e.width/2,y:e.position.y-e.height/2,y1:e.position.y+e.height/2})},t.prototype.cullTilemap=function(t,e){var i=this;return e.tilesToRender=e.tilesData.filter((function(n){return i.isTargetVisible(t,{x:n.position.x-e.tileWidth/2,x1:n.position.x+e.tileWidth/2,y:n.position.y-e.tileHeight/2,y1:n.position.y+e.tileHeight/2})})),e.tilesData.length>0},t.prototype.cullCollider=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.shape.width/2,x1:e.position.x+e.shape.width/2,y:e.position.y-e.shape.height/2,y1:e.position.y+e.shape.height/2})},t.prototype.cullGeometric=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.geometric.width/2,x1:e.position.x+e.geometric.width/2,y:e.position.y-e.geometric.height/2,y1:e.position.y+e.geometric.height/2})},t.prototype.cullText=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.width/2,x1:e.position.x+e.width/2,y:e.position.y-e.height/2,y1:e.position.y+e.height/2})},t.prototype.isTargetVisible=function(t,e){return t.x1>=e.x&&t.x<=e.x1&&t.y1>=e.y&&t.y<=e.y1},t}(),rt=function(){function t(t,e,i){this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.maskColor=null,this.p={x1:0,y1:0,x2:0,y2:0},this.t={x1:0,y1:0,x2:0,y2:0},this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=S(),this.modelMatrix=S(),this.textureMatrix=S()}return t.prototype.render=function(t,e,i,n){this.generateVertices(i),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=D(this.modelMatrix),this.textureMatrix=D(this.textureMatrix),A(this.textureMatrix,this.textureMatrix,[1/i.image.naturalWidth,1/i.image.naturalHeight,1]),this.projectionMatrix=D(this.projectionMatrix),V(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),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),i.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.lastTexture===e&&"tilemap"===n||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,i.alpha),this.maskColor={r:1,g:1,b:1},this.gl.uniform4f(this.programManager.colorUniform,this.maskColor.r,this.maskColor.g,this.maskColor.b,1),this.gl.uniform1f(this.programManager.colorMixUniform,0),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.generateVertices=function(t){var e=this;this.posVertices=[],this.texVertices=[],t.tilesToRender.forEach((function(i){var n,r;e.p.x1=i.positionInViewport.x-t.tileWidth/2,e.p.x2=i.positionInViewport.x+t.tileWidth/2,e.p.y1=i.positionInViewport.y-t.tileHeight/2,e.p.y2=i.positionInViewport.y+t.tileHeight/2,e.posVertices.push(e.p.x1,e.p.y1,e.p.x2,e.p.y1,e.p.x1,e.p.y2,e.p.x1,e.p.y2,e.p.x2,e.p.y1,e.p.x2,e.p.y2),e.t.x1=i.tile.x,e.t.y1=i.tile.y,e.t.x2=i.tile.x+i.tile.width-(null!==(n=t.textureCorrection)&&void 0!==n?n:0),e.t.y2=i.tile.y+i.tile.height-(null!==(r=t.textureCorrection)&&void 0!==r?r:0),e.texVertices.push(e.t.x1,e.t.y2,e.t.x2,e.t.y2,e.t.x1,e.t.y1,e.t.x1,e.t.y1,e.t.x2,e.t.y2,e.t.x2,e.t.y1)}))},t}(),ot=function(){function t(t,e,i){this.gameLoopAccumulator=0,this.physicsLoopAccumulator=0,this.deltaAux=0,this.timeManager=t,this.collisionManager=e,this.renderManager=i}return t.prototype.update=function(t){for(this.timeManager.update(t),this.deltaAux=Math.min(this.timeManager.browserDeltaTime,this.timeManager.maxGameDeltatime),this.gameLoopAccumulator+=this.deltaAux,this.physicsLoopAccumulator+=this.timeManager.browserDeltaTime,this.timeManager.unscaledGameDeltaTime=Math.max(this.timeManager.maxGameDeltatime,this.timeManager.browserDeltaTime),this.timeManager.unscaledPhysicsDeltaTime=this.timeManager.maxPhysicsDeltaTime,this.gameLoopAccumulator>this.timeManager.maxGameDeltatime&&(this.mainIteration(),this.gameLoopAccumulator-=this.timeManager.maxGameDeltatime);this.physicsLoopAccumulator>this.timeManager.maxPhysicsDeltaTime;)this.timeManager.timeScale>0&&this.physicsIteration(),this.physicsLoopAccumulator-=this.timeManager.maxPhysicsDeltaTime;this.preRenderIteration(),this.renderIteration()},t.prototype.mainIteration=function(){this.dispatchFrameEvent(bt),this.dispatchFrameEvent(xt),this.dispatchFrameEvent(vt),this.dispatchFrameEvent(Mt),this.dispatchFrameEvent(_t),this.collisionManager.update()},t.prototype.physicsIteration=function(){this.dispatchFrameEvent(wt),this.dispatchFrameEvent(_t)},t.prototype.preRenderIteration=function(){this.dispatchFrameEvent(Mt),this.dispatchFrameEvent(Ot),this.dispatchFrameEvent(Ct)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(Rt),this.renderManager.clearCanvas(),this.renderManager.render()},t.prototype.dispatchFrameEvent=function(t){window.dispatchEvent(new CustomEvent(t))},t}(),at=function(e,i){if(i.config.collisions.method===t.CollisionMethodConfig.AABB)e.add("CollisionResolver",(function(){return new it}));else{if(i.config.collisions.method!==t.CollisionMethodConfig.SAT)throw new m("Invalid collision method.");e.add("CollisionResolver",(function(){return new tt}))}e.add("CollisionManager",(function(){return new b(e.getSingleton("CollisionResolver"),e.getSingleton("RenderManager"),i.config.collisions.quadTreeBounds,i.config.collisions.quadMaxLevel,i.config.collisions.collidersPerQuad,i.config.debugEnabled&&i.config.collisions.debugQuadTree)}))},st=function(e,i,n){var r=lt();if(i.config.context2d===t.Context2DConfig.Default||i.config.context2d===t.Context2DConfig.Fallback&&null===r)e.add("Renderer",(function(){return new j(n.canvas)})),i.config.debugEnabled&&console.log("Using 2d rendering context");else{if(null===r)throw new m("WebGL is not supported, use context2d instead.");ht(r,e,n),i.config.debugEnabled&&console.log("Using WebGL rendering context (version: "+r+")")}e.add("FontAtlasFactory",(function(){return new X})),e.add("CullingService",(function(){return new nt})),e.add("RenderManager",(function(){return new P(e.getSingleton("Renderer"),e.getSingleton("CullingService"),i.config.canvasColor,i.config.debugEnabled)}))},ht=function(t,e,i){e.add("ShaderLoader",(function(){return new H})),e.add("ProgramFactory",(function(){return new L(e.getSingleton("ShaderLoader"))})),e.add("ProgramManager",(function(){return new Q(e.getSingleton("ProgramFactory"),t,i.canvas)})),e.add("TextureFactory",(function(){return new U(t,i.canvas)})),e.add("TextureManager",(function(){return new Y(e.getSingleton("TextureFactory"))})),e.add("WebGLImageRenderer",(function(){return new I(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLTextRenderer",(function(){return new K(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLGeometricRenderer",(function(){return new $(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLTilemapRenderer",(function(){return new rt(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("Renderer",(function(){return new W(t,i.canvas,e.getSingleton("ProgramManager"),e.getSingleton("TextureManager"),e.getSingleton("FontAtlasFactory"),e.getSingleton("WebGLImageRenderer"),e.getSingleton("WebGLTilemapRenderer"),e.getSingleton("WebGLTextRenderer"),e.getSingleton("WebGLGeometricRenderer"))}))},ct=function(t,e){t.add("Mouse",(function(){return new C(e.canvas)})),t.add("Keyboard",(function(){return new O(e.canvas)})),t.add("Gamepad",(function(){return new _})),t.add("Touch",(function(){return new et(e.canvas)})),t.add("InputManager",(function(){return new M(t.getSingleton("Mouse"),t.getSingleton("Keyboard"),t.getSingleton("Gamepad"),t.getSingleton("Touch"))}))},lt=function(){return null!==document.createElement("canvas").getContext(F.WebGL2)?F.WebGL2:null!==document.createElement("canvas").getContext(F.LegacyWebGL)?F.LegacyWebGL:null},ut=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 m("There is already an object constructor with the name "+t);this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new m("Invalid object constructor name: "+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 m("Invalid object constructor name: "+t);return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new m("There is already a constant value with the name "+t);this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new m("Invalid constant name: "+t);return this.constants.get(t)},t}(),pt=function(){function t(){}return t.initialize=function(){this.assetManager=jt.getSingleton("AssetManager")},t.getAssetsLoaded=function(){return this.assetManager.getAssetsLoaded()},t.createImage=function(t){return this.assetManager.createImage(t)},t.createAudio=function(t){return this.assetManager.createAudio(t)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.assetManager=null,t}(),dt=function(){function t(){}return t.initialize=function(){this.domManager=jt.getSingleton("DomManager")},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}(),ft=function(){function t(){}return t.initialize=function(){this.inputManager=jt.getSingleton("InputManager")},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}(),gt=function(){function t(){}return t.initialize=function(){this.sceneManager=jt.getSingleton("SceneManager")},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}(),mt=function(){function t(){}return t.initialize=function(){this.timeManager=jt.getSingleton("TimeManager")},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}),t.timeManager=null,t}(),yt=function(){function t(){}return t.initialize=function(){this.manager=jt.getSingleton("GameObjectManager")},t.addGameObject=function(t,e,i){return void 0===i&&(i=null),this.manager.addGameObject(t,e,i)},t.getGameObjects=function(){return this.manager.getGameObjects()},t.findGameObjectByName=function(t){return this.manager.findGameObjectByName(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParentAndName=function(t,e){return this.manager.findGameObjectByParentAndName(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.findGameObjectByTag=function(t){return this.manager.findGameObjectByTag(t)},t.destroyAllGameObjects=function(){this.manager.destroyAllGameObjects()},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t}(),bt="angry-pixel-start",xt="angry-pixel-update",vt="angry-pixel-update-engine",_t="angry-pixel-update-collider",wt="angry-pixel-update-physics",Mt="angry-pixel-update-transform",Ot="angry-pixel-update-prerender",Ct="angry-pixel-update-camera",Rt="angry-pixel-update-render",jt=new ut;t.Context2DConfig=void 0,(z=t.Context2DConfig||(t.Context2DConfig={})).Default="default",z.Disabled="disabled",z.Fallback="fallback",t.CollisionMethodConfig=void 0,(N=t.CollisionMethodConfig||(t.CollisionMethodConfig={})).AABB="aabb",N.SAT="sat";var Pt,Tt={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",context2d:t.Context2DConfig.Fallback,spriteDefaultScale:null,gameFrameRate:60,physicsFramerate:240,collisions:{method:t.CollisionMethodConfig.AABB,quadTreeBounds:null,debugQuadTree:!1,quadMaxLevel:6,collidersPerQuad:15}},St=function(){function t(t){var e=this;this._running=!1,this._stop=!1,this.frameRequestId=null,this.errorEventHandler=function(t){-1!==t.error.message.indexOf(m.messagePrefix)&&(e.stop(),t.stopPropagation(),t.preventDefault(),console.error(t.error.message+"\n"+t.filename+":"+t.lineno))},this._config=a(a({},Tt),t),this._config.collisions=a(a({},Tt.collisions),t.collisions),window.addEventListener("error",this.errorEventHandler),this.setupManagers(),this.initializeFacades()}return t.prototype.setupManagers=function(){!function(t,e){t.addConstant("GameConfig",e.config),t.add("DomManager",(function(){return new x(e.config.containerNode,e.config.gameWidth,e.config.gameHeight)}));var i=t.getSingleton("DomManager");st(t,e,i),ct(t,i),at(t,e),t.add("SceneManager",(function(){return new q(e,t.getSingleton("RenderManager"))})),t.add("GameObjectManager",(function(){return new v})),t.add("AssetManager",(function(){return new p})),t.add("TimeManager",(function(){return new k(e.config.gameFrameRate,e.config.physicsFramerate)})),t.add("IterationManager",(function(){return new ot(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RenderManager"))}))}(jt,this),this.renderManager=jt.getSingleton("RenderManager"),this.sceneManager=jt.getSingleton("SceneManager"),this.iterationManager=jt.getSingleton("IterationManager")},t.prototype.initializeFacades=function(){pt.initialize(),dt.initialize(),ft.initialize(),gt.initialize(),mt.initialize(),yt.initialize()},Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"running",{get:function(){return this._running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i){void 0===i&&(i=!1),this.sceneManager.addScene(t,e,i)},t.prototype.run=function(){this.sceneManager.loadOpeningScene(),this.requestAnimationFrame()},t.prototype.stop=function(){this.pauseLoop(),this.sceneManager.unloadCurrentScene(),this.renderManager.clearCanvas()},t.prototype.gameLoop=function(t){!0!==this._stop&&(this._running=!0,this.iterationManager.update(t),this.requestAnimationFrame())},t.prototype.pauseLoop=function(){this._stop=!0,this._running=!1,null!==this.frameRequestId&&(window.cancelAnimationFrame(this.frameRequestId),this.frameRequestId=null)},t.prototype.resumeLoop=function(){0==this._running&&null===this.frameRequestId&&(this._stop=!1,this.requestAnimationFrame())},t.prototype.requestAnimationFrame=function(){var t=this;this.frameRequestId=window.requestAnimationFrame((function(e){return t.gameLoop(e)}))},t}(),Dt=function(){var t=(new Date).getTime(),e=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)}))},Et=function(){function t(){var t=this;this.sceneManager=jt.getSingleton("SceneManager"),this.gameObjectManager=jt.getSingleton("GameObjectManager"),this.id=Dt(),this.allowMultiple=!0,this.type=null,this.name=null,this.gameObject=null,this._active=!0,this.started=!1,this.gameLoopEventHandler=function(e){if(!1!==t._active)try{!1===t.started&&e.type===bt?(t.start(),t.started=!0):!0===t.started&&e.type===t.updateEvent&&t.update()}catch(t){throw-1!==t.message.indexOf(m.messagePrefix)?t:new m(t.message)}},window.addEventListener(bt,this.gameLoopEventHandler),window.addEventListener(this.updateEvent,this.gameLoopEventHandler)}return Object.defineProperty(t.prototype,"updateEvent",{get:function(){return xt},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"active",{get:function(){return this._active},enumerable:!1,configurable:!0}),t.prototype.setActive=function(t){this._active=t},t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.getComponentByName=function(t){return this.gameObject.getComponentByName(t)},t.prototype.getComponentByType=function(t){return this.gameObject.getComponentByType(t)},t.prototype.getComponentsByType=function(t){return this.gameObject.getComponentsByType(t)},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.hasComponentOfName=function(t){return null!==this.getComponentByName(t)},t.prototype.hasComponentOfType=function(t){return null!==this.getComponentByType(t)},t.prototype.removeComponentByName=function(t){this.gameObject.removeComponentByName(t)},t.prototype.removeComponentByType=function(t){this.gameObject.removeComponentByType(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(bt,this.gameLoopEventHandler),window.removeEventListener(this.updateEvent,this.gameLoopEventHandler),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),At=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return vt},enumerable:!1,configurable:!0}),e}(Et),Bt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return _t},enumerable:!1,configurable:!0}),e}(Et),Vt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return wt},enumerable:!1,configurable:!0}),e}(Et),Ft=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return Mt},enumerable:!1,configurable:!0}),e}(Et),Gt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return Ot},enumerable:!1,configurable:!0}),e}(Et),It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return Ct},enumerable:!1,configurable:!0}),e}(Et),Lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return Rt},enumerable:!1,configurable:!0}),e}(Et),Ht=function(){function t(){this._degrees=0,this._radians=0,this._direction=new e}return Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},t}(),Ut="Transform",zt=function(t){function i(){var i=t.call(this)||this;return i._position=new e,i._scale=new e(1,1),i._rotation=new Ht,i._innerPosition=new e,i._parent=null,i.parentScale=!0,i.parentRotation=!0,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.allowMultiple=!1,i.type=Ut,i}return r(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&&this.updateInnerPositionFromParent()},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent?(!1===this.lastPosition.equals(this._position)&&this.updateInnerPositionFromParent(),this.setPositionFromParent()):this._innerPosition.copy(this._position),this.lastPosition.copy(this._position)},i.prototype.updateInnerPositionFromParent=function(){e.subtract(this._innerPosition,this._position,this._parent.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),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.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}(Ft),Nt="Default",Wt=function(){function t(){var t=this;this.id=Dt(),this.name=null,this.tag=null,this.layer=Nt,this.ui=!1,this._active=!0,this.started=!1,this._parent=null,this.sceneManager=jt.getSingleton("SceneManager"),this.gameObjectManager=jt.getSingleton("GameObjectManager"),this.components=[],this.inactiveComponents=[],this.inactiveChildren=[],this.gameLoopEventHandler=function(e){if(!1!==t._active)try{!1===t.started&&e.type===bt?(t.start(),t.started=!0):!0===t.started&&e.type===xt&&t.update()}catch(t){throw-1!==t.message.indexOf(m.messagePrefix)?t:new m(t.message)}},this.addComponent((function(){return new zt})),window.addEventListener(bt,this.gameLoopEventHandler),window.addEventListener(xt,this.gameLoopEventHandler)}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.getComponentByType(Ut)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"active",{get:function(){return this._active},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=t?t.transform:null},enumerable:!1,configurable:!0}),t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.addComponent=function(t,e){void 0===e&&(e=null);var i=t();return this.checkMultipleComponent(i),i.name=e,i.gameObject=this,this.components.push(i),i},t.prototype.checkMultipleComponent=function(t){if(!1===t.allowMultiple&&this.hasComponentOfType(t.type))throw new m("GameObject only allows one component of type "+t.type)},t.prototype.getComponents=function(){return this.components},t.prototype.getComponentByName=function(t){return this.components.reduce((function(e,i){return i.name===t?i:e}),null)},t.prototype.getComponentByType=function(t){return this.components.reduce((function(e,i){return i.type===t?i:e}),null)},t.prototype.getComponentsByType=function(t){return this.components.filter((function(e){return e.type===t}))},t.prototype.hasComponentOfName=function(t){return null!==this.getComponentByName(t)},t.prototype.hasComponentOfType=function(t){return null!==this.getComponentByType(t)},t.prototype.removeComponentByName=function(t){var e=this;this.components.every((function(i,n){if(i.name===t)return i.destroy(),delete e.components[n],!1}))},t.prototype.removeComponentByType=function(t){var e=this;this.components.every((function(i,n){if(i.type===t)return i.destroy(),delete e.components[n],!1}))},t.prototype.removeComponents=function(){var t=this;this.components.every((function(e,i){return e.destroy(),delete t.components[i]})),this.components=[]},t.prototype.addChild=function(t,e){return this.gameObjectManager.addGameObject(t,e,this)},t.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},t.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParentAndName(this,t)},t.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},t.prototype.setActive=function(t){var e=this;!1===t&&this.updateInactiveCache(),this.components.filter((function(t){return-1===e.inactiveComponents.indexOf(t.id)})).forEach((function(e){return e.setActive(t)})),this.getChildren().filter((function(t){return-1===e.inactiveChildren.indexOf(t.id)})).forEach((function(e){return e.setActive(t)})),this._active=t},t.prototype.updateInactiveCache=function(){var t=this;this.inactiveComponents=[],this.inactiveChildren=[],this.components.filter((function(t){return!1===t.active})).forEach((function(e){return t.inactiveComponents.push(e.id)})),this.getChildren().filter((function(t){return!1===t.active})).forEach((function(e){return t.inactiveChildren.push(e.id)}))},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(bt,this.gameLoopEventHandler),window.removeEventListener(xt,this.gameLoopEventHandler),this.removeComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),qt=function(){this.depth=0,this.layers=[],this.originalViewportRect=null,this.viewportRect=null,this.worldSpaceRect=null,this.zoom=0},kt=[Nt],Yt="Camera",Qt=function(t){function e(){var e=t.call(this)||this;return e.renderManager=jt.getSingleton("RenderManager"),e.domManager=jt.getSingleton("DomManager"),e._layers=kt,e._depth=0,e._zoom=1,e._originalViewportRect=new i(0,0,0,0),e._viewportRect=new i(0,0,0,0),e._worldSpaceRect=new i(0,0,0,0),e.cameraData=new qt,e.allowMultiple=!1,e.type=Yt,e.canvas=e.domManager.canvas,e}return r(e,t),Object.defineProperty(e.prototype,"layers",{get:function(){return this._layers},set:function(t){this._layers=c(c([],kt,!0),t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this._depth},set:function(t){this._depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new m("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"originalViewportRect",{get:function(){return this._originalViewportRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this._worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this._viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this._layers.push(t)},e.prototype.update=function(){this.updateOriginalViewportRect(),this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},e.prototype.updateOriginalViewportRect=function(){this._originalViewportRect.x=-this.canvas.width/2,this._originalViewportRect.y=-this.canvas.height/2,this._originalViewportRect.width=this.canvas.width,this._originalViewportRect.height=this.canvas.height},e.prototype.updateViewportRect=function(){var t=1/this._zoom;this._viewportRect.x=this._originalViewportRect.x*t,this._viewportRect.y=this._originalViewportRect.y*t,this._viewportRect.width=this._originalViewportRect.width*t,this._viewportRect.height=this._originalViewportRect.height*t},e.prototype.updateWorldSpaceRect=function(){this._worldSpaceRect.x=this.gameObject.transform.position.x-this._viewportRect.width/2,this._worldSpaceRect.y=this.gameObject.transform.position.y-this._viewportRect.height/2,this._worldSpaceRect.width=this._viewportRect.width,this._worldSpaceRect.height=this._viewportRect.height},e.prototype.updateCameraData=function(){this.cameraData.depth=this._depth,this.cameraData.layers=this._layers,this.cameraData.originalViewportRect=this._originalViewportRect,this.cameraData.viewportRect=this._viewportRect,this.cameraData.worldSpaceRect=this._worldSpaceRect,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},e}(It),Xt=function(t){function e(){var e=t.call(this)||this;return e.transform.position.set(0,0),e.camera=e.addComponent((function(){return new Qt})),e}return r(e,t),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,"originalViewporRect",{get:function(){return this.camera.originalViewportRect},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}(Wt),Zt="GameCamera",Kt=function(){function t(){var t=this;this.game=null,this.name=null,this.gameObjectManager=jt.getSingleton("GameObjectManager"),this.started=!1,this.gameLoopEventHandler=function(e){try{!1===t.started&&e.type===bt?(t.start(),t.started=!0):!0===t.started&&e.type===xt&&t.update()}catch(t){throw-1!==t.message.indexOf(m.messagePrefix)?t:new m(t.message)}},window.addEventListener(bt,this.gameLoopEventHandler),window.addEventListener(xt,this.gameLoopEventHandler),this.addGameObject((function(){return new Xt}),Zt),this.gameLoopEventHandler.bind(this)}return Object.defineProperty(t.prototype,"gameCamera",{get:function(){return this.findGameObjectByName(Zt)},enumerable:!1,configurable:!0}),t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.getGameObjects=function(){return this.gameObjectManager.getGameObjects()},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.destroyAllGameObjects=function(){this.gameObjectManager.destroyAllGameObjects()},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(bt,this.gameLoopEventHandler),window.removeEventListener(xt,this.gameLoopEventHandler),this.gameObjectManager.destroyAllGameObjects(),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),$t=function(){function t(t){var i,n,r,o,a=this;this._image=null,this._slice=null,this._scale=null!==(i=jt.getConstant("GameConfig").spriteDefaultScale)&&void 0!==i?i:new e(1,1),this._smooth=!1,this._width=null,this._height=null,this._loaded=!1,this._image=t.image,this._slice=null!==(n=t.slice)&&void 0!==n?n:this._slice,null!==this._slice&&(this._width=this._slice.width,this._height=this._slice.height),this._scale=null!==(r=t.scale)&&void 0!==r?r:this._scale,this._smooth=null!==(o=t.smooth)&&void 0!==o?o:this._smooth,this._image.naturalWidth?this.onLoad():this._image.addEventListener("load",(function(){return a.onLoad()}))}return Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"image",{get:function(){return this._image},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"slice",{get:function(){return this._slice},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this._scale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"smooth",{get:function(){return this._smooth},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),t.prototype.onLoad=function(){var t,e;this._width=(null!==(t=this._width)&&void 0!==t?t:this._image.naturalWidth)*this._scale.x,this._height=(null!==(e=this._height)&&void 0!==e?e:this._image.naturalHeight)*this._scale.y,this._loaded=!0},t}(),Jt=function(t){var e,i;this.sprites=[],this.speed=1,this.loop=!1,this.sprites=t.sprites,this.speed=null!==(e=t.speed)&&void 0!==e?e:this.speed,this.loop=null!==(i=t.loop)&&void 0!==i?i:this.loop},te=function(t,e,i,n){this.x=t,this.y=e,this.width=i,this.height=n},ee=function(){function t(t){var i,n;this.image=null,this.offset=new e(0,0),this.tileSpacing=new e(0,0),this._tiles=[],this.image=t.image,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.tileSpacing=null!==(n=t.spacing)&&void 0!==n?n:this.tileSpacing,this.generateTiles()}return t.prototype.generateTiles=function(){for(var t=0,e=0;e<this.gridHeight;e++)for(var i=0;i<this.gridWidth;i++)this._tiles[t]=new te(i*this.tileWidth+i*this.tileSpacing.x+this.offset.x,e*this.tileHeight+e*this.tileSpacing.y+this.offset.y,this.tileWidth,this.tileHeight),t++},t.prototype.getTile=function(t){return this._tiles[t]?this._tiles[t]:null},Object.defineProperty(t.prototype,"tiles",{get:function(){return this._tiles},enumerable:!1,configurable:!0}),t}(),ie=function(t){function i(i,n,r,o){void 0===o&&(o=0);var a=t.call(this)||this;return a.cacheVector=new e,a.axes=[],a._type=d.Rectangle,a._position.set(i.x,i.y),a._width=n,a._height=r,a._angle=o,a._model=[new e(-n/2,-r/2),new e(-n/2,r/2),new e(n/2,r/2),new e(n/2,-r/2)],a._vertices=[new e,new e,new e,new e],a.axes=[new e,new e],a.update(),a}return r(i,t),i.prototype.update=function(){this.updateModel();for(var t=0;t<this._model.length;t++)this._vertices[t].set(this._model[t].x*Math.cos(this._angle)-this._model[t].y*Math.sin(this._angle)+this._position.x,this._model[t].x*Math.sin(this._angle)+this._model[t].y*Math.cos(this._angle)+this._position.y);this.updateDirection(),this.updateAxes()},i.prototype.updateModel=function(){this._model[0].set(-this._width/2,-this._height/2),this._model[1].set(-this._width/2,this._height/2),this._model[2].set(this._width/2,this._height/2),this._model[3].set(this._width/2,-this._height/2)},i.prototype.updateDirection=function(){e.unit(this._direction,e.subtract(this.cacheVector,this._vertices[1],this._vertices[0]))},i.prototype.updateAxes=function(){e.normal(this.axes[0],this._direction),this.axes[1].set(this._direction.x,this._direction.y)},i.prototype.clone=function(){return new i(this._position,this._width,this._height,this._angle)},i.prototype.getAxes=function(){return this.axes},i}(R),ne=function(){function t(t,i,n,r,o,a){void 0===a&&(a=0),this._position=new e,this._width=0,this._height=0,this._angle=0,this._quadMaxBounds=new e,this._quadMinBounds=new e,this._position.set(t.x,t.y),this._quadVertices=[new e,new e,new e,new e],this._width=i,this._height=n,this._angle=a,this.gameObject=o,this.physics=r,this.shape=new ie(this._position,this._width,this._height),this.updateQuadVertices()}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y),this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t,this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t,this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomLeftQuadVertex",{get:function(){return this._quadVertices[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomRightQuadVertex",{get:function(){return this._quadVertices[3]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topLeftQuadVertex",{get:function(){return this._quadVertices[1]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topRightQuadVertex",{get:function(){return this._quadVertices[2]},enumerable:!1,configurable:!0}),t.prototype.updateShape=function(){this.shape.position=this._position,this.shape.width=this._width,this.shape.height=this.height,this.shape.angle=this._angle,this.shape.update()},t.prototype.updateQuadVertices=function(){var t=this;this._quadMaxBounds.set(this.shape.vertices[0].x,this.shape.vertices[0].y),this._quadMinBounds.set(this.shape.vertices[0].x,this.shape.vertices[0].y),this.shape.vertices.forEach((function(e){t._quadMaxBounds.set(Math.max(e.x,t._quadMaxBounds.x),Math.max(e.y,t._quadMaxBounds.y)),t._quadMinBounds.set(Math.min(e.x,t._quadMinBounds.x),Math.min(e.y,t._quadMinBounds.y))})),this._quadVertices[0].set(this._quadMinBounds.x,this._quadMinBounds.y),this._quadVertices[1].set(this._quadMinBounds.x,this._quadMaxBounds.y),this._quadVertices[2].set(this._quadMaxBounds.x,this._quadMaxBounds.y),this._quadVertices[3].set(this._quadMaxBounds.x,this._quadMinBounds.y)},t}(),re=function(t){function e(){var e=t.call(this)||this;return e.collisionManager=jt.getSingleton("CollisionManager"),e.colliders=[],e._physics=!0,e.renderer=null,e.collisionsCache=[],e}return r(e,t),Object.defineProperty(e.prototype,"physics",{get:function(){return this._physics},enumerable:!1,configurable:!0}),e.prototype.addCollider=function(t){this.colliders.push(t),this.collisionManager.addCollider(t)},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){this.updatePosition();for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var a=o[r];if(a.remoteCollider.gameObject.layer===t)return a}return null},e.prototype.getCollisionsWithLayer=function(t){this.updatePosition(),this.collisionsCache=[];for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var a=o[r];a.remoteCollider.gameObject.layer===t&&this.collisionsCache.push(a)}return c([],this.collisionsCache,!0)},e.prototype.setActive=function(e){var i=this;!0===e&&!1===this.active?this.colliders.forEach((function(t){return i.collisionManager.addCollider(t)})):!1===e&&!0===this.active&&this.colliders.forEach((function(t){return i.collisionManager.removeCollider(t)})),this.renderer&&this.renderer.setActive(e),t.prototype.setActive.call(this,e)},e.prototype.destroy=function(){var e=this;this.colliders.forEach((function(t){return e.collisionManager.removeCollider(t)})),t.prototype.destroy.call(this)},e}(Bt),oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=l.Collider,e.color=null,e.shape=null,e}return r(e,t),e}(f),ae="BoxCollider",se=function(i){function n(n){var r,o,a,s,h,c=i.call(this)||this;return c.debug=!1,c.offsetX=0,c.offsetY=0,c.realWidth=0,c.realHeight=0,c.realOffset=new e,c.realPosition=new e,c.realRotation=0,c.applyRotation=jt.getConstant("GameConfig").collisions.method===t.CollisionMethodConfig.SAT,c.innerPosition=new e,c.type=ae,c.width=n.width,c.height=n.height,c.offsetX=null!==(r=n.offsetX)&&void 0!==r?r:c.offsetX,c.offsetY=null!==(o=n.offsetY)&&void 0!==o?o:c.offsetY,c._physics=null!==(a=n.physics)&&void 0!==a?a:c._physics,c.debug=(null!==(s=n.debug)&&void 0!==s?s:c.debug)&&jt.getConstant("GameConfig").debugEnabled,c.rotation=null!==(h=n.rotation)&&void 0!==h?h:new Ht,c}return r(n,i),n.prototype.start=function(){var t=this;this.updateRealSize(),this.addCollider(new ne(this.gameObject.transform.position,this.realWidth,this.realHeight,this._physics,this.gameObject,this.realRotation)),this.debug&&(this.renderer=this.gameObject.addComponent((function(){return new he(t.colliders[0])})))},n.prototype.update=function(){this.updatePosition()},n.prototype.updatePosition=function(){this.updateRealSize(),this.colliders[0].width=this.realWidth,this.colliders[0].height=this.realHeight,this.colliders[0].position=e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.realRotation&&this.applyRotation&&(this.colliders[0].angle=this.realRotation),0!==this.gameObject.transform.rotation.radians&&this.translate()},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.gameObject.transform.rotation.radians+this.rotation.radians},n.prototype.translate=function(){e.subtract(this.innerPosition,this.colliders[0].position,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)),this.colliders[0].position=this.realPosition},n}(re),he=function(t){function e(e){var i=t.call(this)||this;return i.renderManager=jt.getSingleton("RenderManager"),i.type="BoxColliderRenderer",i.renderData=new oe,i.renderData.debug=!0,i.renderData.color="#00FF00",i.collider=e,i}return r(e,t),e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position=this.collider.position,this.renderData.shape=this.collider.shape,this.renderManager.addRenderData(this.renderData)},e}(Lt),ce="TilemapCollider",le=function(t){function i(i){var n,r=t.call(this)||this;return r.tilemapRenderer=null,r.debug=!1,r.needsCollider=function(t){r.cacheVertex[0].set(t.position.x,t.position.y+t.height),r.cacheVertex[1].set(t.position.x+t.width,t.position.y),r.cacheVertex[2].set(t.position.x,t.position.y-t.height),r.cacheVertex[3].set(t.position.x-t.width,t.position.y);for(var e=function(t){if(void 0===r.tilemapRenderer.tilesData.find((function(e){return e.position.equals(r.cacheVertex[t])})))return{value:!0}},i=0;i<r.cacheVertex.length;i++){var n=e(i);if("object"==typeof n)return n.value}return!1},r.type=ce,r.tilemapRenderer=i.tilemapRenderer,r.debug=(null!==(n=i.debug)&&void 0!==n?n:r.debug)&&jt.getConstant("GameConfig").debugEnabled,r._physics=!0,r.cacheVertex=[new e,new e,new e,new e],r}return r(i,t),i.prototype.start=function(){var t=this;this.tilemapRenderer.tilesData.filter(this.needsCollider).forEach((function(e){t.addCollider(new ne(e.position,e.width,e.height,t._physics,t.gameObject))})),this.debug&&(this.renderer=this.gameObject.addComponent((function(){return new ue(t.colliders)})))},i.prototype.updatePosition=function(){},i}(re),ue=function(t){function e(e){var i=t.call(this)||this;return i.renderManager=jt.getSingleton("RenderManager"),i.renderData=[],i.colliders=[],i.type="TilemapColliderRenderer",i.colliders=e,i.colliders.forEach((function(t,e){i.renderData[e]=new oe,i.renderData[e].debug=!0,i.renderData[e].color="#00FF00"})),i}return r(e,t),e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].shape=e.shape,t.renderManager.addRenderData(t.renderData[i])}))},e}(Lt),pe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=l.Image,e.image=null,e.width=0,e.height=0,e.slice=null,e.flipHorizontal=!1,e.flipVertical=!1,e.rotation=0,e.smooth=!0,e.alpha=1,e.maskColor=null,e.maskColorMix=null,e}return r(e,t),e}(f),de="SpriteRenderer",fe=function(t){function i(i){var n,r,o,a,s,h,c,l,u,p;void 0===i&&(i={sprite:null});var d=t.call(this)||this;return d.renderManager=jt.getSingleton("RenderManager"),d.sprite=null,d.offset=new e,d.flipHorizontal=!1,d.flipVertical=!1,d.rotation=new Ht,d.smooth=!1,d.opacity=1,d._tiled=new e(1,1),d.maskColor="#ffffff",d.maskColorMix=0,d.renderData=[],d.innerPosition=new e,d.cachePosition=new e,d.cacheRenderPosition=new e,d.scaledOffset=new e,d.type=de,d.sprite=i.sprite,d.offset=null!==(n=i.offset)&&void 0!==n?n:d.offset,d.smooth=null!==(r=i.smooth)&&void 0!==r?r:d.smooth,d.rotation=null!==(o=i.rotation)&&void 0!==o?o:d.rotation,d.flipHorizontal=null!==(a=i.flipHorizontal)&&void 0!==a?a:d.flipHorizontal,d.flipVertical=null!==(s=i.flipVertical)&&void 0!==s?s:d.flipVertical,d.opacity=null!==(h=i.opacity)&&void 0!==h?h:d.opacity,d.tiled=null!==(c=i.tiled)&&void 0!==c?c:d._tiled,d.maskColor=null!==(l=i.maskColor)&&void 0!==l?l:d.maskColor,d.maskColorMix=null!==(u=i.maskColorMix)&&void 0!==u?u:d.maskColorMix,d.layer=null!==(p=i.layer)&&void 0!==p?p:d.layer,d}return r(i,t),Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new m("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},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]=new pe}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].ui=this.gameObject.ui,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.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.cachePosition,this.cachePosition,this.cacheRenderPosition),this.renderData[t].position=this.cachePosition,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}(Lt),ge=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=l.Text,e}return r(e,t),e}(f),me="TextRenderer",ye=function(t){function i(i){var n,r,o,a,s,h,c,l,u,p,d,f,g=t.call(this)||this;if(g.fontFamily="Sans",g.fontUrl=null,g.fontSize=12,g.width=100,g.height=100,g.offset=new e,g.color="#000000",g.lineSeparation=0,g.letterSpacing=0,g.bitmapSize=64,g.charRanges=[32,126,161,255],g.smooth=!1,g.bitmapOffset=new e,g.renderManager=jt.getSingleton("RenderManager"),g.renderData=new ge,g.lastFrameText="",g.type=me,g.text=i.text,g.fontFamily=i.fontFamily,g.fontUrl=null!==(n=i.fontUrl)&&void 0!==n?n:g.fontUrl,g.fontSize=null!==(r=i.fontSize)&&void 0!==r?r:g.fontSize,g.width=null!==(o=i.width)&&void 0!==o?o:g.width,g.height=null!==(a=i.height)&&void 0!==a?a:g.height,g.offset=null!==(s=i.offset)&&void 0!==s?s:g.offset,g.color=null!==(h=i.color)&&void 0!==h?h:g.color,g.lineSeparation=null!==(c=i.lineSeparation)&&void 0!==c?c:g.lineSeparation,g.letterSpacing=null!==(l=i.letterSpacing)&&void 0!==l?l:g.letterSpacing,g.bitmapSize=null!==(u=i.bitmapSize)&&void 0!==u?u:g.bitmapSize,g.charRanges=null!==(p=i.charRanges)&&void 0!==p?p:g.charRanges,g.smooth=null!==(d=i.smooth)&&void 0!==d?d:g.smooth,g.bitmapOffset=null!==(f=i.bitmapOffset)&&void 0!==f?f:g.bitmapOffset,g.charRanges.length%2!=0)throw new m("TextRenderer.charRanges must be a 2 column matrix");if(g.lineSeparation%2!=0)throw new m("TextRenderer.lineSeparation must be multiple of 2");return g}return r(i,t),i.prototype.start=function(){this.renderData.layer=this.gameObject.layer,this.renderData.ui=this.gameObject.ui,this.renderData.fontFamily=this.fontFamily,this.renderData.fontUrl=this.fontUrl,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.bitmapSize=this.bitmapSize,this.renderData.charRanges=this.charRanges,this.renderData.smooth=this.smooth,this.renderData.bitmapOffset=this.bitmapOffset},i.prototype.update=function(){this.renderData.width=this.width,this.renderData.height=this.height,this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.fontSize=this.fontSize,this.renderData.color=this.color,e.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text},i.prototype.crop=function(){if(this.fontSize>this.height)return"";for(var t=0,e=this.fontSize,i=[],n=[],r=0,o=this.text.replace(/\n/," \n ").split(" ");r<o.length;r++){var a=o[r],s="\n"!==a?a.length*(this.fontSize+this.letterSpacing):0;if("\n"===a||t>0&&t+s>this.width){if(n.push(i.join(" ")),(e+=this.fontSize+this.lineSeparation)>this.height)return n.join("\n");i=[],t=0}s>0&&(i.push(a),t+=s)}return n.push(i.join(" ")),n.join("\n")},i}(Lt),be=function(){function t(t,i,n){this._position=new e,this._position.set(t.x,t.y),this._width=i,this._height=n}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),t}(),xe=function(){this.position=new e,this.positionInViewport=new e},ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=l.Tilemap,e.tilesData=[],e.tilesToRender=[],e}return r(e,t),e}(f),_e=function(t){function i(i){var n,r,o,a,s,h=t.call(this)||this;return h.renderOrder="center",h.smooth=!1,h.textureCorrection=null,h.tileScale=null!==(n=jt.getConstant("GameConfig").spriteDefaultScale)&&void 0!==n?n:new e(1,1),h.tileWidth=0,h.tileHeight=0,h.orientation=new e(1,1),h.renderManager=jt.getSingleton("RenderManager"),h.tilemapProcessed=!1,h.renderData=new Map,h.cols=[],h.rows=[],h._width=0,h._height=0,h.tiles=[],h._realWidth=0,h._realHeight=0,h.cacheV2=new e,h.allowMultiple=!1,h.tileset=i.tileset,h.tileScale=null!==(r=i.tileScale)&&void 0!==r?r:h.tileScale,h.smooth=null!==(o=i.smooth)&&void 0!==o?o:h.smooth,h.renderOrder=null!==(a=i.renderOrder)&&void 0!==a?a:h.renderOrder,h.textureCorrection=null!==(s=i.textureCorrection)&&void 0!==s?s:h.textureCorrection,h}return r(i,t),i.prototype.start=function(){this.tileWidth=this.tileset.tileWidth*this.tileScale.x*Math.abs(this.gameObject.transform.scale.x),this.tileHeight=this.tileset.tileHeight*this.tileScale.y*Math.abs(this.gameObject.transform.scale.y),this.orientation.set(Math.sign(this.gameObject.transform.scale.x),Math.sign(this.gameObject.transform.scale.y)),this.processTilemap(),this.updatePosition()},i.prototype.update=function(){var t=this;this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTile=function(t,e,i,n,r,o){void 0===n&&(n=1),void 0===r&&(r={h:!1,v:!1}),void 0===o&&(o={x:0,y:0}),null!==t&&this.addTileToRenderData(t,e,i,n,r,o),this.updateSizeInfo(e,i)},i.prototype.addTileToRenderData=function(t,e,i,n,r,o){!1===this.renderData.has(n)&&this.renderData.set(n,this.createRenderDataForAlpha(n));var a=new xe;a.tile=t,a.position.set(this.gameObject.transform.position.x+e*this.tileWidth*this.orientation.x+o.x*Math.abs(this.gameObject.transform.scale.x)+this.tileWidth*this.orientation.x/2,this.gameObject.transform.position.y-i*this.tileHeight*this.orientation.y-o.y*Math.abs(this.gameObject.transform.scale.y)-this.tileHeight*this.orientation.y/2),a.flipHorizontal=r.h!==this.orientation.x<0,a.flipVertical=r.v!==this.orientation.y<0,this.renderData.get(n).tilesData.push(a)},i.prototype.createRenderDataForAlpha=function(t){var e=new ve;return e.ui=!1,e.alpha=t,e.image=this.tileset.image,e.layer=this.gameObject.layer,e.smooth=this.smooth,e.tileWidth=this.tileWidth,e.tileHeight=this.tileHeight,e.textureCorrection=this.textureCorrection,e},i.prototype.updateSizeInfo=function(t,e){this._width=!1===this.cols.includes(t)?this.cols.push(t):this._width,this._height=!1===this.rows.includes(e)?this.rows.push(e):this._height,this._realWidth=this._width*this.tileWidth,this._realHeight=this._height*this.tileHeight},i.prototype.updatePosition=function(){var t=this;this.cacheV2.set(("center"===this.renderOrder?-Math.round(this._realWidth/2):["left-down","left-up"].includes(this.renderOrder)?-this._realWidth:0)*this.orientation.x,("center"===this.renderOrder?Math.round(this._realHeight/2):["right-up","left-up"].includes(this.renderOrder)?this._realHeight:0)*this.orientation.y),this.renderData.forEach((function(i){return i.tilesData.forEach((function(i){e.add(i.position,i.position,t.cacheV2),t.addTileData(i)}))}))},i.prototype.addTileData=function(t){this.tiles.push(new be(t.position,this.tileWidth,this.tileHeight))},Object.defineProperty(i.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"realWidth",{get:function(){return this._realWidth},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"realHeight",{get:function(){return this._realHeight},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"tilesData",{get:function(){return this.tiles},enumerable:!1,configurable:!0}),i}(Lt),we="TiledRenderer",Me=function(t){function e(e){var i,n,r=this;return e.renderOrder=null!==(i=e.renderOrder)&&void 0!==i?i:e.tilemapData.renderorder,(r=t.call(this,e)||this).type=we,r.tiledTilemap=e.tilemapData,r.layerName=null!==(n=e.layerName)&&void 0!==n?n:null,r}return r(e,t),e.prototype.processTilemap=function(){var t=this;this.tiledTilemap.layers.forEach((function(e){var i,n;!0!==e.visible||null!==t.layerName&&t.layerName!==e.name||(!0===t.tiledTilemap.infinite?e.chunks.forEach((function(i){var n,r;return t.processChunk(i,e.opacity,{x:null!==(n=e.offsetx)&&void 0!==n?n:0,y:null!==(r=e.offsety)&&void 0!==r?r:0})})):t.processChunk(e,e.opacity,{x:null!==(i=e.offsetx)&&void 0!==i?i:0,y:null!==(n=e.offsety)&&void 0!==n?n:0}))})),this.tilemapProcessed=!0},e.prototype.processChunk=function(t,e,i){void 0===e&&(e=1),void 0===i&&(i={x:0,y:0});for(var n=0,r=0;r<t.height;r++)for(var o=0;o<t.width;o++){var a=this.tileset.getTile(t.data[n]-1);this.processTile(a,o+t.x,r+t.y,e,{h:!1,v:!1},i),n++}},e}(_e),Oe=1,Ce=2,Re=3,je="TilemapRenderer",Pe=function(t){function e(e){var i,n=t.call(this,e)||this;return n.alpha=1,n.type=je,n.tilemapData=e.tilemapData,n.alpha=null!==(i=e.alpha)&&void 0!==i?i:n.alpha,n}return r(e,t),e.prototype.processTilemap=function(){var t=this;this.tilemapData.trim().split("\n").forEach((function(e,i){e.split(",").forEach((function(e,n){var r=parseInt(e.trim()),o=null,a={h:!1,v:!1};if(!1===isNaN(r)){var s=r>999?r%1e3:r,h=Math.round(r/1e3);o=t.tileset.getTile(s),a.h=[Oe,Re].includes(h),a.v=[Ce,Re].includes(h)}t.processTile(o,n,i,t.alpha,a)}))})),this.tilemapProcessed=!0},e}(_e),Te="Animator",Se=function(t){function e(e){var i=t.call(this)||this;return i.timeManager=jt.getSingleton("TimeManager"),i.spriteRenderer=null,i.animations=new Map,i.currentAnimation=null,i.defaultSprite=null,i.type=Te,i.spriteRenderer=e.spriteRenderer,i}return r(e,t),e.prototype.start=function(){this.defaultSprite=this.spriteRenderer.sprite},e.prototype.update=function(){null!==this.currentAnimation?(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.stopAnimation():this.spriteRenderer.sprite=this.currentAnimation.sprite):this.spriteRenderer.sprite=this.defaultSprite},e.prototype.addAnimation=function(t,e){return this.animations.set(t,new De(e)),this},e.prototype.playAnimation=function(t){if(!1!==this.active){if(!1===this.animations.has(t))throw new m("Animation with name "+t+" does not exist.");this.currentAnimation=this.animations.get(t)}},e.prototype.stopAnimation=function(){!1!==this.active&&null!==this.currentAnimation&&(this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(At),De=function(){function t(t){this._sprite=null,this._restarted=!1,this.currentFrame=0,this.frameTime=0,this._animation=t}return Object.defineProperty(t.prototype,"sprite",{get:function(){return this._sprite},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"restarted",{get:function(){return this._restarted},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){return this._animation.loop},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!1,configurable:!0}),t.prototype.playFrame=function(t){this._restarted=!1,this.frameTime>=1/(24*this._animation.speed)&&(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}(),Ee=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Ae="AudioPlayer",Be=function(t){function e(e){var i,n,r;void 0===e&&(e={audio:null,volume:1,loop:!1});var o=t.call(this)||this;return o.volume=1,o.loop=!1,o.audio=null,o.clones=new Map,o._playing=!1,o._paused=!1,o.audioEventHandler=function(t){"ended"===t.type&&(o._playing=!1,o.audio.removeEventListener("ended",o.audioEventHandler))},o.userinputEventHandler=function(){Ee.forEach((function(t){window.removeEventListener(t,o.userinputEventHandler)})),o.audio.play()},o.allowMultiple=!1,o.type=Ae,o.audio=null!==(i=e.audio)&&void 0!==i?i:o.audio,o.volume=null!==(n=e.volume)&&void 0!==n?n:o.volume,o.loop=null!==(r=e.loop)&&void 0!==r?r:o.loop,o}return r(e,t),e.prototype.playAudio=function(t,e){void 0===e&&(e=null),!1===this.clones.has(Symbol.for(t.src))&&this.cloneAudio(t);var i=this.clones.get(Symbol.for(t.src));i.currentTime>0&&(i.currentTime=0),i.volume=null!=e?e:this.volume,i.play()},e.prototype.cloneAudio=function(t){var e=t.cloneNode();this.clones.set(Symbol.for(t.src),e)},e.prototype.play=function(){var t=this;if(null!==this.audio&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.audio.play();this.audio.volume=this.volume,this.audio.loop=this.loop,this.audio.addEventListener("ended",this.audioEventHandler),this._playing=!0,this.audio.play().then((function(){})).catch((function(){return Ee.forEach((function(e){return window.addEventListener(e,t.userinputEventHandler)}))}))}},e.prototype.stop=function(){this._playing&&(this.audio.pause(),this.audio.currentTime=0,this.audio.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this.audio.pause(),this._paused=!0)},e.prototype.setActive=function(e){!1===e&&this.stop(),t.prototype.setActive.call(this,e)},e.prototype.destroy=function(){this.stop(),t.prototype.destroy.call(this)},e}(At);t.RigidBodyType=void 0,(Pt=t.RigidBodyType||(t.RigidBodyType={}))[Pt.Static=0]="Static",Pt[Pt.Dynamic=1]="Dynamic";var Ve="RigidBody",Fe=function(i){function n(t){var n,r,o=i.call(this)||this;return o.timeManager=jt.getSingleton("TimeManager"),o.gravityScale=9.8,o.velocityScale=60,o._colliderComponents=[],o._layersToCollide=[],o._velocity=new e,o._gravity=new e(0,1),o.deltaGravity=new e,o.deltaVelocity=new e,o.collisions=[],o.penetrationPerDirection={x:new Map,y:new Map},o.updatePosition=!1,o.penetrationResolution=new e,o.nextObjectPosition=new e,o.type=Ve,o.allowMultiple=!1,o._rigidBodyType=t.rigidBodyType,o._layersToCollide=null!==(n=t.layersToCollide)&&void 0!==n?n:o._layersToCollide,o._gravity.set(0,null!==(r=t.gravity)&&void 0!==r?r:o._gravity.y),o}return r(n,i),Object.defineProperty(n.prototype,"rigidBodyType",{get:function(){return this._rigidBodyType},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"velocity",{get:function(){return this._velocity},set:function(t){this._velocity.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"gravity",{get:function(){return this._gravity.y},set:function(t){this._gravity.set(this._gravity.x,t)},enumerable:!1,configurable:!0}),n.prototype.start=function(){var t=this;if(this.gameObject.getComponents().forEach((function(e){return e instanceof re&&e.physics?t._colliderComponents.push(e):null})),0===this._colliderComponents.length)throw new m("RigidBody needs at least one Collider")},n.prototype.update=function(){this._rigidBodyType!==t.RigidBodyType.Static&&(this.applyGravity(),this.deltaVelocity.set(0,0),this.applyVelocity("x"),this.applyReposition("x"),this.deltaVelocity.set(0,0),this.applyVelocity("y"),this.applyReposition("y"))},n.prototype.applyGravity=function(){this._gravity.y<=0||(this._velocity=e.add(this._velocity,this._velocity,e.scale(this.deltaGravity,this._gravity,-this.gravityScale*this.timeManager.physicsDeltaTime)))},n.prototype.applyVelocity=function(t){this.deltaVelocity[t]=this._velocity[t]*this.velocityScale*this.timeManager.physicsDeltaTime,0===this.deltaVelocity.x&&0===this.deltaVelocity.y||(this.gameObject.transform.position=e.add(this.nextObjectPosition,this.gameObject.transform.position,this.deltaVelocity))},n.prototype.applyReposition=function(t){var e=this;0!==this._layersToCollide.length&&(this.updatePosition=!1,this.penetrationResolution.set(this.gameObject.transform.position.x,this.gameObject.transform.position.y),this.penetrationPerDirection[t].clear(),this.updateCollisions(),0!==this.collisions.length&&(this.collisions.forEach((function(i){!0===i.remoteCollider.physics&&null!==i.remoteCollider.gameObject.getComponentByType(Ve)&&0!==i.collisionData.displacementDirection[t]&&e.setPenetrationPerDirectionPerAxis(t,i)})),this.setPenetrationResolution(t),this.updatePosition&&(this.gameObject.transform.position=this.penetrationResolution)))},n.prototype.setPenetrationPerDirectionPerAxis=function(t,e){var i;this.penetrationPerDirection[t].set(e.collisionData.displacementDirection[t],Math.max(null!==(i=this.penetrationPerDirection[t].get(e.collisionData.displacementDirection[t]))&&void 0!==i?i:0,e.collisionData.penetration))},n.prototype.setPenetrationResolution=function(t){var e=this;this.penetrationPerDirection[t].forEach((function(i,n){e.penetrationResolution[t]+=n*i,0!==e._velocity[t]&&Math.sign(e._velocity[t])!==Math.sign(n)&&(e._velocity[t]=0),e.updatePosition=!0}))},n.prototype.updateCollisions=function(){var t=this;this.collisions=[],this._colliderComponents.forEach((function(e){return t._layersToCollide.forEach((function(i){return e.getCollisionsWithLayer(i).forEach((function(e){return t.collisions.push(e)}))}))}))},n}(Vt),Ge=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return r(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){ft.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.scale(this.position,ft.mouse.positionInViewport,1/this.camera.zoom),e.add(this.position,this.position,this.camera.worldSpaceRect.center),e.round(this.position,this.position),console.log("Space position: {x: "+this.position.x+", y: "+this.position.y+"}")),this.mousePressed=ft.mouse.leftButtonPressed},i}(Wt);t.Animation=Jt,t.Animator=Se,t.AssetManager=pt,t.AudioPlayer=Be,t.BoxCollider=se,t.Camera=Qt,t.CollisionData=J,t.Component=Et,t.CsvTilemapRenderer=Pe,t.DomManager=dt,t.GAME_CAMERA_ID=Zt,t.Game=St,t.GameCamera=Xt,t.GameObject=Wt,t.GameObjectManager=yt,t.GamepadController=_,t.GamepadData=w,t.InputManager=ft,t.KeyboardController=O,t.LAYER_DEFAULT=Nt,t.MouseController=C,t.PhysicsComponent=Vt,t.PreRenderComponent=Gt,t.Rectangle=i,t.RigidBody=Fe,t.Scene=Kt,t.SceneManager=gt,t.SpacePointer=Ge,t.Sprite=$t,t.SpriteRenderer=fe,t.TYPE_ANIMATOR=Te,t.TYPE_AUDIO_PLAYER=Ae,t.TYPE_BOX_COLLIDER=ae,t.TYPE_CAMERA=Yt,t.TYPE_RIGIDBODY=Ve,t.TYPE_SPRITE_RENDERER=de,t.TYPE_TEXT_RENDERER=me,t.TYPE_TILED_RENDERER=we,t.TYPE_TILEMAP_COLLIDER=ce,t.TYPE_TILEMAP_RENDERER=je,t.TYPE_TRANSFORM=Ut,t.TextRenderer=ye,t.TiledTilemapRenderer=Me,t.TilemapCollider=le,t.Tileset=ee,t.TimeManager=mt,t.TouchController=et,t.Transform=zt,t.Vector2=e,t.clamp=function(t,e,i){return Math.min(i,Math.max(e,t))},t.fixedRound=function(t,e){return Math.round(t*(10^e))/(10^e)},t.random=function(t,e){return Math.floor(Math.random()*(e-t))+t},t.range=function(t,e,i){void 0===i&&(i=1);for(var n=[],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";var e=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),i=function(){function t(t,i,n,r){this._position=new e,this._center=new e,this._width=0,this._height=0,this.set(t,i,n,r)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.updateFromRect=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlappingRectangle=function(t){return this.x1>=t.x&&this.x<=t.x1&&this.y1>=t.y&&this.y<=t.y1},t}(),n=function(){function t(t){this._degrees=0,this._radians=0,this._direction=new e,t&&t.radians?this.radians=t.radians:t&&t.degrees&&(this.degrees=t.degrees)}return Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},t}(),r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},r(t,e)};function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var a,s=function(){return s=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},s.apply(this,arguments)};function h(t,e,i,n){return new(i||(i=Promise))((function(r,o){function a(t){try{h(n.next(t))}catch(t){o(t)}}function s(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((n=n.apply(t,e||[])).next())}))}function l(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r<o;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(t){t.Image="Image",t.Audio="Audio",t.Video="Video"}(a||(a={}));var u,p=function(){this.type=null,this.url=null,this.loaded=!1,this.element=null},d=function(){function t(){this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.laadImage=function(t){var e=this.createAsset(t,a.Image);return e.element=new Image,e.element.src=t,e.element.naturalWidth?e.loaded=!0:e.element.addEventListener("load",(function(){return e.loaded=!0})),e.element},t.prototype.loadAudio=function(t){var e=this.createAsset(t,a.Audio);return e.element=new Audio,e.element.src=t,e.element.duration?e.loaded=!0:e.element.addEventListener("canplaythrough",(function(){return e.loaded=!0})),e.element},t.prototype.getImage=function(t){return this.getAsset(t,a.Image)},t.prototype.getVideo=function(t){return this.getAsset(t,a.Video)},t.prototype.getAudio=function(t){return this.getAsset(t,a.Audio)},t.prototype.getAsset=function(t,e){return void 0===e&&(e=null),this.assets.reduce((function(i,n){return n.url!==t||null!==e&&e!==n.type?i:n}),null).element},t.prototype.createAsset=function(t,e){var i=new p;return i.type=e,i.url=t,this.assets.push(i),i},t}(),f="AngryPixelException",g=function(t){function e(e){var i=t.call(this,e)||this;return i.name=f,i}return o(e,t),e}(Error),m=function(){function t(t,n,r,o){void 0===r&&(r=6),void 0===o&&(o=15),this._bounds=new i(0,0,0,0),this._quadrants=[],this.colliders=[],this.sw=0,this.se=1,this.nw=2,this.ne=3,this.center=new e,this.childrenWidth=0,this.childrenHeight=0,this.quadrantsForCollider=[],this.level=t,this._bounds.updateFromRect(n),this.maxLevels=r,this.maxColliders=o,this.updateCache()}return Object.defineProperty(t.prototype,"bounds",{get:function(){return this._bounds},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"quadrants",{get:function(){return this._quadrants},enumerable:!1,configurable:!0}),t.prototype.updateBounds=function(t){this._bounds.updateFromRect(t),this.updateCache()},t.prototype.clearColliders=function(){this.colliders=[],this._quadrants.forEach((function(t){return t.clearColliders()}))},t.prototype.clearQuadrants=function(){this._quadrants.forEach((function(t){return t.clearQuadrants()})),this._quadrants=[]},t.prototype.addCollider=function(t){this._quadrants.length>0?this.insertColliderIntoChildrenQuads(t):(this.colliders.push(t),this.colliders.length>this.maxColliders&&this.level<this.maxLevels&&this.splitQuad())},t.prototype.retrieve=function(t){var e=[];this._quadrants.length>0&&this.getChildrenQuadrantForCollider(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})),e.push.apply(e,this.colliders);var i=e.indexOf(t);return-1!==i&&e.splice(i,1),e},t.prototype.splitQuad=function(){var e=this;this._quadrants=[new i(this.center.x-this.childrenWidth,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new i(this.center.x,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new i(this.center.x-this.childrenWidth,this.center.y,this.childrenWidth,this.childrenHeight),new i(this.center.x,this.center.y,this.childrenWidth,this.childrenHeight)].map((function(i){return new t(e.level+1,i,e.maxLevels,e.maxColliders)}));for(var n=0,r=this.colliders;n<r.length;n++){var o=r[n];this.insertColliderIntoChildrenQuads(o)}this.colliders=[]},t.prototype.getChildrenQuadrantForCollider=function(t){if(0===this._quadrants.length)throw new g("Current quadrant does not have quadrant children.");if(this.quadrantsForCollider=[],t.bottomLeftQuadVertex.x<=this.center.x&&t.bottomLeftQuadVertex.y<=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.sw]),t.bottomRightQuadVertex.x>=this.center.x&&t.bottomRightQuadVertex.y<=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.se]),t.topLeftQuadVertex.x<=this.center.x&&t.topLeftQuadVertex.y>=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.nw]),t.topRightQuadVertex.x>=this.center.x&&t.topRightQuadVertex.y>=this.center.y&&this.quadrantsForCollider.push(this._quadrants[this.ne]),0===this.quadrantsForCollider.length)throw new g("Children does not fit in any children quadrant");return this.quadrantsForCollider},t.prototype.insertColliderIntoChildrenQuads=function(t){this.getChildrenQuadrantForCollider(t).forEach((function(e){return e.addCollider(t)}))},t.prototype.updateCache=function(){this.center.set(this._bounds.width/2+this._bounds.x,this._bounds.height/2+this._bounds.y),this.childrenWidth=this._bounds.width/2,this.childrenHeight=this._bounds.height/2},t}(),y=function(){function t(t,n,r,o){void 0===n&&(n=null),this.minBounds=new e,this.maxBounds=new e,this.newBounds=new i(0,0,0,0),this.fixedQuadTree=null!==n,this.resolver=t,this.colliders=[],this.fixedQuadTree?this.bounds=n:this.bounds=new i(0,0,0,0),this.quadTree=new m(0,this.bounds,r,o)}return t.prototype.addCollider=function(t){this.colliders.push(t)},t.prototype.removeCollider=function(t){var e=this.colliders.indexOf(t);-1!==e&&(delete this.colliders[e],this.colliders.splice(e,1))},t.prototype.getCollisionsForCollider=function(t){return-1===this.colliders.indexOf(t)?[]:this.narrowPhase(t,this.broadPhase(t))},t.prototype.broadPhase=function(t){return this.quadTree.retrieve(t)},t.prototype.narrowPhase=function(t,e){var i=this,n=[];return e.filter((function(e){return e.gameObject!==t.gameObject})).forEach((function(e){var r=i.resolver.getCollisionData(t.shape,e.shape);null!==r&&n.push({localCollider:t,remoteCollider:e,collisionData:r})})),n},t.prototype.update=function(){if(0!==this.colliders.length){this.quadTree.clearColliders(),this.quadTree.clearQuadrants(),!1===this.fixedQuadTree&&(this.updateNewBounds(),!1===this.newBounds.equals(this.bounds)&&(this.bounds.updateFromRect(this.newBounds),this.quadTree.updateBounds(this.bounds)));for(var t=0,e=this.colliders;t<e.length;t++){var i=e[t];this.quadTree.addCollider(i)}}},t.prototype.updateNewBounds=function(){var t=this;this.colliders.forEach((function(e){t.minBounds.set(Math.min(e.bottomLeftQuadVertex.x,t.minBounds.x),Math.min(e.bottomLeftQuadVertex.y,t.minBounds.y)),t.maxBounds.set(Math.max(e.topRightQuadVertex.x,t.maxBounds.x),Math.max(e.topRightQuadVertex.y,t.maxBounds.y))})),this.newBounds.set(this.minBounds.x,this.minBounds.y,this.maxBounds.x-this.minBounds.x,this.maxBounds.y-this.minBounds.y)},t}(),b=function(){function t(t,e,i){if(this._canvas=null,!t)throw new g("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}(),x=function(){function t(){this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i){void 0===i&&(i=null);var n=this.findGameObjectByName(e);if(n&&!1===n.keep)throw new g("There is already a GameObject with the name "+e);if(n&&n.keep)return n;var r=t();return r.name=e,r.parent=i,this.gameObjects.push(r),r.init(),r},t.prototype.getGameObjects=function(){return this.gameObjects},t.prototype.findGameObjectById=function(t){return this.gameObjects.reduce((function(e,i){return i.id===t?i:e}),null)},t.prototype.findGameObjectByName=function(t){return this.gameObjects.reduce((function(e,i){return i.name===t?i:e}),null)},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParentAndName=function(t,e){return this.gameObjects.reduce((function(i,n){return n.name===e&&n.parent===t?n:i}),null)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.findGameObjectByTag=function(t){var e;return null!==(e=this.findGameObjectsByTag(t)[0])&&void 0!==e?e:null},t.prototype.destroyAllGameObjects=function(){var t=this;this.gameObjects.forEach((function(e){return e.keep?null:t._destroyGameObject(e,!1)})),this.gameObjects=[]},t.prototype.destroyGameObject=function(t){this._destroyGameObject(t,!0)},t.prototype._destroyGameObject=function(t,e){var i=this.gameObjects.indexOf(t);-1!==i&&(e&&this.destroyChildren(t),t.destroy(),delete this.gameObjects[i])},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){e.destroyChildren(t),e.destroyGameObject(t)}))},t}(),v=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 _),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}(),_=function(){function t(){this._connected=!1,this._id=null,this.buttons=new Map,this.axes=new Map,this._dpadAxes=new e,this._leftStickAxes=new e,this._rightStickAxes=new e}return t.prototype.updateFromGamepad=function(t){var e=this;this._id=t.id,this._connected=t.connected,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._id},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,"connected",{get:function(){return this._connected},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}),t}(),w=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}(),M=function(){function t(t){var e=this;this.keyPresses=new Map,this.eventHandler=function(t){"keydown"===t.type&&e.keyPresses.set(t.code,!0),"keyup"===t.type&&e.keyPresses.set(t.code,!1)},this.canvas=t,this.canvas.addEventListener("keydown",this.eventHandler),this.canvas.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyPresses.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.keyPresses.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.keyPresses.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyPresses.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.keyPresses.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.keyPresses.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),C=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}();!function(t){t[t.Rectangle=0]="Rectangle"}(u||(u={}));var O,R=function(){function t(){this._model=[],this._vertices=[],this._position=new e,this._direction=new e,this._height=0,this._width=0,this._angle=0}return Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertices",{get:function(){return this._vertices},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Image=0]="Image",t[t.Text=1]="Text",t[t.Geometric=2]="Geometric",t[t.Collider=3]="Collider",t[t.Tilemap=4]="Tilemap",t[t.Mask=5]="Mask"}(O||(O={}));var j=function(){function t(){this.ui=!1,this.debug=!1,this.layer=null,this._position=new e(0,0),this._positionInViewport=new e(0,0)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},set:function(t){this._positionInViewport.set(t.x,t.y)},enumerable:!1,configurable:!0}),t}(),P=function(){function t(t){this.canvas=null,this.canvasContext=null,this.imagePosition=new e(0,0),this.canvas=t,this.canvasContext=t.getContext("2d")}return t.prototype.clearCanvas=function(t){void 0===t&&(t=null),this.canvasContext.clearRect(0,0,this.canvas.width,this.canvas.height),null!==t&&(this.canvasContext.fillStyle=t,this.canvasContext.fillRect(0,0,this.canvas.width,this.canvas.height))},t.prototype.render=function(t,e){switch(e.type){case O.Image:this.renderImage(e,t.zoom);break;case O.Tilemap:this.renderTilemap(e,t.zoom);break;case O.Text:this.renderText(e);break;case O.Geometric:this.renderGeometric(e,t.zoom);break;case O.Collider:this.renderCollider(e,t.zoom)}},t.prototype.renderImage=function(t,e){this.updateRenderPosition(t),this.imagePosition.set(0,0),this.canvasContext.save(),this.applyZoom(t,e),0!==t.rotation?(this.canvasContext.translate(t.positionInViewport.x+t.width/2,t.positionInViewport.y+t.height/2),this.imagePosition.set(-t.width/2,-t.height/2),this.canvasContext.rotate(-t.rotation)):(this.canvasContext.translate(t.positionInViewport.x,t.positionInViewport.y),this.imagePosition.set(t.flipHorizontal?-t.width:this.imagePosition.x,t.flipVertical?-t.height:this.imagePosition.y)),this.canvasContext.globalAlpha=t.alpha,this.canvasContext.imageSmoothingEnabled=t.smooth,this.canvasContext.scale(t.flipHorizontal?-1:1,t.flipVertical?-1:1),void 0!==t.slice&&null!==t.slice?this.canvasContext.drawImage(t.image,t.slice.x,t.slice.y,t.slice.width,t.slice.height,this.imagePosition.x,this.imagePosition.y,t.width,t.height):this.canvasContext.drawImage(t.image,this.imagePosition.x,this.imagePosition.y,t.width,t.height),this.canvasContext.restore()},t.prototype.renderTilemap=function(t,e){var i=this;t.tilesToRender.forEach((function(n){i.canvasContext.save(),i.applyZoom(t,e),i.imagePosition.set(0,0),i.canvasContext.translate(i.canvas.width/2+n.positionInViewport.x-t.tileWidth/2,i.canvas.height/2-n.positionInViewport.y-t.tileHeight/2),i.imagePosition.set(n.flipHorizontal?-n.tile.width:i.imagePosition.x,n.flipVertical?-n.tile.height:i.imagePosition.y),i.canvasContext.globalAlpha=t.alpha,i.canvasContext.imageSmoothingEnabled=t.smooth,i.canvasContext.scale(n.flipHorizontal?-1:1,n.flipVertical?-1:1),i.canvasContext.drawImage(t.image,n.tile.x,n.tile.y,n.tile.width,n.tile.height,i.imagePosition.x,i.imagePosition.y,t.tileWidth,t.tileHeight),i.canvasContext.restore()}))},t.prototype.renderText=function(t){var e=this;this.updateRenderPosition(t),this.canvasContext.save(),this.canvasContext.font=t.fontSize+"px "+t.fontFamily,this.canvasContext.fillStyle=t.color,this.canvasContext.textBaseline="middle",t.text.split("\n").length>1?t.text.split("\n").forEach((function(i,n){e.canvasContext.fillText(i,t.positionInViewport.x,t.positionInViewport.y+(t.lineSeparation+t.fontSize)*n)})):this.canvasContext.fillText(t.text,t.positionInViewport.x,t.positionInViewport.y),this.canvasContext.restore()},t.prototype.renderGeometric=function(t,e){this.canvasContext.save(),this.applyZoom(t,e),this.updateRenderPosition(t),"Rectangle"===t.geometricType&&(this.canvasContext.strokeStyle=t.color,this.canvasContext.strokeRect(t.positionInViewport.x-t.getGeometric().width/2,t.positionInViewport.y-t.getGeometric().height/2,t.getGeometric().width,t.getGeometric().height)),this.canvasContext.restore()},t.prototype.renderCollider=function(t,e){if(this.canvasContext.save(),this.applyZoom(t,e),this.updateRenderPosition(t),this.canvasContext.beginPath(),this.canvasContext.strokeStyle=t.color,0!==t.shape.angle?(this.canvasContext.translate(t.positionInViewport.x,t.positionInViewport.y),this.canvasContext.rotate(-t.shape.angle),this.imagePosition.set(-t.shape.width/2,-t.shape.height/2)):(this.canvasContext.translate(t.positionInViewport.x-t.shape.width/2,t.positionInViewport.y-t.shape.height/2),this.imagePosition.set(0,0)),t.shape.type===u.Rectangle)this.canvasContext.strokeRect(this.imagePosition.x,this.imagePosition.y,t.shape.width,t.shape.height);this.canvasContext.restore()},t.prototype.applyZoom=function(t,e){t.ui||this.canvasContext.setTransform(e,0,0,e,this.canvas.width*(1-e)/2,this.canvas.height*(1-e)/2)},t.prototype.updateRenderPosition=function(t){t.type===O.Image&&this.centerImage(t),t.positionInViewport.set(Number((t.positionInViewport.x+this.canvas.width/2).toFixed(0)),Number((this.canvas.height/2-t.positionInViewport.y).toFixed(0)))},t.prototype.centerImage=function(t){t.positionInViewport.set(t.positionInViewport.x-Math.floor(t.width/2),t.positionInViewport.y+Math.floor(t.height/2))},t}(),T=function(){function t(t,e,i,n){void 0===n&&(n=!1),this.debug=!1,this.renderData=[],this.cameraData=[],this.renderer=t,this.cullingService=e,this.canvasColor=i,this.debug=n}return t.prototype.clearCanvas=function(){this.renderer.clearCanvas(this.canvasColor)},t.prototype.addRenderData=function(t){!1===this.debug&&t.debug||this.renderData.push(t)},t.prototype.addCameraData=function(t){this.cameraData.push(t)},t.prototype.render=function(){var t=this;this.cameraData.sort((function(t,e){return t.depth-e.depth})).forEach((function(e){return t.renderByCamera(e)})),this.clearData()},t.prototype.clearData=function(){this.renderData=[],this.cameraData=[]},t.prototype.renderByCamera=function(t){var e=this;this.orderRendeData(t),this.cullingService.applyCulling(t,this.renderData).forEach((function(i){e.updateFromCameraViewport(t,i),e.renderer.render(t,i)}))},t.prototype.orderRendeData=function(t){this.renderData.sort((function(e,i){return t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer)}))},t.prototype.updateFromCameraViewport=function(t,e){var i=this;!0!==e.ui?e.type===O.Tilemap?e.tilesToRender.forEach((function(e){return i.setPositionInViewport(t,e)})):this.setPositionInViewport(t,e):e.positionInViewport=e.position},t.prototype.setPositionInViewport=function(t,e){e.positionInViewport.set(Math.round(e.position.x-t.worldSpaceRect.x-t.worldSpaceRect.width/2),Math.round(e.position.y-t.worldSpaceRect.y-t.worldSpaceRect.height/2))},t}(),S="undefined"!=typeof Float32Array?Float32Array:Array;function D(){var t=new S(16);return S!=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 A(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 E(t,e,i){var n,r,o,a,s,h,l,c,u,p,d,f,g=i[0],m=i[1],y=i[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*y+e[12],t[13]=e[1]*g+e[5]*m+e[9]*y+e[13],t[14]=e[2]*g+e[6]*m+e[10]*y+e[14],t[15]=e[3]*g+e[7]*m+e[11]*y+e[15]):(n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],h=e[5],l=e[6],c=e[7],u=e[8],p=e[9],d=e[10],f=e[11],t[0]=n,t[1]=r,t[2]=o,t[3]=a,t[4]=s,t[5]=h,t[6]=l,t[7]=c,t[8]=u,t[9]=p,t[10]=d,t[11]=f,t[12]=n*g+s*m+u*y+e[12],t[13]=r*g+h*m+p*y+e[13],t[14]=o*g+l*m+d*y+e[14],t[15]=a*g+c*m+f*y+e[15]),t}function B(t,e,i){var n=i[0],r=i[1],o=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]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function V(t,e,i){var n=Math.sin(i),r=Math.cos(i),o=e[0],a=e[1],s=e[2],h=e[3],l=e[4],c=e[5],u=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*r+l*n,t[1]=a*r+c*n,t[2]=s*r+u*n,t[3]=h*r+p*n,t[4]=l*r-o*n,t[5]=c*r-a*n,t[6]=u*r-s*n,t[7]=p*r-h*n,t}function F(t,e,i,n,r,o,a){var s=1/(e-i),h=1/(n-r),l=1/(o-a);return t[0]=-2*s,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)*s,t[13]=(r+n)*h,t[14]=(a+o)*l,t[15]=1,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var G,I=function(t){var e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},L=function(){function t(t,e,i){this.lastTexture=null,this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=D(),this.modelMatrix=D(),this.textureMatrix=D(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i,n){var r;if("image"!==n&&(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=A(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[i.positionInViewport.x,i.positionInViewport.y,0]),V(this.modelMatrix,this.modelMatrix,i.rotation),B(this.modelMatrix,this.modelMatrix,[i.width*(i.flipHorizontal?-1:1),i.height*(i.flipVertical?-1:1),1]),this.textureMatrix=A(this.textureMatrix),i.slice&&(E(this.textureMatrix,this.textureMatrix,[i.slice.x/i.image.naturalWidth,i.slice.y/i.image.naturalHeight,0]),B(this.textureMatrix,this.textureMatrix,[i.slice.width/i.image.naturalWidth,i.slice.height/i.image.naturalHeight,1])),this.projectionMatrix=A(this.projectionMatrix),F(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND),this.lastTexture===e&&"image"===n||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,i.alpha),this.gl.uniform1i(this.programManager.useTintColorUniform,i.tintColor?1:0),i.tintColor){var o=I(i.tintColor),a=o.r,s=o.g,h=o.b,l=o.a;this.gl.uniform4f(this.programManager.tintColorUniform,a,s,h,l)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,i.maskColor?1:0),i.maskColor){var c=I(i.maskColor);a=c.r,s=c.g,h=c.b;this.gl.uniform4f(this.programManager.maskColorUniform,a,s,h,i.alpha),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(r=i.maskColorMix)&&void 0!==r?r:0)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),k=function(){function t(t){this.shaderLoader=t}return t.prototype.create=function(t,e,i){var n=t.createProgram(),r=this.shaderLoader.load(t,t.VERTEX_SHADER,e),o=this.shaderLoader.load(t,t.FRAGMENT_SHADER,i);return this.link(t,n,r,o),n},t.prototype.link=function(t,e,i,n){t.attachShader(e,i),t.attachShader(e,n),t.linkProgram(e);var r=t.LINK_STATUS;if(!t.getProgramParameter(e,r)){var o=t.getProgramInfoLog(e);throw t.deleteProgram(e),new g("Unable to initialize the Program: "+o)}},t}(),U=function(){function t(){}return t.prototype.load=function(t,e,i){var n=t.createShader(e);t.shaderSource(n,i),t.compileShader(n);var r=t.COMPILE_STATUS;if(!t.getShaderParameter(n,r)){var o=t.getShaderInfoLog(n);throw t.deleteShader(n),new g("Unable to initialize the shader program: "+o)}return n},t}(),H=function(){function t(t,e){this.gl=e.getContext(t)}return t.prototype.createFromImage=function(t,e,i){var n=this;return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(function(){return n.create(t,i,e)})),i},t.prototype.createFromCanvas=function(t,e,i){return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i},t.prototype.create=function(t,e,i){void 0===i&&(i=!0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)},t}();!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(G||(G={}));var z,W,N=function(){function t(t,e,i,n,r,o,a,s,h,l){this.canvas=e,this.gl=this.canvas.getContext(t),i.loadProgram(),this.textureManager=n,this.imageRenderer=o,this.tilemapRenderer=a,this.textRenderer=s,this.geometricRenderer=h,this.maskRenderer=l,this.fontAtlasFactory=r}return t.prototype.clearCanvas=function(t){var e=I(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.render=function(t,e){e.type===O.Image&&(this.renderImage(t,e),this.lastRender="image"),e.type===O.Tilemap&&(this.renderTilemap(t,e),this.lastRender="tilemap"),e.type===O.Text&&(this.renderText(t,e),this.lastRender="text"),e.type===O.Collider&&(this.geometricRenderer.renderCollider(t.viewportRect,e,this.lastRender),this.lastRender="geometric"),e.type===O.Geometric&&(this.geometricRenderer.renderGeometric(t.viewportRect,e,this.lastRender),this.lastRender="geometric"),e.type===O.Mask&&(this.renderMask(t,e),this.lastRender="mask")},t.prototype.renderImage=function(t,e){this.imageRenderer.render(!0===e.ui?t.originalViewportRect:t.viewportRect,this.textureManager.getOrCreateTextureFromImage(e.image,e.smooth),e,this.lastRender)},t.prototype.renderTilemap=function(t,e){this.tilemapRenderer.render(!0===e.ui?t.originalViewportRect:t.viewportRect,this.textureManager.getOrCreateTextureFromImage(e.image,e.smooth),e,this.lastRender)},t.prototype.renderText=function(t,e){this.fontAtlasFactory.loadingFontAtlas(e.fontFamily)||(this.fontAtlasFactory.hasFontAtlas(e.fontFamily)?this.fontAtlasLoaded(this.fontAtlasFactory.getFontAtlas(e.fontFamily),t,e):this.fontAtlasFactory.asyncCreate(e.charRanges,e.fontFamily,e.fontUrl,e.bitmapSize))},t.prototype.renderMask=function(t,e){this.maskRenderer.render(!0===e.ui?t.originalViewportRect:t.viewportRect,e,this.lastRender)},t.prototype.fontAtlasLoaded=function(t,e,i){this.textRenderer.render(!0===i.ui?e.originalViewportRect:e.viewportRect,this.textureManager.getOrCreateTextureFromCanvas(i.fontFamily,t.canvas,i.smooth),t,i,this.lastRender)},t}(),q=function(){function t(t,e){this.game=null,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.game=t,this.renderManager=e}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i){if(void 0===i&&(i=!1),this.scenes.has(t))throw new g("There is already a scene with the name '"+t+"'");this.scenes.set(t,e),!0!==i&&null!==this.openingSceneName||(this.openingSceneName=t)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new g("There is no opening scene");this.loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(null===this.game)throw new g("Game not initialized.");if(!1===this.scenes.has(t))throw new g("Scene with name "+t+" does not exists");this.unloadCurrentScene(),this.currentScene=this.scenes.get(t)(),this.currentScene.name=t,this.currentScene.game=this.game,this.currentScene.init()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.destroy(),this.currentScene=null,this.currentSceneName=null,this.renderManager.clearData())},t}(),Y=function(){function t(t,e){if(this.maxGameDeltatime=0,this.maxPhysicsDeltaTime=0,this.timeScale=1,this.browserDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.max=1/15,this.then=0,t<15)throw new g("Game framerate cannot be less than 15");if(e<60)throw new g("Physics framerate cannot be less than 60");if(e<t)throw new g("Physics framerate cannot be less than game framerate");this.maxGameDeltatime=parseFloat((1/t).toFixed(6)),this.maxPhysicsDeltaTime=parseFloat((1/e).toFixed(6))}return t.prototype.update=function(t){var e=.001*t;this.browserDeltaTime=Math.min(Math.max(0,e-this.then),this.max),this.then=e},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}(),Q=function(){function t(t){this.textures=new Map,this.textureFactory=t}return t.prototype.getTexture=function(t){var e;return null!==(e=this.textures.get(Symbol.for(t)))&&void 0!==e?e:null},t.prototype.getOrCreateTextureFromImage=function(t,e){var i;return void 0===e&&(e=!0),null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)},t.prototype.createTextureFromImage=function(t,e){void 0===e&&(e=!0);var i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i},t.prototype.getOrCreateTextureFromCanvas=function(t,e,i){var n;return void 0===i&&(i=!0),null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)},t.prototype.createTextureFromCanvas=function(t,e,i){void 0===i&&(i=!0);var n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n},t}(),X=function(){function t(t,e,i){this.gl=i.getContext(e),this.programFactory=t,this.contextVersion=e}return t.prototype.loadProgram=function(){this.program=this.contextVersion===G.WebGL2?this.programFactory.create(this.gl,"#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(this.gl,"precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)},t}(),Z=function(){function t(){this.bitmapSize=64,this.fontAtlas=new Map,this.loading=new Map}return t.prototype.hasFontAtlas=function(t){return this.fontAtlas.has(Symbol.for(t))},t.prototype.loadingFontAtlas=function(t){var e;return null!==(e=this.loading.get(Symbol.for(t)))&&void 0!==e&&e},t.prototype.getFontAtlas=function(t){return this.fontAtlas.get(Symbol.for(t))},t.prototype.asyncCreate=function(t,e,i,n){var r=this;void 0===i&&(i=null),void 0===n&&(n=null),this.bitmapSize=null!=n?n:this.bitmapSize;var o=new K(e);this.chars=[];for(var a=0;a<t.length;a+=2)for(var s=t[a];s<=t[a+1];s++)this.chars.push(String.fromCharCode(s));o.canvas.width=Math.round(Math.sqrt(this.chars.length))*this.bitmapSize,o.canvas.height=o.canvas.width,null!==i?this.loadFont(e,i).then((function(){return r.renderAtlas(o,e)})):this.renderAtlas(o,e)},t.prototype.loadFont=function(t,e){return h(this,void 0,void 0,(function(){var i;return l(this,(function(n){switch(n.label){case 0:return this.loading.set(Symbol.for(t),!0),[4,(i=new FontFace(t,"url("+e+")")).load()];case 1:return n.sent(),document.fonts.add(i),this.loading.set(Symbol.for(t),!1),[2]}}))}))},t.prototype.renderAtlas=function(t,e){var i=t.canvas.getContext("2d");i.clearRect(0,0,t.canvas.width,t.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font=this.bitmapSize+"px "+e;for(var n=0,r=0,o=0;o<this.chars.length;o++)i.fillText(this.chars[o],n,r),t.glyphsData.set(this.chars[o],{x:n,y:r,width:this.bitmapSize,height:this.bitmapSize}),(n+=this.bitmapSize)>t.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);this.fontAtlas.set(Symbol.for(e),t)},t}(),K=function(t){this.canvas=document.createElement("canvas"),this.glyphsData=new Map,this.name=t},$=function(){function t(t,i,n){this.posVertices=[],this.texVertices=[],this.posVerticesSize=new e,this.lastTexture=null,this.gl=i.getContext(t),this.programManager=n,this.projectionMatrix=D(),this.modelMatrix=D(),this.textureMatrix=D()}return t.prototype.render=function(t,e,i,n,r){if(n.text){this.generateTextVertices(i,n),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=A(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,this.getTranslationForOrientation(n)),V(this.modelMatrix,this.modelMatrix,n.rotation),this.textureMatrix=A(this.textureMatrix),B(this.textureMatrix,this.textureMatrix,[1/i.canvas.width,1/i.canvas.height,1]),this.projectionMatrix=A(this.projectionMatrix),F(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),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),n.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.lastTexture===e&&"text"===r||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,n.opacity);var o=I(n.color),a=o.r,s=o.g,h=o.b,l=o.a;this.gl.uniform4f(this.programManager.maskColorUniform,a,s,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)}},t.prototype.generateTextVertices=function(t,e){this.posVertices=[],this.texVertices=[];for(var i=this.getDimensions(e),n={x1:-i.width/2,y1:i.height/2-e.fontSize,x2:0,y2:i.height/2},r={x1:0,y1:0,x2:0,y2:0},o=0;o<e.text.length;o++){var a=e.text[o];if("\n"!==a)if(" "!==a){var s=t.glyphsData.get(a);s&&(n.x2=n.x1+e.fontSize,r.x1=s.x+e.bitmapOffset.x,r.y1=s.y+e.bitmapOffset.y,r.x2=s.x+s.width-1,r.y2=s.y+s.height-1,this.posVertices.push(n.x1,n.y1,n.x2,n.y1,n.x1,n.y2,n.x1,n.y2,n.x2,n.y1,n.x2,n.y2),this.texVertices.push(r.x1,r.y2,r.x2,r.y2,r.x1,r.y1,r.x1,r.y1,r.x2,r.y2,r.x2,r.y1)),n.x1+=e.fontSize+e.letterSpacing}else n.x1+=e.fontSize+e.letterSpacing;else n.y1-=e.fontSize+e.lineSeparation,n.y2=n.y1+e.fontSize,n.x1=-i.width/2}this.posVerticesSize.set(i.width,i.height)},t.prototype.getTranslationForOrientation=function(t){return[t.positionInViewport.x+("center"===t.orientation?0:this.posVerticesSize.x/2),t.positionInViewport.y+("rightDown"===t.orientation?-this.posVerticesSize.y/2:"rightUp"===t.orientation?this.posVerticesSize.y:0),0]},t.prototype.getDimensions=function(t){return t.text.split("\n").reduce((function(e,i,n){return e.width=Math.max(e.width,i.length*(t.fontSize+t.letterSpacing)),e.height+=t.fontSize+Math.min(n,1)*t.lineSeparation,e}),{width:0,height:0})},t}(),J=function(){function t(t,e,i){this.vertices=new Map,this.texVertices=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),this.lastVertices=null,this.lastRender=null,this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=D(),this.modelMatrix=D(),this.textureMatrix=D()}return t.prototype.renderCollider=function(t,e,i){this.lastRender=i,e.shape.type===u.Rectangle&&this.renderRectangle(t,e.positionInViewport,{width:e.shape.width,height:e.shape.height},e.color,e.shape.angle)},t.prototype.renderGeometric=function(t,e,i){this.lastRender=i,"Rectangle"===e.geometricType&&this.renderRectangle(t,e.positionInViewport,{width:e.getGeometric().width,height:e.getGeometric().height},e.color)},t.prototype.renderRectangle=function(t,e,i,n,r){void 0===r&&(r=0);var o=Symbol.for("RW"+i.width+"H"+i.height);!1===this.vertices.has(o)&&this.vertices.set(o,new Float32Array(this.generateRectangleVertices(i.width,i.height,1)));var a=this.vertices.get(o);this.lastVertices===o&&"geometric"===this.lastRender||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,a,this.gl.DYNAMIC_DRAW)),this.lastVertices=o,"geometric"!==this.lastRender&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.DYNAMIC_DRAW)),this.modelMatrix=A(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[e.x,e.y,0]),V(this.modelMatrix,this.modelMatrix,r),this.projectionMatrix=A(this.projectionMatrix),F(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var s=I(n),h=s.r,l=s.g,c=s.b,u=s.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,l,c,u),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,a.length/2)},t.prototype.generateRectangleVertices=function(t,e,i){var n=e/2,r=t/2;return c(c(c(c([],this.generateLineVertices(-r,-n,r,-n+i),!0),this.generateLineVertices(r-i,-n,r,n),!0),this.generateLineVertices(-r,n-i,r,n),!0),this.generateLineVertices(-r,-n,-r+i,n),!0)},t.prototype.generateLineVertices=function(t,e,i,n){return[t,e,i,e,t,n,t,n,i,e,i,n]},t}(),tt=function(){function t(t,i){this._displacementDirection=new e,this._penetration=t,this._displacementDirection.set(i.x,i.y)}return Object.defineProperty(t.prototype,"penetration",{get:function(){return this._penetration},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"displacementDirection",{get:function(){return this._displacementDirection},enumerable:!1,configurable:!0}),t}(),et=function(){function t(){this.proj1={min:0,max:0},this.proj2={min:0,max:0}}return t.prototype.getCollisionData=function(t,i){this.currentOverlap=null,this.minOverlap=null,this.displaceDirection=null,this.axes=c(c([],t.getAxes(),!0),i.getAxes(),!0);for(var n=0;n<this.axes.length;n++){if(this.projectShapeOntoAxis(this.proj1,this.axes[n],t),this.projectShapeOntoAxis(this.proj2,this.axes[n],i),this.currentOverlap=Math.min(this.proj1.max,this.proj2.max)-Math.max(this.proj1.min,this.proj2.min),this.currentOverlap<0)return null;this.preventContainment(n),(this.currentOverlap<this.minOverlap||null===this.minOverlap)&&(this.minOverlap=this.currentOverlap,this.displaceDirection=this.axes[n],this.proj1.max<this.proj2.max&&e.scale(this.displaceDirection,this.displaceDirection,-1))}return new tt(this.minOverlap,this.displaceDirection)},t.prototype.projectShapeOntoAxis=function(t,i,n){return t.min=e.dot(i,n.vertices[0]),t.max=t.min,n.vertices.forEach((function(n){t.min=Math.min(e.dot(i,n),t.min),t.max=Math.max(e.dot(i,n),t.max)})),t},t.prototype.preventContainment=function(t){if(this.proj1.max>this.proj2.max&&this.proj1.min<this.proj2.min||this.proj1.max<this.proj2.max&&this.proj1.min>this.proj2.min){var i=Math.abs(this.proj1.min-this.proj2.min),n=Math.abs(this.proj1.max-this.proj2.max);i<n?this.currentOverlap+=i:(this.currentOverlap+=n,e.scale(this.axes[t],this.axes[t],-1))}},t}(),it=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}(),nt=function(){function t(){this.shape1Rect=new i(0,0,0,0),this.shape2Rect=new i(0,0,0,0),this.displaceDirection=new e}return t.prototype.getCollisionData=function(t,e){return this.setShapeRect(t,this.shape1Rect),this.setShapeRect(e,this.shape2Rect),this.overlapX=Math.min(this.shape1Rect.x1,this.shape2Rect.x1)-Math.max(this.shape1Rect.x,this.shape2Rect.x),this.overlapY=Math.min(this.shape1Rect.y1,this.shape2Rect.y1)-Math.max(this.shape1Rect.y,this.shape2Rect.y),this.overlapX<0||this.overlapY<0?null:(this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displaceDirection.set(0,Math.sign(this.shape1Rect.y1-this.shape2Rect.y1)),this.preventContainment(this.shape1Rect.y,this.shape2Rect.y,this.shape1Rect.y1,this.shape2Rect.y1)):(this.minOverlap=this.overlapX,this.displaceDirection.set(Math.sign(this.shape1Rect.x1-this.shape2Rect.x1),this.overlapY===this.overlapX?Math.sign(this.shape1Rect.y1-this.shape2Rect.y1):0),this.preventContainment(this.shape1Rect.x,this.shape2Rect.x,this.shape1Rect.x1,this.shape2Rect.x1)),new tt(this.minOverlap,this.displaceDirection))},t.prototype.setShapeRect=function(t,e){e.set(t.position.x-t.width/2,t.position.y-t.height/2,t.width,t.height)},t.prototype.preventContainment=function(t,i,n,r){if(t>n&&i<r||n>t&&r<i){var o=Math.abs(t-n),a=Math.abs(i-r);o<a?this.minOverlap+=o:(this.minOverlap+=a,e.scale(this.displaceDirection,this.displaceDirection,-1))}},t}(),rt=function(){function t(){}return t.prototype.applyCulling=function(t,e){var i=this;return e.filter((function(e){if(!1===t.layers.includes(e.layer))return!1;var n=e.ui?t.viewportRect:t.worldSpaceRect;switch(e.type){case O.Image:return i.cullSprite(n,e);case O.Tilemap:return i.cullTilemap(n,e);case O.Collider:return i.cullCollider(n,e);case O.Geometric:return i.cullGeometric(n,e);case O.Text:return i.cullText(n,e);case O.Mask:return i.cullSprite(n,e)}}))},t.prototype.cullSprite=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.width/2,x1:e.position.x+e.width/2,y:e.position.y-e.height/2,y1:e.position.y+e.height/2})},t.prototype.cullTilemap=function(t,e){var i=this;return e.tilesToRender=e.tilesData.filter((function(n){return i.isTargetVisible(t,{x:n.position.x-e.tileWidth/2,x1:n.position.x+e.tileWidth/2,y:n.position.y-e.tileHeight/2,y1:n.position.y+e.tileHeight/2})})),e.tilesData.length>0},t.prototype.cullCollider=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.shape.width/2,x1:e.position.x+e.shape.width/2,y:e.position.y-e.shape.height/2,y1:e.position.y+e.shape.height/2})},t.prototype.cullGeometric=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.geometric.width/2,x1:e.position.x+e.geometric.width/2,y:e.position.y-e.geometric.height/2,y1:e.position.y+e.geometric.height/2})},t.prototype.cullText=function(t,e){return this.isTargetVisible(t,{x:e.position.x-e.width/2,x1:e.position.x+e.width/2,y:e.position.y-e.height/2,y1:e.position.y+e.height/2})},t.prototype.isTargetVisible=function(t,e){return t.x1>=e.x&&t.x<=e.x1&&t.y1>=e.y&&t.y<=e.y1},t}(),ot=function(){function t(t,e,i){this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.p={x1:0,y1:0,x2:0,y2:0},this.t={x1:0,y1:0,x2:0,y2:0},this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=D(),this.modelMatrix=D(),this.textureMatrix=D()}return t.prototype.render=function(t,e,i,n){if(this.generateVertices(i),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=A(this.modelMatrix),this.textureMatrix=A(this.textureMatrix),B(this.textureMatrix,this.textureMatrix,[1/i.image.naturalWidth,1/i.image.naturalHeight,1]),this.projectionMatrix=A(this.projectionMatrix),F(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND),this.lastTexture===e&&"tilemap"===n||(this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=e),this.gl.uniform1i(this.programManager.useMaskColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,i.alpha),this.gl.uniform1i(this.programManager.useTintColorUniform,i.tintColor?1:0),i.tintColor){var r=I(i.tintColor),o=r.r,a=r.g,s=r.b,h=r.a;this.gl.uniform4f(this.programManager.tintColorUniform,o,a,s,h)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.generateVertices=function(t){var e=this;this.posVertices=[],this.texVertices=[],t.tilesToRender.forEach((function(i){var n,r;e.p.x1=i.positionInViewport.x-t.tileWidth/2,e.p.x2=i.positionInViewport.x+t.tileWidth/2,e.p.y1=i.positionInViewport.y-t.tileHeight/2,e.p.y2=i.positionInViewport.y+t.tileHeight/2,e.posVertices.push(e.p.x1,e.p.y1,e.p.x2,e.p.y1,e.p.x1,e.p.y2,e.p.x1,e.p.y2,e.p.x2,e.p.y1,e.p.x2,e.p.y2),e.t.x1=i.tile.x,e.t.y1=i.tile.y,e.t.x2=i.tile.x+i.tile.width-(null!==(n=t.textureCorrection)&&void 0!==n?n:0),e.t.y2=i.tile.y+i.tile.height-(null!==(r=t.textureCorrection)&&void 0!==r?r:0),e.texVertices.push(e.t.x1,e.t.y2,e.t.x2,e.t.y2,e.t.x1,e.t.y1,e.t.x1,e.t.y1,e.t.x2,e.t.y2,e.t.x2,e.t.y1)}))},t}(),at="angry-pixel-start",st="angry-pixel-update",ht="angry-pixel-update-engine",lt="angry-pixel-update-collider",ct="angry-pixel-update-physics",ut="angry-pixel-update-transform",pt="angry-pixel-update-prerender",dt="angry-pixel-update-camera",ft="angry-pixel-update-render",gt=function(){function t(t,e,i,n){this.timeManager=t,this.collisionManager=e,this.renderManager=i,this.inputManager=n,this.gameLoopAccumulator=0,this.physicsLoopAccumulator=0,this.deltaAux=0}return t.prototype.update=function(t){for(this.timeManager.update(t),this.deltaAux=Math.min(this.timeManager.browserDeltaTime,this.timeManager.maxGameDeltatime),this.gameLoopAccumulator+=this.deltaAux,this.physicsLoopAccumulator+=this.timeManager.browserDeltaTime,this.timeManager.unscaledGameDeltaTime=Math.max(this.timeManager.maxGameDeltatime,this.timeManager.browserDeltaTime),this.timeManager.unscaledPhysicsDeltaTime=this.timeManager.maxPhysicsDeltaTime,this.gameLoopAccumulator>this.timeManager.maxGameDeltatime&&(this.mainIteration(),this.gameLoopAccumulator-=this.timeManager.maxGameDeltatime);this.physicsLoopAccumulator>this.timeManager.maxPhysicsDeltaTime;)this.timeManager.timeScale>0&&this.physicsIteration(),this.physicsLoopAccumulator-=this.timeManager.maxPhysicsDeltaTime;this.preRenderIteration(),this.renderIteration()},t.prototype.mainIteration=function(){this.dispatchFrameEvent(at),this.inputManager.update(),this.dispatchFrameEvent(st),this.dispatchFrameEvent(ht),this.dispatchFrameEvent(ut),this.dispatchFrameEvent(lt),this.collisionManager.update()},t.prototype.physicsIteration=function(){this.dispatchFrameEvent(ct),this.dispatchFrameEvent(lt)},t.prototype.preRenderIteration=function(){this.dispatchFrameEvent(ut),this.dispatchFrameEvent(pt),this.dispatchFrameEvent(dt)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(ft),this.renderManager.clearCanvas(),this.renderManager.render()},t.prototype.dispatchFrameEvent=function(t){window.dispatchEvent(new CustomEvent(t))},t}(),mt=function(){function t(){}return t.initialize=function(t){this.assetManager=t},t.getAssetsLoaded=function(){return this.assetManager.getAssetsLoaded()},t.loadImage=function(t){return this.assetManager.laadImage(t)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.assetManager=null,t}(),yt=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}(),bt=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}(),xt=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}(),vt=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}),t.timeManager=null,t}(),_t=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i){return void 0===i&&(i=null),this.manager.addGameObject(t,e,i)},t.getGameObjects=function(){return this.manager.getGameObjects()},t.findGameObjectByName=function(t){return this.manager.findGameObjectByName(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParentAndName=function(t,e){return this.manager.findGameObjectByParentAndName(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.findGameObjectByTag=function(t){return this.manager.findGameObjectByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t}(),wt=function(){function t(t,e,i){this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl=e.getContext(t),this.programManager=i,this.projectionMatrix=D(),this.modelMatrix=D(),this.textureMatrix=D()}return t.prototype.render=function(t,e,i){"mask"!==i&&(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=A(this.modelMatrix),E(this.modelMatrix,this.modelMatrix,[e.positionInViewport.x,e.positionInViewport.y,0]),V(this.modelMatrix,this.modelMatrix,e.rotation),B(this.modelMatrix,this.modelMatrix,[e.width,e.height,1]),this.projectionMatrix=A(this.projectionMatrix),F(this.projectionMatrix,t.x,t.x1,t.y,t.y1,-1,1),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),e.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);var n=I(e.color),r=n.r,o=n.g,a=n.b,s=n.a;this.gl.uniform4f(this.programManager.solidColorUniform,r,o,a,s),this.gl.uniform1f(this.programManager.alphaUniform,e.alpha),this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),Mt=function(e,i){if(i.collisions.method===t.CollisionMethodConfig.AABB)e.add("CollisionResolver",(function(){return new nt}));else{if(i.collisions.method!==t.CollisionMethodConfig.SAT)throw new g("Invalid collision method.");e.add("CollisionResolver",(function(){return new et}))}e.add("CollisionManager",(function(){return new y(e.getSingleton("CollisionResolver"),i.collisions.quadTreeBounds,i.collisions.quadMaxLevel,i.collisions.collidersPerQuad)}))},Ct=function(e,i,n){var r=jt();if(i.context2d===t.Context2DConfig.Default||i.context2d===t.Context2DConfig.Fallback&&null===r)e.add("Renderer",(function(){return new P(n.canvas)})),i.debugEnabled&&console.log("Using 2d rendering context");else{if(null===r)throw new g("WebGL is not supported, use context2d instead.");Ot(r,e,n),i.debugEnabled&&console.log("Using WebGL rendering context (version: "+r+")")}e.add("FontAtlasFactory",(function(){return new Z})),e.add("CullingService",(function(){return new rt})),e.add("RenderManager",(function(){return new T(e.getSingleton("Renderer"),e.getSingleton("CullingService"),i.canvasColor,i.debugEnabled)}))},Ot=function(t,e,i){e.add("ShaderLoader",(function(){return new U})),e.add("ProgramFactory",(function(){return new k(e.getSingleton("ShaderLoader"))})),e.add("ProgramManager",(function(){return new X(e.getSingleton("ProgramFactory"),t,i.canvas)})),e.add("TextureFactory",(function(){return new H(t,i.canvas)})),e.add("TextureManager",(function(){return new Q(e.getSingleton("TextureFactory"))})),e.add("WebGLImageRenderer",(function(){return new L(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLTextRenderer",(function(){return new $(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLGeometricRenderer",(function(){return new J(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLTilemapRenderer",(function(){return new ot(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("WebGLMaskRenderer",(function(){return new wt(t,i.canvas,e.getSingleton("ProgramManager"))})),e.add("Renderer",(function(){return new N(t,i.canvas,e.getSingleton("ProgramManager"),e.getSingleton("TextureManager"),e.getSingleton("FontAtlasFactory"),e.getSingleton("WebGLImageRenderer"),e.getSingleton("WebGLTilemapRenderer"),e.getSingleton("WebGLTextRenderer"),e.getSingleton("WebGLGeometricRenderer"),e.getSingleton("WebGLMaskRenderer"))}))},Rt=function(t,e){t.add("Mouse",(function(){return new C(e.canvas)})),t.add("Keyboard",(function(){return new M(e.canvas)})),t.add("Gamepad",(function(){return new v})),t.add("Touch",(function(){return new it(e.canvas)})),t.add("InputManager",(function(){return new w(t.getSingleton("Mouse"),t.getSingleton("Keyboard"),t.getSingleton("Gamepad"),t.getSingleton("Touch"))}))},jt=function(){return null!==document.createElement("canvas").getContext(G.WebGL2)?G.WebGL2:null!==document.createElement("canvas").getContext(G.LegacyWebGL)?G.LegacyWebGL:null},Pt=function(t){mt.initialize(t.getSingleton("AssetManager")),yt.initialize(t.getSingleton("DomManager")),bt.initialize(t.getSingleton("InputManager")),xt.initialize(t.getSingleton("SceneManager")),vt.initialize(t.getSingleton("TimeManager")),_t.initialize(t.getSingleton("GameObjectManager"))},Tt=new(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 g("There is already an object constructor with the name "+t);this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new g("Invalid object constructor name: "+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 g("Invalid object constructor name: "+t);return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new g("There is already a constant value with the name "+t);this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new g("Invalid constant name: "+t);return this.constants.get(t)},t}());t.Context2DConfig=void 0,(z=t.Context2DConfig||(t.Context2DConfig={})).Default="default",z.Disabled="disabled",z.Fallback="fallback",t.CollisionMethodConfig=void 0,(W=t.CollisionMethodConfig||(t.CollisionMethodConfig={})).AABB="aabb",W.SAT="sat";var St,Dt={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",context2d:t.Context2DConfig.Fallback,spriteDefaultScale:null,gameFrameRate:60,physicsFramerate:240,collisions:{method:t.CollisionMethodConfig.AABB,quadTreeBounds:null,quadMaxLevel:6,collidersPerQuad:15}},At=function(){function t(t){var e=this;this._running=!1,this._stop=!1,this.frameRequestId=null,this.errorEventHandler=function(t){t.error.name===f&&(e.stop(),t.stopPropagation(),t.preventDefault(),console.error(t.error.message+"\n"+t.filename+":"+t.lineno))},this._config=s(s({},Dt),t),this._config.collisions=s(s({},Dt.collisions),t.collisions),window.addEventListener("error",this.errorEventHandler),Tt.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){!function(t,e){t.addConstant("GameConfig",e),t.add("DomManager",(function(){return new b(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager");Ct(t,e,i),Rt(t,i),Mt(t,e),t.add("SceneManager",(function(){return new q(t.getConstant("Game"),t.getSingleton("RenderManager"))})),t.add("GameObjectManager",(function(){return new x})),t.add("AssetManager",(function(){return new d})),t.add("TimeManager",(function(){return new Y(e.gameFrameRate,e.physicsFramerate)})),t.add("IterationManager",(function(){return new gt(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"))})),Pt(t)}(Tt,this._config),this.renderManager=Tt.getSingleton("RenderManager"),this.sceneManager=Tt.getSingleton("SceneManager"),this.iterationManager=Tt.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._running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i){void 0===i&&(i=!1),this.sceneManager.addScene(t,e,i)},t.prototype.run=function(){this.sceneManager.loadOpeningScene(),this.requestAnimationFrame()},t.prototype.stop=function(){this.pauseLoop(),this.sceneManager.unloadCurrentScene(),this.renderManager.clearCanvas()},t.prototype.gameLoop=function(t){!0!==this._stop&&(this._running=!0,this.iterationManager.update(t),this.requestAnimationFrame())},t.prototype.pauseLoop=function(){this._stop=!0,this._running=!1,null!==this.frameRequestId&&(window.cancelAnimationFrame(this.frameRequestId),this.frameRequestId=null)},t.prototype.resumeLoop=function(){0==this._running&&null===this.frameRequestId&&(this._stop=!1,this.requestAnimationFrame())},t.prototype.requestAnimationFrame=function(){var t=this;this.frameRequestId=window.requestAnimationFrame((function(e){return t.gameLoop(e)}))},t}(),Et=function(){var t=(new Date).getTime(),e=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)}))},Bt=function(){function t(){var t=this;this.sceneManager=Tt.getSingleton("SceneManager"),this.gameObjectManager=Tt.getSingleton("GameObjectManager"),this.id=Et(),this.allowMultiple=!0,this.type=null,this.name=null,this.gameObject=null,this._active=!0,this.started=!1,this.gameLoopEventHandler=function(e){if(!1!==t._active)try{t.started||e.type!==at?t.started&&e.type===t.updateEvent&&t.update():(t.start(),t.started=!0)}catch(t){throw t.name===f?t:new g(t.message)}},window.addEventListener(at,this.gameLoopEventHandler),window.addEventListener(this.updateEvent,this.gameLoopEventHandler)}return Object.defineProperty(t.prototype,"updateEvent",{get:function(){return st},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"active",{get:function(){return this._active},enumerable:!1,configurable:!0}),t.prototype.setActive=function(t){this._active=t},t.prototype.init=function(){},t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.getComponentByName=function(t){return this.gameObject.getComponentByName(t)},t.prototype.getComponentByType=function(t){return this.gameObject.getComponentByType(t)},t.prototype.getComponentsByType=function(t){return this.gameObject.getComponentsByType(t)},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.hasComponentOfName=function(t){return null!==this.getComponentByName(t)},t.prototype.hasComponentOfType=function(t){return null!==this.getComponentByType(t)},t.prototype.removeComponentByName=function(t){this.gameObject.removeComponentByName(t)},t.prototype.removeComponentByType=function(t){this.gameObject.removeComponentByType(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(at,this.gameLoopEventHandler),window.removeEventListener(this.updateEvent,this.gameLoopEventHandler),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),Vt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return ht},enumerable:!1,configurable:!0}),e}(Bt),Ft=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return lt},enumerable:!1,configurable:!0}),e}(Bt),Gt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return ct},enumerable:!1,configurable:!0}),e}(Bt),It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return ut},enumerable:!1,configurable:!0}),e}(Bt),Lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return pt},enumerable:!1,configurable:!0}),e}(Bt),kt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return dt},enumerable:!1,configurable:!0}),e}(Bt),Ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"updateEvent",{get:function(){return ft},enumerable:!1,configurable:!0}),e}(Bt),Ht={Animator:"Animator",AudioPlayer:"AudioPlayer",Camera:"camera",RigidBody:"RigidBody",Transform:"Transform",BoxCollider:"BoxCollider",TilemapCollider:"TilemapCollider",CsvTilemapRenderer:"CsvTilemapRenderer",SpriteRenderer:"SpriteRenderer",TextRenderer:"TextRenderer",TiledTilemapRenderer:"TiledTilemapRenderer",MaskRenderer:"MaskRenderer"},zt=function(t){function i(){var i=t.call(this)||this;return i._position=new e,i._scale=new e(1,1),i._rotation=new n,i._innerPosition=new e,i._parent=null,i.parentScale=!0,i.parentRotation=!0,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.scaledInnerPosition=new e,i.allowMultiple=!1,i.type=Ht.Transform,i}return o(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&&this.updateInnerPositionFromParent()},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent?(!1===this.lastPosition.equals(this._position)&&this.updateInnerPositionFromParent(),this.setPositionFromParent()):this._innerPosition.copy(this._position),this.lastPosition.copy(this._position)},i.prototype.updateInnerPositionFromParent=function(){e.subtract(this._innerPosition,this._position,this._parent.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.updateScaledInnerPosition(),e.add(this._position,this._parent.position,this.scaledInnerPosition)):this._position.copy(this._parent.position),this._rotation.radians=this.parentRotation?this._parent.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}(It),Wt="Default",Nt=function(){function t(){var t=this;this.id=Et(),this.name=null,this.tag=null,this.layer=Wt,this.ui=!1,this.keep=!1,this._active=!0,this._parent=null,this.started=!1,this.sceneManager=Tt.getSingleton("SceneManager"),this.gameObjectManager=Tt.getSingleton("GameObjectManager"),this.components=[],this.inactiveComponents=[],this.inactiveChildren=[],this.gameLoopEventHandler=function(e){if(!1!==t._active)try{t.started||e.type!==at?t.started&&e.type===st&&t.update():(t.start(),t.started=!0)}catch(t){throw t.name===f?t:new g(t.message)}},this.addComponent((function(){return new zt})),window.addEventListener(at,this.gameLoopEventHandler),window.addEventListener(st,this.gameLoopEventHandler)}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.getComponentByType(Ht.Transform)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"active",{get:function(){return this._active},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=t?t.transform:null},enumerable:!1,configurable:!0}),t.prototype.init=function(){},t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.addComponent=function(t,e){void 0===e&&(e=null);var i=t();return this.checkMultipleComponent(i),i.name=e,i.gameObject=this,i.init(),this.components.push(i),i},t.prototype.checkMultipleComponent=function(t){if(!1===t.allowMultiple&&this.hasComponentOfType(t.type))throw new g("GameObject only allows one component of type "+t.type)},t.prototype.getComponents=function(){return this.components},t.prototype.getComponentByName=function(t){return this.components.reduce((function(e,i){return i.name===t?i:e}),null)},t.prototype.getComponentByType=function(t){return this.components.reduce((function(e,i){return i.type===t?i:e}),null)},t.prototype.getComponentsByType=function(t){return this.components.filter((function(e){return e.type===t}))},t.prototype.hasComponentOfName=function(t){return null!==this.getComponentByName(t)},t.prototype.hasComponentOfType=function(t){return null!==this.getComponentByType(t)},t.prototype.removeComponentByName=function(t){var e=this;this.components.every((function(i,n){if(i.name===t)return i.destroy(),delete e.components[n],!1}))},t.prototype.removeComponentByType=function(t){var e=this;this.components.every((function(i,n){if(i.type===t)return i.destroy(),delete e.components[n],!1}))},t.prototype.removeComponents=function(){var t=this;this.components.every((function(e,i){return e.destroy(),delete t.components[i]})),this.components=[]},t.prototype.addChild=function(t,e){return this.gameObjectManager.addGameObject(t,e,this)},t.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},t.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParentAndName(this,t)},t.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},t.prototype.setActive=function(t){var e=this;!1===t&&this.updateInactiveCache(),this.components.filter((function(t){return-1===e.inactiveComponents.indexOf(t.id)})).forEach((function(e){return e.setActive(t)})),this.getChildren().filter((function(t){return-1===e.inactiveChildren.indexOf(t.id)})).forEach((function(e){return e.setActive(t)})),this._active=t},t.prototype.updateInactiveCache=function(){var t=this;this.inactiveComponents=[],this.inactiveChildren=[],this.components.filter((function(t){return!1===t.active})).forEach((function(e){return t.inactiveComponents.push(e.id)})),this.getChildren().filter((function(t){return!1===t.active})).forEach((function(e){return t.inactiveChildren.push(e.id)}))},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(at,this.gameLoopEventHandler),window.removeEventListener(st,this.gameLoopEventHandler),this.removeComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),qt=function(){this.depth=0,this.layers=[],this.originalViewportRect=null,this.viewportRect=null,this.worldSpaceRect=null,this.zoom=0},Yt=[Wt],Qt=function(t){function e(){var e=t.call(this)||this;return e.renderManager=Tt.getSingleton("RenderManager"),e.domManager=Tt.getSingleton("DomManager"),e._layers=Yt,e._depth=0,e._zoom=1,e._originalViewportRect=new i(0,0,0,0),e._viewportRect=new i(0,0,0,0),e._worldSpaceRect=new i(0,0,0,0),e.cameraData=new qt,e.allowMultiple=!1,e.type=Ht.Camera,e.canvas=e.domManager.canvas,e}return o(e,t),Object.defineProperty(e.prototype,"layers",{get:function(){return this._layers},set:function(t){this._layers=c(c([],Yt,!0),t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this._depth},set:function(t){this._depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new g("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"originalViewportRect",{get:function(){return this._originalViewportRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this._worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this._viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this._layers.push(t)},e.prototype.update=function(){this.updateOriginalViewportRect(),this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},e.prototype.updateOriginalViewportRect=function(){this._originalViewportRect.x=-this.canvas.width/2,this._originalViewportRect.y=-this.canvas.height/2,this._originalViewportRect.width=this.canvas.width,this._originalViewportRect.height=this.canvas.height},e.prototype.updateViewportRect=function(){var t=1/this._zoom;this._viewportRect.x=this._originalViewportRect.x*t,this._viewportRect.y=this._originalViewportRect.y*t,this._viewportRect.width=this._originalViewportRect.width*t,this._viewportRect.height=this._originalViewportRect.height*t},e.prototype.updateWorldSpaceRect=function(){this._worldSpaceRect.x=this.gameObject.transform.position.x-this._viewportRect.width/2,this._worldSpaceRect.y=this.gameObject.transform.position.y-this._viewportRect.height/2,this._worldSpaceRect.width=this._viewportRect.width,this._worldSpaceRect.height=this._viewportRect.height},e.prototype.updateCameraData=function(){this.cameraData.depth=this._depth,this.cameraData.layers=this._layers,this.cameraData.originalViewportRect=this._originalViewportRect,this.cameraData.viewportRect=this._viewportRect,this.cameraData.worldSpaceRect=this._worldSpaceRect,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},e}(kt),Xt=function(t){function e(){var e=t.call(this)||this;return e.transform.position.set(0,0),e.camera=e.addComponent((function(){return new Qt})),e}return o(e,t),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,"originalViewporRect",{get:function(){return this.camera.originalViewportRect},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}(Nt),Zt="GameCamera",Kt=function(){function t(){var t=this;this.gameObjectManager=Tt.getSingleton("GameObjectManager"),this.game=null,this.name=null,this.started=!1,this.gameLoopEventHandler=function(e){try{t.started||e.type!==at?t.started&&e.type===st&&t.update():(t.start(),t.started=!0)}catch(t){throw t.name===f?t:new g(t.message)}},window.addEventListener(at,this.gameLoopEventHandler),window.addEventListener(st,this.gameLoopEventHandler),this.addGameObject((function(){return new Xt}),Zt)}return Object.defineProperty(t.prototype,"gameCamera",{get:function(){return this.findGameObjectByName(Zt)},enumerable:!1,configurable:!0}),t.prototype.init=function(){},t.prototype.start=function(){},t.prototype.update=function(){},t.prototype.addGameObject=function(t,e){return this.gameObjectManager.addGameObject(t,e)},t.prototype.getGameObjects=function(){return this.gameObjectManager.getGameObjects()},t.prototype.findGameObjectByName=function(t){return this.gameObjectManager.findGameObjectByName(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.findGameObjectByTag=function(t){return this.gameObjectManager.findGameObjectByTag(t)},t.prototype.destroyGameObjectByName=function(t){this.destroyGameObject(this.findGameObjectByName(t))},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t.prototype.destroy=function(){var t=this;window.removeEventListener(at,this.gameLoopEventHandler),window.removeEventListener(st,this.gameLoopEventHandler),this.gameObjectManager.destroyAllGameObjects(),Object.keys(this).forEach((function(e){return delete t[e]}))},t}(),$t=function(t){function i(i,n,r,o){void 0===o&&(o=0);var a=t.call(this)||this;return a.cacheVector=new e,a.axes=[],a._type=u.Rectangle,a._position.set(i.x,i.y),a._width=n,a._height=r,a._angle=o,a._model=[new e(-n/2,-r/2),new e(-n/2,r/2),new e(n/2,r/2),new e(n/2,-r/2)],a._vertices=[new e,new e,new e,new e],a.axes=[new e,new e],a.update(),a}return o(i,t),i.prototype.update=function(){this.updateModel();for(var t=0;t<this._model.length;t++)this._vertices[t].set(this._model[t].x*Math.cos(this._angle)-this._model[t].y*Math.sin(this._angle)+this._position.x,this._model[t].x*Math.sin(this._angle)+this._model[t].y*Math.cos(this._angle)+this._position.y);this.updateDirection(),this.updateAxes()},i.prototype.updateModel=function(){this._model[0].set(-this._width/2,-this._height/2),this._model[1].set(-this._width/2,this._height/2),this._model[2].set(this._width/2,this._height/2),this._model[3].set(this._width/2,-this._height/2)},i.prototype.updateDirection=function(){e.unit(this._direction,e.subtract(this.cacheVector,this._vertices[1],this._vertices[0]))},i.prototype.updateAxes=function(){e.normal(this.axes[0],this._direction),this.axes[1].set(this._direction.x,this._direction.y)},i.prototype.clone=function(){return new i(this._position,this._width,this._height,this._angle)},i.prototype.getAxes=function(){return this.axes},i}(R),Jt=function(){function t(t,i,n,r,o,a){void 0===a&&(a=0),this._position=new e,this._width=0,this._height=0,this._angle=0,this._quadMaxBounds=new e,this._quadMinBounds=new e,this._position.set(t.x,t.y),this._quadVertices=[new e,new e,new e,new e],this._width=i,this._height=n,this._angle=a,this.gameObject=o,this.physics=r,this.shape=new $t(this._position,this._width,this._height),this.updateQuadVertices()}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y),this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t,this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t,this.updateShape(),this.updateQuadVertices()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomLeftQuadVertex",{get:function(){return this._quadVertices[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomRightQuadVertex",{get:function(){return this._quadVertices[3]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topLeftQuadVertex",{get:function(){return this._quadVertices[1]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topRightQuadVertex",{get:function(){return this._quadVertices[2]},enumerable:!1,configurable:!0}),t.prototype.updateShape=function(){this.shape.position=this._position,this.shape.width=this._width,this.shape.height=this.height,this.shape.angle=this._angle,this.shape.update()},t.prototype.updateQuadVertices=function(){var t=this;this._quadMaxBounds.set(this.shape.vertices[0].x,this.shape.vertices[0].y),this._quadMinBounds.set(this.shape.vertices[0].x,this.shape.vertices[0].y),this.shape.vertices.forEach((function(e){t._quadMaxBounds.set(Math.max(e.x,t._quadMaxBounds.x),Math.max(e.y,t._quadMaxBounds.y)),t._quadMinBounds.set(Math.min(e.x,t._quadMinBounds.x),Math.min(e.y,t._quadMinBounds.y))})),this._quadVertices[0].set(this._quadMinBounds.x,this._quadMinBounds.y),this._quadVertices[1].set(this._quadMinBounds.x,this._quadMaxBounds.y),this._quadVertices[2].set(this._quadMaxBounds.x,this._quadMaxBounds.y),this._quadVertices[3].set(this._quadMaxBounds.x,this._quadMinBounds.y)},t}(),te=function(t){function e(){var e=t.call(this)||this;return e.collisionManager=Tt.getSingleton("CollisionManager"),e.colliders=[],e._physics=!0,e.renderer=null,e.collisionsCache=[],e}return o(e,t),Object.defineProperty(e.prototype,"physics",{get:function(){return this._physics},enumerable:!1,configurable:!0}),e.prototype.addCollider=function(t){this.colliders.push(t),this.collisionManager.addCollider(t)},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){this.updatePosition();for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var a=o[r];if(a.remoteCollider.gameObject.layer===t)return a}return null},e.prototype.getCollisionsWithLayer=function(t){this.updatePosition(),this.collisionsCache=[];for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var a=o[r];a.remoteCollider.gameObject.layer===t&&this.collisionsCache.push(a)}return c([],this.collisionsCache,!0)},e.prototype.setActive=function(e){var i=this;!0===e&&!1===this.active?this.colliders.forEach((function(t){return i.collisionManager.addCollider(t)})):!1===e&&!0===this.active&&this.colliders.forEach((function(t){return i.collisionManager.removeCollider(t)})),this.renderer&&this.renderer.setActive(e),t.prototype.setActive.call(this,e)},e.prototype.destroy=function(){var e=this;this.colliders.forEach((function(t){return e.collisionManager.removeCollider(t)})),t.prototype.destroy.call(this)},e}(Ft),ee=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=O.Collider,e.color=null,e.shape=null,e}return o(e,t),e}(j),ie=function(i){function r(r){var o,a,s,h,l,c=i.call(this)||this;return c.debug=!1,c.offsetX=0,c.offsetY=0,c.realWidth=0,c.realHeight=0,c.realOffset=new e,c.realPosition=new e,c.realRotation=0,c.applyRotation=Tt.getConstant("GameConfig").collisions.method===t.CollisionMethodConfig.SAT,c.innerPosition=new e,c.type=Ht.BoxCollider,c.width=r.width,c.height=r.height,c.offsetX=null!==(o=r.offsetX)&&void 0!==o?o:c.offsetX,c.offsetY=null!==(a=r.offsetY)&&void 0!==a?a:c.offsetY,c._physics=null!==(s=r.physics)&&void 0!==s?s:c._physics,c.debug=(null!==(h=r.debug)&&void 0!==h?h:c.debug)&&Tt.getConstant("GameConfig").debugEnabled,c.rotation=null!==(l=r.rotation)&&void 0!==l?l:new n,c}return o(r,i),r.prototype.start=function(){var t=this;this.updateRealSize(),this.addCollider(new Jt(this.gameObject.transform.position,this.realWidth,this.realHeight,this._physics,this.gameObject,this.realRotation)),this.debug&&(this.renderer=this.gameObject.addComponent((function(){return new ne(t.colliders[0])})))},r.prototype.update=function(){this.updatePosition()},r.prototype.updatePosition=function(){this.updateRealSize(),this.colliders[0].width=this.realWidth,this.colliders[0].height=this.realHeight,this.colliders[0].position=e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.realRotation&&this.applyRotation&&(this.colliders[0].angle=this.realRotation),0!==this.gameObject.transform.rotation.radians&&this.translate()},r.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.gameObject.transform.rotation.radians+this.rotation.radians},r.prototype.translate=function(){e.subtract(this.innerPosition,this.colliders[0].position,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)),this.colliders[0].position=this.realPosition},r}(te),ne=function(t){function e(e){var i=t.call(this)||this;return i.renderManager=Tt.getSingleton("RenderManager"),i.type="BoxColliderRenderer",i.renderData=new ee,i.renderData.debug=!0,i.renderData.color="#00FF00",i.collider=e,i}return o(e,t),e.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position=this.collider.position,this.renderData.shape=this.collider.shape,this.renderManager.addRenderData(this.renderData)},e}(Ut),re=function(t){function i(i){var n,r=t.call(this)||this;return r.tilemapRenderer=null,r.debug=!1,r.needsCollider=function(t){r.cacheVertex[0].set(t.position.x,t.position.y+t.height),r.cacheVertex[1].set(t.position.x+t.width,t.position.y),r.cacheVertex[2].set(t.position.x,t.position.y-t.height),r.cacheVertex[3].set(t.position.x-t.width,t.position.y);for(var e=function(t){if(void 0===r.tilemapRenderer.tilesData.find((function(e){return e.position.equals(r.cacheVertex[t])})))return{value:!0}},i=0;i<r.cacheVertex.length;i++){var n=e(i);if("object"==typeof n)return n.value}return!1},r.type=Ht.TilemapCollider,r.tilemapRenderer=i.tilemapRenderer,r.debug=(null!==(n=i.debug)&&void 0!==n?n:r.debug)&&Tt.getConstant("GameConfig").debugEnabled,r._physics=!0,r.cacheVertex=[new e,new e,new e,new e],r}return o(i,t),i.prototype.start=function(){var t=this;this.tilemapRenderer.tilesData.filter(this.needsCollider).forEach((function(e){t.addCollider(new Jt(e.position,e.width,e.height,t._physics,t.gameObject))})),this.debug&&(this.renderer=this.gameObject.addComponent((function(){return new oe(t.colliders)})))},i.prototype.updatePosition=function(){},i}(te),oe=function(t){function e(e){var i=t.call(this)||this;return i.renderManager=Tt.getSingleton("RenderManager"),i.renderData=[],i.colliders=[],i.type="TilemapColliderRenderer",i.colliders=e,i.colliders.forEach((function(t,e){i.renderData[e]=new ee,i.renderData[e].debug=!0,i.renderData[e].color="#00FF00"})),i}return o(e,t),e.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].shape=e.shape,t.renderManager.addRenderData(t.renderData[i])}))},e}(Ut),ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=O.Image,e}return o(e,t),e}(j),se=function(t){function i(i){var r,o,a,s,h,l,c,u,p,d,f;void 0===i&&(i={sprite:null});var g=t.call(this)||this;return g.renderManager=Tt.getSingleton("RenderManager"),g.sprite=null,g.offset=new e,g.flipHorizontal=!1,g.flipVertical=!1,g.rotation=new n,g.smooth=!1,g.opacity=1,g._tiled=new e(1,1),g.maskColor=null,g.maskColorMix=0,g.tintColor=null,g.renderData=[],g.innerPosition=new e,g.cachePosition=new e,g.cacheRenderPosition=new e,g.scaledOffset=new e,g.type=Ht.SpriteRenderer,g.sprite=i.sprite,g.offset=null!==(r=i.offset)&&void 0!==r?r:g.offset,g.smooth=null!==(o=i.smooth)&&void 0!==o?o:g.smooth,g.rotation=null!==(a=i.rotation)&&void 0!==a?a:g.rotation,g.flipHorizontal=null!==(s=i.flipHorizontal)&&void 0!==s?s:g.flipHorizontal,g.flipVertical=null!==(h=i.flipVertical)&&void 0!==h?h:g.flipVertical,g.opacity=null!==(l=i.opacity)&&void 0!==l?l:g.opacity,g.tiled=null!==(c=i.tiled)&&void 0!==c?c:g._tiled,g.maskColor=null!==(u=i.maskColor)&&void 0!==u?u:g.maskColor,g.maskColorMix=null!==(p=i.maskColorMix)&&void 0!==p?p:g.maskColorMix,g.tintColor=null!==(d=i.tintColor)&&void 0!==d?d:g.tintColor,g.layer=null!==(f=i.layer)&&void 0!==f?f:g.layer,g}return o(i,t),Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new g("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},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]=new ae}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].ui=this.gameObject.ui,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.cachePosition,this.cachePosition,this.cacheRenderPosition),this.renderData[t].position=this.cachePosition,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}(Ut),he=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=O.Text,e}return o(e,t),e}(j),le=function(t){function i(i){var r,o,a,s,h,l,c,u,p,d,f,m,y,b,x,v=t.call(this)||this;if(v.fontFamily="Sans",v.fontUrl=null,v.fontSize=12,v.width=100,v.height=100,v.offset=new e,v.color="#000000",v.lineSeparation=0,v.letterSpacing=0,v.bitmapSize=64,v.charRanges=[32,126,161,255],v.smooth=!1,v.bitmapOffset=new e,v.rotation=new n,v.opacity=1,v.orientation="center",v.renderManager=Tt.getSingleton("RenderManager"),v.renderData=new he,v.lastFrameText="",v.type=Ht.TextRenderer,v.text=i.text,v.fontFamily=i.fontFamily,v.fontUrl=null!==(r=i.fontUrl)&&void 0!==r?r:v.fontUrl,v.fontSize=null!==(o=i.fontSize)&&void 0!==o?o:v.fontSize,v.width=null!==(a=i.width)&&void 0!==a?a:v.width,v.height=null!==(s=i.height)&&void 0!==s?s:v.height,v.offset=null!==(h=i.offset)&&void 0!==h?h:v.offset,v.color=null!==(l=i.color)&&void 0!==l?l:v.color,v.lineSeparation=null!==(c=i.lineSeparation)&&void 0!==c?c:v.lineSeparation,v.letterSpacing=null!==(u=i.letterSpacing)&&void 0!==u?u:v.letterSpacing,v.bitmapSize=null!==(p=i.bitmapSize)&&void 0!==p?p:v.bitmapSize,v.charRanges=null!==(d=i.charRanges)&&void 0!==d?d:v.charRanges,v.smooth=null!==(f=i.smooth)&&void 0!==f?f:v.smooth,v.bitmapOffset=null!==(m=i.bitmapOffset)&&void 0!==m?m:v.bitmapOffset,v.rotation=null!==(y=i.rotation)&&void 0!==y?y:v.rotation,v.opacity=null!==(b=i.opacity)&&void 0!==b?b:v.opacity,v.orientation=null!==(x=i.orientation)&&void 0!==x?x:v.orientation,v.charRanges.length%2!=0)throw new g("TextRenderer.charRanges must be a 2 column matrix");if(v.lineSeparation%2!=0)throw new g("TextRenderer.lineSeparation must be multiple of 2");return v}return o(i,t),i.prototype.start=function(){this.renderData.layer=this.gameObject.layer,this.renderData.ui=this.gameObject.ui,this.renderData.fontFamily=this.fontFamily,this.renderData.fontUrl=this.fontUrl,this.renderData.fontSize=this.fontSize,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.bitmapSize=this.bitmapSize,this.renderData.charRanges=this.charRanges,this.renderData.smooth=this.smooth,this.renderData.bitmapOffset=this.bitmapOffset,this.renderData.orientation=this.orientation,this.renderData.width=this.width,this.renderData.height=this.height},i.prototype.update=function(){this.text&&(this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.opacity=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 o=0,a=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];o<a.length;o++){var s=a[o];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(s)}return e.join("\n")},i}(Ut),ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=O.Mask,e}return o(e,t),e}(j),ue=function(t){function i(i){var r,o,a,s,h=t.call(this)||this;return h.renderManager=Tt.getSingleton("RenderManager"),h.offset=new e,h.rotation=new n,h.opacity=1,h.renderData=new ce,h.innerPosition=new e,h.scaledOffset=new e,h.type=Ht.MaskRenderer,h.width=i.width,h.height=i.height,h.color=i.color,h.offset=null!==(r=i.offset)&&void 0!==r?r:h.offset,h.rotation=null!==(o=i.rotation)&&void 0!==o?o:h.rotation,h.opacity=null!==(a=i.opacity)&&void 0!==a?a:h.opacity,h.layer=null!==(s=i.layer)&&void 0!==s?s:h.layer,h}return o(i,t),i.prototype.update=function(){var t;this.renderData.ui=this.gameObject.ui,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}(Ut),pe=function(){function t(t,i,n){this._position=new e,this._position.set(t.x,t.y),this._width=i,this._height=n}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),t}(),de=function(){this.position=new e,this.positionInViewport=new e},fe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=O.Tilemap,e.tilesData=[],e.tilesToRender=[],e}return o(e,t),e}(j),ge=function(t){function i(i){var n,r,o,a,s,h=t.call(this)||this;return h.renderOrder="center",h.smooth=!1,h.textureCorrection=null,h.tileScale=null!==(n=Tt.getConstant("GameConfig").spriteDefaultScale)&&void 0!==n?n:new e(1,1),h.tileWidth=0,h.tileHeight=0,h.orientation=new e(1,1),h.renderManager=Tt.getSingleton("RenderManager"),h.tilemapProcessed=!1,h.renderData=new Map,h.cols=[],h.rows=[],h._width=0,h._height=0,h.tiles=[],h._realWidth=0,h._realHeight=0,h.cacheV2=new e,h.allowMultiple=!1,h.tileset=i.tileset,h.tileScale=null!==(r=i.tileScale)&&void 0!==r?r:h.tileScale,h.smooth=null!==(o=i.smooth)&&void 0!==o?o:h.smooth,h.renderOrder=null!==(a=i.renderOrder)&&void 0!==a?a:h.renderOrder,h.textureCorrection=null!==(s=i.textureCorrection)&&void 0!==s?s:h.textureCorrection,h}return o(i,t),i.prototype.start=function(){this.tileWidth=this.tileset.tileWidth*this.tileScale.x*Math.abs(this.gameObject.transform.scale.x),this.tileHeight=this.tileset.tileHeight*this.tileScale.y*Math.abs(this.gameObject.transform.scale.y),this.orientation.set(Math.sign(this.gameObject.transform.scale.x),Math.sign(this.gameObject.transform.scale.y)),this.processTilemap(),this.updatePosition()},i.prototype.update=function(){var t=this;this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processLayer=function(t){var e=new fe;e.ui=!1,e.alpha=t.alpha,e.image=this.tileset.image,e.layer=this.gameObject.layer,e.smooth=this.smooth,e.tileWidth=this.tileWidth,e.tileHeight=this.tileHeight,e.textureCorrection=this.textureCorrection,e.tintColor=t.tintColor,this.renderData.set(t.layer,e)},i.prototype.processTile=function(t){null!==t.tile&&this.addTileToRenderData(t),this.updateSizeInfo(t.col,t.row)},i.prototype.addTileToRenderData=function(t){if(this.renderData.has(t.layer)){var e=new de;e.tile=t.tile,e.position.set(this.gameObject.transform.position.x+t.col*this.tileWidth*this.orientation.x+t.offset.x*Math.abs(this.gameObject.transform.scale.x)+this.tileWidth*this.orientation.x/2,this.gameObject.transform.position.y-t.row*this.tileHeight*this.orientation.y-t.offset.y*Math.abs(this.gameObject.transform.scale.y)-this.tileHeight*this.orientation.y/2),e.flipHorizontal=t.flip.h!==this.orientation.x<0,e.flipVertical=t.flip.v!==this.orientation.y<0,this.renderData.get(t.layer).tilesData.push(e)}},i.prototype.updateSizeInfo=function(t,e){this._width=!1===this.cols.includes(t)?this.cols.push(t):this._width,this._height=!1===this.rows.includes(e)?this.rows.push(e):this._height,this._realWidth=this._width*this.tileWidth,this._realHeight=this._height*this.tileHeight},i.prototype.updatePosition=function(){var t=this;this.cacheV2.set(("center"===this.renderOrder?-Math.round(this._realWidth/2):["left-down","left-up"].includes(this.renderOrder)?-this._realWidth:0)*this.orientation.x,("center"===this.renderOrder?Math.round(this._realHeight/2):["right-up","left-up"].includes(this.renderOrder)?this._realHeight:0)*this.orientation.y),this.renderData.forEach((function(i){return i.tilesData.forEach((function(i){e.add(i.position,i.position,t.cacheV2),t.addTileData(i)}))}))},i.prototype.addTileData=function(t){this.tiles.push(new pe(t.position,this.tileWidth,this.tileHeight))},Object.defineProperty(i.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"realWidth",{get:function(){return this._realWidth},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"realHeight",{get:function(){return this._realHeight},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"tilesData",{get:function(){return this.tiles},enumerable:!1,configurable:!0}),i}(Ut),me=function(t){function e(e){var i,n,r=this;return e.renderOrder=null!==(i=e.renderOrder)&&void 0!==i?i:e.tilemapData.renderorder,(r=t.call(this,e)||this).type=Ht.TiledTilemapRenderer,r.tiledTilemap=e.tilemapData,r.layerName=null!==(n=e.layerName)&&void 0!==n?n:null,r}return o(e,t),e.prototype.processTilemap=function(){var t=this;this.tiledTilemap.layers.forEach((function(e){var i,n,r;!0!==e.visible||null!==t.layerName&&t.layerName!==e.name||(t.renderData.has(e.name)||t.processLayer({layer:e.name,alpha:e.opacity,tintColor:null!==(i=e.tintcolor)&&void 0!==i?i:null}),!0===t.tiledTilemap.infinite?e.chunks.forEach((function(i){var n,r;return t.processChunk(e.name,i,{x:null!==(n=e.offsetx)&&void 0!==n?n:0,y:null!==(r=e.offsety)&&void 0!==r?r:0})})):t.processChunk(e.name,e,{x:null!==(n=e.offsetx)&&void 0!==n?n:0,y:null!==(r=e.offsety)&&void 0!==r?r:0}))})),this.tilemapProcessed=!0},e.prototype.processChunk=function(t,e,i){void 0===i&&(i={x:0,y:0});for(var n=0,r=0;r<e.height;r++)for(var o=0;o<e.width;o++){var a=this.tileset.getTile(e.data[n]-1);this.processTile({layer:t,tile:a,col:o+e.x,row:r+e.y,flip:{h:!1,v:!1},offset:i}),n++}},e}(ge),ye=1,be=2,xe=3,ve=function(t){function e(e){var i,n,r=t.call(this,e)||this;return r.alpha=1,r.tintColor=null,r.type=Ht.CsvTilemapRenderer,r.tilemapData=e.tilemapData,r.alpha=null!==(i=e.alpha)&&void 0!==i?i:r.alpha,r.tintColor=null!==(n=e.tintColor)&&void 0!==n?n:r.tintColor,r}return o(e,t),e.prototype.processTilemap=function(){var t=this;this.processLayer({layer:"csv",alpha:this.alpha,tintColor:this.tintColor}),this.tilemapData.trim().split("\n").forEach((function(e,i){e.split(",").forEach((function(e,n){var r=parseInt(e.trim()),o=null,a={h:!1,v:!1};if(!1===isNaN(r)){var s=r>999?r%1e3:r,h=Math.round(r/1e3);o=t.tileset.getTile(s),a.h=[ye,xe].includes(h),a.v=[be,xe].includes(h)}t.processTile({layer:"csv",tile:o,col:n,row:i,flip:a,offset:{x:0,y:0}})}))})),this.tilemapProcessed=!0},e}(ge),_e=function(t,e,i,n){this.x=t,this.y=e,this.width=i,this.height=n},we=function(){function t(t){var i,n;this.image=null,this.offset=new e(0,0),this.tileSpacing=new e(0,0),this._tiles=[],this.image=t.image,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.tileSpacing=null!==(n=t.spacing)&&void 0!==n?n:this.tileSpacing,this.generateTiles()}return t.prototype.generateTiles=function(){for(var t=0,e=0;e<this.gridHeight;e++)for(var i=0;i<this.gridWidth;i++)this._tiles[t]=new _e(i*this.tileWidth+i*this.tileSpacing.x+this.offset.x,e*this.tileHeight+e*this.tileSpacing.y+this.offset.y,this.tileWidth,this.tileHeight),t++},t.prototype.getTile=function(t){return this._tiles[t]?this._tiles[t]:null},Object.defineProperty(t.prototype,"tiles",{get:function(){return this._tiles},enumerable:!1,configurable:!0}),t}(),Me=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},Ce=function(t){function e(e){var i=t.call(this)||this;return i.timeManager=Tt.getSingleton("TimeManager"),i.spriteRenderer=null,i.animations=new Map,i.currentAnimation=null,i.type=Ht.Animator,i.spriteRenderer=e.spriteRenderer,i}return o(e,t),e.prototype.update=function(){null!==this.currentAnimation&&(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.stopAnimation():this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return i&&(e.framerate=i),this.animations.set(t,new Oe(e)),this},e.prototype.playAnimation=function(t){if(!1!==this.active){if(!1===this.animations.has(t))throw new g("Animation with name "+t+" does not exist.");this.currentAnimation=this.animations.get(t)}},e.prototype.stopAnimation=function(){!1!==this.active&&null!==this.currentAnimation&&(this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(Vt),Oe=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.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}(),Re=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],je=function(t){function e(e){var i,n,r;void 0===e&&(e={audio:null,volume:1,loop:!1});var o=t.call(this)||this;return o.volume=1,o.loop=!1,o.audio=null,o.clones=new Map,o._playing=!1,o._paused=!1,o.audioEventHandler=function(t){"ended"===t.type&&(o._playing=!1,o.audio.removeEventListener("ended",o.audioEventHandler))},o.userinputEventHandler=function(){Re.forEach((function(t){window.removeEventListener(t,o.userinputEventHandler)})),o.audio.play()},o.allowMultiple=!1,o.type=Ht.AudioPlayer,o.audio=null!==(i=e.audio)&&void 0!==i?i:o.audio,o.volume=null!==(n=e.volume)&&void 0!==n?n:o.volume,o.loop=null!==(r=e.loop)&&void 0!==r?r:o.loop,o}return o(e,t),e.prototype.playAudio=function(t,e){void 0===e&&(e=null),!1===this.clones.has(Symbol.for(t.src))&&this.cloneAudio(t);var i=this.clones.get(Symbol.for(t.src));i.currentTime>0&&(i.currentTime=0),i.volume=null!=e?e:this.volume,i.play()},e.prototype.cloneAudio=function(t){var e=t.cloneNode();this.clones.set(Symbol.for(t.src),e)},e.prototype.play=function(){var t=this;if(null!==this.audio&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.audio.play();this.audio.volume=this.volume,this.audio.loop=this.loop,this.audio.addEventListener("ended",this.audioEventHandler),this._playing=!0,this.audio.play().then((function(){})).catch((function(){return Re.forEach((function(e){return window.addEventListener(e,t.userinputEventHandler)}))}))}},e.prototype.stop=function(){this._playing&&(this.audio.pause(),this.audio.currentTime=0,this.audio.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this.audio.pause(),this._paused=!0)},e.prototype.setActive=function(e){!1===e&&this.stop(),t.prototype.setActive.call(this,e)},e.prototype.destroy=function(){this.stop(),t.prototype.destroy.call(this)},e}(Vt);t.RigidBodyType=void 0,(St=t.RigidBodyType||(t.RigidBodyType={}))[St.Static=0]="Static",St[St.Dynamic=1]="Dynamic";var Pe=function(i){function n(t){var n,r,o=i.call(this)||this;return o.timeManager=Tt.getSingleton("TimeManager"),o._colliderComponents=[],o._layersToCollide=[],o._velocity=new e,o._gravity=new e(0,10),o.deltaGravity=new e,o.deltaVelocity=new e,o.collisions=[],o.penetrationPerDirection={x:new Map,y:new Map},o.updatePosition=!1,o.penetrationResolution=new e,o.type=Ht.RigidBody,o.allowMultiple=!1,o._rigidBodyType=t.rigidBodyType,o._layersToCollide=null!==(n=t.layersToCollide)&&void 0!==n?n:o._layersToCollide,o._gravity.set(0,null!==(r=t.gravity)&&void 0!==r?r:o._gravity.y),o}return o(n,i),Object.defineProperty(n.prototype,"rigidBodyType",{get:function(){return this._rigidBodyType},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"velocity",{get:function(){return this._velocity},set:function(t){this._velocity.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"gravity",{get:function(){return this._gravity.y},set:function(t){this._gravity.set(this._gravity.x,Math.abs(t))},enumerable:!1,configurable:!0}),n.prototype.start=function(){var t=this;if(this.gameObject.getComponents().forEach((function(e){return e instanceof te&&e.physics?t._colliderComponents.push(e):null})),0===this._colliderComponents.length)throw new g("RigidBody needs at least one Collider")},n.prototype.update=function(){this._rigidBodyType!==t.RigidBodyType.Static&&(this.applyGravity(),this.deltaVelocity.set(0,0),this.applyVelocity("x"),this.applyReposition("x"),this.deltaVelocity.set(0,0),this.applyVelocity("y"),this.applyReposition("y"))},n.prototype.applyGravity=function(){this._gravity.y<=0||(this._velocity=e.add(this._velocity,this._velocity,e.scale(this.deltaGravity,this._gravity,-this.timeManager.physicsDeltaTime)))},n.prototype.applyVelocity=function(t){this.deltaVelocity[t]=this._velocity[t]*this.timeManager.physicsDeltaTime,0===this.deltaVelocity.x&&0===this.deltaVelocity.y||e.add(this.gameObject.transform.position,this.gameObject.transform.position,this.deltaVelocity)},n.prototype.applyReposition=function(t){var e=this;0!==this._layersToCollide.length&&(this.updatePosition=!1,this.penetrationResolution.set(this.gameObject.transform.position.x,this.gameObject.transform.position.y),this.penetrationPerDirection[t].clear(),this.updateCollisions(),0!==this.collisions.length&&(this.collisions.forEach((function(i){!0===i.remoteCollider.physics&&null!==i.remoteCollider.gameObject.getComponentByType(Ht.RigidBody)&&0!==i.collisionData.displacementDirection[t]&&e.setPenetrationPerDirectionPerAxis(t,i)})),this.setPenetrationResolution(t),this.updatePosition&&(this.gameObject.transform.position=this.penetrationResolution)))},n.prototype.setPenetrationPerDirectionPerAxis=function(t,e){var i;this.penetrationPerDirection[t].set(e.collisionData.displacementDirection[t],Math.max(null!==(i=this.penetrationPerDirection[t].get(e.collisionData.displacementDirection[t]))&&void 0!==i?i:0,e.collisionData.penetration))},n.prototype.setPenetrationResolution=function(t){var e=this;this.penetrationPerDirection[t].forEach((function(i,n){e.penetrationResolution[t]+=n*i,0!==e._velocity[t]&&Math.sign(e._velocity[t])!==Math.sign(n)&&(e._velocity[t]=0),e.updatePosition=!0}))},n.prototype.updateCollisions=function(){var t=this;this.collisions=[],this._colliderComponents.forEach((function(e){return t._layersToCollide.forEach((function(i){return e.getCollisionsWithLayer(i).forEach((function(e){return t.collisions.push(e)}))}))}))},n}(Gt),Te=function(){function t(t){var i,n,r,o,a=this;this._image=null,this._slice=null,this._scale=null!==(i=Tt.getConstant("GameConfig").spriteDefaultScale)&&void 0!==i?i:new e(1,1),this._smooth=!1,this._width=null,this._height=null,this._loaded=!1,this._image=t.image,this._slice=null!==(n=t.slice)&&void 0!==n?n:this._slice,null!==this._slice&&(this._width=this._slice.width,this._height=this._slice.height),this._scale=null!==(r=t.scale)&&void 0!==r?r:this._scale,this._smooth=null!==(o=t.smooth)&&void 0!==o?o:this._smooth,this._image.naturalWidth?this.onLoad():this._image.addEventListener("load",(function(){return a.onLoad()}))}return Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"image",{get:function(){return this._image},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"slice",{get:function(){return this._slice},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this._scale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"smooth",{get:function(){return this._smooth},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),t.prototype.onLoad=function(){var t,e;this._width=(null!==(t=this._width)&&void 0!==t?t:this._image.naturalWidth)*this._scale.x,this._height=(null!==(e=this._height)&&void 0!==e?e:this._image.naturalHeight)*this._scale.y,this._loaded=!0},t}(),Se=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return o(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){bt.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.scale(this.position,bt.mouse.positionInViewport,1/this.camera.zoom),e.add(this.position,this.position,this.camera.worldSpaceRect.center),e.round(this.position,this.position),console.log("Space position: {x: "+this.position.x+", y: "+this.position.y+"}")),this.mousePressed=bt.mouse.leftButtonPressed},i}(Nt);t.Animation=Me,t.Animator=Ce,t.AssetManager=mt,t.AudioPlayer=je,t.BoxCollider=ie,t.Camera=Qt,t.CollisionData=tt,t.Component=Bt,t.ComponentTypes=Ht,t.CsvTilemapRenderer=ve,t.DomManager=yt,t.GAME_CAMERA_ID=Zt,t.Game=At,t.GameCamera=Xt,t.GameObject=Nt,t.GameObjectManager=_t,t.GamepadController=v,t.GamepadData=_,t.InputManager=bt,t.KeyboardController=M,t.LAYER_DEFAULT=Wt,t.MaskRenderer=ue,t.MouseController=C,t.PhysicsComponent=Gt,t.PreRenderComponent=Lt,t.Rectangle=i,t.RigidBody=Pe,t.Rotation=n,t.Scene=Kt,t.SceneManager=xt,t.SpacePointer=Se,t.Sprite=Te,t.SpriteRenderer=se,t.TextRenderer=le,t.TiledTilemapRenderer=me,t.TilemapCollider=re,t.Tileset=we,t.TimeManager=vt,t.TouchController=it,t.Transform=zt,t.Vector2=e,t.between=function(t,e,i){return t>=e&&t<=i},t.clamp=function(t,e,i){return Math.min(i,Math.max(e,t))},t.fixedRound=function(t,e){return Math.round(t*(10^e))/(10^e)},t.random=function(t,e){return Math.floor(Math.random()*(e-t))+t},t.range=function(t,e,i){void 0===i&&(i=1);for(var n=[],r=t;r<=e;r+=i)n.push(r);return n},Object.defineProperty(t,"__esModule",{value:!0})}));