angry-pixel 1.2.17 → 2.0.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,2 +1,2 @@
1
- var t=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),e=function(){function e(e,i,n,r){this._position=new t,this._center=new t,this._width=0,this._height=0,this.set(e,i,n,r)}return Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),e.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},e.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},e.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},e.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},e.prototype.contains=function(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)},e}(),i=function(t,e,i){return Math.min(i,Math.max(e,t))},n=function(t,e){return Math.round(Math.random()*(e-t))+t},r=function(t,e,i){return void 0===i&&(i=2),o(Math.random()*(e-t)+t,i)},o=function(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)},s=function(t,e,i){void 0===i&&(i=1);for(var n=[],r=t;r<=e;r+=i)n.push(r);return n},a=function(t,e,i){return t>=e&&t<=i},h=function(){function e(e,i){void 0===e&&(e=null),void 0===i&&(i=null),this._degrees=0,this._radians=0,this._direction=new t,e?this.radians=e:i&&(this.degrees=i)}return Object.defineProperty(e.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),e.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))},e}(),l=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new l,this._center=new l,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof l&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new l,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var c=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.getGamepads=function(){return Array.from(this.gamepads.values())},t.prototype.gamepadConnected=function(t){this.gamepads.set(t.index,new u),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.getGamepadsFromBrowser();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.getGamepadsFromBrowser=function(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]},t}(),u=function(){function t(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new l,this._leftStickAxes=new l,this._rightStickAxes=new l,this._vibrating=!1}return t.prototype.updateFromGamepad=function(t){var e=this;this._gamepad=t,t.buttons.forEach((function(t,i){return e.buttons.set(i,t.pressed)})),t.axes.forEach((function(t,i){return e.axes.set(i,t)}))},Object.defineProperty(t.prototype,"id",{get:function(){return this._gamepad.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._gamepad.connected},enumerable:!1,configurable:!0}),t.prototype.getButtonPressed=function(t){return this.buttons.get(t)},t.prototype.getAxis=function(t){return this.axes.get(t)},Object.defineProperty(t.prototype,"dpadAxes",{get:function(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickAxes",{get:function(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickAxes",{get:function(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadUp",{get:function(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadDown",{get:function(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadLeft",{get:function(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dpadRight",{get:function(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomFace",{get:function(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightFace",{get:function(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftFace",{get:function(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topFace",{get:function(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftShoulder",{get:function(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightShoulder",{get:function(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftTrigger",{get:function(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"back",{get:function(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"start",{get:function(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickButton",{get:function(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickButton",{get:function(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(1))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickHorizontal",{get:function(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightStickVertical",{get:function(){var t;return null!==(t=-this.axes.get(3))&&void 0!==t?t:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"anyButtonPressed",{get:function(){var t;return null!==(t=Array.from(this.buttons.values()).find((function(t){return t})))&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vibrating",{get:function(){return this._vibrating},enumerable:!1,configurable:!0}),t.prototype.vibrate=function(t,e,i,n){var r=this;void 0===t&&(t=200),void 0===e&&(e=.2),void 0===i&&(i=.2),void 0===n&&(n=0),this._gamepad.vibrationActuator&&(this._vibrating=!0,this._gamepad.vibrationActuator.playEffect(this._gamepad.vibrationActuator.type,{duration:t,weakMagnitude:e,strongMagnitude:i,startDelay:n}).catch((function(){return r._vibrating=!1})).finally((function(){return r._vibrating=!1})))},t}(),p=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}(),d=function(){function t(t){var e=this;this.pressedKeys=[],this.keyMap=new Map,this.eventHandler=function(t){if("keydown"===t.type&&(e.keyMap.set(t.code,!0),e.pressedKeys.includes(t.code)||e.pressedKeys.push(t.code)),"keyup"===t.type){e.keyMap.set(t.code,!1);var i=e.pressedKeys.indexOf(t.code);-1!==i&&e.pressedKeys.splice(i,1)}},t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler)}return t.prototype.isPressed=function(t){var e;return null!==(e=this.keyMap.get(t))&&void 0!==e&&e},t.prototype.orPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t||null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!1)},t.prototype.andPressed=function(t){var e=this;return t.reduce((function(t,i){var n;return t&&null!==(n=e.keyMap.get(i))&&void 0!==n&&n}),!0)},t.prototype.isPressedReturn=function(t,e,i){return this.keyMap.get(t)?e:i},t.prototype.orPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t||null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!1)?e:i},t.prototype.andPressedReturn=function(t,e,i){var n=this;return t.reduce((function(t,e){var i;return t&&null!==(i=n.keyMap.get(e))&&void 0!==i&&i}),!0)?e:i},t}(),f=function(){function t(t){this._leftButtonPressed=!1,this._scrollButtonPressed=!1,this._rightButtonPressed=!1,this._positionInViewport=new l,this._hasMoved=!1,this._wheelScroll=new l,this.lastPositionInViewport=new l,this.canvas=t,this.setup()}return Object.defineProperty(t.prototype,"leftButtonPressed",{get:function(){return this._leftButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scrollButtonPressed",{get:function(){return this._scrollButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightButtonPressed",{get:function(){return this._rightButtonPressed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"positionInViewport",{get:function(){return this._positionInViewport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasMoved",{get:function(){return this._hasMoved},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"wheelScroll",{get:function(){return this._wheelScroll},enumerable:!1,configurable:!0}),t.prototype.update=function(){!1===this._positionInViewport.equals(this.lastPositionInViewport)?(this._hasMoved=!0,this.lastPositionInViewport.copy(this._positionInViewport)):this._hasMoved=!1,this.wheelEvent?(this._wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this._wheelScroll.set(0,0)},t.prototype.setup=function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){return t.updatePosition(e)})),this.canvas.addEventListener("mousedown",(function(e){return t.updateButtonDown(e)})),this.canvas.addEventListener("mouseup",(function(e){return t.updateButtonUp(e)})),this.canvas.addEventListener("wheel",(function(e){return t.handleWheelEvent(e)}))},t.prototype.updateButtonDown=function(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0===t.button,this._scrollButtonPressed=1===t.button,this._rightButtonPressed=2===t.button},t.prototype.updateButtonUp=function(t){t.preventDefault(),t.stopPropagation(),this._leftButtonPressed=0!==t.button&&this._leftButtonPressed,this._scrollButtonPressed=1!==t.button&&this._scrollButtonPressed,this._rightButtonPressed=2!==t.button&&this._rightButtonPressed},t.prototype.updatePosition=function(t){t.preventDefault(),t.stopPropagation(),this._positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)},t.prototype.handleWheelEvent=function(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t},t}(),g=function(){function t(t){var e=this;this._touching=!1,this._interactions=[],this.eventHandler=function(t){"touchstart"===t.type&&(e._touching=!0,e.updatePosition(t)),"touchmove"===t.type&&e.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(e._touching=!1)},this.canvas=t,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}return Object.defineProperty(t.prototype,"touching",{get:function(){return this._touching},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"interactions",{get:function(){return this._interactions},enumerable:!1,configurable:!0}),t.prototype.updatePosition=function(t){if(t.preventDefault(),t.stopPropagation(),this._interactions=[],0!==t.targetTouches.length)for(var e=0;e<t.targetTouches.length;e++)this._interactions[e]={positionInViewport:new l((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new l(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}},t}(),m=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}(),y=function(){function t(t,e,i,n){this._position=new m,this._center=new m,this._width=0,this._height=0,this.set(t,e,i,n)}return Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof m&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)},t}(),v=function(t,e,i){return Math.min(i,Math.max(e,t))};!function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new m,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}();var x,b=function(){function t(){}return t.prototype.create=function(t){var e=t.shape,i=t.layer,n=t.updateCollisions,r=t.physics,o=t.position,s=t.rotation,a=t.group,h=t.onCollision;return{id:0,active:!0,layer:i,shape:e,updateCollisions:n,physics:r,position:null!=o?o:new m,rotation:null!=s?s:0,group:a,onCollision:h}},t}(),M=function(){function t(t,e){void 0===e&&(e=0),this.area=new y(0,0,0,0),this.depth=0,this.items=[],this.children=[],this.depth=e,this.resize(t)}return t.prototype.resize=function(t){this.clear(),this.area.copy(t)},t.prototype.clear=function(){this.items=[],this.children.forEach((function(t){return t.clear()})),this.children=[]},t.prototype.insert=function(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])},t.prototype.split=function(){var e=this,i=this.area.width/2,n=this.area.height/2;this.children=[new y(this.area.x,this.area.y,i,n),new y(this.area.x,this.area.y+n,i,n),new y(this.area.x+i,this.area.y+n,i,n),new y(this.area.x+i,this.area.y,i,n)].map((function(i){return new t(i,e.depth+1)})),this.items.forEach((function(t){return e.insertItemIntoChildren(t[0],t[1])})),this.items=[]},t.prototype.insertItemIntoChildren=function(t,e){this.getChildrenForArea(e).forEach((function(i){return i.insert(t,e)}))},t.prototype.retrieve=function(t){var e=[];return this.children.length>0?this.getChildrenForArea(t).forEach((function(i){return e.push.apply(e,i.retrieve(t))})):this.items.forEach((function(t){return e.push(t[0])})),e},t.prototype.getChildrenForArea=function(t){var 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},t}(),_=function(t,e,i,n){return Math.min((t-e)/i|0,n-1)},w=function(){function t(t){this.coordinates={x0:0,x1:0,y0:0,y1:0},this._subdivisions=1,this.resize(t)}return Object.defineProperty(t.prototype,"subdivisions",{get:function(){return this._subdivisions},set:function(t){this._subdivisions=v(t,1,20)},enumerable:!1,configurable:!0}),t.prototype.resize=function(t){this.area=t,this.cellWidth=Math.ceil(t.width/this._subdivisions),this.cellHeight=Math.ceil(t.height/this._subdivisions),this.itemsInCells=[];for(var e=0;e<this._subdivisions;e++){this.itemsInCells[e]=[];for(var i=0;i<this._subdivisions;i++)this.itemsInCells[e][i]=[]}},t.prototype.clear=function(){for(var t=0;t<this._subdivisions;t++)for(var e=0;e<this._subdivisions;e++)this.itemsInCells[t][e]=[]},t.prototype.insert=function(t,e){this.updateCoordinates(e);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].push(t)},t.prototype.retrieve=function(t){var e=[];this.updateCoordinates(t);for(var i=this.coordinates.x0;i<=this.coordinates.x1;i++)for(var n=this.coordinates.y0;n<=this.coordinates.y1;n++)this.itemsInCells[i][n].forEach((function(t){return e.includes(t)?null:e.push(t)}));return e},t.prototype.updateCoordinates=function(t){this.coordinates.x0=_(t.x,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.x1=_(t.x1,this.area.x,this.cellWidth,this._subdivisions),this.coordinates.y0=_(t.y,this.area.y,this.cellHeight,this._subdivisions),this.coordinates.y1=_(t.y1,this.area.y,this.cellHeight,this._subdivisions)},t}();!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(x||(x={}));var C,j=function(){function t(t,e,i,n){this.collisions=[],this.lastCollidersAmount=0,this.minArea=new m,this.maxArea=new m,this.newArea=new y(0,0,0,0),this.method=t,this.colliders=[],this.activeColliders=[],this.collisionMatrix=n,this.setupBroadPhaseResolver(null!=e?e:x.QuadTree,i)}return t.prototype.setupBroadPhaseResolver=function(t,e){this.collisionArea=null!=e?e:new y(0,0,0,0),this.fixedCollisionArea=!!e,t===x.SpartialGrid?this.broadPhaseResolver=new w(this.collisionArea):this.broadPhaseResolver=new M(this.collisionArea)},t.prototype.addCollider=function(t){t.id=this.colliders.length,this.colliders.push(t)},t.prototype.getCollider=function(t){return this.colliders[t]},t.prototype.removeCollider=function(t){this.colliders.splice(t.id,1),this.colliders.forEach((function(t,e){return t.id=e}))},t.prototype.clearColliders=function(){this.colliders=[]},t.prototype.getCollisionsForCollider=function(t){return t.active?this.collisions.filter((function(e){return e.localCollider.id===t.id})):[]},t.prototype.getCollisionsForColliderAndLayer=function(t,e){return t.active?this.collisions.filter((function(i){return i.localCollider.id===t.id&&i.remoteCollider.layer===e})):[]},t.prototype.refreshCollisionsForCollider=function(t){this.colliders[t.id]&&t.active&&(this.collisions=this.collisions.filter((function(e){return e.localCollider.id!==t.id&&e.remoteCollider.id!==t.id})),this.updateShape(t),this.narrowPhase(t,this.broadPhase(t)))},t.prototype.resolve=function(){var t=this;this.collisions=[],0!==this.colliders.length&&(this.activeColliders=this.colliders.filter((function(t){return t.active})),this.broadPhaseResolver.clear(),this.activeColliders.forEach((function(e){t.updateShape(e)})),!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((function(e){var i=e.id,n=e.shape.boundingBox;return t.broadPhaseResolver.insert(i,n)})),this.updateCollisions())},t.prototype.updateShape=function(t){t.shape.position=t.position,t.shape.rotation=t.rotation,t.shape.update()},t.prototype.updateNewArea=function(){var t=this;this.activeColliders.forEach((function(e){var i=e.shape.boundingBox;t.minArea.set(Math.min(i.x,t.minArea.x),Math.min(i.y,t.minArea.y)),t.maxArea.set(Math.max(i.x1,t.maxArea.x),Math.max(i.y1,t.maxArea.y))})),this.newArea.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)},t.prototype.checkForSpartialGridResize=function(){this.broadPhaseResolver instanceof w&&this.lastCollidersAmount!==this.activeColliders.length&&(this.broadPhaseResolver.subdivisions=1+(this.activeColliders.length/10|0),this.broadPhaseResolver.resize(this.collisionArea),this.lastCollidersAmount=this.activeColliders.length)},t.prototype.updateCollisions=function(){var t=this;this.activeColliders.filter((function(t){return t.updateCollisions})).forEach((function(e){return t.narrowPhase(e,t.broadPhase(e))}))},t.prototype.broadPhase=function(t){var e=this;return this.collisionMatrix?this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active})).filter((function(i){return e.collisionMatrix.some((function(e){return e[0]===t.layer&&e[1]===i.layer||e[1]===t.layer&&e[0]===i.layer}))})):this.broadPhaseResolver.retrieve(t.shape.boundingBox).map((function(t){return e.colliders[t]})).filter((function(t){return t.active}))},t.prototype.narrowPhase=function(t,e){var i=this;e.filter((function(e){return!(t.group&&e.group&&e.group===t.group||t.id===e.id)})).forEach((function(e){if(!i.isResolved(t,e)){var n=i.method.getCollisionResolution(t.shape,e.shape);null!==n&&(i.collisions.push({localCollider:t,remoteCollider:e,resolution:n},{localCollider:e,remoteCollider:t,resolution:{direction:n.displacementDirection,displacementDirection:n.direction,penetration:n.penetration}}),t.onCollision&&t.onCollision(n))}}))},t.prototype.isResolved=function(t,e){for(var i=0,n=this.collisions;i<n.length;i++){var r=n[i];if(r.localCollider.id===t.id&&r.remoteCollider.id===e.id)return!0}return!1},t}();!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(C||(C={}));var O,P=function(){function t(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}return t.prototype.getCollisionResolution=function(t,e){return t.type===C.Polygon&&e.type===C.Polygon?this.AABBResolver.resolve(t,e):t.type===C.Circumference&&e.type===C.Polygon?this.circumferenceAABBResolver.resolve(t,e):t.type===C.Polygon&&e.type===C.Circumference?this.circumferenceAABBResolver.resolve(e,t,!0):t.type===C.Circumference&&e.type===C.Circumference?this.circumferenceResolver.resolve(t,e):null},t}();!function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(O||(O={}));var R=function(){function t(t,e){this.circumferenceResolver=t,this.satResolver=e}return t.prototype.getCollisionResolution=function(t,e){return t.type===C.Circumference&&e.type===C.Circumference?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)},t}(),A=function(){function t(){this.direction=new m,this.displacementDirection=new m}return t.prototype.resolve=function(t,e){var i=t.boundingBox,n=e.boundingBox;return this.overlapX=Math.min(i.x1,n.x1)-Math.max(i.x,n.x),this.overlapY=Math.min(i.y1,n.y1)-Math.max(i.y,n.y),this.overlapX<0||this.overlapY<0?null:(this.checkOverlapForLines(i,n),this.direction.set(Math.sign(n.center.x-i.center.x),Math.sign(n.center.y-i.center.y)),this.preventContainment(i,n),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)),m.unit(this.displacementDirection,this.displacementDirection),{direction:m.scale(new m,this.displacementDirection,-1),displacementDirection:this.displacementDirection.clone(),penetration:this.minOverlap})},t.prototype.checkOverlapForLines=function(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)))},t.prototype.preventContainment=function(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){var i=Math.abs(t.y-e.y),n=Math.abs(t.y1-e.y1);this.overlapY+=i<n?i:n}this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)&&(i=Math.abs(t.x-e.x),n=Math.abs(t.x1-e.x1),this.overlapX+=i<n?i:n)},t}(),S=function(){function t(){this.closestPoint=new m,this.distance=new m,this.direction=new m}return t.prototype.resolve=function(t,e,i){return void 0===i&&(i=!1),this.closestPoint.set(v(t.position.x,e.boundingBox.x,e.boundingBox.x1),v(t.position.y,e.boundingBox.y,e.boundingBox.y1)),m.subtract(this.distance,this.closestPoint,t.position),this.distance.magnitude>t.radius?null:(m.unit(this.direction,this.distance),{direction:i?m.scale(new m,this.direction,-1):this.direction.clone(),displacementDirection:i?this.direction.clone():m.scale(new m,this.direction,-1),penetration:t.radius-this.distance.magnitude})},t}(),E=function(){function t(){this.distance=new m,this.direction=new m}return t.prototype.resolve=function(t,e){return m.subtract(this.distance,e.position,t.position),this.distance.magnitude>t.radius+e.radius?null:(m.unit(this.direction,this.distance),{direction:this.direction.clone(),displacementDirection:m.scale(new m,this.direction,-1),penetration:t.radius+e.radius-this.distance.magnitude})},t}(),T=function(t,e){return T=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])},T(t,e)};function D(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r<o;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var F,B=function(){function t(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new m,this.distance=new m(1/0,1/0),this.cache=new m}return t.prototype.resolve=function(t,e){var i=this;this.minOverlap=1/0,t.type===C.Circumference?this.setCircumferenceAxis(t,e):e.type===C.Circumference&&this.setCircumferenceAxis(e,t),this.axes=D([],t.projectionAxes,!0),e.projectionAxes.forEach((function(t){return i.axes.some((function(e){return e.equals(t)}))?null:i.axes.push(t)}));for(var n=0;n<this.axes.length;n++){if(t.type===C.Circumference?this.setCircumferenceVertices(t,this.axes[n]):e.type===C.Circumference&&this.setCircumferenceVertices(e,this.axes[n]),this.projectShapeOntoAxis(this.projA,t,this.axes[n]),this.projectShapeOntoAxis(this.projB,e,this.axes[n]),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return null;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){var r=Math.abs(this.projA.min-this.projB.min),o=Math.abs(this.projA.max-this.projB.max);r<o?this.currentOverlap+=r:(this.currentOverlap+=o,m.scale(this.axes[n],this.axes[n],-1),this.invertAxis=!1)}this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.smallestAxis.copy(this.axes[n]),this.invertAxis&&this.projA.max<this.projB.max&&m.scale(this.smallestAxis,this.axes[n],-1))}return{direction:m.scale(new m,this.smallestAxis,-1),displacementDirection:this.smallestAxis.clone(),penetration:this.minOverlap}},t.prototype.projectShapeOntoAxis=function(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((function(e){t.min=Math.min(m.dot(i,e),t.min),t.max=Math.max(m.dot(i,e),t.max)})),t},t.prototype.setCircumferenceAxis=function(t,e){var i=this;this.distance.set(1/0,1/0),e.vertices.forEach((function(e){m.subtract(i.cache,e,t.position),i.cache.magnitude<i.distance.magnitude&&i.distance.copy(i.cache)})),m.unit(t.projectionAxes[0],this.distance)},t.prototype.setCircumferenceVertices=function(t,e){m.add(t.vertices[0],t.position,m.scale(this.cache,m.unit(this.cache,e),-t.radius)),m.add(t.vertices[1],t.position,m.scale(this.cache,m.unit(this.cache,e),t.radius))},t}(),U=function(){function t(t,e,i,n){this.collisionManager=t,this.colliderFactory=e,this.rigidBodyManager=i,this.rigidBodyFactory=n}return t.prototype.addCollider=function(t){var e=this.colliderFactory.create(t);return this.collisionManager.addCollider(e),e},t.prototype.removeCollider=function(t){this.collisionManager.removeCollider(t)},t.prototype.getCollisionsForCollider=function(t){return this.collisionManager.getCollisionsForCollider(t)},t.prototype.getCollisionsForColliderAndLayer=function(t,e){return this.collisionManager.getCollisionsForColliderAndLayer(t,e)},t.prototype.addRigidBody=function(t){var e=this.rigidBodyFactory.create(t);return this.rigidBodyManager.addRigidBody(e),e},t.prototype.removeRigidBody=function(t){this.rigidBodyManager.removeRigidBody(t)},t.prototype.resolve=function(t){this.collisionManager.resolve(),this.rigidBodyManager.resolve(t)},t.prototype.clear=function(){this.collisionManager.clearColliders(),this.rigidBodyManager.clearRigidBodies()},t}(),I=function(){function t(){}return t.prototype.create=function(t){var e=t.colliderIds,i=t.type,n=t.gravity,r=t.position,o=t.velocity,s=t.onResolve;if(0===e.length)throw new Error("RigidBody needs at least one collider");return{active:!0,colliderIds:e,type:i,gravity:null!=n?n:0,position:null!=r?r:new m,velocity:null!=o?o:new m,onResolve:s}},t}();!function(t){t[t.Static=0]="Static",t[t.Dynamic=1]="Dynamic",t[t.Kinematic=2]="Kinematic"}(F||(F={}));var L=["x","y"],V=function(){function t(t){this.collisionManager=t,this.rigidBodies=[],this.activeRigidBodies=[],this.colliders=[],this.velocity=new m,this.displacement=new m,this.cacheDisplacement=0}return t.prototype.addRigidBody=function(t){this.rigidBodies.push(t)},t.prototype.removeRigidBody=function(t){var e=this.rigidBodies.indexOf(t);e>=0&&this.rigidBodies.splice(e,1)},t.prototype.clearRigidBodies=function(){this.rigidBodies=[]},t.prototype.resolve=function(t){var e=this;this.activeRigidBodies=this.rigidBodies.filter((function(t){return t.active})),this.colliders=this.activeRigidBodies.reduce((function(t,e){return D(D([],t,!0),e.colliderIds,!0)}),[]),this.activeRigidBodies.forEach((function(i){i.type===F.Dynamic?e.dynamicUpdate(i,t):i.type===F.Kinematic&&e.kinematicUpdate(i,t),i.onResolve&&i.onResolve(i)}))},t.prototype.dynamicUpdate=function(t,e){var i=this;this.applyGravity(t,e),L.forEach((function(n){i.applyVelocity(t,e,n),i.obtainDisplacement(t,n),i.applyReposition(t,n)}))},t.prototype.kinematicUpdate=function(t,e){var i=this;m.add(t.position,t.position,m.scale(this.velocity,t.velocity,e)),t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){m.add(t.position,t.position,i.velocity),i.collisionManager.refreshCollisionsForCollider(t)}))},t.prototype.applyGravity=function(t,e){t.gravity>0&&(t.velocity.y-=t.gravity*e)},t.prototype.applyVelocity=function(t,e,i){var n=this;this.velocity[i]=t.velocity[i]*e,0!==this.velocity[i]&&(t.position[i]+=this.velocity[i],t.colliderIds.map((function(t){return n.collisionManager.getCollider(t)})).forEach((function(t){t.position[i]+=n.velocity[i],n.collisionManager.refreshCollisionsForCollider(t)})))},t.prototype.obtainDisplacement=function(t,e){var i=this;this.displacement[e]=0,this.getCollisions(t).forEach((function(t){i.cacheDisplacement=t.resolution.displacementDirection[e]*t.resolution.penetration,i.displacement[e]=Math.abs(i.displacement[e])>Math.abs(i.cacheDisplacement)?i.displacement[e]:i.cacheDisplacement}))},t.prototype.applyReposition=function(t,e){var i=this;0!==this.displacement[e]&&(t.position[e]+=this.displacement[e],t.colliderIds.map((function(t){return i.collisionManager.getCollider(t)})).forEach((function(t){t.position[e]+=i.displacement[e],i.collisionManager.refreshCollisionsForCollider(t)})),Math.sign(this.displacement[e])!==Math.sign(t.velocity[e])&&(t.velocity[e]=0))},t.prototype.getCollisions=function(t){var e=this;return t.colliderIds.map((function(t){return e.collisionManager.getCollider(t)})).filter((function(t){return t.active&&t.physics})).reduce((function(t,i){return t.push.apply(t,e.collisionManager.getCollisionsForCollider(i).filter((function(t){return t.remoteCollider.physics&&e.colliders.includes(t.remoteCollider.id)}))),t}),[])},t}(),G=function(){function t(t){this.radius=t,this.type=C.Circumference,this.boundingBox=new y(0,0,0,0),this.vertices=[new m,new m],this.projectionAxes=[new m],this._position=new m}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateBoundingBox()},t.prototype.updateBoundingBox=function(){this.boundingBox.set(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},t}(),k=function(){function t(t){this.vertexModel=t,this.type=C.Polygon,this.vertices=[new m,new m],this.projectionAxes=[new m],this.boundingBox=new y(0,0,0,0),this.rotation=0,this._position=new m}return t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.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)},t.prototype.updateBoundingBox=function(){this.boundingBox.x=Math.min(this.vertices[0].x,this.vertices[1].x),this.boundingBox.y=Math.min(this.vertices[0].y,this.vertices[1].y),this.boundingBox.width=Math.max(this.vertices[0].x,this.vertices[1].x)-this.boundingBox.x,this.boundingBox.height=Math.max(this.vertices[0].y,this.vertices[1].y)-this.boundingBox.y},t.prototype.updateProjectionAxes=function(){m.normal(this.projectionAxes[0],m.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0]))},t}(),W=function(){function t(t){this.vertexModel=t,this.type=C.Polygon,this.vertices=[],this.boundingBox=new y(0,0,0,0),this.rotation=0,this._projectionAxes=[],this._position=new m,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(var e=0;e<this.vertexModel.length;e++)this.vertices.push(new m),this._projectionAxes.push(new m)}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.copy(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"projectionAxes",{get:function(){return this._projectionAxes},enumerable:!1,configurable:!0}),t.prototype.update=function(){this.updateVertices(),this.updateBoundingBox(),this.updateProjectionAxes()},t.prototype.updateVertices=function(){for(var t=0;t<this.vertexModel.length;t++)this.vertices[t].set(this.vertexModel[t].x*Math.cos(this.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)},t.prototype.updateBoundingBox=function(){var t=this;this.boxMinX=this.vertices[0].x,this.boxMinY=this.vertices[0].y,this.boxMaxX=this.vertices[0].x,this.boxMaxY=this.vertices[0].y,this.vertices.forEach((function(e){t.boxMinX=Math.min(e.x,t.boxMinX),t.boxMinY=Math.min(e.y,t.boxMinY),t.boxMaxX=Math.max(e.x,t.boxMaxX),t.boxMaxY=Math.max(e.y,t.boxMaxY)})),this.boundingBox.set(this.boxMinX,this.boxMinY,this.boxMaxX-this.boxMinX,this.boxMaxY-this.boxMinY)},t.prototype.updateProjectionAxes=function(){for(var t,e=0;e<this.vertices.length;e++)m.normal(this._projectionAxes[e],m.subtract(this._projectionAxes[e],null!==(t=this.vertices[e+1])&&void 0!==t?t:this.vertices[0],this.vertices[e]))},t}(),H=function(t){function e(e,i){var n=t.call(this,[new m(-e/2,-i/2),new m(-e/2,i/2),new m(e/2,i/2),new m(e/2,-i/2)])||this;return n.width=e,n.height=i,n._projectionAxes=[new m,new m],n}return function(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}T(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,t),e.prototype.updateSize=function(t,e){this.width=t,this.height=e,this.vertexModel[0].set(-t/2,-e/2),this.vertexModel[1].set(-t/2,e/2),this.vertexModel[2].set(t/2,e/2),this.vertexModel[3].set(t/2,-e/2)},e.prototype.updateProjectionAxes=function(){m.unit(this.projectionAxes[0],m.subtract(this.projectionAxes[0],this.vertices[1],this.vertices[0])),m.normal(this.projectionAxes[1],this.projectionAxes[0])},e}(W),z=function(t,e){return z=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])},z(t,e)};function N(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}z(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var Y,X=function(){return X=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},X.apply(this,arguments)};function q(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r<o;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,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"}(Y||(Y={}));var K,Q,$,J=function(){function t(t,e,i,n,r,o,s){this.timeManager=t,this.physicsManager=e,this.renderManager=i,this.inputManager=n,this.gameObjectManager=r,this.sceneManager=o,this.canvasColor=s,this.running=!1,this.gameLoopAccumulator=0,this.gameObjects=[],this.components=[],this.changingScene=!1,this.sceneEvents=[Y.Start,Y.Update,Y.StopGame],this.gameObjectEvents=[Y.Start,Y.Update]}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.dispatchFrameEvent(Y.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.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.minGameDeltatime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.minGameDeltatime),this.renderIteration(),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene()),window.requestAnimationFrame((function(t){return e.requestAnimationLoop(t)})))},t.prototype.gameLogicIteration=function(t){this.timeManager.updateForGame(t),this.load(),this.dispatchFrameEvent(Y.Start),this.inputManager.update(),this.dispatchFrameEvent(Y.Update),this.dispatchFrameEvent(Y.UpdateEngine),this.dispatchFrameEvent(Y.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.dispatchFrameEvent(Y.UpdatePreRender)},t.prototype.renderIteration=function(){this.dispatchFrameEvent(Y.UpdatePreRender),this.dispatchFrameEvent(Y.UpdateCamera),this.dispatchFrameEvent(Y.UpdateRender),this.renderManager.clearScreen(this.canvasColor),this.renderManager.render(),this.renderManager.clearData()},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(Y.UpdatePhysics),this.dispatchFrameEvent(Y.UpdateCollider),this.dispatchFrameEvent(Y.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(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),Z=function(){function t(t){this.updateEvent=Y.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===Y.Init&&this.init?this.init(e):t!==Y.Start||this.started?t===this.updateEvent&&this.started&&this.update?this.update():t===Y.Destroy?(this.onDestroy&&this.onDestroy(),this._destroy()):t===Y.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}(),tt=function(t){function e(e,i,n){void 0===n&&(n="");var r=t.call(this,e)||this;return r.allowMultiple=!0,r._active=!0,r.gameObject=i,r.name=n,r}return N(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.getLoadedScene()},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}(Z),et=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdateEngine,e}return N(e,t),e}(tt),it=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdateCollider,e}return N(e,t),e}(tt),nt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdatePhysics,e}return N(e,t),e}(tt),rt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdateTransform,e}return N(e,t),e}(tt),ot=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdatePreRender,e}return N(e,t),e}(tt),st=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdateCamera,e}return N(e,t),e}(tt),at=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateEvent=Y.UpdateRender,e}return N(e,t),e}(tt);!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(K||(K={})),function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ViewPort=1]="ViewPort"}(Q||(Q={})),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"}($||($={}));var ht=function(){function t(t){this.gl=t,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0}}return t.prototype.setViewport=function(t,e){var i=t.position,n=t.zoom;e===Q.WorldSpace?(this.viewport.x=i.x-this.gl.canvas.width/n/2,this.viewport.x1=i.x+this.gl.canvas.width/n/2,this.viewport.y=i.y-this.gl.canvas.height/n/2,this.viewport.y1=i.y+this.gl.canvas.height/n/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)},t.prototype.setObjectForResizeable=function(t){var e=t.position,i=t.width,n=t.height,r=t.rotation,o=void 0===r?0:r,s=Math.abs(Math.sin(o)),a=Math.abs(Math.cos(o)),h=s*n+a*i,l=s*i+a*n;this.object.x=e.x-h/2,this.object.x1=e.x+h/2,this.object.y=e.y-l/2,this.object.y1=e.y+l/2},t.prototype.setObjectForText=function(t){var e=t.position,i=t.text,n=t.fontSize,r=t.lineSeparation,o=t.letterSpacing,s=t.rotation,a=i.split("\n").reduce((function(t,e){return Math.max(t,e.length)}),0)*(n+(null!=o?o:0))*2,h=i.split("\n").length*(n+(null!=r?r:0));this.setObjectForResizeable({position:e,width:a,height:h,rotation:s})},t.prototype.setObjectForGeometric=function(t){var e=this,i=t.position,n=t.vertexModel,r=t.shape,o=t.radius;r===K.Circumference?(this.object.x=i.x-o,this.object.y=i.y-o,this.object.x1=i.x+o,this.object.y1=i.y+o):(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,n.forEach((function(t){e.object.x=Math.min(t.x+i.x,e.object.x),e.object.y=Math.min(t.y+i.y,e.object.y),e.object.x1=Math.max(t.x+i.x,e.object.x1),e.object.y1=Math.max(t.y+i.y,e.object.y1)})))},t.prototype.setObjectForTilemap=function(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})},t.prototype.applyCullingInTiles=function(t){var e=this,i=t.tiles,n=t.tilemap,r=n.width,o=n.tileWidth,s=n.tileHeight;t.culledTiles=i.map((function(t,i){return e.viewport.x1>=e.object.x+i%r*o&&e.viewport.x<=e.object.x+i%r*o+o&&e.viewport.y1>=e.object.y1-((i/r|0)*s+s)&&e.viewport.y<=e.object.y1-(i/r|0)*s?t:0}))},t.prototype.isInViewPort=function(t,e){switch(this.setViewport(e,t.location),t.type){case $.Video:case $.Mask:case $.Sprite:this.setObjectForResizeable(t);break;case $.Geometric:this.setObjectForGeometric(t);break;case $.Text:this.setObjectForText(t);break;case $.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},t.prototype.applyCulling=function(t,e){var i=this;return e.filter((function(e){return!!i.isInViewPort(e,t)&&(e.type===$.Tilemap&&i.applyCullingInTiles(e),!0)}))},t}(),lt=function(){return lt=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},lt.apply(this,arguments)};function ct(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r<o;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var ut,pt=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"magnitude",{get:function(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction||(this._direction=new t),t.unit(this._direction,this)},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e){this._x=t,this._y=e},t.prototype.copy=function(t){this.set(t.x,t.y)},t.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},t.prototype.clone=function(){return new t(this._x,this._y)},t.prototype.distance=function(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))},t.add=function(t,e,i){return t.set(e.x+i.x,e.y+i.y),t},t.subtract=function(t,e,i){return t.set(e.x-i.x,e.y-i.y),t},t.unit=function(t,e){return 0===e.magnitude?t.set(0,0):t.set(e.x/e.magnitude,e.y/e.magnitude),t},t.normal=function(t,e){return t.set(-e.y,e.x),this.unit(t,t)},t.scale=function(t,e,i){return t.set(e.x*i,e.y*i),t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(t,e){return t.x*e.y-t.y*e.x},t.round=function(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t},t}();!function(){function t(t,e,i,n){this._position=new pt,this._center=new pt,this._width=0,this._height=0,this.set(t,e,i,n)}Object.defineProperty(t.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.set(t,this._position.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.set(this._position.x,t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"x1",{get:function(){return this._position.x+this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y1",{get:function(){return this._position.y+this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position.set(t.x,t.y)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i,n){this._position.set(t,e),this._width=i,this._height=n},t.prototype.equals=function(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height},t.prototype.copy=function(t){this.set(t.x,t.y,t.width,t.height)},t.prototype.overlaps=function(t){return this.x1>=t.x&&this.x<t.x1&&this.y1>=t.y&&this.y<t.y1},t.prototype.contains=function(e){return e instanceof t?e.x1<=this.x1&&e.x>=this.x&&e.y1<=this.y1&&e.y>=this.y:e instanceof pt&&!(e.x<this.x||e.y<this.y||e.x>=this.x1||e.y>=this.y1)}}(),function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this._degrees=0,this._radians=0,this._direction=new pt,t?this.radians=t:e&&(this.degrees=e)}Object.defineProperty(t.prototype,"degrees",{get:function(){return this._degrees},set:function(t){this._degrees=t,this._radians=t*Math.PI/180,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radians",{get:function(){return this._radians},set:function(t){this._radians=t,this._degrees=180*t/Math.PI,this.updateDirection()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!1,configurable:!0}),t.prototype.updateDirection=function(){this._direction.set(Math.cos(this._radians),Math.sin(this._radians))}}(),function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(ut||(ut={}));var dt,ft=function(){function t(t,e){this.webglManager=t,this.cullingManager=e,this.renderData=[],this.cameraData=[]}return t.prototype.addRenderData=function(t){this.renderData.push(t)},t.prototype.addCameraData=function(t){this.cameraData.push(t)},t.prototype.render=function(){var t=this;this.cameraData.sort((function(t,e){return t.depth-e.depth})).forEach((function(e){return t.renderByCamera(e)}))},t.prototype.renderByCamera=function(t){var e=this;this.cullingManager.applyCulling(t,this.renderData.filter((function(e){return t.layers.includes(e.layer)})).sort((function(e,i){return t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer)})).map((function(t){return t.type===$.Tilemap?function(t){var e=lt(lt({},t),{culledTiles:[],tilemap:lt(lt({},t.tilemap),{height:Math.ceil(t.tiles.length/t.tilemap.width),realWidth:t.tilemap.width*t.tilemap.tileWidth,realHeight:0}),renderPosition:new pt});return e.tilemap.realHeight=e.tilemap.height*e.tilemap.tileHeight,function(t){t.renderPosition.set(t.position.x+(t.orientation!==ut.Center?t.tilemap.realWidth/2:0),t.position.y+(t.orientation===ut.RightDown?-t.tilemap.realHeight/2:t.orientation===ut.RightUp?t.tilemap.realHeight/2:0))}(e),e}(t):t}))).forEach((function(i){return e.webglManager.render(i,t)}))},t.prototype.clearData=function(){this.renderData=[],this.cameraData=[]},t.prototype.clearScreen=function(t){this.webglManager.clearCanvas(t)},t.prototype.preloadTexture=function(t){this.webglManager.createTexture(t)},t}();!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(dt||(dt={}));var gt=function(){function t(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)}return t.prototype.getContextVersion=function(){return null!==this.canvas.getContext(dt.WebGL2)?dt.WebGL2:null!==this.canvas.getContext(dt.LegacyWebGL)?dt.LegacyWebGL:void 0},t}(),mt=function(){function t(){this.fontAtlas=new Map}return t.prototype.hasFontAtlas=function(t){return this.fontAtlas.has(this.symbol(t))},t.prototype.getFontAtlas=function(t){return this.fontAtlas.get(this.symbol(t))},t.prototype.getOrCreate=function(t,e,i){var n;return null!==(n=this.getFontAtlas(e))&&void 0!==n?n:this.create(t,e,i)},t.prototype.create=function(t,e,i){this.bitmapSize=i,this.chars=[];for(var n=0;n<t.length;n+=2)for(var r=t[n];r<=t[n+1];r++)this.chars.push(String.fromCharCode(r));var o=this.renderAtlas(e instanceof FontFace?e.family:e);return this.fontAtlas.set(this.symbol(e),o),o},t.prototype.symbol=function(t){return Symbol.for(t instanceof FontFace?t.family:t)},t.prototype.renderAtlas=function(t){var e=new yt(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="".concat(this.bitmapSize,"px ").concat(t);for(var n=0,r=0,o=0;o<this.chars.length;o++)i.fillText(this.chars[o],n,r),e.glyphs.set(this.chars[o],{id:o,width:i.measureText(this.chars[o]).width}),(n+=this.bitmapSize)>e.canvas.width-this.bitmapSize&&(n=0,r+=this.bitmapSize);return e},t}(),yt=function(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},vt=function(){function t(t,e){this.gl=t,this.shaderLoader=e}return t.prototype.create=function(t,e){var 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);var o=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,o)){var s=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error("Unable to initialize the Program: ".concat(s))}return i},t}(),xt=function(){function t(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}return t.prototype.loadProgram=function(){this.program=this.contextVersion===dt.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 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 * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision highp 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)},t}(),bt=function(){function t(t){this.gl=t}return t.prototype.load=function(t,e){var i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);var n=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,n)){var r=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error("Unable to initialize the shader program: ".concat(r))}return i},t}(),Mt="undefined"!=typeof Float32Array?Float32Array:Array;function _t(){var t=new Mt(16);return Mt!=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 wt(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 Ct(t,e,i){var n,r,o,s,a,h,l,c,u,p,d,f,g=i[0],m=i[1],y=i[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*y+e[12],t[13]=e[1]*g+e[5]*m+e[9]*y+e[13],t[14]=e[2]*g+e[6]*m+e[10]*y+e[14],t[15]=e[3]*g+e[7]*m+e[11]*y+e[15]):(n=e[0],r=e[1],o=e[2],s=e[3],a=e[4],h=e[5],l=e[6],c=e[7],u=e[8],p=e[9],d=e[10],f=e[11],t[0]=n,t[1]=r,t[2]=o,t[3]=s,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=u,t[9]=p,t[10]=d,t[11]=f,t[12]=n*g+a*m+u*y+e[12],t[13]=r*g+h*m+p*y+e[13],t[14]=o*g+l*m+d*y+e[14],t[15]=s*g+c*m+f*y+e[15]),t}function jt(t,e,i){var n=i[0],r=i[1],o=i[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ot(t,e,i){var n=Math.sin(i),r=Math.cos(i),o=e[0],s=e[1],a=e[2],h=e[3],l=e[4],c=e[5],u=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*r+l*n,t[1]=s*r+c*n,t[2]=a*r+u*n,t[3]=h*r+p*n,t[4]=l*r-o*n,t[5]=c*r-s*n,t[6]=u*r-a*n,t[7]=p*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 Pt,Rt=function(t){var e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null},At=function(t,e,i,n){var r,o;(function(t,e,i,n,r,o,s){var a=1/(e-i),h=1/(n-r);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]=-1,t[11]=0,t[12]=(e+i)*a,t[13]=(r+n)*h,t[14]=-0,t[15]=1})(t=wt(t),-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2),n===Q.WorldSpace&&(jt(t,t,[null!==(r=i.zoom)&&void 0!==r?r:1,null!==(o=i.zoom)&&void 0!==o?o:1,1]),Ct(t,t,[-i.position.x,-i.position.y,0]))},St=function(){function t(t,e){this.gl=t,this.programManager=e,this.vertices=new Map,this.lastVertices=null,this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t();var i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(function(t,e,i){void 0===i&&(i=1);for(var n=[],r=1;r<=60;r+=i)n.push(r);return n}(0,0,1).reduce((function(t,e){return ct(ct([],t,!0),[Math.cos(e*i),Math.sin(e*i)],!1)}),[]))}return t.prototype.render=function(t,e,i){switch(t.shape){case K.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP,i);break;case K.Line:this.renderLines(t,e,this.gl.LINES,i);break;case K.Circumference:this.renderCircumference(t,e)}},t.prototype.renderLines=function(t,e,i,n){var r,o=this.generateVerticesKey(t.vertexModel);!1===this.vertices.has(o)&&this.vertices.set(o,new Float32Array(this.generatePolygonVertices(t.vertexModel)));var s=this.vertices.get(o);this.lastVertices===o&&n===$.Geometric||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW)),this.lastVertices=o,this.modelMatrix=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),At(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);var a=Rt(t.color),h=a.r,l=a.g,c=a.b,u=a.a;this.gl.uniform4f(this.programManager.solidColorUniform,h,l,c,u),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,s.length/2)},t.prototype.generateVerticesKey=function(t){return Symbol.for(t.reduce((function(t,e){return"".concat(t).concat(e.x).concat(e.y)}),t.length.toString()))},t.prototype.generatePolygonVertices=function(t){for(var e=[],i=0;i<t.length;i++)e.push(t[i].x,t[i].y);return e},t.prototype.renderCircumference=function(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=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),jt(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),At(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);var i=Rt(t.color),n=i.r,r=i.g,o=i.b,s=i.a;this.gl.uniform4f(this.programManager.solidColorUniform,n,r,o,s),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)},t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Pt||(Pt={}));var Et,Tt=function(){function t(t,e){this.gl=t,this.programManager=e,this.type=$.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t();for(var i=2*Math.PI/60,n=[0,0],r=0;r<=60;r++)n.push(Math.cos(r*i),Math.sin(r*i));this.circumferenceVertices=new Float32Array(n)}return t.prototype.render=function(t,e,i){var n,r;i===$.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===Pt.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),jt(this.modelMatrix,this.modelMatrix,t.shape===Pt.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),At(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);var o=Rt(t.color),s=o.r,a=o.g,h=o.b,l=o.a;this.gl.uniform4f(this.programManager.solidColorUniform,s,a,h,l),this.gl.uniform1f(this.programManager.alphaUniform,null!==(r=t.alpha)&&void 0!==r?r:1),t.shape===Pt.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape},t}(),Dt=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,r,o,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),jt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=wt(this.textureMatrix),t.slice&&(Ct(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),jt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),At(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);var 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){var h=Rt(t.tintColor),l=h.r,c=h.g,u=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,l,c,u,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=Rt(t.maskColor);l=d.r,c=d.g,u=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,l,c,u,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}();!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Et||(Et={}));var Ft,Bt=new pt,Ut=new pt,It=[32,126,161,255],Lt=Et.Center,Vt=function(){function t(t,e,i,n){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=n,this.type=$.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new pt,this.modelPosition=new pt,this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t()}return t.prototype.render=function(t,e,i){var n;if(!t.text)throw new Error("Nothing to render");this.setDefaultValues(t);var 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=wt(this.modelMatrix),this.setPositionFromOrientation(t),Ct(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),jt(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=wt(this.textureMatrix),At(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);var o=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+r.fontFaceFamily,r.canvas,t.smooth);this.lastTexture===o&&i===$.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,o),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=o),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.alpha);var s=Rt(t.color),a=s.r,h=s.g,l=s.b,c=s.a;this.gl.uniform4f(this.programManager.maskColorUniform,a,h,l,c),this.gl.uniform1f(this.programManager.maskColorMixUniform,1),this.gl.uniform1i(this.programManager.useMaskColorUniform,1),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.setDefaultValues=function(t){var e,i,n,r,o,s,a,h,l,c;t.bitmap?(t.bitmap.margin=null!==(e=t.bitmap.margin)&&void 0!==e?e:Bt,t.bitmap.spacing=null!==(i=t.bitmap.spacing)&&void 0!==i?i:Ut,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:It):t.bitmap={margin:Bt,spacing:Ut,fontSize:64,charRanges:It},t.color=null!==(o=t.color)&&void 0!==o?o:"#000000",t.letterSpacing=null!==(s=t.letterSpacing)&&void 0!==s?s:0,t.lineSeparation=null!==(a=t.lineSeparation)&&void 0!==a?a:0,t.alpha=null!==(h=t.alpha)&&void 0!==h?h:1,t.orientation=null!==(l=t.orientation)&&void 0!==l?l:Lt,t.rotation=null!==(c=t.rotation)&&void 0!==c?c:0},t.prototype.generateTextVertices=function(t,e){var i=e.text,n=e.fontSize,r=e.bitmap,o=e.letterSpacing,s=e.lineSeparation;this.posVertices=[],this.texVertices=[];var a=0,h=0,l=0;o/=n,s/=n;for(var c=0;c<i.length;c++){var u=i[c];if("\n"!==u){var p=t.glyphs.get(u);if(p){var d=p.width/t.bitmapFontSize;this.posVertices.push(a,h-1,a+d,h-1,a,h,a,h,a+d,h-1,a+d,h);var f=p.id%t.gridSize*t.bitmapFontSize,g=(p.id/t.gridSize|0)*t.bitmapFontSize,m=(f+r.margin.x)/t.canvas.width,y=(g+r.margin.y)/t.canvas.width,v=(f+p.width+r.spacing.x)/t.canvas.width,x=(g+t.bitmapFontSize+r.spacing.y)/t.canvas.width;this.texVertices.push(m,x,v,x,m,y,m,y,v,x,v,y),a+=d+o}}else l=Math.max(l,a),a=0,h-=1+s}this.textSize.set(Math.max(l,a)*n,Math.abs(h-1)*n)},t.prototype.setPositionFromOrientation=function(t){this.modelPosition.set(t.position.x+(t.orientation===Et.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Et.Center||t.orientation===Et.RightCenter?this.textSize.y/2:t.orientation===Et.RightUp?this.textSize.y:0))},t}(),Gt=function(){function t(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 pt,texSpacing:new pt,texWidth:0,texHeight:0,texCorrection:new pt},this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t()}return t.prototype.render=function(t,e,i){var n,r,o,s;if(0===t.culledTiles.reduce((function(t,e){return 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=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.renderPosition.x,t.renderPosition.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),jt(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=wt(this.textureMatrix),jt(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),At(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);var a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===$.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){var h=Rt(t.tintColor),l=h.r,c=h.g,u=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,l,c,u,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=Rt(t.maskColor);l=d.r,c=d.g,u=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,l,c,u,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2)},t.prototype.processTileset=function(t){var e,i,n,r,o,s,a,h=t.tileset;h.margin=null!==(e=h.margin)&&void 0!==e?e:new pt,h.spacing=null!==(i=h.spacing)&&void 0!==i?i:new pt,h.correction=null!==(n=h.correction)&&void 0!==n?n:new pt,this.tileset.width=h.width,this.tileset.tileWidth=h.tileWidth+(null!==(r=h.margin.x)&&void 0!==r?r:0)+(null!==(o=h.spacing.x)&&void 0!==o?o:0),this.tileset.tileHeight=h.tileHeight+(null!==(s=h.margin.y)&&void 0!==s?s:0)+(null!==(a=h.spacing.y)&&void 0!==a?a:0),this.tileset.texMargin.set(h.margin.x/this.tileset.tileWidth,h.margin.y/this.tileset.tileHeight),this.tileset.texSpacing.set(h.spacing.x/this.tileset.tileWidth,h.spacing.y/this.tileset.tileHeight),this.tileset.texCorrection.set(h.correction.x/this.tileset.tileWidth,h.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},t.prototype.generateVertices=function(t){var e=this,i=t.culledTiles,n=t.tilemap;this.posVertices=[],this.texVertices=[];var r=Math.floor(i.length/n.width);i.forEach((function(t,i){if(0!==t){var o=i%n.width-n.width/2,s=r/2-Math.floor(i/n.width);e.posVertices.push(o,s-1,o+1,s-1,o,s,o,s,o+1,s-1,o+1,s);var a=(t-1)%e.tileset.width+e.tileset.texMargin.x+e.tileset.texCorrection.x,h=Math.floor((t-1)/e.tileset.width)+e.tileset.texMargin.y+e.tileset.texCorrection.y;e.texVertices.push(a,h+e.tileset.texHeight,a+e.tileset.texWidth,h+e.tileset.texHeight,a,h,a,h,a+e.tileset.texWidth,h+e.tileset.texHeight,a+e.tileset.texWidth,h)}}))},t}(),kt=function(){function t(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,this.projectionMatrix=_t(),this.modelMatrix=_t(),this.textureMatrix=_t(),this.posVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.texVertices=new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0])}return t.prototype.render=function(t,e,i){var n,r,o,s;i!==t.type&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.posVertices,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.texVertices,this.gl.STATIC_DRAW)),this.modelMatrix=wt(this.modelMatrix),Ct(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),Ot(this.modelMatrix,this.modelMatrix,null!==(n=t.rotation)&&void 0!==n?n:0),jt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=wt(this.textureMatrix),t.slice&&(Ct(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),jt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),At(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);var 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){var h=Rt(t.tintColor),l=h.r,c=h.g,u=h.b,p=h.a;this.gl.uniform4f(this.programManager.tintColorUniform,l,c,u,p)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){var d=Rt(t.maskColor);l=d.r,c=d.g,u=d.b,this.gl.uniform4f(this.programManager.maskColorUniform,l,c,u,null!==(o=t.alpha)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(s=t.maskColorMix)&&void 0!==s?s:1)}this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t}(),Wt=function(){function t(t){this.gl=t}return t.prototype.createFromImage=function(t,e,i){var n=this;return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(function(){return n.createFromSource(t,i,e)})),i},t.prototype.createFromCanvas=function(t,e,i){return void 0===e&&(e=!0),void 0===i&&(i=null),i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i},t.prototype.createPixelTexture=function(){var 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},t.prototype.createFromSource=function(t,e,i){void 0===i&&(i=!0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),!1===i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST)):(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)),this.gl.bindTexture(this.gl.TEXTURE_2D,null)},t}(),Ht=function(){function t(t){this.textureFactory=t,this.textures=new Map}return t.prototype.getOrCreateTextureFromImage=function(t,e){var i;return void 0===e&&(e=!0),null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)},t.prototype.createTextureFromImage=function(t,e){void 0===e&&(e=!0);var i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i},t.prototype.getOrCreateTextureFromCanvas=function(t,e,i){var n;return void 0===i&&(i=!0),null!==(n=this.textures.get(Symbol.for(t)))&&void 0!==n?n:this.createTextureFromCanvas(t,e,i)},t.prototype.createTextureFromCanvas=function(t,e,i){void 0===i&&(i=!0);var n=this.textureFactory.createFromCanvas(e,i);return this.textures.set(Symbol.for(t),n),n},t.prototype.getOrCreateTextureFromVideo=function(t){var e;return null!==(e=this.textures.get(Symbol.for(t.src)))&&void 0!==e?e:this.createTextureFromVideo(t)},t.prototype.createTextureFromVideo=function(t){var e=this.textureFactory.createPixelTexture();return this.textures.set(Symbol.for(t.src),e),e},t}(),zt=function(){function t(t,e,i,n){this.gl=t,this.textureManager=i,this.renderers=n,e.loadProgram()}return t.prototype.render=function(t,e){try{this.renderers.get(t.type).render(t,e,this.lastRender),this.lastRender=t.type}catch(t){return}},t.prototype.clearCanvas=function(t){var e=Rt(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.createTexture=function(t,e){void 0===e&&(e=!1),this.textureManager.createTextureFromImage(t,e)},t}();!function(t){t.Image="Image",t.Audio="Audio",t.Font="Font",t.Video="Video"}(Ft||(Ft={}));var Nt,Yt=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,Ft.Image,n),o=function(){e&&i.renderManager.preloadTexture(n),r.loaded=!0};return n.naturalWidth?o():n.addEventListener("load",o),n},t.prototype.loadAudio=function(t){var e=new Audio;e.src=t;var i=this.createAsset(t,Ft.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,Ft.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,Ft.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===Ft.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===Ft.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===Ft.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===Ft.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}(),Xt=function(t){function e(e){var i=t.call(this,e)||this;return i.name="AngryPixelException",i}return N(e,t),e}(Error),qt=function(){function t(t,e,i){if(this._canvas=null,!t)throw new Xt("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}(),Kt=function(){function t(t){this.container=t,this.gameObjects=[],this.lastId=0}return t.prototype.addGameObject=function(t,e,i,n){var r=new t(this.container,++this.lastId,n,i);return this.gameObjects.push(r),r.dispatch(Y.Init,e),r},t.prototype.findGameObjects=function(t){return t?this.gameObjects.filter((function(e){return e instanceof t})):q([],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(Y.Destroy)}},t.prototype.destroyChildren=function(t){var e=this;this.findGameObjectsByParent(t).forEach((function(t){return e.destroyGameObject(t)}))},t}(),Qt=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=[],this.changingScene=!1,this.sceneEvents=[Y.Start,Y.Update,Y.StopGame],this.gameObjectEvents=[Y.Start,Y.Update]}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.dispatchFrameEvent(Y.StopGame),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.sceneManager.pendingSceneToload()&&(this.sceneManager.loadPendingScene(),this.changingScene=!1),this.load(),this.dispatchFrameEvent(Y.Start),this.dispatchFrameEvent(Y.Update),this.dispatchFrameEvent(Y.UpdateEngine),this.dispatchFrameEvent(Y.UpdateTransform),this.timeManager.gameFramerate===this.timeManager.physicsFramerate&&(this.timeManager.updateForPhysics(t),this.physicsIteration()),this.sceneManager.pendingSceneToload()&&(this.changingScene=!0,this.sceneManager.unloadCurrentScene())},t.prototype.physicsIteration=function(){this.timeManager.timeScale<=0||this.changingScene||(this.dispatchFrameEvent(Y.UpdatePhysics),this.dispatchFrameEvent(Y.UpdateCollider),this.dispatchFrameEvent(Y.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(){var t=this;this.loadedScene=this.sceneManager.getLoadedScene(),this.gameObjects=this.gameObjectManager.findGameObjects().filter((function(t){return t.active})),this.components=[],this.gameObjects.forEach((function(e){return e.getComponents().filter((function(t){return t.active})).forEach((function(e){return t.components.push(e)}))}))},t.prototype.dispatchFrameEvent=function(t){this.sceneEvents.includes(t)&&this.loadedScene.dispatch(t),this.gameObjectEvents.includes(t)&&this.gameObjects.forEach((function(e){e.active&&e.dispatch(t)})),this.components.forEach((function(e){e.active&&e.dispatch(t)}))},t}(),$t=function(){function t(t,e){this.container=t,this.renderManager=e,this.scenes=new Map,this.sceneNamePendingToLoad=null}return t.prototype.addScene=function(t,e,i,n){var r=this;if(void 0===n&&(n=!1),this.scenes.has(e))throw new Xt("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(Y.Init,i),n})),!n&&this.openingSceneName||(this.openingSceneName=e)},t.prototype.loadScene=function(t){if(!1===this.scenes.has(t))throw new Xt("Scene with name ".concat(t," does not exists"));this.sceneNamePendingToLoad=t},t.prototype.getLoadedScene=function(){return this.currentScene},t.prototype.loadOpeningScene=function(){if(null===this.openingSceneName)throw new Xt("There is no opening scene");this.scenes.get(this.openingSceneName)()},t.prototype.pendingSceneToload=function(){return null!==this.sceneNamePendingToLoad},t.prototype.loadPendingScene=function(){this.sceneNamePendingToLoad&&(this.scenes.get(this.sceneNamePendingToLoad)(),this.sceneNamePendingToLoad=null)},t.prototype.unloadCurrentScene=function(){this.currentScene&&(this.currentScene.dispatch(Y.Destroy),this.currentScene=void 0)},t}(),Jt=[60,120,180,240],Zt=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,!Jt.includes(t))throw new Xt("Invalid Physics frame rate. Allowed: [".concat(Jt.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}(),te=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 Xt("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 Xt("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 Xt("Invalid object constructor name: ".concat(t));return this.constructors.get(t)()},t.prototype.addConstant=function(t,e){if(this.constants.has(t))throw new Xt("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 Xt("Invalid constant name: ".concat(t));return this.constants.get(t)},t}(),ee={containerNode:void 0,gameWidth:320,gameHeight:180,debugEnabled:!1,canvasColor:"#000000",physicsFramerate:180,headless:!1,spriteDefaultScale:new t(1,1),collisions:{collisionMethod:O.SAT,collisionBroadPhaseMethod:x.SpartialGrid}},ie=function(){function t(t){this._config=X(X({},ee),t),this._config.collisions=X(X({},ee.collisions),t.collisions),this.container=new te,this.container.addConstant("Game",this),this.setupManagers()}return t.prototype.setupManagers=function(){(function(t,e){if(t.addConstant("GameConfig",e),t.add("TimeManager",(function(){return new Zt(e.physicsFramerate)})),t.add("GameObjectManager",(function(){return new Kt(t)})),t.add("PhysicsManager",(function(){return function(t){var e=void 0===t?{}:t,i=e.collisionArea,n=e.collisionMatrix,r=e.collisionMethod,o=e.collisionBroadPhaseMethod,s=new E,a=r===O.AABB?new P(new A,new S,s):new R(s,new B),h=new j(a,o,i,n),l=new b,c=new V(h),u=new I;return new U(h,l,c,u)}(e.collisions)})),e.headless)t.add("IterationManager",(function(){return new Qt(t.getSingleton("TimeManager"),t.getSingleton("PhysicsManager"),t.getSingleton("GameObjectManager"),t.getSingleton("SceneManager"))}));else{t.add("DomManager",(function(){return new qt(e.containerNode,e.gameWidth,e.gameHeight)}));var i=t.getSingleton("DomManager").canvas;t.add("RenderManager",(function(){return function(t){var e=new gt(t),i=e.gl,n=e.contextVersion,r=new xt(i,n,new vt(i,new bt(i))),o=new Ht(new Wt(i)),s=new zt(i,r,o,new Map([[$.Sprite,new Dt(i,r,o)],[$.Text,new Vt(i,r,o,new mt)],[$.Tilemap,new Gt(i,r,o)],[$.Geometric,new St(i,r)],[$.Mask,new Tt(i,r)],[$.Video,new kt(i,r,o)]]));return new ft(s,new ht(i))}(i)})),t.add("InputManager",(function(){return function(t){return new p(new f(t),new d(t),new c,new g(t))}(i)})),t.add("AssetManager",(function(){return new Yt(t.getSingleton("RenderManager"))})),t.add("IterationManager",(function(){return new J(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 $t(t,e.headless?void 0:t.getSingleton("RenderManager"))}))})(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){this.sceneManager.addScene(t,e,"object"==typeof i?i:void 0,"boolean"==typeof i?i:null!=n&&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}(),ne=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 N(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}(rt),re=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 N(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){for(var e=0,i=this.colliders;e<i.length;e++){var n=i[e];if(this.physicsManager.getCollisionsForColliderAndLayer(n,t).length>0)return!0}return!1},e.prototype.collidesWithLayers=function(t,e){void 0===e&&(e="or");for(var i=0,n=0,r=this.colliders;n<r.length;n++)for(var o=r[n],s=0,a=this.physicsManager.getCollisionsForCollider(o);s<a.length;s++){var h=a[s];if(t.includes(h.remoteCollider.layer)){if("or"===e)return!0;i++}}return"and"===e&&i===t.length},e.prototype.getCollisionWithLayer=function(t){for(var e=0,i=this.colliders;e<i.length;e++){var n=i[e],r=this.physicsManager.getCollisionsForColliderAndLayer(n,t);if(r.length>0)return this.createCollisionData(r[0])}return null},e.prototype.getCollisionsWithLayer=function(t){for(var e=this,i=[],n=0,r=this.colliders;n<r.length;n++){var o=r[n];this.physicsManager.getCollisionsForColliderAndLayer(o,t).forEach((function(t){return i.push(e.createCollisionData(t))}))}return i},e.prototype.getCollisionsWithLayers=function(t){for(var e=[],i=0,n=this.colliders;i<n.length;i++)for(var r=n[i],o=0,s=this.physicsManager.getCollisionsForCollider(r);o<s.length;o++){var a=s[o];t.includes(a.remoteCollider.layer)&&e.push(this.createCollisionData(a))}return e},e.prototype.createCollisionData=function(t){return{gameObject:this.gameObjectManager.findGameObjectById(Number(t.remoteCollider.group)),collider:t.remoteCollider,resolution:t.resolution,getGameObject:function(){return this.gameObject},localCollider:t.localCollider}},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}(it),oe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMultiple=!1,t}return N(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}),Object.defineProperty(i.prototype,"rigidBodyType",{get:function(){return this.rigidBody.type},enumerable:!1,configurable:!0}),i.prototype.init=function(e){var i,n=e.rigidBodyType,r=e.gravity;if(0===this.getColliderIds().length)throw new Xt("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 Xt("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 re&&t.physics})).reduce((function(t,e){return q(q([],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}(et),se="Default",ae=function(t){function e(e,i,n,r){void 0===n&&(n=""),void 0===r&&(r=null);var o=t.call(this,e)||this;return o.layer="Default",o.ui=!1,o.keep=!1,o._parent=null,o._active=!0,o.components=[],o.activeComponentsCache=[],o.activeChildrenCache=[],o.id=i,o.name=n,o.addComponent(ne),r&&(o.transform.position=r.transform.position,o.parent=r),o}return N(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(ne)},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.getLoadedScene()},e.prototype.addComponent=function(t,e,i){var n="string"==typeof e?void 0:e,r="string"==typeof e?e:i,o=new t(this.container,this,r);return this.checkMultipleComponent(o,t),this.components.push(o),o.dispatch(Y.Init,n),o},e.prototype.checkMultipleComponent=function(t,e){if(!1===t.allowMultiple&&this.hasComponent(e))throw new Xt("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(Y.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(Y.Destroy),delete this.components[t];this.components=[]},e.prototype._stopGame=function(){},e}(Z),he=["Default"],le=function(i){function n(){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=he,t._zoom=1,t}return N(n,i),Object.defineProperty(n.prototype,"zoom",{get:function(){return this._zoom},set:function(t){if(this.zoom<=0)throw new Xt("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.canvas=this.domManager.canvas,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}(st),ce=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return N(e,t),e.prototype.init=function(){this.transform.position.set(0,0),this.camera=this.addComponent(le)},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}(ae),ue=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(ce),r}return N(e,t),Object.defineProperty(e.prototype,"gameCamera",{get:function(){return this.findGameObject(ce)},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}(Z),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 N(i,e),i.prototype.init=function(e){var i,n,r,o,s,a;if(this.gameConfig.collisions.collisionMethod!==O.SAT)throw new Xt("Polygon Colliders need SAT collision method.");if(e.vertexModel.length<3)throw new Xt("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!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(o=e.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(s=e.rotation)&&void 0!==s?s: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 W(this.scaledVertexModel),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(de,{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}(re),de=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return N(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:$.Geometric,location:Q.WorldSpace,layer:this.gameObject.layer,position:new t,shape:K.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}(at),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.realWidth=0,i.realHeight=0,i.realOffset=new t,i.realPosition=new t,i.realRotation=0,i.applyRotation=i.gameConfig.collisions.collisionMethod===O.SAT,i.innerPosition=new t,i}return N(i,e),i.prototype.init=function(t){var e,i,n,r,o,s;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.gameConfig.debugEnabled,this.rotation=null!==(o=t.rotation)&&void 0!==o?o:new h,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(),rotation:this.rotation.radians,shape:new H(this.realWidth,this.realHeight),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(de,{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}(re),ge=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 N(i,e),i.prototype.init=function(t){var e,i,n,r,o;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.gameConfig.debugEnabled,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(),shape:new G(this.radius),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()})),this.debug&&(this.renderer=this.gameObject.addComponent(me,{collider:this.colliders[0]}))},i.prototype.updateRealSize=function(){this.realRadius=this.radius*Math.max(Math.abs(this.gameObject.transform.scale.x),Math.abs(this.gameObject.transform.scale.y)),this.realOffset.x=this.offsetX*this.gameObject.transform.scale.x,this.realOffset.y=this.offsetY*this.gameObject.transform.scale.y},i.prototype.updatePosition=function(){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}(re),me=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return N(i,e),i.prototype.init=function(e){var i=e.collider;this.renderData={type:$.Geometric,location:Q.WorldSpace,layer:this.gameObject.layer,position:new t,shape:K.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}(at),ye=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.debug=!1,i.position=new t,i}return N(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.scaledWidth/2,this.gameObject.transform.position.y+this.scaledHeight/2),this.composite?this.useLineColliders():this.useBoxColliders(),this.debug&&(this.renderer=this.gameObject.addComponent(ve,{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 H(e.scaledTileWidth,e.scaledTileHeight),updateCollisions:!1,physics:e.physics,group:e.gameObject.id.toString()}))}))},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=[],o=[];this.tilemapRenderer.tiles.forEach((function(t,e){if(0!==t){var i=e%n.tilemapRenderer.width,s=Math.floor(e/n.tilemapRenderer.width);r[s]||(r[s]=[]),r[s+1]||(r[s+1]=[]),o[s]||(o[s]=[]),o[s+1]||(o[s+1]=[]);var a=n.getNeighbors(e);n.hasTile(a[0])||(r[s][i]=!0),n.hasTile(a[2])||(r[s+1][i]=!0),n.hasTile(a[1])||(o[s][i]=!0),n.hasTile(a[3])||(o[s][i+1]=!0)}}));for(var s=0;s<r.length;s++)if(r[s])for(var a=0;a<r[s].length;a++)!e||!i||s===i.y&&r[s][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),r[s][a]&&(e||(e=new t(a,s)),i=new t(a+1,s));for(e&&i&&this.addLineCollider(e,i),e=void 0,i=void 0,a=0;a<=this.tilemapRenderer.width;a++)for(s=0;s<o.length;s++)o[s]&&(!e||!i||a===i.x&&o[s][a]||(this.addLineCollider(e,i),e=void 0,i=void 0),o[s][a]&&(e||(e=new t(a,s)),i=new t(a,s+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 k([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.toString()});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}(re),ve=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderData=[],t.colliders=[],t}return N(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:$.Geometric,layer:i.gameObject.layer,location:Q.WorldSpace,position:new t,shape:K.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}(at),xe=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 N(i,e),i.prototype.init=function(e){var i,n,r,o,s,a;if(this.gameConfig.collisions.collisionMethod!==O.SAT)throw new Xt("Edge Colliders need SAT collision method.");if(e.vertexModel.length<2)throw new Xt("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!==(n=e.offsetX)&&void 0!==n?n:this.offsetX,this.offsetY=null!==(r=e.offsetY)&&void 0!==r?r:this.offsetY,this.physics=null!==(o=e.physics)&&void 0!==o?o:this.physics,this.rotation=null!==(s=e.rotation)&&void 0!==s?s: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 k([this.scaledVertexModel[l],this.scaledVertexModel[l+1]]),updateCollisions:!0,physics:this.physics,group:this.gameObject.id.toString()}));this.debug&&(this.renderer=this.gameObject.addComponent(be,{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}(re),be=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.renderData=[],t.colliders=[],t}return N(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:$.Geometric,layer:i.gameObject.layer,location:Q.WorldSpace,position:new t,shape:K.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}(at),Me=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.renderData=[],i.innerPosition=new t,i.cachePosition=new t,i.cacheRenderPosition=new t,i.scaledOffset=new t,i.cacheScale=new t,i}return N(i,e),i.prototype.init=function(e){var i,n,r,o,s,a,l,c,u;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!==(o=e.flipVertical)&&void 0!==o&&o,this.opacity=null!==(s=e.opacity)&&void 0!==s?s: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,this.scale=null!==(u=null!==(c=e.scale)&&void 0!==c?c:this.gameConfig.spriteDefaultScale.clone())&&void 0!==u?u:new t(1,1),this.width=e.width,this.height=e.height},Object.defineProperty(i.prototype,"tiled",{get:function(){return this._tiled},set:function(t){if(t.x%1!=0||t.y%1!=0)throw new Xt("SpriteRenderer.tiled: Vector2 components must be integers");this._tiled.set(t.x,t.y)},enumerable:!1,configurable:!0}),i.prototype.update=function(){if(this.sprite&&!0===this.sprite.loaded){this.cacheScale.set(this.scale.x*this.gameObject.transform.scale.x,this.scale.y*this.gameObject.transform.scale.y),this.updateRenderDataArray();for(var t=0,e=0;e<this._tiled.x;e++)for(var i=0;i<this._tiled.y;i++)this.updateRenderData(t,e,i),t++}},i.prototype.updateRenderDataArray=function(){if(this.renderData.length!==this._tiled.x*this._tiled.y){this.renderData=[];for(var e=0;e<this._tiled.x*this._tiled.y;e++)this.renderData[e]={type:$.Sprite,location:Q.WorldSpace,layer:"",position:new t,image:this.sprite.image,width:0,height:0}}},i.prototype.updateRenderData=function(t,e,i){var n,r,o;this.renderData[t].location=this.gameObject.ui?Q.ViewPort:Q.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=(null!==(r=this.width)&&void 0!==r?r:this.sprite.width)*Math.abs(this.cacheScale.x),this.renderData[t].height=(null!==(o=this.height)&&void 0!==o?o:this.sprite.height)*Math.abs(this.cacheScale.y),this.renderData[t].slice=this.sprite.slice,this.renderData[t].flipHorizontal=this.flipHorizontal!==this.cacheScale.x<0,this.renderData[t].flipVertical=this.flipVertical!==this.cacheScale.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}(at),_e=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.lastFrameText="",t}return N(i,e),i.prototype.init=function(e){var i,n,r,o,s,a,l,c,u,p,d,f,g;if(this.text=null!==(i=e.text)&&void 0!==i?i:"",this.font=null!==(n=e.font)&&void 0!==n?n:"Sans",this.fontSize=null!==(r=e.fontSize)&&void 0!==r?r:12,this.width=null!==(o=e.width)&&void 0!==o?o:100,this.height=null!==(s=e.height)&&void 0!==s?s:100,this.offset=null!==(a=e.offset)&&void 0!==a?a:new t,this.color=null!==(l=e.color)&&void 0!==l?l:"#000000",this.charRanges=null!==(c=e.charRanges)&&void 0!==c?c:[32,126,161,255],this.lineSeparation=null!==(u=e.lineSeparation)&&void 0!==u?u:0,this.letterSpacing=null!==(p=e.letterSpacing)&&void 0!==p?p:0,this.smooth=null!==(d=e.smooth)&&void 0!==d&&d,this.rotation=null!==(f=e.rotation)&&void 0!==f?f: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 Xt("TextRenderer.charRanges must be a 2 column matrix");if(this.lineSeparation%2!=0)throw new Xt("TextRenderer.lineSeparation must be multiple of 2")},i.prototype.start=function(){this.renderData={type:$.Text,location:Q.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?Q.ViewPort:Q.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=this;if(this.fontSize>this.height)return"";for(var e=[],i=0,n=0,r=this.text.split("\n");n<r.length;n++)for(var o=r[n].split(" ").reduce((function(e,i){var n=e[e.length-1]+(e[e.length-1].length>0?" ":"")+i;return n.length*(t.fontSize+t.letterSpacing)>t.width?e.push(i):e[e.length-1]=n,e}),[""]),s=0,a=o;s<a.length;s++){var h=a[s];if((i+=this.fontSize+this.lineSeparation)>this.height)return e.join("\n");e.push(h)}return e.join("\n")},i}(at),we=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 N(i,e),i.prototype.init=function(e){var i,n,r,o,s,a,h;this.shape=e.shape,this.color=e.color,this.width=null!==(i=e.width)&&void 0!==i?i:0,this.height=null!==(n=e.height)&&void 0!==n?n:0,this.radius=null!==(r=e.radius)&&void 0!==r?r:0,this.offset=null!==(o=e.offset)&&void 0!==o?o:this.offset,this.rotation=null!==(s=e.rotation)&&void 0!==s?s:this.rotation,this.opacity=null!==(a=e.opacity)&&void 0!==a?a:this.opacity,this.layer=e.layer,this.renderData={type:$.Mask,layer:null!==(h=this.layer)&&void 0!==h?h:this.gameObject.layer,location:this.gameObject.ui?Q.ViewPort:Q.WorldSpace,position:new t,width:0,height:0,radius:0,color:"",shape:this.shape}},i.prototype.update=function(){var t;this.renderData.location=this.gameObject.ui?Q.ViewPort:Q.WorldSpace,this.renderData.layer=null!==(t=this.layer)&&void 0!==t?t:this.gameObject.layer,this.renderData.shape=this.shape,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.renderData.radius=this.radius*Math.abs(Math.max(this.gameObject.transform.scale.x,this.gameObject.transform.scale.y)),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}(at),Ce=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"],je=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(){Ce.forEach((function(t){window.removeEventListener(t,i.userInputEventHandler)})),i.video&&i._playing&&i.video.play()},i}return N(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,o,s,a,l,c,u,p;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!==(o=e.rotation)&&void 0!==o?o:new h,this.flipHorizontal=null!==(s=e.flipHorizontal)&&void 0!==s&&s,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!==(u=e.volume)&&void 0!==u?u:1,this._loop=null!==(p=e.loop)&&void 0!==p&&p,this.renderData={type:$.Video,location:Q.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(){Ce.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?Q.ViewPort:Q.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}(at),Oe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.tiles=[],t.infinite=!1,t.tilesetTileIds=[],t.chunks=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t.renderData=[],t}return N(i,e),i.prototype.init=function(t){var e=this,i=t.tiledData,n=t.tilemapLayer,r=t.tileset,o=t.tileWidth,s=t.tileHeight,a=t.layer,h=t.smooth;if(this.tiledData=i,this.tileset=r,this.tileWidth=null!=o?o:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=s?s:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=a,this.smooth=null!=h&&h,this.tiledLayer=this.tiledData.layers.find((function(t){return"tilelayer"===t.type&&t.name===n})),!this.tiledLayer)throw new Xt("Invalid tilemap layer");this.width=0,this.height=0,this.tiledData.layers.forEach((function(t){"tilelayer"===t.type&&(e.width=Math.max(e.width,t.width),e.height=Math.max(e.height,t.height))})),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;!0===this.tiledLayer.visible&&(this.opacity=this.tiledLayer.opacity,this.tintColor=this.tiledLayer.tintcolor,this.tiledData.infinite?(this.infinite=!0,this.tiledLayer.chunks.sort((function(t,e){return t.x-e.x})).sort((function(t,e){return t.y-e.y})).forEach((function(e){return t.processChunk(e)}))):this.processFixedLayer()),this.updateRenderData(),this.tilesetTileIds=[]},i.prototype.processFixedLayer=function(){var e,i=this;this.tiles=this.tiledLayer.data.map((function(t){return i.getTilesetTileId(t)})),this.renderData.push({type:$.Tilemap,layer:null!==(e=this.layer)&&void 0!==e?e:this.gameObject.layer,location:this.gameObject.ui?Q.ViewPort:Q.WorldSpace,position:new t,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:ut.Center,smooth:this.smooth})},i.prototype.processChunk=function(e){var i,n=this,r={type:$.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?Q.ViewPort:Q.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:ut.Center,smooth:this.smooth};r.tiles.forEach((function(t,i){n.tiles[n.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.width*this.scaledTileWidth,this.realHeight=this.height*this.scaledTileHeight,this.renderData.forEach((function(e,i){var n;if(e.layer=null!==(n=t.layer)&&void 0!==n?n:t.gameObject.layer,t.infinite){var r=t.chunks[i];e.position.set(t.gameObject.transform.position.x-t.realWidth/2+(r.x+r.width/2)*t.scaledTileWidth,t.gameObject.transform.position.y+t.realHeight/2-(r.y+r.height/2)*t.scaledTileHeight)}else e.position.copy(t.gameObject.transform.position);e.tilemap.tileWidth=t.scaledTileWidth,e.tilemap.tileHeight=t.scaledTileHeight,e.tintColor=t.tintColor,e.alpha=t.opacity}))},i}(at),Pe=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.tiles=[],t.scaledTileWidth=0,t.scaledTileHeight=0,t}return N(i,e),i.prototype.init=function(e){var i,n=this,r=e.tiles,o=e.tileset,s=e.tileWidth,a=e.tileHeight,h=e.width,l=e.layer,c=e.opacity,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=o,this.width=h,this.tileWidth=null!=s?s:this.tileset.tileWidth*this.gameConfig.spriteDefaultScale.x,this.tileHeight=null!=a?a:this.tileset.tileHeight*this.gameConfig.spriteDefaultScale.y,this.layer=l,this.height=Math.ceil(this.tiles.length/this.width),this.opacity=c,this.tintColor=u,this.renderData={type:$.Tilemap,layer:null!==(i=this.layer)&&void 0!==i?i:this.gameObject.layer,location:this.gameObject.ui?Q.ViewPort:Q.WorldSpace,position:new t,tileset:this.tileset,tilemap:{width:this.width,tileWidth:this.tileWidth,tileHeight:this.tileHeight},tiles:this.tiles,orientation:ut.Center,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.opacity,this.renderData.tilemap.tileWidth=this.scaledTileWidth,this.renderData.tilemap.tileHeight=this.scaledTileHeight},i}(at),Re=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 N(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 Ae(t)),this},e.prototype.playAnimation=function(t){if(void 0===t&&(t="default"),!1!==this.active){if(!1===this.animations.has(t))throw new Xt("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,this.paused=!1)},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}(et),Ae=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}(),Se=["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(){Se.forEach((function(t){window.removeEventListener(t,e.userInputEventHandler)})),e.audioContext.resume(),e._audioSource&&e._playing&&e._audioSource.play()},e}return N(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&&Se.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}(et),Te=function(){function t(t){var e,i=this;this._width=null,this._height=null,this._loaded=!1,this.image=t.image,this.smooth=null!==(e=t.smooth)&&void 0!==e&&e,this.slice=t.slice,this.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(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaded",{get:function(){return this._loaded},enumerable:!1,configurable:!0}),t}();!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(Nt||(Nt={}));var De=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 N(i,e),i.prototype.init=function(t){var e=t.type,i=t.height,n=t.radius,r=t.touchEnabled,o=t.width,s=t.offset;this.type=e,this.width=null!=o?o:this.width,this.height=null!=i?i:this.height,this.radius=null!=n?n:this.radius,this.touchEnabled=null!=r?r:this.touchEnabled,this.offset=null!=s?s:this.offset},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===Nt.Rectangle&&(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===Nt.Circumference&&(t.subtract(this.distance,this.position,this.mouse.positionInViewport),this.pressed=this.distance.magnitude<=this.scaled.radius)},i.prototype.resolveTouchAndRectangle=function(){if(this.type===Nt.Rectangle)for(var t=0,e=this.touch.interactions;t<e.length;t++){var i=e[t],n=i.positionInViewport,r=i.radius;if(this.pressed)return;this.pressed=this.position.x+this.scaled.width/2>=n.x-r.x&&this.position.x-this.scaled.width/2<=n.x+r.x&&this.position.y+this.scaled.height/2>=n.y-r.y&&this.position.y-this.scaled.height/2<=n.y+r.y}},i.prototype.resolveTouchAndCircumference=function(){if(this.type===Nt.Circumference)for(var e=0,i=this.touch.interactions;e<i.length;e++){var n=i[e],r=n.positionInViewport,o=n.radius;if(this.pressed)return;t.subtract(this.distance,this.position,r),this.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(o.x,o.y)}},i}(et),Fe=function(e){function i(){var i=null!==e&&e.apply(this,arguments)||this;return i.mousePressed=!1,i.position=new t,i}return N(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}(ae);export{Re as Animator,Ee as AudioPlayer,ge as BallCollider,fe as BoxCollider,x as BroadPhaseMethods,De as Button,Nt as ButtonType,le as Camera,O as CollisionMethods,tt as Component,xe as EdgeCollider,ie as Game,ce as GameCamera,ae as GameObject,c as GamepadController,u as GamepadData,d as KeyboardController,se as LAYER_DEFAULT,we as MaskRenderer,Pt as MaskShape,f as MouseController,nt as PhysicsComponent,pe as PolygonCollider,de as PolygonColliderRenderer,ot as PreRenderComponent,e as Rectangle,oe as RigidBody,F as RigidBodyType,h as Rotation,ue as Scene,Fe as SpacePointer,Te as Sprite,Me as SpriteRenderer,Et as TextOrientation,_e as TextRenderer,Oe as TiledTilemapRenderer,ye as TilemapCollider,Pe as TilemapRenderer,g as TouchController,ne as Transform,t as Vector2,je as VideoRenderer,a as between,i as clamp,o as fixedRound,r as randomFloat,n as randomInt,s as range};
1
+ const t={AssetManager:Symbol.for("AssetManager"),CanvasElement:Symbol.for("CanvasElement"),CollisionRepository:Symbol.for("CollisionRepository"),CollisionBroadphaseResolver:Symbol.for("CollisionBroadphaseResolver"),CollisionResolutionMethod:Symbol.for("CollisionResolutionMethod"),CollisionAABBResolver:Symbol.for("CollisionAABBResolver"),CollisionCircumferenceAABBResolver:Symbol.for("CollisionCircumferenceAABBResolver"),CollisionCircumferenceResolver:Symbol.for("CollisionCircumferenceResolver"),CollisionSatResolver:Symbol.for("CollisionSatResolver"),CollisionMatrix:Symbol.for("CollisionMatrix"),EntityManager:Symbol.for("EntityManager"),GameConfig:Symbol.for("GameConfig"),InputManager:Symbol.for("InputManager"),LoopManager:Symbol.for("LoopManager"),RenderManager:Symbol.for("RenderManager"),SceneManager:Symbol.for("SceneManager"),SystemFactory:Symbol.for("SystemFactory"),SystemManager:Symbol.for("SystemManager"),TimeManager:Symbol.for("TimeManager"),WebGLManager:Symbol.for("WebGLManager")};class e{constructor(){this.instances=new Map,this.types=new Map}add(t,e){if(!e&&!t.prototype.__ioc_injectable)throw new Error(`Type ${t.name} is not injectable`);return this.types.set(null!=e?e:t.prototype.__ioc_injectable,t),this}set(t,e){return this.instances.set(t,e),this}get(t){var e,i;if(!this.instances.has(t)){const s=this.types.get(t);if(!s)throw new Error(`${t.toString()} is not a valid type`);const o=new s(...(null!==(e=s.prototype.__ioc_inject_constructor)&&void 0!==e?e:[]).map((t=>this.get(t))));(null!==(i=s.prototype.__ioc_inject_prop)&&void 0!==i?i:[]).forEach((([t,e])=>o[t]=this.get(e))),this.instances.set(t,o)}return this.instances.get(t)}has(t){return this.types.has(t)||this.instances.has(t)}}function i(t){return function(e){e.prototype.__ioc_injectable&&e.prototype.__ioc_injectable===t||(e.prototype.__ioc_injectable=t)}}function s(t){return function(e,i,s){void 0!==s?(e.prototype.__ioc_inject_constructor||(e.prototype.__ioc_inject_constructor=[]),e.prototype.__ioc_inject_constructor[s]=t):void 0!==i&&(e.constructor.prototype.__ioc_inject_prop||(e.constructor.prototype.__ioc_inject_prop=[]),e.constructor.prototype.__ioc_inject_prop.push([i,t]))}}var o;function r(t,e,i,s){var o,r=arguments.length,a=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(o=t[n])&&(a=(r<3?o(a):r>3?o(e,i,a):o(e,i))||a);return r>3&&a&&Object.defineProperty(e,i,a),a}function a(t,e){return function(i,s){e(i,s,t)}}!function(t){t[t.QuadTree=0]="QuadTree",t[t.SpartialGrid=1]="SpartialGrid"}(o||(o={})),"function"==typeof SuppressedError&&SuppressedError;class n{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))}get direction(){return this._direction||(this._direction=new n),n.unit(this._direction,this)}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 n(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 h{constructor(t=0,e=0,i=0,s=0){this.width=0,this.height=0,this._position=new n,this._center=new n,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 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 h?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof n&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}}const l=(t,e,i)=>Math.min(i,Math.max(e,t)),c=(t,e)=>Math.round(Math.random()*(e-t))+t,d=(t,e,i=2)=>m(Math.random()*(e-t)+t,i),m=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),g=(t,e,i=1)=>{const s=[];for(let o=t;o<=e;o+=i)s.push(o);return s},u=(t,e,i)=>t>=e&&t<=i;var p;let y=p=class{constructor(t=new h,e=0){this.children=[],this.shapes=[],this.minArea=new n,this.maxArea=new n,this.area=t,this.depth=e}clear(){this.shapes=[],this.children=[]}update(t){this.clear(),this.resizeArea(t),t.forEach((({id:t,boundingBox:e})=>this.insert(t,e)))}resizeArea(t){this.minArea.set(0,0),this.maxArea.set(0,0),t.forEach((({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.area.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}retrieve(t){const e=[];return this.children.length>0?this.getChildrenForBox(t).forEach((i=>e.push(...i.retrieve(t).filter((t=>!e.includes(t)))))):this.shapes.forEach((t=>e.push(t[0]))),e}insert(t,e){0===this.children.length&&this.shapes.length>16&&this.depth<8&&this.split(),this.children.length>0?this.insertItemIntoChildren(t,e):this.shapes.push([t,e])}split(){const t=this.area.width/2,e=this.area.height/2;this.children=[new h(this.area.x,this.area.y,t,e),new h(this.area.x,this.area.y+e,t,e),new h(this.area.x+t,this.area.y+e,t,e),new h(this.area.x+t,this.area.y,t,e)].map((t=>new p(t,this.depth+1))),this.shapes.forEach((t=>this.insertItemIntoChildren(t[0],t[1]))),this.shapes=[]}insertItemIntoChildren(t,e){this.getChildrenForBox(e).forEach((i=>i.insert(t,e)))}getChildrenForBox(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}};y=p=r([i(t.CollisionBroadphaseResolver)],y);const f=(t,e,i,s)=>Math.min((t-e)/i|0,s-1);let x=class{constructor(){this.area=new h,this.colliders=[],this.subdivisions=0,this.coordinates={x0:0,x1:0,y0:0,y1:0},this.minArea=new n,this.maxArea=new n}clear(){for(let t=0;t<this.subdivisions;t++)for(let e=0;e<this.subdivisions;e++)this.colliders[t][e]=[]}update(t){this.resizeArea(t),this.updateSubdivisions(t.length),t.forEach((({id:t,boundingBox:e})=>this.insert(t,e)))}resizeArea(t){this.minArea.set(0,0),this.maxArea.set(0,0),t.forEach((({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.area.set(this.minArea.x,this.minArea.y,this.maxArea.x-this.minArea.x,this.maxArea.y-this.minArea.y)}updateSubdivisions(t){this.subdivisions=1+(t/10|0),this.cellWidth=Math.ceil(this.area.width/this.subdivisions),this.cellHeight=Math.ceil(this.area.height/this.subdivisions),this.colliders=[];for(let t=0;t<this.subdivisions;t++){this.colliders[t]=[];for(let e=0;e<this.subdivisions;e++)this.colliders[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.colliders[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.colliders[t][i].forEach((t=>e.includes(t)?void 0:e.push(t)));return e}updateCoordinates(t){this.coordinates.x0=f(t.x,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.x1=f(t.x1,this.area.x,this.cellWidth,this.subdivisions),this.coordinates.y0=f(t.y,this.area.y,this.cellHeight,this.subdivisions),this.coordinates.y1=f(t.y1,this.area.y,this.cellHeight,this.subdivisions)}};x=r([i(t.CollisionBroadphaseResolver)],x);class M{get vertexModel(){return this._vertexModel}set vertexModel(t){if(this._vertexModel=t,2===t.length)return this.vertices=[new n,new n],void(this.projectionAxes=[new n]);this.vertices=[],this.projectionAxes=[],this._vertexModel.forEach((()=>{this.vertices.push(new n),this.projectionAxes.push(new n)}))}constructor(t,e=0){this.rotation=e,this.boundingBox=new h,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new n,this.projectionAxes=[],this.radius=0,this.vertices=[],this.updateCollisions=!0,this._vertexModel=[],this.vertexModel=t}}class v{constructor(t){this.radius=t,this.boundingBox=new h,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new n,this.projectionAxes=[new n],this.rotation=0,this.vertexModel=[],this.vertices=[new n,new n],this.updateCollisions=!0}}let S=class{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}findCollision(t,e){return t instanceof M&&e instanceof M?this.AABBResolver.resolve(t,e):t instanceof v&&e instanceof M?this.circumferenceAABBResolver.resolve(t,e):t instanceof M&&e instanceof v?this.circumferenceAABBResolver.resolve(e,t,!0):t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):void 0}};var C;S=r([i(t.CollisionResolutionMethod),a(0,s(t.CollisionAABBResolver)),a(1,s(t.CollisionCircumferenceAABBResolver)),a(2,s(t.CollisionCircumferenceResolver))],S),function(t){t[t.AABB=0]="AABB",t[t.SAT=1]="SAT"}(C||(C={}));let b=class{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}findCollision(t,e){return t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}};b=r([i(t.CollisionResolutionMethod),a(0,s(t.CollisionCircumferenceResolver)),a(1,s(t.CollisionSatResolver))],b);let w=class{constructor(){this.direction=new n,this.resolutionDirection=new n}resolve({boundingBox:t},{boundingBox:e}){if(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))return 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.resolutionDirection.set(0,this.direction.y)):(this.minOverlap=this.overlapX,this.resolutionDirection.set(this.direction.x,this.overlapY===this.overlapX?this.direction.y:0)),{direction:n.unit(new n,this.resolutionDirection),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}}};w=r([i(t.CollisionAABBResolver)],w);let _=class{constructor(){this.closestPoint=new n,this.distance=new n,this.direction=new n}resolve(t,e,i=!1){if(this.closestPoint.set(l(t.position.x,e.boundingBox.x,e.boundingBox.x1),l(t.position.y,e.boundingBox.y,e.boundingBox.y1)),n.subtract(this.distance,this.closestPoint,t.position),!(this.distance.magnitude>t.radius))return n.unit(this.direction,this.distance),{direction:i?n.scale(new n,this.direction,-1):this.direction.clone(),penetration:t.radius-this.distance.magnitude}}};_=r([i(t.CollisionCircumferenceAABBResolver)],_);let E=class{constructor(){this.distance=new n,this.direction=new n}resolve(t,e){if(n.subtract(this.distance,e.position,t.position),!(this.distance.magnitude>t.radius+e.radius))return n.unit(this.direction,this.distance),{direction:this.direction.clone(),penetration:t.radius+e.radius-this.distance.magnitude}}};E=r([i(t.CollisionCircumferenceResolver)],E);let R=class{constructor(){this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new n,this.distance=new n(1/0,1/0),this.cache=new n}resolve(t,e){this.minOverlap=1/0,t instanceof v?this.setCircumferenceAxis(t,e):e instanceof v&&this.setCircumferenceAxis(e,t),this.axes=[...t.projectionAxes],e.projectionAxes.forEach((t=>this.axes.some((e=>e.equals(t)))?void 0:this.axes.push(t)));for(let i=0;i<this.axes.length;i++){if(t instanceof v?this.setCircumferenceVertices(t,this.axes[i]):e instanceof v&&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;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,n.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&&n.scale(this.smallestAxis,this.axes[i],-1))}return{direction:n.scale(new n,this.smallestAxis,-1),penetration:this.minOverlap}}projectShapeOntoAxis(t,e,i){return t.min=1/0,t.max=-1/0,e.vertices.forEach((e=>{t.min=Math.min(n.dot(i,e),t.min),t.max=Math.max(n.dot(i,e),t.max)})),t}setCircumferenceAxis(t,e){this.distance.set(1/0,1/0),e.vertices.forEach((e=>{n.subtract(this.cache,e,t.position),this.cache.magnitude<this.distance.magnitude&&this.distance.copy(this.cache)})),n.unit(t.projectionAxes[0],this.distance)}setCircumferenceVertices(t,e){n.add(t.vertices[0],t.position,n.scale(this.cache,n.unit(this.cache,e),-t.radius)),n.add(t.vertices[1],t.position,n.scale(this.cache,n.unit(this.cache,e),t.radius))}};R=r([i(t.CollisionSatResolver)],R);let A=class{constructor(){this.collisions=[]}findCollisionsForCollider(t){return this.collisions.filter((e=>e.localCollider===t))}findCollisionsForColliderAndLayer(t,e){return this.collisions.filter((i=>i.localCollider===t&&i.remoteCollider.layer===e))}findAll(){return this.collisions}persist(t){this.collisions.push(t)}removeAll(){this.collisions=[]}};A=r([i(t.CollisionRepository)],A);let T=class{constructor(){this.lastEntityId=0,this.lastComponentTypeId=0,this.components=new Map,this.disabledEntities=new Set,this.disabledComponents=new Map}createEntity(t){return this.lastEntityId++,t&&t.forEach((t=>this.addComponent(this.lastEntityId,t))),this.lastEntityId}removeEntity(t){this.components.forEach((e=>{e.has(t)&&e.delete(t)})),this.disabledComponents.delete(t),this.disabledEntities.delete(t)}removeAllEntities(){this.components.clear(),this.disabledComponents.clear(),this.disabledEntities.clear(),this.lastEntityId=0}isEntityEnabled(t){return!this.disabledEntities.has(t)}enableEntity(t){this.disabledEntities.delete(t)}disableEntity(t){this.disabledEntities.add(t)}disableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.disableEntity(s)}enableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.enableEntity(s)}addComponent(t,e){const i=this.getComponentTypeId(e),s="object"==typeof e?e:new e;if(this.components.has(i)||this.components.set(i,new Map),this.components.get(i).has(t))throw new Error(`Entity ${t} already has a component of type ${i}`);return this.components.get(i).set(t,s),s}hasComponent(t,e){return void 0!==this.getComponent(t,e)}getComponent(t,e){var i;return null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.get(t)}getComponents(t){const e=[];return this.components.forEach((i=>i.forEach(((i,s)=>{t===s&&e.push(i)})))),e}getEntityForComponent(t){const e=this.getComponentTypeId(t);if(this.components.has(e))for(const[i,s]of this.components.get(e))if(s===t)return i}removeComponent(t,e){var i;const s=this.getComponentTypeId("object"==typeof t?t:e),o="number"==typeof t?t:this.getEntityForComponent(t);(null===(i=this.components.get(s))||void 0===i?void 0:i.has(o))&&this.components.get(s).delete(o)}isComponentEnabled(t,e){var i,s;const o=this.getComponentTypeId("object"==typeof t?t:e),r="number"==typeof t?t:this.getEntityForComponent(t);return null===(s=!(null===(i=this.disabledComponents.get(r))||void 0===i?void 0:i.has(o)))||void 0===s||s}disableComponent(t,e){const i="number"==typeof t?t:this.getEntityForComponent(t),s=this.getComponentTypeId("object"==typeof t?t:e);this.disabledComponents.has(i)?this.disabledComponents.get(i).has(s)||this.disabledComponents.get(i).add(s):this.disabledComponents.set(i,new Set([s]))}enableComponent(t,e){var i;const s="number"==typeof t?t:this.getEntityForComponent(t),o=this.getComponentTypeId("object"==typeof t?t:e);(null===(i=this.disabledComponents.get(s))||void 0===i?void 0:i.has(o))&&this.disabledComponents.get(s).delete(o)}search(t,e,i=!1){const s=[],o=this.getComponentTypeId(t);return this.components.has(o)&&this.components.get(o).forEach(((o,r)=>{e&&!Object.keys(e).every((t=>o[t]===e[t]))||!(i||this.isEntityEnabled(r)&&this.isComponentEnabled(r,t))||s.push({entity:r,component:o})})),s}searchEntitiesByComponents(t){const e=[];let i=!0;for(const s of t){const t=this.getComponentTypeId(s);if(!t||!this.components.has(t))return[];if(i){e.push(...this.components.get(t).keys()),i=!1;continue}const o=new Set(this.components.get(t).keys());e.forEach(((t,i)=>{o.has(t)||e.splice(i,1)}))}return e}getComponentTypeId(t){const e="object"==typeof t?t.constructor.prototype:t.prototype;return void 0===e.__ecs_type_id&&(e.__ecs_type_id=++this.lastComponentTypeId),e.__ecs_type_id}};T=r([i(t.EntityManager)],T);let D=class{constructor(){this.systems=[]}findSystemIndex(t){return this.systems.findIndex((e=>e[0]instanceof t))}addSystem(t,e){if(this.systems.some((t=>t[0]instanceof t.constructor)))throw new Error(`SystemManager already has an instance of ${t.constructor.name}.`);this.systems.push([t,e,!1,!1])}hasSystem(t){return this.systems.some((e=>e[0]instanceof t))}getSystem(t){const e=this.findSystemIndex(t);return-1!==e?this.systems[e][0]:void 0}enableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!0===this.systems[e][2])return;const i=this.systems[e];!1===i[3]&&(i[3]=!0,i[0].onCreate&&i[0].onCreate()),i[2]=!0,i[0].onEnabled&&i[0].onEnabled()}disableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!1===this.systems[e][2])return;const i=this.systems[e];i[2]=!1,i[0].onDisabled&&i[0].onDisabled()}setExecutionOrder(t,e){const i=this.findSystemIndex(t);if(-1===i)throw new Error(`Cannot set execution order because ${t.name} is not a system.`);this.systems.splice(e,0,this.systems.splice(i,1)[0])}removeSystem(t){const e=this.findSystemIndex(t);if(-1===e)return;const i=this.systems.splice(e,1)[0][0];i.onDestroy&&i.onDestroy()}update(t){this.systems.filter((e=>e[1]===t&&!0===e[2])).forEach((t=>t[0].onUpdate()))}};D=r([i(t.SystemManager)],D);class B{constructor(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new n,this._leftStickAxes=new n,this._rightStickAxes=new n}get dpadAxes(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes}get leftStickAxes(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes}get rightStickAxes(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes}get dpadUp(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t}get dpadDown(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t}get dpadLeft(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t}get dpadRight(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t}get bottomFace(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t}get rightFace(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t}get leftFace(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t}get topFace(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t}get leftShoulder(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t}get rightShoulder(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t}get leftTrigger(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t}get rightTrigger(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t}get back(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t}get start(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t}get leftStickButton(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t}get rightStickButton(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t}get leftStickHorizontal(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0}get leftStickVertical(){var t;return-(null!==(t=this.axes.get(1))&&void 0!==t?t:0)}get rightStickHorizontal(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0}get rightStickVertical(){var t;return-(null!==(t=this.axes.get(3))&&void 0!==t?t:0)}get anyButtonPressed(){var t;return null!==(t=Array.from(this.buttons.values()).find((t=>t)))&&void 0!==t&&t}vibrate(t=200,e=.2,i=.2,s=0){this.vibrationInput={duration:t,weakMagnitude:e,startDelay:s,strongMagnitude:i}}}class P{constructor(){this.pressedKeys=[]}isPressed(t){return this.pressedKeys.includes(t)}orPressed(t){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)}andPressed(t){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)}isPressedReturn(t,e,i){return this.pressedKeys.includes(t)?e:i}orPressedReturn(t,e,i){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)?e:i}andPressedReturn(t,e,i){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)?e:i}}class U{constructor(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new n,this.hasMoved=!1,this.wheelScroll=new n}}class F{constructor(){this.touching=!1,this.interactions=[]}}let L=class{constructor(){this.keyboard=new P,this.mouse=new U,this.touchScreen=new F,this.gamepads=[]}};L=r([i(t.InputManager)],L);const I=[60,120,180,240];let j=class{get deltaTime(){return this.unscaledDeltaTime*this.timeScale}get physicsDeltaTime(){return this.unscaledPhysicsDeltaTime*this.timeScale}get renderDeltaTime(){return this.browserDeltaTime*this.timeScale}constructor({physicsFramerate:t}){if(this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForRender=0,t&&!I.includes(t))throw new Error(`Invalid Physics frame rate. Allowed: [${I.join(", ")}]`);this.fixedGameFramerate=60,this.fixedGameDeltaTime=parseFloat((1/this.fixedGameFramerate).toFixed(6)),this.fixedPhysicsFramerate=null!=t?t:180,this.fixedPhysicsDeltaTime=parseFloat((1/this.fixedPhysicsFramerate).toFixed(6))}updateForRender(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForRender),this.maxDeltaTime),this.thenForRender=t}updateForGame(t){this.unscaledDeltaTime=Math.min(Math.max(this.fixedGameDeltaTime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t}updateForPhysics(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t}};var k;j=r([i(t.TimeManager),a(0,s(t.GameConfig))],j),function(t){t[t.Image=0]="Image",t[t.Audio=1]="Audio",t[t.Font=2]="Font",t[t.Video=3]="Video"}(k||(k={}));let O=class{constructor(){this.assets=[]}getAssetsLoaded(){return this.assets.reduce(((t,e)=>t&&e.loaded),!0)}loadImage(t){const e=new Image;e.crossOrigin="",e.src=t;const i=this.createAsset(t,k.Image,e),s=()=>i.loaded=!0;return e.complete?s():e.addEventListener("load",s),e}loadAudio(t){const e=new Audio;e.src=t;const i=this.createAsset(t,k.Audio,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(()=>i.loaded=!0)),e}loadFont(t,e){const i=new FontFace(t,`url(${e})`),s=this.createAsset(e,k.Font,i);return s.family=t,document.fonts.add(i),i.load().then((()=>s.loaded=!0)),i}loadVideo(t){const e=document.createElement("video");e.playsInline=!0,e.src=t;const i=this.createAsset(t,k.Video,e);return e.duration?i.loaded=!0:e.addEventListener("canplaythrough",(()=>i.loaded=!0)),e}getImage(t){var e;return null===(e=this.assets.find((e=>e.type===k.Image&&e.url===t)))||void 0===e?void 0:e.element}getAudio(t){var e;return null===(e=this.assets.find((e=>e.type===k.Audio&&e.url===t)))||void 0===e?void 0:e.element}getFont(t){var e;return null===(e=this.assets.find((e=>e.type===k.Font&&e.family===t)))||void 0===e?void 0:e.element}getVideo(t){var e;return null===(e=this.assets.find((e=>e.type===k.Video&&e.url===t)))||void 0===e?void 0:e.element}createAsset(t,e,i){const s={type:e,url:t,element:i,loaded:!1};return this.assets.push(s),s}};O=r([i(t.AssetManager)],O);class V{constructor(t){this.action="stop",this.loop=!1,this.playing=!1,this.volume=1,this._currentAudio=void 0,Object.assign(this,t)}}const G={AudioPlayerSystem:Symbol.for("AudioPlayerSystem"),ButtonSystem:Symbol.for("ButtonSystem"),ChildrenSystem:Symbol.for("ChildrenSystem"),ParentSystem:Symbol.for("ParentSystem"),TiledWrapperSystem:Symbol.for("TiledWrapperSystem"),TilemapPreProcessingSystem:Symbol.for("TilemapPreProcessingSystem"),TransformSystem:Symbol.for("TransformSystem"),GamepadSystem:Symbol.for("GamepadSystem"),KeyboardSystem:Symbol.for("KeyboardSystem"),MouseSystem:Symbol.for("MouseSystem"),TouchScreenSystem:Symbol.for("TouchScreenSystem"),UpdateBallColliderShapeSystem:Symbol.for("UpdateBallColliderShapeSystem"),UpdateBoxColliderShapeSystem:Symbol.for("UpdateBoxColliderShapeSystem"),UpdateEdgeColliderShapeSystem:Symbol.for("UpdateEdgeColliderShapeSystem"),UpdatePolygonColliderShapeSystem:Symbol.for("UpdatePolygonColliderShapeSystem"),UpdateTilemapColliderShapeSystem:Symbol.for("UpdateTilemapColliderShapeSystem"),UpdateCollidersAfterRepositionSystem:Symbol.for("UpdateCollidersAfterRepositionSystem"),ApplyRepositionSystem:Symbol.for("ApplyRepositionSystem"),ApplyVelocitySystem:Symbol.for("ApplyVelocitySystem"),ResolveCollisionSystem:Symbol.for("ResolveCollisionSystem"),AnimatorSystem:Symbol.for("AnimatorSystem"),CameraSystem:Symbol.for("CameraSystem"),ClearScreenSystem:Symbol.for("ClearScreenSystem"),ColliderRenderSystem:Symbol.for("ColliderRenderSystem"),CullingSystem:Symbol.for("CullingSystem"),MaskRendererSystem:Symbol.for("MaskRendererSystem"),RenderSystem:Symbol.for("RenderSystem"),ShadowLightRendererSystem:Symbol.for("ShadowLightRendererSystem"),SpriteRendererSystem:Symbol.for("SpriteRendererSystem"),TextRendererSystem:Symbol.for("TextRendererSystem"),TilemapRendererSystem:Symbol.for("TilemapRendererSystem"),VideoRendererSystem:Symbol.for("VideoRendererSystem")},W=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let z=class{constructor(t,e,i){this.entityManager=t,this.inputManager=e,this.timeManager=i,this.canPlay=!1,this.userInputEventHandler=()=>{W.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,W.forEach((t=>window.addEventListener(t,this.userInputEventHandler))),document.addEventListener("visibilitychange",(()=>{this.entityManager.search(V).forEach((({component:{audioSource:t,playing:e}})=>{document.hidden&&t?t.pause():!document.hidden&&t&&e&&t.play()}))}))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(V).forEach((({component:t})=>{t.audioSource&&t.audioSource.duration&&(t.audioSource.loop=t.loop,t.audioSource.volume=t.volume,t.audioSource.src!==t._currentAudio&&(t._currentAudio=t.audioSource.src,t.playing=!1,t.audioSource.currentTime=0),"play"!==t.action||t.playing?"pause"===t.action&&t.playing?(t.audioSource.pause(),t.playing=!1):"stop"!==t.action||t.audioSource.paused&&0===t.audioSource.currentTime?t.playing&&t.audioSource.paused&&(t.action="stop",t.playing=!1):(t.audioSource.pause(),t.audioSource.currentTime=0,t.playing=!1):(t.audioSource.playbackRate=this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16),t.audioSource.play().then((()=>t.playing=!0)).catch((()=>{}))))}))}onDisable(){this.entityManager.search(V).forEach((({component:{audioSource:t}})=>{t&&(t.pause(),t.currentTime=0)}))}onDestroy(){this.onDisable()}};var H;function N(){return function(t){$(t,H.GameLogic)}}function Y(){return function(t){$(t,H.GamePhysics)}}function X(){return function(t){$(t,H.GamePreRender)}}z=r([i(G.AudioPlayerSystem),a(0,s(t.EntityManager)),a(1,s(t.InputManager)),a(2,s(t.TimeManager))],z),function(t){t[t.GameLogic=0]="GameLogic",t[t.GamePhysics=1]="GamePhysics",t[t.GamePreRender=2]="GamePreRender",t[t.Physics=3]="Physics",t[t.PostGameLogic=4]="PostGameLogic",t[t.PreGameLogic=5]="PreGameLogic",t[t.Render=6]="Render"}(H||(H={}));const $=(t,e)=>{t.prototype.__system_group||(t.prototype.__system_group=e)};class K{get parent(){return this._parent}set parent(t){this._parent!==t&&(this._parent=t,this._parent?(this.localPosition.copy(this.position),n.subtract(this.position,this.position,this._parent.position)):this.position.copy(this.localPosition))}constructor(t){this.position=new n,this.scale=new n(1,1),this.rotation=0,this.localPosition=new n,this.localScale=new n(1,1),this.localRotation=0,this._childEntities=[],this._parent=void 0,t&&t.parent&&(this.position=t.parent.position.clone(),this.parent=t.parent,delete t.parent),Object.assign(this,t)}}const q="Default";class Q{constructor(t){this.layers=[q],this.zoom=1,this.depth=0,this._renderData={position:new n,depth:0,zoom:1,layers:[]},Object.assign(this,t)}}var J;!function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(J||(J={}));class Z{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(J.WebGL2)?J.WebGL2:null!==this.canvas.getContext(J.LegacyWebGL)?J.LegacyWebGL:void 0}}class tt{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 et(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,o=0;for(let t=0;t<this.chars.length;t++)i.fillText(this.chars[t],s,o),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,o+=this.bitmapSize);return e}}class et{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 it{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),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,s),this.gl.attachShader(i,o),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class st{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){this.program=this.contextVersion===J.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nout vec2 texCoords;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision highp float;\n\nin vec2 texCoords;\n\n// texture, mask and shadow\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[64];\nuniform int u_numLights;\n\nout vec4 fragColor;\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 if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < u_numLights; i++) {\n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n fragColor = vec4(u_solidColor.rgb, alpha);\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\n// texture, mask and shadow\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[10];\nuniform int u_numLights;\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 if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < u_numLights; i++) {\n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n gl_FragColor = vec4(u_solidColor.rgb, alpha);\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.renderLightUniform=this.gl.getUniformLocation(this.program,"u_renderLight"),this.numLightsUniform=this.gl.getUniformLocation(this.program,"u_numLights"),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 ot{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 rt="undefined"!=typeof Float32Array?Float32Array:Array;function at(){var t=new rt(16);return rt!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function nt(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 ht(t,e,i){var s,o,r,a,n,h,l,c,d,m,g,u,p=i[0],y=i[1],f=i[2];return e===t?(t[12]=e[0]*p+e[4]*y+e[8]*f+e[12],t[13]=e[1]*p+e[5]*y+e[9]*f+e[13],t[14]=e[2]*p+e[6]*y+e[10]*f+e[14],t[15]=e[3]*p+e[7]*y+e[11]*f+e[15]):(s=e[0],o=e[1],r=e[2],a=e[3],n=e[4],h=e[5],l=e[6],c=e[7],d=e[8],m=e[9],g=e[10],u=e[11],t[0]=s,t[1]=o,t[2]=r,t[3]=a,t[4]=n,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=m,t[10]=g,t[11]=u,t[12]=s*p+n*y+d*f+e[12],t[13]=o*p+h*y+m*f+e[13],t[14]=r*p+l*y+g*f+e[14],t[15]=a*p+c*y+u*f+e[15]),t}function lt(t,e,i){var s=i[0],o=i[1],r=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]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ct(t,e,i){var s=Math.sin(i),o=Math.cos(i),r=e[0],a=e[1],n=e[2],h=e[3],l=e[4],c=e[5],d=e[6],m=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*o+l*s,t[1]=a*o+c*s,t[2]=n*o+d*s,t[3]=h*o+m*s,t[4]=l*o-r*s,t[5]=c*o-a*s,t[6]=d*o-n*s,t[7]=m*o-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 dt=function(t,e,i,s,o,r,a){var n=1/(e-i),h=1/(s-o),l=1/(r-a);return t[0]=-2*n,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)*n,t[13]=(o+s)*h,t[14]=(a+r)*l,t[15]=1,t};const mt=(t,e,i,s)=>{t=nt(t),dt(t,-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),lt(t,t,[null!=i?i:1,null!=i?i:1,1]),ht(t,t,[-s.x,-s.y,0])},gt=t=>{const e=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[2],16)/256,g:parseInt(e[3],16)/256,b:parseInt(e[4],16)/256,a:void 0!==e[1]?parseInt(e[1],16)/256:1}:null};class ut{constructor(t){this.gl=t}render(t){const e=gt(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var pt,yt,ft;!function(t){t[t.Polygon=0]="Polygon",t[t.Circumference=1]="Circumference",t[t.Line=2]="Line"}(pt||(pt={}));class xt{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at();const i=2*Math.PI/60;this.circumferenceVertices=new Float32Array(g(1,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]))}render(t,e){switch(t.shape){case pt.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP);break;case pt.Line:this.renderLines(t,e,this.gl.LINES);break;case pt.Circumference:this.renderCircumference(t,e);break;default:return!1}return!0}renderLines(t,e,i){var s;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertexModel.reduce(((t,e)=>[...t,e.x,e.y]),[])),this.gl.DYNAMIC_DRAW),this.modelMatrix=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),mt(this.projectionMatrix,this.gl,e.zoom,e.position),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:o,g:r,b:a,a:n}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,a,n),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,t.vertexModel.length)}renderCircumference(t,e){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.circumferenceVertices,this.gl.DYNAMIC_DRAW),this.modelMatrix=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),lt(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),mt(this.projectionMatrix,this.gl,e.zoom,e.position),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:o,a:r}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,i,s,o,r),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,this.circumferenceVertices.length/2)}}!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",t[t.Shadow=6]="Shadow"}(yt||(yt={})),function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(ft||(ft={}));let Mt=class{constructor(t,e){this.gl=t,this.programManager=e,this.type=yt.Mask,this.rectangleVertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at();const i=2*Math.PI/60,s=[0,0];for(let t=0;t<=60;t++)s.push(Math.cos(t*i),Math.sin(t*i));this.circumferenceVertices=new Float32Array(s)}render(t,e,i){var s,o;i===yt.Mask&&this.lastShape===t.shape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.programManager.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,t.shape===ft.Rectangle?this.rectangleVertices:this.circumferenceVertices,this.gl.STATIC_DRAW)),this.modelMatrix=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),lt(this.modelMatrix,this.modelMatrix,t.shape===ft.Rectangle?[t.width,t.height,1]:[t.radius,t.radius,1]),mt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:a,b:n,a:h}=gt(t.color);return this.gl.uniform4f(this.programManager.solidColorUniform,r,a,n,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),t.shape===ft.Rectangle?this.gl.drawArrays(this.gl.TRIANGLES,0,6):this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,this.circumferenceVertices.length/2),this.lastShape=t.shape,!0}},vt=class{constructor(t,e){this.gl=t,this.programManager=e,this.vertices=new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e){var i,s;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=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(i=t.rotation)&&void 0!==i?i:0),lt(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),mt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0),this.gl.uniform1i(this.programManager.renderLightUniform,1);const{r:o,g:r,b:a,a:n}=gt(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,a,n),this.gl.uniform1f(this.programManager.alphaUniform,null!==(s=t.opacity)&&void 0!==s?s:1),this.gl.uniform1i(this.programManager.numLightsUniform,t.lights.length);for(const[i,s]of t.lights.entries()){if(i>=64)break;this.gl.uniform2f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].position`),this.gl.canvas.width/2+(s.position.x-e.position.x)*e.zoom,this.gl.canvas.height/2+(s.position.y-e.position.y)*e.zoom),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].radius`),s.radius*e.zoom),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].smoothMode`),s.smooth?1:0),this.gl.uniform1f(this.gl.getUniformLocation(this.programManager.program,`u_lights[${i}].intensity`),Math.max(0,Math.min(1,s.intensity)))}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.gl.uniform1i(this.programManager.renderLightUniform,0),!0}},St=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,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 s,o,r,a;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=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),lt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontally?-1:1),t.height*(t.flipVertically?-1:1),1]),this.textureMatrix=nt(this.textureMatrix),t.slice&&(ht(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),lt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),mt(this.projectionMatrix,this.gl,e.zoom,e.position),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 n=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===n&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=gt(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=gt(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};var Ct;!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(Ct||(Ct={}));let bt=class{constructor(t,e,i,s){this.gl=t,this.programManager=e,this.textureManager=i,this.fontAtlasFactory=s,this.type=yt.Text,this.posVertices=[],this.texVertices=[],this.lastTexture=null,this.textSize=new n,this.modelPosition=new n,this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var s;if(!t.text)return!1;const o=this.fontAtlasFactory.getOrCreate(t.bitmap.charRanges,t.font,t.bitmap.fontSize);this.generateTextVertices(o,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=nt(this.modelMatrix),this.setPositionFromOrientation(t),ht(this.modelMatrix,this.modelMatrix,[this.modelPosition.x,this.modelPosition.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),lt(this.modelMatrix,this.modelMatrix,[t.fontSize,t.fontSize,1]),this.textureMatrix=nt(this.textureMatrix),mt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND);const r=this.textureManager.getOrCreateTextureFromCanvas("FontFamily:"+o.fontFaceFamily,o.canvas,t.smooth);this.lastTexture===r&&i===yt.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=r),this.gl.uniform1i(this.programManager.useTintColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.opacity);const{r:a,g:n,b:h,a:l}=gt(t.color);return this.gl.uniform4f(this.programManager.maskColorUniform,a,n,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),!0}generateTextVertices(t,{text:e,fontSize:i,bitmap:s,letterSpacing:o,lineSeparation:r}){this.posVertices=[],this.texVertices=[];let a=0,n=0,h=0;o/=i,r/=i;for(let i=0;i<e.length;i++){const l=e[i];if("\n"===l){h=Math.max(h,a),a=0,n-=1+r;continue}const c=t.glyphs.get(l);if(c){const e=c.width/t.bitmapFontSize;this.posVertices.push(a,n-1,a+e,n-1,a,n,a,n,a+e,n-1,a+e,n);const i=c.id%t.gridSize*t.bitmapFontSize,r=(c.id/t.gridSize|0)*t.bitmapFontSize,h=(i+s.margin.x)/t.canvas.width,l=(r+s.margin.y)/t.canvas.width,d=(i+c.width+s.spacing.x)/t.canvas.width,m=(r+t.bitmapFontSize+s.spacing.y)/t.canvas.width;this.texVertices.push(h,m,d,m,h,l,h,l,d,m,d,l),a+=e+o}}this.textSize.set(Math.max(h,a)*i,Math.abs(n-1)*i)}setPositionFromOrientation(t){this.modelPosition.set(t.position.x+(t.orientation===Ct.Center?-this.textSize.x/2:0),t.position.y+(t.orientation===Ct.Center||t.orientation===Ct.RightCenter?this.textSize.y/2:t.orientation===Ct.RightUp?this.textSize.y:0))}};var wt;!function(t){t[t.Center=0]="Center",t[t.RightUp=1]="RightUp",t[t.RightDown=2]="RightDown",t[t.RightCenter=3]="RightCenter"}(wt||(wt={}));let _t=class{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 n,texSpacing:new n,texWidth:0,texHeight:0,texCorrection:new n},this.projectionMatrix=at(),this.modelMatrix=at(),this.textureMatrix=at()}render(t,e,i){var s,o,r,a;if(0===t.tiles.reduce(((t,e)=>t+e),0))return!1;if(this.processTileset(t),this.generateVertices(t),0===this.posVertices.length)return!1;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=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),lt(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=nt(this.textureMatrix),lt(this.textureMatrix,this.textureMatrix,[this.tileset.tileWidth/t.tileset.image.naturalWidth,this.tileset.tileHeight/t.tileset.image.naturalHeight,1]),mt(this.projectionMatrix,this.gl,e.zoom,e.position),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 n=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===n&&i===yt.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=gt(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=gt(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}processTileset({tileset:t}){var e,i,s,o,r,a,h;t.margin=null!==(e=t.margin)&&void 0!==e?e:new n,t.spacing=null!==(i=t.spacing)&&void 0!==i?i:new n,t.correction=null!==(s=t.correction)&&void 0!==s?s:new n,this.tileset.width=t.width,this.tileset.tileWidth=t.tileWidth+(null!==(o=t.margin.x)&&void 0!==o?o:0)+(null!==(r=t.spacing.x)&&void 0!==r?r:0),this.tileset.tileHeight=t.tileHeight+(null!==(a=t.margin.y)&&void 0!==a?a:0)+(null!==(h=t.spacing.y)&&void 0!==h?h: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({tiles:t,tilemap:e}){this.posVertices=[],this.texVertices=[];const i=Math.floor(t.length/e.width);t.forEach(((t,s)=>{if(0===t)return;const o=s%e.width-e.width/2,r=i/2-Math.floor(s/e.width);this.posVertices.push(o,r-1,o+1,r-1,o,r,o,r,o+1,r-1,o+1,r);const a=(t-1)%this.tileset.width+this.tileset.texMargin.x+this.tileset.texCorrection.x,n=Math.floor((t-1)/this.tileset.width)+this.tileset.texMargin.y+this.tileset.texCorrection.y;this.texVertices.push(a,n+this.tileset.texHeight,a+this.tileset.texWidth,n+this.tileset.texHeight,a,n,a,n,a+this.tileset.texWidth,n+this.tileset.texHeight,a+this.tileset.texWidth,n)}))}},Et=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.lastTexture=null,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 s,o,r,a;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=nt(this.modelMatrix),ht(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),ct(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),lt(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=nt(this.textureMatrix),t.slice&&(ht(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),lt(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),mt(this.projectionMatrix,this.gl,e.zoom,e.position),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 n=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===n&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=n),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!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=gt(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=gt(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(a=t.maskColorMix)&&void 0!==a?a:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};class Rt{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 At{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!0){var i;return null!==(i=this.textures.get(Symbol.for(t.src)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!0){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(Symbol.for(t.src),i),i}getOrCreateTextureFromCanvas(t,e,i=!0){var 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}}let Tt=class{constructor(t){this.renderers=new Map;const e=new Z(t),i=e.gl,s=e.contextVersion,o=new st(i,s,new it(i,new ot(i))),r=new At(new Rt(i)),a=new tt;this.renderers.set(yt.Sprite,new St(i,o,r)),this.renderers.set(yt.Text,new bt(i,o,r,a)),this.renderers.set(yt.Tilemap,new _t(i,o,r)),this.renderers.set(yt.Geometric,new xt(i,o)),this.renderers.set(yt.Mask,new Mt(i,o)),this.renderers.set(yt.Video,new Et(i,o,r)),this.renderers.set(yt.Shadow,new vt(i,o)),this.canvasColorRenderer=new ut(i),o.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender)&&(this.lastRender=t.type)}renderCanvasColor(t){this.canvasColorRenderer.render(t)}};Tt=r([i(t.WebGLManager),a(0,s(t.CanvasElement))],Tt);class Dt{constructor(t){this.offset=new n,this.rotation=0,this.layer=q,this.loop=!1,this.volume=1,this.play=!1,this.pause=!1,this._renderData={type:yt.Video,height:void 0,layer:void 0,position:new n,video:void 0,width:void 0,flipHorizontal:void 0,flipVertical:void 0,maskColor:void 0,maskColorMix:void 0,opacity:void 0,rotation:void 0,slice:void 0,tintColor:void 0},Object.assign(this,t)}}const Bt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Pt=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.timeManager=i,this.scaledOffset=new n,this.userInputEventHandler=()=>{Bt.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0}}onCreate(){this.canPlay=!1,Bt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}onUpdate(){this.entityManager.search(Dt).forEach((({entity:t,component:e})=>{var i,s;const o=this.entityManager.getComponent(t,K);if(!o)throw new Error("VideoRenderer component needs a Transform");e.video&&e.video.duration&&(this.checkVideoState(e),this.scaledOffset.set(e.offset.x*o.localScale.x,e.offset.y*o.localScale.y),n.add(e._renderData.position,o.localPosition,this.scaledOffset),e._renderData.layer=e.layer,e._renderData.video=e.video,e._renderData.width=(null!==(i=e.width)&&void 0!==i?i:e.video.videoWidth)*Math.abs(o.localScale.x),e._renderData.height=(null!==(s=e.height)&&void 0!==s?s:e.video.videoHeight)*Math.abs(o.localScale.y),e._renderData.rotation=o.localRotation+e.rotation,e._renderData.slice=e.slice,e._renderData.flipHorizontal=e.flipHorizontally,e._renderData.flipVertical=e.flipVertically,e._renderData.opacity=e.opacity,e._renderData.maskColor=e.maskColor,e._renderData.maskColorMix=e.maskColorMix,e._renderData.tintColor=e.tintColor,0!==o.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,o),this.renderManager.addRenderData(e._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}checkVideoState(t){const{video:e,play:i,pause:s,loop:o,volume:r}=t;e.loop=o,e.volume=r,e.playbackRate=this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16),i&&e.ended&&(t.play=!1),i&&e.paused&&this.canPlay&&e.play(),!i&&e.currentTime>0&&(e.pause(),e.currentTime=0),s&&!e.paused&&e.pause(),!s&&e.paused&&i&&this.canPlay&&e.play()}onDisable(){this.entityManager.search(Dt).forEach((({component:t})=>{t.video&&(t.video.pause(),t.video.currentTime=0)}))}onDestroy(){this.onDisable()}};Pt=r([i(G.VideoRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager)),a(2,s(t.TimeManager))],Pt);class Ut{constructor(t,e){this.entityManager=t,this.assetManager=e}loadAssets(){}setup(){}}let Ft=class{constructor(t,e,i,s){this.systemManager=t,this.systemFactory=e,this.entityManager=i,this.assetManager=s,this.scenes=new Map,this.loadingScene=!1}addScene(t,e,i=!1){const s=new t(this.entityManager,this.assetManager);this.scenes.set(e,s),i&&(this.openingSceneName=e)}loadScene(t){if(!this.scenes.has(t))throw new Error(`Invalid scene name: '${t}'`);this.sceneNameToBeLoaded=t}loadOpeningScene(){if(!this.openingSceneName)throw new Error("There is no opening scene");this.sceneNameToBeLoaded=this.openingSceneName}update(){this.sceneNameToBeLoaded&&(this.currentSceneName&&this.destroyCurrentScene(),this.currentSceneName=this.sceneNameToBeLoaded,this.sceneNameToBeLoaded=void 0,this.scenes.get(this.currentSceneName).loadAssets(),this.loadingScene=!0),this.loadingScene&&this.assetManager.getAssetsLoaded()&&(this.loadingScene=!1,this.scenes.get(this.currentSceneName).setup(),this.systemManager.update(H.PostGameLogic),this.scenes.get(this.currentSceneName).systems.forEach(((t,e)=>{this.systemFactory.createSystemIfNotExists(t),this.systemManager.enableSystem(t),this.systemManager.setExecutionOrder(t,e)})))}destroyCurrentScene(){this.systemManager.disableSystem(z),this.systemManager.disableSystem(Pt),this.entityManager.removeAllEntities(),this.scenes.get(this.currentSceneName).systems.forEach((t=>this.systemManager.disableSystem(t))),this.systemManager.enableSystem(z),this.systemManager.enableSystem(Pt)}};Ft=r([i(t.SceneManager),a(0,s(t.SystemManager)),a(1,s(t.SystemFactory)),a(2,s(t.EntityManager)),a(3,s(t.AssetManager))],Ft);class Lt{constructor(t){this.width=0,this.height=0,this.radius=0,this.touchEnabled=!0,this.offset=new n,this.pressed=!1,Object.assign(this,t)}}var It;!function(t){t[t.Rectangle=0]="Rectangle",t[t.Circumference=1]="Circumference"}(It||(It={}));let jt=class{constructor(t,e){this.entityManager=t,this.scaled={position:new n,width:0,height:0,radius:0},this.distance=new n,this.pressedLastFrame=!1,this.mouse=e.mouse,this.touchScreen=e.touchScreen}onUpdate(){this.entityManager.search(Lt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("Button component needs a Transform");this.pressedLastFrame=e.pressed,e.pressed=!1,this.scale(e,i),this.mouse.leftButtonPressed&&(this.resolveMouseAndRectangle(e),this.resolveMouseAndCircumference(e)),e.touchEnabled&&this.touchScreen.touching&&(this.resolveTouchAndRectangle(e),this.resolveTouchAndCircumference(e)),e.onClick&&!this.pressedLastFrame&&e.pressed&&e.onClick(),e.onPressed&&e.pressed&&e.onPressed()}))}scale(t,{localPosition:e,localScale:i}){this.scaled.width=t.width*i.x,this.scaled.height=t.width*i.y,this.scaled.position.x=e.x+t.offset.x*i.x,this.scaled.position.y=e.y+t.offset.y*i.y,this.scaled.radius=t.radius*Math.max(Math.abs(i.x),Math.abs(i.y))}resolveMouseAndRectangle(t){t.shape===It.Rectangle&&(t.pressed=u(this.mouse.positionInViewport.x,this.scaled.position.x-this.scaled.width/2,this.scaled.position.x+this.scaled.width/2)&&u(this.mouse.positionInViewport.y,this.scaled.position.y-this.scaled.height/2,this.scaled.position.y+this.scaled.height/2))}resolveMouseAndCircumference(t){t.shape===It.Circumference&&(n.subtract(this.distance,this.scaled.position,this.mouse.positionInViewport),t.pressed=this.distance.magnitude<=this.scaled.radius)}resolveTouchAndRectangle(t){if(t.shape===It.Rectangle)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;t.pressed=this.scaled.position.x+this.scaled.width/2>=e.x-i.x&&this.scaled.position.x-this.scaled.width/2<=e.x+i.x&&this.scaled.position.y+this.scaled.height/2>=e.y-i.y&&this.scaled.position.y-this.scaled.height/2<=e.y+i.y}}resolveTouchAndCircumference(t){if(t.shape===It.Circumference)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;n.subtract(this.distance,this.scaled.position,e),t.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(i.x,i.y)}}};jt=r([i(G.ButtonSystem),a(0,s(t.EntityManager)),a(1,s(t.InputManager))],jt);class kt{constructor(){this.entities=[]}}let Ot=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(kt).forEach((({entity:t,component:e})=>{e.entities=this.entityManager.getComponent(t,K)._childEntities}))}};Ot=r([i(G.ChildrenSystem),a(0,s(t.EntityManager))],Ot);class Vt{}let Gt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Vt).forEach((({entity:t,component:e})=>{e.entity=this.entityManager.getComponent(t,K)._parentEntity}))}};Gt=r([i(G.ParentSystem),a(0,s(t.EntityManager))],Gt);class Wt{constructor(t){Object.assign(this,t)}}class zt{constructor(t){this.layer=q,this.tileset=void 0,this.data=[],this.chunks=[],this.width=0,this.height=0,this.tileWidth=void 0,this.tileHeight=void 0,this.tintColor=void 0,this.opacity=1,this.smooth=!1,this._processed=!1,this._renderData=[],Object.assign(this,t)}}let Ht=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Wt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,zt);if(!i)return;const s=e.tilemap.layers.find((t=>t.name===e.layerToRender&&"tilelayer"===t.type));s&&(e.tilemap.infinite?i.chunks=s.chunks:i.data=s.data,i.width=e.tilemap.width)}))}};Ht=r([i(G.TiledWrapperSystem),a(0,s(t.EntityManager))],Ht);const Nt=16;let Yt=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(zt).forEach((({component:t})=>{var e,i;t._processed||(t.chunks&&t.chunks.length>0?this.chunksToData(t):t.data&&t.data.length>0&&this.dataToChunks(t),t.tileWidth=null!==(e=t.tileWidth)&&void 0!==e?e:t.tileset.tileWidth,t.tileHeight=null!==(i=t.tileHeight)&&void 0!==i?i:t.tileset.tileHeight,t._processed=!0)}))}dataToChunks(t){t.height=Math.ceil(t.data.length/t.width);const e=Math.ceil(t.width/Nt),i=Math.ceil(t.height/Nt);for(let s=0;s<i;s++)for(let i=0;i<e;i++){const e={x:i*Nt,y:s*Nt,width:Nt,height:Nt,data:[]};for(let i=0;i<e.width*e.height;i++){const s=e.x+i%e.width,o=t.width*(e.y+Math.floor(i/e.width));e.data[i]=s<t.width&&o<t.height*t.width?t.data[o+s]:0}t.chunks.push(e)}}chunksToData(t){t.data=[],t.chunks.forEach((e=>e.data.forEach(((i,s)=>{t.data[t.width*(e.y+Math.floor(s/e.width))+e.x+s%e.width]=i})))),t.height=Math.ceil(t.data.length/t.width)}};Yt=r([i(G.TilemapPreProcessingSystem),a(0,s(t.EntityManager))],Yt);const Xt=t=>t.parent?1+Xt(t.parent):0;let $t=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(K).sort(((t,e)=>Xt(t.component)-Xt(e.component))).forEach((({component:t,entity:e})=>{t.parent&&this.entityManager.getEntityForComponent(t.parent)?(t._childEntities=[],t._parentEntity=this.entityManager.getEntityForComponent(t.parent),t.parent._childEntities.push(e),this.translateChild(t.parent,t)):this.updateTransform(t)}))}updateTransform(t){t.parent=void 0,t._parentEntity=void 0,t._childEntities=[],t.localPosition.copy(t.position),t.localScale.copy(t.scale),t.localRotation=t.rotation}translateChild(t,e){e.localRotation=e.rotation+t.localRotation,e.localScale.x=e.scale.x*t.scale.x,e.localScale.y=e.scale.y*t.scale.y;const i=Math.atan2(e.position.y,e.position.x)+t.localRotation;e.localPosition.set(t.localPosition.x+e.position.magnitude*Math.cos(i),t.localPosition.y+e.position.magnitude*Math.sin(i))}};$t=r([i(G.TransformSystem),a(0,s(t.EntityManager))],$t);let Kt=class{constructor(t){this.inputManager=t,this.gamepads=new Map,this.eventHandler=t=>{"gamepadconnected"===t.type?this.gamepadConnected(t.gamepad):"gamepaddisconnected"===t.type&&this.gamepadDisconected(t.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}gamepadConnected(t){this.gamepads.set(t.index,t),this.inputManager.gamepads[t.index]||(this.inputManager.gamepads[t.index]=new B,this.inputManager.gamepads[t.index].index=t.index),this.inputManager.gamepads[t.index].id=t.id,this.inputManager.gamepads[t.index].connected=!0}gamepadDisconected(t){this.gamepads.delete(t.index),this.inputManager.gamepads[t.index].connected=!1}onUpdate(){for(const t of this.getGamepadsFromBrowser())t&&(!1===this.gamepads.has(t.index)?this.gamepadConnected(t):this.gamepads.set(t.index,t));this.gamepads.forEach((t=>{const e=this.inputManager.gamepads[t.index];t.buttons.forEach(((t,i)=>e.buttons.set(i,t.pressed))),t.axes.forEach(((t,i)=>e.axes.set(i,t))),e.vibrationInput&&(t.vibrationActuator.playEffect(t.vibrationActuator.type,{duration:e.vibrationInput.duration,weakMagnitude:e.vibrationInput.weakMagnitude,strongMagnitude:e.vibrationInput.strongMagnitude,startDelay:e.vibrationInput.startDelay}).catch((()=>e.vibrating=!1)).finally((()=>e.vibrating=!1)),e.vibrating=!0,e.vibrationInput=void 0)}))}getGamepadsFromBrowser(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]}};Kt=r([i(G.GamepadSystem),a(0,s(t.InputManager))],Kt);let qt=class{constructor(t,{keyboard:e}){this.pressedKeys=[],this.eventHandler=t=>{"keydown"!==t.type||this.pressedKeys.includes(t.code)||this.pressedKeys.push(t.code),"keyup"===t.type&&this.pressedKeys.includes(t.code)&&this.pressedKeys.splice(this.pressedKeys.indexOf(t.code),1)},this.keyboard=e,t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler),t.addEventListener("focusout",(()=>this.pressedKeys=[]))}onUpdate(){this.keyboard.pressedKeys=[...this.pressedKeys]}};qt=r([i(G.KeyboardSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],qt);let Qt=class{constructor(t,{mouse:e}){this.canvas=t,this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new n,this.lastPositionInViewport=new n,this.mouse=e,this.canvas.addEventListener("mousemove",(t=>this.updatePosition(t))),this.canvas.addEventListener("mousedown",(t=>this.updateButtonDown(t))),this.canvas.addEventListener("mouseup",(t=>this.updateButtonUp(t))),this.canvas.addEventListener("wheel",(t=>this.handleWheelEvent(t))),this.canvas.addEventListener("focusout",(()=>this.onFocusOut()))}updateButtonDown(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0===t.button,this.scrollButtonPressed=1===t.button,this.rightButtonPressed=2===t.button}updateButtonUp(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}updatePosition(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)}handleWheelEvent(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t}onFocusOut(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1}onUpdate(){this.mouse.leftButtonPressed=this.leftButtonPressed,this.mouse.rightButtonPressed=this.rightButtonPressed,this.mouse.scrollButtonPressed=this.scrollButtonPressed,this.mouse.positionInViewport.copy(this.positionInViewport),this.positionInViewport.equals(this.lastPositionInViewport)?this.mouse.hasMoved=!1:(this.mouse.hasMoved=!0,this.lastPositionInViewport.copy(this.positionInViewport)),this.wheelEvent?(this.mouse.wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this.mouse.wheelScroll.set(0,0)}};Qt=r([i(G.MouseSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],Qt);let Jt=class{constructor(t,{touchScreen:e}){this.canvas=t,this.touching=!1,this.interactions=[],this.eventHandler=t=>{"touchstart"===t.type&&(this.touching=!0,this.updatePosition(t)),"touchmove"===t.type&&this.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(this.touching=!1)},this.touchScreen=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)}updatePosition(t){if(t.preventDefault(),t.stopPropagation(),this.interactions=[],0!==t.targetTouches.length)for(let e=0;e<t.targetTouches.length;e++)this.interactions[e]={positionInViewport:new n((t.targetTouches[e].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[e].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new n(t.targetTouches[e].radiusX,t.targetTouches[e].radiusY)}}onUpdate(){this.touchScreen.touching=this.touching,this.touchScreen.interactions=[...this.touchScreen.interactions]}};Jt=r([i(G.TouchScreenSystem),a(0,s(t.CanvasElement)),a(1,s(t.InputManager))],Jt);class Zt{constructor(t){this.animations=new Map,this.speed=1,this.reset=!1,this.playing=!1,this.currentFrame=0,this.currentTime=0,this._currentAnimation=void 0,Object.assign(this,t)}}class te{constructor(t){this.slice={size:new n,offset:new n,padding:new n},this.frames=[],this.fps=12,this.loop=!1,Object.assign(this,t)}}class ee{constructor(t){this.layer=q,this.smooth=!1,this.offset=new n,this.flipHorizontally=!1,this.flipVertically=!1,this.rotation=0,this.opacity=1,this.scale=new n(1,1),this._renderData={type:yt.Sprite,position:new n,layer:void 0,image:void 0,width:void 0,height:void 0},Object.assign(this,t)}}let ie=class{constructor(t,e){this.entityManager=t,this.timeManager=e}onUpdate(){this.entityManager.search(Zt).forEach((({entity:t,component:e})=>{if(this.reset(e),this.animation=e.animations.get(e.animation),!this.animation)return;this.play(e),e._currentAnimation=e.animation;const i=this.entityManager.getComponent(t,ee);i&&this.renderSprite(e,i)}))}reset(t){t.reset&&(t.currentFrame=0,t.currentTime=0,t.playing=void 0!==t.animation,t.reset=!1)}play(t){t.animation!==t._currentAnimation&&(t._currentAnimation=t.animation,t.currentFrame=0,t.currentTime=0,t.playing=!0),t.playing&&(t.currentTime>=1/this.animation.fps*(t.currentFrame+1)&&(t.currentFrame===this.animation.frames.length-1?this.animation.loop?(t.currentFrame=0,t.currentTime=0):t.playing=!1:t.currentFrame++),t.currentTime+=this.timeManager.renderDeltaTime*t.speed)}renderSprite(t,e){if(Array.isArray(this.animation.image))e.image=this.animation.image[t.currentFrame];else{const i=this.animation.frames[t.currentFrame],s=Math.floor(this.animation.image.naturalWidth/this.animation.slice.size.x);e.image=this.animation.image,e.slice={x:i%s*this.animation.slice.size.x+this.animation.slice.offset.x,y:Math.floor(i/s)*this.animation.slice.size.y+this.animation.slice.offset.y,width:this.animation.slice.size.x-this.animation.slice.padding.y,height:this.animation.slice.size.y-this.animation.slice.padding.y}}}};ie=r([i(G.AnimatorSystem),a(0,s(t.EntityManager)),a(1,s(t.TimeManager))],ie);let se=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(Q).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("Camera component needs a Transform");e._renderData.position.copy(i.localPosition),e._renderData.layers=e.layers,e._renderData.depth=e.depth,e._renderData.zoom=e.zoom,this.renderManager.addCameraData(e._renderData)}))}};se=r([i(G.CameraSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],se);let oe=class{constructor(t,e){this.webGLManager=t,this.gameConfig=e}onUpdate(){this.webGLManager.renderCanvasColor(this.gameConfig.canvasColor)}};oe=r([i(G.ClearScreenSystem),a(0,s(t.WebGLManager)),a(1,s(t.GameConfig))],oe);class re{constructor(t){this.radius=0,this.offset=new n,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class ae{constructor(t){this.layer="",this.physics=!0,this.width=0,this.height=0,this.offset=new n,this.rotation=0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class ne{constructor(t){this.vertexModel=[],this.offset=new n,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class he{constructor(t){this.vertexModel=[],this.offset=new n,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}class le{constructor(t){this.composite=!0,this.layer="",this.ignoreCollisionsWithLayers=[],this.offset=new n,this.physics=!0,this.shapes=[],Object.assign(this,t)}}let ce=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.collisionMethod=i.collisions.collisionMethod,this.debugEnabled=i.debugEnabled}onUpdate(){this.debugEnabled&&[re,ae,he,ne,le].forEach((t=>this.entityManager.search(t).forEach((({component:t})=>t.shapes.forEach((t=>{const e={type:yt.Geometric,position:new n,layer:q,color:"#00FF00",shape:void 0,radius:void 0,rotation:void 0,vertexModel:void 0};t instanceof M?this.collisionMethod===C.SAT?(e.shape=t.vertices.length>2?pt.Polygon:pt.Line,e.vertexModel=t.vertices):this.collisionMethod===C.AABB&&(e.shape=pt.Polygon,e.vertexModel=[new n(t.boundingBox.x,t.boundingBox.y),new n(t.boundingBox.x,t.boundingBox.y1),new n(t.boundingBox.x1,t.boundingBox.y1),new n(t.boundingBox.x1,t.boundingBox.y)]):t instanceof v&&(e.shape=pt.Circumference,e.position.copy(t.position),e.radius=t.radius),this.renderManager.addRenderData(e)}))))))}};ce=r([i(G.ColliderRenderSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager)),a(2,s(t.GameConfig))],ce);let de=class{constructor(t,e){this.renderManager=t,this.canvas=e,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0},this.culledRenderData=[]}onUpdate(){this.culledRenderData=[],this.renderManager.getCameraData().forEach((t=>{this.setViewport(t),this.renderManager.getRenderData().filter((e=>t.layers.includes(e.layer))).forEach((t=>{this.isInViewPort(t)&&(t.type===yt.Tilemap&&this.applyCullingInTiles(t),this.culledRenderData.push(t))}))})),this.renderManager.setRenderData(this.culledRenderData)}isInViewPort(t){switch(t.type){case yt.Video:case yt.Mask:case yt.Shadow:case yt.Sprite:this.setObjectForResizeable(t);break;case yt.Geometric:this.setObjectForGeometric(t);break;case yt.Text:this.setObjectForText(t);break;case yt.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}setViewport({position:t,zoom:e}){this.viewport.x=t.x-this.canvas.width/e/2,this.viewport.x1=t.x+this.canvas.width/e/2,this.viewport.y=t.y-this.canvas.height/e/2,this.viewport.y1=t.y+this.canvas.height/e/2}setObjectForResizeable({position:t,width:e,height:i,rotation:s=0}){const o=Math.abs(Math.sin(s)),r=Math.abs(Math.cos(s)),a=o*i+r*e,n=o*e+r*i;this.object.x=t.x-a/2,this.object.x1=t.x+a/2,this.object.y=t.y-n/2,this.object.y1=t.y+n/2}setObjectForText({position:t,text:e,fontSize:i,lineSeparation:s,letterSpacing:o,rotation:r}){const a=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=o?o:0))*2,n=e.split("\n").length*(i+(null!=s?s:0));this.setObjectForResizeable({position:t,width:a,height:n,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:s}){i===pt.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.position,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:o}}=t;t.tiles=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)*o+o)&&this.viewport.y<=this.object.y1-(e/i|0)*o?t:0))}};de=r([i(G.CullingSystem),a(0,s(t.RenderManager)),a(1,s(t.CanvasElement))],de);class me{constructor(t){this.width=0,this.height=0,this.radius=0,this.offset=new n,this.rotation=0,this.opacity=1,this.layer=q,this._renderData={type:yt.Mask,color:void 0,height:void 0,layer:void 0,opacity:void 0,position:new n,radius:void 0,rotation:void 0,shape:void 0,width:void 0},Object.assign(this,t)}}let ge=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(me).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("MaskRenderer component needs a Transform");this.scaledOffset.set(e.offset.x*i.localScale.x,e.offset.y*i.localScale.y),n.add(e._renderData.position,i.localPosition,this.scaledOffset),e._renderData.width=e.width*Math.abs(i.localScale.x),e._renderData.height=e.height*Math.abs(i.localScale.y),e._renderData.rotation=i.localRotation+e.rotation,e._renderData.color=e.color,e._renderData.layer=e.layer,e._renderData.opacity=e.opacity,e._renderData.radius=e.radius*Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)),e._renderData.shape=e.shape,0!==i.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,i),this.renderManager.addRenderData(e._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};ge=r([i(G.MaskRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],ge);let ue=class{constructor(t){this.renderManager=t}onUpdate(){this.renderManager.render(),this.renderManager.removeCameraData(),this.renderManager.removeRenderData()}};ue=r([i(G.RenderSystem),a(0,s(t.RenderManager))],ue);class pe{constructor(t){this.radius=0,this.smooth=!1,this.layer="",this.intensity=1,this._boundingBox=new h,Object.assign(this,t)}}class ye{constructor(t){this.width=0,this.height=0,this.color="#000000",this.opacity=1,this.layer="",this._boundingBox=new h,this._renderData={type:yt.Shadow,layer:void 0,color:void 0,opacity:void 0,width:void 0,height:void 0,position:void 0,rotation:void 0,lights:[]},Object.assign(this,t)}}let fe=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){const t=this.entityManager.search(pe);t.forEach((({entity:t,component:e})=>this.updateLightRendererBoundingBox(t,e))),this.entityManager.search(ye).forEach((({entity:e,component:i})=>{this.updatShadowRendererBoundingBox(e,i),i._renderData.layer=i.layer,i._renderData.color=i.color,i._renderData.opacity=i.opacity,i._renderData.width=i._boundingBox.width,i._renderData.height=i._boundingBox.height,i._renderData.position=i._boundingBox.center,i._renderData.rotation=0,i._renderData.lights=[],i._renderData.lights=t.filter((({component:t})=>t.layer===i.layer&&t._boundingBox.overlaps(i._boundingBox))).map((({component:{_boundingBox:t,smooth:e,intensity:i}})=>({position:t.center,radius:t.width/2,smooth:e,intensity:i}))),this.renderManager.addRenderData(i._renderData)}))}updateLightRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("LightRenderer component needs a Transform");const s=e.radius*Math.abs(Math.max(i.localScale.x,i.localScale.y));e._boundingBox.set(i.localPosition.x-s,i.localPosition.y-s,2*s,2*s)}updatShadowRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("ShadowRenderer component needs a Transform");const s=e.width*Math.abs(i.localScale.x),o=e.height*Math.abs(i.localScale.y);e._boundingBox.set(i.localPosition.x-s/2,i.localPosition.y-o/2,s,o)}};fe=r([i(G.ShadowLightRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],fe);let xe=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(ee).forEach((({component:t,entity:e})=>{var i,s,o,r,a,h;const l=this.entityManager.getComponent(e,K);if(!l)throw new Error("SpriteRenderer component needs a Transform");t.image&&t.image.complete&&(this.scaledOffset.set(t.offset.x*l.localScale.x,t.offset.y*l.localScale.y),n.add(t._renderData.position,l.localPosition,this.scaledOffset),t._renderData.width=(null!==(o=null!==(i=t.width)&&void 0!==i?i:null===(s=t.slice)||void 0===s?void 0:s.width)&&void 0!==o?o:t.image.naturalWidth)*Math.abs(t.scale.x*l.localScale.x),t._renderData.height=(null!==(h=null!==(r=t.height)&&void 0!==r?r:null===(a=t.slice)||void 0===a?void 0:a.height)&&void 0!==h?h:t.image.naturalHeight)*Math.abs(t.scale.y*l.localScale.y),t._renderData.flipHorizontally=t.flipHorizontally!==l.scale.x<0,t._renderData.flipVertically=t.flipVertically!==l.scale.y<0,t._renderData.rotation=l.localRotation+t.rotation,0!==l.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,l),t._renderData.image=t.image,t._renderData.layer=t.layer,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.opacity=t.opacity,t._renderData.slice=t.slice,t._renderData.smooth=t.smooth,t._renderData.tintColor=t.tintColor,this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};xe=r([i(G.SpriteRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],xe);class Me{constructor(t){this.layer=q,this.text="Hello World!",this.font="Arial",this.fontSize=16,this.width=160,this.height=16,this.offset=new n,this.color="#000000",this.lineSeparation=0,this.letterSpacing=0,this.charRanges=[32,126,161,255],this.smooth=!1,this.rotation=0,this.opacity=1,this.orientation=Ct.Center,this.bitmapMargin=new n,this.bitmapSpacing=new n,this._renderData={type:yt.Text,position:new n,layer:void 0,text:void 0,color:void 0,font:void 0,fontSize:void 0,opacity:void 0,smooth:void 0,rotation:void 0,orientation:void 0,letterSpacing:void 0,lineSeparation:void 0,bitmap:{charRanges:void 0,fontSize:64,margin:void 0,spacing:void 0}},Object.assign(this,t)}}let ve=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.scaledOffset=new n}onUpdate(){this.entityManager.search(Me).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("TextRenderer component needs a Transform");0===e.text.length||e.font instanceof FontFace&&"loaded"!==e.font.status||(this.scaledOffset.set(e.offset.x*i.localScale.x,e.offset.y*i.localScale.y),n.add(e._renderData.position,i.localPosition,this.scaledOffset),e._renderData.layer=e.layer,e._renderData.font=e.font,e._renderData.fontSize=e.fontSize,e._renderData.text=this.crop(e),e._renderData.orientation=e.orientation,e._renderData.color=e.color,e._renderData.lineSeparation=e.lineSeparation,e._renderData.letterSpacing=e.letterSpacing,e._renderData.smooth=e.smooth,e._renderData.rotation=i.localRotation+e.rotation,e._renderData.opacity=e.opacity,e._renderData.bitmap.charRanges=e.charRanges,e._renderData.bitmap.margin=e.bitmapMargin,e._renderData.bitmap.spacing=e.bitmapSpacing,0!==i.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(e._renderData,i),this.renderManager.addRenderData(e._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}crop({fontSize:t,height:e,text:i,letterSpacing:s,width:o,lineSeparation:r}){if(t>e)return"";const a=[];let n=0;for(const h of i.split("\n")){const i=h.split(/(\s+)/).reduce(((e,i)=>{const r=e.length-1,a=e[r]+i;return a.length*(t+s)>o?e.push(i):e[r]=a,e}),[""]);for(const s of i){if(n+=t+r,n>e)return a.join("\n");a.push(s)}}return a.join("\n")}};ve=r([i(G.TextRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],ve);let Se=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search(zt).forEach((({entity:t,component:e})=>{const i=this.entityManager.getComponent(t,K);if(!i)throw new Error("TilemapRenderer component needs a Transform");e._processed&&e.tileset.image&&e.tileset.image.complete&&e.chunks.forEach(((t,s)=>{e._renderData[s]||(e._renderData[s]=Ce());const o=e._renderData[s];o.type=yt.Tilemap,o.orientation=wt.Center,o.position=new n,o.layer=e.layer,o.tilemap.width=t.width,o.tilemap.height=Math.ceil(e.data.length/t.width),o.tilemap.tileWidth=e.tileWidth*Math.abs(i.localScale.x),o.tilemap.tileHeight=e.tileHeight*Math.abs(i.localScale.y),o.tilemap.realWidth=o.tilemap.width*o.tilemap.tileWidth,o.tilemap.realHeight=o.tilemap.height*o.tilemap.tileHeight,o.tiles=t.data,o.tileset=e.tileset,o.opacity=e.opacity,o.rotation=i.localRotation,o.tintColor=e.tintColor,o.smooth=e.smooth,o.position.x=i.localPosition.x+(t.x-e.width/2+t.width/2)*o.tilemap.tileWidth,o.position.y=i.localPosition.y+(e.height/2-t.y-t.height/2)*o.tilemap.tileHeight,this.renderManager.addRenderData(o)}))}))}};Se=r([i(G.TilemapRendererSystem),a(0,s(t.EntityManager)),a(1,s(t.RenderManager))],Se);const Ce=()=>({type:yt.Tilemap,layer:void 0,position:new n,tilemap:{height:void 0,realHeight:void 0,realWidth:void 0,tileHeight:void 0,tileWidth:void 0,width:void 0},tiles:void 0,tileset:void 0});var be;!function(t){t[t.Dynamic=0]="Dynamic",t[t.Static=1]="Static"}(be||(be={}));class we{constructor(t){this.type=be.Dynamic,this.velocity=new n,this.gravity=0,this.acceleration=new n,Object.assign(this,t)}}let _e=class{constructor(t,e,i){this.entityManager=t,this.timeManager=e,this.transformSystem=i,this.distance=new n}onUpdate(){this.entityManager.search(we,{type:be.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,K);t.velocity.y-=t.gravity*this.timeManager.physicsDeltaTime,n.add(i.position,i.position,n.scale(this.distance,n.add(t.velocity,t.velocity,t.acceleration),this.timeManager.physicsDeltaTime))})),this.transformSystem.onUpdate()}};_e=r([i(G.ApplyVelocitySystem),a(0,s(t.EntityManager)),a(1,s(t.TimeManager)),a(2,s(G.TransformSystem))],_e);class Ee{constructor(){this.auxMin=new n,this.auxMax=new n,this.auxScaledOffset=new n}updatePositionAndVertices(t,e,i){this.translatePosition(t,e,i),t instanceof M?(this.auxAngle=t.rotation+i.localRotation,t.vertexModel.forEach(((e,s)=>t.vertices[s].set(e.x*i.localScale.x,e.y*i.localScale.y))),t.vertices.forEach((e=>e.set(e.x*Math.cos(this.auxAngle)-e.y*Math.sin(this.auxAngle)+t.position.x,e.x*Math.sin(this.auxAngle)+e.y*Math.cos(this.auxAngle)+t.position.y)))):t instanceof v&&(t.radius*=Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)))}translatePosition(t,e,{localPosition:i,localScale:s,localRotation:o}){if(this.auxScaledOffset.set(e.x*s.x,e.y*s.y),0!==o){const e=Math.atan2(this.auxScaledOffset.y,this.auxScaledOffset.x)+o;t.position.set(i.x+this.auxScaledOffset.magnitude*Math.cos(e),i.y+this.auxScaledOffset.magnitude*Math.sin(e))}else n.add(t.position,i,this.auxScaledOffset)}updateBoundingBox(t){t instanceof v?this.updateCircumferenceBoundingBox(t):t instanceof M&&this.updatePolygonBoundingBox(t)}updateCircumferenceBoundingBox(t){t.boundingBox.set(t.position.x-t.radius,t.position.y-t.radius,2*t.radius,2*t.radius)}updatePolygonBoundingBox(t){this.auxMin.x=t.vertices[0].x,this.auxMin.y=t.vertices[0].y,this.auxMax.x=t.vertices[0].x,this.auxMax.y=t.vertices[0].y,t.vertices.forEach((t=>{this.auxMin.x=Math.min(t.x,this.auxMin.x),this.auxMin.y=Math.min(t.y,this.auxMin.y),this.auxMax.x=Math.max(t.x,this.auxMax.x),this.auxMax.y=Math.max(t.y,this.auxMax.y)})),t.boundingBox.set(this.auxMin.x,this.auxMin.y,this.auxMax.x-this.auxMin.x,this.auxMax.y-this.auxMin.y)}updateProjectionAxes(t){var e;if(t.vertices.length>2)for(let i=0;i<t.vertices.length;i++)n.normal(t.projectionAxes[i],n.subtract(t.projectionAxes[i],null!==(e=t.vertices[i+1])&&void 0!==e?e:t.vertices[0],t.vertices[i]));else n.normal(t.projectionAxes[0],n.subtract(t.projectionAxes[0],t.vertices[1],t.vertices[0]))}}let Re=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(re).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new v(t.radius)),t.shapes[0].radius=t.radius,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Re=r([i(G.UpdateBallColliderShapeSystem),a(0,s(t.EntityManager))],Re);let Ae=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(ae).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new M([new n,new n,new n,new n])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel[0].set(-t.width/2,-t.height/2),t.shapes[0].vertexModel[1].set(-t.width/2,t.height/2),t.shapes[0].vertexModel[2].set(t.width/2,t.height/2),t.shapes[0].vertexModel[3].set(t.width/2,-t.height/2),this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Ae=r([i(G.UpdateBoxColliderShapeSystem),a(0,s(t.EntityManager))],Ae);let Te=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(ne).forEach((({component:t,entity:e})=>{for(let i=0;i<t.vertexModel.length-1;i++)t.shapes[i]||(t.shapes[i]=new M([new n,new n])),t.shapes[i].rotation=t.rotation,t.shapes[i].vertexModel=[t.vertexModel[i],t.vertexModel[i+1]],this.updatePositionAndVertices(t.shapes[i],t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(t.shapes[i]),this.updateProjectionAxes(t.shapes[i])}))}};Te=r([i(G.UpdateEdgeColliderShapeSystem),a(0,s(t.EntityManager))],Te);let De=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(he).forEach((({component:t,entity:e})=>{0===t.shapes.length&&(t.shapes[0]=new M([])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel=t.vertexModel,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};De=r([i(G.UpdatePolygonColliderShapeSystem),a(0,s(t.EntityManager))],De);let Be=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(le).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,zt);if(i&&0!==i.data.length){0===t.shapes.length&&(t.composite?this.useEdges(t,i):this.useBoxes(t,i));for(const i of t.shapes)this.updatePositionAndVertices(i,t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(i),this.updateProjectionAxes(i)}}))}useBoxes(t,e){t.shapes=[],e.data.forEach(((i,s)=>{if(!this.needsCollider(i,s,e))return;const o=new M(this.generateRectangleVertices(s,e));o.updateCollisions=!1,t.shapes.push(o)}))}generateRectangleVertices(t,{width:e,height:i,tileWidth:s,tileHeight:o}){const r=-e*s/2+t%e*s,a=i*o/2-Math.floor(t/e)*o;return[new n(r,a-o),new n(r,a),new n(r+s,a),new n(r+s,a-o)]}needsCollider(t,e,{data:i,width:s,height:o}){return 0!==t&&this.getNeighbors(e,s,o).some((t=>!t||!i[t]||0===i[t]))}useEdges(t,e){t.shapes=[];const i=[],s=[];let o,r;e.data.forEach(((t,o)=>{if(0===t)return;const r=o%e.width,a=Math.floor(o/e.width);i[a]||(i[a]=[]),i[a+1]||(i[a+1]=[]),s[a]||(s[a]=[]),s[a+1]||(s[a+1]=[]);const n=this.getNeighbors(o,e.width,e.height);this.hasTile(n[0],e)||(i[a][r]=!0),this.hasTile(n[2],e)||(i[a+1][r]=!0),this.hasTile(n[1],e)||(s[a][r]=!0),this.hasTile(n[3],e)||(s[a][r+1]=!0)}));for(let s=0;s<i.length;s++)if(i[s])for(let a=0;a<i[s].length;a++)!o||!r||s===r.y&&i[s][a]||(t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0),i[s][a]&&(o||(o=new n(a,s)),r=new n(a+1,s));o&&r&&t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0;for(let i=0;i<=e.width;i++)for(let a=0;a<s.length;a++)s[a]&&(!o||!r||i===r.x&&s[a][i]||(t.shapes.push(this.createEdge(o,r,e)),o=void 0,r=void 0),s[a][i]&&(o||(o=new n(i,a)),r=new n(i,a+1)));o&&r&&t.shapes.push(this.createEdge(o,r,e))}hasTile(t,{data:e}){return void 0!==t&&e[t]&&e[t]>0}createEdge(t,e,{width:i,height:s,tileWidth:o,tileHeight:r}){t.x=-i*o/2+t.x*o,t.y=s*r/2-t.y*r,e.x=-i*o/2+e.x*o,e.y=s*r/2-e.y*r;const a=new M([new n(t.x,t.y),new n(e.x,e.y)]);return a.updateCollisions=!1,a}getNeighbors(t,e,i){return[t-e>=0?t-e:void 0,t%e>0?t-1:void 0,t+e<=e*i?t+e:void 0,t%e<e-1?t+1:void 0]}};Be=r([i(G.UpdateTilemapColliderShapeSystem),a(0,s(t.EntityManager))],Be);let Pe=class{constructor(t,e,i,s,o){this.entityManager=t,this.broadPhaseResolver=e,this.collisionMatrix=i,this.collisionResolutionMethod=s,this.collisionRepository=o,this.colliders=[],this.collisions=new Set,this.shapes=[]}onUpdate(){this.collisionRepository.removeAll(),this.colliders=[],this.collisions.clear(),this.shapes=[],[re,ae,he,ne,le].forEach((t=>this.entityManager.search(t).forEach((({component:t,entity:e})=>{this.colliders.push(t),t.shapes.forEach((i=>{var s;i.entity=e,i.collider=this.colliders.length-1,i.id=this.shapes.length,i.ignoreCollisionsWithLayers=null!==(s=t.ignoreCollisionsWithLayers)&&void 0!==s?s:[],i.layer=t.layer,this.shapes.push(i)}))})))),this.broadPhaseResolver.update(this.shapes),this.shapes.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase({boundingBox:t,layer:e}){return this.collisionMatrix?this.broadPhaseResolver.retrieve(t).map((t=>this.shapes[t])).filter((t=>this.collisionMatrix.some((i=>i[0]===e&&i[1]===t.layer||i[1]===e&&i[0]===t.layer)))):this.broadPhaseResolver.retrieve(t).map((t=>this.shapes[t]))}narrowPhase(t,e){e.filter((e=>t.entity!==e.entity&&t.id!==e.id&&!t.ignoreCollisionsWithLayers.includes(e.layer)&&!e.ignoreCollisionsWithLayers.includes(t.layer)&&!this.isResolved(t,e))).forEach((e=>{const i=this.collisionResolutionMethod.findCollision(t,e);i&&(this.collisionRepository.persist({localCollider:this.colliders[t.collider],localEntity:t.entity,remoteCollider:this.colliders[e.collider],remoteEntity:e.entity,resolution:i}),this.collisionRepository.persist({localCollider:this.colliders[e.collider],localEntity:e.entity,remoteCollider:this.colliders[t.collider],remoteEntity:t.entity,resolution:{direction:n.scale(new n,i.direction,-1),penetration:i.penetration}}),this.collisions.add(`${t.id}-${e.id}`),this.collisions.add(`${e.id}-${t.id}`))}))}isResolved(t,e){return this.collisions.has(`${t.id}-${e.id}`)}};Pe=r([i(G.ResolveCollisionSystem),a(0,s(t.EntityManager)),a(1,s(t.CollisionBroadphaseResolver)),a(2,s(t.CollisionMatrix)),a(3,s(t.CollisionResolutionMethod)),a(4,s(t.CollisionRepository))],Pe);let Ue=class{constructor(t,e,i){this.entityManager=t,this.collisionRepository=e,this.transformSystem=i,this.displacement=new n}onUpdate(){this.entityManager.search(we,{type:be.Dynamic}).forEach((({component:t,entity:e})=>{const i=this.entityManager.getComponent(e,K),s=[e,...i._childEntities];this.displacement.set(0,0),this.collisionRepository.findAll().filter((({localCollider:t,localEntity:e})=>s.includes(e)&&t.physics)).forEach((({resolution:{direction:t,penetration:e}})=>{e>this.displacement.magnitude&&n.scale(this.displacement,t,-e)})),0!==this.displacement.magnitude&&(n.add(i.position,i.position,this.displacement),this.displacement.x*t.velocity.x<0&&(t.velocity.x=0),this.displacement.y*t.velocity.y<0&&(t.velocity.y=0))})),this.transformSystem.onUpdate()}};Ue=r([i(G.ApplyRepositionSystem),a(0,s(t.EntityManager)),a(1,s(t.CollisionRepository)),a(2,s(G.TransformSystem))],Ue);let Fe=class extends Ee{constructor(t){super(),this.entityManager=t}onUpdate(){[re,ae,he,ne,le].forEach((t=>this.entityManager.search(t,{updateCollisions:!0}).forEach((({component:t,entity:e})=>t.shapes.forEach((i=>{this.updatePositionAndVertices(i,t.offset,this.entityManager.getComponent(e,K)),this.updateBoundingBox(i)}))))))}};Fe=r([i(G.UpdateCollidersAfterRepositionSystem),a(0,s(t.EntityManager))],Fe);const Le=new Map([[H.PreGameLogic,[{name:G.KeyboardSystem,type:qt},{name:G.MouseSystem,type:Qt},{name:G.TouchScreenSystem,type:Jt},{name:G.GamepadSystem,type:Kt},{name:G.ButtonSystem,type:jt},{name:G.AudioPlayerSystem,type:z},{name:G.TiledWrapperSystem,type:Ht},{name:G.TilemapPreProcessingSystem,type:Yt}]],[H.PostGameLogic,[{name:G.TransformSystem,type:$t},{name:G.ChildrenSystem,type:Ot},{name:G.ParentSystem,type:Gt}]],[H.Physics,[{name:G.ApplyVelocitySystem,type:_e},{name:G.UpdateBallColliderShapeSystem,type:Re},{name:G.UpdateBoxColliderShapeSystem,type:Ae},{name:G.UpdateEdgeColliderShapeSystem,type:Te},{name:G.UpdatePolygonColliderShapeSystem,type:De},{name:G.UpdateTilemapColliderShapeSystem,type:Be},{name:G.ResolveCollisionSystem,type:Pe},{name:G.ApplyRepositionSystem,type:Ue},{name:G.UpdateCollidersAfterRepositionSystem,type:Fe}]],[H.Render,[{name:G.AnimatorSystem,type:ie},{name:G.CameraSystem,type:se},{name:G.TilemapRendererSystem,type:Se},{name:G.SpriteRendererSystem,type:xe},{name:G.MaskRendererSystem,type:ge},{name:G.ShadowLightRendererSystem,type:fe},{name:G.TextRendererSystem,type:ve},{name:G.VideoRendererSystem,type:Pt},{name:G.ColliderRenderSystem,type:ce},{name:G.CullingSystem,type:de},{name:G.ClearScreenSystem,type:oe},{name:G.RenderSystem,type:ue}]]]);let Ie=class{constructor(t,e,i){this.timeManager=t,this.systemManager=e,this.sceneManager=i,this.running=!1,this.gameLoopAccumulator=0}start(){this.running||(this.running=!0,this.gameLoopAccumulator=0,this.enableSystems(),this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.asyncPhysicsLoop())}enableSystems(){Le.forEach((t=>{t.forEach((t=>this.systemManager.enableSystem(t.type)))}))}stop(){this.running=!1}requestAnimationLoop(t){this.running&&(this.timeManager.updateForRender(.001*t),this.sceneManager.update(),this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.gameLoopAccumulator>=this.timeManager.fixedGameDeltaTime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.fixedGameDeltaTime),this.renderIteration(),window.requestAnimationFrame((t=>this.requestAnimationLoop(t))))}gameLogicIteration(t){this.timeManager.updateForGame(t),this.systemManager.update(H.PreGameLogic),this.systemManager.update(H.GameLogic),this.systemManager.update(H.PostGameLogic)}renderIteration(){this.systemManager.update(H.GamePreRender),this.systemManager.update(H.Render)}asyncPhysicsLoop(){this.physicsIntervalId=window.setInterval((()=>{if(!this.running)return window.clearInterval(this.physicsIntervalId);this.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||this.physicsIteration()}),1e3/this.timeManager.fixedPhysicsFramerate)}physicsIteration(){this.timeManager.timeScale<=0||(this.systemManager.update(H.GamePhysics),this.systemManager.update(H.Physics))}};Ie=r([i(t.LoopManager),a(0,s(t.TimeManager)),a(1,s(t.SystemManager)),a(2,s(t.SceneManager))],Ie);class je{constructor(t,e){this.container=t,this.systemManager=e,this.lastSystemTypeId=0}createSystemIfNotExists(t){if(this.systemManager.hasSystem(t))return;const e="__system_"+this.lastSystemTypeId++;var i;this.container.add(t,e),this.systemManager.addSystem(this.container.get(e),null!==(i=t.prototype.__system_group)&&void 0!==i?i:H.GameLogic)}}let ke=class{constructor(t){this.webGLManager=t,this.renderData=[],this.cameraData=[]}addCameraData(t){this.cameraData.push(t)}addRenderData(t){this.renderData.push(t)}setRenderData(t){this.renderData=t}getCameraData(){return this.cameraData}getRenderData(){return this.renderData}removeCameraData(){this.cameraData=[]}removeRenderData(){this.renderData=[]}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).forEach((e=>this.webGLManager.render(e,t)))))}};ke=r([i(t.RenderManager),a(0,s(t.WebGLManager))],ke);const Oe=t=>{var e,i,s,r,a,n,h,l;if(!(t.containerNode instanceof HTMLElement))throw new Error("GameConfig Error: Invalid containerNode");if("number"!=typeof t.width)throw new Error("GameConfig Error: Invalid width");if("number"!=typeof t.height)throw new Error("GameConfig Error: Invalid height");t.debugEnabled=null!==(e=t.debugEnabled)&&void 0!==e&&e,t.canvasColor=null!==(i=t.canvasColor)&&void 0!==i?i:"#000000",t.physicsFramerate=null!==(s=t.physicsFramerate)&&void 0!==s?s:180,t.headless=null!==(r=t.headless)&&void 0!==r&&r,t.collisions=null!==(a=t.collisions)&&void 0!==a?a:{},t.collisions.collisionBroadPhaseMethod=null!==(n=t.collisions.collisionBroadPhaseMethod)&&void 0!==n?n:o.SpartialGrid,t.collisions.collisionMatrix=null!==(h=t.collisions.collisionMatrix)&&void 0!==h?h:void 0,t.collisions.collisionMethod=null!==(l=t.collisions.collisionMethod)&&void 0!==l?l:C.SAT},Ve=({containerNode:t,width:e,height:i})=>{const s=document.createElement("canvas");return s.id="angryPixelGameCanvas",s.width=Math.floor(e),s.height=Math.floor(i),s.tabIndex=0,s.addEventListener("contextmenu",(t=>t.preventDefault())),t.appendChild(s),s.focus(),s},Ge=e=>{e.add(T),e.add(D),e.set(t.SystemFactory,new je(e,e.get(t.SystemManager))),e.add(j),e.add(O),e.add(L),e.add(Ft),e.add(L),e.add(Ie),e.add(Tt),e.add(ke)},We=e=>{e.get(t.GameConfig).headless&&ze(Le),Le.forEach(((i,s)=>i.forEach((({type:i,name:o})=>{e.add(i),e.get(t.SystemManager).addSystem(e.get(o),s)}))))},ze=t=>{t.delete(H.Render),t.set(H.PreGameLogic,t.get(H.PreGameLogic).filter((({name:t})=>![G.AudioPlayerSystem,G.ButtonSystem,G.GamepadSystem,G.KeyboardSystem,G.MouseSystem,G.TouchScreenSystem].includes(t))))},He=e=>{const{collisions:{collisionBroadPhaseMethod:i,collisionMatrix:s,collisionMethod:r}}=e.get(t.GameConfig);e.add(A),e.add(E),r===C.AABB?(e.add(w),e.add(_)):e.add(R),e.add(i===o.QuadTree?y:x),e.add(r===C.AABB?S:b),e.set(t.CollisionMatrix,s)};class Ne{constructor(i){this.container=(i=>{Oe(i);const s=new e;return s.set(t.GameConfig,i),s.set(t.CanvasElement,Ve(i)),He(s),Ge(s),We(s),s})(i)}get running(){return this.container.get(t.LoopManager).running}addScene(e,i,s=!1){this.container.get(t.SceneManager).addScene(e,i,s)}addDependencyType(t,e){this.container.add(t,e)}addDependencyInstance(t,e){this.container.set(e,t)}start(){this.container.get(t.LoopManager).start()}stop(){this.container.get(t.LoopManager).stop()}}class Ye{onUpdate(){}}r([s(t.EntityManager)],Ye.prototype,"entityManager",void 0),r([s(t.AssetManager)],Ye.prototype,"assetManager",void 0),r([s(t.SceneManager)],Ye.prototype,"sceneManager",void 0),r([s(t.TimeManager)],Ye.prototype,"timeManager",void 0),r([s(t.InputManager)],Ye.prototype,"inputManager",void 0),r([s(t.CollisionRepository)],Ye.prototype,"collisionRepository",void 0);const Xe={AssetManager:t.AssetManager,CanvasElement:t.CanvasElement,CollisionRepository:t.CollisionRepository,EntityManager:t.EntityManager,GameConfig:t.GameConfig,InputManager:t.InputManager,SceneManager:t.SceneManager,SystemManager:t.SystemManager,TimeManager:t.TimeManager};export{te as Animation,Zt as Animator,O as AssetManager,V as AudioPlayer,re as BallCollider,ae as BoxCollider,o as BroadPhaseMethods,Lt as Button,It as ButtonShape,Q as Camera,kt as Children,v as Circumference,C as CollisionMethods,A as CollisionRepository,ne as EdgeCollider,T as EntityManager,Ne as Game,Ye as GameSystem,B as GamepadController,L as InputManager,P as Keyboard,pe as LightRenderer,me as MaskRenderer,ft as MaskShape,U as Mouse,Vt as Parent,M as Polygon,he as PolygonCollider,h as Rectangle,we as RigidBody,be as RigidBodyType,Ut as Scene,Ft as SceneManager,ye as ShadowRenderer,ee as SpriteRenderer,Xe as Symbols,D as SystemManager,Ct as TextOrientation,Me as TextRenderer,Wt as TiledWrapper,le as TilemapCollider,wt as TilemapOrientation,zt as TilemapRenderer,j as TimeManager,F as TouchScreen,K as Transform,n as Vector2,Dt as VideoRenderer,u as between,l as clamp,q as defaultRenderLayer,m as fixedRound,N as gameLogicSystem,Y as gamePhysicsSystem,X as gamePreRenderSystem,s as inject,i as injectable,d as randomFloat,c as randomInt,g as range};
2
2
  //# sourceMappingURL=index.esm.js.map