This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
dwelibs/dist/dwelibs.min.js

1 line
6.0 KiB
JavaScript

!function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";window.DWE={};n(1),n(2),n(3),n(4),n(5)},function(t,e,n){"use strict";DWE.context=function(t){return t.star=function(e,n,r,o,i){var a=Math.PI/2*3,u=e,c=n,s=Math.PI/r;t.beginPath(),t.moveTo(e,n-o);for(var h=0;h<r;h++)u=e+Math.cos(a)*o,c=n+Math.sin(a)*o,t.lineTo(u,c),a+=s,u=e+Math.cos(a)*i,c=n+Math.sin(a)*i,t.lineTo(u,c),a+=s;t.lineTo(e,n-o),t.closePath()},t.fillStar=function(e,n,r,o,i){t.star(e,n,r,o,i),t.fill()},t.circle=function(e,n,r,o){o||(o=0),t.beginPath(),t.arc(e,n,r,o,2*Math.PI,!0),t.closePath()},t.fillCircle=function(e,n,r,o){t.circle(e,n,r,o),t.fill()},t}},function(t,e,n){"use strict";var r=function(){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,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}DWE.Math={},DWE.Math.random=function(t,e){return Math.floor(Math.random()*e)+t},DWE.Math.lerp=function(t,e,n){return(1-n)*t+n*e},DWE.Math.reverseLerp=function(t,e,n){return 1/((e-t)*n)},DWE.Math.intersectsBox=function(t,e,n,r,o,i,a,u){return 2*Math.abs(t-o)<=n+a&&2*Math.abs(e-i)<=r+u},DWE.Math.intersects2Box=function(t,e){return 2*Math.abs(t.x-e.x)<=t.width+e.width&&2*Math.abs(t.y-e.y)<=t.height+e.height},DWE.Math.clamp=function(t,e,n){return Math.max(e,Math.min(n,t))},DWE.Math.Vector2=function(){function t(e,n){o(this,t),this.x=e,this.y=n}return r(t,[{key:"normalize",value:function(){var t=this.magnitude;this.x/=t,this.y/=t}},{key:"distance",value:function(t){if(!(t instanceof DWE.Math.Vector2))throw new Error("Distance function takes another Vector2 as an argument.");return Math.abs(Math.sqrt(Math.pow(t.x-this.x,2)+Math.pow(t.y-this.y,2)))}},{key:"magnitude",get:function(){return Math.abs(Math.sqrt(this.x*this.x+this.y*this.y))}}]),t}(),DWE.Math.Box2=function(){function t(e,n,r,i){o(this,t),this.x=e,this.y=n,this.width=r,this.height=i}return r(t,[{key:"intersectsBox",value:function(t){if(!(t instanceof DWE.Math.Box2))throw new Error("Intersection function takes another Box2 as an argument.");return DWE.Math.intersects2Box(this,t)}},{key:"intersectsCircle",value:function(t){if(!(t instanceof DWE.Math.Circle))throw new Error("Intersection function takes another Circle as an argument.");var e=new DWE.Math.Vector2(Math.abs(t.x-this.x),Math.abs(t.y-this.y));return!(e.x>this.width/2+t.r)&&(!(e.y>this.height/2+t.r)&&(e.x<=this.width/2||(e.y<=this.height/2||Math.pow(e.x-this.width/2,2)+Math.pow(e.y-this.height/2,2)<=Math.pow(t.r,2))))}}]),t}(),DWE.Math.Circle=function(){function t(e,n,r){o(this,t),this.x=e,this.y=n,this.r=r}return r(t,[{key:"radius",get:function(){return this.r}}]),t}()},function(t,e,n){"use strict";DWE.getMousePosition=function(t,e){var n=void 0,r=void 0;if(t.changedTouches){var o=t.changedTouches[0];o&&(t.pageX=o.pageX,t.pageY=o.pageY)}return t.pageX||t.pageY?(n=t.pageX,r=t.pageY):(n=t.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,r=t.clientY+document.body.scrollTop+document.documentElement.scrollTop),n-=e.offsetLeft,r-=e.offsetTop,new DWE.Math.Vector2(n,r)}},function(t,e,n){"use strict";DWE.Keyboard={};var r={},o={},i={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,pausebreak:19,capslock:20,escape:27,pgup:33,pgdown:34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,"left-window":91,"right-window":92,select:93,numpad0:96,numpad1:97,numpad2:98,numpad3:99,numpad4:100,numpad5:101,numpad6:102,numpad7:103,numpad8:104,numpad9:105,multiply:106,add:107,subtract:109,decimal:110,divide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,numlock:144,scrolllock:145,"semi-colon":186,equals:187,comma:188,dash:189,period:190,fwdslash:191,grave:192,"open-bracket":219,bkslash:220,"close-braket":221,"single-quote":222};function a(t){return null!=r[t]&&r[t]}function u(t){return null!=o[t]&&o[t]}DWE.Keyboard.toggleKey=function(t,e){var n=null;for(var o in i){if(t===i[o]){n=o;break}}n||(n=String.fromCharCode(t).toLowerCase()),r[n]=!0===e},DWE.Keyboard.keyDown=function(t){var e;window.event?e=window.event.keyCode:t&&(e=t.which),DWE.Keyboard.toggleKey(e,!0)},DWE.Keyboard.keyUp=function(t){var e;window.event?e=window.event.keyCode:t&&(e=t.which),DWE.Keyboard.toggleKey(e,!1)},DWE.Keyboard.isDown=function(t){return a(t)&&u(t)},DWE.Keyboard.isUp=function(t){return!DWE.Keyboard.isDown(t)},DWE.Keyboard.isPressed=function(t){return!0===a(t)&&!1===u(t)},DWE.Keyboard.nextIteration=function(){for(var t in o={},r)!0===r[t]&&(o[t]=!0)}},function(t,e,n){"use strict";DWE.Image={},DWE.Image.Image=function(t){var e=this;this.src=t,this.img=new Image,this.img.src=this.src,this.width=0,this.height=0,this.loaded=!1,this.errored=!1,this.img.onload=function(){e.loaded=!0,e.width=e.img.width,e.height=e.img.height,e.onload&&e.onload.apply(e,[])},this.img.onerror=function(t){e.loaded=!1,e.errored=!0,e.onerror&&e.onerror.apply(e,[t])}},DWE.Image.loadImageArray=function(t){return new Promise(function(e,n){var r=0,o=t.length,i=[];!function a(u){var c=t[u],s=new DWE.Image.Image(c);s.onload=function(){i.push(s),++r==o?e(i):a(r)},s.onerror=function(t){n(t)}}(r)})}}]);