angry-pixel 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -1 +1 @@
1
- class t{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 t(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}class e{constructor(e,i,n,s){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,s)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(i){return i instanceof e?i.x1<=this.x1&&i.x>=this.x&&i.y1<=this.y1&&i.y>=this.y:i instanceof t&&!(i.x<this.x||i.y<this.y||i.x>=this.x1||i.y>=this.y1)}}const i=(t,e,i)=>Math.min(i,Math.max(e,t)),n=(t,e)=>Math.round(Math.random()*(e-t))+t,s=(t,e,i=2)=>r(Math.random()*(e-t)+t,i),r=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),o=(t,e,i=1)=>{const n=[];for(let s=t;s<=e;s+=i)n.push(s);return n},a=(t,e,i)=>t>=e&&t<=i;class h{constructor(e=null,i=null){this._degrees=0,this._radians=0,this._direction=new t,e?this.radians=e:i&&(this.degrees=i)}set degrees(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()}get degrees(){return this._degrees}set radians(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()}get radians(){return this._radians}get direction(){return this._direction}updateDirection(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}var l=function(t,e){return l=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])},l(t,e)};function c(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}l(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var d=function(){return d=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},d.apply(this,arguments)};function u(t,e,i){if(i||2===arguments.length)for(var n,s=0,r=e.length;s<r;s++)!n&&s in e||(n||(n=Array.prototype.slice.call(e,0,s)),n[s]=e[s]);return t.concat(n||Array.prototype.slice.call(e))}var p,g=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"}(p||(p={}));var m,f=function(){function t(t,e,i,n,s,r,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=s,this.sceneManager=r,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(p.Start),this.inputManager.update(),this.dispatchFrameEvent(p.Update),this.dispatchFrameEvent(p.UpdateEngine),this.dispatchFrameEvent(p.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(p.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(p.UpdatePreRender),this.dispatchFrameEvent(p.UpdateCamera),this.dispatchFrameEvent(p.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(p.UpdatePhysics),this.dispatchFrameEvent(p.UpdateCollider),this.dispatchFrameEvent(p.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return u(u([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==p.Start&&t!==p.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}(),y=function(){function t(t){this.updateEvent=p.Update,this.started=!1,this.container=t,this.gameObjectManager=this.container.getSingleton("GameObjectManager")}return t.prototype.dispatch=function(t,e){t===p.Init&&this.init?this.init(e):t!==p.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===p.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}(),x=function(t){function e(e,i,n){void 0===n&&(n="");var s=t.call(this,e)||this;return s.id=g(),s.allowMultiple=!0,s._active=!0,s.gameObject=i,s.name=n,s}return c(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}(y),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateEngine,e}return c(e,t),e}(x),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCollider,e}return c(e,t),e}(x),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePhysics,e}return c(e,t),e}(x),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateTransform,e}return c(e,t),e}(x),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePreRender,e}return c(e,t),e}(x),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCamera,e}return c(e,t),e}(x),j=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateRender,e}return c(e,t),e}(x);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font"}(m||(m={}));var O,P,R,A,S=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,m.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,m.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url(".concat(e,")")),n=this.createAsset(e,m.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===m.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===m.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===m.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}(),T=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return c(e,t),e}(Error),D=function(){function t(t,e,i){if(this._canvas=null,!t)throw new T("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}(),F=function(){function t(t){this.container=t,this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var s=new t(this.container,n,i);return this.gameObjects.push(s),s.dispatch(p.Init,e),s},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(p.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),E=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 B),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}(),B=function(){function e(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new t,this._leftStickAxes=new t,this._rightStickAxes=new t}return e.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(e.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),e.prototype.getButtonPressed=function(t){return this.buttons.get(t)},e.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(e.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(e.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),e.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})},e}(),I=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}(),U=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}(),G=function(){function e(e){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new t(0,0),this._hasMoved=!1,this.lastPositionInViewport=new t(0,0),this.canvas=e,this.setup()}return Object.defineProperty(e.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),e.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},e.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)}))},e.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},e.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},e.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)},e}(),L=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var s=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new T("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(s.container,e,s.container.getConstant("Game"));return s.currentScene=n,n.dispatch(p.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new T("There is no opening scene");this._loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new T("Scene with name ".concat(t," does not exists"));this.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(p.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),V=[60,120,180,240],W=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!V.includes(t))throw new T("Invalid Physics frame rate. Allowed: [".concat(V.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}(),k=function(){function e(e){var i=this;this._touching=!1,this._positionInViewport=new t(0,0),this._radius=new t(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=e,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(e.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"radius",{get:function(){return this._radius},enumerable:!1,configurable:!0}),e.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))},e}(),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}(),Y=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}(),N=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}(),$=function(){function t(t,e,i,n){this.timeManager=t,this.physicsManager=e,this.gameObjectManager=i,this.sceneManager=n,this.running=!1,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.physicsManager.clear()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(p.Start),this.dispatchFrameEvent(p.Update),this.dispatchFrameEvent(p.UpdateEngine),this.dispatchFrameEvent(p.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.update()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(p.UpdatePhysics),this.dispatchFrameEvent(p.UpdateCollider),this.dispatchFrameEvent(p.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return u(u([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==p.Start&&t!==p.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"}(O||(O={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(P||(P={})),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"}(R||(R={}));class K{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===P.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 s=Math.abs(Math.sin(n)),r=Math.abs(Math.cos(n)),o=s*i+r*e,a=s*e+r*i;this.object.x=t.x-o/2,this.object.x1=t.x+o/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:s,rotation:r}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=s?s:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===O.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:s}}=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)*s+s)&&this.viewport.y<=this.object.y1-(e/i|0)*s?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case R.Mask:case R.Sprite:this.setObjectForResizeable(t);break;case R.Geometric:this.setObjectForGeometric(t);break;case R.Text:this.setObjectForText(t);break;case R.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===R.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}}!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(A||(A={}));class J{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(t){this.cullingManager.applyCulling(t,this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).map((t=>t.type===R.Tilemap?(t=>{const e=Object.assign(Object.assign({},t),{culledTiles:[],tilemap:Object.assign(Object.assign({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new Q});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,(t=>{t.renderPosition.set(t.position.x+(t.orientation!==A.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===A.RightDown?-t.tilemap.realHeight/2:t.orientation===A.RightUp?t.tilemap.realHeight/2:0))})(e),e})(t):t))).forEach((e=>this.webglManager.render(e,t)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}}var Z;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(Z||(Z={}));class tt{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(Z.WebGL2)?Z.WebGL2:null!==this.canvas.getContext(Z.LegacyWebGL)?Z.LegacyWebGL:void 0}}class et{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 it(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,s=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,s),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,s+=this.bitmapSize);return e}}class it{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 nt{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),s=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,s),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class st{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===Z.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 rt{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 ot="undefined"!=typeof Float32Array?Float32Array:Array;function at(){var t=new ot(16);return ot!=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 ht(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 lt(t,e,i){var n,s,r,o,a,h,l,c,d,u,p,g,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(n=e[0],s=e[1],r=e[2],o=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],u=e[9],p=e[10],g=e[11],t[0]=n,t[1]=s,t[2]=r,t[3]=o,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=u,t[10]=p,t[11]=g,t[12]=n*m+a*f+d*y+e[12],t[13]=s*m+h*f+u*y+e[13],t[14]=r*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function ct(t,e,i){var n=i[0],s=i[1],r=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function dt(t,e,i){var n=Math.sin(i),s=Math.cos(i),r=e[0],o=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],u=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*s+l*n,t[1]=o*s+c*n,t[2]=a*s+d*n,t[3]=h*s+u*n,t[4]=l*s-r*n,t[5]=c*s-o*n,t[6]=d*s-a*n,t[7]=u*s-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 ut;function pt(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function gt(t,e,i){var n=new ot(3);return n[0]=t,n[1]=e,n[2]=i,n}function mt(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}pt(),function(){var t;t=new ot(4),ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),pt(),gt(1,0,0),gt(0,1,0),mt(),mt(),ut=new ot(9),ot!=Float32Array&&(ut[1]=0,ut[2]=0,ut[3]=0,ut[5]=0,ut[6]=0,ut[7]=0),ut[0]=1,ut[4]=1,ut[8]=1,function(){var t=new ot(2);ot!=Float32Array&&(t[0]=0,t[1]=0)}();const ft=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},yt=(t,e,i,n)=>{var s,r;(function(t,e,i,n,s,r,o){var a=1/(e-i),h=1/(n-s),l=1/(r-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(s+n)*h,t[14]=(o+r)*l,t[15]=1})(t=ht(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),lt(t,t,[0,0,0]),n===P.WorldSpace&&ct(t,t,[null!==(s=i.zoom)&&void 0!==s?s:1,null!==(r=i.zoom)&&void 0!==r?r:1,1])};class xt{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at();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 O.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case O.Line:this.renderLines(t,e,this.gl.LINES,i);break;case O.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var s;const r=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(r)&&this.vertices.set(r,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(r);this.lastVertices===r&&n===R.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW)),this.lastVertices=r,this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),dt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),yt(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}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,o.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ct(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),yt(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:s,a:r}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,s,r),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class vt{constructor(t,e){this.gl=t,this.programManager=e,this.type=R.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n,s;i!==R.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=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),dt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),yt(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:r,g:o,b:a,a:h}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class bt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at(),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,s,r,o;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),dt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=ht(this.textureMatrix),t.slice&&(lt(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),ct(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),yt(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!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:s}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,s)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}var Mt;!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Mt||(Mt={}));const wt=new Q,Ct=new Q,_t=[32,126,161,255],jt=Mt.Center;class Ot{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=R.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new Q,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n;if(!t.text)return;this.setDefaultValues(t);const s=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(s,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=ht(this.modelMatrix),this.setPositionFromOrientation(t),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),dt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=ht(this.textureMatrix),yt(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 r=this.textureManager.getOrCreateTextureFromCanvas(s.fontFaceFamily,s.canvas,t.smooth);this.lastTexture===r&&i===R.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=r),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:o,g:a,b:h,a:l}=ft(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,o,a,h,l),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}setDefaultValues(t){var e,i,n,s,r,o,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:wt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:Ct,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(s=t.bitmap.charRanges)&&void 0!==s?s:_t):t.bitmap={margin:wt,spacing:Ct,fontSize:64,charRanges:_t},t.color=null!==(r=t.color)&&void 0!==r?r:"#000000",t.letterSpacing=null!==(o=t.letterSpacing)&&void 0!==o?o:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:jt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:s,lineSeparation:r}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;s/=i,r/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,o),o=0,a-=1+r;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(o,a-1,o+e,a-1,o,a,o,a,o+e,a-1,o+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,r=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(r+n.margin.y)/t.canvas.width,d=(i+c.width+n.spacing.x)/t.canvas.width,u=(r+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,u,d,u,h,l,h,l,d,u,d,l),o+=e+s}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-1)*i)}setPositionFromOrientation(t){this.modelPosition.set(t.position.x+(t.orientation===Mt.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Mt.Center||t.orientation===Mt.RightCenter?this.textSize.y/2:t.orientation===Mt.RightUp?this.textSize.y:0))}}class Pt{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=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n,s,r,o;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=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),dt(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=ht(this.textureMatrix),ct(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),yt(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===R.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!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:s}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,s)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,s,r,o,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!==(s=t.margin.x)&&void 0!==s?s:0)+(null!==(r=t.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=t.tileHeight+(null!==(o=t.margin.y)&&void 0!==o?o:0)+(null!==(a=t.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y}generateVertices({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const s=n%e.width-e.width/2,r=i/2-Math.floor(n/e.width);this.posVertices.push(s,r-1,s+1,r-1,s,r,s,r,s+1,r-1,s+1,r);const o=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(o,a+this.tileset.texHeight,o+this.tileset.texWidth,a+this.tileset.texHeight,o,a,o,a,o+this.tileset.texWidth,a+this.tileset.texHeight,o+this.tileset.texWidth,a)}))}}class Rt{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 At{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 St{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=ft(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}class Tt{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 Tt(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}class Dt{constructor(t,e,i,n){this._position=new Tt,this._center=new Tt,this._width=0,this._height=0,this.set(t,e,i,n)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(t){return t instanceof Dt?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Tt&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const Ft=(t,e,i)=>Math.min(i,Math.max(e,t));class Et{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:n,position:s,rotation:r,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:n,position:null!=s?s:new Tt,rotation:null!=r?r:0,group:o,onCollision:a}}}class Bt{constructor(t,e=0){this.area=new Dt(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}resize(t){this.clear(),this.area.copy(t)}clear(){this.items=[],this.children.forEach((t=>t.clear())),this.children=[]}insert(t,e){0===this.children.length&&this.items.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.items.push([t,e])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new Dt(this.area.x,this.area.y,t,e),new Dt(this.area.x,this.area.y+e,t,e),new Dt(this.area.x+t,this.area.y+e,t,e),new Dt(this.area.x+t,this.area.y,t,e)].map((t=>new Bt(t,this.depth+1))),this.items.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.items=[]}insertItemIntoChildren(t,e){this.getChildrenForArea(e).forEach((i=>i.insert(t,e)))}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((i=>e.push(...i.retrieve(t)))):this.items.forEach((t=>e.push(t[0]))),e}getChildrenForArea(t){const e=[];return t.x<=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[0]),t.x<=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[1]),t.x1>=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[2]),t.x1>=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[3]),e}}const It=(t,e,i,n)=>Math.min((t-e)/i|0,n-1);class Ut{constructor(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}get subdivisions(){return this._subdivisions}set subdivisions(t){this._subdivisions=Ft(t,1,20)}resize(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(let t=0;t<this._subdivisions;t++){this.itemsInCells[t]=[];for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}}clear(){for(let t=0;t<this._subdivisions;t++)for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[e][i].push(t)}retrieve(t){const e=[];this.updateCoordinates(t);for(let t=this.coordinates.x0;t<=this.coordinates.x1;t++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[t][i].forEach((t=>e.includes(t)?null:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=It(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=It(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=It(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=It(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}var Gt,Lt,Vt,Wt;!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Gt||(Gt={}));class kt{constructor(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Tt,this.maxArea=new Tt,this.newArea=new Dt(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:Gt.QuadTree,i)}setupBroadPhaseResolver(t,e){this.collisionArea=null!=e?e:new Dt(0,0,0,0),this.fixedCollisionArea=!!e,t===Gt.SpartialGrid?this.broadPhaseResolver=new Ut(this.collisionArea):this.broadPhaseResolver=new Bt(this.collisionArea)}addCollider(t){this.colliders[t.id]=t}getCollider(t){return this.colliders[t]}removeCollider(t){delete this.colliders[t.id]}clearColliders(){this.colliders=[]}getCollisionsForCollider(t){return t.active?this.collisions.filter((e=>e.localCollider.id===t.id)):[]}refreshCollisionsForCollider(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((e=>e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id)),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))}resolve(){this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((t=>t.active)),this.broadPhaseResolver.clear(),this.activeColliders.forEach((t=>{this.updateShape(t)})),!1===this.fixedCollisionArea&&(this.updateNewArea(),!1===this.newArea.equals(this.collisionArea)&&(this.collisionArea.copy(this.newArea),this.broadPhaseResolver.resize(this.collisionArea))),this.checkForSpartialGridResize(),this.activeColliders.forEach((({id:t,shape:{boundingBox:e}})=>this.broadPhaseResolver.insert(t,e))),this.updateCollisions())}updateShape(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()}updateNewArea(){this.activeColliders.forEach((({shape:{boundingBox:t}})=>{this.minArea.set(Math.min(t.x,this.minArea.x),Math.min(t.y,this.minArea.y)),this.maxArea.set(Math.max(t.x1,this.maxArea.x),Math.max(t.y1,this.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}checkForSpartialGridResize(){this.broadPhaseResolver instanceof Ut&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)}updateCollisions(){this.activeColliders.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase(t){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t])).filter((e=>this.collisionMatrix.some((i=>i[0]===t.layer&&i[1]===e.layer||i[1]===t.layer&&i[0]===e.layer)))):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t]))}narrowPhase(t,e){e.filter((e=>!(t.group&&e.group&&e.group===t.group||t.id===e.id))).forEach((e=>{if(this.isResolved(t,e))return;const i=this.method.getCollisionResolution(t.shape,e.shape);null!==i&&(this.collisions.push({localCollider:t,remoteCollider:e,resolution:i},{localCollider:e,remoteCollider:t,resolution:{direction:i.displacementDirection,displacementDirection:i.direction,penetration:i.penetration}}),t.onCollision&&t.onCollision(i))}))}isResolved(t,e){for(const i of this.collisions)if(i.localCollider.id===t.id&&i.remoteCollider.id===e.id)return!0;return!1}}!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Lt||(Lt={}));class Ht{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Lt.Polygon&&e.type===Lt.Polygon?this.AABBResolver.resolve(t,e):t.type===Lt.Circumference&&e.type===Lt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Lt.Polygon&&e.type===Lt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Lt.Circumference&&e.type===Lt.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(Vt||(Vt={}));class zt{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Lt.Circumference&&e.type===Lt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class Yt{constructor(){this.direction=new Tt,this.displacementDirection=new Tt}resolve({boundingBox:t},{boundingBox:e}){return this.overlapX=Math.min(t.x1,e.x1)-Math.max(t.x,e.x),this.overlapY=Math.min(t.y1,e.y1)-Math.max(t.y,e.y),this.overlapX<0||this.overlapY<0?null:(this.checkOverlapForLines(t,e),this.direction.set(Math.sign(e.center.x-t.center.x),Math.sign(e.center.y-t.center.y)),this.preventContainment(t,e),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),Tt.unit(this.displacementDirection,this.displacementDirection),{direction:Tt.scale(new Tt,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),penetration:this.minOverlap})}checkOverlapForLines(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))}preventContainment(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){const i=Math.abs(t.y-e.y),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),n=Math.abs(t.x1-e.x1);this.overlapX+=i<n?i:n}}}class Nt{constructor(){this.closestPoint=new Tt,this.distance=new Tt,this.direction=new Tt}resolve(t,e,i=!1){return this.closestPoint.set(Ft(t.position.x,e.boundingBox.x,e.boundingBox.x1),Ft(t.position.y,e.boundingBox.y,e.boundingBox.y1)),Tt.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Tt.unit(this.direction,this.distance),{direction:i?Tt.scale(new Tt,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Tt.scale(new Tt,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class Xt{constructor(){this.distance=new Tt,this.direction=new Tt}resolve(t,e){return Tt.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Tt.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Tt.scale(new Tt,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class qt{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Tt,this.distance=new Tt(1/0,1/0),this.cache=new Tt}resolve(t,e){this.minOverlap=1/0,t.type===Lt.Circumference?this.setCircumferenceAxis(t,e):e.type===Lt.Circumference&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?null:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t.type===Lt.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Lt.Circumference&&this.setCircumferenceVertices(e,this.axes[i]),this.projectShapeOntoAxis(this.projA,t,this.axes[i]),this.projectShapeOntoAxis(this.projB,e,this.axes[i]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;if(this.invertAxis=!0,this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){const t=Math.abs(this.projA.min-this.projB.min),e=Math.abs(this.projA.max-this.projB.max);t<e?this.currentOverlap+=t:(this.currentOverlap+=e,Tt.scale(this.axes[i],this.axes[i],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[i]),this.invertAxis&&this.projA.max<this.projB.max&&Tt.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Tt.scale(new Tt,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(Tt.dot(i,e),t.min),t.max=Math.max(Tt.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Tt.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Tt.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Tt.add(t.vertices[0],t.position,Tt.scale(this.cache,Tt.unit(this.cache,e),-t.radius)),Tt.add(t.vertices[1],t.position,Tt.scale(this.cache,Tt.unit(this.cache,e),t.radius))}}class $t{constructor(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}addCollider(t){const e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e}removeCollider(t){this.collisionManager.removeCollider(t)}getCollisionsForCollider(t){return this.collisionManager.getCollisionsForCollider(t)}addRigidBody(t){const e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e}removeRigidBody(t){this.rigidBodyManager.removeRigidBody(t)}resolve(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)}clear(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()}}class Kt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:n,velocity:s,onResolve:r}){if(0===t.length)throw new Error("RigidBody needs at least one collider");return{id:++this.lastId,active:!0,colliderIds:t,type:e,gravity:null!=i?i:0,position:null!=n?n:new Tt,velocity:null!=s?s:new Tt,onResolve:r}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Wt||(Wt={}));const Qt=["x","y"];class Jt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Tt,this.displacement=new Tt,this.cacheDisplacement=0}addRigidBody(t){this.rigidBodies[t.id]=t}removeRigidBody(t){delete this.rigidBodies[t.id]}clearRigidBodies(){this.rigidBodies=[]}resolve(t){this.activeRigidBodies=this.rigidBodies.filter((t=>t.active)),this.colliders=this.activeRigidBodies.reduce(((t,e)=>[...t,...e.colliderIds]),[]),this.activeRigidBodies.forEach((e=>{e.type===Wt.Dynamic?this.dynamicUpdate(e,t):e.type===Wt.Kinematic&&this.kinematicUpdate(e,t),e.onResolve&&e.onResolve(e)}))}dynamicUpdate(t,e){this.applyGravity(t,e),Qt.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Tt.add(t.position,t.position,Tt.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Tt.add(t.position,t.position,this.velocity),this.collisionManager.refreshCollisionsForCollider(t)}))}applyGravity(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)}applyVelocity(t,e,i){this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[i]+=this.velocity[i],this.collisionManager.refreshCollisionsForCollider(t)})))}obtainDisplacement(t,e){this.displacement[e]=0,this.getCollisions(t).forEach((t=>{this.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,this.displacement[e]=Math.abs(this.displacement[e])>Math.abs(this.cacheDisplacement)?this.displacement[e]:this.cacheDisplacement}))}applyReposition(t,e){0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[e]+=this.displacement[e],this.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))}getCollisions(t){return t.colliderIds.map((t=>this.collisionManager.getCollider(t))).filter((t=>t.active&&t.physics)).reduce(((t,e)=>(t.push(...this.collisionManager.getCollisionsForCollider(e).filter((t=>t.remoteCollider.physics&&this.colliders.includes(t.remoteCollider.id)))),t)),[])}}class Zt{constructor(t){this.radius=t,this.type=Lt.Circumference,this.boundingBox=new Dt(0,0,0,0),this.vertices=[new Tt,new Tt],this.projectionAxes=[new Tt],this._position=new Tt}set position(t){this._position.copy(t)}get position(){return this._position}update(){this.updateBoundingBox()}updateBoundingBox(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}class te{constructor(t){this.vertexModel=t,this.type=Lt.Polygon,this.vertices=[new Tt,new Tt],this.projectionAxes=[new Tt],this.boundingBox=new Dt(0,0,0,0),this.rotation=0,this._position=new Tt}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}set position(t){this._position.copy(t)}get position(){return this._position}updateVertices(){for(let t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)}updateBoundingBox(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y}updateProjectionAxes(){Tt.normal(this.projectionAxes[0],Tt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class ee{constructor(t){this.vertexModel=t,this.type=Lt.Polygon,this.vertices=[],this.boundingBox=new Dt(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Tt,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(let t=0;t<this.vertexModel.length;t++)this.vertices.push(new Tt),this._projectionAxes.push(new Tt)}set position(t){this._position.copy(t)}get position(){return this._position}get projectionAxes(){return this._projectionAxes}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}updateVertices(){for(let t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)}updateBoundingBox(){this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((t=>{this.boxMinX=Math.min(t.x,this.boxMinX),this.boxMinY=Math.min(t.y,this.boxMinY),this.boxMaxX=Math.max(t.x,this.boxMaxX),this.boxMaxY=Math.max(t.y,this.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)}updateProjectionAxes(){var t;for(let e=0;e<this.vertices.length;e++)Tt.normal(this._projectionAxes[e],Tt.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class ie extends ee{constructor(t,e){super([new Tt(-t/2,-e/2),new Tt(-t/2,e/2),new Tt(t/2,e/2),new Tt(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Tt,new Tt]}updateSize(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)}updateProjectionAxes(){Tt.unit(this.projectionAxes[0],Tt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Tt.normal(this.projectionAxes[1],this.projectionAxes[0])}}var ne,se=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new W(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new F(t)})),t.add("PhysicsManager",(function(){return(({collisionArea:t,collisionMatrix:e,collisionMethod:i,collisionBroadPhaseMethod:n}={})=>{const s=new Xt,r=i===Vt.AABB?new Ht(new Yt,new Nt,s):new zt(s,new qt),o=new kt(r,n,t,e),a=new Et,h=new Jt(o),l=new Kt;return new $t(o,a,h,l)})(e.collisions)})),e.headless?t.add("IterationManager",(function(){return new $(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))})):(t.add("DomManager",(function(){return new D(e.containerNode,e.gameWidth,e.gameHeight)})),t.add("RenderManager",(function(){return(t=>{const e=new tt(t),i=e.gl,n=e.contextVersion,s=new st(i,n,new nt(i,new rt(i))),r=new At(new Rt(i)),o=new St(i,s,new Map([[R.Sprite,new bt(i,s,r)],[R.Text,new Ot(i,s,r,new et)],[R.Tilemap,new Pt(i,s,r)],[R.Geometric,new xt(i,s)],[R.Mask,new vt(i,s)]]));return new J(o,new K(i))})(t.getSingleton("DomManager").canvas)})),re(t),t.add("AssetManager",(function(){return new S})),t.add("IterationManager",(function(){return new f(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))),t.add("SceneManager",(function(){return new L(t,e.headless?void 0:t.getSingleton("RenderManager"))})),oe(t,e)},re=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new I(new G(e.canvas),new U(e.canvas),new E,new k(e.canvas))}))},oe=function(t,e){e.headless||(H.initialize(t.getSingleton("AssetManager")),z.initialize(t.getSingleton("DomManager")),Y.initialize(t.getSingleton("InputManager"))),N.initialize(t.getSingleton("SceneManager")),X.initialize(t.getSingleton("TimeManager")),q.initialize(t.getSingleton("GameObjectManager"))},ae=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 T("There is already an object constructor with the name ".concat(t));this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new T("Invalid object constructor name: ".concat(t));return!1===this.instances.has(t)&&this.instances.set(t,this.constructors.get(t)()),this.instances.get(t)},t.prototype.getTranscient=function(t){if(!1===this.constructors.has(t))throw new T("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new T("There is already a constant value with the name ".concat(t));this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new T("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),he={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new t(1,1),collisions:{collisionMethod:Vt.SAT,collisionBroadPhaseMethod:Gt.SpartialGrid}},le=function(){function t(t){this._config=d(d({},he),t),this._config.collisions=d(d({},he.collisions),t.collisions),this.container=new ae,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){se(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}(),ce=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new t,i._scale=new t(1,1),i._rotation=new h,i._innerPosition=new t,i._parent=null,i.cache=new t,i.lastParentRadians=0,i.lastPosition=new t,i.scaledInnerPosition=new t,i}return c(i,e),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(e){this._parent=e,null!==this._parent&&t.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(),t.add(this._position,this._parent.position,this.scaledInnerPosition)):t.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 e=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(e),Math.sin(e)),t.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}(w),de=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.physicsManager=e.container.getSingleton("PhysicsManager"),e.renderer=null,e.colliders=[],e.physics=!0,e}return c(e,t),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],s=0,r=this.physicsManager.getCollisionsForCollider(n);s<r.length;s++){var o=r[s];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var s=n[i],r=0,o=this.physicsManager.getCollisionsForCollider(s);r<o.length;r++){var a=o[r];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.group),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(b),ue=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMultiple=!1,t.physicsManager=t.container.getSingleton("PhysicsManager"),t}return c(i,e),Object.defineProperty(i.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),i.prototype.init=function(e){var i,n=e.rigidBodyType,s=e.gravity;if(0===this.getColliderIds().length)throw new T("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:n,colliderIds:this.getColliderIds(),gravity:null!==(i=Math.abs(s))&&void 0!==i?i:0,velocity:new t,position:new t})},i.prototype.update=function(){if(0===this.getColliderIds().length)throw new T("RigidBody needs at least one Collider with physics");this.rigidBody.colliderIds=this.getColliderIds(),this.rigidBody.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position},i.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof de&&t.physics})).reduce((function(t,e){return u(u([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},i.prototype.onActiveChange=function(){this.rigidBody.active=this.active},i.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},i}(v),pe="Default",ge=function(t){function e(e,i,n){void 0===i&&(i="");var s=t.call(this,e)||this;return s.id=g(),s.layer="Default",s.ui=!1,s.keep=!1,s._parent=null,s._active=!0,s.components=[],s.activeComponentsCache=[],s.activeChildrenCache=[],s.name=i,s.addComponent(ce),s.parent=null!=n?n:null,s}return c(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(ce)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(ue)},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,s="string"==typeof e?e:i,r=new t(this.container,this,s);return this.checkMultipleComponent(r,t),this.components.push(r),r.dispatch(p.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new T("GameObject only allows one component of type ".concat(e.name))},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(p.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(p.Destroy),delete this.components[t];this.components=[]},e}(y),me=["Default"],fe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.renderManager=t.container.getSingleton("RenderManager"),t.canvas=t.container.getSingleton("DomManager").canvas,t.viewportRect=new e(0,0,0,0),t.worldSpaceRect=new e(0,0,0,0),t.depth=0,t.layers=me,t._zoom=1,t}return c(n,i),Object.defineProperty(n.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new T("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),n.prototype.addLayer=function(t){this.layers.push(t)},n.prototype.init=function(){this.cameraData={position:new t,layers:[],depth:1}},n.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},n.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},n.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},n.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},n}(_),ye=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return c(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(fe)},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}(ge),xe=function(t){function e(e,i,n){var s=t.call(this,e)||this;return s.name=i,s.game=n,s.game.config.headless||s.addGameObject(ye),s}return c(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ye)},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}(y),ve=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.scaledVertexModel=[],i.scaledOffset=new t,i.scaledPosition=new t,i.finalRotation=0,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==Vt.SAT)throw new T("Polygon Colliders need SAT collision method.");if(e.vertexModel.length<3)throw new T("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(s=e.offsetY)&&void 0!==s?s:this.offsetY,this.physics=null!==(r=e.physics)&&void 0!==r?r:this.physics,this.rotation=null!==(o=e.rotation)&&void 0!==o?o:new h,this.layer=e.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new t);this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new ee(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(be,{collider:this.colliders[0]}))},i.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateCollider()},i.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},i.prototype.updatePosition=function(){t.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateCollider=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].rotation=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel},i}(de),be=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:P.WorldSpace,layer:this.gameObject.layer,position:new t,shape:O.Polygon,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.rotation=this.collider.shape.rotation,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},i}(j),Me=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realWidth=0,i.realHeight=0,i.realOffset=new t,i.realPosition=new t,i.realRotation=0,i.applyRotation=i.container.getConstant("GameConfig").collisions.collisionMethod===Vt.SAT,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(t){var e,i,n,s,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!==(s=t.debug)&&void 0!==s?s:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new h,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new ie(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(be,{collider:this.colliders[0]}))},i.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateCollider()},i.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},i.prototype.updatePosition=function(){t.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateCollider=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position=this.realPosition,this.colliders[0].rotation=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight)},i}(de),we=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new t,i.realPosition=new t,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(t){var e,i,n,s,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!==(s=t.debug)&&void 0!==s?s:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new Zt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(Ce,{collider:this.colliders[0]}))},i.prototype.update=function(){this.updateRealSize(),this.updatePosition(),this.updateCollider()},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(){t.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateCollider=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position=this.realPosition,this.colliders[0].shape.radius=this.realRadius},i}(de),Ce=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:P.WorldSpace,layer:this.gameObject.layer,position:new t,shape:O.Circumference,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},i}(j),_e=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.position=new t,i}return c(i,e),i.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,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===A.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([A.Center,A.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==A.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(je,{colliders:this.colliders}))},i.prototype.useBoxColliders=function(){var e=this;this.tilemapRenderer.tiles.forEach((function(i,n){var s;e.needsCollider(i,n)&&e.colliders.push(e.physicsManager.addCollider({layer:null!==(s=e.layer)&&void 0!==s?s:e.gameObject.layer,position:new t(e.position.x+(n%e.tilemapRenderer.width+.5)*e.scaledTileWidth,e.position.y-(Math.floor(n/e.tilemapRenderer.width)+.5)*e.scaledTileHeight),shape:new ie(e.scaledTileWidth,e.scaledTileHeight),updateCollisions:!1,physics:e.physics,group:e.gameObject.id}))}))},i.prototype.useLineColliders=function(){var e,i,n=this,s=[],r=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,o=Math.floor(e/n.tilemapRenderer.width);s[o]||(s[o]=[]),s[o+1]||(s[o+1]=[]),r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(s[o][i]=!0,s[o][i+1]=!0),n.hasTile(a[2])||(s[o+1][i]=!0,s[o+1][i+1]=!0),n.hasTile(a[1])||(r[o][i]=!0,r[o+1][i]=!0),n.hasTile(a[3])||(r[o][i+1]=!0,r[o+1][i+1]=!0)}}));for(var o=0;o<s.length;o++)for(var a=0;a<s[o].length;a++)!e||!i||o*-this.scaledTileHeight===i.y&&s[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),s[o][a]&&(e?i=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight):e=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight));e&&i&&this.addLineCollider(e,i),e=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<r.length;o++)!e||!i||a*this.scaledTileWidth===i.x&&r[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),r[o][a]&&(e?i=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight):e=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight));e&&i&&this.addLineCollider(e,i)},i.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},i.prototype.addLineCollider=function(t,e){var i,n=this.physicsManager.addCollider({layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,position:this.position.clone(),shape:new te([t.clone(),e.clone()]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id});this.colliders.push(n)},i.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]}))},i.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]},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e){var i;return e.layer=null!==(i=t.layer)&&void 0!==i?i:t.gameObject.layer}))},i}(de),je=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,n=e.colliders;this.colliders=n,this.colliders.forEach((function(e,n){i.renderData[n]={type:R.Geometric,layer:i.gameObject.layer,location:P.WorldSpace,position:new t,shape:O.Polygon,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(j),Oe=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.scaledVertexModel=[],i.scaledOffset=new t,i.scaledPosition=new t,i.finalRotation=0,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==Vt.SAT)throw new T("Edge Colliders need SAT collision method.");if(e.vertexModel.length<2)throw new T("Edge Collider needs at least 2 vertices.");this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(s=e.offsetY)&&void 0!==s?s:this.offsetY,this.physics=null!==(r=e.physics)&&void 0!==r?r:this.physics,this.rotation=null!==(o=e.rotation)&&void 0!==o?o:new h,this.layer=e.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new t);for(l=0;l<this.scaledVertexModel.length-1;l++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new te([this.scaledVertexModel[l],this.scaledVertexModel[l+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(Pe,{colliders:this.colliders}))},i.prototype.update=function(){this.updateSize(),this.updatePosition(),this.updateColliders()},i.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},i.prototype.updatePosition=function(){t.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].position=this.scaledPosition,this.colliders[e].rotation=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]]},i}(de),Pe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,n=e.colliders;this.colliders=n,this.colliders.forEach((function(e,n){i.renderData[n]={type:R.Geometric,layer:i.gameObject.layer,location:P.WorldSpace,position:new t,shape:O.Line,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(j),Re=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.spriteDefaultScale=i.container.getConstant("GameConfig").spriteDefaultScale,i.renderData=[],i.innerPosition=new t,i.cachePosition=new t,i.cacheRenderPosition=new t,i.scaledOffset=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a,l;void 0===e&&(e={}),this.sprite=e.sprite,this.offset=null!==(i=e.offset)&&void 0!==i?i:new t,this.rotation=null!==(n=e.rotation)&&void 0!==n?n:new h,this.flipHorizontal=null!==(s=e.flipHorizontal)&&void 0!==s&&s,this.flipVertical=null!==(r=e.flipVertical)&&void 0!==r&&r,this.opacity=null!==(o=e.opacity)&&void 0!==o?o:1,this._tiled=null!==(a=e.tiled)&&void 0!==a?a:new t(1,1),this.maskColor=e.maskColor,this.maskColorMix=null!==(l=e.maskColorMix)&&void 0!==l?l:0,this.tintColor=e.tintColor,this.layer=e.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 T("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 e=0;e<this._tiled.x*this._tiled.y;e++)this.renderData[e]={type:R.Sprite,location:P.WorldSpace,layer:"",position:new t,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?P.ViewPort:P.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(e,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),t.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[e].width/2*(this._tiled.x-1),this.renderData[e].height/2*(this._tiled.y-1)),t.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[e].width,n*this.renderData[e].height),t.add(this.renderData[e].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(e)},i.prototype.translateRenderPosition=function(e){t.subtract(this.innerPosition,this.renderData[e].position,this.gameObject.transform.position);var i=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[e].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}(j),Ae=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.lastFrameText="",t}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a,l,c,d,u;if(this.text=e.text,this.font=null!==(i=e.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=e.fontSize)&&void 0!==n?n:12,this.width=null!==(s=e.width)&&void 0!==s?s:100,this.height=null!==(r=e.height)&&void 0!==r?r:100,this.offset=null!==(o=e.offset)&&void 0!==o?o:new t,this.color=null!==(a=e.color)&&void 0!==a?a:"#000000",this.charRanges=null!==(l=e.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=e.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(d=e.letterSpacing)&&void 0!==d?d:0,this.smooth=e.smooth,this.rotation=null!==(u=e.rotation)&&void 0!==u?u:new h,this.opacity=e.opacity,this.orientation=e.orientation,this.bitmapMargin=e.bitmapMargin,this.bitmapSpacing=e.bitmapSpacing,this.charRanges.length%2!=0)throw new T("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new T("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:R.Text,location:P.WorldSpace,position:new t,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 e,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?P.ViewPort:P.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===(e=this.rotation)||void 0===e?void 0:e.radians))&&void 0!==i?i:0,this.renderData.alpha=this.opacity,t.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,s=this.text.split("\n");n<s.length;n++)for(var r=0,o=null!==(t=s[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];r<o.length;r++){var a=o[r];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(j),Se=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.offset=new t,i.rotation=new h,i.opacity=1,i.innerPosition=new t,i.scaledOffset=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r;this.width=e.width,this.height=e.height,this.color=e.color,this.offset=null!==(i=e.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=e.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(s=e.opacity)&&void 0!==s?s:this.opacity,this.layer=e.layer,this.renderData={type:R.Mask,layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?P.ViewPort:P.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),t.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){t.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i}(j),Te=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.tiles=[],t.tilesetTileIds=[],t.chunks=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t.renderData=[],t}return c(i,e),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,s=t.tileWidth,r=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=s,this.tileHeight=r,this.layer=o,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(i){return t.processChunk(i,e)})):t.processChunk(e,e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(e,i){var n,s=this,r={type:R.Tilemap,layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,tileset:this.tileset,tilemap:{width:e.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:e.data.map((function(t){return s.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};e.type&&"tilelayer"===e.type?this.tiles=r.tiles:r.tiles.forEach((function(t,i){s.tiles[s.tiledData.width*(e.y+Math.floor(i/e.width))+e.x+i%e.width]=t})),this.renderData.push(r),this.chunks.push(e)},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}(j),De=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.tiles=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t}return c(i,e),i.prototype.init=function(e){var i,n=this,s=e.tiles,r=e.tileset,o=e.tileWidth,a=e.tileHeight,h=e.width,l=e.layer,c=e.orientation,d=e.alpha,u=e.tintColor,p=e.smooth;s.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=r,this.width=h,this.tileWidth=o,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=d,this.tintColor=u,this.renderData={type:R.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,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}(j),Fe=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},Ee=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 c(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e="default"),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new Be(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new T("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(v),Be=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}(),Ie=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Ue=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(){Ie.forEach((function(t){window.removeEventListener(t,e.userinputEventHandler)})),e.audio.play()},e}return c(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 Ie.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}(v),Ge=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}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(ne||(ne={}));var Le=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.allowMultiple=!1,i.width=100,i.height=100,i.radius=50,i.touchEnabled=!0,i._offset=new t,i.pressed=!1,i.mouse=i.container.getSingleton("InputManager").mouse,i.touch=i.container.getSingleton("InputManager").touch,i.position=new t,i.distance=new t,i.pressedLastFrame=!1,i.scaled={width:0,height:0,radius:0,offset:new t},i}return c(i,e),Object.defineProperty(i.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),i.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,s=t.touchEnabled,r=t.width,o=t.offset;this.type=e,this.width=null!=r?r:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=s?s:this.touchEnabled,this._offset=null!=o?o:this._offset},i.prototype.update=function(){this.scale(),t.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},i.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this._offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this._offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*this.gameObject.transform.scale.magnitude},i.prototype.resolveMouseAndRectangle=function(){this.type===ne.Rectangle&&(this.pressed||(this.pressed=a(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&a(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},i.prototype.resolveMouseAndCircumference=function(){this.type===ne.Circumference&&(t.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},i.prototype.resolveTouchAndRectangle=function(){this.type===ne.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))},i.prototype.resolveTouchAndCircumference=function(){this.type===ne.Circumference&&(t.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},i}(x),Ve=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new t,i}return c(i,e),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){Y.mouse.leftButtonPressed&&!1===this.mousePressed&&(t.round(this.position,t.add(this.position,this.camera.transform.position,t.scale(this.position,Y.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=Y.mouse.leftButtonPressed},i}(ge);export{Fe as Animation,Ee as Animator,H as AssetManager,Ue as AudioPlayer,we as BallCollider,Me as BoxCollider,Gt as BroadPhaseMethods,Le as Button,ne as ButtonType,fe as Camera,Vt as CollisionMethods,x as Component,z as DomManager,Oe as EdgeCollider,le as Game,ye as GameCamera,ge as GameObject,q as GameObjectManager,E as GamepadController,B as GamepadData,Y as InputManager,U as KeyboardController,pe as LAYER_DEFAULT,Se as MaskRenderer,G as MouseController,M as PhysicsComponent,ve as PolygonCollider,be as PolygonColliderRenderer,C as PreRenderComponent,e as Rectangle,ue as RigidBody,Wt as RigidBodyType,h as Rotation,xe as Scene,N as SceneManager,Ve as SpacePointer,Ge as Sprite,Re as SpriteRenderer,Mt as TextOrientation,Ae as TextRenderer,Te as TiledTilemapRenderer,_e as TilemapCollider,A as TilemapOrientation,De as TilemapRenderer,X as TimeManager,k as TouchController,ce as Transform,t as Vector2,a as between,i as clamp,r as fixedRound,s as randomFloat,n as randomInt,o as range};
1
+ class t{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 t(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}class e{constructor(e,i,n,s){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,s)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(i){return i instanceof e?i.x1<=this.x1&&i.x>=this.x&&i.y1<=this.y1&&i.y>=this.y:i instanceof t&&!(i.x<this.x||i.y<this.y||i.x>=this.x1||i.y>=this.y1)}}const i=(t,e,i)=>Math.min(i,Math.max(e,t)),n=(t,e)=>Math.round(Math.random()*(e-t))+t,s=(t,e,i=2)=>r(Math.random()*(e-t)+t,i),r=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),o=(t,e,i=1)=>{const n=[];for(let s=t;s<=e;s+=i)n.push(s);return n},a=(t,e,i)=>t>=e&&t<=i;class h{constructor(e=null,i=null){this._degrees=0,this._radians=0,this._direction=new t,e?this.radians=e:i&&(this.degrees=i)}set degrees(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()}get degrees(){return this._degrees}set radians(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()}get radians(){return this._radians}get direction(){return this._direction}updateDirection(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}var l=function(t,e){return l=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])},l(t,e)};function c(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}l(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var u=function(){return u=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},u.apply(this,arguments)};function d(t,e,i){if(i||2===arguments.length)for(var n,s=0,r=e.length;s<r;s++)!n&&s in e||(n||(n=Array.prototype.slice.call(e,0,s)),n[s]=e[s]);return t.concat(n||Array.prototype.slice.call(e))}var p,g=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"}(p||(p={}));var m,f=function(){function t(t,e,i,n,s,r,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=s,this.sceneManager=r,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(p.Start),this.inputManager.update(),this.dispatchFrameEvent(p.Update),this.dispatchFrameEvent(p.UpdateEngine),this.dispatchFrameEvent(p.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(p.UpdatePreRender),this.sceneManager.update()},t.prototype.renderIteration=function(){this.dispatchFrameEvent(p.UpdatePreRender),this.dispatchFrameEvent(p.UpdateCamera),this.dispatchFrameEvent(p.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(p.UpdatePhysics),this.dispatchFrameEvent(p.UpdateCollider),this.dispatchFrameEvent(p.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsIntervalId=window.setInterval((function(){if(!t.running)return window.clearInterval(t.physicsIntervalId);t.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return d(d([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==p.Start&&t!==p.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}(),y=function(){function t(t){this.updateEvent=p.Update,this.started=!1,this.container=t,this.gameObjectManager=this.container.getSingleton("GameObjectManager")}return t.prototype.dispatch=function(t,e){t===p.Init&&this.init?this.init(e):t!==p.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===p.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}(),x=function(t){function e(e,i,n){void 0===n&&(n="");var s=t.call(this,e)||this;return s.id=g(),s.allowMultiple=!0,s._active=!0,s.gameObject=i,s.name=n,s}return c(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}(y),v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateEngine,e}return c(e,t),e}(x),b=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCollider,e}return c(e,t),e}(x),M=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePhysics,e}return c(e,t),e}(x),w=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateTransform,e}return c(e,t),e}(x),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePreRender,e}return c(e,t),e}(x),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCamera,e}return c(e,t),e}(x),j=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateRender,e}return c(e,t),e}(x);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font"}(m||(m={}));var O,P,R,A,S=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,m.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,m.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.loadFont=function(t,e){var i=new FontFace(t,"url(".concat(e,")")),n=this.createAsset(e,m.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===m.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===m.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===m.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}(),T=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return c(e,t),e}(Error),D=function(){function t(t,e,i){if(this._canvas=null,!t)throw new T("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}(),E=function(){function t(t){this.container=t,this.gameObjects=[]}return t.prototype.addGameObject=function(t,e,i,n){var s=new t(this.container,n,i);return this.gameObjects.push(s),s.dispatch(p.Init,e),s},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):d([],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(p.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),F=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 B),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}(),B=function(){function e(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new t,this._leftStickAxes=new t,this._rightStickAxes=new t}return e.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(e.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),e.prototype.getButtonPressed=function(t){return this.buttons.get(t)},e.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(e.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(e.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),e.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})},e}(),I=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}(),U=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}(),G=function(){function e(e){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new t(0,0),this._hasMoved=!1,this.lastPositionInViewport=new t(0,0),this.canvas=e,this.setup()}return Object.defineProperty(e.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),e.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1},e.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)}))},e.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},e.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},e.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)},e}(),L=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.currentScene=null,this.openingSceneName=null,this.sceneToLoad=null}return t.prototype.getCurrentScene=function(){return this.currentScene},t.prototype.addScene=function(t,e,i,n){var s=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new T("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var n=new t(s.container,e,s.container.getConstant("Game"));return s.currentScene=n,n.dispatch(p.Init,i),n})),!0!==n&&null!==this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new T("There is no opening scene");this._loadScene(this.openingSceneName)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new T("Scene with name ".concat(t," does not exists"));this.sceneToLoad=t},t.prototype.update=function(){null!==this.sceneToLoad&&(this._loadScene(this.sceneToLoad),this.sceneToLoad=null)},t.prototype._loadScene=function(t){this.unloadCurrentScene(),this.scenes.get(t)()},t.prototype.unloadCurrentScene=function(){null!==this.currentScene&&(this.currentScene.dispatch(p.Destroy),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),k=[60,120,180,240],V=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.gameDeltaTime=0,this.unscaledGameDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!k.includes(t))throw new T("Invalid Physics frame rate. Allowed: [".concat(k.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}(),W=function(){function e(e){var i=this;this._touching=!1,this._positionInViewport=new t(0,0),this._radius=new t(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=e,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(e.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"radius",{get:function(){return this._radius},enumerable:!1,configurable:!0}),e.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))},e}(),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}(),Y=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}(),N=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}(),$=function(){function t(t,e,i,n){this.timeManager=t,this.physicsManager=e,this.gameObjectManager=i,this.sceneManager=n,this.running=!1,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.unloadCurrentScene(),this.physicsManager.clear()},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.asyncGameLoop(),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(p.Start),this.dispatchFrameEvent(p.Update),this.dispatchFrameEvent(p.UpdateEngine),this.dispatchFrameEvent(p.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.update()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||(this.dispatchFrameEvent(p.UpdatePhysics),this.dispatchFrameEvent(p.UpdateCollider),this.dispatchFrameEvent(p.UpdateTransform),this.physicsManager.resolve(this.timeManager.physicsDeltaTime))},t.prototype.asyncGameLoop=function(){var t=this;this.gameInterval=setInterval((function(){if(!t.running)return clearInterval(t.gameInterval);t.gameLogicIteration(process.uptime())}),1e3/this.timeManager.gameFramerate)},t.prototype.asyncPhysicsLoop=function(){var t=this;this.physicsInterval=setInterval((function(){if(!t.running)return clearInterval(t.physicsInterval);t.timeManager.updateForPhysics(process.uptime()),t.physicsIteration()}),1e3/this.timeManager.physicsFramerate)},t.prototype.load=function(){this.currentScene=this.sceneManager.getCurrentScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=this.gameObjects.reduce((function(t,e){return d(d([],t,!0),e.getComponents().filter((function(t){return t.active})),!0)}),[])},t.prototype.dispatchFrameEvent=function(t){t!==p.Start&&t!==p.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"}(O||(O={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(P||(P={})),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"}(R||(R={}));class K{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===P.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 s=Math.abs(Math.sin(n)),r=Math.abs(Math.cos(n)),o=s*i+r*e,a=s*e+r*i;this.object.x=t.x-o/2,this.object.x1=t.x+o/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:s,rotation:r}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=s?s:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===O.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:s}}=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)*s+s)&&this.viewport.y<=this.object.y1-(e/i|0)*s?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case R.Mask:case R.Sprite:this.setObjectForResizeable(t);break;case R.Geometric:this.setObjectForGeometric(t);break;case R.Text:this.setObjectForText(t);break;case R.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===R.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}}!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(A||(A={}));class J{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(t){this.cullingManager.applyCulling(t,this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).map((t=>t.type===R.Tilemap?(t=>{const e=Object.assign(Object.assign({},t),{culledTiles:[],tilemap:Object.assign(Object.assign({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new Q});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,(t=>{t.renderPosition.set(t.position.x+(t.orientation!==A.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===A.RightDown?-t.tilemap.realHeight/2:t.orientation===A.RightUp?t.tilemap.realHeight/2:0))})(e),e})(t):t))).forEach((e=>this.webglManager.render(e,t)))}clearData(){this.renderData=[],this.cameraData=[]}clearScreen(t){this.webglManager.clearCanvas(t)}}var Z;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(Z||(Z={}));class tt{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(Z.WebGL2)?Z.WebGL2:null!==this.canvas.getContext(Z.LegacyWebGL)?Z.LegacyWebGL:void 0}}class et{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 it(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,s=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,s),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,s+=this.bitmapSize);return e}}class it{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 nt{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),s=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,s),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class st{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===Z.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 rt{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 ot="undefined"!=typeof Float32Array?Float32Array:Array;function at(){var t=new ot(16);return ot!=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 ht(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 lt(t,e,i){var n,s,r,o,a,h,l,c,u,d,p,g,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(n=e[0],s=e[1],r=e[2],o=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]=s,t[2]=r,t[3]=o,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*m+a*f+u*y+e[12],t[13]=s*m+h*f+d*y+e[13],t[14]=r*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function ct(t,e,i){var n=i[0],s=i[1],r=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ut(t,e,i){var n=Math.sin(i),s=Math.cos(i),r=e[0],o=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]=r*s+l*n,t[1]=o*s+c*n,t[2]=a*s+u*n,t[3]=h*s+d*n,t[4]=l*s-r*n,t[5]=c*s-o*n,t[6]=u*s-a*n,t[7]=d*s-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 dt;function pt(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function gt(t,e,i){var n=new ot(3);return n[0]=t,n[1]=e,n[2]=i,n}function mt(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}pt(),function(){var t;t=new ot(4),ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),pt(),gt(1,0,0),gt(0,1,0),mt(),mt(),dt=new ot(9),ot!=Float32Array&&(dt[1]=0,dt[2]=0,dt[3]=0,dt[5]=0,dt[6]=0,dt[7]=0),dt[0]=1,dt[4]=1,dt[8]=1,function(){var t=new ot(2);ot!=Float32Array&&(t[0]=0,t[1]=0)}();const ft=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},yt=(t,e,i,n)=>{var s,r;(function(t,e,i,n,s,r,o){var a=1/(e-i),h=1/(n-s),l=1/(r-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(s+n)*h,t[14]=(o+r)*l,t[15]=1})(t=ht(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),lt(t,t,[0,0,0]),n===P.WorldSpace&&ct(t,t,[null!==(s=i.zoom)&&void 0!==s?s:1,null!==(r=i.zoom)&&void 0!==r?r:1,1])};class xt{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at();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 O.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case O.Line:this.renderLines(t,e,this.gl.LINES,i);break;case O.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,n){var s;const r=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(r)&&this.vertices.set(r,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(r);this.lastVertices===r&&n===R.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW)),this.lastVertices=r,this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ut(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),yt(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}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,o.length/2)}generateVerticesKey(t){return Symbol.for(t.reduce(((t,e)=>`${t}${e.x}${e.y}`),t.length.toString()))}generatePolygonVertices(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e}renderCircumference(t,e){this.lastVertices=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ct(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),yt(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:s,a:r}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,s,r),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class vt{constructor(t,e){this.gl=t,this.programManager=e,this.type=R.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n,s;i!==R.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=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ut(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),yt(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:r,g:o,b:a,a:h}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class bt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at(),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,s,r,o;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.position,e.position):t.position),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ut(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=ht(this.textureMatrix),t.slice&&(lt(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),ct(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),yt(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!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:s}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,s)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}var Mt;!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Mt||(Mt={}));const wt=new Q,Ct=new Q,_t=[32,126,161,255],jt=Mt.Center;class Ot{constructor(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=R.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new Q,this.modelPosition=new Q,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n;if(!t.text)return;this.setDefaultValues(t);const s=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(s,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=ht(this.modelMatrix),this.setPositionFromOrientation(t),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ut(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=ht(this.textureMatrix),yt(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 r=this.textureManager.getOrCreateTextureFromCanvas(s.fontFaceFamily,s.canvas,t.smooth);this.lastTexture===r&&i===R.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=r),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:o,g:a,b:h,a:l}=ft(t.color);this.gl.uniform4f(this.programManager.maskColorUniform,o,a,h,l),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}setDefaultValues(t){var e,i,n,s,r,o,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:wt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:Ct,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(s=t.bitmap.charRanges)&&void 0!==s?s:_t):t.bitmap={margin:wt,spacing:Ct,fontSize:64,charRanges:_t},t.color=null!==(r=t.color)&&void 0!==r?r:"#000000",t.letterSpacing=null!==(o=t.letterSpacing)&&void 0!==o?o:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:jt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:s,lineSeparation:r}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;s/=i,r/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,o),o=0,a-=1+r;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(o,a-1,o+e,a-1,o,a,o,a,o+e,a-1,o+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,r=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(r+n.margin.y)/t.canvas.width,u=(i+c.width+n.spacing.x)/t.canvas.width,d=(r+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,d,u,d,h,l,h,l,u,d,u,l),o+=e+s}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-1)*i)}setPositionFromOrientation(t){this.modelPosition.set(t.position.x+(t.orientation===Mt.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Mt.Center||t.orientation===Mt.RightCenter?this.textSize.y/2:t.orientation===Mt.RightUp?this.textSize.y:0))}}class Pt{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=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var n,s,r,o;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=ht(this.modelMatrix),Q.round(this.modelPosition,t.location===P.WorldSpace?Q.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),lt(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ut(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),ct(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=ht(this.textureMatrix),ct(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),yt(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===R.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!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:s}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,s)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,s,r,o,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!==(s=t.margin.x)&&void 0!==s?s:0)+(null!==(r=t.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=t.tileHeight+(null!==(o=t.margin.y)&&void 0!==o?o:0)+(null!==(a=t.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y}generateVertices({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const s=n%e.width-e.width/2,r=i/2-Math.floor(n/e.width);this.posVertices.push(s,r-1,s+1,r-1,s,r,s,r,s+1,r-1,s+1,r);const o=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(o,a+this.tileset.texHeight,o+this.tileset.texWidth,a+this.tileset.texHeight,o,a,o,a,o+this.tileset.texWidth,a+this.tileset.texHeight,o+this.tileset.texWidth,a)}))}}class Rt{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 At{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 St{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=ft(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}class Tt{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 Tt(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}}class Dt{constructor(t,e,i,n){this._position=new Tt,this._center=new Tt,this._width=0,this._height=0,this.set(t,e,i,n)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(t){return t instanceof Dt?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Tt&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const Et=(t,e,i)=>Math.min(i,Math.max(e,t));class Ft{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:n,position:s,rotation:r,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:n,position:null!=s?s:new Tt,rotation:null!=r?r:0,group:o,onCollision:a}}}class Bt{constructor(t,e=0){this.area=new Dt(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}resize(t){this.clear(),this.area.copy(t)}clear(){this.items=[],this.children.forEach((t=>t.clear())),this.children=[]}insert(t,e){0===this.children.length&&this.items.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.items.push([t,e])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new Dt(this.area.x,this.area.y,t,e),new Dt(this.area.x,this.area.y+e,t,e),new Dt(this.area.x+t,this.area.y+e,t,e),new Dt(this.area.x+t,this.area.y,t,e)].map((t=>new Bt(t,this.depth+1))),this.items.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.items=[]}insertItemIntoChildren(t,e){this.getChildrenForArea(e).forEach((i=>i.insert(t,e)))}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((i=>e.push(...i.retrieve(t)))):this.items.forEach((t=>e.push(t[0]))),e}getChildrenForArea(t){const e=[];return t.x<=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[0]),t.x<=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[1]),t.x1>=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[2]),t.x1>=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[3]),e}}const It=(t,e,i,n)=>Math.min((t-e)/i|0,n-1);class Ut{constructor(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}get subdivisions(){return this._subdivisions}set subdivisions(t){this._subdivisions=Et(t,1,20)}resize(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(let t=0;t<this._subdivisions;t++){this.itemsInCells[t]=[];for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}}clear(){for(let t=0;t<this._subdivisions;t++)for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[e][i].push(t)}retrieve(t){const e=[];this.updateCoordinates(t);for(let t=this.coordinates.x0;t<=this.coordinates.x1;t++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[t][i].forEach((t=>e.includes(t)?null:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=It(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=It(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=It(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=It(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}var Gt,Lt,kt,Vt;!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Gt||(Gt={}));class Wt{constructor(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Tt,this.maxArea=new Tt,this.newArea=new Dt(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:Gt.QuadTree,i)}setupBroadPhaseResolver(t,e){this.collisionArea=null!=e?e:new Dt(0,0,0,0),this.fixedCollisionArea=!!e,t===Gt.SpartialGrid?this.broadPhaseResolver=new Ut(this.collisionArea):this.broadPhaseResolver=new Bt(this.collisionArea)}addCollider(t){this.colliders[t.id]=t}getCollider(t){return this.colliders[t]}removeCollider(t){delete this.colliders[t.id]}clearColliders(){this.colliders=[]}getCollisionsForCollider(t){return t.active?this.collisions.filter((e=>e.localCollider.id===t.id)):[]}refreshCollisionsForCollider(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((e=>e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id)),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))}resolve(){this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((t=>t.active)),this.broadPhaseResolver.clear(),this.activeColliders.forEach((t=>{this.updateShape(t)})),!1===this.fixedCollisionArea&&(this.updateNewArea(),!1===this.newArea.equals(this.collisionArea)&&(this.collisionArea.copy(this.newArea),this.broadPhaseResolver.resize(this.collisionArea))),this.checkForSpartialGridResize(),this.activeColliders.forEach((({id:t,shape:{boundingBox:e}})=>this.broadPhaseResolver.insert(t,e))),this.updateCollisions())}updateShape(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()}updateNewArea(){this.activeColliders.forEach((({shape:{boundingBox:t}})=>{this.minArea.set(Math.min(t.x,this.minArea.x),Math.min(t.y,this.minArea.y)),this.maxArea.set(Math.max(t.x1,this.maxArea.x),Math.max(t.y1,this.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}checkForSpartialGridResize(){this.broadPhaseResolver instanceof Ut&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)}updateCollisions(){this.activeColliders.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase(t){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t])).filter((e=>this.collisionMatrix.some((i=>i[0]===t.layer&&i[1]===e.layer||i[1]===t.layer&&i[0]===e.layer)))):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t]))}narrowPhase(t,e){e.filter((e=>!(t.group&&e.group&&e.group===t.group||t.id===e.id))).forEach((e=>{if(this.isResolved(t,e))return;const i=this.method.getCollisionResolution(t.shape,e.shape);null!==i&&(this.collisions.push({localCollider:t,remoteCollider:e,resolution:i},{localCollider:e,remoteCollider:t,resolution:{direction:i.displacementDirection,displacementDirection:i.direction,penetration:i.penetration}}),t.onCollision&&t.onCollision(i))}))}isResolved(t,e){for(const i of this.collisions)if(i.localCollider.id===t.id&&i.remoteCollider.id===e.id)return!0;return!1}}!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Lt||(Lt={}));class Ht{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Lt.Polygon&&e.type===Lt.Polygon?this.AABBResolver.resolve(t,e):t.type===Lt.Circumference&&e.type===Lt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Lt.Polygon&&e.type===Lt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Lt.Circumference&&e.type===Lt.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(kt||(kt={}));class zt{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Lt.Circumference&&e.type===Lt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class Yt{constructor(){this.direction=new Tt,this.displacementDirection=new Tt}resolve({boundingBox:t},{boundingBox:e}){return this.overlapX=Math.min(t.x1,e.x1)-Math.max(t.x,e.x),this.overlapY=Math.min(t.y1,e.y1)-Math.max(t.y,e.y),this.overlapX<0||this.overlapY<0?null:(this.checkOverlapForLines(t,e),this.direction.set(Math.sign(e.center.x-t.center.x),Math.sign(e.center.y-t.center.y)),this.preventContainment(t,e),this.overlapY<this.overlapX?(this.minOverlap=this.overlapY,this.displacementDirection.set(0,-this.direction.y)):(this.minOverlap=this.overlapX,this.displacementDirection.set(-this.direction.x,this.overlapY===this.overlapX?-this.direction.y:0)),Tt.unit(this.displacementDirection,this.displacementDirection),{direction:Tt.scale(new Tt,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),penetration:this.minOverlap})}checkOverlapForLines(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))}preventContainment(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){const i=Math.abs(t.y-e.y),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),n=Math.abs(t.x1-e.x1);this.overlapX+=i<n?i:n}}}class Nt{constructor(){this.closestPoint=new Tt,this.distance=new Tt,this.direction=new Tt}resolve(t,e,i=!1){return this.closestPoint.set(Et(t.position.x,e.boundingBox.x,e.boundingBox.x1),Et(t.position.y,e.boundingBox.y,e.boundingBox.y1)),Tt.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Tt.unit(this.direction,this.distance),{direction:i?Tt.scale(new Tt,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Tt.scale(new Tt,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class Xt{constructor(){this.distance=new Tt,this.direction=new Tt}resolve(t,e){return Tt.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Tt.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Tt.scale(new Tt,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class qt{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Tt,this.distance=new Tt(1/0,1/0),this.cache=new Tt}resolve(t,e){this.minOverlap=1/0,t.type===Lt.Circumference?this.setCircumferenceAxis(t,e):e.type===Lt.Circumference&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?null:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t.type===Lt.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Lt.Circumference&&this.setCircumferenceVertices(e,this.axes[i]),this.projectShapeOntoAxis(this.projA,t,this.axes[i]),this.projectShapeOntoAxis(this.projB,e,this.axes[i]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;if(this.invertAxis=!0,this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){const t=Math.abs(this.projA.min-this.projB.min),e=Math.abs(this.projA.max-this.projB.max);t<e?this.currentOverlap+=t:(this.currentOverlap+=e,Tt.scale(this.axes[i],this.axes[i],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[i]),this.invertAxis&&this.projA.max<this.projB.max&&Tt.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Tt.scale(new Tt,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(Tt.dot(i,e),t.min),t.max=Math.max(Tt.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Tt.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Tt.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Tt.add(t.vertices[0],t.position,Tt.scale(this.cache,Tt.unit(this.cache,e),-t.radius)),Tt.add(t.vertices[1],t.position,Tt.scale(this.cache,Tt.unit(this.cache,e),t.radius))}}class $t{constructor(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}addCollider(t){const e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e}removeCollider(t){this.collisionManager.removeCollider(t)}getCollisionsForCollider(t){return this.collisionManager.getCollisionsForCollider(t)}addRigidBody(t){const e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e}removeRigidBody(t){this.rigidBodyManager.removeRigidBody(t)}resolve(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)}clear(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()}}class Kt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:n,velocity:s,onResolve:r}){if(0===t.length)throw new Error("RigidBody needs at least one collider");return{id:++this.lastId,active:!0,colliderIds:t,type:e,gravity:null!=i?i:0,position:null!=n?n:new Tt,velocity:null!=s?s:new Tt,onResolve:r}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Vt||(Vt={}));const Qt=["x","y"];class Jt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Tt,this.displacement=new Tt,this.cacheDisplacement=0}addRigidBody(t){this.rigidBodies[t.id]=t}removeRigidBody(t){delete this.rigidBodies[t.id]}clearRigidBodies(){this.rigidBodies=[]}resolve(t){this.activeRigidBodies=this.rigidBodies.filter((t=>t.active)),this.colliders=this.activeRigidBodies.reduce(((t,e)=>[...t,...e.colliderIds]),[]),this.activeRigidBodies.forEach((e=>{e.type===Vt.Dynamic?this.dynamicUpdate(e,t):e.type===Vt.Kinematic&&this.kinematicUpdate(e,t),e.onResolve&&e.onResolve(e)}))}dynamicUpdate(t,e){this.applyGravity(t,e),Qt.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Tt.add(t.position,t.position,Tt.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Tt.add(t.position,t.position,this.velocity),this.collisionManager.refreshCollisionsForCollider(t)}))}applyGravity(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)}applyVelocity(t,e,i){this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[i]+=this.velocity[i],this.collisionManager.refreshCollisionsForCollider(t)})))}obtainDisplacement(t,e){this.displacement[e]=0,this.getCollisions(t).forEach((t=>{this.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,this.displacement[e]=Math.abs(this.displacement[e])>Math.abs(this.cacheDisplacement)?this.displacement[e]:this.cacheDisplacement}))}applyReposition(t,e){0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{t.position[e]+=this.displacement[e],this.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))}getCollisions(t){return t.colliderIds.map((t=>this.collisionManager.getCollider(t))).filter((t=>t.active&&t.physics)).reduce(((t,e)=>(t.push(...this.collisionManager.getCollisionsForCollider(e).filter((t=>t.remoteCollider.physics&&this.colliders.includes(t.remoteCollider.id)))),t)),[])}}class Zt{constructor(t){this.radius=t,this.type=Lt.Circumference,this.boundingBox=new Dt(0,0,0,0),this.vertices=[new Tt,new Tt],this.projectionAxes=[new Tt],this._position=new Tt}set position(t){this._position.copy(t)}get position(){return this._position}update(){this.updateBoundingBox()}updateBoundingBox(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)}}class te{constructor(t){this.vertexModel=t,this.type=Lt.Polygon,this.vertices=[new Tt,new Tt],this.projectionAxes=[new Tt],this.boundingBox=new Dt(0,0,0,0),this.rotation=0,this._position=new Tt}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}set position(t){this._position.copy(t)}get position(){return this._position}updateVertices(){for(let t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)}updateBoundingBox(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y}updateProjectionAxes(){Tt.normal(this.projectionAxes[0],Tt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class ee{constructor(t){this.vertexModel=t,this.type=Lt.Polygon,this.vertices=[],this.boundingBox=new Dt(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Tt,this.boxMinX=Number.MAX_SAFE_INTEGER,this.boxMinY=Number.MAX_SAFE_INTEGER,this.boxMaxX=-Number.MAX_SAFE_INTEGER,this.boxMaxY=-Number.MAX_SAFE_INTEGER;for(let t=0;t<this.vertexModel.length;t++)this.vertices.push(new Tt),this._projectionAxes.push(new Tt)}set position(t){this._position.copy(t)}get position(){return this._position}get projectionAxes(){return this._projectionAxes}update(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()}updateVertices(){for(let t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.rotation)-this.vertexModel[t].y*Math.sin(this.rotation)+this._position.x,this.vertexModel[t].x*Math.sin(this.rotation)+this.vertexModel[t].y*Math.cos(this.rotation)+this._position.y)}updateBoundingBox(){this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((t=>{this.boxMinX=Math.min(t.x,this.boxMinX),this.boxMinY=Math.min(t.y,this.boxMinY),this.boxMaxX=Math.max(t.x,this.boxMaxX),this.boxMaxY=Math.max(t.y,this.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)}updateProjectionAxes(){var t;for(let e=0;e<this.vertices.length;e++)Tt.normal(this._projectionAxes[e],Tt.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class ie extends ee{constructor(t,e){super([new Tt(-t/2,-e/2),new Tt(-t/2,e/2),new Tt(t/2,e/2),new Tt(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Tt,new Tt]}updateSize(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)}updateProjectionAxes(){Tt.unit(this.projectionAxes[0],Tt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Tt.normal(this.projectionAxes[1],this.projectionAxes[0])}}var ne,se=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new V(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new E(t)})),t.add("PhysicsManager",(function(){return(({collisionArea:t,collisionMatrix:e,collisionMethod:i,collisionBroadPhaseMethod:n}={})=>{const s=new Xt,r=i===kt.AABB?new Ht(new Yt,new Nt,s):new zt(s,new qt),o=new Wt(r,n,t,e),a=new Ft,h=new Jt(o),l=new Kt;return new $t(o,a,h,l)})(e.collisions)})),e.headless?t.add("IterationManager",(function(){return new $(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))})):(t.add("DomManager",(function(){return new D(e.containerNode,e.gameWidth,e.gameHeight)})),t.add("RenderManager",(function(){return(t=>{const e=new tt(t),i=e.gl,n=e.contextVersion,s=new st(i,n,new nt(i,new rt(i))),r=new At(new Rt(i)),o=new St(i,s,new Map([[R.Sprite,new bt(i,s,r)],[R.Text,new Ot(i,s,r,new et)],[R.Tilemap,new Pt(i,s,r)],[R.Geometric,new xt(i,s)],[R.Mask,new vt(i,s)]]));return new J(o,new K(i))})(t.getSingleton("DomManager").canvas)})),re(t),t.add("AssetManager",(function(){return new S})),t.add("IterationManager",(function(){return new f(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("RenderManager"),t.getSingleton("InputManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"),e.canvasColor)}))),t.add("SceneManager",(function(){return new L(t,e.headless?void 0:t.getSingleton("RenderManager"))})),oe(t,e)},re=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new I(new G(e.canvas),new U(e.canvas),new F,new W(e.canvas))}))},oe=function(t,e){e.headless||(H.initialize(t.getSingleton("AssetManager")),z.initialize(t.getSingleton("DomManager")),Y.initialize(t.getSingleton("InputManager"))),N.initialize(t.getSingleton("SceneManager")),X.initialize(t.getSingleton("TimeManager")),q.initialize(t.getSingleton("GameObjectManager"))},ae=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 T("There is already an object constructor with the name ".concat(t));this.constructors.set(t,e)},t.prototype.getSingleton=function(t){if(!1===this.constructors.has(t))throw new T("Invalid object constructor name: ".concat(t));return!1===this.instances.has(t)&&this.instances.set(t,this.constructors.get(t)()),this.instances.get(t)},t.prototype.getTranscient=function(t){if(!1===this.constructors.has(t))throw new T("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new T("There is already a constant value with the name ".concat(t));this.constants.set(t,e)},t.prototype.getConstant=function(t){if(!1===this.constants.has(t))throw new T("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),he={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new t(1,1),collisions:{collisionMethod:kt.SAT,collisionBroadPhaseMethod:Gt.SpartialGrid}},le=function(){function t(t){this._config=u(u({},he),t),this._config.collisions=u(u({},he.collisions),t.collisions),this.container=new ae,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){se(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}(),ce=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.allowMultiple=!1,i.parentScale=!0,i.parentRotation=!0,i._position=new t,i._scale=new t(1,1),i._rotation=new h,i._innerPosition=new t,i._parent=null,i.cache=new t,i.lastParentRadians=0,i.lastPosition=new t,i.scaledInnerPosition=new t,i}return c(i,e),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(e){this._parent=e,null!==this._parent&&t.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(),t.add(this._position,this._parent.position,this.scaledInnerPosition)):t.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 e=Math.atan2(this._innerPosition.y,this._innerPosition.x)+(this._parent.rotation.radians-this.lastParentRadians);this.cache.set(Math.cos(e),Math.sin(e)),t.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}(w),ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.physicsManager=e.container.getSingleton("PhysicsManager"),e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return c(e,t),e.prototype.update=function(){this.activateColliders&&(this.colliders.forEach((function(t){return t.active=!0})),this.activateColliders=!1),this.updateRealSize(),this.updatePosition(),this.updateColliders()},e.prototype.collidesWithLayer=function(t){return null!==this.getCollisionWithLayer(t)},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++)for(var n=i[e],s=0,r=this.physicsManager.getCollisionsForCollider(n);s<r.length;s++){var o=r[s];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var s=n[i],r=0,o=this.physicsManager.getCollisionsForCollider(s);r<o.length;r++){var a=o[r];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.group),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(b),de=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMultiple=!1,t.physicsManager=t.container.getSingleton("PhysicsManager"),t}return c(i,e),Object.defineProperty(i.prototype,"velocity",{get:function(){return this.rigidBody.velocity},set:function(t){this.rigidBody.velocity.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"gravity",{get:function(){return this.rigidBody.gravity},set:function(t){this.rigidBody.gravity=Math.abs(t)},enumerable:!1,configurable:!0}),i.prototype.init=function(e){var i,n=e.rigidBodyType,s=e.gravity;if(0===this.getColliderIds().length)throw new T("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:n,colliderIds:this.getColliderIds(),gravity:null!==(i=Math.abs(s))&&void 0!==i?i:0,velocity:new t,position:new t})},i.prototype.update=function(){if(0===this.getColliderIds().length)throw new T("RigidBody needs at least one Collider with physics");this.rigidBody.colliderIds=this.getColliderIds(),this.rigidBody.position=this.gameObject.transform.parent?this.gameObject.transform.innerPosition:this.gameObject.transform.position},i.prototype.getColliderIds=function(){return this.gameObject.getComponents().filter((function(t){return t instanceof ue&&t.physics})).reduce((function(t,e){return d(d([],t,!0),e.colliders.map((function(t){return t.id})),!0)}),[])},i.prototype.onActiveChange=function(){this.rigidBody.active=this.active},i.prototype.onDestroy=function(){this.physicsManager.removeRigidBody(this.rigidBody)},i}(v),pe="Default",ge=function(t){function e(e,i,n){void 0===i&&(i="");var s=t.call(this,e)||this;return s.id=g(),s.layer="Default",s.ui=!1,s.keep=!1,s._parent=null,s._active=!0,s.components=[],s.activeComponentsCache=[],s.activeChildrenCache=[],s.name=i,s.addComponent(ce),s.parent=null!=n?n:null,s}return c(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(ce)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(de)},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,s="string"==typeof e?e:i,r=new t(this.container,this,s);return this.checkMultipleComponent(r,t),this.components.push(r),r.dispatch(p.Init,n),r},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new T("GameObject only allows one component of type ".concat(e.name))},e.prototype.getComponents=function(t){return t?this.components.filter((function(e){return e instanceof t})):this.components},e.prototype.getComponent=function(t){return"string"==typeof t?this.components.find((function(e){return e.name===t})):this.components.find((function(e){return e instanceof t}))},e.prototype.hasComponent=function(t){return"string"==typeof t?this.components.some((function(e){return e.name===t})):this.components.some((function(e){return e instanceof t}))},e.prototype.removeComponent=function(t){var e=this.components.indexOf(t);-1!==e&&this.components.splice(e,1)[0].dispatch(p.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(p.Destroy),delete this.components[t];this.components=[]},e}(y),me=["Default"],fe=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.renderManager=t.container.getSingleton("RenderManager"),t.canvas=t.container.getSingleton("DomManager").canvas,t.viewportRect=new e(0,0,0,0),t.worldSpaceRect=new e(0,0,0,0),t.depth=0,t.layers=me,t._zoom=1,t}return c(n,i),Object.defineProperty(n.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new T("zoom must be greather than 0");this._zoom=t},enumerable:!1,configurable:!0}),n.prototype.addLayer=function(t){this.layers.push(t)},n.prototype.init=function(){this.cameraData={position:new t,layers:[],depth:1}},n.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},n.prototype.updateViewportRect=function(){this.viewportRect.x=-this.canvas.width/2,this.viewportRect.y=-this.canvas.height/2,this.viewportRect.width=this.canvas.width,this.viewportRect.height=this.canvas.height},n.prototype.updateWorldSpaceRect=function(){this.worldSpaceRect.x=(this.gameObject.transform.position.x-this.viewportRect.width/2)/this._zoom,this.worldSpaceRect.y=(this.gameObject.transform.position.y-this.viewportRect.height/2)/this._zoom,this.worldSpaceRect.width=this.viewportRect.width/this._zoom,this.worldSpaceRect.height=this.viewportRect.height/this._zoom},n.prototype.updateCameraData=function(){this.cameraData.position.copy(this.gameObject.transform.position),this.cameraData.depth=this.depth,this.cameraData.layers=this.layers,this.cameraData.zoom=this._zoom,this.renderManager.addCameraData(this.cameraData)},n}(_),ye=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return c(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(fe)},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}(ge),xe=function(t){function e(e,i,n){var s=t.call(this,e)||this;return s.name=i,s.game=n,s.game.config.headless||s.addGameObject(ye),s}return c(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ye)},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}(y),ve=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.scaledVertexModel=[],i.scaledOffset=new t,i.scaledPosition=new t,i.finalRotation=0,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==kt.SAT)throw new T("Polygon Colliders need SAT collision method.");if(e.vertexModel.length<3)throw new T("Polygon Collider needs at least 3 vertices.");this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(s=e.offsetY)&&void 0!==s?s:this.offsetY,this.physics=null!==(r=e.physics)&&void 0!==r?r:this.physics,this.rotation=null!==(o=e.rotation)&&void 0!==o?o:new h,this.layer=e.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new t);this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new ee(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(be,{collider:this.colliders[0]}))},i.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},i.prototype.updatePosition=function(){t.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.scaledPosition),this.colliders[0].rotation=this.finalRotation,this.colliders[0].shape.vertexModel=this.scaledVertexModel},i}(ue),be=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:P.WorldSpace,layer:this.gameObject.layer,position:new t,shape:O.Polygon,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.rotation=this.collider.shape.rotation,this.renderData.vertexModel=this.collider.shape.vertexModel,this.renderManager.addRenderData(this.renderData)},i}(j),Me=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realWidth=0,i.realHeight=0,i.realOffset=new t,i.realPosition=new t,i.realRotation=0,i.applyRotation=i.container.getConstant("GameConfig").collisions.collisionMethod===kt.SAT,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(t){var e,i,n,s,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!==(s=t.debug)&&void 0!==s?s:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:new h,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(o=this.layer)&&void 0!==o?o:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new ie(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(be,{collider:this.colliders[0]}))},i.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},i.prototype.updatePosition=function(){t.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].rotation=this.realRotation,this.colliders[0].shape.updateSize(this.realWidth,this.realHeight)},i}(ue),we=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.realRadius=0,i.realOffset=new t,i.realPosition=new t,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(t){var e,i,n,s,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!==(s=t.debug)&&void 0!==s?s:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new Zt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(Ce,{collider:this.colliders[0]}))},i.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},i.prototype.updatePosition=function(){t.add(this.realPosition,this.gameObject.transform.position,this.realOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.realPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateColliders=function(){var t;this.colliders[0].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[0].position.copy(this.realPosition),this.colliders[0].shape.radius=this.realRadius},i}(ue),Ce=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:P.WorldSpace,layer:this.gameObject.layer,position:new t,shape:O.Circumference,color:"#00FF00"},this.collider=i},i.prototype.update=function(){this.renderData.layer=this.gameObject.layer,this.renderData.position.copy(this.collider.position),this.renderData.radius=this.collider.shape.radius,this.renderManager.addRenderData(this.renderData)},i}(j),_e=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.position=new t,i}return c(i,e),i.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,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===A.Center?-this.scaledWidth/2:0),this.gameObject.transform.position.y+([A.Center,A.RightCenter].includes(this.tilemapRenderer.orientation)?this.scaledHeight/2:this.tilemapRenderer.orientation==A.RightUp?this.scaledHeight:0)),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(je,{colliders:this.colliders}))},i.prototype.useBoxColliders=function(){var e=this;this.tilemapRenderer.tiles.forEach((function(i,n){var s;e.needsCollider(i,n)&&e.colliders.push(e.physicsManager.addCollider({layer:null!==(s=e.layer)&&void 0!==s?s:e.gameObject.layer,position:new t(e.position.x+(n%e.tilemapRenderer.width+.5)*e.scaledTileWidth,e.position.y-(Math.floor(n/e.tilemapRenderer.width)+.5)*e.scaledTileHeight),shape:new ie(e.scaledTileWidth,e.scaledTileHeight),updateCollisions:!1,physics:e.physics,group:e.gameObject.id}))}))},i.prototype.useLineColliders=function(){var e,i,n=this,s=[],r=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,o=Math.floor(e/n.tilemapRenderer.width);s[o]||(s[o]=[]),s[o+1]||(s[o+1]=[]),r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(s[o][i]=!0,s[o][i+1]=!0),n.hasTile(a[2])||(s[o+1][i]=!0,s[o+1][i+1]=!0),n.hasTile(a[1])||(r[o][i]=!0,r[o+1][i]=!0),n.hasTile(a[3])||(r[o][i+1]=!0,r[o+1][i+1]=!0)}}));for(var o=0;o<s.length;o++)for(var a=0;a<s[o].length;a++)!e||!i||o*-this.scaledTileHeight===i.y&&s[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),s[o][a]&&(e?i=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight):e=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight));e&&i&&this.addLineCollider(e,i),e=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<r.length;o++)!e||!i||a*this.scaledTileWidth===i.x&&r[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),r[o][a]&&(e?i=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight):e=new t(a*this.scaledTileWidth,o*-this.scaledTileHeight));e&&i&&this.addLineCollider(e,i)},i.prototype.hasTile=function(t){return void 0!==t&&this.tilemapRenderer.tiles[t]&&this.tilemapRenderer.tiles[t]>0},i.prototype.addLineCollider=function(t,e){var i,n=this.physicsManager.addCollider({layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,position:this.position.clone(),shape:new te([t.clone(),e.clone()]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id});this.colliders.push(n)},i.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]}))},i.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]},i.prototype.updateRealSize=function(){},i.prototype.updatePosition=function(){},i.prototype.updateColliders=function(){var t=this;this.colliders.forEach((function(e){var i;return e.layer=null!==(i=t.layer)&&void 0!==i?i:t.gameObject.layer}))},i}(ue),je=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,n=e.colliders;this.colliders=n,this.colliders.forEach((function(e,n){i.renderData[n]={type:R.Geometric,layer:i.gameObject.layer,location:P.WorldSpace,position:new t,shape:O.Polygon,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position.copy(e.shape.position),t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(j),Oe=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.offsetX=0,i.offsetY=0,i.scaledVertexModel=[],i.scaledOffset=new t,i.scaledPosition=new t,i.finalRotation=0,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a;if(this.container.getConstant("GameConfig").collisions.collisionMethod!==kt.SAT)throw new T("Edge Colliders need SAT collision method.");if(e.vertexModel.length<2)throw new T("Edge Collider needs at least 2 vertices.");this.debug=(null!==(i=e.debug)&&void 0!==i?i:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(s=e.offsetY)&&void 0!==s?s:this.offsetY,this.physics=null!==(r=e.physics)&&void 0!==r?r:this.physics,this.rotation=null!==(o=e.rotation)&&void 0!==o?o:new h,this.layer=e.layer;for(var l=0;l<this.vertexModel.length;l++)this.scaledVertexModel.push(new t);for(l=0;l<this.scaledVertexModel.length-1;l++)this.colliders.push(this.physicsManager.addCollider({layer:null!==(a=this.layer)&&void 0!==a?a:this.gameObject.layer,position:this.gameObject.transform.position.clone(),rotation:this.rotation.radians,shape:new te([this.scaledVertexModel[l],this.scaledVertexModel[l+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(Pe,{colliders:this.colliders}))},i.prototype.updateRealSize=function(){var t=this;this.vertexModel.forEach((function(e,i){return t.scaledVertexModel[i].set(e.x*t.gameObject.transform.scale.x,e.y*t.gameObject.transform.scale.y)})),this.scaledOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.scaledOffset.y=this.offsetY*this.gameObject.transform.scale.y,this.finalRotation=this.gameObject.transform.rotation.radians+this.rotation.radians},i.prototype.updatePosition=function(){t.add(this.scaledPosition,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translate()},i.prototype.translate=function(){t.subtract(this.innerPosition,this.scaledPosition,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i.prototype.updateColliders=function(){for(var t,e=0;e<this.scaledVertexModel.length-1;e++)this.colliders[e].layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.colliders[e].position.copy(this.scaledPosition),this.colliders[e].rotation=this.finalRotation,this.colliders[e].shape.vertexModel=[this.scaledVertexModel[e],this.scaledVertexModel[e+1]]},i}(ue),Pe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,n=e.colliders;this.colliders=n,this.colliders.forEach((function(e,n){i.renderData[n]={type:R.Geometric,layer:i.gameObject.layer,location:P.WorldSpace,position:new t,shape:O.Line,color:"#00FF00"}}))},i.prototype.update=function(){var t=this;this.colliders.forEach((function(e,i){t.renderData[i].layer=t.gameObject.layer,t.renderData[i].position=e.position,t.renderData[i].rotation=e.rotation,t.renderData[i].vertexModel=e.shape.vertexModel,t.renderManager.addRenderData(t.renderData[i])}))},i}(j),Re=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.spriteDefaultScale=i.container.getConstant("GameConfig").spriteDefaultScale,i.renderData=[],i.innerPosition=new t,i.cachePosition=new t,i.cacheRenderPosition=new t,i.scaledOffset=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a,l;void 0===e&&(e={}),this.sprite=e.sprite,this.offset=null!==(i=e.offset)&&void 0!==i?i:new t,this.rotation=null!==(n=e.rotation)&&void 0!==n?n:new h,this.flipHorizontal=null!==(s=e.flipHorizontal)&&void 0!==s&&s,this.flipVertical=null!==(r=e.flipVertical)&&void 0!==r&&r,this.opacity=null!==(o=e.opacity)&&void 0!==o?o:1,this._tiled=null!==(a=e.tiled)&&void 0!==a?a:new t(1,1),this.maskColor=e.maskColor,this.maskColorMix=null!==(l=e.maskColorMix)&&void 0!==l?l:0,this.tintColor=e.tintColor,this.layer=e.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 T("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 e=0;e<this._tiled.x*this._tiled.y;e++)this.renderData[e]={type:R.Sprite,location:P.WorldSpace,layer:"",position:new t,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n;this.renderData[t].location=this.gameObject.ui?P.ViewPort:P.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(e,i,n){this.scaledOffset.set(this.offset.x*this.gameObject.transform.scale.x,this.offset.y*this.gameObject.transform.scale.y),t.add(this.cachePosition,this.gameObject.transform.position,this.scaledOffset),this.cacheRenderPosition.set(this.renderData[e].width/2*(this._tiled.x-1),this.renderData[e].height/2*(this._tiled.y-1)),t.subtract(this.cachePosition,this.cachePosition,this.cacheRenderPosition),this.cacheRenderPosition.set(i*this.renderData[e].width,n*this.renderData[e].height),t.add(this.renderData[e].position,this.cachePosition,this.cacheRenderPosition),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition(e)},i.prototype.translateRenderPosition=function(e){t.subtract(this.innerPosition,this.renderData[e].position,this.gameObject.transform.position);var i=Math.atan2(this.innerPosition.y,this.innerPosition.x)+this.gameObject.transform.rotation.radians;this.renderData[e].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}(j),Ae=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.lastFrameText="",t}return c(i,e),i.prototype.init=function(e){var i,n,s,r,o,a,l,c,u,d,p,g;if(this.text=e.text,this.font=null!==(i=e.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(n=e.fontSize)&&void 0!==n?n:12,this.width=null!==(s=e.width)&&void 0!==s?s:100,this.height=null!==(r=e.height)&&void 0!==r?r:100,this.offset=null!==(o=e.offset)&&void 0!==o?o:new t,this.color=null!==(a=e.color)&&void 0!==a?a:"#000000",this.charRanges=null!==(l=e.charRanges)&&void 0!==l?l:[32,126,161,255],this.lineSeparation=null!==(c=e.lineSeparation)&&void 0!==c?c:0,this.letterSpacing=null!==(u=e.letterSpacing)&&void 0!==u?u:0,this.smooth=null!==(d=e.smooth)&&void 0!==d&&d,this.rotation=null!==(p=e.rotation)&&void 0!==p?p:new h,this.opacity=null!==(g=e.opacity)&&void 0!==g?g:1,this.orientation=e.orientation,this.bitmapMargin=e.bitmapMargin,this.bitmapSpacing=e.bitmapSpacing,this.charRanges.length%2!=0)throw new T("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new T("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:R.Text,location:P.WorldSpace,position:new t,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 e,i;this.text&&(this.renderData.layer=this.gameObject.layer,this.renderData.location=this.gameObject.ui?P.ViewPort:P.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===(e=this.rotation)||void 0===e?void 0:e.radians))&&void 0!==i?i:0,this.renderData.alpha=this.opacity,t.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,s=this.text.split("\n");n<s.length;n++)for(var r=0,o=null!==(t=s[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];r<o.length;r++){var a=o[r];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(j),Se=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.offset=new t,i.rotation=new h,i.opacity=1,i.innerPosition=new t,i.scaledOffset=new t,i}return c(i,e),i.prototype.init=function(e){var i,n,s,r;this.width=e.width,this.height=e.height,this.color=e.color,this.offset=null!==(i=e.offset)&&void 0!==i?i:this.offset,this.rotation=null!==(n=e.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(s=e.opacity)&&void 0!==s?s:this.opacity,this.layer=e.layer,this.renderData={type:R.Mask,layer:null!==(r=this.layer)&&void 0!==r?r:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?P.ViewPort:P.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),t.add(this.renderData.position,this.gameObject.transform.position,this.scaledOffset),0!==this.gameObject.transform.rotation.radians&&this.translateRenderPosition()},i.prototype.translateRenderPosition=function(){t.subtract(this.innerPosition,this.renderData.position,this.gameObject.transform.position);var e=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(e),this.gameObject.transform.position.y+this.innerPosition.magnitude*Math.sin(e))},i}(j),Te=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.tiles=[],t.tilesetTileIds=[],t.chunks=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t.renderData=[],t}return c(i,e),i.prototype.init=function(t){var e=t.tiledData,i=t.tilemapLayer,n=t.tileset,s=t.tileWidth,r=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=s,this.tileHeight=r,this.layer=o,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(e){return t.processChunk(e)})):t.processChunk(e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(e){var i,n=this,s={type:R.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,tileset:this.tileset,tilemap:{width:e.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:e.data.map((function(t){return n.getTilesetTileId(t)})),orientation:this.orientation,smooth:this.smooth};e.type&&"tilelayer"===e.type?this.tiles=s.tiles:s.tiles.forEach((function(t,i){n.tiles[n.tiledData.width*(e.y+Math.floor(i/e.width))+e.x+i%e.width]=t})),this.renderData.push(s),this.chunks.push(e)},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}(j),De=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderManager=t.container.getSingleton("RenderManager"),t.tiles=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t}return c(i,e),i.prototype.init=function(e){var i,n=this,s=e.tiles,r=e.tileset,o=e.tileWidth,a=e.tileHeight,h=e.width,l=e.layer,c=e.orientation,u=e.alpha,d=e.tintColor,p=e.smooth;s.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=r,this.width=h,this.tileWidth=o,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=u,this.tintColor=d,this.renderData={type:R.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?P.ViewPort:P.WorldSpace,position:new t,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}(j),Ee=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},Fe=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 c(e,t),e.prototype.init=function(t){var e=t.spriteRenderer;this.spriteRenderer=e},e.prototype.update=function(){null===this.currentAnimation||this.paused||(this.currentAnimation.playFrame(this.timeManager.deltaTime),!0===this.currentAnimation.restarted&&!1===this.currentAnimation.loop?this.currentAnimation=null:this.spriteRenderer.sprite=this.currentAnimation.sprite)},e.prototype.addAnimation=function(t,e,i){return void 0===e&&(e="default"),t.framerate=null!=i?i:t.framerate,this.animations.set(e,new Be(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new T("Animation with name ".concat(t," does not exist."));this.stopAnimation(),this.currentAnimation=this.animations.get(t)}},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused=!1},e.prototype.stopAnimation=function(){null!==this.currentAnimation&&(this.currentAnimation.reset(),this.currentAnimation=null)},e.prototype.isPlayingAnimation=function(t){return this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(v),Be=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}(),Ie=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Ue=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.tracks=[],e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e._audioSource.removeEventListener("ended",e.audioEventHandler))},e.userInputEventHandler=function(){Ie.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource.play()},e}return c(e,t),e.prototype.init=function(t){var e=void 0===t?{}:t,i=e.audioSource,n=e.loop,s=e.volume,r=e.playOnStart;this.audioContext=new AudioContext,i&&(this.audioSource=i),this._volume=null!=s?s:1,this._loop=null!=n&&n,this.playOnStart=null!=r&&r},e.prototype.start=function(){this.playOnStart&&this.play()},Object.defineProperty(e.prototype,"audioSource",{get:function(){return this._audioSource},set:function(t){if(this._audioSource=t.cloneNode(),!this.tracks.find((function(e){return e.mediaElement.src===t.src}))){var e=this.audioContext.createMediaElementSource(this._audioSource);e.connect(this.audioContext.destination),this.tracks.push(e)}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.audioSource&&(this._audioSource.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.audioSource&&(this._audioSource.loop=t)},enumerable:!1,configurable:!0}),e.prototype.playClip=function(t,e){t.currentTime>0&&(t.currentTime=0),t.volume=null!=e?e:this._volume,t.play()},e.prototype.play=function(){var t=this;if(this._audioSource&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this._audioSource.play();this._audioSource.volume=this._volume,this._audioSource.loop=this._loop,this._audioSource.addEventListener("ended",this.audioEventHandler),this._playing=!0,this._audioSource.play().catch((function(){"running"!==t.audioContext.state&&Ie.forEach((function(e){return window.addEventListener(e,t.userInputEventHandler)}))}))}},e.prototype.stop=function(){this._playing&&(this._audioSource.pause(),this._audioSource.currentTime=0,this._audioSource.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this._audioSource.pause(),this._paused=!0)},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop(),this.audioContext.close()},e}(v),Ge=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}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(ne||(ne={}));var Le=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.allowMultiple=!1,i.width=100,i.height=100,i.radius=50,i.touchEnabled=!0,i._offset=new t,i.pressed=!1,i.mouse=i.container.getSingleton("InputManager").mouse,i.touch=i.container.getSingleton("InputManager").touch,i.position=new t,i.distance=new t,i.pressedLastFrame=!1,i.scaled={width:0,height:0,radius:0,offset:new t},i}return c(i,e),Object.defineProperty(i.prototype,"offset",{get:function(){return this._offset},set:function(t){this._offset=t},enumerable:!1,configurable:!0}),i.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,s=t.touchEnabled,r=t.width,o=t.offset;this.type=e,this.width=null!=r?r:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=s?s:this.touchEnabled,this._offset=null!=o?o:this._offset},i.prototype.update=function(){this.scale(),t.add(this.position,this.gameObject.transform.position,this.scaled.offset),this.pressedLastFrame=this.pressed,this.pressed=!1,this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(),this.resolveMouseAndCircumference()),this.touchEnabled&&this.touch.touching&&(this.resolveTouchAndRectangle(),this.resolveTouchAndCircumference()),this.onClick&&!this.pressedLastFrame&&this.pressed&&this.onClick(),this.onPressed&&this.pressed&&this.onPressed()},i.prototype.scale=function(){this.scaled.width=this.width*this.gameObject.transform.scale.x,this.scaled.height=this.width*this.gameObject.transform.scale.y,this.scaled.offset.x=this._offset.x*this.gameObject.transform.scale.x,this.scaled.offset.y=this._offset.y*this.gameObject.transform.scale.y,this.scaled.radius=this.radius*this.gameObject.transform.scale.magnitude},i.prototype.resolveMouseAndRectangle=function(){this.type===ne.Rectangle&&(this.pressed||(this.pressed=a(this.mouse.positionInViewport.x,this.position.x-this.scaled.width/2,this.position.x+this.scaled.width/2)&&a(this.mouse.positionInViewport.y,this.position.y-this.scaled.height/2,this.position.y+this.scaled.height/2)))},i.prototype.resolveMouseAndCircumference=function(){this.type===ne.Circumference&&(t.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius))},i.prototype.resolveTouchAndRectangle=function(){this.type===ne.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))},i.prototype.resolveTouchAndCircumference=function(){this.type===ne.Circumference&&(t.subtract(this.distance,this.position,this.touch.positionInViewport),this.pressed||(this.pressed=this.distance.magnitude<=this.scaled.radius+this.touch.radius.x))},i}(x),ke=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new t,i}return c(i,e),i.prototype.start=function(){this.camera=this.getCurrentScene().gameCamera},i.prototype.update=function(){Y.mouse.leftButtonPressed&&!1===this.mousePressed&&(t.round(this.position,t.add(this.position,this.camera.transform.position,t.scale(this.position,Y.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=Y.mouse.leftButtonPressed},i}(ge);export{Ee as Animation,Fe as Animator,H as AssetManager,Ue as AudioPlayer,we as BallCollider,Me as BoxCollider,Gt as BroadPhaseMethods,Le as Button,ne as ButtonType,fe as Camera,kt as CollisionMethods,x as Component,z as DomManager,Oe as EdgeCollider,le as Game,ye as GameCamera,ge as GameObject,q as GameObjectManager,F as GamepadController,B as GamepadData,Y as InputManager,U as KeyboardController,pe as LAYER_DEFAULT,Se as MaskRenderer,G as MouseController,M as PhysicsComponent,ve as PolygonCollider,be as PolygonColliderRenderer,C as PreRenderComponent,e as Rectangle,de as RigidBody,Vt as RigidBodyType,h as Rotation,xe as Scene,N as SceneManager,ke as SpacePointer,Ge as Sprite,Re as SpriteRenderer,Mt as TextOrientation,Ae as TextRenderer,Te as TiledTilemapRenderer,_e as TilemapCollider,A as TilemapOrientation,De as TilemapRenderer,X as TimeManager,W as TouchController,ce as Transform,t as Vector2,a as between,i as clamp,r as fixedRound,s as randomFloat,n as randomInt,o as range};