UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 7.12 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).rexkeyshubplugin=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 n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,f(i.key),i);}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),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 r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function s(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 u(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,i=r(t);if(e){var o=r(this).constructor;n=Reflect.construct(i,arguments,o);}else n=i.apply(this,arguments);return s(this,n)}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},a.apply(this,arguments)}function f(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(t,"string");return "symbol"==typeof e?e:String(e)}var h={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):[]}},l=Phaser.Input.Keyboard.KeyCodes,c={};for(var p in l)c[l[p]]=p;var y=Phaser.Input.Keyboard.Key,v=Phaser.Utils.Array.Add,d=Phaser.Utils.Array.Remove,m=function(e){i(s,e);var o=u(s);function s(e,n){var i;return t(this,s),(i=o.call(this,e,n)).ports=[],i}return n(s,[{key:"destroy",value:function(){for(var t=0,e=this.ports.length;t<e;t++)this.ports[t].off("down",this.update,this).off("up",this.update,this);this.ports=void 0,a(r(s.prototype),"destroy",this).call(this);}},{key:"plug",value:function(t){return v(this.ports,t,0,(function(t){t.on("down",this.update,this).on("up",this.update,this),this.update(E);}),this),this}},{key:"unplug",value:function(t){return d(this.ports,t,(function(t){t.off("down",this.update,this).off("up",this.update,this),this.update(E);}),this),this}},{key:"update",value:function(t){if(void 0===t.cancelled&&(t.cancelled=0,t.stopImmediatePropagation=function(){t.cancelled=1;},t.stopPropagation=function(){t.cancelled=-1;}),-1!==t.cancelled){for(var e=!1,n=0,i=this.ports.length;n<i;n++)if(this.ports[n].isDown){e=!0;break}if(this.isDown!==e){if((t=E).timeStamp=Date.now(),t.keyCode=this.keyCode,e?this.onDown(t):this.onUp(t),!t.cancelled){var r=(e?"keydown-":"keyup-")+c[this.keyCode];this.plugin.emit(r,t);}if(!t.cancelled){r=e?"keydown":"keyup";this.plugin.emit(r,t);}}t.cancelled=0;}else t.cancelled=0;}}]),s}(y),E={timeStamp:0,keyCode:0,altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,location:0},g=Phaser.Utils.Objects.GetValue,_=Phaser.Input.Keyboard.KeyCodes,b=function(){function e(n,i){t(this,e),void 0===i&&(i={});var r=g(i,"eventEmitter",void 0),o=g(i,"EventEmitterClass",void 0);this.setEventEmitter(r,o),i.eventEmitter=this.getEventEmitter(),this.scene=n,this.keys={};}return n(e,[{key:"destroy",value:function(){for(var t in this.destroyEventEmitter(),this.keys)this.keys[t].destroy();this.keys=void 0;}},{key:"plugKey",value:function(t,e){return void 0===e&&(e=t.keyCode),this.addKey(e).plug(t),this}},{key:"plugKeys",value:function(t){if(Array.isArray(t))for(var e=0,n=t.length;e<n;e++)this.plugKey(t[e]);else for(var i in t)this.plugKey(t[i],i);return this}},{key:"unplug",value:function(t){if(Array.isArray(t))for(var e=0,n=t.length;e<n;e++)this.unplugKey(t[e]);else for(var i in t)this.unplugKey(t[i]);return this}},{key:"addKey",value:function(t){return "string"==typeof t&&(t=_[t.toUpperCase()]),this.keys.hasOwnProperty(t)||(this.keys[t]=new m(this,t)),this.keys[t]}},{key:"addKeys",value:function(t){var e={};if("string"==typeof t)for(var n=0,i=(t=t.split(",")).length;n<i;n++){var r=t[n].trim();r&&(e[r]=this.addKey(r));}else for(var o in t)e[o]=this.addKey(t[o]);return e}},{key:"createCursorKeys",value:function(){return this.addKeys({up:_.UP,down:_.DOWN,left:_.LEFT,right:_.RIGHT,space:_.SPACE,shift:_.SHIFT})}}]),e}();return Object.assign(b.prototype,h),function(e){i(o,Phaser.Plugins.BasePlugin);var r=u(o);function o(e){return t(this,o),r.call(this,e)}return n(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new b(t,e)}}]),o}()}));