UNPKG

phaser3-rex-plugins

Version:
1,660 lines (1,568 loc) 91.5 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.rexgesturesplugin = factory()); })(this, (function () { 'use strict'; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } var ObjectFactory = /*#__PURE__*/function () { function ObjectFactory(scene) { _classCallCheck(this, ObjectFactory); this.scene = scene; } _createClass(ObjectFactory, null, [{ key: "register", value: function register(type, callback) { ObjectFactory.prototype[type] = callback; } }]); return ObjectFactory; }(); var EventEmitterMethods$1 = { setEventEmitter: function setEventEmitter(eventEmitter, EventEmitterClass) { if (EventEmitterClass === undefined) { EventEmitterClass = Phaser.Events.EventEmitter; // Use built-in EventEmitter class by default } this._privateEE = eventEmitter === true || eventEmitter === undefined; this._eventEmitter = this._privateEE ? new EventEmitterClass() : eventEmitter; return this; }, destroyEventEmitter: function destroyEventEmitter() { if (this._eventEmitter && this._privateEE) { this._eventEmitter.shutdown(); } return this; }, getEventEmitter: function getEventEmitter() { return this._eventEmitter; }, on: function on() { if (this._eventEmitter) { this._eventEmitter.on.apply(this._eventEmitter, arguments); } return this; }, once: function once() { if (this._eventEmitter) { this._eventEmitter.once.apply(this._eventEmitter, arguments); } return this; }, off: function off() { if (this._eventEmitter) { this._eventEmitter.off.apply(this._eventEmitter, arguments); } return this; }, emit: function emit(event) { if (this._eventEmitter && event) { this._eventEmitter.emit.apply(this._eventEmitter, arguments); } return this; }, addListener: function addListener() { if (this._eventEmitter) { this._eventEmitter.addListener.apply(this._eventEmitter, arguments); } return this; }, removeListener: function removeListener() { if (this._eventEmitter) { this._eventEmitter.removeListener.apply(this._eventEmitter, arguments); } return this; }, removeAllListeners: function removeAllListeners() { if (this._eventEmitter) { this._eventEmitter.removeAllListeners.apply(this._eventEmitter, arguments); } return this; }, listenerCount: function listenerCount() { if (this._eventEmitter) { return this._eventEmitter.listenerCount.apply(this._eventEmitter, arguments); } return 0; }, listeners: function listeners() { if (this._eventEmitter) { return this._eventEmitter.listeners.apply(this._eventEmitter, arguments); } return []; }, eventNames: function eventNames() { if (this._eventEmitter) { return this._eventEmitter.eventNames.apply(this._eventEmitter, arguments); } return []; } }; var SceneClass = Phaser.Scene; var IsSceneObject = function IsSceneObject(object) { return object instanceof SceneClass; }; var GetSceneObject = function GetSceneObject(object) { if (object == null || _typeof(object) !== 'object') { return null; } else if (IsSceneObject(object)) { // object = scene return object; } else if (object.scene && IsSceneObject(object.scene)) { // object = game object return object.scene; } else if (object.parent && object.parent.scene && IsSceneObject(object.parent.scene)) { // parent = bob object return object.parent.scene; } else { return null; } }; var GameClass = Phaser.Game; var IsGame = function IsGame(object) { return object instanceof GameClass; }; var GetGame = function GetGame(object) { if (object == null || _typeof(object) !== 'object') { return null; } else if (IsGame(object)) { return object; } else if (IsGame(object.game)) { return object.game; } else if (IsSceneObject(object)) { // object = scene object return object.sys.game; } else if (IsSceneObject(object.scene)) { // object = game object return object.scene.sys.game; } }; var GetValue$a = Phaser.Utils.Objects.GetValue; var ComponentBase = /*#__PURE__*/function () { function ComponentBase(parent, config) { _classCallCheck(this, ComponentBase); this.setParent(parent); // gameObject, scene, or game this.isShutdown = false; // Event emitter, default is private event emitter this.setEventEmitter(GetValue$a(config, 'eventEmitter', true)); // Register callback of parent destroy event, also see `shutdown` method if (this.parent) { if (this.parent === this.scene) { // parent is a scene this.scene.sys.events.once('shutdown', this.onEnvDestroy, this); } else if (this.parent === this.game) { // parent is game this.game.events.once('shutdown', this.onEnvDestroy, this); } else if (this.parent.once) { // parent is game object or something else this.parent.once('destroy', this.onParentDestroy, this); } // bob object does not have event emitter } } _createClass(ComponentBase, [{ key: "shutdown", value: function shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } // parent might not be shutdown yet if (this.parent) { if (this.parent === this.scene) { // parent is a scene this.scene.sys.events.off('shutdown', this.onEnvDestroy, this); } else if (this.parent === this.game) { // parent is game this.game.events.off('shutdown', this.onEnvDestroy, this); } else if (this.parent.once) { // parent is game object or something else this.parent.off('destroy', this.onParentDestroy, this); } // bob object does not have event emitter } this.destroyEventEmitter(); this.parent = undefined; this.scene = undefined; this.game = undefined; this.isShutdown = true; } }, { key: "destroy", value: function destroy(fromScene) { this.shutdown(fromScene); } }, { key: "onEnvDestroy", value: function onEnvDestroy() { this.destroy(true); } }, { key: "onParentDestroy", value: function onParentDestroy(parent, fromScene) { this.destroy(fromScene); } }, { key: "setParent", value: function setParent(parent) { this.parent = parent; // gameObject, scene, or game this.scene = GetSceneObject(parent); this.game = GetGame(parent); return this; } }]); return ComponentBase; }(); Object.assign(ComponentBase.prototype, EventEmitterMethods$1); var GetValue$9 = Phaser.Utils.Objects.GetValue; var TickTask = /*#__PURE__*/function (_ComponentBase) { _inherits(TickTask, _ComponentBase); var _super = _createSuper(TickTask); function TickTask(parent, config) { var _this; _classCallCheck(this, TickTask); _this = _super.call(this, parent, config); _this._isRunning = false; _this.isPaused = false; _this.tickingState = false; _this.setTickingMode(GetValue$9(config, 'tickingMode', 1)); // boot() later return _this; } // override _createClass(TickTask, [{ key: "boot", value: function boot() { if (this.tickingMode === 2 && !this.tickingState) { this.startTicking(); } } // override }, { key: "shutdown", value: function shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } this.stop(); if (this.tickingState) { this.stopTicking(); } _get(_getPrototypeOf(TickTask.prototype), "shutdown", this).call(this, fromScene); } }, { key: "setTickingMode", value: function setTickingMode(mode) { if (typeof mode === 'string') { mode = TICKINGMODE[mode]; } this.tickingMode = mode; } // override }, { key: "startTicking", value: function startTicking() { this.tickingState = true; } // override }, { key: "stopTicking", value: function stopTicking() { this.tickingState = false; } }, { key: "isRunning", get: function get() { return this._isRunning; }, set: function set(value) { if (this._isRunning === value) { return; } this._isRunning = value; if (this.tickingMode === 1 && value != this.tickingState) { if (value) { this.startTicking(); } else { this.stopTicking(); } } } }, { key: "start", value: function start() { this.isPaused = false; this.isRunning = true; return this; } }, { key: "pause", value: function pause() { // Only can ba paused in running state if (this.isRunning) { this.isPaused = true; this.isRunning = false; } return this; } }, { key: "resume", value: function resume() { // Only can ba resumed in paused state (paused from running state) if (this.isPaused) { this.isRunning = true; } return this; } }, { key: "stop", value: function stop() { this.isPaused = false; this.isRunning = false; return this; } }, { key: "complete", value: function complete() { this.isPaused = false; this.isRunning = false; this.emit('complete', this.parent, this); } }]); return TickTask; }(ComponentBase); var TICKINGMODE = { 'no': 0, 'lazy': 1, 'always': 2 }; var GetValue$8 = Phaser.Utils.Objects.GetValue; var OnePointerTracer = /*#__PURE__*/function (_TickTask) { _inherits(OnePointerTracer, _TickTask); var _super = _createSuper(OnePointerTracer); function OnePointerTracer(gameObject, config) { var _this; _classCallCheck(this, OnePointerTracer); var scene = GetSceneObject(gameObject); if (scene === gameObject) { gameObject = undefined; } _this = _super.call(this, scene, config); _this.gameObject = gameObject; if (gameObject) { gameObject.setInteractive(GetValue$8(config, "inputConfig", undefined)); } _this._enable = undefined; _this.resetFromJSON(config); _this.boot(); return _this; } _createClass(OnePointerTracer, [{ key: "resetFromJSON", value: function resetFromJSON(o) { this.setEnable(GetValue$8(o, 'enable', true)); this.setDetectBounds(); if (this.gameObject === undefined) { this.setDetectBounds(GetValue$8(o, 'bounds', undefined)); } else { this.setDetectBounds(); } this.tracerState = TOUCH0$1; // this.recongizedState = new stateClass(this); this.pointer = undefined; this.lastPointer = undefined; // Last catched pointer this.movedState = false; this.isTouchingAnyObject = false; return this; } }, { key: "boot", value: function boot() { _get(_getPrototypeOf(OnePointerTracer.prototype), "boot", this).call(this); if (this.gameObject) { this.gameObject.on('pointerdown', this.onPointerDown, this); } else { this.scene.input.on('pointerdown', this.onPointerDown, this); } this.scene.input.on('pointerup', this.onPointerUp, this); this.scene.input.on('gameout', this.dragCancel, this); this.scene.input.on('pointermove', this.onPointerMove, this); this.scene.sys.events.once('shutdown', this.destroy, this); } }, { key: "shutdown", value: function shutdown(fromScene) { if (!this.scene) { return; } if (this.gameObject) ; else { this.scene.input.off('pointerdown', this.onPointerDown, this); } this.scene.input.off('pointerup', this.onPointerUp, this); this.scene.input.off('gameout', this.dragCancel, this); this.scene.input.off('pointermove', this.onPointerMove, this); this.scene.sys.events.off('shutdown', this.destroy, this); this.gameObject = undefined; this.bounds = undefined; this.pointer = undefined; this.lastPointer = undefined; // Last catched pointer this.movedState = false; _get(_getPrototypeOf(OnePointerTracer.prototype), "shutdown", this).call(this, fromScene); } }, { key: "enable", get: function get() { return this._enable; }, set: function set(e) { if (this._enable === e) { return; } if (!e) { this.dragCancel(); } this._enable = e; return this; } }, { key: "setEnable", value: function setEnable(e) { if (e === undefined) { e = true; } this.enable = e; return this; } }, { key: "setDetectBounds", value: function setDetectBounds(bounds) { this.bounds = bounds; return this; } }, { key: "toggleEnable", value: function toggleEnable() { this.setEnable(!this.enable); return this; } }, { key: "onPointerDown", value: function onPointerDown(pointer, gameObjects) { if (!this.enable) { return; } if (this.pointer !== undefined) { return; } var isInsideBounds = this.bounds ? this.bounds.contains(pointer.x, pointer.y) : true; if (!isInsideBounds) { return; } if (this.pointer === pointer) { return; } this.pointer = pointer; this.lastPointer = pointer; this.movedState = false; this.tracerState = TOUCH1$1; if (this.gameObject === undefined) { this.isTouchingAnyObject = gameObjects.length > 0; } this.onDragStart(); } }, { key: "onPointerUp", value: function onPointerUp(pointer) { if (!this.enable) { return; } var isInsideBounds = this.bounds ? this.bounds.contains(pointer.x, pointer.y) : true; if (!isInsideBounds) { return; } if (this.pointer !== pointer) { return; } this.pointer = undefined; this.movedState = false; this.tracerState = TOUCH0$1; this.onDragEnd(); } }, { key: "onPointerMove", value: function onPointerMove(pointer) { if (!this.enable) { return; } if (pointer.isDown) { var isInsideBounds = this.bounds ? this.bounds.contains(pointer.x, pointer.y) : true; var isCatchedPointer = this.pointer === pointer; if (!isCatchedPointer && isInsideBounds) ; else if (isCatchedPointer && !isInsideBounds) { // Pointer moves out of bounds this.onPointerUp(pointer); } else { // Pointer drags in bounds if (!this.movedState) { this.movedState = pointer.x !== pointer.downX || pointer.y !== pointer.downY; } if (this.movedState) { this.onDrag(); } } } } }, { key: "dragCancel", value: function dragCancel() { if (this.tracerState === TOUCH1$1) { this.onDragEnd(); } this.pointer = undefined; this.tracerState = TOUCH0$1; return this; } }, { key: "onDragStart", value: function onDragStart() { this.emit('dragstart', this); } }, { key: "onDragEnd", value: function onDragEnd() { this.emit('dragend', this); } }, { key: "onDrag", value: function onDrag() { this.emit('drag', this); } // onLastPointerMove() { } }, { key: "preUpdate", value: function preUpdate(time, delta) {} }, { key: "postUpdate", value: function postUpdate(time, delta) {} }, { key: "startTicking", value: function startTicking() { _get(_getPrototypeOf(OnePointerTracer.prototype), "startTicking", this).call(this); this.scene.sys.events.on('preupdate', this.preUpdate, this); this.scene.sys.events.on('postupdate', this.postUpdate, this); } }, { key: "stopTicking", value: function stopTicking() { _get(_getPrototypeOf(OnePointerTracer.prototype), "stopTicking", this).call(this); if (this.scene) { // Scene might be destoryed this.scene.sys.events.off('preupdate', this.preUpdate, this); this.scene.sys.events.off('postupdate', this.postUpdate, this); } } }, { key: "setRecongizedStateObject", value: function setRecongizedStateObject(stateObject) { this.recongizedState = stateObject; return this; } }, { key: "state", get: function get() { return this.recongizedState.state; }, set: function set(newState) { this.recongizedState.state = newState; } }, { key: "cancel", value: function cancel() { this.state = IDLE$7; return this; } }]); return OnePointerTracer; }(TickTask); var TOUCH0$1 = 0; var TOUCH1$1 = 1; var IDLE$7 = 'IDLE'; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var eventemitter3 = {exports: {}}; (function (module) { var has = Object.prototype.hasOwnProperty , prefix = '~'; /** * Constructor to create a storage for our `EE` objects. * An `Events` instance is a plain object whose properties are event names. * * @constructor * @private */ function Events() {} // // We try to not inherit from `Object.prototype`. In some engines creating an // instance in this way is faster than calling `Object.create(null)` directly. // If `Object.create(null)` is not supported we prefix the event names with a // character to make sure that the built-in object properties are not // overridden or used as an attack vector. // if (Object.create) { Events.prototype = Object.create(null); // // This hack is needed because the `__proto__` property is still inherited in // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. // if (!new Events().__proto__) prefix = false; } /** * Representation of a single event listener. * * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} [once=false] Specify if the listener is a one-time listener. * @constructor * @private */ function EE(fn, context, once) { this.fn = fn; this.context = context; this.once = once || false; } /** * Add a listener for a given event. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} once Specify if the listener is a one-time listener. * @returns {EventEmitter} * @private */ function addListener(emitter, event, fn, context, once) { if (typeof fn !== 'function') { throw new TypeError('The listener must be a function'); } var listener = new EE(fn, context || emitter, once) , evt = prefix ? prefix + event : event; if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); else emitter._events[evt] = [emitter._events[evt], listener]; return emitter; } /** * Clear event by name. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} evt The Event name. * @private */ function clearEvent(emitter, evt) { if (--emitter._eventsCount === 0) emitter._events = new Events(); else delete emitter._events[evt]; } /** * Minimal `EventEmitter` interface that is molded against the Node.js * `EventEmitter` interface. * * @constructor * @public */ function EventEmitter() { this._events = new Events(); this._eventsCount = 0; } /** * Return an array listing the events for which the emitter has registered * listeners. * * @returns {Array} * @public */ EventEmitter.prototype.eventNames = function eventNames() { var names = [] , events , name; if (this._eventsCount === 0) return names; for (name in (events = this._events)) { if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); } if (Object.getOwnPropertySymbols) { return names.concat(Object.getOwnPropertySymbols(events)); } return names; }; /** * Return the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Array} The registered listeners. * @public */ EventEmitter.prototype.listeners = function listeners(event) { var evt = prefix ? prefix + event : event , handlers = this._events[evt]; if (!handlers) return []; if (handlers.fn) return [handlers.fn]; for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { ee[i] = handlers[i].fn; } return ee; }; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. * @public */ EventEmitter.prototype.listenerCount = function listenerCount(event) { var evt = prefix ? prefix + event : event , listeners = this._events[evt]; if (!listeners) return 0; if (listeners.fn) return 1; return listeners.length; }; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. * @public */ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return false; var listeners = this._events[evt] , len = arguments.length , args , i; if (listeners.fn) { if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); switch (len) { case 1: return listeners.fn.call(listeners.context), true; case 2: return listeners.fn.call(listeners.context, a1), true; case 3: return listeners.fn.call(listeners.context, a1, a2), true; case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } for (i = 1, args = new Array(len -1); i < len; i++) { args[i - 1] = arguments[i]; } listeners.fn.apply(listeners.context, args); } else { var length = listeners.length , j; for (i = 0; i < length; i++) { if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); switch (len) { case 1: listeners[i].fn.call(listeners[i].context); break; case 2: listeners[i].fn.call(listeners[i].context, a1); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; default: if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { args[j - 1] = arguments[j]; } listeners[i].fn.apply(listeners[i].context, args); } } } return true; }; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.on = function on(event, fn, context) { return addListener(this, event, fn, context, false); }; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.once = function once(event, fn, context) { return addListener(this, event, fn, context, true); }; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return this; if (!fn) { clearEvent(this, evt); return this; } var listeners = this._events[evt]; if (listeners.fn) { if ( listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context) ) { clearEvent(this, evt); } } else { for (var i = 0, events = [], length = listeners.length; i < length; i++) { if ( listeners[i].fn !== fn || (once && !listeners[i].once) || (context && listeners[i].context !== context) ) { events.push(listeners[i]); } } // // Reset the array, or remove it completely if we have no more listeners. // if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; else clearEvent(this, evt); } return this; }; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { var evt; if (event) { evt = prefix ? prefix + event : event; if (this._events[evt]) clearEvent(this, evt); } else { this._events = new Events(); this._eventsCount = 0; } return this; }; // // Alias methods names because people roll like that. // EventEmitter.prototype.off = EventEmitter.prototype.removeListener; EventEmitter.prototype.addListener = EventEmitter.prototype.on; // // Expose the prefix. // EventEmitter.prefixed = prefix; // // Allow `EventEmitter` to be imported as module namespace. // EventEmitter.EventEmitter = EventEmitter; // // Expose the module. // { module.exports = EventEmitter; } } (eventemitter3)); var eventemitter3Exports = eventemitter3.exports; var EE = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports); var EventEmitter = /*#__PURE__*/function (_EE) { _inherits(EventEmitter, _EE); var _super = _createSuper(EventEmitter); function EventEmitter() { _classCallCheck(this, EventEmitter); return _super.apply(this, arguments); } _createClass(EventEmitter, [{ key: "shutdown", value: function shutdown() { this.removeAllListeners(); } }, { key: "destroy", value: function destroy() { this.removeAllListeners(); } }]); return EventEmitter; }(EE); var EventEmitterMethods = { setEventEmitter: function setEventEmitter(eventEmitter, EventEmitterClass) { if (EventEmitterClass === undefined) { EventEmitterClass = EventEmitter; } this._privateEE = eventEmitter === true || eventEmitter === undefined; this._eventEmitter = this._privateEE ? new EventEmitterClass() : eventEmitter; return this; }, destroyEventEmitter: function destroyEventEmitter() { if (this._eventEmitter && this._privateEE) { this._eventEmitter.shutdown(); } return this; }, getEventEmitter: function getEventEmitter() { return this._eventEmitter; }, on: function on() { if (this._eventEmitter) { this._eventEmitter.on.apply(this._eventEmitter, arguments); } return this; }, once: function once() { if (this._eventEmitter) { this._eventEmitter.once.apply(this._eventEmitter, arguments); } return this; }, off: function off() { if (this._eventEmitter) { this._eventEmitter.off.apply(this._eventEmitter, arguments); } return this; }, emit: function emit(event) { if (this._eventEmitter && event) { this._eventEmitter.emit.apply(this._eventEmitter, arguments); } return this; }, addListener: function addListener() { if (this._eventEmitter) { this._eventEmitter.addListener.apply(this._eventEmitter, arguments); } return this; }, removeListener: function removeListener() { if (this._eventEmitter) { this._eventEmitter.removeListener.apply(this._eventEmitter, arguments); } return this; }, removeAllListeners: function removeAllListeners() { if (this._eventEmitter) { this._eventEmitter.removeAllListeners.apply(this._eventEmitter, arguments); } return this; }, listenerCount: function listenerCount() { if (this._eventEmitter) { return this._eventEmitter.listenerCount.apply(this._eventEmitter, arguments); } return 0; }, listeners: function listeners() { if (this._eventEmitter) { return this._eventEmitter.listeners.apply(this._eventEmitter, arguments); } return []; }, eventNames: function eventNames() { if (this._eventEmitter) { return this._eventEmitter.eventNames.apply(this._eventEmitter, arguments); } return []; } }; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2019 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // Source object // The key as a string, or an array of keys, i.e. 'banner', or 'banner.hideBanner' // The default value to use if the key doesn't exist /** * Retrieves a value from an object. * * @function Phaser.Utils.Objects.GetValue * @since 3.0.0 * * @param {object} source - The object to retrieve the value from. * @param {string} key - The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (`.`) - `banner.hideBanner` would return the value of the `hideBanner` property from the object stored in the `banner` property of the `source` object. * @param {*} defaultValue - The value to return if the `key` isn't found in the `source` object. * * @return {*} The value of the requested key. */ var GetValue$7 = function GetValue(source, key, defaultValue) { if (!source || typeof source === 'number') { return defaultValue; } else if (source.hasOwnProperty(key)) { return source[key]; } else if (key.indexOf('.') !== -1) { var keys = key.split('.'); var parent = source; var value = defaultValue; // Use for loop here so we can break early for (var i = 0; i < keys.length; i++) { if (parent.hasOwnProperty(keys[i])) { // Yes it has a key property, let's carry on down value = parent[keys[i]]; parent = parent[keys[i]]; } else { // Can't go any further, so reset to default value = defaultValue; break; } } return value; } else { return defaultValue; } }; var StateProperties$1 = ['next', 'exit', 'enter']; var FSM$1 = /*#__PURE__*/function () { /* var config = { start: 'A', // default: undefined states: { A: { next: 'B', // function() { return 'B'; } enter: function() {}, exit: function() {}, }, // ... }, extend: { i: 0, name: 'abc' // ... }, init: function() {}, enable: true, eventEmitter: true, }; */ function FSM(config) { _classCallCheck(this, FSM); // Attach get-next-state function var states = GetValue$7(config, 'states', undefined); if (states) { this.addStates(states); } // Attach extend members var extend = GetValue$7(config, 'extend', undefined); if (extend) { for (var name in extend) { if (!this.hasOwnProperty(name) || this[name] === undefined) { this[name] = extend[name]; } } } // Event emitter var eventEmitter = GetValue$7(config, 'eventEmitter', undefined); var EventEmitterClass = GetValue$7(config, 'EventEmitterClass', undefined); this.setEventEmitter(eventEmitter, EventEmitterClass); this._stateLock = false; this.resetFromJSON(config); } _createClass(FSM, [{ key: "shutdown", value: function shutdown() { this.destroyEventEmitter(); } }, { key: "destroy", value: function destroy() { this.shutdown(); } }, { key: "resetFromJSON", value: function resetFromJSON(o) { this.setEnable(GetValue$7(o, 'enable', true)); this.start(GetValue$7(o, 'start', undefined)); var init = GetValue$7(o, 'init', undefined); if (init) { init.call(this); } return this; } }, { key: "toJSON", value: function toJSON() { return { curState: this.state, prevState: this.prevState, enable: this.enable, start: this._start }; } }, { key: "setEnable", value: function setEnable(e) { if (e === undefined) { e = true; } this.enable = e; return this; } }, { key: "toggleEnable", value: function toggleEnable() { this.setEnable(!this.enable); return this; } }, { key: "state", get: function get() { return this._state; }, set: function set(newState) { if (!this.enable || this._stateLock) { return; } if (this._state === newState) { return; } this._prevState = this._state; this._state = newState; this._stateLock = true; // lock state this.emit('statechange', this); if (this._prevState != null) { var exitEventName = 'exit_' + this._prevState; var exitCallback = this[exitEventName]; if (exitCallback) { exitCallback.call(this); } this.emit(exitEventName, this); } this._stateLock = false; if (this._state != null) { var enterEventName = 'enter_' + this._state; var enterCallback = this[enterEventName]; if (enterCallback) { enterCallback.call(this); } this.emit(enterEventName, this); } } }, { key: "prevState", get: function get() { return this._prevState; } }, { key: "start", value: function start(state) { this._start = state; this._prevState = undefined; this._state = state; // Won't fire statechange events return this; } }, { key: "goto", value: function goto(nextState) { if (nextState != null) { this.state = nextState; } return this; } }, { key: "next", value: function next() { var nextState; var getNextState = this['next_' + this.state]; if (getNextState) { if (typeof getNextState === 'string') { nextState = getNextState; } else { nextState = getNextState.call(this); } } this["goto"](nextState); return this; } }, { key: "stateProperties", get: function get() { return StateProperties$1; } }, { key: "addState", value: function addState(name, state) { if (typeof name !== 'string') { state = name; name = state.name; } var stateProperties = this.stateProperties; for (var i = 0, cnt = stateProperties.length; i < cnt; i++) { var propertyName = stateProperties[i]; var propertyValue = state[propertyName]; if (propertyValue) { this["".concat(propertyName, "_").concat(name)] = propertyValue; } } return this; } }, { key: "addStates", value: function addStates(states) { if (Array.isArray(states)) { for (var i = 0, cnt = states.length; i < cnt; i++) { this.addState(states[i]); } } else { for (var name in states) { this.addState(name, states[name]); } } return this; } }, { key: "runMethod", value: function runMethod(methodName, a1, a2, a3, a4, a5) { var fn = this[methodName + '_' + this.state]; if (!fn) { return undefined; } // Copy from eventemitter3 var len = arguments.length; switch (len) { case 1: return fn.call(this); case 2: return fn.call(this, a1); case 3: return fn.call(this, a1, a2); case 4: return fn.call(this, a1, a2, a3); case 5: return fn.call(this, a1, a2, a3, a4); case 6: return fn.call(this, a1, a2, a3, a4, a5); } var args = new Array(len - 1); for (var i = 1; i < len; i++) { args[i - 1] = arguments[i]; } return fn.apply(this, args); } }]); return FSM; }(); Object.assign(FSM$1.prototype, EventEmitterMethods); var HasListener = function HasListener(eventEmitter, eventName, fn, context, once) { if (once === undefined) { once = false; } var listeners = eventEmitter._events[eventName]; if (!listeners) { return false; } for (var i = 0, cnt = listeners.length; i < cnt; i++) { var listener = listeners[i]; if (listener.fn === fn && listener.context === context && listener.once === once) { return true; } } return false; }; var StateProperties = ['next', 'exit', 'enter', 'update', 'preupdate', 'postupdate']; var FSM = /*#__PURE__*/function (_FSMBase) { _inherits(FSM, _FSMBase); var _super = _createSuper(FSM); function FSM() { _classCallCheck(this, FSM); return _super.apply(this, arguments); } _createClass(FSM, [{ key: "shutdown", value: /* var config = { start: 'A', // default: undefined states: { A: { next: 'B', // function() { return 'B'; } enter: function() {}, exit: function() {}, update: function(time, delta) {}, preupdate: function(time, delta) {}, postupdate: function(time, delta) {}, }, // ... }, extend: { i: 0, name: 'abc' // ... }, init: function() {}, enable: true, scene: undefined, eventEmitter: true, }; */ function shutdown() { this.stopUpdate(); this.stopPreUpdate(); this.stopPostUpdate(); this._scene = undefined; _get(_getPrototypeOf(FSM.prototype), "shutdown", this).call(this); } }, { key: "resetFromJSON", value: function resetFromJSON(o) { _get(_getPrototypeOf(FSM.prototype), "resetFromJSON", this).call(this, o); this._scene = GetValue$7(o, 'scene', undefined); return this; } }, { key: "stateProperties", get: function get() { return StateProperties; } }, { key: "update", value: function update(time, delta) { this.runMethod('update', time, delta); } }, { key: "preupdate", value: function preupdate(time, delta) { this.runMethod('preupdate', time, delta); } }, { key: "postupdate", value: function postupdate(time, delta) { this.runMethod('postupdate', time, delta); } }, { key: "startUpdate", value: function startUpdate(scene) { if (!scene) { scene = this._scene; } var eventEmitter = scene.sys.events; if (HasListener(eventEmitter, 'update', this.update, this)) { return this; } this._scene = scene; eventEmitter.on('update', this.update, this); return this; } }, { key: "stopUpdate", value: function stopUpdate() { if (!this._scene) { return this; } this._scene.sys.events.off('update', this.update, this); return this; } }, { key: "startPreUpdate", value: function startPreUpdate(scene) { if (!scene) { scene = this._scene; } var eventEmitter = scene.sys.events; if (HasListener(eventEmitter, 'preupdate', this.preupdate, this)) { return this; } this._scene = scene; eventEmitter.on('preupdate', this.preupdate, this); return this; } }, { key: "stopPreUpdate", value: function stopPreUpdate() { if (!this._scene) { return this; } this._scene.sys.events.off('preupdate', this.preupdate, this); return this; } }, { key: "startPostUpdate", value: function startPostUpdate(scene) { if (!scene) { scene = this._scene; } var eventEmitter = scene.sys.events; if (HasListener(eventEmitter, 'postupdate', this.postupdate, this)) { return this; } this._scene = scene; eventEmitter.on('postupdate', this.postupdate, this); return this; } }, { key: "stopPostUpdate", value: function stopPostUpdate() { if (!this._scene) { return this; } this._scene.sys.events.off('postupdate', this.postupdate, this); return this; } }]); return FSM; }(FSM$1); var GetValue$6 = Phaser.Utils.Objects.GetValue; var DistanceBetween$2 = Phaser.Math.Distance.Between; var Tap = /*#__PURE__*/function (_OnePointerTracer) { _inherits(Tap, _OnePointerTracer); var _super = _createSuper(Tap); function Tap(gameObject, config) { var _this; _classCallCheck(this, Tap); _this = _super.call(this, gameObject, config); var self = _assertThisInitialized(_this); var stateConfig = { states: { IDLE: { enter: function enter() { self.stop(); self.tapsCount = 0; self.x = 0; self.y = 0;