angry-pixel 1.1.15 → 1.2.1

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,r){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,r)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(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,r=(t,e,i=2)=>s(Math.random()*(e-t)+t,i),s=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),o=(t,e,i=1)=>{const n=[];for(let r=t;r<=e;r+=i)n.push(r);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 r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},d.apply(this,arguments)};function u(t,e,i){if(i||2===arguments.length)for(var n,r=0,s=e.length;r<s;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var 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",t[t.StopGame=11]="StopGame"}(p||(p={}));var m,f=function(){function t(t,e,i,n,r,s,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=r,this.sceneManager=s,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.stopGame(),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(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()):t===p.StopGame&&(this.onDestroy&&this.onDestroy(),this._stopGame()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),v=function(t){function e(e,i,n){void 0===n&&(n="");var r=t.call(this,e)||this;return r.id=g(),r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=n,r}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())},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){},e}(y),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateEngine,e}return c(e,t),e}(v),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}(v),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}(v),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}(v),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePreRender,e}return c(e,t),e}(v),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCamera,e}return c(e,t),e}(v),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}(v);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(m||(m={}));var O,P,R,A,S=function(){function t(t){this.renderManager=t,this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.loadImage=function(t,e){var i=this;void 0===e&&(e=!1);var n=new Image;n.crossOrigin="",n.src=t;var r=this.createAsset(t,m.Image,n),s=function(){e&&i.renderManager.preloadTexture(n),r.loaded=!0};return n.naturalWidth?s():n.addEventListener("load",s),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,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.loadVideo=function(t){var e=document.createElement("video");e.playsInline=!0,e.src=t;var i=this.createAsset(t,m.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===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.getVideo=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===m.Video&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var n={type:e,url:t,element:i,loaded:!1};return this.assets.push(n),n},t}(),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 r=new t(this.container,n,i);return this.gameObjects.push(r),r.dispatch(p.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):u([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(t){var e=this;void 0===t&&(t=!1),this.gameObjects.filter((function(e){return t||!e.keep})).forEach((function(t){return e.destroy(t,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var n=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(n),n.dispatch(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,this._vibrating=!1}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}),Object.defineProperty(e.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),e.prototype.vibrate=function(t,e,i,n){var r=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return r._vibrating=!1})).finally((function(){return r._vibrating=!1})))},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.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),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 r=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(r.container,e,r.container.getConstant("Game"));return r.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.prototype.stopGame=function(){null!==this.currentScene&&(this.currentScene.dispatch(p.StopGame),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),V=[60,120,180,240],k=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}(),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,e){return this.assetManager.loadImage(t,e)},t.loadAudio=function(t){return this.assetManager.loadAudio(t)},t.loadFont=function(t,e){return this.assetManager.loadFont(t,e)},t.loadVideo=function(t){return this.assetManager.loadVideo(t)},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.getVideo=function(t){return this.assetManager.getVideo(t)},t.assetManager=null,t}(),z=function(){function t(){}return t.initialize=function(t){this.domManager=t},Object.defineProperty(t,"gameWidth",{get:function(){return this.domManager.canvas.width},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gameHeight",{get:function(){return this.domManager.canvas.height},enumerable:!1,configurable:!0}),Object.defineProperty(t,"canvas",{get:function(){return this.domManager.canvas},enumerable:!1,configurable:!0}),t.domManager=null,t}(),N=function(){function t(){}return t.initialize=function(t){this.inputManager=t},Object.defineProperty(t,"mouse",{get:function(){return this.inputManager.mouse},enumerable:!1,configurable:!0}),Object.defineProperty(t,"keyboard",{get:function(){return this.inputManager.keyboard},enumerable:!1,configurable:!0}),Object.defineProperty(t,"gamepad",{get:function(){return this.inputManager.gamepad},enumerable:!1,configurable:!0}),Object.defineProperty(t,"touch",{get:function(){return this.inputManager.touch},enumerable:!1,configurable:!0}),t.inputManager=null,t}(),Y=function(){function t(){}return t.initialize=function(t){this.sceneManager=t},t.loadScene=function(t){this.sceneManager.loadScene(t)},t.getCurrentSceneName=function(){return this.sceneManager.currentSceneName},t.loadOpeningScene=function(){this.sceneManager.loadOpeningScene()},t.sceneManager=null,t}(),X=function(){function t(){}return t.initialize=function(t){this.timeManager=t},Object.defineProperty(t,"deltaTime",{get:function(){return this.timeManager.deltaTime},enumerable:!1,configurable:!0}),t.getTimeScale=function(){return this.timeManager.timeScale},t.setTimeScale=function(t){this.timeManager.timeScale=t},Object.defineProperty(t,"unscaledDeltaTime",{get:function(){return this.timeManager.unscaledGameDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"physicsDeltaTime",{get:function(){return this.timeManager.physicsDeltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(t,"browserDeltaTime",{get:function(){return this.timeManager.browserDeltaTime},enumerable:!1,configurable:!0}),t.timeManager=null,t}(),q=function(){function t(){}return t.initialize=function(t){this.manager=t},t.addGameObject=function(t,e,i,n){return this.manager.addGameObject(t,e,i,n)},t.findAllGameObjects=function(){return this.manager.findGameObjects()},t.findGameObjects=function(t){return this.manager.findGameObjects(t)},t.findGameObject=function(t){return this.manager.findGameObject(t)},t.findGameObjectsByParent=function(t){return this.manager.findGameObjectsByParent(t)},t.findGameObjectByParent=function(t,e){return this.manager.findGameObjectByParent(t,e)},t.findGameObjectsByTag=function(t){return this.manager.findGameObjectsByTag(t)},t.destroyGameObject=function(t){this.manager.destroyGameObject(t)},t}(),K=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",t[t.Video=5]="Video"}(R||(R={}));class ${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 r=Math.abs(Math.sin(n)),s=Math.abs(Math.cos(n)),o=r*i+s*e,a=r*e+s*i;this.object.x=t.x-o/2,this.object.x1=t.x+o/2,this.object.y=t.y-a/2,this.object.y1=t.y+a/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:n,letterSpacing:r,rotation:s}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=n?n:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:s})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:n}){i===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:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*n&&this.viewport.x<=this.object.x+e%i*n+n&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case R.Video: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)}preloadTexture(t){this.webglManager.createTexture(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(this.symbol(t))}getFontAtlas(t){return this.fontAtlas.get(this.symbol(t))}getOrCreate(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)}create(t,e,i){this.bitmapSize=i,this.chars=[];for(let e=0;e<t.length;e+=2)for(let i=t[e];i<=t[e+1];i++)this.chars.push(String.fromCharCode(i));const n=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),n),n}symbol(t){return Symbol.for(t instanceof FontFace?t.family:t)}renderAtlas(t){const e=new 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,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],n,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e}}class 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),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i);const s=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,s)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class rt{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 st{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,r,s,o,a,h,l,c,d,u,p,g,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(n=e[0],r=e[1],s=e[2],o=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],u=e[9],p=e[10],g=e[11],t[0]=n,t[1]=r,t[2]=s,t[3]=o,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=u,t[10]=p,t[11]=g,t[12]=n*m+a*f+d*y+e[12],t[13]=r*m+h*f+u*y+e[13],t[14]=s*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function ct(t,e,i){var n=i[0],r=i[1],s=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function dt(t,e,i){var n=Math.sin(i),r=Math.cos(i),s=e[0],o=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],u=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*r+l*n,t[1]=o*r+c*n,t[2]=a*r+d*n,t[3]=h*r+u*n,t[4]=l*r-s*n,t[5]=c*r-o*n,t[6]=d*r-a*n,t[7]=u*r-h*n,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var 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 r,s;(function(t,e,i,n,r,s,o){var a=1/(e-i),h=1/(n-r),l=1/(s-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=(o+s)*l,t[15]=1})(t=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!==(r=i.zoom)&&void 0!==r?r:1,null!==(s=i.zoom)&&void 0!==s?s:1,1])};class vt{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 r;const s=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(s)&&this.vertices.set(s,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(s);this.lastVertices===s&&n===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=s,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!==(r=t.rotation)&&void 0!==r?r: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:r,a:s}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,n,r,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class xt{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,r;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:s,g:o,b:a,a:h}=ft(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,s,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class 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,r,s,o;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}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,_t=new Q,Ct=[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)throw new Error("Nothing to render");this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=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 s=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===s&&i===R.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,s),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=s),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);const{r:o,g:a,b:h,a:l}=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,r,s,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:_t,t.bitmap.fontSize=null!==(n=t.bitmap.fontSize)&&void 0!==n?n:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:Ct):t.bitmap={margin:wt,spacing:_t,fontSize:64,charRanges:Ct},t.color=null!==(s=t.color)&&void 0!==s?s:"#000000",t.letterSpacing=null!==(o=t.letterSpacing)&&void 0!==o?o:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:jt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:n,letterSpacing:r,lineSeparation:s}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;r/=i,s/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,o),o=0,a-=1+s;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(o,a-1,o+e,a-1,o,a,o,a,o+e,a-1,o+e,a);const i=c.id%t.gridSize*t.bitmapFontSize,s=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+n.margin.x)/t.canvas.width,l=(s+n.margin.y)/t.canvas.width,d=(i+c.width+n.spacing.x)/t.canvas.width,u=(s+t.bitmapFontSize+n.spacing.y)/t.canvas.width;this.texVertices.push(h,u,d,u,h,l,h,l,d,u,d,l),o+=e+r}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-1)*i)}setPositionFromOrientation(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,r,s,o;if(0===t.culledTiles.reduce(((t,e)=>t+e),0))throw new Error("Nothing to render");if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)throw new Error("Nothing to render");this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)}processTileset({tileset:t}){var e,i,n,r,s,o,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new Q,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new Q,t.correction=null!==(n=t.correction)&&void 0!==n?n:new Q,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(s=t.spacing.x)&&void 0!==s?s:0),this.tileset.tileHeight=t.tileHeight+(null!==(o=t.margin.y)&&void 0!==o?o:0)+(null!==(a=t.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(t.margin.x/this.tileset.tileWidth,t.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(t.spacing.x/this.tileset.tileWidth,t.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(t.correction.x/this.tileset.tileWidth,t.correction.y/this.tileset.tileHeight),this.tileset.texWidth=1-this.tileset.texMargin.x-this.tileset.texSpacing.x-2*this.tileset.texCorrection.x,this.tileset.texHeight=1-this.tileset.texMargin.y-this.tileset.texSpacing.y-2*this.tileset.texCorrection.y}generateVertices({culledTiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,n)=>{if(0===t)return;const r=n%e.width-e.width/2,s=i/2-Math.floor(n/e.width);this.posVertices.push(r,s-1,r+1,s-1,r,s,r,s,r+1,s-1,r+1,s);const o=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,a=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(o,a+this.tileset.texHeight,o+this.tileset.texWidth,a+this.tileset.texHeight,o,a,o,a,o+this.tileset.texWidth,a+this.tileset.texHeight,o+this.tileset.texWidth,a)}))}}class Rt{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,r,s,o;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=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.video.videoWidth,t.slice.y/t.video.videoHeight,0]),ct(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,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.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:n,a:r}=ft(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,n,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:n}=ft(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,n,null!==(s=t.alpha)&&void 0!==s?s:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class At{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(()=>this.createFromSource(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i}createPixelTexture(){const t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t}createFromSource(t,e,i=!0){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}}class St{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}getOrCreateTextureFromVideo(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)}createTextureFromVideo(t){const e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e}}class Tt{constructor(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}render(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}}clearCanvas(t){const e=ft(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}createTexture(t,e=!1){this.textureManager.createTextureFromImage(t,e)}}class Dt{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 Dt(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 Et{constructor(t,e,i,n){this._position=new Dt,this._center=new Dt,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 Et?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Dt&&!(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 Bt{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:n,position:r,rotation:s,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:n,position:null!=r?r:new Dt,rotation:null!=s?s:0,group:o,onCollision:a}}}class It{constructor(t,e=0){this.area=new Et(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 Et(this.area.x,this.area.y,t,e),new Et(this.area.x,this.area.y+e,t,e),new Et(this.area.x+t,this.area.y+e,t,e),new Et(this.area.x+t,this.area.y,t,e)].map((t=>new It(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 Ut=(t,e,i,n)=>Math.min((t-e)/i|0,n-1);class Gt{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=Ut(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Ut(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Ut(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Ut(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}var Lt,Vt,kt,Wt;!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Lt||(Lt={}));class Ht{constructor(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Dt,this.maxArea=new Dt,this.newArea=new Et(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:Lt.QuadTree,i)}setupBroadPhaseResolver(t,e){this.collisionArea=null!=e?e:new Et(0,0,0,0),this.fixedCollisionArea=!!e,t===Lt.SpartialGrid?this.broadPhaseResolver=new Gt(this.collisionArea):this.broadPhaseResolver=new It(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 Gt&&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"}(Vt||(Vt={}));class zt{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Vt.Polygon&&e.type===Vt.Polygon?this.AABBResolver.resolve(t,e):t.type===Vt.Circumference&&e.type===Vt.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Vt.Polygon&&e.type===Vt.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Vt.Circumference&&e.type===Vt.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(kt||(kt={}));class Nt{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Vt.Circumference&&e.type===Vt.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class Yt{constructor(){this.direction=new Dt,this.displacementDirection=new Dt}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)),Dt.unit(this.displacementDirection,this.displacementDirection),{direction:Dt.scale(new Dt,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 Xt{constructor(){this.closestPoint=new Dt,this.distance=new Dt,this.direction=new Dt}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)),Dt.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Dt.unit(this.direction,this.distance),{direction:i?Dt.scale(new Dt,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Dt.scale(new Dt,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class qt{constructor(){this.distance=new Dt,this.direction=new Dt}resolve(t,e){return Dt.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Dt.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Dt.scale(new Dt,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class Kt{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Dt,this.distance=new Dt(1/0,1/0),this.cache=new Dt}resolve(t,e){this.minOverlap=1/0,t.type===Vt.Circumference?this.setCircumferenceAxis(t,e):e.type===Vt.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===Vt.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Vt.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,Dt.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&&Dt.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Dt.scale(new Dt,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(Dt.dot(i,e),t.min),t.max=Math.max(Dt.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Dt.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Dt.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Dt.add(t.vertices[0],t.position,Dt.scale(this.cache,Dt.unit(this.cache,e),-t.radius)),Dt.add(t.vertices[1],t.position,Dt.scale(this.cache,Dt.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 Qt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:n,velocity:r,onResolve:s}){if(0===t.length)throw new Error("RigidBody needs at least one collider");return{id:++this.lastId,active:!0,colliderIds:t,type:e,gravity:null!=i?i:0,position:null!=n?n:new Dt,velocity:null!=r?r:new Dt,onResolve:s}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Wt||(Wt={}));const Jt=["x","y"];class Zt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Dt,this.displacement=new Dt,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),Jt.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Dt.add(t.position,t.position,Dt.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Dt.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 te{constructor(t){this.radius=t,this.type=Vt.Circumference,this.boundingBox=new Et(0,0,0,0),this.vertices=[new Dt,new Dt],this.projectionAxes=[new Dt],this._position=new Dt}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 ee{constructor(t){this.vertexModel=t,this.type=Vt.Polygon,this.vertices=[new Dt,new Dt],this.projectionAxes=[new Dt],this.boundingBox=new Et(0,0,0,0),this.rotation=0,this._position=new Dt}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(){Dt.normal(this.projectionAxes[0],Dt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class ie{constructor(t){this.vertexModel=t,this.type=Vt.Polygon,this.vertices=[],this.boundingBox=new Et(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Dt,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 Dt),this._projectionAxes.push(new Dt)}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++)Dt.normal(this._projectionAxes[e],Dt.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class ne extends ie{constructor(t,e){super([new Dt(-t/2,-e/2),new Dt(-t/2,e/2),new Dt(t/2,e/2),new Dt(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Dt,new Dt]}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(){Dt.unit(this.projectionAxes[0],Dt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Dt.normal(this.projectionAxes[1],this.projectionAxes[0])}}var re,se=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new k(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new E(t)})),t.add("PhysicsManager",(function(){return(({collisionArea:t,collisionMatrix:e,collisionMethod:i,collisionBroadPhaseMethod:n}={})=>{const r=new qt,s=i===kt.AABB?new zt(new Yt,new Xt,r):new Nt(r,new Kt),o=new Ht(s,n,t,e),a=new Bt,h=new Zt(o),l=new Qt;return new $t(o,a,h,l)})(e.collisions)})),e.headless?t.add("IterationManager",(function(){return new K(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,r=new rt(i,n,new nt(i,new st(i))),s=new St(new At(i)),o=new Tt(i,r,s,new Map([[R.Sprite,new bt(i,r,s)],[R.Text,new Ot(i,r,s,new et)],[R.Tilemap,new Pt(i,r,s)],[R.Geometric,new vt(i,r)],[R.Mask,new xt(i,r)],[R.Video,new Rt(i,r,s)]]));return new J(o,new $(i))})(t.getSingleton("DomManager").canvas)})),oe(t),t.add("AssetManager",(function(){return new S(t.getSingleton("RenderManager"))})),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"))})),ae(t,e)},oe=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))}))},ae=function(t,e){e.headless||(H.initialize(t.getSingleton("AssetManager")),z.initialize(t.getSingleton("DomManager")),N.initialize(t.getSingleton("InputManager"))),Y.initialize(t.getSingleton("SceneManager")),X.initialize(t.getSingleton("TimeManager")),q.initialize(t.getSingleton("GameObjectManager"))},he=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}(),le={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new t(1,1),collisions:{collisionMethod:kt.SAT,collisionBroadPhaseMethod:Lt.SpartialGrid}},ce=function(){function t(t){this._config=d(d({},le),t),this._config.collisions=d(d({},le.collisions),t.collisions),this.container=new he,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}(),de=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],r=0,s=this.physicsManager.getCollisionsForCollider(n);r<s.length;r++){var o=s[r];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],s=0,o=this.physicsManager.getCollisionsForCollider(r);s<o.length;s++){var a=o[s];a.remoteCollider.layer===t&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(t.remoteCollider.group),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject}}},e.prototype.onActiveChange=function(){var t=this;this.renderer&&(this.renderer.active=this.active),this.active?this.activateColliders=!0:this.colliders.forEach((function(e){return e.active=t.active}))},e.prototype.onDestroy=function(){var t=this;this.colliders.forEach((function(e){return t.physicsManager.removeCollider(e)}))},e}(b),pe=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,r=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(r))&&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 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}(x),ge="Default",me=function(t){function e(e,i,n){void 0===i&&(i="");var r=t.call(this,e)||this;return r.id=g(),r.layer="Default",r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.name=i,r.addComponent(de),r.parent=null!=n?n:null,r}return c(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus(),this.onActiveChange())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(de)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(pe)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.container.getSingleton("SceneManager").getCurrentScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r="string"==typeof e?e:i,s=new t(this.container,this,r);return this.checkMultipleComponent(s,t),this.components.push(s),s.dispatch(p.Init,n),s},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.prototype._stopGame=function(){},e}(y),fe=["Default"],ye=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=fe,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}(C),ve=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(ye)},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}(me),xe=function(t){function e(e,i,n){var r=t.call(this,e)||this;return r.name=i,r.game=n,r.game.config.headless||r.addGameObject(ve),r}return c(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ve)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!0),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(y),be=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,r,s,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!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(s=e.physics)&&void 0!==s?s: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 ie(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(Me,{collider:this.colliders[0]}))},i.prototype.updateRealSize=function(){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),Me=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),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.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,r,s,o;this.width=t.width,this.height=t.height,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.rotation=null!==(s=t.rotation)&&void 0!==s?s: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 ne(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(Me,{collider:this.colliders[0]}))},i.prototype.updateRealSize=function(){this.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),_e=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,r,s;this.radius=t.radius,this.offsetX=null!==(e=t.offsetX)&&void 0!==e?e:this.offsetX,this.offsetY=null!==(i=t.offsetY)&&void 0!==i?i:this.offsetY,this.physics=null!==(n=t.physics)&&void 0!==n?n:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.container.getConstant("GameConfig").debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new te(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),je=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(Oe,{colliders:this.colliders}))},i.prototype.useBoxColliders=function(){var e=this;this.tilemapRenderer.tiles.forEach((function(i,n){var r;e.needsCollider(i,n)&&e.colliders.push(e.physicsManager.addCollider({layer:null!==(r=e.layer)&&void 0!==r?r: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 ne(e.scaledTileWidth,e.scaledTileHeight),updateCollisions:!1,physics:e.physics,group:e.gameObject.id}))}))},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.useLineColliders=function(){var e,i,n=this,r=[],s=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,o=Math.floor(e/n.tilemapRenderer.width);r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]),s[o]||(s[o]=[]),s[o+1]||(s[o+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[o][i]=!0),n.hasTile(a[2])||(r[o+1][i]=!0),n.hasTile(a[1])||(s[o][i]=!0),n.hasTile(a[3])||(s[o][i+1]=!0)}}));for(var o=0;o<r.length;o++)if(r[o])for(var a=0;a<r[o].length;a++)!e||!i||o===i.y&&r[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),r[o][a]&&(e||(e=new t(a,o)),i=new t(a+1,o));e&&i&&this.addLineCollider(e,i),e=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<s.length;o++)s[o]&&(!e||!i||a===i.x&&s[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),s[o][a]&&(e||(e=new t(a,o)),i=new t(a,o+1)));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(e,i){var n,r=this.physicsManager.addCollider({layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,position:this.position.clone(),shape:new ee([new t(e.x*this.scaledTileWidth,e.y*-this.scaledTileHeight),new t(i.x*this.scaledTileWidth,i.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id});this.colliders.push(r)},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),Oe=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),Pe=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,r,s,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!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(s=e.physics)&&void 0!==s?s: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 ee([this.scaledVertexModel[l],this.scaledVertexModel[l+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(Re,{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),Re=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),Ae=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,r,s,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!==(r=e.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(s=e.flipVertical)&&void 0!==s&&s,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),Se=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,r,s,o,a,l,c,d,u,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!==(r=e.width)&&void 0!==r?r:100,this.height=null!==(s=e.height)&&void 0!==s?s: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=null!==(u=e.smooth)&&void 0!==u&&u,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,r=this.text.split("\n");n<r.length;n++)for(var s=0,o=null!==(t=r[n].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];s<o.length;s++){var a=o[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(j),Te=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,r,s;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!==(r=e.opacity)&&void 0!==r?r:this.opacity,this.layer=e.layer,this.renderData={type:R.Mask,layer:null!==(s=this.layer)&&void 0!==s?s: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),De=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,r=t.tileWidth,s=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=n,this.tileWidth=r,this.tileHeight=s,this.layer=o,this.smooth=null!=h&&h,this.width=this.tiledData.width,this.height=this.tiledData.height,this.orientation=a,this.processTilemap()},i.prototype.update=function(){var t=this;this.updateRenderData(),this.renderData.forEach((function(e){return t.renderManager.addRenderData(e)}))},i.prototype.processTilemap=function(){var t=this;this.tiledData.layers.forEach((function(e){!0===e.visible&&t.tilemapLayer===e.name&&(t.alpha=e.opacity,t.tintColor=e.tintcolor,!0===t.tiledData.infinite?e.chunks.forEach((function(e){return t.processChunk(e)})):t.processChunk(e))})),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processChunk=function(e){var i,n=this,r={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=r.tiles:r.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(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),Ee=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,r=e.tiles,s=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;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?n.tiles.push(Number(t)):null}))})),this.tileset=s,this.width=h,this.tileWidth=o,this.tileHeight=a,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.orientation=c,this.alpha=d,this.tintColor=u,this.renderData={type: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=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Be=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderManager=i.container.getSingleton("RenderManager"),i.innerPosition=new t,i.scaledOffset=new t,i._playing=!1,i._paused=!1,i.videoEventHandler=function(t){"ended"===t.type&&(i._playing=!1,i.video.removeEventListener("ended",i.videoEventHandler))},i.userInputEventHandler=function(){Fe.forEach((function(t){window.removeEventListener(t,i.userInputEventHandler)})),i.video&&i._playing&&i.video.play()},i}return c(i,e),Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.video&&(this.video.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.video&&(this.video.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),i.prototype.init=function(e){var i,n,r,s,o,a,l,c,d,u;this.video=e.video,this.width=null!==(i=e.width)&&void 0!==i?i:this.video.videoWidth,this.height=null!==(n=e.height)&&void 0!==n?n:this.video.videoHeight,this.offset=null!==(r=e.offset)&&void 0!==r?r:new t,this.rotation=null!==(s=e.rotation)&&void 0!==s?s:new h,this.flipHorizontal=null!==(o=e.flipHorizontal)&&void 0!==o&&o,this.flipVertical=null!==(a=e.flipVertical)&&void 0!==a&&a,this.opacity=null!==(l=e.opacity)&&void 0!==l?l:1,this.maskColor=e.maskColor,this.maskColorMix=null!==(c=e.maskColorMix)&&void 0!==c?c:0,this.tintColor=e.tintColor,this.layer=e.layer,this.slice=e.slice,this._volume=null!==(d=e.volume)&&void 0!==d?d:1,this._loop=null!==(u=e.loop)&&void 0!==u&&u,this.renderData={type:R.Video,location:P.WorldSpace,layer:"",position:new t,video:this.video,width:this.width,height:this.height}},i.prototype.play=function(){var t=this;if((this.video||!this.video.duration)&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.video.play();this.video.loop=this._loop,this.video.volume=this._volume,this.video.addEventListener("ended",this.videoEventHandler),this._playing=!0;var e=this.video.play();void 0!==e&&e.catch((function(){Fe.forEach((function(e){return window.addEventListener(e,t.userInputEventHandler)}))}))}},i.prototype.stop=function(){this._playing&&(this.video.pause(),this.video.currentTime=0,this.video.removeEventListener("ended",this.videoEventHandler),this._playing=!1,this._paused=!1)},i.prototype.pause=function(){this._playing&&!1===this._paused&&(this.video.pause(),this._paused=!0)},i.prototype.update=function(){var t;this.video&&this.video.duration&&(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.video=this.video,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.slice=this.slice,this.renderData.flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData.flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.maskColor=this.maskColor,this.renderData.maskColorMix=this.maskColorMix,this.renderData.tintColor=this.tintColor,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData))},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.prototype.onActiveChange=function(){!1===this.active&&this.stop()},i.prototype.onDestroy=function(){this.stop()},i}(j),Ie=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},Ue=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 Ge(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 void 0===t&&(t="default"),null!==this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e}(x),Ge=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}(),Le=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Ve=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.tracks=[],e.audioSourceCache=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e._audioSource.removeEventListener("ended",e.audioEventHandler))},e.userInputEventHandler=function(){Le.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return c(e,t),Object.defineProperty(e.prototype,"audioSource",{get:function(){return this._audioSource},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this._audioSource&&(this._audioSource.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this._audioSource&&(this._audioSource.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e=this,i=void 0===t?{}:t,n=i.loop,r=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&Le.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=r?r:1,this._loop=null!=n&&n},e.prototype.playClip=function(t,e){t.currentTime>0&&(t.currentTime=0),t.volume=null!=e?e:this._volume,t.play()},e.prototype.addAudioSource=function(t,e){void 0===e&&(e="default");var i=t.cloneNode();this.audioSourceCache.set(e,i);var n=this.audioContext.createMediaElementSource(i);n.connect(this.audioContext.destination),this.tracks.push(n)},e.prototype.loadAudioSource=function(t,e,i){this.stop(),this._audioSource=this.audioSourceCache.get(t),this._loop=null!=e?e:this._loop,this._volume=null!=i?i:this._volume},e.prototype.play=function(){if(this._audioSource&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this._audioSource.play();this._audioSource.volume=this._volume,this._audioSource.loop=this._loop,this._audioSource.addEventListener("ended",this.audioEventHandler),this._playing=!0,"running"===this.audioContext.state&&this._audioSource.play()}},e.prototype.stop=function(){this._playing&&(this._audioSource.pause(),this._audioSource.currentTime=0,this._audioSource.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this._audioSource.pause(),this._paused=!0)},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop(),this.audioContext.close()},e}(x),ke=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"}(re||(re={}));var We=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,r=t.touchEnabled,s=t.width,o=t.offset;this.type=e,this.width=null!=s?s:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this._offset=null!=o?o:this._offset},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*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y))},i.prototype.resolveMouseAndRectangle=function(){this.type===re.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===re.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===re.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===re.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}(v),He=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(){N.mouse.leftButtonPressed&&!1===this.mousePressed&&(t.round(this.position,t.add(this.position,this.camera.transform.position,t.scale(this.position,N.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=N.mouse.leftButtonPressed},i}(me);export{Ie as Animation,Ue as Animator,H as AssetManager,Ve as AudioPlayer,_e as BallCollider,we as BoxCollider,Lt as BroadPhaseMethods,We as Button,re as ButtonType,ye as Camera,kt as CollisionMethods,v as Component,z as DomManager,Pe as EdgeCollider,ce as Game,ve as GameCamera,me as GameObject,q as GameObjectManager,F as GamepadController,B as GamepadData,N as InputManager,U as KeyboardController,ge as LAYER_DEFAULT,Te as MaskRenderer,G as MouseController,M as PhysicsComponent,be as PolygonCollider,Me as PolygonColliderRenderer,_ as PreRenderComponent,e as Rectangle,pe as RigidBody,Wt as RigidBodyType,h as Rotation,xe as Scene,Y as SceneManager,He as SpacePointer,ke as Sprite,Ae as SpriteRenderer,Mt as TextOrientation,Se as TextRenderer,De as TiledTilemapRenderer,je as TilemapCollider,A as TilemapOrientation,Ee as TilemapRenderer,X as TimeManager,W as TouchController,de as Transform,t as Vector2,Be as VideoRenderer,a as between,i as clamp,s as fixedRound,r 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,s,r){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,s,r)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,s){this._position.set(t,e),this._width=i,this._height=s}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(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)),s=(t,e)=>Math.round(Math.random()*(e-t))+t,r=(t,e,i=2)=>n(Math.random()*(e-t)+t,i),n=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),o=(t,e,i=1)=>{const s=[];for(let r=t;r<=e;r+=i)s.push(r);return s},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,s=arguments.length;i<s;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},d.apply(this,arguments)};function u(t,e,i){if(i||2===arguments.length)for(var s,r=0,n=e.length;r<n;r++)!s&&r in e||(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;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 s=16*Math.random();return t>0?(s=(t+s)%16|0,t=Math.floor(t/16)):(s=(e+s)%16|0,e=Math.floor(e/16)),("x"==i?s:7&s|8).toString(16)}))};!function(t){t[t.Init=0]="Init",t[t.Start=1]="Start",t[t.Update=2]="Update",t[t.UpdateEngine=3]="UpdateEngine",t[t.UpdateCollider=4]="UpdateCollider",t[t.UpdatePhysics=5]="UpdatePhysics",t[t.UpdateTransform=6]="UpdateTransform",t[t.UpdatePreRender=7]="UpdatePreRender",t[t.UpdateCamera=8]="UpdateCamera",t[t.UpdateRender=9]="UpdateRender",t[t.Destroy=10]="Destroy",t[t.StopGame=11]="StopGame"}(p||(p={}));var m,f=function(){function t(t,e,i,s,r,n,o){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=s,this.gameObjectManager=r,this.sceneManager=n,this.canvasColor=o,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[]}return t.prototype.start=function(){this.startLoop(!0)},t.prototype.pause=function(){this.running=!1},t.prototype.resume=function(){this.startLoop(!1)},t.prototype.stop=function(){this.running=!1,this.sceneManager.stopGame(),this.physicsManager.clear(),this.renderManager.clearScreen(this.canvasColor)},t.prototype.startLoop=function(t){this.running||(this.running=!0,t&&this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.timeManager.gameFramerate!==this.timeManager.physicsFramerate&&this.asyncPhysicsLoop())},t.prototype.requestAnimationLoop=function(t){var e=this;this.running&&(this.timeManager.updateForBrowser(.001*t),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(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.gameConfig=this.container.getConstant("GameConfig"),this.gameConfig.headless||(this.assetManager=this.container.getSingleton("AssetManager"),this.domManager=this.container.getSingleton("DomManager"),this.inputManager=this.container.getSingleton("InputManager"),this.renderManager=this.container.getSingleton("RenderManager")),this.gameObjectManager=this.container.getSingleton("GameObjectManager"),this.physicsManager=this.container.getSingleton("PhysicsManager"),this.sceneManager=this.container.getSingleton("SceneManager"),this.timeManager=this.container.getSingleton("TimeManager")}return t.prototype.dispatch=function(t,e){t===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()):t===p.StopGame&&(this.onDestroy&&this.onDestroy(),this._stopGame()):(this.start&&this.start(),this.started=!0)},t.prototype.addGameObject=function(t,e,i){return"string"==typeof e&&(i=e,e={}),this.gameObjectManager.addGameObject(t,e,void 0,i)},t.prototype.findGameObjects=function(t){return t?this.gameObjectManager.findGameObjects(t):this.gameObjectManager.findGameObjects()},t.prototype.findGameObject=function(t){return this.gameObjectManager.findGameObject(t)},t.prototype.findGameObjectsByTag=function(t){return this.gameObjectManager.findGameObjectsByTag(t)},t.prototype.destroyGameObject=function(t){this.gameObjectManager.destroyGameObject(t)},t}(),v=function(t){function e(e,i,s){void 0===s&&(s="");var r=t.call(this,e)||this;return r.id=g(),r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=s,r}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())},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},e.prototype.getGameObject=function(){return this.gameObject},e.prototype.getComponents=function(t){return t?this.gameObject.getComponents(t):this.gameObject.getComponents()},e.prototype.getComponent=function(t){return this.gameObject.getComponent(t)},e.prototype.hasComponent=function(t){return this.gameObject.hasComponent(t)},e.prototype.removeComponent=function(t){this.gameObject.removeComponent(t)},e.prototype._destroy=function(){var t=this;Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){},e}(y),x=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateEngine,e}return c(e,t),e}(v),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}(v),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}(v),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}(v),_=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdatePreRender,e}return c(e,t),e}(v),C=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=p.UpdateCamera,e}return c(e,t),e}(v),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}(v);!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(m||(m={}));var P,O,R,A,S=function(){function t(t){this.renderManager=t,this.assets=[]}return t.prototype.getAssetsLoaded=function(){return this.assets.reduce((function(t,e){return t&&e.loaded}),!0)},t.prototype.loadImage=function(t,e){var i=this;void 0===e&&(e=!1);var s=new Image;s.crossOrigin="",s.src=t;var r=this.createAsset(t,m.Image,s),n=function(){e&&i.renderManager.preloadTexture(s),r.loaded=!0};return s.naturalWidth?n():s.addEventListener("load",n),s},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,")")),s=this.createAsset(e,m.Font,i);return s.family=t,i.load().then((function(t){document.fonts.add(t),s.loaded=!0})),i},t.prototype.loadVideo=function(t){var e=document.createElement("video");e.playsInline=!0,e.src=t;var i=this.createAsset(t,m.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(function(){return i.loaded=!0})),e},t.prototype.getImage=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===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.getVideo=function(t){var e;return null===(e=this.assets.find((function(e){return e.type===m.Video&&e.url===t})))||void 0===e?void 0:e.element},t.prototype.createAsset=function(t,e,i){var s={type:e,url:t,element:i,loaded:!1};return this.assets.push(s),s},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,s){var r=new t(this.container,s,i);return this.gameObjects.push(r),r.dispatch(p.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):u([],this.gameObjects,!0)},t.prototype.findGameObjectById=function(t){return this.gameObjects.find((function(e){return e.id===t}))},t.prototype.findGameObject=function(t){return"string"==typeof t?this.gameObjects.find((function(e){return e.name===t})):this.gameObjects.find((function(e){return e instanceof t}))},t.prototype.findGameObjectsByParent=function(t){return this.gameObjects.filter((function(e){return e.parent===t}))},t.prototype.findGameObjectByParent=function(t,e){return"string"==typeof e?this.gameObjects.find((function(i){return i.name===e&&i.parent===t})):this.gameObjects.find((function(i){return i instanceof e&&i.parent===t}))},t.prototype.findGameObjectsByTag=function(t){return this.gameObjects.filter((function(e){return e.tag===t}))},t.prototype.destroyAllGameObjects=function(t){var e=this;void 0===t&&(t=!1),this.gameObjects.filter((function(e){return t||!e.keep})).forEach((function(t){return e.destroy(t,!1)}))},t.prototype.destroyGameObject=function(t){this.destroy(t,!0)},t.prototype.destroy=function(t,e){var i=this.gameObjects.indexOf(t);if(-1!==i){var s=this.gameObjects.splice(i,1)[0];e&&this.destroyChildren(s),s.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,this._vibrating=!1}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}),Object.defineProperty(e.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),e.prototype.vibrate=function(t,e,i,s){var r=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===s&&(s=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:s}).catch((function(){return r._vibrating=!1})).finally((function(){return r._vibrating=!1})))},e}(),U=function(){function t(t,e,i,s){this.mouse=t,this.keyboard=e,this.gamepad=i,this.touch=s}return t.prototype.update=function(){this.mouse.update(),this.gamepad.update()},t}(),I=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var s;return t||null!==(s=e.keyMap.get(i))&&void 0!==s&&s}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var s;return t&&null!==(s=e.keyMap.get(i))&&void 0!==s&&s}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var s=this;return t.reduce((function(t,e){var i;return t||null!==(i=s.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var s=this;return t.reduce((function(t,e){var i;return t&&null!==(i=s.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),L=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}(),V=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,s){var r=this;if(void 0===s&&(s=!1),this.scenes.has(e))throw new T("There is already a scene with the name '".concat(e,"'"));this.scenes.set(e,(function(){var s=new t(r.container,e,r.container.getConstant("Game"));return r.currentScene=s,s.dispatch(p.Init,i),s})),!0!==s&&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.prototype.stopGame=function(){null!==this.currentScene&&(this.currentScene.dispatch(p.StopGame),this.currentScene=null,this.currentSceneName=null,this.renderManager&&this.renderManager.clearData())},t}(),k=[60,120,180,240],G=function(){function t(t){if(this.minGameDeltatime=0,this.minPhysicsDeltaTime=0,this.gameFramerate=60,this.physicsFramerate=180,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForBrowser=0,!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 Object.defineProperty(t.prototype,"deltaTime",{get:function(){return this.unscaledDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"physicsDeltaTime",{get:function(){return this.unscaledPhysicsDeltaTime*this.timeScale},enumerable:!1,configurable:!0}),t.prototype.updateForGame=function(t){this.unscaledDeltaTime=Math.min(Math.max(this.minGameDeltatime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t},t.prototype.updateForBrowser=function(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForBrowser),this.maxDeltaTime),this.thenForBrowser=t},t.prototype.updateForPhysics=function(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t},t}(),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(t,e,i,s){this.timeManager=t,this.physicsManager=e,this.gameObjectManager=i,this.sceneManager=s,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"}(P||(P={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(O||(O={})),function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric",t[t.Video=5]="Video"}(R||(R={}));class z{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===O.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:s=0}){const r=Math.abs(Math.sin(s)),n=Math.abs(Math.cos(s)),o=r*i+n*e,a=r*e+n*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:s,letterSpacing:r,rotation:n}){const o=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=r?r:0))*2,a=e.split("\n").length*(i+(null!=s?s:0));this.setObjectForResizeable({position:t,width:o,height:a,rotation:n})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:s}){i===P.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForTilemap(t){t.tilemap.height=Math.ceil(t.tiles.length/t.tilemap.width),this.setObjectForResizeable({position:t.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:s,tileHeight:r}}=t;t.culledTiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*s&&this.viewport.x<=this.object.x+e%i*s+s&&this.viewport.y1>=this.object.y1-((e/i|0)*r+r)&&this.viewport.y<=this.object.y1-(e/i|0)*r?t:0))}isInViewPort(t,e){switch(this.setViewport(e,t.location),t.type){case R.Video: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 Y{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 Y(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 N{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 Y});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)}preloadTexture(t){this.webglManager.createTexture(t)}}var X;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(X||(X={}));class q{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(X.WebGL2)?X.WebGL2:null!==this.canvas.getContext(X.LegacyWebGL)?X.LegacyWebGL:void 0}}class K{constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(this.symbol(t))}getFontAtlas(t){return this.fontAtlas.get(this.symbol(t))}getOrCreate(t,e,i){var s;return null!==(s=this.getFontAtlas(e))&&void 0!==s?s:this.create(t,e,i)}create(t,e,i){this.bitmapSize=i,this.chars=[];for(let e=0;e<t.length;e+=2)for(let i=t[e];i<=t[e+1];i++)this.chars.push(String.fromCharCode(i));const s=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),s),s}symbol(t){return Symbol.for(t instanceof FontFace?t.family:t)}renderAtlas(t){const e=new $(t,this.bitmapSize,Math.ceil(Math.sqrt(this.chars.length))),i=e.canvas.getContext("2d");i.clearRect(0,0,e.canvas.width,e.canvas.height),i.textBaseline="top",i.fillStyle="#000",i.font=`${this.bitmapSize}px ${t}`;let s=0,r=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],s,r),e.glyphs.set(this.chars[t],{id:t,width:i.measureText(this.chars[t]).width}),(s+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(s=0,r+=this.bitmapSize);return e}}class ${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 Q{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),s=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),r=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,s),this.gl.attachShader(i,r),this.gl.linkProgram(i);const n=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,n)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class J{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===X.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 Z{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const s=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,s)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var tt="undefined"!=typeof Float32Array?Float32Array:Array;function et(){var t=new tt(16);return tt!=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 it(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function st(t,e,i){var s,r,n,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]):(s=e[0],r=e[1],n=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]=s,t[1]=r,t[2]=n,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]=s*m+a*f+d*y+e[12],t[13]=r*m+h*f+u*y+e[13],t[14]=n*m+l*f+p*y+e[14],t[15]=o*m+c*f+g*y+e[15]),t}function rt(t,e,i){var s=i[0],r=i[1],n=i[2];return t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=e[11]*n,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function nt(t,e,i){var s=Math.sin(i),r=Math.cos(i),n=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]=n*r+l*s,t[1]=o*r+c*s,t[2]=a*r+d*s,t[3]=h*r+u*s,t[4]=l*r-n*s,t[5]=c*r-o*s,t[6]=d*r-a*s,t[7]=u*r-h*s,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ot;function at(){var t=new tt(3);return tt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ht(t,e,i){var s=new tt(3);return s[0]=t,s[1]=e,s[2]=i,s}function lt(){var t=new tt(4);return tt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}at(),function(){var t;t=new tt(4),tt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0)}(),at(),ht(1,0,0),ht(0,1,0),lt(),lt(),ot=new tt(9),tt!=Float32Array&&(ot[1]=0,ot[2]=0,ot[3]=0,ot[5]=0,ot[6]=0,ot[7]=0),ot[0]=1,ot[4]=1,ot[8]=1,function(){var t=new tt(2);tt!=Float32Array&&(t[0]=0,t[1]=0)}();const ct=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},dt=(t,e,i,s)=>{var r,n;(function(t,e,i,s,r,n,o){var a=1/(e-i),h=1/(s-r),l=1/(n-o);t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(r+s)*h,t[14]=(o+n)*l,t[15]=1})(t=it(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),st(t,t,[0,0,0]),s===O.WorldSpace&&rt(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(n=i.zoom)&&void 0!==n?n:1,1])};class ut{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(((t,e,i=1)=>{const s=[];for(let t=1;t<=e;t+=i)s.push(t);return s})(0,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e,i){switch(t.shape){case P.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case P.Line:this.renderLines(t,e,this.gl.LINES,i);break;case P.Circumference:this.renderCircumference(t,e)}}renderLines(t,e,i,s){var r;const n=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(n)&&this.vertices.set(n,new Float32Array(this.generatePolygonVertices(t.vertexModel)));const o=this.vertices.get(n);this.lastVertices===n&&s===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=n,this.modelMatrix=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),dt(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}=ct(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=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),rt(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),dt(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:s,b:r,a:n}=ct(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,s,r,n),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}class pt{constructor(t,e){this.gl=t,this.programManager=e,this.type=R.Mask,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et()}render(t,e,i){var s,r;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=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),dt(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:n,g:o,b:a,a:h}=ct(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,n,o,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class gt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}render(t,e,i){var s,r,n,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=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=it(this.textureMatrix),t.slice&&(st(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),rt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),dt(this.projectionMatrix,this.gl,e,t.location),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:r}=ct(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=ct(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(n=t.alpha)&&void 0!==n?n: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 ft=new Y,yt=new Y,vt=[32,126,161,255],xt=mt.Center;class bt{constructor(t,e,i,s){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=s,this.type=R.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new Y,this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et()}render(t,e,i){var s;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);const r=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(r,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=it(this.modelMatrix),this.setPositionFromOrientation(t),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,this.modelPosition,e.position):this.modelPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=it(this.textureMatrix),dt(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 n=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===n&&i===R.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),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}=ct(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,s,r,n,o,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:ft,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:yt,t.bitmap.fontSize=null!==(s=t.bitmap.fontSize)&&void 0!==s?s:64,t.bitmap.charRanges=null!==(r=t.bitmap.charRanges)&&void 0!==r?r:vt):t.bitmap={margin:ft,spacing:yt,fontSize:64,charRanges:vt},t.color=null!==(n=t.color)&&void 0!==n?n:"#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:xt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0}generateTextVertices(t,{text:e,fontSize:i,bitmap:s,letterSpacing:r,lineSeparation:n}){this.posVertices=[],this.texVertices=[];let o=0,a=0,h=0;r/=i,n/=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+n;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,n=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+s.margin.x)/t.canvas.width,l=(n+s.margin.y)/t.canvas.width,d=(i+c.width+s.spacing.x)/t.canvas.width,u=(n+t.bitmapFontSize+s.spacing.y)/t.canvas.width;this.texVertices.push(h,u,d,u,h,l,h,l,d,u,d,l),o+=e+r}}this.textSize.set(Math.max(h,o)*i,Math.abs(a-1)*i)}setPositionFromOrientation(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 Mt{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 Y,texSpacing:new Y,texWidth:0,texHeight:0,texCorrection:new Y},this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et()}render(t,e,i){var s,r,n,o;if(0===t.culledTiles.reduce(((t,e)=>t+e),0))throw new Error("Nothing to render");if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)throw new Error("Nothing to render");this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.modelMatrix=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.renderPosition,e.position):t.renderPosition),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=it(this.textureMatrix),rt(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),dt(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!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:r}=ct(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=ct(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(n=t.alpha)&&void 0!==n?n: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,s,r,n,o,a;t.margin=null!==(e=t.margin)&&void 0!==e?e:new Y,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new Y,t.correction=null!==(s=t.correction)&&void 0!==s?s:new Y,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(r=t.margin.x)&&void 0!==r?r:0)+(null!==(n=t.spacing.x)&&void 0!==n?n: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,s)=>{if(0===t)return;const r=s%e.width-e.width/2,n=i/2-Math.floor(s/e.width);this.posVertices.push(r,n-1,r+1,n-1,r,n,r,n,r+1,n-1,r+1,n);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 wt{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.modelPosition=new Y,this.projectionMatrix=et(),this.modelMatrix=et(),this.textureMatrix=et(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}render(t,e,i){var s,r,n,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=it(this.modelMatrix),Y.round(this.modelPosition,t.location===O.WorldSpace?Y.subtract(this.modelPosition,t.position,e.position):t.position),st(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),nt(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=it(this.textureMatrix),t.slice&&(st(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),rt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),dt(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.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:r}=ct(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,r)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=ct(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(n=t.alpha)&&void 0!==n?n:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(o=t.maskColorMix)&&void 0!==o?o:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)}}class _t{constructor(t){this.gl=t}createFromImage(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(()=>this.createFromSource(t,i,e))),i}createFromCanvas(t,e=!0,i=null){return i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i}createPixelTexture(){const t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t}createFromSource(t,e,i=!0){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}}class Ct{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!0){var i;return null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!0){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i}getOrCreateTextureFromCanvas(t,e,i=!0){var s;return null!==(s=this.textures.get(Symbol.for(t)))&&void 0!==s?s:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!0){const s=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),s),s}getOrCreateTextureFromVideo(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)}createTextureFromVideo(t){const e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e}}class jt{constructor(t,e,i,s){this.gl=t,this.textureManager=i,this.renderers=s,e.loadProgram()}render(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}}clearCanvas(t){const e=ct(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}createTexture(t,e=!1){this.textureManager.createTextureFromImage(t,e)}}class Pt{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 Pt(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 Ot{constructor(t,e,i,s){this._position=new Pt,this._center=new Pt,this._width=0,this._height=0,this.set(t,e,i,s)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this._width}get y1(){return this._position.y+this._height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get 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,s){this._position.set(t,e),this._width=i,this._height=s}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}overlaps(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1}contains(t){return t instanceof Ot?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof Pt&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const Rt=(t,e,i)=>Math.min(i,Math.max(e,t));class At{constructor(){this.lastId=0}create({shape:t,layer:e,updateCollisions:i,physics:s,position:r,rotation:n,group:o,onCollision:a}){return{id:++this.lastId,active:!0,layer:e,shape:t,updateCollisions:i,physics:s,position:null!=r?r:new Pt,rotation:null!=n?n:0,group:o,onCollision:a}}}class St{constructor(t,e=0){this.area=new Ot(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 Ot(this.area.x,this.area.y,t,e),new Ot(this.area.x,this.area.y+e,t,e),new Ot(this.area.x+t,this.area.y+e,t,e),new Ot(this.area.x+t,this.area.y,t,e)].map((t=>new St(t,this.depth+1))),this.items.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.items=[]}insertItemIntoChildren(t,e){this.getChildrenForArea(e).forEach((i=>i.insert(t,e)))}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((i=>e.push(...i.retrieve(t)))):this.items.forEach((t=>e.push(t[0]))),e}getChildrenForArea(t){const e=[];return t.x<=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[0]),t.x<=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[1]),t.x1>=this.area.center.x&&t.y1>=this.area.center.y&&e.push(this.children[2]),t.x1>=this.area.center.x&&t.y<=this.area.center.y&&e.push(this.children[3]),e}}const Tt=(t,e,i,s)=>Math.min((t-e)/i|0,s-1);class Dt{constructor(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}get subdivisions(){return this._subdivisions}set subdivisions(t){this._subdivisions=Rt(t,1,20)}resize(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(let t=0;t<this._subdivisions;t++){this.itemsInCells[t]=[];for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}}clear(){for(let t=0;t<this._subdivisions;t++)for(let e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[e][i].push(t)}retrieve(t){const e=[];this.updateCoordinates(t);for(let t=this.coordinates.x0;t<=this.coordinates.x1;t++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++)this.itemsInCells[t][i].forEach((t=>e.includes(t)?null:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=Tt(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=Tt(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=Tt(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=Tt(t.y1,this.area.y,this.cellHeight,this._subdivisions)}}var Et,Ft,Bt,Ut;!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(Et||(Et={}));class It{constructor(t,e,i,s){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new Pt,this.maxArea=new Pt,this.newArea=new Ot(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=s,this.setupBroadPhaseResolver(null!=e?e:Et.QuadTree,i)}setupBroadPhaseResolver(t,e){this.collisionArea=null!=e?e:new Ot(0,0,0,0),this.fixedCollisionArea=!!e,t===Et.SpartialGrid?this.broadPhaseResolver=new Dt(this.collisionArea):this.broadPhaseResolver=new St(this.collisionArea)}addCollider(t){this.colliders[t.id]=t}getCollider(t){return this.colliders[t]}removeCollider(t){delete this.colliders[t.id]}clearColliders(){this.colliders=[]}getCollisionsForCollider(t){return t.active?this.collisions.filter((e=>e.localCollider.id===t.id)):[]}refreshCollisionsForCollider(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((e=>e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id)),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))}resolve(){this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((t=>t.active)),this.broadPhaseResolver.clear(),this.activeColliders.forEach((t=>{this.updateShape(t)})),!1===this.fixedCollisionArea&&(this.updateNewArea(),!1===this.newArea.equals(this.collisionArea)&&(this.collisionArea.copy(this.newArea),this.broadPhaseResolver.resize(this.collisionArea))),this.checkForSpartialGridResize(),this.activeColliders.forEach((({id:t,shape:{boundingBox:e}})=>this.broadPhaseResolver.insert(t,e))),this.updateCollisions())}updateShape(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()}updateNewArea(){this.activeColliders.forEach((({shape:{boundingBox:t}})=>{this.minArea.set(Math.min(t.x,this.minArea.x),Math.min(t.y,this.minArea.y)),this.maxArea.set(Math.max(t.x1,this.maxArea.x),Math.max(t.y1,this.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}checkForSpartialGridResize(){this.broadPhaseResolver instanceof Dt&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)}updateCollisions(){this.activeColliders.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase(t){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t])).filter((e=>this.collisionMatrix.some((i=>i[0]===t.layer&&i[1]===e.layer||i[1]===t.layer&&i[0]===e.layer)))):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((t=>this.colliders[t]))}narrowPhase(t,e){e.filter((e=>!(t.group&&e.group&&e.group===t.group||t.id===e.id))).forEach((e=>{if(this.isResolved(t,e))return;const i=this.method.getCollisionResolution(t.shape,e.shape);null!==i&&(this.collisions.push({localCollider:t,remoteCollider:e,resolution:i},{localCollider:e,remoteCollider:t,resolution:{direction:i.displacementDirection,displacementDirection:i.direction,penetration:i.penetration}}),t.onCollision&&t.onCollision(i))}))}isResolved(t,e){for(const i of this.collisions)if(i.localCollider.id===t.id&&i.remoteCollider.id===e.id)return!0;return!1}}!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(Ft||(Ft={}));class Lt{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}getCollisionResolution(t,e){return t.type===Ft.Polygon&&e.type===Ft.Polygon?this.AABBResolver.resolve(t,e):t.type===Ft.Circumference&&e.type===Ft.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===Ft.Polygon&&e.type===Ft.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):null}}!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(Bt||(Bt={}));class Vt{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}getCollisionResolution(t,e){return t.type===Ft.Circumference&&e.type===Ft.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}}class kt{constructor(){this.direction=new Pt,this.displacementDirection=new Pt}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)),Pt.unit(this.displacementDirection,this.displacementDirection),{direction:Pt.scale(new Pt,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),s=Math.abs(t.y1-e.y1);this.overlapY+=i<s?i:s}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),s=Math.abs(t.x1-e.x1);this.overlapX+=i<s?i:s}}}class Gt{constructor(){this.closestPoint=new Pt,this.distance=new Pt,this.direction=new Pt}resolve(t,e,i=!1){return this.closestPoint.set(Rt(t.position.x,e.boundingBox.x,e.boundingBox.x1),Rt(t.position.y,e.boundingBox.y,e.boundingBox.y1)),Pt.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(Pt.unit(this.direction,this.distance),{direction:i?Pt.scale(new Pt,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():Pt.scale(new Pt,this.direction,-1),penetration:t.radius-this.distance.magnitude})}}class Wt{constructor(){this.distance=new Pt,this.direction=new Pt}resolve(t,e){return Pt.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(Pt.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:Pt.scale(new Pt,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})}}class Ht{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new Pt,this.distance=new Pt(1/0,1/0),this.cache=new Pt}resolve(t,e){this.minOverlap=1/0,t.type===Ft.Circumference?this.setCircumferenceAxis(t,e):e.type===Ft.Circumference&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?null:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t.type===Ft.Circumference?this.setCircumferenceVertices(t,this.axes[i]):e.type===Ft.Circumference&&this.setCircumferenceVertices(e,this.axes[i]),this.projectShapeOntoAxis(this.projA,t,this.axes[i]),this.projectShapeOntoAxis(this.projB,e,this.axes[i]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;if(this.invertAxis=!0,this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min){const t=Math.abs(this.projA.min-this.projB.min),e=Math.abs(this.projA.max-this.projB.max);t<e?this.currentOverlap+=t:(this.currentOverlap+=e,Pt.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&&Pt.scale(this.smallestAxis,this.axes[i],-1))}return{direction:Pt.scale(new Pt,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(Pt.dot(i,e),t.min),t.max=Math.max(Pt.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{Pt.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),Pt.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){Pt.add(t.vertices[0],t.position,Pt.scale(this.cache,Pt.unit(this.cache,e),-t.radius)),Pt.add(t.vertices[1],t.position,Pt.scale(this.cache,Pt.unit(this.cache,e),t.radius))}}class zt{constructor(t,e,i,s){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=s}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 Yt{constructor(){this.lastId=0}create({colliderIds:t,type:e,gravity:i,position:s,velocity:r,onResolve:n}){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!=s?s:new Pt,velocity:null!=r?r:new Pt,onResolve:n}}}!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(Ut||(Ut={}));const Nt=["x","y"];class Xt{constructor(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new Pt,this.displacement=new Pt,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===Ut.Dynamic?this.dynamicUpdate(e,t):e.type===Ut.Kinematic&&this.kinematicUpdate(e,t),e.onResolve&&e.onResolve(e)}))}dynamicUpdate(t,e){this.applyGravity(t,e),Nt.forEach((i=>{this.applyVelocity(t,e,i),this.obtainDisplacement(t,i),this.applyReposition(t,i)}))}kinematicUpdate(t,e){Pt.add(t.position,t.position,Pt.scale(this.velocity,t.velocity,e)),t.colliderIds.map((t=>this.collisionManager.getCollider(t))).forEach((t=>{Pt.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 qt{constructor(t){this.radius=t,this.type=Ft.Circumference,this.boundingBox=new Ot(0,0,0,0),this.vertices=[new Pt,new Pt],this.projectionAxes=[new Pt],this._position=new Pt}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 Kt{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[new Pt,new Pt],this.projectionAxes=[new Pt],this.boundingBox=new Ot(0,0,0,0),this.rotation=0,this._position=new Pt}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(){Pt.normal(this.projectionAxes[0],Pt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))}}class $t{constructor(t){this.vertexModel=t,this.type=Ft.Polygon,this.vertices=[],this.boundingBox=new Ot(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new Pt,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 Pt),this._projectionAxes.push(new Pt)}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++)Pt.normal(this._projectionAxes[e],Pt.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))}}class Qt extends $t{constructor(t,e){super([new Pt(-t/2,-e/2),new Pt(-t/2,e/2),new Pt(t/2,e/2),new Pt(t/2,-e/2)]),this.width=t,this.height=e,this._projectionAxes=[new Pt,new Pt]}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(){Pt.unit(this.projectionAxes[0],Pt.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),Pt.normal(this.projectionAxes[1],this.projectionAxes[0])}}var Jt,Zt=function(t,e){t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new G(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new E(t)})),t.add("PhysicsManager",(function(){return(({collisionArea:t,collisionMatrix:e,collisionMethod:i,collisionBroadPhaseMethod:s}={})=>{const r=new Wt,n=i===Bt.AABB?new Lt(new kt,new Gt,r):new Vt(r,new Ht),o=new It(n,s,t,e),a=new At,h=new Xt(o),l=new Yt;return new zt(o,a,h,l)})(e.collisions)})),e.headless?t.add("IterationManager",(function(){return new H(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 q(t),i=e.gl,s=e.contextVersion,r=new J(i,s,new Q(i,new Z(i))),n=new Ct(new _t(i)),o=new jt(i,r,n,new Map([[R.Sprite,new gt(i,r,n)],[R.Text,new bt(i,r,n,new K)],[R.Tilemap,new Mt(i,r,n)],[R.Geometric,new ut(i,r)],[R.Mask,new pt(i,r)],[R.Video,new wt(i,r,n)]]));return new N(o,new z(i))})(t.getSingleton("DomManager").canvas)})),te(t),t.add("AssetManager",(function(){return new S(t.getSingleton("RenderManager"))})),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 V(t,e.headless?void 0:t.getSingleton("RenderManager"))}))},te=function(t){var e=t.getSingleton("DomManager");t.add("InputManager",(function(){return new U(new L(e.canvas),new I(e.canvas),new F,new W(e.canvas))}))},ee=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}(),ie={containerNode:null,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new t(1,1),collisions:{collisionMethod:Bt.SAT,collisionBroadPhaseMethod:Et.SpartialGrid}},se=function(){function t(t){this._config=d(d({},ie),t),this._config.collisions=d(d({},ie.collisions),t.collisions),this.container=new ee,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){Zt(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,s){void 0===s&&(s=!1),this.sceneManager.addScene(t,e,i,s)},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}(),re=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),ne=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.renderer=null,e.colliders=[],e.physics=!0,e.activateColliders=!1,e}return 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 s=i[e],r=0,n=this.physicsManager.getCollisionsForCollider(s);r<n.length;r++){var o=n[r];if(o.remoteCollider.layer===t)return this.createCollisionData(o)}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=[],i=0,s=this.colliders;i<s.length;i++)for(var r=s[i],n=0,o=this.physicsManager.getCollisionsForCollider(r);n<o.length;n++){var a=o[n];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),oe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMultiple=!1,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,s=e.rigidBodyType,r=e.gravity;if(0===this.getColliderIds().length)throw new T("RigidBody needs at least one Collider with physics");this.rigidBody=this.physicsManager.addRigidBody({type:s,colliderIds:this.getColliderIds(),gravity:null!==(i=Math.abs(r))&&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 ne&&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}(x),ae="Default",he=function(t){function e(e,i,s){void 0===i&&(i="");var r=t.call(this,e)||this;return r.id=g(),r.layer="Default",r.ui=!1,r.keep=!1,r._parent=null,r._active=!0,r.components=[],r.activeComponentsCache=[],r.activeChildrenCache=[],r.name=i,r.addComponent(re),r.parent=null!=s?s:null,r}return c(e,t),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.updateComponentsActiveStatus(),this.updateChildrenActiveStatus(),this.onActiveChange())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},set:function(t){this._parent=t,this.transform.parent=null!==t?t.transform:null},enumerable:!1,configurable:!0}),e.prototype.updateComponentsActiveStatus=function(){var t=this;!1===this.active&&(this.activeComponentsCache=this.components.filter((function(t){return t.active}))),this.activeComponentsCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeComponentsCache=[])},e.prototype.updateChildrenActiveStatus=function(){var t=this;!1===this.active&&(this.activeChildrenCache=this.getChildren().filter((function(t){return t.active}))),this.activeChildrenCache.forEach((function(e){return e.active=t.active})),!0===this.active&&(this.activeChildrenCache=[])},Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(re)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rigidBody",{get:function(){return this.getComponent(oe)},enumerable:!1,configurable:!0}),e.prototype.onActiveChange=function(){},e.prototype.getCurrentScene=function(){return this.sceneManager.getCurrentScene()},e.prototype.addComponent=function(t,e,i){var s="string"==typeof e?void 0:e,r="string"==typeof e?e:i,n=new t(this.container,this,r);return this.checkMultipleComponent(n,t),this.components.push(n),n.dispatch(p.Init,s),n},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 s=this.gameObjectManager.addGameObject(t,e,this,i);return s.transform.innerPosition.set(0,0),s.transform.position.copy(this.transform.position),s},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.prototype._stopGame=function(){},e}(y),le=["Default"],ce=function(i){function s(){var t=null!==i&&i.apply(this,arguments)||this;return t.allowMultiple=!1,t.viewportRect=new e(0,0,0,0),t.worldSpaceRect=new e(0,0,0,0),t.depth=0,t.layers=le,t._zoom=1,t}return c(s,i),Object.defineProperty(s.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}),s.prototype.addLayer=function(t){this.layers.push(t)},s.prototype.init=function(){this.canvas=this.domManager.canvas,this.cameraData={position:new t,layers:[],depth:1}},s.prototype.update=function(){this.updateViewportRect(),this.updateWorldSpaceRect(),this.updateCameraData()},s.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},s.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},s.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)},s}(C),de=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(ce)},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}(he),ue=function(t){function e(e,i,s){var r=t.call(this,e)||this;return r.name=i,r.game=s,r.game.config.headless||r.addGameObject(de),r}return c(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(de)},enumerable:!1,configurable:!0}),e.prototype._destroy=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!1),Object.keys(this).forEach((function(e){return delete t[e]}))},e.prototype._stopGame=function(){var t=this;this.gameObjectManager.destroyAllGameObjects(!0),Object.keys(this).forEach((function(e){return delete t[e]}))},e}(y),pe=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,s,r,n,o,a;if(this.gameConfig.collisions.collisionMethod!==Bt.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.gameConfig.debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(s=e.offsetX)&&void 0!==s?s:this.offsetX,this.offsetY=null!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(n=e.physics)&&void 0!==n?n: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 $t(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ge,{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}(ne),ge=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:O.WorldSpace,layer:this.gameObject.layer,position:new t,shape:P.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.gameConfig.collisions.collisionMethod===Bt.SAT,i.innerPosition=new t,i}return c(i,e),i.prototype.init=function(t){var e,i,s,r,n,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!==(s=t.physics)&&void 0!==s?s:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.gameConfig.debugEnabled,this.rotation=null!==(n=t.rotation)&&void 0!==n?n: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 Qt(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ge,{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}(ne),fe=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,s,r,n;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!==(s=t.physics)&&void 0!==s?s:this.physics,this.debug=(null!==(r=t.debug)&&void 0!==r?r:this.debug)&&this.gameConfig.debugEnabled,this.layer=t.layer,this.colliders.push(this.physicsManager.addCollider({layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,position:this.gameObject.transform.position.clone(),shape:new qt(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id})),this.debug&&(this.renderer=this.gameObject.addComponent(ye,{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}(ne),ye=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return c(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:R.Geometric,location:O.WorldSpace,layer:this.gameObject.layer,position:new t,shape:P.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),ve=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.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(xe,{colliders:this.colliders}))},i.prototype.useBoxColliders=function(){var e=this;this.tilemapRenderer.tiles.forEach((function(i,s){var r;e.needsCollider(i,s)&&e.colliders.push(e.physicsManager.addCollider({layer:null!==(r=e.layer)&&void 0!==r?r:e.gameObject.layer,position:new t(e.position.x+(s%e.tilemapRenderer.width+.5)*e.scaledTileWidth,e.position.y-(Math.floor(s/e.tilemapRenderer.width)+.5)*e.scaledTileHeight),shape:new Qt(e.scaledTileWidth,e.scaledTileHeight),updateCollisions:!1,physics:e.physics,group:e.gameObject.id}))}))},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.useLineColliders=function(){var e,i,s=this,r=[],n=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%s.tilemapRenderer.width,o=Math.floor(e/s.tilemapRenderer.width);r[o]||(r[o]=[]),r[o+1]||(r[o+1]=[]),n[o]||(n[o]=[]),n[o+1]||(n[o+1]=[]);var a=s.getNeighbors(e);s.hasTile(a[0])||(r[o][i]=!0),s.hasTile(a[2])||(r[o+1][i]=!0),s.hasTile(a[1])||(n[o][i]=!0),s.hasTile(a[3])||(n[o][i+1]=!0)}}));for(var o=0;o<r.length;o++)if(r[o])for(var a=0;a<r[o].length;a++)!e||!i||o===i.y&&r[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),r[o][a]&&(e||(e=new t(a,o)),i=new t(a+1,o));e&&i&&this.addLineCollider(e,i),e=void 0,i=void 0;for(a=0;a<=this.tilemapRenderer.width;a++)for(o=0;o<n.length;o++)n[o]&&(!e||!i||a===i.x&&n[o][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),n[o][a]&&(e||(e=new t(a,o)),i=new t(a,o+1)));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(e,i){var s,r=this.physicsManager.addCollider({layer:null!==(s=this.layer)&&void 0!==s?s:this.gameObject.layer,position:this.position.clone(),shape:new Kt([new t(e.x*this.scaledTileWidth,e.y*-this.scaledTileHeight),new t(i.x*this.scaledTileWidth,i.y*-this.scaledTileHeight)]),updateCollisions:!1,physics:this.physics,group:this.gameObject.id});this.colliders.push(r)},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}(ne),xe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,s=e.colliders;this.colliders=s,this.colliders.forEach((function(e,s){i.renderData[s]={type:R.Geometric,layer:i.gameObject.layer,location:O.WorldSpace,position:new t,shape:P.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),be=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,s,r,n,o,a;if(this.gameConfig.collisions.collisionMethod!==Bt.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.gameConfig.debugEnabled,this.vertexModel=e.vertexModel,this.offsetX=null!==(s=e.offsetX)&&void 0!==s?s:this.offsetX,this.offsetY=null!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(n=e.physics)&&void 0!==n?n: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 Kt([this.scaledVertexModel[l],this.scaledVertexModel[l+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id}));this.debug&&(this.renderer=this.gameObject.addComponent(Me,{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}(ne),Me=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderData=[],t.colliders=[],t}return c(i,e),i.prototype.init=function(e){var i=this,s=e.colliders;this.colliders=s,this.colliders.forEach((function(e,s){i.renderData[s]={type:R.Geometric,layer:i.gameObject.layer,location:O.WorldSpace,position:new t,shape:P.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),we=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.spriteDefaultScale=i.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,s,r,n,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!==(s=e.rotation)&&void 0!==s?s:new h,this.flipHorizontal=null!==(r=e.flipHorizontal)&&void 0!==r&&r,this.flipVertical=null!==(n=e.flipVertical)&&void 0!==n&&n,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 s=0;s<this._tiled.y;s++)this.updateRenderData(e,i,s),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:O.WorldSpace,layer:"",position:new t,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var s;this.renderData[t].location=this.gameObject.ui?O.ViewPort:O.WorldSpace,this.renderData[t].layer=null!==(s=this.layer)&&void 0!==s?s: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,s){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,s*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),_e=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.lastFrameText="",t}return c(i,e),i.prototype.init=function(e){var i,s,r,n,o,a,l,c,d,u,p,g;if(this.text=e.text,this.font=null!==(i=e.font)&&void 0!==i?i:"Sans",this.fontSize=null!==(s=e.fontSize)&&void 0!==s?s:12,this.width=null!==(r=e.width)&&void 0!==r?r:100,this.height=null!==(n=e.height)&&void 0!==n?n: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=null!==(u=e.smooth)&&void 0!==u&&u,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:O.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?O.ViewPort:O.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,s=0,r=this.text.split("\n");s<r.length;s++)for(var n=0,o=null!==(t=r[s].match(new RegExp(".{1,"+Math.floor(this.width/(this.fontSize+this.letterSpacing))+"}","g")))&&void 0!==t?t:[""];n<o.length;n++){var a=o[n];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(a)}return e.join("\n")},i}(j),Ce=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return 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,s,r,n;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!==(s=e.rotation)&&void 0!==s?s:this.rotation,this.opacity=null!==(r=e.opacity)&&void 0!==r?r:this.opacity,this.layer=e.layer,this.renderData={type:R.Mask,layer:null!==(n=this.layer)&&void 0!==n?n:this.gameObject.layer,location:this.gameObject.ui?O.ViewPort:O.WorldSpace,position:new t,width:0,height:0,color:""}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?O.ViewPort:O.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),je=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Pe=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.innerPosition=new t,i.scaledOffset=new t,i._playing=!1,i._paused=!1,i.videoEventHandler=function(t){"ended"===t.type&&(i._playing=!1,i.video.removeEventListener("ended",i.videoEventHandler))},i.userInputEventHandler=function(){je.forEach((function(t){window.removeEventListener(t,i.userInputEventHandler)})),i.video&&i._playing&&i.video.play()},i}return c(i,e),Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this.video&&(this.video.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this.video&&(this.video.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),i.prototype.init=function(e){var i,s,r,n,o,a,l,c,d,u;this.video=e.video,this.width=null!==(i=e.width)&&void 0!==i?i:this.video.videoWidth,this.height=null!==(s=e.height)&&void 0!==s?s:this.video.videoHeight,this.offset=null!==(r=e.offset)&&void 0!==r?r:new t,this.rotation=null!==(n=e.rotation)&&void 0!==n?n:new h,this.flipHorizontal=null!==(o=e.flipHorizontal)&&void 0!==o&&o,this.flipVertical=null!==(a=e.flipVertical)&&void 0!==a&&a,this.opacity=null!==(l=e.opacity)&&void 0!==l?l:1,this.maskColor=e.maskColor,this.maskColorMix=null!==(c=e.maskColorMix)&&void 0!==c?c:0,this.tintColor=e.tintColor,this.layer=e.layer,this.slice=e.slice,this._volume=null!==(d=e.volume)&&void 0!==d?d:1,this._loop=null!==(u=e.loop)&&void 0!==u&&u,this.renderData={type:R.Video,location:O.WorldSpace,layer:"",position:new t,video:this.video,width:this.width,height:this.height}},i.prototype.play=function(){var t=this;if((this.video||!this.video.duration)&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this.video.play();this.video.loop=this._loop,this.video.volume=this._volume,this.video.addEventListener("ended",this.videoEventHandler),this._playing=!0;var e=this.video.play();void 0!==e&&e.catch((function(){je.forEach((function(e){return window.addEventListener(e,t.userInputEventHandler)}))}))}},i.prototype.stop=function(){this._playing&&(this.video.pause(),this.video.currentTime=0,this.video.removeEventListener("ended",this.videoEventHandler),this._playing=!1,this._paused=!1)},i.prototype.pause=function(){this._playing&&!1===this._paused&&(this.video.pause(),this._paused=!0)},i.prototype.update=function(){var t;this.video&&this.video.duration&&(this.renderData.location=this.gameObject.ui?O.ViewPort:O.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.video=this.video,this.renderData.width=this.width*Math.abs(this.gameObject.transform.scale.x),this.renderData.height=this.height*Math.abs(this.gameObject.transform.scale.y),this.renderData.slice=this.slice,this.renderData.flipHorizontal=this.flipHorizontal!==this.gameObject.transform.scale.x<0,this.renderData.flipVertical=this.flipVertical!==this.gameObject.transform.scale.y<0,this.renderData.rotation=this.gameObject.transform.rotation.radians+this.rotation.radians,this.renderData.alpha=this.opacity,this.renderData.maskColor=this.maskColor,this.renderData.maskColorMix=this.maskColorMix,this.renderData.tintColor=this.tintColor,this.calculateRenderPosition(),this.renderManager.addRenderData(this.renderData))},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.prototype.onActiveChange=function(){!1===this.active&&this.stop()},i.prototype.onDestroy=function(){this.stop()},i}(j),Oe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return 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,s=t.tileset,r=t.tileWidth,n=t.tileHeight,o=t.layer,a=t.orientation,h=t.smooth;this.tiledData=e,this.tilemapLayer=i,this.tileset=s,this.tileWidth=r,this.tileHeight=n,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,s=this,r={type:R.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?O.ViewPort:O.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 s;e.layer=null!==(s=t.layer)&&void 0!==s?s: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),Re=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.tiles=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t}return c(i,e),i.prototype.init=function(e){var i,s=this,r=e.tiles,n=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;r.split("\n").forEach((function(t){t.split(",").forEach((function(t){return t.trim().length>0?s.tiles.push(Number(t)):null}))})),this.tileset=n,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?O.ViewPort:O.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),Ae=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},Se=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.spriteRenderer=null,e.animations=new Map,e.currentAnimation=null,e.paused=!1,e}return 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 Te(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 void 0===t&&(t="default"),null!==this.currentAnimation&&this.animations.get(t)&&this.animations.get(t)===this.currentAnimation},e.prototype.isPaused=function(){return this.paused},e}(x),Te=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}(),De=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],Ee=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.allowMultiple=!1,e.tracks=[],e.audioSourceCache=new Map,e._playing=!1,e._paused=!1,e.audioEventHandler=function(t){"ended"===t.type&&(e._playing=!1,e._audioSource.removeEventListener("ended",e.audioEventHandler))},e.userInputEventHandler=function(){De.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return c(e,t),Object.defineProperty(e.prototype,"audioSource",{get:function(){return this._audioSource},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this._volume},set:function(t){this._volume=t,this._audioSource&&(this._audioSource.volume=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this._audioSource&&(this._audioSource.loop=t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"playing",{get:function(){return this._playing},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},enumerable:!1,configurable:!0}),e.prototype.init=function(t){var e=this,i=void 0===t?{}:t,s=i.loop,r=i.volume;this.audioContext=new AudioContext,"running"!==this.audioContext.state&&De.forEach((function(t){return window.addEventListener(t,e.userInputEventHandler)})),this._volume=null!=r?r:1,this._loop=null!=s&&s},e.prototype.playClip=function(t,e){t.currentTime>0&&(t.currentTime=0),t.volume=null!=e?e:this._volume,t.play()},e.prototype.addAudioSource=function(t,e){void 0===e&&(e="default");var i=t.cloneNode();this.audioSourceCache.set(e,i);var s=this.audioContext.createMediaElementSource(i);s.connect(this.audioContext.destination),this.tracks.push(s)},e.prototype.loadAudioSource=function(t,e,i){this.stop(),this._audioSource=this.audioSourceCache.get(t),this._loop=null!=e?e:this._loop,this._volume=null!=i?i:this._volume},e.prototype.play=function(){if(this._audioSource&&(!this._playing||!1!==this._paused)){if(this._paused)return this._paused=!1,void this._audioSource.play();this._audioSource.volume=this._volume,this._audioSource.loop=this._loop,this._audioSource.addEventListener("ended",this.audioEventHandler),this._playing=!0,"running"===this.audioContext.state&&this._audioSource.play()}},e.prototype.stop=function(){this._playing&&(this._audioSource.pause(),this._audioSource.currentTime=0,this._audioSource.removeEventListener("ended",this.audioEventHandler),this._playing=!1,this._paused=!1)},e.prototype.pause=function(){this._playing&&!1===this._paused&&(this._audioSource.pause(),this._paused=!0)},e.prototype.onActiveChange=function(){!1===this.active&&this.stop()},e.prototype.onDestroy=function(){this.stop(),this.audioContext.close()},e}(x),Fe=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 s=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?s():this.image.addEventListener("load",(function(){return s()}))}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"}(Jt||(Jt={}));var Be=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.inputManager.mouse,i.touch=i.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,s=t.radius,r=t.touchEnabled,n=t.width,o=t.offset;this.type=e,this.width=null!=n?n:this.width,this.height=null!=i?i:this.height,this.radius=null!=s?s:this.radius,this.touchEnabled=null!=r?r: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*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y))},i.prototype.resolveMouseAndRectangle=function(){this.type===Jt.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===Jt.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===Jt.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===Jt.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}(v),Ue=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(){this.inputManager.mouse.leftButtonPressed&&!1===this.mousePressed&&(t.round(this.position,t.add(this.position,this.camera.transform.position,t.scale(this.position,this.inputManager.mouse.positionInViewport,1/this.camera.zoom))),console.log("Space position: {x: ".concat(this.position.x,", y: ").concat(this.position.y,"}"))),this.mousePressed=this.inputManager.mouse.leftButtonPressed},i}(he);export{Ae as Animation,Se as Animator,Ee as AudioPlayer,fe as BallCollider,me as BoxCollider,Et as BroadPhaseMethods,Be as Button,Jt as ButtonType,ce as Camera,Bt as CollisionMethods,v as Component,be as EdgeCollider,se as Game,de as GameCamera,he as GameObject,F as GamepadController,B as GamepadData,I as KeyboardController,ae as LAYER_DEFAULT,Ce as MaskRenderer,L as MouseController,M as PhysicsComponent,pe as PolygonCollider,ge as PolygonColliderRenderer,_ as PreRenderComponent,e as Rectangle,oe as RigidBody,Ut as RigidBodyType,h as Rotation,ue as Scene,Ue as SpacePointer,Fe as Sprite,we as SpriteRenderer,mt as TextOrientation,_e as TextRenderer,Oe as TiledTilemapRenderer,ve as TilemapCollider,A as TilemapOrientation,Re as TilemapRenderer,W as TouchController,re as Transform,t as Vector2,Pe as VideoRenderer,a as between,i as clamp,n as fixedRound,r as randomFloat,s as randomInt,o as range};