UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 12.7 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).rexfsmplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(i=r.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(i,"string"))?s:String(s)),r);}var i,s;}function r(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(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);}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(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 n,r=s(t);if(e){var i=s(this).constructor;n=Reflect.construct(r,arguments,i);}else n=r.apply(this,arguments);return u(this,n)}}function c(){return c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(r){var i=Object.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(arguments.length<3?t:n):i.value}},c.apply(this,arguments)}function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var f={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}function i(t,e,n){this.fn=t,this.context=e,this.once=n||!1;}function s(t,e,r,s,o){if("function"!=typeof r)throw new TypeError("The listener must be a function");var u=new i(r,s||t,o),a=n?n+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],u]:t._events[a].push(u):(t._events[a]=u,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new r:delete t._events[e];}function u(){this._events=new r,this._eventsCount=0;}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),u.prototype.eventNames=function(){var t,r,i=[];if(0===this._eventsCount)return i;for(r in t=this._events)e.call(t,r)&&i.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},u.prototype.listeners=function(t){var e=n?n+t:t,r=this._events[e];if(!r)return [];if(r.fn)return [r.fn];for(var i=0,s=r.length,o=new Array(s);i<s;i++)o[i]=r[i].fn;return o},u.prototype.listenerCount=function(t){var e=n?n+t:t,r=this._events[e];return r?r.fn?1:r.length:0},u.prototype.emit=function(t,e,r,i,s,o){var u=n?n+t:t;if(!this._events[u])return !1;var a,c,h=this._events[u],f=arguments.length;if(h.fn){switch(h.once&&this.removeListener(t,h.fn,void 0,!0),f){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,e),!0;case 3:return h.fn.call(h.context,e,r),!0;case 4:return h.fn.call(h.context,e,r,i),!0;case 5:return h.fn.call(h.context,e,r,i,s),!0;case 6:return h.fn.call(h.context,e,r,i,s,o),!0}for(c=1,a=new Array(f-1);c<f;c++)a[c-1]=arguments[c];h.fn.apply(h.context,a);}else {var l,p=h.length;for(c=0;c<p;c++)switch(h[c].once&&this.removeListener(t,h[c].fn,void 0,!0),f){case 1:h[c].fn.call(h[c].context);break;case 2:h[c].fn.call(h[c].context,e);break;case 3:h[c].fn.call(h[c].context,e,r);break;case 4:h[c].fn.call(h[c].context,e,r,i);break;default:if(!a)for(l=1,a=new Array(f-1);l<f;l++)a[l-1]=arguments[l];h[c].fn.apply(h[c].context,a);}}return !0},u.prototype.on=function(t,e,n){return s(this,t,e,n,!1)},u.prototype.once=function(t,e,n){return s(this,t,e,n,!0)},u.prototype.removeListener=function(t,e,r,i){var s=n?n+t:t;if(!this._events[s])return this;if(!e)return o(this,s),this;var u=this._events[s];if(u.fn)u.fn!==e||i&&!u.once||r&&u.context!==r||o(this,s);else {for(var a=0,c=[],h=u.length;a<h;a++)(u[a].fn!==e||i&&!u[a].once||r&&u[a].context!==r)&&c.push(u[a]);c.length?this._events[s]=1===c.length?c[0]:c:o(this,s);}return this},u.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&o(this,e)):(this._events=new r,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=n,u.EventEmitter=u,t.exports=u;}(f);var l=function(t){i(s,t);var n=a(s);function s(){return e(this,s),n.apply(this,arguments)}return r(s,[{key:"shutdown",value:function(){this.removeAllListeners();}},{key:"destroy",value:function(){this.removeAllListeners();}}]),s}(h(f.exports)),p={setEventEmitter:function(t,e){return void 0===e&&(e=l),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):[]}},v=function(t,e,n){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var r=e.split("."),i=t,s=n,o=0;o<r.length;o++){if(!i.hasOwnProperty(r[o])){s=n;break}s=i[r[o]],i=i[r[o]];}return s}return n}return n},y=["next","exit","enter"],d=function(){function t(n){e(this,t);var r=v(n,"states",void 0);r&&this.addStates(r);var i=v(n,"extend",void 0);if(i)for(var s in i)this.hasOwnProperty(s)&&void 0!==this[s]||(this[s]=i[s]);var o=v(n,"eventEmitter",void 0),u=v(n,"EventEmitterClass",void 0);this.setEventEmitter(o,u),this._stateLock=!1,this.resetFromJSON(n);}return r(t,[{key:"shutdown",value:function(){this.destroyEventEmitter();}},{key:"destroy",value:function(){this.shutdown();}},{key:"resetFromJSON",value:function(t){this.setEnable(v(t,"enable",!0)),this.start(v(t,"start",void 0));var e=v(t,"init",void 0);return e&&e.call(this),this}},{key:"toJSON",value:function(){return {curState:this.state,prevState:this.prevState,enable:this.enable,start:this._start}}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"state",get:function(){return this._state},set:function(t){if(this.enable&&!this._stateLock&&this._state!==t){if(this._prevState=this._state,this._state=t,this._stateLock=!0,this.emit("statechange",this),null!=this._prevState){var e="exit_"+this._prevState,n=this[e];n&&n.call(this),this.emit(e,this);}if(this._stateLock=!1,null!=this._state){var r="enter_"+this._state,i=this[r];i&&i.call(this),this.emit(r,this);}}}},{key:"prevState",get:function(){return this._prevState}},{key:"start",value:function(t){return this._start=t,this._prevState=void 0,this._state=t,this}},{key:"goto",value:function(t){return null!=t&&(this.state=t),this}},{key:"next",value:function(){var t,e=this["next_"+this.state];return e&&(t="string"==typeof e?e:e.call(this)),this.goto(t),this}},{key:"stateProperties",get:function(){return y}},{key:"addState",value:function(t,e){"string"!=typeof t&&(t=(e=t).name);for(var n=this.stateProperties,r=0,i=n.length;r<i;r++){var s=n[r],o=e[s];o&&(this["".concat(s,"_").concat(t)]=o);}return this}},{key:"addStates",value:function(t){if(Array.isArray(t))for(var e=0,n=t.length;e<n;e++)this.addState(t[e]);else for(var r in t)this.addState(r,t[r]);return this}},{key:"runMethod",value:function(t,e,n,r,i,s){var o=this[t+"_"+this.state];if(o){var u=arguments.length;switch(u){case 1:return o.call(this);case 2:return o.call(this,e);case 3:return o.call(this,e,n);case 4:return o.call(this,e,n,r);case 5:return o.call(this,e,n,r,i);case 6:return o.call(this,e,n,r,i,s)}for(var a=new Array(u-1),c=1;c<u;c++)a[c-1]=arguments[c];return o.apply(this,a)}}}]),t}();Object.assign(d.prototype,p);var _=function(t,e,n,r,i){void 0===i&&(i=!1);var s=t._events[e];if(!s)return !1;for(var o=0,u=s.length;o<u;o++){var a=s[o];if(a.fn===n&&a.context===r&&a.once===i)return !0}return !1},m=["next","exit","enter","update","preupdate","postupdate"],b=function(t){i(o,t);var n=a(o);function o(){return e(this,o),n.apply(this,arguments)}return r(o,[{key:"shutdown",value:function(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,c(s(o.prototype),"shutdown",this).call(this);}},{key:"resetFromJSON",value:function(t){return c(s(o.prototype),"resetFromJSON",this).call(this,t),this._scene=v(t,"scene",void 0),this}},{key:"stateProperties",get:function(){return m}},{key:"update",value:function(t,e){this.runMethod("update",t,e);}},{key:"preupdate",value:function(t,e){this.runMethod("preupdate",t,e);}},{key:"postupdate",value:function(t,e){this.runMethod("postupdate",t,e);}},{key:"startUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return _(e,"update",this.update,this)||(this._scene=t,e.on("update",this.update,this)),this}},{key:"stopUpdate",value:function(){return this._scene?(this._scene.sys.events.off("update",this.update,this),this):this}},{key:"startPreUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return _(e,"preupdate",this.preupdate,this)||(this._scene=t,e.on("preupdate",this.preupdate,this)),this}},{key:"stopPreUpdate",value:function(){return this._scene?(this._scene.sys.events.off("preupdate",this.preupdate,this),this):this}},{key:"startPostUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return _(e,"postupdate",this.postupdate,this)||(this._scene=t,e.on("postupdate",this.postupdate,this)),this}},{key:"stopPostUpdate",value:function(){return this._scene?(this._scene.sys.events.off("postupdate",this.postupdate,this),this):this}}]),o}(d),E=function(t){return null==t||""===t||0===t.length},g=function(t){i(s,Phaser.Plugins.BasePlugin);var n=a(s);function s(t){return e(this,s),n.call(this,t)}return r(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new b(t)}}]),s}();return function(e,n,r,i){if(void 0===i&&(i="."),"object"===t(e)){if(E(n)){if(null==r)return;"object"===t(r)&&(e=r);}else {"string"==typeof n&&(n=n.split(i));var s=n.pop(),o=function(e,n,r){var i=e;if(E(n));else {var s;"string"==typeof n&&(n=n.split("."));for(var o=0,u=n.length;o<u;o++){var a;null!=i[s=n[o]]&&"object"===t(i[s])||(a=o===u-1?void 0===r?{}:r:{},i[s]=a),i=i[s];}}return i}(e,n);o[s]=r;}}}(window,"RexPlugins.FSM",b),g}));