UNPKG

@moderrkowo/jsgl

Version:

Client-side JavaScript library for creating web 2D games. Focusing at objective game.

1 lines 58.1 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.JSGL=e():t.JSGL=e()}(self,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t){return t|t}function r(t,e,n){return t>=e&&t<=n}function o(t,e,n){return Math.min(n,Math.max(e,t))}function i(t){return o(t,0,1)}function a(t,e,n){return t*(1-n)+e*n}function s(t,e,n){return i((n-t)/(e-t))}function u(t,e,n,r,o){return a(n,r,s(t,e,o))}function c(t,e){return n(Math.random()*(e-t))+t}function l(t){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},l(t)}function f(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==l(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==l(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===l(o)?o:String(o)),r)}var o}t.r(e),t.d(e,{Clamp:()=>o,Clamp01:()=>i,ClickableGameObject:()=>F,DefaultGame:()=>ne,DrawableGameObject:()=>I,ExampleHTML:()=>Rt,Game:()=>Kt,GameObject:()=>T,Input:()=>Ut,InvertedLerp:()=>s,IsInRange:()=>r,Lerp:()=>a,RandomInRange:()=>c,Range:()=>u,Renderer:()=>Lt,Rotation:()=>v,RotationStyle:()=>j,RotationType:()=>m,Shape:()=>tt,ShapeType:()=>S,Signals:()=>E,SimpleShape:()=>ut,SimpleSprite:()=>wt,Sprite:()=>mt,Transform:()=>g,Vector2:()=>y,author:()=>ue,defaultDrawSettings:()=>N,defaultGameSettings:()=>O,error:()=>ae,floor:()=>n,license:()=>se,log:()=>oe,msg:()=>re,warn:()=>ie});var y=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"number"!=typeof e)throw new Error("X must be an number!");if("number"!=typeof n)throw new Error("Y must be an number!");this.x=e,this.y=n}var e,o,i;return e=t,i=[{key:"Lerp",value:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return new t(a(e.x,n.x,r),a(e.y,n.y,r))}},{key:"Max",value:function(e,n){return new t(Math.max(e.x,n.x),Math.max(e.y,n.y))}},{key:"Min",value:function(e,n){return new t(Math.min(e.x,n.x),Math.min(e.y,n.y))}},{key:"IsPointIn",value:function(t,e,n){return r(n.x,t.x,e.x)&&r(n.y,t.y,e.y)}},{key:"Equal",value:function(e,n){return void 0!==e&&void 0!==n&&e instanceof t&&n instanceof t&&e.x===n.x&&e.y===n.y}},{key:"zero",get:function(){return new t(0,0)}},{key:"one",get:function(){return new t(1,1)}},{key:"up",get:function(){return new t(0,1)}},{key:"down",get:function(){return new t(0,-1)}},{key:"right",get:function(){return new t(1,0)}},{key:"left",get:function(){return new t(-1,0)}}],(o=[{key:"magnitude",get:function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))}},{key:"set",value:function(e,n){return void 0===e||(e instanceof t?(this.x=e.x,this.y=e.y):"number"==typeof e&&(this.x=e,this.y=void 0!==n&&"number"==typeof n?n:0)),this}},{key:"add",value:function(e,n){return e instanceof t?(this.x+=e.x,this.y+=e.y):"number"==typeof e&&void 0!==n&&"number"==typeof n&&(this.x+=e,this.y+=n),this}},{key:"subtract",value:function(e,n){return e instanceof t?(this.x-=e.x,this.y-=e.y):"number"==typeof e&&void 0!==n&&"number"==typeof n&&(this.x-=e,this.y-=n),this}},{key:"multiply",value:function(e){return e instanceof t?(this.x*=e.x,this.y*=e.y):"number"==typeof e&&(this.x*=e,this.y*=e),this}},{key:"divide",value:function(e){return e instanceof t?(this.x/=e.x,this.y/=e.y):"number"==typeof e&&(this.x/=e,this.y/=e),this}},{key:"distance",value:function(e,n){if(e instanceof t)return Math.sqrt(Math.pow(Math.abs(this.x-e.x),2)+Math.pow(Math.abs(this.y-e.y),2));if("number"==typeof e&&void 0!==n&&"number"==typeof n)return Math.sqrt(Math.pow(Math.abs(this.x-e),2)+Math.pow(Math.abs(this.y-n),2));throw new Error("Invalid params!")}},{key:"floor",value:function(){return this.x=n(this.x),this.y=n(this.y),this}},{key:"equal",value:function(e){return void 0!==e&&e instanceof t&&this.x===e.x&&this.y===e.y}},{key:"clone",value:function(){return new t(this.x,this.y)}}])&&f(e.prototype,o),i&&f(e,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();function h(t){return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},h(t)}function p(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==h(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==h(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===h(o)?o:String(o)),r)}var o}var m=function(t){return t.DEGREES="DEGREES",t.RADIANS="RADIANS",t}({}),v=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{type:m.DEGREES,value:0};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e.type===m.DEGREES)this._value=e.value;else{if(e.type!==m.RADIANS)throw new Error("Cannot recognize rotation type!");this._value=t.ToDegrees(e.value)}}var e,n,r;return e=t,r=[{key:"right",get:function(){return new t({type:m.DEGREES,value:0})}},{key:"down",get:function(){return new t({type:m.DEGREES,value:90})}},{key:"left",get:function(){return new t({type:m.DEGREES,value:-180})}},{key:"up",get:function(){return new t({type:m.DEGREES,value:-90})}},{key:"ToRadians",value:function(t){return t%360*Math.PI/180}},{key:"ToDegrees",value:function(t){return t/Math.PI*180}}],(n=[{key:"angles",get:function(){return t.ToRadians(this._value)},set:function(e){this._value=t.ToDegrees(e)}},{key:"eulerAngles",get:function(){return this._value},set:function(t){this._value=t}}])&&p(e.prototype,n),r&&p(e,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();function b(t){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},b(t)}function d(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==b(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==b(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===b(o)?o:String(o)),r)}var o}var g=function(){function t(e,n,r,o){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.position=new y(e,n),this.scale=new y(r,o),this.rotation=new v({type:m.DEGREES,value:i})}var e,n;return e=t,(n=[{key:"angles",get:function(){return this.rotation.angles},set:function(t){this.rotation.angles=t}},{key:"eulerAngles",get:function(){return this.rotation.eulerAngles},set:function(t){this.rotation.eulerAngles=t}},{key:"positionCenter",get:function(){var t=this.position.x+this.scale.x/2,e=this.position.y+this.scale.y/2;return new y(t,e)}},{key:"forward",get:function(){var t=v.ToRadians(this.rotation.eulerAngles);return new y(Math.cos(t),Math.sin(t))}},{key:"backward",get:function(){return this.forward.multiply(-1)}},{key:"bounce",value:function(){this.rotation.eulerAngles+=180}},{key:"ifOnEdgeBounce",value:function(t){var e=t.clone().subtract(new y(this.scale.x,this.scale.y));!y.IsPointIn(new y,e,this.position)&&(this.position.x=o(this.position.x,0,t.x-this.scale.x),this.position.y=o(this.position.y,0,t.y-this.scale.y),this.bounce())}},{key:"set",value:function(t,e){void 0!==t&&(t instanceof y?(this.position.x=t.x,this.position.y=t.y):"number"==typeof t&&void 0!==e&&"number"==typeof e&&(this.position.x=t,this.position.y=e))}},{key:"setX",value:function(t){void 0!==t&&(t instanceof y?this.position.x=t.x:"number"==typeof t&&(this.position.x=t))}},{key:"setY",value:function(t){void 0!==t&&(t instanceof y?this.position.y=t.y:"number"==typeof t&&(this.position.y=t))}},{key:"translate",value:function(t,e){void 0!==t&&(t instanceof y?(this.position.x+=t.x,this.position.y+=t.y):"number"==typeof t&&void 0!==e&&"number"==typeof e&&(this.position.x+=t,this.position.y+=e))}},{key:"translateX",value:function(t){void 0!==t&&(t instanceof y?this.position.x+=t.x:"number"==typeof t&&(this.position.x+=t))}},{key:"translateY",value:function(t){void 0!==t&&(t instanceof y?this.position.y+=t.y:"number"==typeof t&&(this.position.y+=t))}},{key:"clone",value:function(){return new t(this.position.x,this.position.y,this.scale.x,this.scale.y,this.rotation.eulerAngles)}}])&&d(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}(),w=function(t){return t.High="high",t.Medium="medium",t.Low="low",t}({}),O={canvas:void 0,grid:new y(4,3),autoResize:!0,refreshWhenUnfocused:!0,canvasImageQuality:w.High,drawAlways:!0},S=function(t){return t.Cube="RECT",t.Rect="RECT",t.Rectangle="RECT",t.Circle="CIRCLE",t.Ellipse="CIRCLE",t}({}),j=function(t){return t.dontRotate="dontRotate",t.allAround="allAround",t}({});function P(t){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P(t)}function x(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function k(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==P(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==P(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===P(o)?o:String(o)),r)}var o}var E=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.listeners=[]}var e,n;return e=t,(n=[{key:"emit",value:function(t,e){var n,r=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return x(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(this.listeners);try{for(r.s();!(n=r.n()).done;){var o=n.value;t===o.channel&&o.callback(e)}}catch(t){r.e(t)}finally{r.f()}}},{key:"on",value:function(t,e){this.listeners.push({channel:t,callback:e})}}])&&k(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function R(t){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},R(t)}function D(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==R(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==R(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===R(o)?o:String(o)),r)}var o}var T=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.id=crypto.getRandomValues(new Uint32Array(4)).join("-"),this.enabled=!0,this.name=void 0,this.tag=void 0,this.sortingOrder=0,this.transform=new g(0,0,1,1,0)}var e,n;return e=t,(n=[{key:"Start",value:function(t){}},{key:"Destroy",value:function(t){}},{key:"Update",value:function(t){}},{key:"FixedUpdate",value:function(t){}}])&&D(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function C(t){return C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},C(t)}function _(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,G(r.key),r)}}function M(t,e){return M=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},M(t,e)}function A(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function G(t){var e=function(t,e){if("object"!==C(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==C(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===C(e)?e:String(e)}var I=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&M(t,e)}(u,t);var e,n,o,i,a,s=(i=u,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=L(i);if(a){var n=L(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===C(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return A(t)}(this,t)});function u(){var t,e,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u);for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];return e=A(t=s.call.apply(s,[this].concat(o))),!0,(n=G(n="visible"))in e?Object.defineProperty(e,n,{value:true,enumerable:!0,configurable:!0,writable:!0}):e[n]=true,t}return e=u,o=[{key:"IsTouching",value:function(t,e){return t.visible&&e.visible&&r(t.transform.position.x,e.transform.position.x,e.transform.position.x+e.transform.scale.x)&&r(t.transform.position.y,e.transform.position.y,e.transform.position.y+e.transform.scale.y)}}],(n=[{key:"OnDraw",value:function(t){}},{key:"isTouching",value:function(t){return u.IsTouching(this,t)}}])&&_(e.prototype,n),o&&_(e,o),Object.defineProperty(e,"prototype",{writable:!1}),u}(T);function H(t){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H(t)}function W(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Y(r.key),r)}}function U(t,e){return U=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},U(t,e)}function z(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function B(t){return B=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},B(t)}function V(t,e,n){return(e=Y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Y(t){var e=function(t,e){if("object"!==H(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==H(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===H(e)?e:String(e)}var F=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&U(t,e)}(a,t);var e,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=B(r);if(o){var n=B(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===H(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return z(t)}(this,t)});function a(){var t;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return V(z(t=i.call.apply(i,[this].concat(n))),"showHitbox",!1),V(z(t),"ignoreRaycast",!1),t}return e=a,(n=[{key:"OnMouseClick",value:function(t){}},{key:"OnMouseUp",value:function(t){}},{key:"OnMouseDown",value:function(t){}},{key:"OnMouseHoverStart",value:function(t){}},{key:"OnMouseHoverEnd",value:function(t){}}])&&W(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),a}(I),N={color:"#000000",borderColor:"#000000",angle:0,fill:!0,border:!1,alpha:1,borderSize:1,shadow:{color:"",offsetX:0,offsetY:0,blur:0},rotationStyle:j.allAround};function q(t){return q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},q(t)}function X(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Z(r.key),r)}}function K(t,e){return K=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},K(t,e)}function Q(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function $(t,e,n){return(e=Z(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Z(t){var e=function(t,e){if("object"!==q(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==q(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===q(e)?e:String(e)}var tt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&K(t,e)}(a,t);var e,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=J(r);if(o){var n=J(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===q(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return Q(t)}(this,t)});function a(){var t;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return $(Q(t=i.call.apply(i,[this].concat(n))),"type",S.Rect),$(Q(t),"properties",Object.create(N)),t}return e=a,(n=[{key:"OnDraw",value:function(t){this.type===S.Rect?t.renderer.drawRectangle(this.transform.position.x,this.transform.position.y,this.transform.scale.x,this.transform.scale.y,this.properties):this.type===S.Circle&&t.renderer.drawCircle(this.transform.position.x,this.transform.position.y,Math.max(this.transform.scale.x,this.transform.scale.y),this.properties)}}])&&X(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),a}(F);function et(t){return et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},et(t)}function nt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function rt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?nt(Object(n),!0).forEach((function(e){ot(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function ot(t,e,n){return(e=it(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function it(t){var e=function(t,e){if("object"!==et(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==et(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===et(e)?e:String(e)}function at(t,e){return at=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},at(t,e)}function st(t){return st=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},st(t)}var ut=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&at(t,e)}(i,t);var e,n,r,o=(n=i,r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=st(n);if(r){var o=st(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===et(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function i(t,e){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),(n=o.call(this)).type=t,void 0!==e&&(n.properties=rt(rt({},N),e)),n}return e=i,Object.defineProperty(e,"prototype",{writable:!1}),e}(tt);function ct(t){return ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ct(t)}function lt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,pt(r.key),r)}}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}function yt(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function ht(t){return ht=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ht(t)}function pt(t){var e=function(t,e){if("object"!==ct(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==ct(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===ct(e)?e:String(e)}var mt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(a,t);var e,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=ht(r);if(o){var n=ht(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===ct(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return yt(t)}(this,t)});function a(){var t,e,n,r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a);for(var o=arguments.length,s=new Array(o),u=0;u<o;u++)s[u]=arguments[u];return e=yt(t=i.call.apply(i,[this].concat(s))),n="rotationStyle",r=j.allAround,(n=pt(n))in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,t}return e=a,(n=[{key:"Start",value:function(t){t.game.Update()}},{key:"OnDraw",value:function(t){void 0!==this.texture&&this.visible&&t.renderer.drawSprite(this)}}])&&lt(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),a}(F);function vt(t){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vt(t)}function bt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,o=function(t,e){if("object"!==vt(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==vt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===vt(o)?o:String(o)),r)}var o}function dt(t,e){return dt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},dt(t,e)}function gt(t){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},gt(t)}var wt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&dt(t,e)}(a,t);var e,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=gt(r);if(o){var n=gt(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===vt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function a(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(e=i.call(this))._imageResourceKey=t,e}return e=a,(n=[{key:"Start",value:function(t){this.texture=t.game.GetImage(this._imageResourceKey),t.game.Update()}}])&&bt(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),a}(mt),Ot={document:void 0,backgroundColor:void 0};function St(t){return St="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},St(t)}function jt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Pt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?jt(Object(n),!0).forEach((function(e){xt(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):jt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function xt(t,e,n){return(e=Et(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function kt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Et(r.key),r)}}function Et(t){var e=function(t,e){if("object"!==St(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==St(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===St(e)?e:String(e)}var Rt=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}var e,n;return e=t,n=[{key:"Render",value:function(t){if(!((t=Pt(Pt({},Ot),t)).document instanceof Document)){if(!(document instanceof Document))throw new Error("Default DOM cannot be assigned! Please assign document to 'document' property");t.document=document}t.document.write('<div style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;flex-direction: column;"><canvas id="gameCanvas">Your browser does not support the HTML 5 canvas.</canvas></div>'),t.document.body.style.height="100vh",t.document.body.style.width="100vw",t.document.body.style.margin="0",void 0!==t.backgroundColor&&(t.document.body.style.backgroundColor=t.backgroundColor)}}],null&&kt(e.prototype,null),n&&kt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function Dt(t){return Dt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Dt(t)}function Tt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Ct(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tt(Object(n),!0).forEach((function(e){Mt(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function _t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,At(r.key),r)}}function Mt(t,e,n){return(e=At(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function At(t){var e=function(t,e){if("object"!==Dt(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==Dt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===Dt(e)?e:String(e)}var Lt=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Mt(this,"gridSize",0),Mt(this,"canvasParentSize",1),this.handler=e}var e,n;return e=t,(n=[{key:"resizeCanvas",value:function(){if(!(this.handler.canvas instanceof HTMLCanvasElement))throw new Error("Cannot resize undefined canvas!");var t=this.handler.canvas.parentElement;if(null==t)throw new Error("Parent cannot be null!");var e=t.clientWidth,n=t.clientHeight,r=e*this.canvasParentSize/this.handler.grid.x,o=n*this.canvasParentSize/this.handler.grid.y;this.gridSize=Math.floor(Math.min(r,o)),this.canvasWidth=this.handler.grid.x*this.gridSize,this.canvasHeight=this.handler.grid.y*this.gridSize}},{key:"canvasWidth",get:function(){return this.handler.canvas.width},set:function(t){this.handler.canvas.width=t}},{key:"canvasHeight",get:function(){return this.handler.canvas.height},set:function(t){this.handler.canvas.height=t}},{key:"ctx",get:function(){var t=this.handler.canvas.getContext("2d");if(null==t)throw new Error("There was a problem during getting the context");return t}},{key:"canvasSize",get:function(){return new y(this.canvasWidth,this.canvasHeight)}},{key:"scale",value:function(t){return t*this.gridSize}},{key:"combineDrawSettings",value:function(t){return Ct(Ct({},N),t)}},{key:"setContextSettings",value:function(t){var e,n,r,o;void 0!==t.color&&(this.ctx.fillStyle=t.color),void 0!==t.borderColor&&(this.ctx.strokeStyle=t.borderColor),void 0!==t.borderSize&&(this.ctx.lineWidth=this.scale(t.borderSize/64)),void 0!==t.alpha&&(this.ctx.globalAlpha=i(t.alpha)),void 0!==(null===(e=t.shadow)||void 0===e?void 0:e.color)&&(this.ctx.shadowColor=t.shadow.color),void 0!==(null===(n=t.shadow)||void 0===n?void 0:n.offsetX)&&(this.ctx.shadowOffsetX=this.scale(t.shadow.offsetX)),void 0!==(null===(r=t.shadow)||void 0===r?void 0:r.offsetY)&&(this.ctx.shadowOffsetY=this.scale(t.shadow.offsetY)),void 0!==(null===(o=t.shadow)||void 0===o?void 0:o.blur)&&(this.ctx.shadowBlur=this.scale(t.shadow.blur))}},{key:"drawRectangle",value:function(t,e,n,r,o){o=this.combineDrawSettings(o);var i=this.scale(t-this.handler.canvasViewOffset.x),a=this.scale(e-this.handler.canvasViewOffset.y),s=this.scale(n),u=this.scale(r);this.ctx.save(),this.ctx.translate(i+s/2,a+u/2),void 0!==o.angle&&o.rotationStyle===j.allAround&&this.ctx.rotate(v.ToRadians(o.angle)),this.ctx.translate(-i-s/2,-a-u/2),this.setContextSettings(o),o.fill&&this.ctx.fillRect(i,a,s,u),o.border&&this.ctx.strokeRect(i,a,s,u),this.ctx.restore()}},{key:"drawCircle",value:function(t,e,n,r){r=this.combineDrawSettings(r);var o=this.scale(t-this.handler.canvasViewOffset.x),i=this.scale(e-this.handler.canvasViewOffset.y),a=this.scale(n/2);this.setContextSettings(r),this.ctx.beginPath(),this.ctx.arc(o+a,i+a,a,0,2*Math.PI),this.ctx.closePath(),r.fill&&this.ctx.fill(),r.border&&this.ctx.stroke()}},{key:"drawLine",value:function(t,e,n,r,o){o=this.combineDrawSettings(o),this.setContextSettings(o),this.ctx.beginPath(),this.ctx.moveTo(this.scale(t-this.handler.canvasViewOffset.x),this.scale(e-this.handler.canvasViewOffset.y)),this.ctx.lineTo(this.scale(n-this.handler.canvasViewOffset.x),this.scale(r-this.handler.canvasViewOffset.y)),this.ctx.closePath(),this.ctx.stroke()}},{key:"drawArrow",value:function(t,e,n,r,o){o=this.combineDrawSettings(o);var i=this.gridSize/16;this.ctx.lineWidth=this.gridSize/64,this.setContextSettings(o);var a=new y((t-this.handler.canvasViewOffset.x)*this.gridSize,(e-this.handler.canvasViewOffset.y)*this.gridSize),s=new y((n-this.handler.canvasViewOffset.x)*this.gridSize,(r-this.handler.canvasViewOffset.y)*this.gridSize),u=Math.atan2(s.y-a.y,s.x-a.x),c=Math.sqrt((s.x-a.x)*(s.x-a.x)+(s.y-a.y)*(s.y-a.y));this.ctx.save(),this.ctx.translate(a.x,a.y),this.ctx.rotate(u),this.ctx.beginPath(),this.ctx.moveTo(0,0),this.ctx.lineTo(c-i,0),this.ctx.closePath(),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.lineTo(c-i,i),this.ctx.lineTo(c,0),this.ctx.lineTo(c-i,-i),this.ctx.closePath(),this.ctx.fill(),this.ctx.restore()}},{key:"clearFrame",value:function(){this.ctx.clearRect(0,0,this.canvasWidth,this.canvasHeight)}},{key:"fillFrame",value:function(t){t=this.combineDrawSettings(t),this.setContextSettings(t),this.ctx.fillRect(0,0,this.canvasWidth,this.canvasHeight)}},{key:"fillImageFrame",value:function(t){this.ctx.drawImage(t,0,0,this.canvasWidth,this.canvasHeight)}},{key:"fill",value:function(t){if(t instanceof HTMLCanvasElement)return this.setContextSettings(N),void this.ctx.drawImage(t,0,0,this.canvasWidth,this.canvasHeight);"string"==typeof t?this.setContextSettings(this.combineDrawSettings({color:t})):this.setContextSettings(this.combineDrawSettings(t)),this.ctx.fillRect(0,0,this.canvasWidth,this.canvasHeight)}},{key:"drawImage",value:function(t,e,n,r,o,i){i=this.combineDrawSettings(i);var a=this.scale(e-this.handler.canvasViewOffset.x),s=this.scale(n-this.handler.canvasViewOffset.y),u=this.scale(r),c=this.scale(o);this.ctx.save(),this.ctx.translate(a+u/2,s+c/2),void 0!==i.angle&&i.rotationStyle===j.allAround&&this.ctx.rotate(v.ToRadians(i.angle)),this.ctx.translate(-a-u/2,-s-c/2),this.ctx.drawImage(t,a,s,u,c),this.ctx.restore()}},{key:"drawSprite",value:function(t){return void 0===t.texture||null===t.texture?(console.warn("The Sprite ",t," has not assigned texture!"),!1):t.texture instanceof HTMLImageElement?(this.drawImage(t.texture,t.transform.position.x,t.transform.position.y,t.transform.scale.x,t.transform.scale.y,{angle:t.transform.eulerAngles,rotationStyle:t.rotationStyle}),!0):(console.warn("Texture ".concat(t.name,"[").concat(t.id,"] cannot be ").concat(Dt(t.texture),"!")),!1)}},{key:"drawHitbox",value:function(t){if(t.showHitbox){var e=t.transform.position,n=t.transform.positionCenter,r=t.transform.scale;this.drawRectangle(e.x,e.y,r.x,r.y,{borderColor:"red",fill:!1,border:!0}),this.drawLine(e.x,e.y,e.x+r.x,e.y+r.y,{borderColor:"red"}),this.drawLine(e.x+r.x,e.y,e.x,e.y+r.y,{borderColor:"red"});var o=v.ToRadians(t.transform.eulerAngles);this.drawArrow(n.x,n.y,n.x+r.x/2*Math.cos(o),n.y+r.y/2*Math.sin(o),{color:"red",borderColor:"red"})}}}])&&_t(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function Gt(t){return Gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Gt(t)}function It(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Wt(r.key),r)}}function Ht(t,e,n){return(e=Wt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Wt(t){var e=function(t,e){if("object"!==Gt(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==Gt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===Gt(e)?e:String(e)}var Ut=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Ht(this,"isMousePrimaryButtonDown",!1),Ht(this,"mouseScrollDelta",new y),Ht(this,"mouseClientPosition",new y),Ht(this,"mouseWorldPosition",new y),Ht(this,"mousePreciseWorldPosition",new y),Ht(this,"mouseLocalPosition",new y),Ht(this,"mousePreciseLocalPosition",new y),Ht(this,"keysUp",new Set),Ht(this,"keysDown",new Set)}var e,n;return e=t,(n=[{key:"isKeyDown",value:function(t){return this.keysDown.has(t.toLowerCase().replace("key",""))}},{key:"isKeyUp",value:function(t){return this.keysUp.has(t.toLowerCase().replace("key",""))}}])&&It(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function zt(t){return zt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},zt(t)}function Bt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Vt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Vt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Vt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function Yt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Ft(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Yt(Object(n),!0).forEach((function(e){qt(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Nt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Xt(r.key),r)}}function qt(t,e,n){return(e=Xt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Xt(t){var e=function(t,e){if("object"!==zt(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==zt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===zt(e)?e:String(e)}var Kt=function(){function t(e){var n=this;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),qt(this,"renderer",new Lt(this)),qt(this,"_isPlaying",!1),qt(this,"_unscaledTime",0),qt(this,"_deltaTime",0),qt(this,"timeScale",1),qt(this,"isNeedToUpdate",!0),qt(this,"_gameLoop",(function(t){n._gameLoopUpdate(t),document.hasFocus()||n.gameSettings.refreshWhenUnfocused?(n._gameLoopDraw(),n._isPlaying&&window.requestAnimationFrame(n._gameLoop)):n._isPlaying&&window.requestAnimationFrame(n._gameLoop)})),qt(this,"_signals",new E),qt(this,"emit",(function(t,e){return n._signals.emit(t,e)})),qt(this,"on",(function(t,e){return n._signals.on(t,e)})),qt(this,"resources",new Map),qt(this,"_isLoadedAllResources",!1),qt(this,"gameObjects",[]),qt(this,"_tempMouseWheelDeltaY",0),this.gameSettings=Ft(Ft({},O),e),void 0===this.gameSettings.canvas)throw new Error("Cannot asign canvas.");if(this.canvas=this.gameSettings.canvas,void 0===this.gameSettings.grid)throw new Error("Cannot asign grid.");this.grid=this.gameSettings.grid,this.input=new Ut,this._registerCanvasEvents(),this.gameSettings.autoResize&&window.addEventListener("resize",(function(){n.renderer.resizeCanvas(),n.Update()})),this.renderer.ctx.imageSmoothingEnabled=!0,void 0!==this.gameSettings.canvasImageQuality&&(this.renderer.ctx.imageSmoothingQuality=this.gameSettings.canvasImageQuality),this.canvasViewOffset=new y}var e,o;return e=t,o=[{key:"RescaleCanvasToParentElement",value:function(t){return this.renderer.canvasParentSize=t,this.renderer.resizeCanvas(),this.renderer.canvasSize}},{key:"_registerCanvasEvents",value:function(){var t=this;this.canvas.addEventListener("mousemove",(function(e){t.mouseMoveHandler(t,e)})),document.addEventListener("mouseup",(function(){t.mouseUpHandler(t)})),document.addEventListener("mousedown",(function(){t.mouseDownHandler(t)})),this.canvas.addEventListener("click",(function(){t.mouseClickHandler(t)})),this.canvas.addEventListener("wheel",(function(e){t.mouseWheelHandler(t,e)}),{passive:!1}),document.addEventListener("keydown",(function(e){if(!e.defaultPrevented){e.preventDefault();var n=e.code.toLowerCase().replace("key","");t.input.keysDown.add(n)}})),document.addEventListener("keyup",(function(e){if(!e.defaultPrevented){e.preventDefault();var n=e.code.toLowerCase().replace("key","");t.input.keysUp.add(n)}}))}},{key:"_gameLoopUpdate",value:function(t){this._deltaTime=t-this._unscaledTime,this._unscaledTime=t;var e={unscaledDeltaTime:this._deltaTime/1e3,unscaledTime:this._unscaledTime/1e3,deltaTime:this._deltaTime/1e3*this.timeScale,timeScale:this.timeScale,game:this},n=this.mouseHoveredGameObject,r=this.constructMouseEvent(),o=this.lastMouseHoveredGameObject;o!==n&&(void 0!==o&&o.OnMouseHoverEnd(r),null==n||n.OnMouseHoverStart(r),this.lastMouseHoveredGameObject=n),this.input.mouseScrollDelta=new y(0,this._tempMouseWheelDeltaY),0!==this._tempMouseWheelDeltaY&&this.emit("mouseScroll",r),this._tempMouseWheelDeltaY=0;var i={game:this,input:this.input};this.input.keysDown.size>0&&this.emit("keyDown",i),this.input.keysUp.size>0&&this.emit("keyUp",i);var a,s=Bt(this.gameObjects);try{for(s.s();!(a=s.n()).done;){var u=a.value;if(u.enabled)try{u.Update(e)}catch(t){console.warn("Problem with executing Update @ ".concat(u.constructor.name," "),u),t instanceof Error&&console.error(t.message)}}}catch(t){s.e(t)}finally{s.f()}var c,l=Bt(this.gameObjects);try{for(l.s();!(c=l.n()).done;){var f=c.value;if(f.enabled)try{f.FixedUpdate(e)}catch(t){console.warn("Problem with executing FixedUpdate @ ".concat(f.constructor.name," "),f),t instanceof Error&&console.error(t.message)}}}catch(t){l.e(t)}finally{l.f()}this.input.keysDown.clear(),this.input.keysUp.clear()}},{key:"_gameLoopDraw",value:function(){if(this.isNeedToUpdate||this.gameSettings.drawAlways){this.renderer.clearFrame();var t={renderer:this.renderer,game:this};this.emit("draw",t);var e,n=Bt(this.gameObjects);try{for(n.s();!(e=n.n()).done;){var r=e.value;if(r.enabled&&r instanceof I)try{if(r.OnDraw(t),r instanceof F){var o=r;this.renderer.drawHitbox(o)}}catch(t){console.warn("Problem with executing draw @ ".concat(r.constructor.name," "),r),t instanceof Error&&console.error(t.message)}}}catch(t){n.e(t)}finally{n.f()}this.isNeedToUpdate=!1}}},{key:"Update",value:function(){this.isNeedToUpdate=!0}},{key:"StartGameLoop",value:function(){var t=this;this._isPlaying?console.warn("Cannot start new game loop when the game loop exists."):window.requestAnimationFrame((function(){window.requestAnimationFrame(t._gameLoop.bind(t)),t._isPlaying=!0}))}},{key:"StopGameLoop",value:function(){console.warn("Stopped the game loop! Restarting the game loop will cause a time skip."),this._isPlaying=!1}},{key:"Start",value:function(){this.StartGameLoop(),this.emit("start",{game:this})}},{key:"LoadGameAndStart",value:function(){var t=this;return new Promise((function(e,n){t._isPlaying&&n(new Error("Cannot load and start game because the game loop currently exists!")),t.on("loadAllResources",(function(){t.Start(),e({game:t})}));try{setTimeout((function(){t.LoadAllResources()}),1)}catch(t){n(t)}}))}},{key:"LoadResource",value:function(t,e,n){if("image"!==t)throw new Error("Unknown resource type.");this.resources.set(e,{uid:e,type:t,path:n,object:void 0,loaded:!1}),this.LoadAllResources()}},{key:"CreateImage",value:function(t){var e=new Image;return e.src=t,e}},{key:"GetResource",value:function(t){var e=this.resources.get(t);if(void 0===e)throw new Error("Resource not loaded!");return e}},{key:"GetImage",value:function(t){var e=this.GetResource(t);if("image"===e.type&&e.loaded)return e.object}},{key:"LoadAllResources",value:function(){var t=this;if(0===this.resources.size)return this._signals.emit("loadAllResources",{game:this}),void(this._isLoadedAllResources=!0);var e=0,n=function(){0==(e-=1)&&(t._isLoadedAllResources||(t._signals.emit("loadAllResources",{game:t}),t._isLoadedAllResources=!0))};this.resources.forEach((function(t){if(!t.loaded)if("image"===t.type){var r=new Image;r.src=t.path,r.addEventListener("error",(function(){t.loaded=!1,console.error("Cannot load ".concat(t.uid," resource.")),n()})),r.addEventListener("load",(function(){t.object=r,t.loaded=!0,n()})),e+=1}else console.warn('Type "'.concat(t.type,'" is unknown resources type.'))}))}},{key:"SortGameObjects",value:function(){this.gameObjects.sort((function(t,e){return t.sortingOrder-e.sortingOrder}))}},{key:"AddGameObject",value:function(t){if(!(t i