UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 6.62 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexswirlpipelineplugin=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(i=r.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(i,"string"))?o:String(o)),r);}var i,o;}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t);}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function u(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function a(e){var t=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(e){return !1}}();return function(){var n,r=o(e);if(t){var i=o(this).constructor;n=Reflect.construct(r,arguments,i);}else n=r.apply(this,arguments);return u(this,n)}}var f=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,c=Phaser.Utils.Objects.GetValue,l=Phaser.Math.DegToRad,p=Phaser.Math.RadToDeg,h=function(e){i(o,e);var n=a(o);function o(e){var r;return t(this,o),(r=n.call(this,{name:"rexSwirlPostFx",game:e,renderTarget:!0,fragShader:"#ifdef GL_FRAGMENT_PRECISION_HIGH\n#define highmedp highp\n#else\n#define highmedp mediump\n#endif\nprecision highmedp float;\n\n// Scene buffer\nuniform sampler2D uMainSampler; \nvarying vec2 outTexCoord;\n\n// Effect parameters\nuniform vec2 texSize;\nuniform vec2 center;\nuniform float radius;\nuniform float angle;\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize;\n tc -= center;\n float dist = length(tc);\n if (dist < radius) {\n float percent = (radius - dist) / radius;\n float theta = percent * percent * angle * 8.0;\n float s = sin(theta);\n float c = cos(theta);\n tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));\n }\n tc += center;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n}\n"})).centerX=0,r.centerY=0,r.radius=0,r.rotation=0,r}return r(o,[{key:"resetFromJSON",value:function(e){this.radius=c(e,"radius",0);var t=c(e,"rotation",void 0);return void 0===t?this.setAngle(c(e,"angle",0)):this.setRotation(t),this.setCenter(c(e,"center.x",void 0),c(e,"center.y",void 0)),this}},{key:"onPreRender",value:function(){this.set1f("radius",this.radius),this.set1f("angle",this.rotation);var e=this.renderer.width,t=this.renderer.height;this.set2f("center",this.centerX,t-this.centerY),this.set2f("texSize",e,t);}},{key:"setRadius",value:function(e){return this.radius=e,this}},{key:"setRotation",value:function(e){return this.rotation=e,this}},{key:"angle",get:function(){return p(this.rotation)},set:function(e){this.rotation=l(e);}},{key:"setAngle",value:function(e){return this.angle=e,this}},{key:"setCenter",value:function(e,t){return void 0===e&&(e=this.renderer.width/2,t=this.renderer.height/2),this.centerX=e,this.centerY=t,this}}]),o}(f),d=Phaser.Game,v=function(e){return e instanceof d},y=Phaser.Scene,P=function(e){return e instanceof y},m=function(t,n,r){var i;(i=t,null==i||"object"!==e(i)?null:v(i)?i:v(i.game)?i.game:P(i)?i.sys.game:P(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,r);},g=Phaser.Utils.Array.SpliceOne,b=function(e){i(o,Phaser.Plugins.BasePlugin);var n=a(o);function o(){return t(this,o),n.apply(this,arguments)}return r(o,[{key:"setPostPipelineClass",value:function(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}},{key:"start",value:function(){this.game.events.once("destroy",this.destroy,this),m(this.game,this.postFxPipelineName,this.PostFxPipelineClass);}},{key:"add",value:function(e,t){return function(e,t,n){void 0===n&&(n={}),e.setPostPipeline(t);var r=e.postPipelines[e.postPipelines.length-1];return r.resetFromJSON(n),n.name&&(r.name=n.name),r}(e,this.PostFxPipelineClass,t)}},{key:"remove",value:function(e,t){return function(e,t,n){if(void 0===n)for(var r=(i=e.postPipelines).length-1;r>=0;r--)(s=i[r])instanceof t&&(s.destroy(),g(i,r));else {r=0;for(var i,o=(i=e.postPipelines).length;r<o;r++){var s;(s=i[r])instanceof t&&s.name===n&&(s.destroy(),g(i,r));}}}(e,this.PostFxPipelineClass,t),this}},{key:"get",value:function(e,t){return function(e,t,n){if(void 0===n){for(var r=[],i=0,o=(s=e.postPipelines).length;i<o;i++)(u=s[i])instanceof t&&r.push(u);return r}var s;for(i=0,o=(s=e.postPipelines).length;i<o;i++){var u;if((u=s[i])instanceof t&&u.name===n)return u}}(e,this.PostFxPipelineClass,t)}}]),o}(),x=function(e){return null==e||""===e||0===e.length},S=function(e){i(o,e);var n=a(o);function o(e){var r;return t(this,o),(r=n.call(this,e)).setPostPipelineClass(h,"rexSwirlPostFx"),r}return r(o)}(b);return function(t,n,r,i){if(void 0===i&&(i="."),"object"===e(t)){if(x(n)){if(null==r)return;"object"===e(r)&&(t=r);}else {"string"==typeof n&&(n=n.split(i));var o=n.pop(),s=function(t,n,r){var i=t;if(x(n));else {var o;"string"==typeof n&&(n=n.split("."));for(var s=0,u=n.length;s<u;s++){var a;null!=i[o=n[s]]&&"object"===e(i[o])||(a=s===u-1?void 0===r?{}:r:{},i[o]=a),i=i[o];}}return i}(t,n);s[o]=r;}}}(window,"RexPlugins.Pipelines.SwirlPostFx",h),S}));