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
9.6 KiB
JavaScript

!function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.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 i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));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),n(6)},function(t,e,n){"use strict";DWE.context=function(t){return t.star=function(e,n,r,i,o){var a=Math.PI/2*3,s=e,u=n,c=Math.PI/r;t.beginPath(),t.moveTo(e,n-i);for(var h=0;h<r;h++)s=e+Math.cos(a)*i,u=n+Math.sin(a)*i,t.lineTo(s,u),a+=c,s=e+Math.cos(a)*o,u=n+Math.sin(a)*o,t.lineTo(s,u),a+=c;t.lineTo(e,n-i),t.closePath()},t.fillStar=function(e,n,r,i,o){t.star(e,n,r,i,o),t.fill()},t.circle=function(e,n,r,i){i||(i=0),t.beginPath(),t.arc(e,n,r,i,2*Math.PI,!0),t.closePath()},t.fillCircle=function(e,n,r,i){t.circle(e,n,r,i),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 i(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,i,o,a,s){return 2*Math.abs(t-i)<=n+a&&2*Math.abs(e-o)<=r+s},DWE.Math.clamp=function(t,e,n){return Math.max(e,Math.min(n,t))},DWE.Math.Vector2=function(){function t(e,n){i(this,t),this.x=e,this.y=n}return r(t,[{key:"normalize",value:function(){var t=this.magnitude;return this.x/=t,this.y/=t,this}},{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:"add",value:function(t){if(!(t instanceof DWE.Math.Vector2))throw new Error("Add function takes another Vector2 as an argument.");return this.x+=t.x,this.y+=t.y,this}},{key:"subtract",value:function(t){if(!(t instanceof DWE.Math.Vector2))throw new Error("Subtract function takes another Vector2 as an argument.");return this.x-=t.x,this.y-=t.y,this}},{key:"multiply",value:function(t){if("number"==typeof t&&!isNaN(t))return this.x*=t,this.y*=t,this;if(!(t instanceof DWE.Math.Vector2))throw new Error("Multiply function takes a Vector2 or Number as an argument.");return this.x*=t.x,this.y*=t.y,this}},{key:"divide",value:function(t){if("number"==typeof t&&!isNaN(t))return this.x/=t,this.y/=t,this;if(!(t instanceof DWE.Math.Vector2))throw new Error("Division function takes a Vector2 or Number as an argument.");return this.x/=t.x,this.y/=t.y,this}},{key:"magnitude",get:function(){return Math.abs(Math.sqrt(this.x*this.x+this.y*this.y))}},{key:"isNormal",get:function(){return 1===Math.floor(this.magnitude)}},{key:"angle",get:function(){return this.isNormal?Math.atan2(this.x,this.y):NaN}}]),t}(),DWE.Math.Box2=function(t){function e(t,n,r,o){i(this,e);var a=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return a.width=r,a.height=o,a}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,DWE.Math.Vector2),r(e,[{key:"intersectsBox",value:function(t){if(!(t instanceof DWE.Math.Box2))throw new Error("Intersection function takes another Box2 as an argument.");var e=t.x+t.width/2-(this.x+this.width/2),n=t.y+t.height/2-(this.y+this.height/2),r=t.width/2+this.width/2,i=t.height/2+this.height/2,o=null;if(Math.abs(e)<r&&Math.abs(n)<i){var a=r-Math.abs(e),s=i-Math.abs(n);o=a>=s?n>0?{dir:"t",y:s,x:0}:{dir:"b",y:-s,x:0}:e>0?{dir:"l",y:0,x:a}:{dir:"r",y:0,x:-a}}return o}},{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))))}}]),e}(),DWE.Math.Circle=function(){function t(e,n,r){i(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 i=t.changedTouches[0];i&&(t.pageX=i.pageX,t.pageY=i.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={},i={},o={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 s(t){return null!=i[t]&&i[t]}DWE.Keyboard.toggleKey=function(t,e){var n=null;for(var i in o){if(t===o[i]){n=i;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)&&s(t)},DWE.Keyboard.isUp=function(t){return!DWE.Keyboard.isDown(t)},DWE.Keyboard.isPressed=function(t){return!0===a(t)&&!1===s(t)},DWE.Keyboard.nextIteration=function(){for(var t in i={},r)!0===r[t]&&(i[t]=!0)}},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}}();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.TileMap=function(t){function e(t,n,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.aspectWidth=n,i.aspectHeight=r,i.tiles=[],i}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,DWE.Image.Image),r(e,[{key:"onload",value:function(){for(var t=0;t<this.height/this.aspectHeight;t++)for(var e=0;e<this.width/this.aspectWidth;e++)this.tiles.push(new DWE.Math.Vector2(e,t));this.onready&&this.onready.call(this,this)}},{key:"draw",value:function(t,e,n,r,i,o){var a=this.tiles[e];a&&t.drawImage(this.img,a.x*this.aspectWidth,a.y*this.aspectHeight,this.aspectWidth,this.aspectHeight,n,r,i,o)}}]),e}(),DWE.Image.loadImageArray=function(t){return new Promise(function(e,n){var r=0,i=t.length,o=[];!function a(s){var u=t[s],c=new DWE.Image.Image(u);c.onload=function(){o.push(c),++r==i?e(o):a(r)},c.onerror=function(t){n(t)}}(r)})}},function(t,e,n){"use strict";DWE.File={},DWE.File.httpGET=function(t){return new Promise(function(e,n){var r=new XMLHttpRequest;r.onreadystatechange=function(){4==r.readyState&&200==r.status?e(r.responseText):4==r.readyState&&r.status>=400&&n(r.responseText)},r.open("GET",t,!0),r.responseType="text",r.send(null)})},DWE.File.loadJson=function(t){return new Promise(function(e,n){DWE.File.httpGET(t).then(function(t){var r;try{r=JSON.parse(t)}catch(t){return n(t)}e(r)},n)})}}]);