text: !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).rexcolorreplacepipelineplugin=n()}(this,function(){"use strict";function u(e){return(u="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)}function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(e,n){for(var o=0;o<n.length;o++){var t=n[o];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function i(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}function l(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),n&&o(e,n)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,n){return(o=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function a(e,n){if(n&&("object"==typeof n||"function"==typeof n))return n;if(void 0!==n)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(t){var r=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 e,n=s(t);if(r){var o=s(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return a(this,e)}}function c(e){return null==e||""===e||0===e.length}var e=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,n=Phaser.Utils.Objects.GetValue,p=Phaser.Display.Color.IntegerToRGB,h=Phaser.Display.Color,y=function(){l(t,e);var o=f(t);function t(e){var n;return r(this,t),(n=o.call(this,{name:"rexColorReplacePostFx",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 epsilon;\nuniform vec3 originalColor;\nuniform vec3 newColor;\n\nvoid main (void) {\n  vec4 currentColor = texture2D(uMainSampler, outTexCoord);\n  vec3 colorDiff = originalColor - (currentColor.rgb / max(currentColor.a, 0.0000000001));\n  float colorDistance = length(colorDiff);\n  float doReplace = step(colorDistance, epsilon);\n  gl_FragColor = vec4(mix(currentColor.rgb, (newColor + colorDiff) * currentColor.a, doReplace), currentColor.a);\n}\n"})).epsilon=.4,n._originalColor=new h,n._newColor=new h,n}return i(t,[{key:"resetFromJSON",value:function(e){return this.setEpsilon(n(e,"epsilon",.4)),this.setOriginalColor(n(e,"originalColor",16711680)),this.setNewColor(n(e,"newColor",0)),this}},{key:"onPreRender",value:function(){this.set1f("epsilon",this.epsilon),this.set3f("originalColor",this._originalColor.redGL,this._originalColor.greenGL,this._originalColor.blueGL),this.set3f("newColor",this._newColor.redGL,this._newColor.greenGL,this._newColor.blueGL)}},{key:"setEpsilon",value:function(e){return this.epsilon=e,this}},{key:"originalColor",get:function(){return this._originalColor},set:function(e){"number"==typeof e&&(e=p(e)),this._originalColor.setFromRGB(e)}},{key:"setOriginalColor",value:function(e){return this.originalColor=e,this}},{key:"newColor",get:function(){return this._newColor},set:function(e){"number"==typeof e&&(e=p(e)),this._newColor.setFromRGB(e)}},{key:"setNewColor",value:function(e){return this.newColor=e,this}}]),t}(),v=Phaser.Utils.Array.SpliceOne,g=function(){l(n,Phaser.Plugins.BasePlugin);var e=f(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"setPostPipelineClass",value:function(e,n){return this.PostFxPipelineClass=e,this.postFxPipelineName=n,this}},{key:"start",value:function(){this.game.events.once("destroy",this.destroy,this),this.game.renderer.pipelines.addPostPipeline(this.postFxPipelineName,this.PostFxPipelineClass)}},{key:"add",value:function(e,n){void 0===n&&(n={}),e.setPostPipeline(this.PostFxPipelineClass);var o=e.postPipelines[e.postPipelines.length-1];return o.resetFromJSON(n),n.name&&(o.name=n.name),o}},{key:"remove",value:function(e,n){var o=this.PostFxPipelineClass;if(void 0===n)for(var t=(r=e.postPipelines).length-1;0<=t;t--){(l=r[t])instanceof o&&(l.destroy(),v(r,t))}else{t=0;for(var r,i=(r=e.postPipelines).length;t<i;t++){var l;(l=r[t])instanceof o&&l.name===n&&(l.destroy(),v(r,t))}}return this}},{key:"get",value:function(e,n){var o=this.PostFxPipelineClass;if(void 0===n){for(var t=[],r=0,i=(l=e.postPipelines).length;r<i;r++){(s=l[r])instanceof o&&t.push(s)}return t}var l;for(r=0,i=(l=e.postPipelines).length;r<i;r++){var s;if((s=l[r])instanceof o&&s.name===n)return s}}}]),n}(),d=function(){l(t,g);var o=f(t);function t(e){var n;return r(this,t),(n=o.call(this,e)).setPostPipelineClass(y,"rexColorReplacePostFx"),n}return t}();return function(e,n,o){if("object"===u(e)){if(c(n)){if(null==o)return;"object"===u(o)&&(e=o)}else{"string"==typeof n&&(n=n.split("."));var t=n.pop();(function(e,n,o){var t=e;if(!c(n)){var r;"string"==typeof n&&(n=n.split("."));for(var i=0,l=n.length;i<l;i++){var s;if(null==t[r=n[i]]||"object"!==u(t[r]))s=i!==l-1||void 0===o?{}:o,t[r]=s;t=t[r]}}return t})(e,n)[t]=o}}}(window,"RexPlugins.Pipelines.ColorReplacePostFx",y),d});
  