angry-pixel 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/component/Sprite.d.ts +1 -1
- package/lib/component/collider/EdgeCollider.d.ts +0 -2
- package/lib/component/collider/PolygonCollider.d.ts +0 -2
- package/lib/component/rendering/SpriteRenderer.d.ts +2 -1
- package/lib/core/Component.d.ts +3 -3
- package/lib/core/Game.d.ts +3 -26
- package/lib/core/GameActor.d.ts +3 -0
- package/lib/core/GameConfig.d.ts +23 -0
- package/lib/core/GameObject.d.ts +3 -3
- package/lib/core/Scene.d.ts +3 -1
- package/lib/core/ioc/Config.d.ts +1 -1
- package/lib/core/managers/GameObjectManager.d.ts +3 -0
- package/lib/core/managers/SceneManager.d.ts +4 -3
- package/lib/index.cjs.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/.eslintignore +0 -2
- package/.eslintrc +0 -16
- package/.prettierrc +0 -4
- package/rollup.config.js +0 -17
- package/tsconfig.json +0 -19
package/lib/index.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var a=function(t,e){return a=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])},a(t,e)};function h(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}a(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l,c=function(){return c=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},c.apply(this,arguments)};function u(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.Font="Font"}(l||(l={}));var d,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.loadImage=function(t){var e=new Image;e.crossOrigin="",e.src=t;var i=this.createAsset(t,l.Image,e);return e.naturalWidth?i.loaded=!0:e.addEventListener("load",(function(){return i.loaded=!0})),e},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,l.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url("+e+")"),n=this.createAsset(e,l.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===l.Image&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getAudio=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===l.Audio&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getFont=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===l.Font&&e.family===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var n={type:e,url:t,element:i,loaded:!1};return this.assets.push(n),n},t}(),g=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return h(e,t),e}(Error),f=function(){function t(t,i,n,r){void 0===n&&(n=6),void 0===r&&(r=15),this._bounds=new o(0,0,0,0),this._items=[],this._quadrants=[],this.sw=0,this.se=1,this.nw=2,this.ne=3,this.center=new e,this.childrenWidth=0,this.childrenHeight=0,this.quadsForItem=[],this.level=t,this._bounds.copy(i),this.maxLevels=n,this.maxItems=r,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.copy(t),this.updateCache()},t.prototype.clearItems=function(){this._items=[],this._quadrants.forEach((function(t){return t.clearItems()}))},t.prototype.clearQuadrants=function(){this._quadrants.forEach((function(t){return t.clearQuadrants()})),this._quadrants=[]},t.prototype.addItem=function(t){this._quadrants.length>0?this.insertItemIntoChildrenQuads(t):(this._items.push(t),this._items.length>this.maxItems&&this.level<this.maxLevels&&this.splitQuad())},t.prototype.retrieve=function(t){var e=[];this._quadrants.length>0&&this.getChildrenQuadrantForItem(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})),e.push.apply(e,this._items);var i=e.indexOf(t);return-1!==i&&e.splice(i,1),e},t.prototype.splitQuad=function(){var e=this;this._quadrants=[new o(this.center.x-this.childrenWidth,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new o(this.center.x,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new o(this.center.x-this.childrenWidth,this.center.y,this.childrenWidth,this.childrenHeight),new o(this.center.x,this.center.y,this.childrenWidth,this.childrenHeight)].map((function(i){return new t(e.level+1,i,e.maxLevels,e.maxItems)}));for(var i=0,n=this._items;i<n.length;i++){var r=n[i];this.insertItemIntoChildrenQuads(r)}this._items=[]},t.prototype.getChildrenQuadrantForItem=function(t){if(0===this._quadrants.length)throw new g("Current quadrant does not have quadrant children.");if(this.quadsForItem=[],t.x<=this.center.x&&t.y<=this.center.y&&this.quadsForItem.push(this._quadrants[this.sw]),t.x1>=this.center.x&&t.y<=this.center.y&&this.quadsForItem.push(this._quadrants[this.se]),t.x<=this.center.x&&t.y1>=this.center.y&&this.quadsForItem.push(this._quadrants[this.nw]),t.x1>=this.center.x&&t.y1>=this.center.y&&this.quadsForItem.push(this._quadrants[this.ne]),0===this.quadsForItem.length)throw new g("Item does not fit in any children quadrant");return this.quadsForItem},t.prototype.insertItemIntoChildrenQuads=function(t){this.getChildrenQuadrantForItem(t).forEach((function(e){return e.addItem(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}(),m=function(){function t(t,i,n,r,s){this.collisions=[],this.minBounds=new e,this.maxBounds=new e,this.newBounds=new o(0,0,0,0),this.method=t,this.colliders=[],this.collisionMatrix=s,this.setupQuadTree(i,n,r)}return t.prototype.setupQuadTree=function(t,e,i){i?(this.bounds=i,this.fixedQuadTree=!0):(this.bounds=new o(0,0,0,0),this.fixedQuadTree=!1),this.quadTree=new f(0,this.bounds,t,e)},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 this.collisions.filter((function(e){return e.localCollider===t}))},t.prototype.refreshCollisionsForCollider=function(t){-1!==this.colliders.indexOf(t)&&(this.collisions=this.collisions.filter((function(e){return e.localCollider!==t&&e.remoteCollider!==t})),this.narrowPhase(t,this.broadPhase(t)))},t.prototype.clear=function(){this.colliders=[]},t.prototype.update=function(){if(this.collisions=[],0!==this.colliders.length){this.quadTree.clearItems(),this.quadTree.clearQuadrants(),!1===this.fixedQuadTree&&(this.updateNewBounds(),!1===this.newBounds.equals(this.bounds)&&(this.bounds.copy(this.newBounds),this.quadTree.updateBounds(this.bounds)));for(var t=0,e=this.colliders;t<e.length;t++){var i=e[t];this.quadTree.addItem(i)}this.updateCollisions()}},t.prototype.updateNewBounds=function(){var t=this;this.colliders.forEach((function(e){t.minBounds.set(Math.min(e.x,t.minBounds.x),Math.min(e.y,t.minBounds.y)),t.maxBounds.set(Math.max(e.x1,t.maxBounds.x),Math.max(e.y1,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.updateCollisions=function(){var t=this;this.colliders.filter((function(t){return t.updateCollisions})).forEach((function(e){return t.narrowPhase(e,t.broadPhase(e))}))},t.prototype.broadPhase=function(t){var e=this;return this.collisionMatrix?this.quadTree.retrieve(t).filter((function(i){return e.collisionMatrix.some((function(e){return e[0]===t.layer&&e[1]===i.layer||e[1]===t.layer&&e[0]===i.layer}))})):this.quadTree.retrieve(t)},t.prototype.narrowPhase=function(t,e){var i=this;e.filter((function(e){return e.id!==t.id})).forEach((function(e){if(!i.isResolved(t,e)){var n=i.method.getCollisionResolution(t.shape,e.shape);null!==n&&i.collisions.push({localCollider:t,remoteCollider:e,resolution:n},{localCollider:e,remoteCollider:t,resolution:{direction:n.displacementDirection,displacementDirection:n.direction,penetration:n.penetration}})}}))},t.prototype.isResolved=function(t,e){for(var i=0,n=this.collisions;i<n.length;i++){var r=n[i];if(r.localCollider===t&&r.remoteCollider===e)return!0}return!1},t}(),y=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}();!function(t){t[t.Init=0]="Init",t[t.Start=1]="Start",t[t.Update=2]="Update",t[t.UpdateEngine=3]="UpdateEngine",t[t.UpdateCollider=4]="UpdateCollider",t[t.UpdatePhysics=5]="UpdatePhysics",t[t.UpdateTransform=6]="UpdateTransform",t[t.UpdatePreRender=7]="UpdatePreRender",t[t.UpdateCamera=8]="UpdateCamera",t[t.UpdateRender=9]="UpdateRender",t[t.Destroy=10]="Destroy"}(d||(d={}));var x,v=function(){function t(t,e,i,n,r,o,s,a){this.timeManager=t,this.collisionManager=e,this.physicsManager=i,this.renderManager=n,this.inputManager=r,this.gameObjectManager=o,this.sceneManager=s,this.canvasColor=a,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.physicsManager.clear(),this.dispatchFrameEvent(d.Start),this.inputManager.update(),this.dispatchFrameEvent(d.Update),this.dispatchFrameEvent(d.UpdateEngine),this.dispatchFrameEvent(d.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&this.physicsIteration(t),this.dispatchFrameEvent(d.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(d.UpdatePreRender),this.dispatchFrameEvent(d.UpdateCamera),this.dispatchFrameEvent(d.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(t){this.timeManager.timeScale<=0||(this.timeManager.updateForPhysics(t),this.dispatchFrameEvent(d.UpdatePhysics),this.dispatchFrameEvent(d.UpdateCollider),this.dispatchFrameEvent(d.UpdateTransform),this.collisionManager.update(),this.physicsManager.update(this.timeManager.physicsDeltaTime),this.collisionManager.clear())},t.prototype.asyncPhysicsLoop=function(){var t=this;if(this.running){var e=.001*window.performance.now();document.hidden||this.physicsIteration(e);var i=1/this.timeManager.physicsFramerate-(.001*window.performance.now()-e);window.setTimeout((function(){return t.asyncPhysicsLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return u(u([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==d.Start&&t!==d.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),b=function(){function t(){this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var r=new t(n,i);return this.gameObjects.push(r),r.dispatch(d.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):u([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(){var t=this;this.gameObjects.filter((function(t){return!t.keep})).forEach((function(e){return t.destroy(e,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var n=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(n),n.dispatch(d.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),M=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 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=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}(),w=function(){function t(){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._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n})},t}(),C=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}(),_=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}(),j=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}(),O=function(){function t(t,e){this.game=t,this.renderManager=e,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var r=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new g("There is already a scene with the name '"+e+"'");this.scenes.set(e,(function(){var n=new t(e,r.game);return r.currentScene=n,n.dispatch(d.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},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.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(d.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),P=[60,120,180,240],R=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/15,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!P.includes(t))throw new g("Invalid Physics frame rate. Allowed: ["+P.join(", ")+"]");this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return t.prototype.updateForGame=function(t){this.unscaledGameDeltaTime=Math.min(Math.max(this.minGameDeltatime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t},t.prototype.updateForBrowser=function(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForBrowser),this.maxDeltaTime),this.thenForBrowser=t},t.prototype.updateForPhysics=function(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t},Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledGameDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(x||(x={}));var T,S=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===x.Circumference&&e.type===x.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),D=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}(),A=function(){function t(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}return t.prototype.getCollisionResolution=function(t,e){return t.type===x.Polygon&&e.type===x.Polygon?this.AABBResolver.resolve(t,e):t.type===x.Circumference&&e.type===x.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===x.Polygon&&e.type===x.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===x.Circumference&&e.type===x.Circumference?this.circumferenceResolver.resolve(t,e):null},t}(),F=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.loadImage(t)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.loadFont=function(t,e){return this.assetManager.loadFont(t,e)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.getFont=function(t){return this.assetManager.getFont(t)},t.assetManager=null,t}(),E=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}(),B=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}(),U=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}(),I=function(){function t(){}return t.initialize=function(t){this.timeManager=t},Object.defineProperty(t,"deltaTime",{get:function(){return this.timeManager.deltaTime},enumerable:!1,configurable:!0}),t.getTimeScale=function(){return this.timeManager.timeScale},t.setTimeScale=function(t){this.timeManager.timeScale=t},Object.defineProperty(t,"unscaledDeltaTime",{get:function(){return this.timeManager.unscaledGameDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"physicsDeltaTime",{get:function(){return this.timeManager.physicsDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"browserDeltaTime",{get:function(){return this.timeManager.browserDeltaTime},enumerable:!1,configurable:!0}),t.timeManager=null,t}(),L=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i,n){return this.manager.addGameObject(t,e,i,n)},t.findAllGameObjects=function(){return this.manager.findGameObjects()},t.findGameObjects=function(t){return this.manager.findGameObjects(t)},t.findGameObject=function(t){return this.manager.findGameObject(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParent=function(t,e){return this.manager.findGameObjectByParent(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t}();t.RigidBodyType=void 0,(T=t.RigidBodyType||(t.RigidBodyType={}))[T.Static=0]="Static",T[T.Dynamic=1]="Dynamic",T[T.Kinematic=2]="Kinematic";var G,V,W,k=function(){function i(t){this.collisionManager=t,this.rigidBodyData=[],this.cacheVelocity=new e,this.cacheDisplacement=new e,this.cacheNewDisplacement=0}return i.prototype.addRigidBodyData=function(t){t.cacheVelocity?t.cacheVelocity.set(0,0):t.cacheVelocity=new e,this.rigidBodyData.push(t)},i.prototype.removeRigidBodyData=function(t){var e=this.rigidBodyData.indexOf(t);-1!==e&&(delete this.rigidBodyData[e],this.rigidBodyData.splice(e,1))},i.prototype.update=function(e){var i=this;this.rigidBodyData.forEach((function(n){n.type===t.RigidBodyType.Dynamic?i.dynamicUpdate(n,e):n.type===t.RigidBodyType.Kinematic&&i.kinematicUpdate(n,e)}))},i.prototype.dynamicUpdate=function(t,e){this.applyGravity(t,e),this.applyVelocity(t,e,"x"),this.applyReposition(t,"x",!0),this.applyVelocity(t,e,"y"),this.applyReposition(t,"y",!0)},i.prototype.kinematicUpdate=function(t,i){e.add(t.position,t.position,e.scale(this.cacheVelocity,t.velocity,i))},i.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},i.prototype.applyVelocity=function(t,i,n){var r=this;this.cacheVelocity.set(0,0),this.cacheVelocity[n]=(0!==t.cacheVelocity[n]?t.cacheVelocity[n]:t.velocity[n])*i,e.add(t.position,t.position,this.cacheVelocity),t.colliders.forEach((function(t){e.add(t.shape.position,t.shape.position,r.cacheVelocity),t.shape.update(),r.collisionManager.refreshCollisionsForCollider(t)}))},i.prototype.applyReposition=function(t,i,n){var r=this;this.cacheCollisions=this.getCollisions(t),0!==this.cacheCollisions.length&&(this.cacheDisplacement.set(0,0),this.cacheCollisions.forEach((function(t){r.cacheNewDisplacement=t.resolution.displacementDirection[i]*t.resolution.penetration,r.cacheDisplacement[i]=Math.abs(r.cacheDisplacement[i])>Math.abs(r.cacheNewDisplacement)?r.cacheDisplacement[i]:r.cacheNewDisplacement})),this.cacheDisplacement.magnitude<=0||(e.add(t.position,t.position,this.cacheDisplacement),t.colliders.forEach((function(t){e.add(t.shape.position,t.shape.position,r.cacheDisplacement),t.shape.update(),r.collisionManager.refreshCollisionsForCollider(t)})),n&&0!==this.cacheDisplacement[i]&&Math.sign(this.cacheDisplacement[i])!==Math.sign(t.velocity[i])&&(t.cacheVelocity[i]=t.velocity[i],t.velocity[i]=0)))},i.prototype.getCollisions=function(t){var e=this;return t.colliders.reduce((function(t,i){return t.push.apply(t,e.collisionManager.getCollisionsForCollider(i).filter((function(t){return t.remoteCollider.physics&&t.remoteCollider.rigidBody}))),t}),[])},i.prototype.clear=function(){this.rigidBodyData=[]},i}(),H=function(){function t(){this.direction=new e,this.displacementDirection=new e}return t.prototype.resolve=function(t,i){var n=t.boundingBox,r=i.boundingBox;return this.overlapX=Math.min(n.x1,r.x1)-Math.max(n.x,r.x),this.overlapY=Math.min(n.y1,r.y1)-Math.max(n.y,r.y),this.overlapX<0||this.overlapY<0?null:(this.direction.set(Math.sign(r.x1-n.x1),Math.sign(r.y1-n.y1)),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y),this.preventContainment(n.y,n.y1,r.y,r.y1)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0),this.preventContainment(n.x,n.x1,r.x,r.x1)),e.unit(this.displacementDirection,this.displacementDirection),{penetration:this.minOverlap,displacementDirection:this.displacementDirection.clone(),direction:e.scale(new e,this.displacementDirection,-1)})},t.prototype.preventContainment=function(t,i,n,r){if(t>n&&i<r||n>t&&r<i){var o=Math.abs(t-n),s=Math.abs(i-r);o<s?this.minOverlap+=o:(this.minOverlap+=s,e.scale(this.displacementDirection,this.displacementDirection,-1))}},t}(),z=function(){function t(){this.closestPoint=new e,this.distance=new e,this.direction=new e}return t.prototype.resolve=function(t,n,r){return void 0===r&&(r=!1),this.closestPoint.set(i(t.position.x,n.boundingBox.x,n.boundingBox.x1),i(t.position.y,n.boundingBox.y,n.boundingBox.y1)),e.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(e.unit(this.direction,this.distance),{penetration:t.radius-this.distance.magnitude,direction:r?e.scale(new e,this.direction,-1):this.direction.clone(),displacementDirection:r?this.direction.clone():e.scale(new e,this.direction,-1)})},t}(),N=function(){function t(){this.distance=new e,this.direction=new e}return t.prototype.resolve=function(t,i){return e.subtract(this.distance,i.position,t.position),this.distance.magnitude>t.radius+i.radius?null:(e.unit(this.direction,this.distance),{penetration:t.radius+i.radius-this.distance.magnitude,direction:this.direction.clone(),displacementDirection:e.scale(new e,this.direction,-1)})},t}(),Y=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.displacementDirection=new e,this.distance=new e(1/0,1/0),this.cache=new e}return t.prototype.resolve=function(t,i){this.currentOverlap=null,this.minOverlap=null,t.type===x.Circumference?this.setCircumferenceAxis(t,i):i.type===x.Circumference&&this.setCircumferenceAxis(i,t),this.axes=u(u([],t.projectionAxes,!0),i.projectionAxes,!0);for(var n=0;n<this.axes.length;n++){if(t.type===x.Circumference?this.setCircumferenceVertices(t,this.axes[n]):i.type===x.Circumference&&this.setCircumferenceVertices(i,this.axes[n]),this.projectShapeOntoAxis(this.projA,t,this.axes[n]),this.projectShapeOntoAxis(this.projB,i,this.axes[n]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;this.preventContainment(n),(this.currentOverlap<this.minOverlap||null===this.minOverlap)&&(this.minOverlap=this.currentOverlap,this.displacementDirection.copy(this.axes[n]),this.projA.max<this.projB.max&&e.scale(this.displacementDirection,this.displacementDirection,-1))}return{penetration:this.minOverlap,displacementDirection:this.displacementDirection.clone(),direction:e.scale(new e,this.displacementDirection,-1)}},t.prototype.projectShapeOntoAxis=function(t,i,n){return t.min=e.dot(n,i.vertices[0]),t.max=t.min,i.vertices.forEach((function(i){t.min=Math.min(e.dot(n,i),t.min),t.max=Math.max(e.dot(n,i),t.max)})),t},t.prototype.preventContainment=function(t){if(this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){var i=Math.abs(this.projA.min-this.projB.min),n=Math.abs(this.projA.max-this.projB.max);i<n?this.currentOverlap+=i:(this.currentOverlap+=n,e.scale(this.axes[t],this.axes[t],-1))}},t.prototype.setCircumferenceAxis=function(t,i){var n=this;this.distance.set(1/0,1/0),i.vertices.forEach((function(i){e.subtract(n.cache,i,t.position),n.cache.magnitude<n.distance.magnitude&&n.distance.copy(n.cache)})),e.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,i){e.add(t.vertices[0],t.position,e.scale(this.cache,e.unit(this.cache,i),-t.radius)),e.add(t.vertices[1],t.position,e.scale(this.cache,e.unit(this.cache,i),t.radius))},t}(),X=function(){function t(t,e,i,n,r){this.timeManager=t,this.collisionManager=e,this.physicsManager=i,this.gameObjectManager=n,this.sceneManager=r,this.running=!1,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.physicsManager.clear(),this.dispatchFrameEvent(d.Start),this.dispatchFrameEvent(d.Update),this.dispatchFrameEvent(d.UpdateEngine),this.dispatchFrameEvent(d.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&this.physicsIteration(t),this.sceneManager.update()},t.prototype.physicsIteration=function(t){this.timeManager.timeScale<=0||(this.timeManager.updateForPhysics(t),this.dispatchFrameEvent(d.UpdatePhysics),this.dispatchFrameEvent(d.UpdateCollider),this.dispatchFrameEvent(d.UpdateTransform),this.collisionManager.update(),this.physicsManager.update(this.timeManager.physicsDeltaTime),this.collisionManager.clear())},t.prototype.asyncGameLoop=function(){var t=this;if(this.running){var e=process.uptime();this.gameLogicIteration(e);var i=1/this.timeManager.gameFramerate-(process.uptime()-e);setTimeout((function(){return t.asyncGameLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.asyncPhysicsLoop=function(){var t=this;if(this.running){var e=process.uptime();this.physicsIteration(e);var i=1/this.timeManager.physicsFramerate-(process.uptime()-e);setTimeout((function(){return t.asyncPhysicsLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return u(u([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==d.Start&&t!==d.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(G||(G={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(V||(V={})),function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric"}(W||(W={}));class q{constructor(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}setViewport({position:t,zoom:e},i){i===V.WorldSpace?(this.viewport.x=t.x-this.gl.canvas.width/e/2,this.viewport.x1=t.x+this.gl.canvas.width/e/2,this.viewport.y=t.y-this.gl.canvas.height/e/2,this.viewport.y1=t.y+this.gl.canvas.height/e/2):(this.viewport.x=-this.gl.canvas.width/2,this.viewport.x1=this.gl.canvas.width/2,this.viewport.y=-this.gl.canvas.height/2,this.viewport.y1=this.gl.canvas.height/2)}setObjectForResizeable({position:t,width:e,height:i,rotation:n=0}){const r=Math.sin(n)*i+Math.cos(n)*e,o=Math.sin(n)*e+Math.cos(n)*i;this.object.x=t.x-r/2,this.object.x1=t.x+r/2,this.object.y=t.y-o/2,this.object.y1=t.y+o/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:r,rotation:o}){const s=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:s,height:a,rotation:o})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===G.Circumference?(this.object.x=t.x-n,this.object.y=t.y-n,this.object.x1=t.x+n,this.object.y1=t.y+n):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForTilemap(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.renderPosition,width:t.tilemap.width*t.tilemap.tileWidth,height:t.tilemap.height*t.tilemap.tileHeight,rotation:t.rotation})}applyCullingInTiles(t){const{tiles:e,tilemap:{width:i,tileWidth:n,tileHeight:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*n&&this.viewport.x<=this.object.x+e%i*n+n&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case W.Mask:case W.Sprite:this.setObjectForResizeable(t);break;case W.Geometric:this.setObjectForGeometric(t);break;case W.Text:this.setObjectForText(t);break;case W.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1}applyCulling(t,e){return e.filter((e=>!!this.isInViewPort(e,t)&&(e.type===W.Tilemap&&this.applyCullingInTiles(e),!0)))}}class Q{constructor(t=0,e=0){this._x=t,this._y=e}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}get magnitude(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))}set(t,e){this._x=t,this._y=e}copy(t){this.set(t.x,t.y)}equals(t){return this._x===t.x&&this._y===t.y}clone(){return new Q(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}t.TilemapOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TilemapOrientation||(t.TilemapOrientation={}));class ${constructor(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}addRenderData(t){this.renderData.push(t)}addCameraData(t){this.cameraData.push(t)}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderByCamera(t)))}renderByCamera(e){this.cullingManager.applyCulling(e,this.renderData.filter((t=>e.layers.includes(t.layer))).sort(((t,i)=>e.layers.indexOf(t.layer)-e.layers.indexOf(i.layer))).map((e=>e.type===W.Tilemap?(e=>{const i=Object.assign(Object.assign({},e),{culledTiles:[],tilemap:Object.assign(Object.assign({},e.tilemap),{height:Math.ceil(e.tiles.length/e.tilemap.width),realWidth:e.tilemap.width*e.tilemap.tileWidth,realHeight:0}),renderPosition:new Q});return i.tilemap.realHeight=i.tilemap.height*i.tilemap.tileHeight,(e=>{e.renderPosition.set(e.position.x+(e.orientation!==t.TilemapOrientation.Center?e.tilemap.realWidth/2:0),e.position.y+(e.orientation===t.TilemapOrientation.RightDown?-e.tilemap.realHeight/2:e.orientation===t.TilemapOrientation.RightUp?e.tilemap.realHeight/2:0))})(i),i})(e):e))).forEach((t=>this.webglManager.render(t,e)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}}var K;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(K||(K={}));class J{constructor(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}getContextVersion(){return null!==this.canvas.getContext(K.WebGL2)?K.WebGL2:null!==this.canvas.getContext(K.LegacyWebGL)?K.LegacyWebGL:void 0}}class Z{constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(Symbol.for(t instanceof FontFace?t.family:t))}getFontAtlas(t){return this.fontAtlas.get(Symbol.for(t instanceof FontFace?t.family:t))}getOrCreate(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)}create(t,e,i){this.bitmapSize=i,this.chars=[];for(let e=0;e<t.length;e+=2)for(let i=t[e];i<=t[e+1];i++)this.chars.push(String.fromCharCode(i));const n=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(Symbol.for(e instanceof FontFace?e.family:e),n),n}renderAtlas(t){const e=new tt(t,this.bitmapSize,Math.ceil(Math.sqrt(this.chars.length))),i=e.canvas.getContext("2d");i.clearRect(0,0,e.canvas.width,e.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font=`${this.bitmapSize}px ${t}`;let n=0,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e}}class tt{constructor(t,e,i){this.fontFaceFamily=t,this.bitmapFontSize=e,this.gridSize=i,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*this.bitmapFontSize,this.canvas.height=this.canvas.width}}class et{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i);const o=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,o)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class it{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===K.WebGL2?this.programFactory.create("#version 300 es\nprecision mediump float;\n\nin vec2 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision mediump float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)}}class nt{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var rt="undefined"!=typeof Float32Array?Float32Array:Array;function ot(){var t=new rt(16);return rt!=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 st(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 at(t,e,i){var n,r,o,s,a,h,l,c,u,d,p,g,f=i[0],m=i[1],y=i[2];return e===t?(t[12]=e[0]*f+e[4]*m+e[8]*y+e[12],t[13]=e[1]*f+e[5]*m+e[9]*y+e[13],t[14]=e[2]*f+e[6]*m+e[10]*y+e[14],t[15]=e[3]*f+e[7]*m+e[11]*y+e[15]):(n=e[0],r=e[1],o=e[2],s=e[3],a=e[4],h=e[5],l=e[6],c=e[7],u=e[8],d=e[9],p=e[10],g=e[11],t[0]=n,t[1]=r,t[2]=o,t[3]=s,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=u,t[9]=d,t[10]=p,t[11]=g,t[12]=n*f+a*m+u*y+e[12],t[13]=r*f+h*m+d*y+e[13],t[14]=o*f+l*m+p*y+e[14],t[15]=s*f+c*m+g*y+e[15]),t}function ht(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 lt(t,e,i){var n=Math.sin(i),r=Math.cos(i),o=e[0],s=e[1],a=e[2],h=e[3],l=e[4],c=e[5],u=e[6],d=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]=s*r+c*n,t[2]=a*r+u*n,t[3]=h*r+d*n,t[4]=l*r-o*n,t[5]=c*r-s*n,t[6]=u*r-a*n,t[7]=d*r-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ct;function ut(){var t=new rt(3);return rt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function dt(t,e,i){var n=new rt(3);return n[0]=t,n[1]=e,n[2]=i,n}function pt(){var t=new rt(4);return rt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}ut(),function(){var t;t=new rt(4),rt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),ut(),dt(1,0,0),dt(0,1,0),pt(),pt(),ct=new rt(9),rt!=Float32Array&&(ct[1]=0,ct[2]=0,ct[3]=0,ct[5]=0,ct[6]=0,ct[7]=0),ct[0]=1,ct[4]=1,ct[8]=1,function(){var t=new rt(2);rt!=Float32Array&&(t[0]=0,t[1]=0)}();const gt=t=>{const e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},ft=(t,e,i,n)=>{var r,o;(function(t,e,i,n,r,o,s){var a=1/(e-i),h=1/(n-r),l=1/(o-s);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=(s+o)*l,t[15]=1})(t=st(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),at(t,t,[0,0,0]),n===V.WorldSpace&&ht(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(o=i.zoom)&&void 0!==o?o:1,1])};class mt{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new Q,this.projectionMatrix=ot(),this.modelMatrix=ot(),this.textureMatrix=ot();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(((t,e,i=1)=>{const n=[];for(let t=1;t<=e;t+=i)n.push(t);return n})(0,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e,i){switch(t.shape){case G.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case G.Line:this.renderLines(t,e,this.gl.LINES,i);break;case G.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var r;const o=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(o)&&this.vertices.set(o,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const s=this.vertices.get(o);this.lastVertices===o&&n===W.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW)),this.lastVertices=o,this.modelMatrix=st(this.modelMatrix),Q.round(this.modelPosition,t.location===V.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),at(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),lt(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:a,g:h,b:l,a:c}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=st(this.modelMatrix),at(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ht(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:i,g:n,b:r,a:o}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,r,o),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class yt{constructor(t,e){this.gl=t,this.programManager=e,this.type=W.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new Q,this.projectionMatrix=ot(),this.modelMatrix=ot(),this.textureMatrix=ot()}render(t,e,i){var n,r;i!==W.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=st(this.modelMatrix),Q.round(this.modelPosition,t.location===V.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),at(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),lt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ht(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:o,g:s,b:a,a:h}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,s,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class xt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new Q,this.projectionMatrix=ot(),this.modelMatrix=ot(),this.textureMatrix=ot(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}render(t,e,i){var n,r,o,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=st(this.modelMatrix),Q.round(this.modelPosition,t.location===V.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),at(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),lt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ht(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=st(this.textureMatrix),t.slice&&(at(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),ht(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=gt(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=gt(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}t.TextOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TextOrientation||(t.TextOrientation={}));const vt=new Q,bt=new Q,Mt=[32,126,161,255],wt=t.TextOrientation.Center;class Ct{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=W.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new Q,this.modelPosition=new Q,this.projectionMatrix=ot(),this.modelMatrix=ot(),this.textureMatrix=ot()}render(t,e,i){var n;if(!t.text)return;this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=st(this.modelMatrix),this.setPositionFromOrientation(t),Q.round(this.modelPosition,t.location===V.WorldSpace?Q.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),at(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),lt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ht(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=st(this.textureMatrix),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);const o=this.textureManager.getOrCreateTextureFromCanvas(r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===o&&i===W.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,o),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=o),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.opacity);const{r:s,g:a,b:h,a:l}=gt(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,s,a,h,l),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}setDefaultValues(t){var e,i,n,r,o,s,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:vt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:bt,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:Mt):t.bitmap={margin:vt,spacing:bt,fontSize:64,charRanges:Mt},t.color=null!==(o=t.color)&&void 0!==o?o:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.opacity=null!==(h=t.opacity)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:wt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:r,lineSeparation:o}){this.posVertices=[],this.texVertices=[];let s=0,a=0,h=0;r/=i,o/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,s),s=0,a-=1+o;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(s,a-1,s+e,a-1,s,a,s,a,s+e,a-1,s+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,o=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(o+n.margin.y)/t.canvas.width,u=(i+c.width+n.spacing.x)/t.canvas.width,d=(o+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,d,u,d,h,l,h,l,u,d,u,l),s+=e+r}}this.textSize.set(Math.max(h,s)*i,Math.abs(a-1)*i)}setPositionFromOrientation(e){this.modelPosition.set(e.position.x+(e.orientation===t.TextOrientation.Center?-this.textSize.x/2:0),e.position.y+(e.orientation===t.TextOrientation.Center||e.orientation===t.TextOrientation.RightCenter?this.textSize.y/2:e.orientation===t.TextOrientation.RightUp?this.textSize.y:0))}}class _t{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.tileset={width:0,tileWidth:0,tileHeight:0,texMargin:new Q,texSpacing:new Q,texWidth:0,texHeight:0,texCorrection:new Q},this.modelPosition=new Q,this.projectionMatrix=ot(),this.modelMatrix=ot(),this.textureMatrix=ot()}render(t,e,i){var n,r,o,s;this.processTileset(t),this.generateVertices(t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=st(this.modelMatrix),Q.round(this.modelPosition,t.location===V.WorldSpace?Q.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),at(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),lt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ht(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=st(this.textureMatrix),ht(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),ft(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===W.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=gt(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=gt(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,r,o,s,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new Q,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new Q,t.correction=null!==(n=t.correction)&&void 0!==n?n:new Q,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(o=t.spacing.x)&&void 0!==o?o:0),this.tileset.tileHeight=t.tileHeight+(null!==(s=t.margin.y)&&void 0!==s?s:0)+(null!==(a=t.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y}generateVertices({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const r=n%e.width-e.width/2,o=i/2-Math.floor(n/e.width);this.posVertices.push(r,o-1,r+1,o-1,r,o,r,o,r+1,o-1,r+1,o);const s=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(s,a+this.tileset.texHeight,s+this.tileset.texWidth,a+this.tileset.texHeight,s,a,s,a,s+this.tileset.texWidth,a+this.tileset.texHeight,s+this.tileset.texWidth,a)}))}}class jt{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(()=>this.create(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i}create(t,e,i=!0){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}}class Ot{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!0){var i;return null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!0){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i}getOrCreateTextureFromCanvas(t,e,i=!0){var n;return null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n}}class Pt{constructor(t,e,i){this.gl=t,this.renderers=i,e.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}clearCanvas(t){const e=gt(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var Rt,Tt=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new R(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new b})),St(t,e),e.headless?t.add("IterationManager",(function(){return new X(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RigidBodyManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))})):(t.add("DomManager",(function(){return new y(e.containerNode,e.gameWidth,e.gameHeight)})),t.add("RenderManager",(function(){return(t=>{const e=new J(t),i=e.gl,n=e.contextVersion,r=new it(i,n,new et(i,new nt(i))),o=new Ot(new jt(i)),s=new Pt(i,r,new Map([[W.Sprite,new xt(i,r,o)],[W.Text,new Ct(i,r,o,new Z)],[W.Tilemap,new _t(i,r,o)],[W.Geometric,new mt(i,r)],[W.Mask,new yt(i,r)]]));return new $(s,new q(i))})(t.getSingleton("DomManager").canvas)})),Dt(t),t.add("AssetManager",(function(){return new p})),t.add("IterationManager",(function(){return new v(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RigidBodyManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))),t.add("SceneManager",(function(){return new O(t.getConstant("Game"),e.headless?void 0:t.getSingleton("RenderManager"))})),At(t,e)},St=function(e,i){if(i.collisions.method===t.CollisionMethodConfig.AABB)e.add("CollisionMethod",(function(){return new A(new H,new z,new N)}));else{if(i.collisions.method!==t.CollisionMethodConfig.SAT)throw new g("Invalid collision method.");e.add("CollisionMethod",(function(){return new S(new N,new Y)}))}e.add("CollisionManager",(function(){return new m(e.getSingleton("CollisionMethod"),i.collisions.quadMaxLevel,i.collisions.collidersPerQuad,i.collisions.quadTreeBounds,i.collisions.collisionMatrix)})),e.add("RigidBodyManager",(function(){return new k(e.getSingleton("CollisionManager"))}))},Dt=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new C(new j(e.canvas),new _(e.canvas),new M,new D(e.canvas))}))},At=function(t,e){e.headless||(F.initialize(t.getSingleton("AssetManager")),E.initialize(t.getSingleton("DomManager")),B.initialize(t.getSingleton("InputManager"))),U.initialize(t.getSingleton("SceneManager")),I.initialize(t.getSingleton("TimeManager")),L.initialize(t.getSingleton("GameObjectManager"))},Ft=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.CollisionMethodConfig=void 0,(Rt=t.CollisionMethodConfig||(t.CollisionMethodConfig={})).AABB="aabb",Rt.SAT="sat";var Et,Bt={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",spriteDefaultScale:null,physicsFramerate:180,headless:!1,collisions:{method:t.CollisionMethodConfig.AABB,quadMaxLevel:6,collidersPerQuad:15}},Ut=function(){function t(t){this._config=c(c({},Bt),t),this._config.collisions=c(c({},Bt.collisions),t.collisions),Ft.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){Tt(Ft,this._config),this.sceneManager=Ft.getSingleton("SceneManager"),this.iterationManager=Ft.getSingleton("IterationManager")},Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"running",{get:function(){return this.iterationManager.running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i,n){void 0===n&&(n=!1),this.sceneManager.addScene(t,e,i,n)},t.prototype.run=function(){this.iterationManager.start()},t.prototype.stop=function(){this.iterationManager.stop()},t.prototype.pause=function(){this.iterationManager.pause()},t.prototype.resume=function(){this.iterationManager.resume()},t}(),It=function(){var t=(new Date).getTime(),e="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),("x"==i?n:7&n|8).toString(16)}))},Lt=function(){function t(){this.gameObjectManager=Ft.getSingleton("GameObjectManager"),this.updateEvent=d.Update,this.started=!1}return t.prototype.dispatch=function(t,e){t===d.Init&&this.init?this.init(e):t!==d.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===d.Destroy&&(this.onDestroy&&this.onDestroy(),this._destroy()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),Gt=function(t){function e(e,i){void 0===i&&(i="");var n=t.call(this)||this;return n.sceneManager=Ft.getSingleton("SceneManager"),n.id=It(),n.allowMultiple=!0,n._active=!0,n.gameObject=e,n.name=i,n}return h(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active=t,this.onActiveChange()},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e}(Lt),Vt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdateEngine,e}return h(e,t),e}(Gt),Wt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdateCollider,e}return h(e,t),e}(Gt),kt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdatePhysics,e}return h(e,t),e}(Gt),Ht=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdateTransform,e}return h(e,t),e}(Gt),zt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdatePreRender,e}return h(e,t),e}(Gt),Nt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdateCamera,e}return h(e,t),e}(Gt),Yt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=d.UpdateRender,e}return h(e,t),e}(Gt),Xt=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new e,i._scale=new e(1,1),i._rotation=new s,i._innerPosition=new e,i._parent=null,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.scaledInnerPosition=new e,i}return h(i,t),Object.defineProperty(i.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&e.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},i.prototype.setPositionFromParent=function(){this._innerPosition.magnitude>0?(0!==this._parent.rotation.radians&&this.lastParentRadians!==this._parent.rotation.radians&&(this.translateInnerPosition(),this.lastParentRadians=this._parent.rotation.radians),this.parentScale?(this.updateScaledInnerPosition(),e.add(this._position,this._parent.position,this.scaledInnerPosition)):e.add(this._position,this._parent.position,this._innerPosition)):this._position.copy(this._parent.position),this._rotation.radians=this.parentRotation?this._parent.rotation.radians+this._rotation.radians:this._rotation.radians,this.parentScale&&this._scale.copy(this._parent.scale)},i.prototype.translateInnerPosition=function(){var t=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(t),Math.sin(t)),e.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},i.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},i}(Ht),qt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.collisionManager=Ft.getSingleton("CollisionManager"),e.renderer=null,e.colliders=[],e.physics=!0,e}return h(e,t),e.prototype.update=function(){var t=this;this.colliders.forEach((function(e){return t.collisionManager.addCollider(e)}))},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var s=o[r];if(s.remoteCollider.layer===t)return this.createCollisionData(s)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],o=0,s=this.collisionManager.getCollisionsForCollider(r);o<s.length;o++){var a=s[o];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.id),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){this.renderer&&(this.renderer.active=this.active)},e}(Wt),Qt=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.rigidBodyManager=Ft.getSingleton("RigidBodyManager"),t}return h(n,i),Object.defineProperty(n.prototype,"velocity",{get:function(){return this.data.velocity},set:function(t){this.data.velocity.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"gravity",{get:function(){return this.data.gravity},set:function(t){this.data.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"rigidBodyType",{get:function(){return this.data.type},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var i,n=t.rigidBodyType,r=t.gravity;this.data={type:n,position:null,gravity:null!==(i=Math.abs(r))&&void 0!==i?i:10,velocity:new e,colliders:[]}},n.prototype.start=function(){if(0===this.getColliders().length)throw new g("RigidBody needs at least one Collider with physics")},n.prototype.update=function(){this.data.type!==t.RigidBodyType.Static&&(this.data.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position,this.data.colliders=this.getColliders(),this.rigidBodyManager.addRigidBodyData(this.data))},n.prototype.getColliders=function(){return this.gameObject.getComponents().reduce((function(t,e){return e instanceof qt&&e.physics?u(u([],t,!0),e.colliders,!0):t}),[])},n}(Vt),$t="Default",Kt=function(t){function e(e,i){void 0===e&&(e="");var n=t.call(this)||this;return n.id=It(),n.layer=$t,n.ui=!1,n.keep=!1,n._parent=null,n._active=!0,n.sceneManager=Ft.getSingleton("SceneManager"),n.components=[],n.activeComponentsCache=[],n.activeChildrenCache=[],n.name=e,n.addComponent(Xt),n.parent=null!=i?i:null,n}return h(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChange(),this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(Xt)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(Qt)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r=new t(this,"string"==typeof e?e:i);return this.checkMultipleComponent(r,t),this.components.push(r),r.dispatch(d.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new g("GameObject only allows one component of type "+e.name)},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(d.Destroy)},e.prototype.addChild=function(t,e,i){var n=this.gameObjectManager.addGameObject(t,e,this,i);return n.transform.innerPosition.set(0,0),n.transform.position.copy(this.transform.position),n},e.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},e.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParent(this,t)},e.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},e.prototype._destroy=function(){var t=this;this.destroyComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype.destroyComponents=function(){for(var t=0;t<this.components.length;t++)this.components[t].dispatch(d.Destroy),delete this.components[t];this.components=[]},e}(Lt),Jt=[$t],Zt=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.renderManager=Ft.getSingleton("RenderManager"),e.canvas=Ft.getSingleton("DomManager").canvas,e.viewportRect=new o(0,0,0,0),e.worldSpaceRect=new o(0,0,0,0),e.depth=0,e.layers=Jt,e._zoom=1,e}return h(i,t),Object.defineProperty(i.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}),i.prototype.addLayer=function(t){this.layers.push(t)},i.prototype.init=function(){this.cameraData={position:new e,layers:[],depth:1}},i.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},i.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},i.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},i.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},i}(Nt),te=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return h(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(Zt)},Object.defineProperty(e.prototype,"layers",{get:function(){return this.camera.layers},set:function(t){this.camera.layers=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this.camera.depth},set:function(t){this.camera.depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this.camera.zoom},set:function(t){this.camera.zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this.camera.worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this.camera.viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.camera.layers.push(t)},e}(Kt),ee=function(t){function e(e,i){var n=t.call(this)||this;return n.name=e,n.game=i,n.game.config.headless||n.addGameObject(te),n}return h(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(te)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(Lt),ie=function(){function t(t,e,i,n,r,o){this.shape=t,this.layer=e,this.id=i,this.updateCollisions=n,this.physics=r,this.rigidBody=o}return Object.defineProperty(t.prototype,"x",{get:function(){return this.shape.boundingBox.x},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this.shape.boundingBox.y},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this.shape.boundingBox.x1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this.shape.boundingBox.y1},enumerable:!1,configurable:!0}),t}(),ne=function(){function t(t){this._type=x.Polygon,this._vertices=[],this._boundingBox=new o(0,0,0,0),this._projectionAxes=[],this._position=new e,this._angle=0,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER,this._vertexModel=t;for(var i=0;i<this._vertexModel.length;i++)this._vertices.push(new e),this._projectionAxes.push(new e)}return Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertices",{get:function(){return this._vertices},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"boundingBox",{get:function(){return this._boundingBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertexModel",{get:function(){return this._vertexModel},set:function(t){this._vertexModel=t},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this._vertexModel.length;t++)this._vertices[t].set(this._vertexModel[t].x*Math.cos(this._angle)-this._vertexModel[t].y*Math.sin(this._angle)+this._position.x,this._vertexModel[t].x*Math.sin(this._angle)+this._vertexModel[t].y*Math.cos(this._angle)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,i=0;i<this._vertices.length;i++)e.normal(this.projectionAxes[i],e.subtract(this.projectionAxes[i],null!==(t=this._vertices[i+1])&&void 0!==t?t:this._vertices[0],this._vertices[i]))},t}(),re=function(t){function i(i,n,r){var o=t.call(this,[new e(-i/2,-n/2),new e(-i/2,n/2),new e(i/2,n/2),new e(i/2,-n/2)])||this;return o.width=i,o.height=n,o._position.copy(r),o._projectionAxes=[new e,new e],o.update(),o}return h(i,t),i.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},i.prototype.updateProjectionAxes=function(){e.unit(this._projectionAxes[0],e.subtract(this.projectionAxes[0],this._vertices[1],this._vertices[0])),e.normal(this._projectionAxes[1],this._projectionAxes[0])},i}(ne),oe=function(i){function n(n,r){var o=i.call(this,n,r)||this;if(o.debug=!1,o.offsetX=0,o.offsetY=0,o.scaledVertexModel=[],o.scaledOffset=new e,o.scaledPosition=new e,o.finalRotation=0,o.innerPosition=new e,Ft.getConstant("GameConfig").collisions.method!==t.CollisionMethodConfig.SAT)throw new g("Polygon Colliders need SAT collision method.");return o}return h(n,i),n.prototype.init=function(t){var i,n,r,o,a;if(t.vertexModel.length<3)throw new g("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(i=t.debug)&&void 0!==i?i:this.debug)&&Ft.getConstant("GameConfig").debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(n=t.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(r=t.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(a=t.rotation)&&void 0!==a?a:new s,this.layer=t.layer;for(var h=0;h<this.vertexModel.length;h++)this.scaledVertexModel.push(new e)},n.prototype.start=function(){var t;this.colliders.push(new ie(new ne(this.scaledVertexModel),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(se,{collider:this.colliders[0]}))},n.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateShape(),i.prototype.update.call(this)},n.prototype.updateSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.scaledPosition,this.colliders[0].shape.angle=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel,this.colliders[0].shape.update()},n}(qt),se=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e}return h(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:W.Geometric,layer:this.gameObject.layer,location:V.WorldSpace,position:new e,shape:G.Polygon,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.shape.position),this.renderData.rotation=this.collider.shape.angle,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},i}(Yt),ae=function(i){function n(){var n=null!==i&&i.apply(this,arguments)||this;return n.debug=!1,n.offsetX=0,n.offsetY=0,n.realWidth=0,n.realHeight=0,n.realOffset=new e,n.realPosition=new e,n.realRotation=0,n.applyRotation=Ft.getConstant("GameConfig").collisions.method===t.CollisionMethodConfig.SAT,n.innerPosition=new e,n}return h(n,i),n.prototype.init=function(t){var e,i,n,r,o;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&Ft.getConstant("GameConfig").debugEnabled,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new s,this.layer=t.layer},n.prototype.start=function(){var t;this.colliders.push(new ie(new re(this.realWidth,this.realHeight,this.realPosition),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(se,{collider:this.colliders[0]}))},n.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateShape(),i.prototype.update.call(this)},n.prototype.updateRealSize=function(){this.realWidth=this.width*Math.abs(this.gameObject.transform.scale.x),this.realHeight=this.height*Math.abs(this.gameObject.transform.scale.y),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.realRotation=this.applyRotation?this.gameObject.transform.rotation.radians+this.rotation.radians:0},n.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.realPosition,this.colliders[0].shape.angle=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight),this.colliders[0].shape.update()},n}(qt),he=function(){function t(t){this.type=x.Circumference,this.vertices=[new e,new e],this.projectionAxes=[new e],this.boundingBox=new o(0,0,0,0),this.angle=0,this.vertexModel=[],this.radius=0,this._position=new e,this.vertices=[new e,new e],this.radius=t}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},t}(),le=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new e,i.realPosition=new e,i.innerPosition=new e,i}return h(i,t),i.prototype.init=function(t){var e,i,n,r;this.radius=t.radius,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&Ft.getConstant("GameConfig").debugEnabled,this.layer=t.layer},i.prototype.start=function(){var t;this.colliders.push(new ie(new he(this.radius),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(ce,{collider:this.colliders[0]}))},i.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateShape(),t.prototype.update.call(this)},i.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},i.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){e.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},i.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.realPosition,this.colliders[0].shape.radius=this.realRadius,this.colliders[0].shape.update()},i}(qt),ce=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e}return h(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:W.Geometric,location:V.WorldSpace,layer:this.gameObject.layer,position:new e,shape:G.Circumference,color:"#00FF00"},this.renderData.color="#00FF00",this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.shape=G.Circumference,this.renderData.position.copy(this.collider.shape.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},i}(Yt),ue=function(){function t(t){this.vertexModel=t,this.type=x.Polygon,this.vertices=[new e,new e],this.projectionAxes=[new e],this.boundingBox=new o(0,0,0,0),this.angle=0,this._position=new e}return t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.angle)-this.vertexModel[t].y*Math.sin(this.angle)+this._position.x,this.vertexModel[t].x*Math.sin(this.angle)+this.vertexModel[t].y*Math.cos(this.angle)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){e.normal(this.projectionAxes[0],e.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),de=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.position=new e,t}return h(n,i),n.prototype.init=function(t){var e,i;this.tilemapRenderer=t.tilemapRenderer,this.layer=t.layer,this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&Ft.getConstant("GameConfig").debugEnabled,this.physics=!0,this.composite=null!==(i=t.composite)&&void 0!==i&&i},n.prototype.start=function(){var e;this.layer=null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===t.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([t.TilemapOrientation.Center,t.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==t.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(pe,{colliders:this.colliders}))},n.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(i,n){t.needsCollider(i,n)&&t.colliders.push(new ie(new re(t.scaledTileWidth,t.scaledTileHeight,new e(t.position.x+(n%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(n/t.tilemapRenderer.width)+.5)*t.scaledTileHeight)),t.layer,t.gameObject.id,!1,t.physics,t.hasComponent(Qt)))}))},n.prototype.useLineColliders=function(){var t,i,n=this,r=[],o=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,s=Math.floor(e/n.tilemapRenderer.width);r[s]||(r[s]=[]),r[s+1]||(r[s+1]=[]),o[s]||(o[s]=[]),o[s+1]||(o[s+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[s][i]=!0,r[s][i+1]=!0),n.hasTile(a[2])||(r[s+1][i]=!0,r[s+1][i+1]=!0),n.hasTile(a[1])||(o[s][i]=!0,o[s+1][i]=!0),n.hasTile(a[3])||(o[s][i+1]=!0,o[s+1][i+1]=!0)}}));for(var s=0;s<r.length;s++)for(var a=0;a<r[s].length;a++)!t||!i||s*-this.scaledTileHeight===i.y&&r[s][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),r[s][a]&&(t?i=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight):t=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight));t&&i&&this.addLineCollider(t,i),t=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(s=0;s<o.length;s++)!t||!i||a*this.scaledTileWidth===i.x&&o[s][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),o[s][a]&&(t?i=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight):t=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight));t&&i&&this.addLineCollider(t,i)},n.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},n.prototype.addLineCollider=function(t,e){var i=new ie(new ue([t.clone(),e.clone()]),this.layer,this.gameObject.id,!1,this.physics,this.hasComponent(Qt));i.shape.position=this.position,i.shape.update(),this.colliders.push(i)},n.prototype.needsCollider=function(t,e){var i=this;return 0!==t&&this.getNeighbors(e).some((function(t){return!t||!i.tilemapRenderer.tiles[t]||0===i.tilemapRenderer.tiles[t]}))},n.prototype.getNeighbors=function(t){return[t-this.tilemapRenderer.width>=0?t-this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width>0?t-1:void 0,t+this.tilemapRenderer.width<=this.tilemapRenderer.width*this.tilemapRenderer.height?t+this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width<this.tilemapRenderer.width-1?t+1:void 0]},n.prototype.update=function(){var t=this;this.colliders.forEach((function(e){return e.layer=t.layer})),i.prototype.update.call(this)},n}(qt),pe=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return h(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:W.Geometric,layer:i.gameObject.layer,location:V.WorldSpace,position:new e,shape:G.Polygon,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.shape.angle,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(Yt),ge=function(i){function n(n,r){var o=i.call(this,n,r)||this;if(o.debug=!1,o.offsetX=0,o.offsetY=0,o.scaledVertexModel=[],o.scaledOffset=new e,o.scaledPosition=new e,o.finalRotation=0,o.innerPosition=new e,Ft.getConstant("GameConfig").collisions.method!==t.CollisionMethodConfig.SAT)throw new g("Edge Colliders need SAT collision method.");return o}return h(n,i),n.prototype.init=function(t){var i,n,r,o,a;if(t.vertexModel.length<2)throw new g("Edge Collider needs at least 2 vertices.");this.debug=(null!==(i=t.debug)&&void 0!==i?i:this.debug)&&Ft.getConstant("GameConfig").debugEnabled,this.vertexModel=t.vertexModel,this.offsetX=null!==(n=t.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(r=t.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(o=t.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(a=t.rotation)&&void 0!==a?a:new s,this.layer=t.layer;for(var h=0;h<this.vertexModel.length;h++)this.scaledVertexModel.push(new e)},n.prototype.start=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders.push(new ie(new ue([this.scaledVertexModel[e],this.scaledVertexModel[e+1]]),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt)));this.debug&&(this.renderer=this.gameObject.addComponent(fe,{colliders:this.colliders}))},n.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateColliders(),i.prototype.update.call(this)},n.prototype.updateSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].shape.position=this.scaledPosition,this.colliders[e].shape.angle=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]],this.colliders[e].shape.update()},n}(qt),fe=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return h(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:W.Geometric,layer:i.gameObject.layer,location:V.WorldSpace,position:new e,shape:G.Line,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.shape.position,t.renderData[i].rotation=e.shape.angle,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(Yt),me=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=Ft.getSingleton("RenderManager"),i.renderData=[],i.innerPosition=new e,i.cachePosition=new e,i.cacheRenderPosition=new e,i.scaledOffset=new e,i}return h(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(i=t.offset)&&void 0!==i?i:new e,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:new s,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this._tiled=null!==(h=t.tiled)&&void 0!==h?h:new e(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(l=t.maskColorMix)&&void 0!==l?l:0,this.tintColor=t.tintColor,this.layer=t.layer},Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new 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]={type:W.Sprite,location:V.WorldSpace,layer:"",position:new e,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?V.ViewPort:V.WorldSpace,this.renderData[t].layer=null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,this.renderData[t].image=this.sprite.image,this.renderData[t].width=this.sprite.width*Math.abs(this.gameObject.transform.scale.x),this.renderData[t].height=this.sprite.height*Math.abs(this.gameObject.transform.scale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData[t].rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData[t].smooth=this.sprite.smooth,this.renderData[t].alpha=this.opacity,this.renderData[t].maskColor=this.maskColor,this.renderData[t].maskColorMix=this.maskColorMix,this.renderData[t].tintColor=this.tintColor,this.calculateRenderPosition(t,e,i),this.renderManager.addRenderData(this.renderData[t])},i.prototype.calculateRenderPosition=function(t,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[t].width/2*(this._tiled.x-1),this.renderData[t].height/2*(this._tiled.y-1)),e.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[t].width,n*this.renderData[t].height),e.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},i.prototype.translateRenderPosition=function(t){e.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var i=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[t].position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(i),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(i))},i}(Yt),ye=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e.lastFrameText="",e}return h(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l,c,u,d;if(this.text=t.text,this.font=null!==(i=t.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=t.fontSize)&&void 0!==n?n:12,this.width=null!==(r=t.width)&&void 0!==r?r:100,this.height=null!==(o=t.height)&&void 0!==o?o:100,this.offset=null!==(a=t.offset)&&void 0!==a?a:new e,this.color=null!==(h=t.color)&&void 0!==h?h:"#000000",this.charRanges=null!==(l=t.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=t.letterSpacing)&&void 0!==u?u:0,this.smooth=t.smooth,this.rotation=null!==(d=t.rotation)&&void 0!==d?d:new s,this.opacity=t.opacity,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new g("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new g("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:W.Text,location:V.WorldSpace,position:new e,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},i.prototype.update=function(){var t,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?V.ViewPort:V.WorldSpace,this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.fontSize=this.fontSize,this.renderData.color=this.color,this.renderData.orientation=this.orientation,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.rotation=null!==(i=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==i?i:0,this.renderData.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,s=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];o<s.length;o++){var a=s[o];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(Yt),xe=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=Ft.getSingleton("RenderManager"),i.offset=new e,i.rotation=new s,i.opacity=1,i.innerPosition=new e,i.scaledOffset=new e,i}return h(i,t),i.prototype.init=function(t){var i,n,r,o;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:this.opacity,this.layer=t.layer,this.renderData={type:W.Mask,layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,location:this.gameObject.ui?V.ViewPort:V.WorldSpace,position:new e,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?V.ViewPort:V.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},i.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){e.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},i}(Yt),ve=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return h(i,t),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,r=t.tileWidth,o=t.tileHeight,s=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=r,this.tileHeight=o,this.layer=s,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(i){return t.processChunk(i,e)})):t.processChunk(e,e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(t,i){var n,r=this,o={type:W.Tilemap,layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,location:this.gameObject.ui?V.ViewPort:V.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return r.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=o.tiles:o.tiles.forEach((function(e,i){r.tiles[r.tiledData.width*(t.y+Math.floor(i/t.width))+t.x+i%t.width]=e})),this.renderData.push(o),this.chunks.push(t)},i.prototype.getTilesetTileId=function(t){return this.tilesetTileIds[t]||(this.tilesetTileIds[t]=this.tiledData.tilesets.reduce((function(e,i){return t>=i.firstgid?t-i.firstgid+1:e}),0)),this.tilesetTileIds[t]},i.prototype.updateRenderData=function(){var t=this;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.tiledData.width*this.scaledTileWidth,this.realHeight=this.tiledData.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.alpha}))},i}(Yt),be=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=Ft.getSingleton("RenderManager"),e.scaledTileWidth=0,e.scaledTileHeight=0,e}return h(i,t),i.prototype.init=function(t){var i,n=this,r=t.tiles,o=t.tileset,s=t.tileWidth,a=t.tileHeight,h=t.width,l=t.layer,c=t.orientation,u=t.alpha,d=t.tintColor,p=t.smooth;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=o,this.width=h,this.tileWidth=s,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=u,this.tintColor=d,this.renderData={type:W.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?V.ViewPort:V.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},i.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},i.prototype.updateRenderData=function(){var t;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.position.copy(this.gameObject.transform.position),this.renderData.tintColor=this.tintColor,this.renderData.alpha=this.alpha,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},i}(Yt),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},we="default",Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.timeManager=Ft.getSingleton("TimeManager"),e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return h(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e=we),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new _e(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t=we),!1!==this.active){if(!1===this.animations.has(t))throw new g("Animation with name "+t+" does not exist.");this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(Vt),_e=function(){function t(t){this._sprite=null,this._restarted=!1,this.currentFrame=0,this.frameTime=0,this._animation=t}return Object.defineProperty(t.prototype,"sprite",{get:function(){return this._sprite},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"restarted",{get:function(){return this._restarted},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){return this._animation.loop},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this.currentFrame=0,this.frameTime=0,this._restarted=!0},t.prototype.playFrame=function(t){this._restarted=!1,this.frameTime>=1/this._animation.framerate&&(this.frameTime=0,this.currentFrame=this.currentFrame+1===this._animation.sprites.length?0:this.currentFrame+1,this._restarted=0===this.currentFrame),this._sprite=this._animation.sprites[this.currentFrame],this.frameTime+=t},t}(),je=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.volume=1,e.loop=!1,e.audio=null,e.clones=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e.audio.removeEventListener("ended",e.audioEventHandler))},e.userinputEventHandler=function(){je.forEach((function(t){window.removeEventListener(t,e.userinputEventHandler)})),e.audio.play()},e}return h(e,t),e.prototype.init=function(t){var e,i,n;void 0===t&&(t={}),this.audio=null!==(e=t.audio)&&void 0!==e?e:this.audio,this.volume=null!==(i=t.volume)&&void 0!==i?i:this.volume,this.loop=null!==(n=t.loop)&&void 0!==n?n:this.loop},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 je.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.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop()},e}(Vt),Pe=function(){function t(t){var i,n,r,o=this;this._width=null,this._height=null,this._loaded=!1,this.image=t.image,this.smooth=null!==(i=t.smooth)&&void 0!==i&&i,this.scale=null!==(r=null!==(n=t.scale)&&void 0!==n?n:Ft.getConstant("GameConfig").spriteDefaultScale)&&void 0!==r?r:new e(1,1),this.slice=t.slice,this.slice&&(this._width=this.slice.width,this._height=this.slice.height);var s=function(){var t,e;o._width=(null!==(t=o._width)&&void 0!==t?t:o.image.naturalWidth)*Math.abs(o.scale.x),o._height=(null!==(e=o._height)&&void 0!==e?e:o.image.naturalHeight)*Math.abs(o.scale.y),o._loaded=!0};this.image.naturalWidth?s():this.image.addEventListener("load",(function(){return s()}))}return Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();t.ButtonType=void 0,(Et=t.ButtonType||(t.ButtonType={}))[Et.Rectangle=0]="Rectangle",Et[Et.Circumference=1]="Circumference";var Re=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.width=100,t.height=100,t.radius=50,t.touchEnabled=!0,t._offset=new e,t.pressed=!1,t.mouse=Ft.getSingleton("InputManager").mouse,t.touch=Ft.getSingleton("InputManager").touch,t.position=new e,t.distance=new e,t.pressedLastFrame=!1,t.scaled={width:0,height:0,radius:0,offset:new e},t}return h(n,i),Object.defineProperty(n.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,r=t.touchEnabled,o=t.width,s=t.offset;this.type=e,this.width=null!=o?o:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this._offset=null!=s?s:this._offset},n.prototype.update=function(){this.scale(),e.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},n.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this._offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this._offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*this.gameObject.transform.scale.magnitude},n.prototype.resolveMouseAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=r(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&r(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},n.prototype.resolveMouseAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},n.prototype.resolveTouchAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=this.position.x+this.scaled.width/2>=this.touch.positionInViewport.x-this.touch.radius.x&&this.position.x-this.scaled.width/2<=this.touch.positionInViewport.x+this.touch.radius.x&&this.position.y+this.scaled.height/2>=this.touch.positionInViewport.y-this.touch.radius.y&&this.position.y-this.scaled.height/2<=this.touch.positionInViewport.y+this.touch.radius.y))},n.prototype.resolveTouchAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},n}(Gt),Te=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return h(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){B.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.round(this.position,e.add(this.position,this.camera.transform.position,e.scale(this.position,B.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: "+this.position.x+", y: "+this.position.y+"}")),this.mousePressed=B.mouse.leftButtonPressed},i}(Kt);t.Animation=Me,t.Animator=Ce,t.AssetManager=F,t.AudioPlayer=Oe,t.BallCollider=le,t.BoxCollider=ae,t.Button=Re,t.Camera=Zt,t.ColliderData=ie,t.Component=Gt,t.DomManager=E,t.EdgeCollider=ge,t.Game=Ut,t.GameCamera=te,t.GameObject=Kt,t.GameObjectManager=L,t.GamepadController=M,t.GamepadData=w,t.InputManager=B,t.KeyboardController=_,t.LAYER_DEFAULT=$t,t.MaskRenderer=xe,t.MouseController=j,t.PhysicsComponent=kt,t.PolygonCollider=oe,t.PolygonColliderRenderer=se,t.PreRenderComponent=zt,t.Rectangle=o,t.RigidBody=Qt,t.Rotation=s,t.Scene=ee,t.SceneManager=U,t.SpacePointer=Te,t.Sprite=Pe,t.SpriteRenderer=me,t.TextRenderer=ye,t.TiledTilemapRenderer=ve,t.TilemapCollider=de,t.TilemapRenderer=be,t.TimeManager=I,t.TouchController=D,t.Transform=Xt,t.Vector2=e,t.between=r,t.clamp=i,t.fixedRound=n,t.randomFloat=(t,e,i=2)=>n(Math.random()*(e-t)+t,i),t.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,t.range=(t,e,i=1)=>{const n=[];for(let r=t;r<=e;r+=i)n.push(r);return n},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */var a=function(t,e){return a=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])},a(t,e)};function h(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}a(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l=function(){return l=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},l.apply(this,arguments)};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))}var u,d=function(){var t=(new Date).getTime(),e="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),("x"==i?n:7&n|8).toString(16)}))};!function(t){t[t.Init=0]="Init",t[t.Start=1]="Start",t[t.Update=2]="Update",t[t.UpdateEngine=3]="UpdateEngine",t[t.UpdateCollider=4]="UpdateCollider",t[t.UpdatePhysics=5]="UpdatePhysics",t[t.UpdateTransform=6]="UpdateTransform",t[t.UpdatePreRender=7]="UpdatePreRender",t[t.UpdateCamera=8]="UpdateCamera",t[t.UpdateRender=9]="UpdateRender",t[t.Destroy=10]="Destroy"}(u||(u={}));var p,g=function(){function t(t,e,i,n,r,o,s,a){this.timeManager=t,this.collisionManager=e,this.physicsManager=i,this.renderManager=n,this.inputManager=r,this.gameObjectManager=o,this.sceneManager=s,this.canvasColor=a,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.physicsManager.clear(),this.dispatchFrameEvent(u.Start),this.inputManager.update(),this.dispatchFrameEvent(u.Update),this.dispatchFrameEvent(u.UpdateEngine),this.dispatchFrameEvent(u.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&this.physicsIteration(t),this.dispatchFrameEvent(u.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(u.UpdatePreRender),this.dispatchFrameEvent(u.UpdateCamera),this.dispatchFrameEvent(u.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(t){this.timeManager.timeScale<=0||(this.timeManager.updateForPhysics(t),this.dispatchFrameEvent(u.UpdatePhysics),this.dispatchFrameEvent(u.UpdateCollider),this.dispatchFrameEvent(u.UpdateTransform),this.collisionManager.update(),this.physicsManager.update(this.timeManager.physicsDeltaTime),this.collisionManager.clear())},t.prototype.asyncPhysicsLoop=function(){var t=this;if(this.running){var e=.001*window.performance.now();document.hidden||this.physicsIteration(e);var i=1/this.timeManager.physicsFramerate-(.001*window.performance.now()-e);window.setTimeout((function(){return t.asyncPhysicsLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return c(c([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==u.Start&&t!==u.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}(),f=function(){function t(t){this.updateEvent=u.Update,this.started=!1,this.container=t,this.gameObjectManager=this.container.getSingleton("GameObjectManager")}return t.prototype.dispatch=function(t,e){t===u.Init&&this.init?this.init(e):t!==u.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===u.Destroy&&(this.onDestroy&&this.onDestroy(),this._destroy()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),m=function(t){function e(e,i,n){void 0===n&&(n="");var r=t.call(this,e)||this;return r.id=d(),r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=n,r}return h(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active=t,this.onActiveChange()},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e}(f),y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdateEngine,e}return h(e,t),e}(m),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdateCollider,e}return h(e,t),e}(m),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdatePhysics,e}return h(e,t),e}(m),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdateTransform,e}return h(e,t),e}(m),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdatePreRender,e}return h(e,t),e}(m),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdateCamera,e}return h(e,t),e}(m),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=u.UpdateRender,e}return h(e,t),e}(m);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font"}(p||(p={}));var _,j=function(){function t(){this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.loadImage=function(t){var e=new Image;e.crossOrigin="",e.src=t;var i=this.createAsset(t,p.Image,e);return e.naturalWidth?i.loaded=!0:e.addEventListener("load",(function(){return i.loaded=!0})),e},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,p.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url("+e+")"),n=this.createAsset(e,p.Font,i);return n.family=t,i.load().then((function(t){document.fonts.add(t),n.loaded=!0})),i},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===p.Image&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getAudio=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===p.Audio&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.getFont=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===p.Font&&e.family===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var n={type:e,url:t,element:i,loaded:!1};return this.assets.push(n),n},t}(),O=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return h(e,t),e}(Error),P=function(){function t(t,i,n,r){void 0===n&&(n=6),void 0===r&&(r=15),this._bounds=new o(0,0,0,0),this._items=[],this._quadrants=[],this.sw=0,this.se=1,this.nw=2,this.ne=3,this.center=new e,this.childrenWidth=0,this.childrenHeight=0,this.quadsForItem=[],this.level=t,this._bounds.copy(i),this.maxLevels=n,this.maxItems=r,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.copy(t),this.updateCache()},t.prototype.clearItems=function(){this._items=[],this._quadrants.forEach((function(t){return t.clearItems()}))},t.prototype.clearQuadrants=function(){this._quadrants.forEach((function(t){return t.clearQuadrants()})),this._quadrants=[]},t.prototype.addItem=function(t){this._quadrants.length>0?this.insertItemIntoChildrenQuads(t):(this._items.push(t),this._items.length>this.maxItems&&this.level<this.maxLevels&&this.splitQuad())},t.prototype.retrieve=function(t){var e=[];this._quadrants.length>0&&this.getChildrenQuadrantForItem(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})),e.push.apply(e,this._items);var i=e.indexOf(t);return-1!==i&&e.splice(i,1),e},t.prototype.splitQuad=function(){var e=this;this._quadrants=[new o(this.center.x-this.childrenWidth,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new o(this.center.x,this.center.y-this.childrenHeight,this.childrenWidth,this.childrenHeight),new o(this.center.x-this.childrenWidth,this.center.y,this.childrenWidth,this.childrenHeight),new o(this.center.x,this.center.y,this.childrenWidth,this.childrenHeight)].map((function(i){return new t(e.level+1,i,e.maxLevels,e.maxItems)}));for(var i=0,n=this._items;i<n.length;i++){var r=n[i];this.insertItemIntoChildrenQuads(r)}this._items=[]},t.prototype.getChildrenQuadrantForItem=function(t){if(0===this._quadrants.length)throw new O("Current quadrant does not have quadrant children.");if(this.quadsForItem=[],t.x<=this.center.x&&t.y<=this.center.y&&this.quadsForItem.push(this._quadrants[this.sw]),t.x1>=this.center.x&&t.y<=this.center.y&&this.quadsForItem.push(this._quadrants[this.se]),t.x<=this.center.x&&t.y1>=this.center.y&&this.quadsForItem.push(this._quadrants[this.nw]),t.x1>=this.center.x&&t.y1>=this.center.y&&this.quadsForItem.push(this._quadrants[this.ne]),0===this.quadsForItem.length)throw new O("Item does not fit in any children quadrant");return this.quadsForItem},t.prototype.insertItemIntoChildrenQuads=function(t){this.getChildrenQuadrantForItem(t).forEach((function(e){return e.addItem(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}(),R=function(){function t(t,i,n,r,s){this.collisions=[],this.minBounds=new e,this.maxBounds=new e,this.newBounds=new o(0,0,0,0),this.method=t,this.colliders=[],this.collisionMatrix=s,this.setupQuadTree(i,n,r)}return t.prototype.setupQuadTree=function(t,e,i){i?(this.bounds=i,this.fixedQuadTree=!0):(this.bounds=new o(0,0,0,0),this.fixedQuadTree=!1),this.quadTree=new P(0,this.bounds,t,e)},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 this.collisions.filter((function(e){return e.localCollider===t}))},t.prototype.refreshCollisionsForCollider=function(t){-1!==this.colliders.indexOf(t)&&(this.collisions=this.collisions.filter((function(e){return e.localCollider!==t&&e.remoteCollider!==t})),this.narrowPhase(t,this.broadPhase(t)))},t.prototype.clear=function(){this.colliders=[]},t.prototype.update=function(){if(this.collisions=[],0!==this.colliders.length){this.quadTree.clearItems(),this.quadTree.clearQuadrants(),!1===this.fixedQuadTree&&(this.updateNewBounds(),!1===this.newBounds.equals(this.bounds)&&(this.bounds.copy(this.newBounds),this.quadTree.updateBounds(this.bounds)));for(var t=0,e=this.colliders;t<e.length;t++){var i=e[t];this.quadTree.addItem(i)}this.updateCollisions()}},t.prototype.updateNewBounds=function(){var t=this;this.colliders.forEach((function(e){t.minBounds.set(Math.min(e.x,t.minBounds.x),Math.min(e.y,t.minBounds.y)),t.maxBounds.set(Math.max(e.x1,t.maxBounds.x),Math.max(e.y1,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.updateCollisions=function(){var t=this;this.colliders.filter((function(t){return t.updateCollisions})).forEach((function(e){return t.narrowPhase(e,t.broadPhase(e))}))},t.prototype.broadPhase=function(t){var e=this;return this.collisionMatrix?this.quadTree.retrieve(t).filter((function(i){return e.collisionMatrix.some((function(e){return e[0]===t.layer&&e[1]===i.layer||e[1]===t.layer&&e[0]===i.layer}))})):this.quadTree.retrieve(t)},t.prototype.narrowPhase=function(t,e){var i=this;e.filter((function(e){return e.id!==t.id})).forEach((function(e){if(!i.isResolved(t,e)){var n=i.method.getCollisionResolution(t.shape,e.shape);null!==n&&i.collisions.push({localCollider:t,remoteCollider:e,resolution:n},{localCollider:e,remoteCollider:t,resolution:{direction:n.displacementDirection,displacementDirection:n.direction,penetration:n.penetration}})}}))},t.prototype.isResolved=function(t,e){for(var i=0,n=this.collisions;i<n.length;i++){var r=n[i];if(r.localCollider===t&&r.remoteCollider===e)return!0}return!1},t}(),T=function(){function t(t,e,i){if(this._canvas=null,!t)throw new O("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}(),S=function(){function t(t){this.container=t,this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var r=new t(this.container,n,i);return this.gameObjects.push(r),r.dispatch(u.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):c([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(){var t=this;this.gameObjects.filter((function(t){return!t.keep})).forEach((function(e){return t.destroy(e,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var n=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(n),n.dispatch(u.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),D=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 A),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}(),A=function(){function t(){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._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n})},t}(),F=function(){function t(t,e,i,n){this.mouse=t,this.keyboard=e,this.gamepad=i,this.touch=n}return t.prototype.update=function(){this.mouse.update(),this.gamepad.update()},t}(),E=function(){function t(t){var e=this;this.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}(),B=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}(),U=function(){function t(t,e,i){this.container=t,this.game=e,this.renderManager=i,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var r=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new O("There is already a scene with the name '"+e+"'");this.scenes.set(e,(function(){var n=new t(r.container,e,r.game);return r.currentScene=n,n.dispatch(u.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new O("There is no opening scene");this._loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(null===this.game)throw new O("Game not initialized.");if(!1===this.scenes.has(t))throw new O("Scene with name "+t+" does not exists");this.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(u.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),I=[60,120,180,240],L=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/15,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!I.includes(t))throw new O("Invalid Physics frame rate. Allowed: ["+I.join(", ")+"]");this.physicsFramerate=t,this.minGameDeltatime=parseFloat((1/this.gameFramerate).toFixed(6)),this.minPhysicsDeltaTime=parseFloat((1/this.physicsFramerate).toFixed(6))}return t.prototype.updateForGame=function(t){this.unscaledGameDeltaTime=Math.min(Math.max(this.minGameDeltatime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t},t.prototype.updateForBrowser=function(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForBrowser),this.maxDeltaTime),this.thenForBrowser=t},t.prototype.updateForPhysics=function(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t},Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledGameDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(_||(_={}));var G,V=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===_.Circumference&&e.type===_.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),W=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}(),k=function(){function t(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}return t.prototype.getCollisionResolution=function(t,e){return t.type===_.Polygon&&e.type===_.Polygon?this.AABBResolver.resolve(t,e):t.type===_.Circumference&&e.type===_.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===_.Polygon&&e.type===_.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===_.Circumference&&e.type===_.Circumference?this.circumferenceResolver.resolve(t,e):null},t}(),H=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.loadImage(t)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.loadFont=function(t,e){return this.assetManager.loadFont(t,e)},t.getImage=function(t){return this.assetManager.getImage(t)},t.getAudio=function(t){return this.assetManager.getAudio(t)},t.getFont=function(t){return this.assetManager.getFont(t)},t.assetManager=null,t}(),z=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}(),N=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}(),Y=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}(),X=function(){function t(){}return t.initialize=function(t){this.timeManager=t},Object.defineProperty(t,"deltaTime",{get:function(){return this.timeManager.deltaTime},enumerable:!1,configurable:!0}),t.getTimeScale=function(){return this.timeManager.timeScale},t.setTimeScale=function(t){this.timeManager.timeScale=t},Object.defineProperty(t,"unscaledDeltaTime",{get:function(){return this.timeManager.unscaledGameDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"physicsDeltaTime",{get:function(){return this.timeManager.physicsDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"browserDeltaTime",{get:function(){return this.timeManager.browserDeltaTime},enumerable:!1,configurable:!0}),t.timeManager=null,t}(),q=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i,n){return this.manager.addGameObject(t,e,i,n)},t.findAllGameObjects=function(){return this.manager.findGameObjects()},t.findGameObjects=function(t){return this.manager.findGameObjects(t)},t.findGameObject=function(t){return this.manager.findGameObject(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParent=function(t,e){return this.manager.findGameObjectByParent(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t}();t.RigidBodyType=void 0,(G=t.RigidBodyType||(t.RigidBodyType={}))[G.Static=0]="Static",G[G.Dynamic=1]="Dynamic",G[G.Kinematic=2]="Kinematic";var Q,$,K,J=function(){function i(t){this.collisionManager=t,this.rigidBodyData=[],this.cacheVelocity=new e,this.cacheDisplacement=new e,this.cacheNewDisplacement=0}return i.prototype.addRigidBodyData=function(t){t.cacheVelocity?t.cacheVelocity.set(0,0):t.cacheVelocity=new e,this.rigidBodyData.push(t)},i.prototype.removeRigidBodyData=function(t){var e=this.rigidBodyData.indexOf(t);-1!==e&&(delete this.rigidBodyData[e],this.rigidBodyData.splice(e,1))},i.prototype.update=function(e){var i=this;this.rigidBodyData.forEach((function(n){n.type===t.RigidBodyType.Dynamic?i.dynamicUpdate(n,e):n.type===t.RigidBodyType.Kinematic&&i.kinematicUpdate(n,e)}))},i.prototype.dynamicUpdate=function(t,e){this.applyGravity(t,e),this.applyVelocity(t,e,"x"),this.applyReposition(t,"x",!0),this.applyVelocity(t,e,"y"),this.applyReposition(t,"y",!0)},i.prototype.kinematicUpdate=function(t,i){e.add(t.position,t.position,e.scale(this.cacheVelocity,t.velocity,i))},i.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},i.prototype.applyVelocity=function(t,i,n){var r=this;this.cacheVelocity.set(0,0),this.cacheVelocity[n]=(0!==t.cacheVelocity[n]?t.cacheVelocity[n]:t.velocity[n])*i,e.add(t.position,t.position,this.cacheVelocity),t.colliders.forEach((function(t){e.add(t.shape.position,t.shape.position,r.cacheVelocity),t.shape.update(),r.collisionManager.refreshCollisionsForCollider(t)}))},i.prototype.applyReposition=function(t,i,n){var r=this;this.cacheCollisions=this.getCollisions(t),0!==this.cacheCollisions.length&&(this.cacheDisplacement.set(0,0),this.cacheCollisions.forEach((function(t){r.cacheNewDisplacement=t.resolution.displacementDirection[i]*t.resolution.penetration,r.cacheDisplacement[i]=Math.abs(r.cacheDisplacement[i])>Math.abs(r.cacheNewDisplacement)?r.cacheDisplacement[i]:r.cacheNewDisplacement})),this.cacheDisplacement.magnitude<=0||(e.add(t.position,t.position,this.cacheDisplacement),t.colliders.forEach((function(t){e.add(t.shape.position,t.shape.position,r.cacheDisplacement),t.shape.update(),r.collisionManager.refreshCollisionsForCollider(t)})),n&&0!==this.cacheDisplacement[i]&&Math.sign(this.cacheDisplacement[i])!==Math.sign(t.velocity[i])&&(t.cacheVelocity[i]=t.velocity[i],t.velocity[i]=0)))},i.prototype.getCollisions=function(t){var e=this;return t.colliders.reduce((function(t,i){return t.push.apply(t,e.collisionManager.getCollisionsForCollider(i).filter((function(t){return t.remoteCollider.physics&&t.remoteCollider.rigidBody}))),t}),[])},i.prototype.clear=function(){this.rigidBodyData=[]},i}(),Z=function(){function t(){this.direction=new e,this.displacementDirection=new e}return t.prototype.resolve=function(t,i){var n=t.boundingBox,r=i.boundingBox;return this.overlapX=Math.min(n.x1,r.x1)-Math.max(n.x,r.x),this.overlapY=Math.min(n.y1,r.y1)-Math.max(n.y,r.y),this.overlapX<0||this.overlapY<0?null:(this.direction.set(Math.sign(r.x1-n.x1),Math.sign(r.y1-n.y1)),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y),this.preventContainment(n.y,n.y1,r.y,r.y1)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0),this.preventContainment(n.x,n.x1,r.x,r.x1)),e.unit(this.displacementDirection,this.displacementDirection),{penetration:this.minOverlap,displacementDirection:this.displacementDirection.clone(),direction:e.scale(new e,this.displacementDirection,-1)})},t.prototype.preventContainment=function(t,i,n,r){if(t>n&&i<r||n>t&&r<i){var o=Math.abs(t-n),s=Math.abs(i-r);o<s?this.minOverlap+=o:(this.minOverlap+=s,e.scale(this.displacementDirection,this.displacementDirection,-1))}},t}(),tt=function(){function t(){this.closestPoint=new e,this.distance=new e,this.direction=new e}return t.prototype.resolve=function(t,n,r){return void 0===r&&(r=!1),this.closestPoint.set(i(t.position.x,n.boundingBox.x,n.boundingBox.x1),i(t.position.y,n.boundingBox.y,n.boundingBox.y1)),e.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(e.unit(this.direction,this.distance),{penetration:t.radius-this.distance.magnitude,direction:r?e.scale(new e,this.direction,-1):this.direction.clone(),displacementDirection:r?this.direction.clone():e.scale(new e,this.direction,-1)})},t}(),et=function(){function t(){this.distance=new e,this.direction=new e}return t.prototype.resolve=function(t,i){return e.subtract(this.distance,i.position,t.position),this.distance.magnitude>t.radius+i.radius?null:(e.unit(this.direction,this.distance),{penetration:t.radius+i.radius-this.distance.magnitude,direction:this.direction.clone(),displacementDirection:e.scale(new e,this.direction,-1)})},t}(),it=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.displacementDirection=new e,this.distance=new e(1/0,1/0),this.cache=new e}return t.prototype.resolve=function(t,i){this.currentOverlap=null,this.minOverlap=null,t.type===_.Circumference?this.setCircumferenceAxis(t,i):i.type===_.Circumference&&this.setCircumferenceAxis(i,t),this.axes=c(c([],t.projectionAxes,!0),i.projectionAxes,!0);for(var n=0;n<this.axes.length;n++){if(t.type===_.Circumference?this.setCircumferenceVertices(t,this.axes[n]):i.type===_.Circumference&&this.setCircumferenceVertices(i,this.axes[n]),this.projectShapeOntoAxis(this.projA,t,this.axes[n]),this.projectShapeOntoAxis(this.projB,i,this.axes[n]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;this.preventContainment(n),(this.currentOverlap<this.minOverlap||null===this.minOverlap)&&(this.minOverlap=this.currentOverlap,this.displacementDirection.copy(this.axes[n]),this.projA.max<this.projB.max&&e.scale(this.displacementDirection,this.displacementDirection,-1))}return{penetration:this.minOverlap,displacementDirection:this.displacementDirection.clone(),direction:e.scale(new e,this.displacementDirection,-1)}},t.prototype.projectShapeOntoAxis=function(t,i,n){return t.min=e.dot(n,i.vertices[0]),t.max=t.min,i.vertices.forEach((function(i){t.min=Math.min(e.dot(n,i),t.min),t.max=Math.max(e.dot(n,i),t.max)})),t},t.prototype.preventContainment=function(t){if(this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){var i=Math.abs(this.projA.min-this.projB.min),n=Math.abs(this.projA.max-this.projB.max);i<n?this.currentOverlap+=i:(this.currentOverlap+=n,e.scale(this.axes[t],this.axes[t],-1))}},t.prototype.setCircumferenceAxis=function(t,i){var n=this;this.distance.set(1/0,1/0),i.vertices.forEach((function(i){e.subtract(n.cache,i,t.position),n.cache.magnitude<n.distance.magnitude&&n.distance.copy(n.cache)})),e.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,i){e.add(t.vertices[0],t.position,e.scale(this.cache,e.unit(this.cache,i),-t.radius)),e.add(t.vertices[1],t.position,e.scale(this.cache,e.unit(this.cache,i),t.radius))},t}(),nt=function(){function t(t,e,i,n,r){this.timeManager=t,this.collisionManager=e,this.physicsManager=i,this.gameObjectManager=n,this.sceneManager=r,this.running=!1,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.physicsManager.clear(),this.dispatchFrameEvent(u.Start),this.dispatchFrameEvent(u.Update),this.dispatchFrameEvent(u.UpdateEngine),this.dispatchFrameEvent(u.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&this.physicsIteration(t),this.sceneManager.update()},t.prototype.physicsIteration=function(t){this.timeManager.timeScale<=0||(this.timeManager.updateForPhysics(t),this.dispatchFrameEvent(u.UpdatePhysics),this.dispatchFrameEvent(u.UpdateCollider),this.dispatchFrameEvent(u.UpdateTransform),this.collisionManager.update(),this.physicsManager.update(this.timeManager.physicsDeltaTime),this.collisionManager.clear())},t.prototype.asyncGameLoop=function(){var t=this;if(this.running){var e=process.uptime();this.gameLogicIteration(e);var i=1/this.timeManager.gameFramerate-(process.uptime()-e);setTimeout((function(){return t.asyncGameLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.asyncPhysicsLoop=function(){var t=this;if(this.running){var e=process.uptime();this.physicsIteration(e);var i=1/this.timeManager.physicsFramerate-(process.uptime()-e);setTimeout((function(){return t.asyncPhysicsLoop()}),1e3*Math.max(1e-4,i))}},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return c(c([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==u.Start&&t!==u.Update||(this.currentScene.dispatch(t),this.gameObjects.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))),this.components.filter((function(t){return t.active})).forEach((function(e){return e.dispatch(t)}))},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Q||(Q={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}($||($={})),function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric"}(K||(K={}));class rt{constructor(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}setViewport({position:t,zoom:e},i){i===$.WorldSpace?(this.viewport.x=t.x-this.gl.canvas.width/e/2,this.viewport.x1=t.x+this.gl.canvas.width/e/2,this.viewport.y=t.y-this.gl.canvas.height/e/2,this.viewport.y1=t.y+this.gl.canvas.height/e/2):(this.viewport.x=-this.gl.canvas.width/2,this.viewport.x1=this.gl.canvas.width/2,this.viewport.y=-this.gl.canvas.height/2,this.viewport.y1=this.gl.canvas.height/2)}setObjectForResizeable({position:t,width:e,height:i,rotation:n=0}){const r=Math.abs(Math.sin(n)),o=Math.abs(Math.cos(n)),s=r*i+o*e,a=r*e+o*i;this.object.x=t.x-s/2,this.object.x1=t.x+s/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:r,rotation:o}){const s=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:s,height:a,rotation:o})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===Q.Circumference?(this.object.x=t.x-n,this.object.y=t.y-n,this.object.x1=t.x+n,this.object.y1=t.y+n):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForTilemap(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.renderPosition,width:t.tilemap.width*t.tilemap.tileWidth,height:t.tilemap.height*t.tilemap.tileHeight,rotation:t.rotation})}applyCullingInTiles(t){const{tiles:e,tilemap:{width:i,tileWidth:n,tileHeight:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*n&&this.viewport.x<=this.object.x+e%i*n+n&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case K.Mask:case K.Sprite:this.setObjectForResizeable(t);break;case K.Geometric:this.setObjectForGeometric(t);break;case K.Text:this.setObjectForText(t);break;case K.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1}applyCulling(t,e){return e.filter((e=>!!this.isInViewPort(e,t)&&(e.type===K.Tilemap&&this.applyCullingInTiles(e),!0)))}}class ot{constructor(t=0,e=0){this._x=t,this._y=e}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}get magnitude(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))}set(t,e){this._x=t,this._y=e}copy(t){this.set(t.x,t.y)}equals(t){return this._x===t.x&&this._y===t.y}clone(){return new ot(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}t.TilemapOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TilemapOrientation||(t.TilemapOrientation={}));class st{constructor(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}addRenderData(t){this.renderData.push(t)}addCameraData(t){this.cameraData.push(t)}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderByCamera(t)))}renderByCamera(e){this.cullingManager.applyCulling(e,this.renderData.filter((t=>e.layers.includes(t.layer))).sort(((t,i)=>e.layers.indexOf(t.layer)-e.layers.indexOf(i.layer))).map((e=>e.type===K.Tilemap?(e=>{const i=Object.assign(Object.assign({},e),{culledTiles:[],tilemap:Object.assign(Object.assign({},e.tilemap),{height:Math.ceil(e.tiles.length/e.tilemap.width),realWidth:e.tilemap.width*e.tilemap.tileWidth,realHeight:0}),renderPosition:new ot});return i.tilemap.realHeight=i.tilemap.height*i.tilemap.tileHeight,(e=>{e.renderPosition.set(e.position.x+(e.orientation!==t.TilemapOrientation.Center?e.tilemap.realWidth/2:0),e.position.y+(e.orientation===t.TilemapOrientation.RightDown?-e.tilemap.realHeight/2:e.orientation===t.TilemapOrientation.RightUp?e.tilemap.realHeight/2:0))})(i),i})(e):e))).forEach((t=>this.webglManager.render(t,e)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}}var at;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(at||(at={}));class ht{constructor(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}getContextVersion(){return null!==this.canvas.getContext(at.WebGL2)?at.WebGL2:null!==this.canvas.getContext(at.LegacyWebGL)?at.LegacyWebGL:void 0}}class lt{constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(Symbol.for(t instanceof FontFace?t.family:t))}getFontAtlas(t){return this.fontAtlas.get(Symbol.for(t instanceof FontFace?t.family:t))}getOrCreate(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)}create(t,e,i){this.bitmapSize=i,this.chars=[];for(let e=0;e<t.length;e+=2)for(let i=t[e];i<=t[e+1];i++)this.chars.push(String.fromCharCode(i));const n=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(Symbol.for(e instanceof FontFace?e.family:e),n),n}renderAtlas(t){const e=new ct(t,this.bitmapSize,Math.ceil(Math.sqrt(this.chars.length))),i=e.canvas.getContext("2d");i.clearRect(0,0,e.canvas.width,e.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font=`${this.bitmapSize}px ${t}`;let n=0,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e}}class ct{constructor(t,e,i){this.fontFaceFamily=t,this.bitmapFontSize=e,this.gridSize=i,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*this.bitmapFontSize,this.canvas.height=this.canvas.width}}class ut{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),n=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i);const o=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,o)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class dt{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===at.WebGL2?this.programFactory.create("#version 300 es\nprecision mediump float;\n\nin vec2 positionCoords;\nin vec2 textureCoords;\n\nout vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision mediump float;\n\nout vec4 fragColor;\n\nin vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\n\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\n\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\n\nuniform float u_alpha;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enableVertexAttribArray(this.positionCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.vertexAttribPointer(this.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.texCoordsAttr),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.vertexAttribPointer(this.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)}}class pt{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var gt="undefined"!=typeof Float32Array?Float32Array:Array;function ft(){var t=new gt(16);return gt!=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 mt(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 yt(t,e,i){var n,r,o,s,a,h,l,c,u,d,p,g,f=i[0],m=i[1],y=i[2];return e===t?(t[12]=e[0]*f+e[4]*m+e[8]*y+e[12],t[13]=e[1]*f+e[5]*m+e[9]*y+e[13],t[14]=e[2]*f+e[6]*m+e[10]*y+e[14],t[15]=e[3]*f+e[7]*m+e[11]*y+e[15]):(n=e[0],r=e[1],o=e[2],s=e[3],a=e[4],h=e[5],l=e[6],c=e[7],u=e[8],d=e[9],p=e[10],g=e[11],t[0]=n,t[1]=r,t[2]=o,t[3]=s,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=u,t[9]=d,t[10]=p,t[11]=g,t[12]=n*f+a*m+u*y+e[12],t[13]=r*f+h*m+d*y+e[13],t[14]=o*f+l*m+p*y+e[14],t[15]=s*f+c*m+g*y+e[15]),t}function xt(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 vt(t,e,i){var n=Math.sin(i),r=Math.cos(i),o=e[0],s=e[1],a=e[2],h=e[3],l=e[4],c=e[5],u=e[6],d=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]=s*r+c*n,t[2]=a*r+u*n,t[3]=h*r+d*n,t[4]=l*r-o*n,t[5]=c*r-s*n,t[6]=u*r-a*n,t[7]=d*r-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var bt;function Mt(){var t=new gt(3);return gt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function wt(t,e,i){var n=new gt(3);return n[0]=t,n[1]=e,n[2]=i,n}function Ct(){var t=new gt(4);return gt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}Mt(),function(){var t;t=new gt(4),gt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),Mt(),wt(1,0,0),wt(0,1,0),Ct(),Ct(),bt=new gt(9),gt!=Float32Array&&(bt[1]=0,bt[2]=0,bt[3]=0,bt[5]=0,bt[6]=0,bt[7]=0),bt[0]=1,bt[4]=1,bt[8]=1,function(){var t=new gt(2);gt!=Float32Array&&(t[0]=0,t[1]=0)}();const _t=t=>{const e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},jt=(t,e,i,n)=>{var r,o;(function(t,e,i,n,r,o,s){var a=1/(e-i),h=1/(n-r),l=1/(o-s);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=(s+o)*l,t[15]=1})(t=mt(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),yt(t,t,[0,0,0]),n===$.WorldSpace&&xt(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(o=i.zoom)&&void 0!==o?o:1,1])};class Ot{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new ot,this.projectionMatrix=ft(),this.modelMatrix=ft(),this.textureMatrix=ft();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(((t,e,i=1)=>{const n=[];for(let t=1;t<=e;t+=i)n.push(t);return n})(0,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e,i){switch(t.shape){case Q.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case Q.Line:this.renderLines(t,e,this.gl.LINES,i);break;case Q.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var r;const o=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(o)&&this.vertices.set(o,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const s=this.vertices.get(o);this.lastVertices===o&&n===K.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW)),this.lastVertices=o,this.modelMatrix=mt(this.modelMatrix),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,t.position,e.position):t.position),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),vt(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:a,g:h,b:l,a:c}=_t(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=mt(this.modelMatrix),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,t.position,e.position):t.position),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),xt(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:i,g:n,b:r,a:o}=_t(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,r,o),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class Pt{constructor(t,e){this.gl=t,this.programManager=e,this.type=K.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new ot,this.projectionMatrix=ft(),this.modelMatrix=ft(),this.textureMatrix=ft()}render(t,e,i){var n,r;i!==K.Mask&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.vertices,this.gl.STATIC_DRAW)),this.modelMatrix=mt(this.modelMatrix),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,t.position,e.position):t.position),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),vt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),xt(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha>=0&&t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:o,g:s,b:a,a:h}=_t(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,s,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class Rt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new ot,this.projectionMatrix=ft(),this.modelMatrix=ft(),this.textureMatrix=ft(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}render(t,e,i){var n,r,o,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=mt(this.modelMatrix),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,t.position,e.position):t.position),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),vt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),xt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=mt(this.textureMatrix),t.slice&&(yt(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),xt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=_t(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=_t(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}t.TextOrientation=void 0,function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(t.TextOrientation||(t.TextOrientation={}));const Tt=new ot,St=new ot,Dt=[32,126,161,255],At=t.TextOrientation.Center;class Ft{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=K.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new ot,this.modelPosition=new ot,this.projectionMatrix=ft(),this.modelMatrix=ft(),this.textureMatrix=ft()}render(t,e,i){var n;if(!t.text)return;this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=mt(this.modelMatrix),this.setPositionFromOrientation(t),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),vt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),xt(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=mt(this.textureMatrix),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.alpha<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);const o=this.textureManager.getOrCreateTextureFromCanvas(r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===o&&i===K.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,o),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=o),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:s,g:a,b:h,a:l}=_t(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,s,a,h,l),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}setDefaultValues(t){var e,i,n,r,o,s,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:Tt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:St,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:Dt):t.bitmap={margin:Tt,spacing:St,fontSize:64,charRanges:Dt},t.color=null!==(o=t.color)&&void 0!==o?o:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:At,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:r,lineSeparation:o}){this.posVertices=[],this.texVertices=[];let s=0,a=0,h=0;r/=i,o/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,s),s=0,a-=1+o;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(s,a-1,s+e,a-1,s,a,s,a,s+e,a-1,s+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,o=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(o+n.margin.y)/t.canvas.width,u=(i+c.width+n.spacing.x)/t.canvas.width,d=(o+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,d,u,d,h,l,h,l,u,d,u,l),s+=e+r}}this.textSize.set(Math.max(h,s)*i,Math.abs(a-1)*i)}setPositionFromOrientation(e){this.modelPosition.set(e.position.x+(e.orientation===t.TextOrientation.Center?-this.textSize.x/2:0),e.position.y+(e.orientation===t.TextOrientation.Center||e.orientation===t.TextOrientation.RightCenter?this.textSize.y/2:e.orientation===t.TextOrientation.RightUp?this.textSize.y:0))}}class Et{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.tileset={width:0,tileWidth:0,tileHeight:0,texMargin:new ot,texSpacing:new ot,texWidth:0,texHeight:0,texCorrection:new ot},this.modelPosition=new ot,this.projectionMatrix=ft(),this.modelMatrix=ft(),this.textureMatrix=ft()}render(t,e,i){var n,r,o,s;if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)return;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=mt(this.modelMatrix),ot.round(this.modelPosition,t.location===$.WorldSpace?ot.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),yt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),vt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),xt(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=mt(this.textureMatrix),xt(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),jt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===K.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=_t(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=_t(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,r,o,s,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new ot,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new ot,t.correction=null!==(n=t.correction)&&void 0!==n?n:new ot,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(o=t.spacing.x)&&void 0!==o?o:0),this.tileset.tileHeight=t.tileHeight+(null!==(s=t.margin.y)&&void 0!==s?s:0)+(null!==(a=t.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y}generateVertices({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const r=n%e.width-e.width/2,o=i/2-Math.floor(n/e.width);this.posVertices.push(r,o-1,r+1,o-1,r,o,r,o,r+1,o-1,r+1,o);const s=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(s,a+this.tileset.texHeight,s+this.tileset.texWidth,a+this.tileset.texHeight,s,a,s,a,s+this.tileset.texWidth,a+this.tileset.texHeight,s+this.tileset.texWidth,a)}))}}class Bt{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.create(t,i,e):t.addEventListener("load",(()=>this.create(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.create(t,i,e),i}create(t,e,i=!0){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}}class Ut{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!0){var i;return null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!0){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i}getOrCreateTextureFromCanvas(t,e,i=!0){var n;return null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n}}class It{constructor(t,e,i){this.gl=t,this.renderers=i,e.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}clearCanvas(t){const e=_t(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var Lt;t.CollisionMethodConfig=void 0,(Lt=t.CollisionMethodConfig||(t.CollisionMethodConfig={})).AABB="aabb",Lt.SAT="sat";var Gt,Vt=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new L(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new S(t)})),Wt(t,e),e.headless?t.add("IterationManager",(function(){return new nt(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RigidBodyManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))})):(t.add("DomManager",(function(){return new T(e.containerNode,e.gameWidth,e.gameHeight)})),t.add("RenderManager",(function(){return(t=>{const e=new ht(t),i=e.gl,n=e.contextVersion,r=new dt(i,n,new ut(i,new pt(i))),o=new Ut(new Bt(i)),s=new It(i,r,new Map([[K.Sprite,new Rt(i,r,o)],[K.Text,new Ft(i,r,o,new lt)],[K.Tilemap,new Et(i,r,o)],[K.Geometric,new Ot(i,r)],[K.Mask,new Pt(i,r)]]));return new st(s,new rt(i))})(t.getSingleton("DomManager").canvas)})),kt(t),t.add("AssetManager",(function(){return new j})),t.add("IterationManager",(function(){return new g(t.getSingleton("TimeManager"),t.getSingleton("CollisionManager"),t.getSingleton("RigidBodyManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))),t.add("SceneManager",(function(){return new U(t,t.getConstant("Game"),e.headless?void 0:t.getSingleton("RenderManager"))})),Ht(t,e)},Wt=function(e,i){if(i.collisions.method===t.CollisionMethodConfig.AABB)e.add("CollisionMethod",(function(){return new k(new Z,new tt,new et)}));else{if(i.collisions.method!==t.CollisionMethodConfig.SAT)throw new O("Invalid collision method.");e.add("CollisionMethod",(function(){return new V(new et,new it)}))}e.add("CollisionManager",(function(){return new R(e.getSingleton("CollisionMethod"),i.collisions.quadMaxLevel,i.collisions.collidersPerQuad,i.collisions.quadTreeBounds,i.collisions.collisionMatrix)})),e.add("RigidBodyManager",(function(){return new J(e.getSingleton("CollisionManager"))}))},kt=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new F(new B(e.canvas),new E(e.canvas),new D,new W(e.canvas))}))},Ht=function(t,e){e.headless||(H.initialize(t.getSingleton("AssetManager")),z.initialize(t.getSingleton("DomManager")),N.initialize(t.getSingleton("InputManager"))),Y.initialize(t.getSingleton("SceneManager")),X.initialize(t.getSingleton("TimeManager")),q.initialize(t.getSingleton("GameObjectManager"))},zt=function(){function t(){this.instances=new Map,this.constructors=new Map,this.constants=new Map}return t.prototype.add=function(t,e){if(this.constructors.has(t))throw new O("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 O("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 O("Invalid object constructor name: "+t);return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new O("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 O("Invalid constant name: "+t);return this.constants.get(t)},t}(),Nt={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new e(1,1),collisions:{method:t.CollisionMethodConfig.AABB,quadMaxLevel:6,collidersPerQuad:15}},Yt=function(){function t(t){this._config=l(l({},Nt),t),this._config.collisions=l(l({},Nt.collisions),t.collisions),this.container=new zt,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){Vt(this.container,this._config),this.sceneManager=this.container.getSingleton("SceneManager"),this.iterationManager=this.container.getSingleton("IterationManager")},Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"running",{get:function(){return this.iterationManager.running},enumerable:!1,configurable:!0}),t.prototype.addScene=function(t,e,i,n){void 0===n&&(n=!1),this.sceneManager.addScene(t,e,i,n)},t.prototype.run=function(){this.iterationManager.start()},t.prototype.stop=function(){this.iterationManager.stop()},t.prototype.pause=function(){this.iterationManager.pause()},t.prototype.resume=function(){this.iterationManager.resume()},t}(),Xt=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new e,i._scale=new e(1,1),i._rotation=new s,i._innerPosition=new e,i._parent=null,i.cache=new e,i.lastParentRadians=0,i.lastPosition=new e,i.scaledInnerPosition=new e,i}return h(i,t),Object.defineProperty(i.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"scale",{get:function(){return this._scale},set:function(t){this._scale.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._rotation.direction},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"innerPosition",{get:function(){return this._innerPosition},set:function(t){this._innerPosition.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,null!==this._parent&&e.subtract(this._innerPosition,this._position,this._parent.position)},enumerable:!1,configurable:!0}),i.prototype.update=function(){null!==this._parent&&this.setPositionFromParent(),this.lastPosition.copy(this._position)},i.prototype.setPositionFromParent=function(){this._innerPosition.magnitude>0?(0!==this._parent.rotation.radians&&this.lastParentRadians!==this._parent.rotation.radians&&(this.translateInnerPosition(),this.lastParentRadians=this._parent.rotation.radians),this.parentScale?(this.updateScaledInnerPosition(),e.add(this._position,this._parent.position,this.scaledInnerPosition)):e.add(this._position,this._parent.position,this._innerPosition)):this._position.copy(this._parent.position),this._rotation.radians=this.parentRotation?this._parent.rotation.radians+this._rotation.radians:this._rotation.radians,this.parentScale&&this._scale.copy(this._parent.scale)},i.prototype.translateInnerPosition=function(){var t=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(t),Math.sin(t)),e.scale(this._innerPosition,this.cache,this._innerPosition.magnitude)},i.prototype.updateScaledInnerPosition=function(){this.scaledInnerPosition.set(this._innerPosition.x*this._parent.scale.x,this._innerPosition.y*this._parent.scale.y)},i}(b),qt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.collisionManager=e.container.getSingleton("CollisionManager"),e.renderer=null,e.colliders=[],e.physics=!0,e}return h(e,t),e.prototype.update=function(){var t=this;this.colliders.forEach((function(e){return t.collisionManager.addCollider(e)}))},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],r=0,o=this.collisionManager.getCollisionsForCollider(n);r<o.length;r++){var s=o[r];if(s.remoteCollider.layer===t)return this.createCollisionData(s)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],o=0,s=this.collisionManager.getCollisionsForCollider(r);o<s.length;o++){var a=s[o];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.id),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){this.renderer&&(this.renderer.active=this.active)},e}(x),Qt=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.rigidBodyManager=t.container.getSingleton("RigidBodyManager"),t}return h(n,i),Object.defineProperty(n.prototype,"velocity",{get:function(){return this.data.velocity},set:function(t){this.data.velocity.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"gravity",{get:function(){return this.data.gravity},set:function(t){this.data.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"rigidBodyType",{get:function(){return this.data.type},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var i,n=t.rigidBodyType,r=t.gravity;this.data={type:n,position:null,gravity:null!==(i=Math.abs(r))&&void 0!==i?i:10,velocity:new e,colliders:[]}},n.prototype.start=function(){if(0===this.getColliders().length)throw new O("RigidBody needs at least one Collider with physics")},n.prototype.update=function(){this.data.type!==t.RigidBodyType.Static&&(this.data.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position,this.data.colliders=this.getColliders(),this.rigidBodyManager.addRigidBodyData(this.data))},n.prototype.getColliders=function(){return this.gameObject.getComponents().reduce((function(t,e){return e instanceof qt&&e.physics?c(c([],t,!0),e.colliders,!0):t}),[])},n}(y),$t="Default",Kt=function(t){function e(e,i,n){void 0===i&&(i="");var r=t.call(this,e)||this;return r.id=d(),r.layer=$t,r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.name=i,r.addComponent(Xt),r.parent=null!=n?n:null,r}return h(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChange(),this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(Xt)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(Qt)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r="string"==typeof e?e:i,o=new t(this.container,this,r);return this.checkMultipleComponent(o,t),this.components.push(o),o.dispatch(u.Init,n),o},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new O("GameObject only allows one component of type "+e.name)},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(u.Destroy)},e.prototype.addChild=function(t,e,i){var n=this.gameObjectManager.addGameObject(t,e,this,i);return n.transform.innerPosition.set(0,0),n.transform.position.copy(this.transform.position),n},e.prototype.getChildren=function(){return this.gameObjectManager.findGameObjectsByParent(this)},e.prototype.getChild=function(t){return this.gameObjectManager.findGameObjectByParent(this,t)},e.prototype.destroyChildren=function(){var t=this;this.gameObjectManager.findGameObjectsByParent(this).forEach((function(e){return t.gameObjectManager.destroyGameObject(e)}))},e.prototype._destroy=function(){var t=this;this.destroyComponents(),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype.destroyComponents=function(){for(var t=0;t<this.components.length;t++)this.components[t].dispatch(u.Destroy),delete this.components[t];this.components=[]},e}(f),Jt=[$t],Zt=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.renderManager=e.container.getSingleton("RenderManager"),e.canvas=e.container.getSingleton("DomManager").canvas,e.viewportRect=new o(0,0,0,0),e.worldSpaceRect=new o(0,0,0,0),e.depth=0,e.layers=Jt,e._zoom=1,e}return h(i,t),Object.defineProperty(i.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new O("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),i.prototype.addLayer=function(t){this.layers.push(t)},i.prototype.init=function(){this.cameraData={position:new e,layers:[],depth:1}},i.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},i.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},i.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},i.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},i}(w),te=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return h(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(Zt)},Object.defineProperty(e.prototype,"layers",{get:function(){return this.camera.layers},set:function(t){this.camera.layers=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this.camera.depth},set:function(t){this.camera.depth=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"zoom",{get:function(){return this.camera.zoom},set:function(t){this.camera.zoom=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"worldSpaceRect",{get:function(){return this.camera.worldSpaceRect},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"viewportRect",{get:function(){return this.camera.viewportRect},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){this.camera.layers.push(t)},e}(Kt),ee=function(t){function e(e,i,n){var r=t.call(this,e)||this;return r.name=i,r.game=n,r.game.config.headless||r.addGameObject(te),r}return h(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(te)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(f),ie=function(){function t(t,e,i,n,r,o){this.shape=t,this.layer=e,this.id=i,this.updateCollisions=n,this.physics=r,this.rigidBody=o}return Object.defineProperty(t.prototype,"x",{get:function(){return this.shape.boundingBox.x},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this.shape.boundingBox.y},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this.shape.boundingBox.x1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this.shape.boundingBox.y1},enumerable:!1,configurable:!0}),t}(),ne=function(){function t(t){this._type=_.Polygon,this._vertices=[],this._boundingBox=new o(0,0,0,0),this._projectionAxes=[],this._position=new e,this._angle=0,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER,this._vertexModel=t;for(var i=0;i<this._vertexModel.length;i++)this._vertices.push(new e),this._projectionAxes.push(new e)}return Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertices",{get:function(){return this._vertices},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"boundingBox",{get:function(){return this._boundingBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(t){this._angle=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vertexModel",{get:function(){return this._vertexModel},set:function(t){this._vertexModel=t},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this._vertexModel.length;t++)this._vertices[t].set(this._vertexModel[t].x*Math.cos(this._angle)-this._vertexModel[t].y*Math.sin(this._angle)+this._position.x,this._vertexModel[t].x*Math.sin(this._angle)+this._vertexModel[t].y*Math.cos(this._angle)+this._position.y)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,i=0;i<this._vertices.length;i++)e.normal(this.projectionAxes[i],e.subtract(this.projectionAxes[i],null!==(t=this._vertices[i+1])&&void 0!==t?t:this._vertices[0],this._vertices[i]))},t}(),re=function(t){function i(i,n,r){var o=t.call(this,[new e(-i/2,-n/2),new e(-i/2,n/2),new e(i/2,n/2),new e(i/2,-n/2)])||this;return o.width=i,o.height=n,o._position.copy(r),o._projectionAxes=[new e,new e],o.update(),o}return h(i,t),i.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},i.prototype.updateProjectionAxes=function(){e.unit(this._projectionAxes[0],e.subtract(this.projectionAxes[0],this._vertices[1],this._vertices[0])),e.normal(this._projectionAxes[1],this._projectionAxes[0])},i}(ne),oe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return h(n,i),n.prototype.init=function(i){var n,r,o,a,h;if(this.container.getConstant("GameConfig").collisions.method!==t.CollisionMethodConfig.SAT)throw new O("Polygon Colliders need SAT collision method.");if(i.vertexModel.length<3)throw new O("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new e)},n.prototype.start=function(){var t;this.colliders.push(new ie(new ne(this.scaledVertexModel),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(se,{collider:this.colliders[0]}))},n.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateShape(),i.prototype.update.call(this)},n.prototype.updateSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.scaledPosition,this.colliders[0].shape.angle=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel,this.colliders[0].shape.update()},n}(qt),se=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return h(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:K.Geometric,location:$.WorldSpace,layer:this.gameObject.layer,position:new e,shape:Q.Polygon,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.shape.position),this.renderData.rotation=this.collider.shape.angle,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},i}(C),ae=function(i){function n(){var n=null!==i&&i.apply(this,arguments)||this;return n.debug=!1,n.offsetX=0,n.offsetY=0,n.realWidth=0,n.realHeight=0,n.realOffset=new e,n.realPosition=new e,n.realRotation=0,n.applyRotation=n.container.getConstant("GameConfig").collisions.method===t.CollisionMethodConfig.SAT,n.innerPosition=new e,n}return h(n,i),n.prototype.init=function(t){var e,i,n,r,o;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new s,this.layer=t.layer},n.prototype.start=function(){var t;this.colliders.push(new ie(new re(this.realWidth,this.realHeight,this.realPosition),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(se,{collider:this.colliders[0]}))},n.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateShape(),i.prototype.update.call(this)},n.prototype.updateRealSize=function(){this.realWidth=this.width*Math.abs(this.gameObject.transform.scale.x),this.realHeight=this.height*Math.abs(this.gameObject.transform.scale.y),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.realRotation=this.applyRotation?this.gameObject.transform.rotation.radians+this.rotation.radians:0},n.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.realPosition,this.colliders[0].shape.angle=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight),this.colliders[0].shape.update()},n}(qt),he=function(){function t(t){this.type=_.Circumference,this.vertices=[new e,new e],this.projectionAxes=[new e],this.boundingBox=new o(0,0,0,0),this.angle=0,this.vertexModel=[],this.radius=0,this._position=new e,this.vertices=[new e,new e],this.radius=t}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},t}(),le=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new e,i.realPosition=new e,i.innerPosition=new e,i}return h(i,t),i.prototype.init=function(t){var e,i,n,r;this.radius=t.radius,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.layer=t.layer},i.prototype.start=function(){var t;this.colliders.push(new ie(new he(this.radius),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt))),this.debug&&(this.renderer=this.gameObject.addComponent(ce,{collider:this.colliders[0]}))},i.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateShape(),t.prototype.update.call(this)},i.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},i.prototype.updatePosition=function(){e.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){e.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.realPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},i.prototype.updateShape=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].shape.position=this.realPosition,this.colliders[0].shape.radius=this.realRadius,this.colliders[0].shape.update()},i}(qt),ce=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e}return h(i,t),i.prototype.init=function(t){var i=t.collider;this.renderData={type:K.Geometric,location:$.WorldSpace,layer:this.gameObject.layer,position:new e,shape:Q.Circumference,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.shape.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},i}(C),ue=function(){function t(t){this.vertexModel=t,this.type=_.Polygon,this.vertices=[new e,new e],this.projectionAxes=[new e],this.boundingBox=new o(0,0,0,0),this.angle=0,this._position=new e}return t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.angle)-this.vertexModel[t].y*Math.sin(this.angle)+this._position.x,this.vertexModel[t].x*Math.sin(this.angle)+this.vertexModel[t].y*Math.cos(this.angle)+this._position.y)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){e.normal(this.projectionAxes[0],e.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),de=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.position=new e,t}return h(n,i),n.prototype.init=function(t){var e,i;this.tilemapRenderer=t.tilemapRenderer,this.layer=t.layer,this.debug=(null!==(e=t.debug)&&void 0!==e?e:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.physics=!0,this.composite=null!==(i=t.composite)&&void 0!==i&&i},n.prototype.start=function(){var e;this.layer=null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,this.scaledTileWidth=this.tilemapRenderer.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tilemapRenderer.tileHeight*this.gameObject.transform.scale.y,this.scaledWidth=this.tilemapRenderer.width*this.scaledTileWidth,this.scaledHeight=this.tilemapRenderer.height*this.scaledTileHeight,this.position.set(this.gameObject.transform.position.x+(this.tilemapRenderer.orientation===t.TilemapOrientation.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([t.TilemapOrientation.Center,t.TilemapOrientation.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==t.TilemapOrientation.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(pe,{colliders:this.colliders}))},n.prototype.useBoxColliders=function(){var t=this;this.tilemapRenderer.tiles.forEach((function(i,n){t.needsCollider(i,n)&&t.colliders.push(new ie(new re(t.scaledTileWidth,t.scaledTileHeight,new e(t.position.x+(n%t.tilemapRenderer.width+.5)*t.scaledTileWidth,t.position.y-(Math.floor(n/t.tilemapRenderer.width)+.5)*t.scaledTileHeight)),t.layer,t.gameObject.id,!1,t.physics,t.hasComponent(Qt)))}))},n.prototype.useLineColliders=function(){var t,i,n=this,r=[],o=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,s=Math.floor(e/n.tilemapRenderer.width);r[s]||(r[s]=[]),r[s+1]||(r[s+1]=[]),o[s]||(o[s]=[]),o[s+1]||(o[s+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[s][i]=!0,r[s][i+1]=!0),n.hasTile(a[2])||(r[s+1][i]=!0,r[s+1][i+1]=!0),n.hasTile(a[1])||(o[s][i]=!0,o[s+1][i]=!0),n.hasTile(a[3])||(o[s][i+1]=!0,o[s+1][i+1]=!0)}}));for(var s=0;s<r.length;s++)for(var a=0;a<r[s].length;a++)!t||!i||s*-this.scaledTileHeight===i.y&&r[s][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),r[s][a]&&(t?i=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight):t=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight));t&&i&&this.addLineCollider(t,i),t=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(s=0;s<o.length;s++)!t||!i||a*this.scaledTileWidth===i.x&&o[s][a]||(this.addLineCollider(t,i),t=void 0,i=void 0),o[s][a]&&(t?i=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight):t=new e(a*this.scaledTileWidth,s*-this.scaledTileHeight));t&&i&&this.addLineCollider(t,i)},n.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},n.prototype.addLineCollider=function(t,e){var i=new ie(new ue([t.clone(),e.clone()]),this.layer,this.gameObject.id,!1,this.physics,this.hasComponent(Qt));i.shape.position=this.position,i.shape.update(),this.colliders.push(i)},n.prototype.needsCollider=function(t,e){var i=this;return 0!==t&&this.getNeighbors(e).some((function(t){return!t||!i.tilemapRenderer.tiles[t]||0===i.tilemapRenderer.tiles[t]}))},n.prototype.getNeighbors=function(t){return[t-this.tilemapRenderer.width>=0?t-this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width>0?t-1:void 0,t+this.tilemapRenderer.width<=this.tilemapRenderer.width*this.tilemapRenderer.height?t+this.tilemapRenderer.width:void 0,t%this.tilemapRenderer.width<this.tilemapRenderer.width-1?t+1:void 0]},n.prototype.update=function(){var t=this;this.colliders.forEach((function(e){return e.layer=t.layer})),i.prototype.update.call(this)},n}(qt),pe=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return h(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:K.Geometric,layer:i.gameObject.layer,location:$.WorldSpace,position:new e,shape:Q.Polygon,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.shape.angle,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(C),ge=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.debug=!1,t.offsetX=0,t.offsetY=0,t.scaledVertexModel=[],t.scaledOffset=new e,t.scaledPosition=new e,t.finalRotation=0,t.innerPosition=new e,t}return h(n,i),n.prototype.init=function(i){var n,r,o,a,h;if(this.container.getConstant("GameConfig").collisions.method!==t.CollisionMethodConfig.SAT)throw new O("Edge Colliders need SAT collision method.");if(i.vertexModel.length<2)throw new O("Edge Collider needs at least 2 vertices.");this.debug=(null!==(n=i.debug)&&void 0!==n?n:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=i.vertexModel,this.offsetX=null!==(r=i.offsetX)&&void 0!==r?r:this.offsetX,this.offsetY=null!==(o=i.offsetY)&&void 0!==o?o:this.offsetY,this.physics=null!==(a=i.physics)&&void 0!==a?a:this.physics,this.rotation=null!==(h=i.rotation)&&void 0!==h?h:new s,this.layer=i.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new e)},n.prototype.start=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders.push(new ie(new ue([this.scaledVertexModel[e],this.scaledVertexModel[e+1]]),null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.gameObject.id,!0,this.physics,this.hasComponent(Qt)));this.debug&&(this.renderer=this.gameObject.addComponent(fe,{colliders:this.colliders}))},n.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateColliders(),i.prototype.update.call(this)},n.prototype.updateSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},n.prototype.updatePosition=function(){e.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},n.prototype.translate=function(){e.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.scaledPosition.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},n.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].shape.position=this.scaledPosition,this.colliders[e].shape.angle=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]],this.colliders[e].shape.update()},n}(qt),fe=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.renderData=[],e.colliders=[],e}return h(i,t),i.prototype.init=function(t){var i=this,n=t.colliders;this.colliders=n,this.colliders.forEach((function(t,n){i.renderData[n]={type:K.Geometric,layer:i.gameObject.layer,location:$.WorldSpace,position:new e,shape:Q.Line,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.shape.position,t.renderData[i].rotation=e.shape.angle,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(C),me=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.spriteDefaultScale=i.container.getConstant("GameConfig").spriteDefaultScale,i.renderData=[],i.innerPosition=new e,i.cachePosition=new e,i.cacheRenderPosition=new e,i.scaledOffset=new e,i}return h(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l;void 0===t&&(t={}),this.sprite=t.sprite,this.offset=null!==(i=t.offset)&&void 0!==i?i:new e,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:new s,this.flipHorizontal=null!==(r=t.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(o=t.flipVertical)&&void 0!==o&&o,this.opacity=null!==(a=t.opacity)&&void 0!==a?a:1,this._tiled=null!==(h=t.tiled)&&void 0!==h?h:new e(1,1),this.maskColor=t.maskColor,this.maskColorMix=null!==(l=t.maskColorMix)&&void 0!==l?l:0,this.tintColor=t.tintColor,this.layer=t.layer},Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new O("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){var t;if(this.sprite&&!0===this.sprite.loaded){this.sprite.scale=null!==(t=this.sprite.scale)&&void 0!==t?t:this.spriteDefaultScale,this.updateRenderDataArray();for(var e=0,i=0;i<this._tiled.x;i++)for(var n=0;n<this._tiled.y;n++)this.updateRenderData(e,i,n),e++}},i.prototype.updateRenderDataArray=function(){if(this.renderData.length!==this._tiled.x*this._tiled.y){this.renderData=[];for(var t=0;t<this._tiled.x*this._tiled.y;t++)this.renderData[t]={type:K.Sprite,location:$.WorldSpace,layer:"",position:new e,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?$.ViewPort:$.WorldSpace,this.renderData[t].layer=null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,this.renderData[t].image=this.sprite.image,this.renderData[t].width=this.sprite.width*Math.abs(this.gameObject.transform.scale.x),this.renderData[t].height=this.sprite.height*Math.abs(this.gameObject.transform.scale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData[t].rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData[t].smooth=this.sprite.smooth,this.renderData[t].alpha=this.opacity,this.renderData[t].maskColor=this.maskColor,this.renderData[t].maskColorMix=this.maskColorMix,this.renderData[t].tintColor=this.tintColor,this.calculateRenderPosition(t,e,i),this.renderManager.addRenderData(this.renderData[t])},i.prototype.calculateRenderPosition=function(t,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[t].width/2*(this._tiled.x-1),this.renderData[t].height/2*(this._tiled.y-1)),e.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[t].width,n*this.renderData[t].height),e.add(this.renderData[t].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(t)},i.prototype.translateRenderPosition=function(t){e.subtract(this.innerPosition,this.renderData[t].position,this.gameObject.transform.position);var i=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[t].position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(i),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(i))},i}(C),ye=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.lastFrameText="",e}return h(i,t),i.prototype.init=function(t){var i,n,r,o,a,h,l,c,u,d;if(this.text=t.text,this.font=null!==(i=t.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=t.fontSize)&&void 0!==n?n:12,this.width=null!==(r=t.width)&&void 0!==r?r:100,this.height=null!==(o=t.height)&&void 0!==o?o:100,this.offset=null!==(a=t.offset)&&void 0!==a?a:new e,this.color=null!==(h=t.color)&&void 0!==h?h:"#000000",this.charRanges=null!==(l=t.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=t.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=t.letterSpacing)&&void 0!==u?u:0,this.smooth=t.smooth,this.rotation=null!==(d=t.rotation)&&void 0!==d?d:new s,this.opacity=t.opacity,this.orientation=t.orientation,this.bitmapMargin=t.bitmapMargin,this.bitmapSpacing=t.bitmapSpacing,this.charRanges.length%2!=0)throw new O("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new O("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:K.Text,location:$.WorldSpace,position:new e,layer:this.gameObject.layer,text:"",font:this.font,fontSize:this.fontSize,bitmap:{charRanges:this.charRanges,margin:this.bitmapMargin,spacing:this.bitmapSpacing},smooth:this.smooth}},i.prototype.update=function(){var t,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?$.ViewPort:$.WorldSpace,this.renderData.text=this.text!==this.lastFrameText?this.crop():this.renderData.text,this.renderData.fontSize=this.fontSize,this.renderData.color=this.color,this.renderData.orientation=this.orientation,this.renderData.lineSeparation=this.lineSeparation,this.renderData.letterSpacing=this.letterSpacing,this.renderData.rotation=null!==(i=this.gameObject.transform.rotation.radians+(null===(t=this.rotation)||void 0===t?void 0:t.radians))&&void 0!==i?i:0,this.renderData.alpha=this.opacity,e.add(this.renderData.position,this.gameObject.transform.position,this.offset),this.renderManager.addRenderData(this.renderData),this.lastFrameText=this.text)},i.prototype.crop=function(){var t;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,r=this.text.split("\n");n<r.length;n++)for(var o=0,s=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];o<s.length;o++){var a=s[o];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(C),xe=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.offset=new e,i.rotation=new s,i.opacity=1,i.innerPosition=new e,i.scaledOffset=new e,i}return h(i,t),i.prototype.init=function(t){var i,n,r,o;this.width=t.width,this.height=t.height,this.color=t.color,this.offset=null!==(i=t.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=t.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:this.opacity,this.layer=t.layer,this.renderData={type:K.Mask,layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,location:this.gameObject.ui?$.ViewPort:$.WorldSpace,position:new e,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?$.ViewPort:$.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.color=this.color,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData)},i.prototype.calculateRenderPosition=function(){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),e.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){e.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var t=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData.position.set(this.gameObject.transform.position.x+this.innerPosition.magnitude*Math.cos(t),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(t))},i}(C),ve=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.tilesetTileIds=[],e.chunks=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e.renderData=[],e}return h(i,t),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,r=t.tileWidth,o=t.tileHeight,s=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=r,this.tileHeight=o,this.layer=s,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(i){return t.processChunk(i,e)})):t.processChunk(e,e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(t,i){var n,r=this,o={type:K.Tilemap,layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,location:this.gameObject.ui?$.ViewPort:$.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:t.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:t.data.map((function(t){return r.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};t.type&&"tilelayer"===t.type?this.tiles=o.tiles:o.tiles.forEach((function(e,i){r.tiles[r.tiledData.width*(t.y+Math.floor(i/t.width))+t.x+i%t.width]=e})),this.renderData.push(o),this.chunks.push(t)},i.prototype.getTilesetTileId=function(t){return this.tilesetTileIds[t]||(this.tilesetTileIds[t]=this.tiledData.tilesets.reduce((function(e,i){return t>=i.firstgid?t-i.firstgid+1:e}),0)),this.tilesetTileIds[t]},i.prototype.updateRenderData=function(){var t=this;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.tiledData.width*this.scaledTileWidth,this.realHeight=this.tiledData.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,e.position.set(t.gameObject.transform.position.x+t.chunks[i].x*t.scaledTileWidth,t.gameObject.transform.position.y+t.chunks[i].y*t.scaledTileHeight),e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.alpha}))},i}(C),be=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderManager=e.container.getSingleton("RenderManager"),e.tiles=[],e.scaledTileWidth=0,e.scaledTileHeight=0,e}return h(i,t),i.prototype.init=function(t){var i,n=this,r=t.tiles,o=t.tileset,s=t.tileWidth,a=t.tileHeight,h=t.width,l=t.layer,c=t.orientation,u=t.alpha,d=t.tintColor,p=t.smooth;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=o,this.width=h,this.tileWidth=s,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=u,this.tintColor=d,this.renderData={type:K.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?$.ViewPort:$.WorldSpace,position:new e,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:this.orientation,smooth:p},this.updateRenderData()},i.prototype.update=function(){this.updateRenderData(),this.renderManager.addRenderData(this.renderData)},i.prototype.updateRenderData=function(){var t;this.scaledTileWidth=this.tileWidth*this.gameObject.transform.scale.x,this.scaledTileHeight=this.tileHeight*this.gameObject.transform.scale.y,this.realWidth=this.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.position.copy(this.gameObject.transform.position),this.renderData.tintColor=this.tintColor,this.renderData.alpha=this.alpha,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},i}(C),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},we="default",Ce=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.timeManager=e.container.getSingleton("TimeManager"),e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return h(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e=we),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new _e(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t=we),!1!==this.active){if(!1===this.animations.has(t))throw new O("Animation with name "+t+" does not exist.");this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(y),_e=function(){function t(t){this._sprite=null,this._restarted=!1,this.currentFrame=0,this.frameTime=0,this._animation=t}return Object.defineProperty(t.prototype,"sprite",{get:function(){return this._sprite},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"restarted",{get:function(){return this._restarted},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){return this._animation.loop},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this.currentFrame=0,this.frameTime=0,this._restarted=!0},t.prototype.playFrame=function(t){this._restarted=!1,this.frameTime>=1/this._animation.framerate&&(this.frameTime=0,this.currentFrame=this.currentFrame+1===this._animation.sprites.length?0:this.currentFrame+1,this._restarted=0===this.currentFrame),this._sprite=this._animation.sprites[this.currentFrame],this.frameTime+=t},t}(),je=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Oe=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.volume=1,e.loop=!1,e.audio=null,e.clones=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e.audio.removeEventListener("ended",e.audioEventHandler))},e.userinputEventHandler=function(){je.forEach((function(t){window.removeEventListener(t,e.userinputEventHandler)})),e.audio.play()},e}return h(e,t),e.prototype.init=function(t){var e,i,n;void 0===t&&(t={}),this.audio=null!==(e=t.audio)&&void 0!==e?e:this.audio,this.volume=null!==(i=t.volume)&&void 0!==i?i:this.volume,this.loop=null!==(n=t.loop)&&void 0!==n?n:this.loop},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 je.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.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop()},e}(y),Pe=function(){function t(t){var e,i=this;this._width=null,this._height=null,this._loaded=!1,this.image=t.image,this.smooth=null!==(e=t.smooth)&&void 0!==e&&e,this.slice=t.slice,this.scale=t.scale,this.slice&&(this._width=this.slice.width,this._height=this.slice.height);var n=function(){var t,e;i._width=null!==(t=i._width)&&void 0!==t?t:i.image.naturalWidth,i._height=null!==(e=i._height)&&void 0!==e?e:i.image.naturalHeight,i._loaded=!0};this.image.naturalWidth?n():this.image.addEventListener("load",(function(){return n()}))}return Object.defineProperty(t.prototype,"width",{get:function(){var t,e;return null!==(e=this._width*(null===(t=this.scale)||void 0===t?void 0:t.x))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){var t,e;return null!==(e=this._height*(null===(t=this.scale)||void 0===t?void 0:t.y))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();t.ButtonType=void 0,(Gt=t.ButtonType||(t.ButtonType={}))[Gt.Rectangle=0]="Rectangle",Gt[Gt.Circumference=1]="Circumference";var Re=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.width=100,t.height=100,t.radius=50,t.touchEnabled=!0,t._offset=new e,t.pressed=!1,t.mouse=t.container.getSingleton("InputManager").mouse,t.touch=t.container.getSingleton("InputManager").touch,t.position=new e,t.distance=new e,t.pressedLastFrame=!1,t.scaled={width:0,height:0,radius:0,offset:new e},t}return h(n,i),Object.defineProperty(n.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),n.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,r=t.touchEnabled,o=t.width,s=t.offset;this.type=e,this.width=null!=o?o:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this._offset=null!=s?s:this._offset},n.prototype.update=function(){this.scale(),e.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},n.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this._offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this._offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*this.gameObject.transform.scale.magnitude},n.prototype.resolveMouseAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=r(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&r(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},n.prototype.resolveMouseAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},n.prototype.resolveTouchAndRectangle=function(){this.type===t.ButtonType.Rectangle&&(this.pressed||(this.pressed=this.position.x+this.scaled.width/2>=this.touch.positionInViewport.x-this.touch.radius.x&&this.position.x-this.scaled.width/2<=this.touch.positionInViewport.x+this.touch.radius.x&&this.position.y+this.scaled.height/2>=this.touch.positionInViewport.y-this.touch.radius.y&&this.position.y-this.scaled.height/2<=this.touch.positionInViewport.y+this.touch.radius.y))},n.prototype.resolveTouchAndCircumference=function(){this.type===t.ButtonType.Circumference&&(e.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},n}(m),Te=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new e,i}return h(i,t),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){N.mouse.leftButtonPressed&&!1===this.mousePressed&&(e.round(this.position,e.add(this.position,this.camera.transform.position,e.scale(this.position,N.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: "+this.position.x+", y: "+this.position.y+"}")),this.mousePressed=N.mouse.leftButtonPressed},i}(Kt);t.Animation=Me,t.Animator=Ce,t.AssetManager=H,t.AudioPlayer=Oe,t.BallCollider=le,t.BoxCollider=ae,t.Button=Re,t.Camera=Zt,t.ColliderData=ie,t.Component=m,t.DomManager=z,t.EdgeCollider=ge,t.Game=Yt,t.GameCamera=te,t.GameObject=Kt,t.GameObjectManager=q,t.GamepadController=D,t.GamepadData=A,t.InputManager=N,t.KeyboardController=E,t.LAYER_DEFAULT=$t,t.MaskRenderer=xe,t.MouseController=B,t.PhysicsComponent=v,t.PolygonCollider=oe,t.PolygonColliderRenderer=se,t.PreRenderComponent=M,t.Rectangle=o,t.RigidBody=Qt,t.Rotation=s,t.Scene=ee,t.SceneManager=Y,t.SpacePointer=Te,t.Sprite=Pe,t.SpriteRenderer=me,t.TextRenderer=ye,t.TiledTilemapRenderer=ve,t.TilemapCollider=de,t.TilemapRenderer=be,t.TimeManager=X,t.TouchController=W,t.Transform=Xt,t.Vector2=e,t.between=r,t.clamp=i,t.fixedRound=n,t.randomFloat=(t,e,i=2)=>n(Math.random()*(e-t)+t,i),t.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,t.range=(t,e,i=1)=>{const n=[];for(let r=t;r<=e;r+=i)n.push(r);return n},Object.defineProperty(t,"__esModule",{value:!0})}));
|