phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.72 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexperlingrivatywellplugin=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(o=n.key,i=void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?i:String(i)),n);}var o,i;}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(t,e){if(e&&("object"==typeof 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)}function u(t){var e=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}}();return function(){var r,o=n(t);if(e){var u=n(this).constructor;r=Reflect.construct(o,arguments,u);}else r=o.apply(this,arguments);return i(this,r)}}var a=function(){function e(r,n,o){t(this,e),this.x=r,this.y=n,this.z=o;}return r(e,[{key:"dot2",value:function(t,e){return this.x*t+this.y*e}},{key:"dot3",value:function(t,e,r){return this.x*t+this.y*e+this.z*r}}]),e}(),c=[new a(1,1,0),new a(-1,1,0),new a(1,-1,0),new a(-1,-1,0),new a(1,0,1),new a(-1,0,1),new a(1,0,-1),new a(-1,0,-1),new a(0,1,1),new a(0,-1,1),new a(0,1,-1),new a(0,-1,-1)],f=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],s=.5*(Math.sqrt(3)-1),l=(3-Math.sqrt(3))/6,h=1/6,d=function(t){return t*t*t*(t*(6*t-15)+10)},y=function(t,e,r){return (1-r)*t+r*e},p=function(){function e(r){t(this,e),void 0===r&&(r=0),this.perm=new Array(512),this.gradP=new Array(512),this.setSeed(r);}return r(e,[{key:"setSeed",value:function(t){var e=this.perm,r=this.gradP;t>0&&t<1&&(t*=65536),(t=Math.floor(t))<256&&(t|=t<<8);for(var n=0;n<256;n++){var o;o=1&n?f[n]^255&t:f[n]^t>>8&255,e[n]=e[n+256]=o,r[n]=r[n+256]=c[o%12];}}},{key:"simplex2",value:function(t,e){var r,n,o=this.perm,i=this.gradP,u=(t+e)*s,a=Math.floor(t+u),c=Math.floor(e+u),f=(a+c)*l,h=t-a+f,d=e-c+f;h>d?(r=1,n=0):(r=0,n=1);var y=h-r+l,p=d-n+l,v=h-1+2*l,b=d-1+2*l,w=i[(a&=255)+o[c&=255]],m=i[a+r+o[c+n]],P=i[a+1+o[c+1]],g=.5-h*h-d*d,M=.5-y*y-p*p,O=.5-v*v-b*b;return 70*((g<0?0:(g*=g)*g*w.dot2(h,d))+(M<0?0:(M*=M)*M*m.dot2(y,p))+(O<0?0:(O*=O)*O*P.dot2(v,b)))}},{key:"simplex3",value:function(t,e,r){var n,o,i,u,a,c,f=this.perm,s=this.gradP,l=.3333333333333333*(t+e+r),d=Math.floor(t+l),y=Math.floor(e+l),p=Math.floor(r+l),v=(d+y+p)*h,b=t-d+v,w=e-y+v,m=r-p+v;b>=w?w>=m?(n=1,o=0,i=0,u=1,a=1,c=0):b>=m?(n=1,o=0,i=0,u=1,a=0,c=1):(n=0,o=0,i=1,u=1,a=0,c=1):w<m?(n=0,o=0,i=1,u=0,a=1,c=1):b<m?(n=0,o=1,i=0,u=0,a=1,c=1):(n=0,o=1,i=0,u=1,a=1,c=0);var P=b-n+h,g=w-o+h,M=m-i+h,O=b-u+2*h,j=w-a+2*h,x=m-c+2*h,S=b-1+.5,k=w-1+.5,_=m-1+.5,R=s[(d&=255)+f[(y&=255)+f[p&=255]]],T=s[d+n+f[y+o+f[p+i]]],E=s[d+u+f[y+a+f[p+c]]],B=s[d+1+f[y+1+f[p+1]]],q=.6-b*b-w*w-m*m,z=.6-P*P-g*g-M*M,A=.6-O*O-j*j-x*x,V=.6-S*S-k*k-_*_;return 32*((q<0?0:(q*=q)*q*R.dot3(b,w,m))+(z<0?0:(z*=z)*z*T.dot3(P,g,M))+(A<0?0:(A*=A)*A*E.dot3(O,j,x))+(V<0?0:(V*=V)*V*B.dot3(S,k,_)))}},{key:"perlin2",value:function(t,e){var r=this.perm,n=this.gradP,o=Math.floor(t),i=Math.floor(e);t-=o,e-=i;var u=n[(o&=255)+r[i&=255]].dot2(t,e),a=n[o+r[i+1]].dot2(t,e-1),c=n[o+1+r[i]].dot2(t-1,e),f=n[o+1+r[i+1]].dot2(t-1,e-1),s=d(t);return y(y(u,c,s),y(a,f,s),d(e))}},{key:"perlin3",value:function(t,e,r){var n=this.perm,o=this.gradP,i=Math.floor(t),u=Math.floor(e),a=Math.floor(r);t-=i,e-=u,r-=a;var c=o[(i&=255)+n[(u&=255)+n[a&=255]]].dot3(t,e,r),f=o[i+n[u+n[a+1]]].dot3(t,e,r-1),s=o[i+n[u+1+n[a]]].dot3(t,e-1,r),l=o[i+n[u+1+n[a+1]]].dot3(t,e-1,r-1),h=o[i+1+n[u+n[a]]].dot3(t-1,e,r),p=o[i+1+n[u+n[a+1]]].dot3(t-1,e,r-1),v=o[i+1+n[u+1+n[a]]].dot3(t-1,e-1,r),b=o[i+1+n[u+1+n[a+1]]].dot3(t-1,e-1,r-1),w=d(t),m=d(e),P=d(r);return y(y(y(c,h,w),y(f,p,w),P),y(y(s,v,w),y(l,b,w),P),m)}}]),e}(),v=Phaser.Utils.Objects.GetValue,b=function(){function e(r){t(this,e),this.active=!0,this.noise=new p(v(r,"seed",Math.random())),this.periodScale=v(r,"periodScale",2e-4),this.rotateScale=v(r,"rotateScale",.3),this.velocity=new Phaser.Math.Vector2;}return r(e,[{key:"update",value:function(t,e){var r=e*this.periodScale,n=this.noise.perlin2(t.x*r,t.y*r)*Math.PI;this.velocity.set(t.velocityX,t.velocityY).rotate(n*this.rotateScale),t.velocityX=this.velocity.x,t.velocityY=this.velocity.y;}}]),e}();return function(e){!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&&o(t,e);}(i,Phaser.Plugins.BasePlugin);var n=u(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new b(t)}}]),i}()}));