phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.68 kB
JavaScript
!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).rexbarrelpipelineplugin=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 f(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 a=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,c=Phaser.Utils.Objects.GetValue,l=function(e){i(o,e);var n=f(o);function o(e){var r;return t(this,o),(r=n.call(this,{name:"rexBarrelPostFx",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 float shrinkMode;\nuniform vec2 texSize;\nuniform vec2 center;\nuniform float radius;\nuniform float power;\nuniform float intensity;\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize; \n tc -= center;\n float dist = length(tc) / radius;\n float factor = pow(dist, power);\n if (shrinkMode > 0.0) {\n factor = 1.0 / factor;\n }\n\n tc *= mix(1.0, factor, intensity);\n tc += center;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n\n}\n"})).shrinkMode=!1,r.fishEyeMode=0,r.centerX=0,r.centerY=0,r.radius=0,r.power=1,r.intensity=1,r}return r(o,[{key:"resetFromJSON",value:function(e){return this.setShrinkMode(c(e,"shrink",!1)),this.setRadius(c(e,"radius",0)),this.setCenter(c(e,"center.x",void 0),c(e,"center.y",void 0)),this.setPower(c(e,"power",.5)),this.setIntensity(c(e,"intensity",1)),this}},{key:"onPreRender",value:function(){this.set1f("shrinkMode",this.shrinkMode?1:0),this.set1f("radius",this.radius);var e=this.renderer.width,t=this.renderer.height;this.set2f("center",this.centerX,t-this.centerY),this.set2f("texSize",e,t),this.set1f("power",this.power),this.set1f("intensity",this.intensity);}},{key:"setRadius",value:function(e){return this.radius=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}},{key:"setPower",value:function(e){return this.power=e,this}},{key:"setIntensity",value:function(e){return this.intensity=e,this}},{key:"setShrinkMode",value:function(e){return void 0===e&&(e=!0),this.shrinkMode=e,this}}]),o}(a),p=Phaser.Game,h=function(e){return e instanceof p},d=Phaser.Scene,y=function(e){return e instanceof d},v=function(t,n,r){var i;(i=t,null==i||"object"!==e(i)?null:h(i)?i:h(i.game)?i.game:y(i)?i.sys.game:y(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,r);},m=Phaser.Utils.Array.SpliceOne,P=function(e){i(o,Phaser.Plugins.BasePlugin);var n=f(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),v(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(),m(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(),m(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}(),b=function(e){return null==e||""===e||0===e.length},g=function(e){i(o,e);var n=f(o);function o(e){var r;return t(this,o),(r=n.call(this,e)).setPostPipelineClass(l,"rexBarrelPostFx"),r}return r(o)}(P);return function(t,n,r,i){if(void 0===i&&(i="."),"object"===e(t)){if(b(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(b(n));else {var o;"string"==typeof n&&(n=n.split("."));for(var s=0,u=n.length;s<u;s++){var f;null!=i[o=n[s]]&&"object"===e(i[o])||(f=s===u-1?void 0===r?{}:r:{},i[o]=f),i=i[o];}}return i}(t,n);s[o]=r;}}}(window,"RexPlugins.Pipelines.BarrelPostFx",l),g}));