phaser3-rex-plugins
Version:
2 lines (1 loc) • 9.44 kB
JavaScript
var t,e;t=void 0,e=function(){function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,n="~";function s(){}function r(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function i(t,e,s,i,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new r(s,i||t,o),h=n?n+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),a.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=n?n+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,i=s.length,o=new Array(i);r<i;r++)o[r]=s[r].fn;return o},a.prototype.listenerCount=function(t){var e=n?n+t:t,s=this._events[e];return s?s.fn?1:s.length:0},a.prototype.emit=function(t,e,s,r,i,o){var a=n?n+t:t;if(!this._events[a])return!1;var h,u,p=this._events[a],v=arguments.length;if(p.fn){switch(p.once&&this.removeListener(t,p.fn,void 0,!0),v){case 1:return p.fn.call(p.context),!0;case 2:return p.fn.call(p.context,e),!0;case 3:return p.fn.call(p.context,e,s),!0;case 4:return p.fn.call(p.context,e,s,r),!0;case 5:return p.fn.call(p.context,e,s,r,i),!0;case 6:return p.fn.call(p.context,e,s,r,i,o),!0}for(u=1,h=new Array(v-1);u<v;u++)h[u-1]=arguments[u];p.fn.apply(p.context,h)}else{var f,c=p.length;for(u=0;u<c;u++)switch(p[u].once&&this.removeListener(t,p[u].fn,void 0,!0),v){case 1:p[u].fn.call(p[u].context);break;case 2:p[u].fn.call(p[u].context,e);break;case 3:p[u].fn.call(p[u].context,e,s);break;case 4:p[u].fn.call(p[u].context,e,s,r);break;default:if(!h)for(f=1,h=new Array(v-1);f<v;f++)h[f-1]=arguments[f];p[u].fn.apply(p[u].context,h)}}return!0},a.prototype.on=function(t,e,n){return i(this,t,e,n,!1)},a.prototype.once=function(t,e,n){return i(this,t,e,n,!0)},a.prototype.removeListener=function(t,e,s,r){var i=n?n+t:t;if(!this._events[i])return this;if(!e)return o(this,i),this;var a=this._events[i];if(a.fn)a.fn!==e||r&&!a.once||s&&a.context!==s||o(this,i);else{for(var h=0,u=[],p=a.length;h<p;h++)(a[h].fn!==e||r&&!a[h].once||s&&a[h].context!==s)&&u.push(a[h]);u.length?this._events[i]=1===u.length?u[0]:u:o(this,i)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a}(e);var n=t(e.exports);class s extends n{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var r={setEventEmitter(t,e){return void 0===e&&(e=s),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){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):[]}},i=function(t,e,n,s){var r=t&&("object"==typeof t||"function"==typeof t),i=s&&("object"==typeof s||"function"==typeof s);if(!r&&!i)return n;var a=String(e);if(r&&a in t)return t[a];if(i&&a in s)return s[a];if(-1===a.indexOf("."))return n;var h=a.split(".");if(r){var u=o(t,h,n);if(u.found)return u.value}if(i){var p=o(s,h,n);if(p.found)return p.value}return n},o=function(t,e,n){for(var s=t,r=n,i=0,o=e.length;i<o;i++){var h=e[i];if(!s||"object"!=typeof s&&"function"!=typeof s||!(h in s))return a.found=!1,a;s=r=s[h]}return a.found=!0,a.value=r,a},a={};const h=["next","exit","enter"];let u=class{constructor(t){var e=i(t,"states",void 0);e&&this.addStates(e);var n=i(t,"extend",void 0);if(n)for(var s in n)this.hasOwnProperty(s)&&void 0!==this[s]||(this[s]=n[s]);var r=i(t,"eventEmitter",void 0),o=i(t,"EventEmitterClass",void 0);this.setEventEmitter(r,o),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(i(t,"enable",!0)),this.start(i(t,"start",void 0));var e=i(t,"init",void 0);return e&&e.call(this),this}toJSON(){return{curState:this.state,prevState:this.prevState,enable:this.enable,start:this._start}}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}set state(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 s="enter_"+this._state,r=this[s];r&&r.call(this),this.emit(s,this)}}}get state(){return this._state}get prevState(){return this._prevState}start(t){return this._start=t,this._prevState=void 0,this._state=t,this}goto(t){return null!=t&&(this.state=t),this}next(){var t,e=this["next_"+this.state];return e&&(t="string"==typeof e?e:e.call(this)),this.goto(t),this}get stateProperties(){return h}addState(t,e){"string"!=typeof t&&(t=(e=t).name);for(var n=this.stateProperties,s=0,r=n.length;s<r;s++){var i=n[s],o=e[i];o&&(this[`${i}_${t}`]=o)}return this}addStates(t){if(Array.isArray(t))for(var e=0,n=t.length;e<n;e++)this.addState(t[e]);else for(var s in t)this.addState(s,t[s]);return this}runMethod(t,e,n,s,r,i){var o=this[t+"_"+this.state];if(o){var a=arguments.length;switch(a){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,s);case 5:return o.call(this,e,n,s,r);case 6:return o.call(this,e,n,s,r,i)}for(var h=new Array(a-1),u=1;u<a;u++)h[u-1]=arguments[u];return o.apply(this,h)}}};Object.assign(u.prototype,r);var p=function(t,e,n,s,r){void 0===r&&(r=!1);var i=t._events[e];if(!i)return!1;for(var o=0,a=i.length;o<a;o++){var h=i[o];if(h.fn===n&&h.context===s&&h.once===r)return!0}return!1};const v=["next","exit","enter","update","preupdate","postupdate"];class f extends u{shutdown(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,super.shutdown()}resetFromJSON(t){return super.resetFromJSON(t),this._scene=i(t,"scene",void 0),this}get stateProperties(){return v}update(t,e){this.runMethod("update",t,e)}preupdate(t,e){this.runMethod("preupdate",t,e)}postupdate(t,e){this.runMethod("postupdate",t,e)}startUpdate(t){t||(t=this._scene);var e=t.sys.events;return p(e,"update",this.update,this)||(this._scene=t,e.on("update",this.update,this)),this}stopUpdate(){return this._scene?(this._scene.sys.events.off("update",this.update,this),this):this}startPreUpdate(t){t||(t=this._scene);var e=t.sys.events;return p(e,"preupdate",this.preupdate,this)||(this._scene=t,e.on("preupdate",this.preupdate,this)),this}stopPreUpdate(){return this._scene?(this._scene.sys.events.off("preupdate",this.preupdate,this),this):this}startPostUpdate(t){t||(t=this._scene);var e=t.sys.events;return p(e,"postupdate",this.postupdate,this)||(this._scene=t,e.on("postupdate",this.postupdate,this)),this}stopPostUpdate(){return this._scene?(this._scene.sys.events.off("postupdate",this.postupdate,this),this):this}}var c=function(t){return null!==t&&"object"==typeof t};class l extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t){return new f(t)}}return function(t,e,n,s="."){if(!c(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(s)||"number"==typeof e)return t[e]=n,t;var r=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,s);if(0===r.length)return t;for(var i=t,o=r.length,a=0;a<o-1;a++){var h=r[a],u=i[h];c(u)||(i[h]={}),i=i[h]}i[r[o-1]]=n}(window,"RexPlugins.FSM",f),l},"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();