UNPKG

phaser3-rex-plugins

Version:
7 lines (6 loc) 10.9 kB
!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).rexbracketparserplugin=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 i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=n.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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)}(r,"string"))?s:String(s)),n);}var r,s;}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(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&&s(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function o(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 a(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 i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return o(this,i)}}function u(){return u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},u.apply(this,arguments)}function l(t){return function(t){if(Array.isArray(t))return h(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return h(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return h(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}var c={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},f=function(t,e,i){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),r=t,s=i,o=0;o<n.length;o++){if(!r.hasOwnProperty(n[o])){s=i;break}s=r[n[o]],r=r[n[o]];}return s}return i}return i},p=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,v=/^0x[0-9A-F]+$/i,m=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(p.test(t))t=parseFloat(t);else if(v.test(t))t=parseInt(t,16);else switch(t){case"false":t=!1;break;case"true":t=!0;break;case"null":t=null;break;case"undefined":t=void 0;}return t},d=function(t){return t.replace(g,"\\$&").replace(y,"\\x2d")},g=/[|\\{}()[\]^$+*?.]/g,y=/-/g,E=function(){function e(i){t(this,e),this.setEventEmitter(f(i,"eventEmitter",void 0)),this.setValueConverter(f(i,"valueConvert",!0)),this.setLoopEnable(f(i,"loop",!1)),this.setMultipleLinesTagEnable(f(i,"multipleLinesTag",!1));var n=f(i,"delimiters","<>");this.setDelimiters(n[0],n[1]),this.setTranslateTagNameCallback(f(i,"translateTagNameCallback")),this.isRunning=!1,this.isPaused=!1,this.skipEventFlag=!1,this.justCompleted=!1,this.lastTagStart=null,this.lastTagEnd=null,this.lastContent=null;}return i(e,[{key:"shutdown",value:function(){this.destroyEventEmitter();}},{key:"destroy",value:function(){this.shutdown();}},{key:"setMultipleLinesTagEnable",value:function(t){return void 0===t&&(t=!0),this.multipleLinesTagEnable=t,this}},{key:"setDelimiters",value:function(t,e){void 0===e&&(e=t[1],t=t[0]),this.delimiterLeft=t,this.delimiterRight=e,t=d(this.delimiterLeft),e=d(this.delimiterRight);var i=this.multipleLinesTagEnable?"gs":"gi";return this.reSplit=RegExp("".concat(t,"(.+?)").concat(e),i),this}},{key:"setTranslateTagNameCallback",value:function(t){return this.translateTagNameCallback=t,this}},{key:"setValueConverter",value:function(t){return !0===t?t=m:t||(t=b),this.valueConverter=t,this}},{key:"setLoopEnable",value:function(t){return void 0===t&&(t=!0),this.loopEnable=t,this}},{key:"setSource",value:function(t){return this.source=t,this}},{key:"resetIndex",value:function(t){return void 0===t&&(t=0),this.progressIndex=t,this.reSplit.lastIndex=t,this.lastTagStart=null,this.lastTagEnd=null,this.lastContent=null,this.justCompleted=!1,this.isRunning=!1,this}},{key:"start",value:function(t){return this.setSource(t).restart(),this}},{key:"restart",value:function(){this.resetIndex().next();}},{key:"next",value:function(){if(this.isPaused&&this.onResume(),this.isRunning)return this;if(this.isRunning=!0,this.justCompleted)return this.isRunning=!1,this;0===this.reSplit.lastIndex&&this.onStart();var t=this.source,e=t.length;for(this.reSplit.lastIndex=this.progressIndex;;){var i=this.reSplit.exec(t);if(!i){if(this.progressIndex<e&&(this.onContent(t.substring(this.progressIndex,e)),this.isPaused)){this.progressIndex=e;break}return this.onComplete(),void(this.isRunning=!1)}var n=this.reSplit.lastIndex,r=n-i[0].length;if(this.progressIndex<r&&(this.onContent(t.substring(this.progressIndex,r)),this.isPaused)){this.progressIndex=r;break}if(this.onTag(i[1]),this.progressIndex=n,this.isPaused)break}return this.isRunning=!1,this}},{key:"skipEvent",value:function(){return this.skipEventFlag=!0,this}},{key:"pause",value:function(){return this.isPaused||this.onPause(),this}},{key:"pauseUntilEvent",value:function(t,e){return this.isPaused||(this.pause(),t.once(e,(function(){this.next();}),this)),this}},{key:"onContent",value:function(t){this.skipEventFlag=!1,this.emit("content",t),this.lastContent=t;}},{key:"onTag",value:function(t){}},{key:"onStart",value:function(){this.isRunning=!0,this.emit("start",this);}},{key:"onComplete",value:function(){this.isRunning=!1,this.justCompleted=!0,this.emit("complete",this),this.loopEnable&&this.resetIndex();}},{key:"onPause",value:function(){this.isPaused=!0,this.emit("pause",this);}},{key:"onResume",value:function(){this.isPaused=!1,this.emit("resume",this);}}]),e}(),b=function(t){return t}; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2019 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */Object.assign(E.prototype,c);var k=function(e){n(o,e);var s=a(o);function o(e){var i;t(this,o),void 0===e&&(e={}),e.hasOwnProperty("multipleLinesTag")||(e.multipleLinesTag=!1),(i=s.call(this,e)).setTagExpression(f(e,"regex.tag",void 0)),i.setValueExpression(f(e,"regex.value",void 0));var n=f(e,"delimiters","<>");return i.setDelimiters(n[0],n[1]),i}return i(o,[{key:"setTagExpression",value:function(t){return t||(t=x),this.tagExpression=t,this}},{key:"setValueExpression",value:function(t){return t||(t=x),this.valueExpression=t,this}},{key:"setDelimiters",value:function(t,e){u(r(o.prototype),"setDelimiters",this).call(this,t,e);var i="(".concat(this.tagExpression,")(=(").concat(this.valueExpression,"))?");if(this.reTag=RegExp(i,"i"),this.tagExpression!==x||this.valueExpression!==x){var n="".concat(this.tagExpression,"(=").concat(this.valueExpression,")?"),s="/".concat(this.tagExpression);t=d(this.delimiterLeft),e=d(this.delimiterRight);var a=this.multipleLinesTagEnable?"gs":"gi";this.reSplit=RegExp("".concat(t,"((").concat(n,")|(").concat(s,"))").concat(e),a);}return this}},{key:"onTag",value:function(t){var e=t.match(this.reTag),i=e[1],n="/"===i.charAt(0);if(n&&(i=i.substring(1,i.length)),this.translateTagNameCallback&&(i=this.translateTagNameCallback(i)),this.skipEventFlag=!1,n)this.emit("-".concat(i)),this.skipEventFlag||this.emit("-",i),this.lastTagEnd=i;else {var r=function(t,e){if(null==t)return [];void 0===e&&(e=m);for(var i=t.split(","),n=0,r=i.length;n<r;n++)i[n]=e(i[n]);return i}(e[3],this.valueConverter);this.emit.apply(this,["+".concat(i)].concat(l(r))),this.skipEventFlag||this.emit.apply(this,["+",i].concat(l(r))),this.lastTagStart=i;}}}]),o}(E),x="[^=]+";return function(e){n(s,Phaser.Plugins.BasePlugin);var r=a(s);function s(e){return t(this,s),r.call(this,e)}return i(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new k(t)}}]),s}()}));