UNPKG

phaser4-rex-plugins

Version:
1,270 lines (1,042 loc) 2.3 MB
(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.rexgraphplugin = factory()); })(this, (function () { 'use strict'; class ObjectFactory { constructor(scene) { this.scene = scene; scene.sys.events.once('destroy', this.destroy, this); } destroy() { this.scene = null; } static register(type, callback) { ObjectFactory.prototype[type] = callback; } } var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 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); class EventEmitter extends EE { shutdown() { this.removeAllListeners(); } destroy() { this.removeAllListeners(); } } var GetValue$3 = function (source, key, defaultValue) { if (!source || typeof source === 'number') { return defaultValue; } if (typeof (key) === 'string') { if (source.hasOwnProperty(key)) { return source[key]; } if (key.indexOf('.') !== -1) { key = key.split('.'); } else { return defaultValue; } } var keys = key; var parent = source; var value = defaultValue; // Use for loop here so we can break early for (var i = 0; i < keys.length; i++) { key = keys[i]; if (parent.hasOwnProperty(key)) { // Yes it has a key property, let's carry on down value = parent[key]; parent = value; } else { // Can't go any further, so reset to default value = defaultValue; break; } } return value; }; class Bank { constructor(config) { this.nextId = GetValue$3(config, 'start', 1); // start index this.uidKey = GetValue$3(config, 'uidKey', '$uid'); this.autoRemove = GetValue$3(config, 'remove', true); this.refs = {}; this.count = 0; } add(gameObject, uid) { var refs = this.refs; var uidKey = this.uidKey; if (uidKey) { if (gameObject.hasOwnProperty('uidKey') && gameObject[uidKey] != null) { return this; } } if (uid == null) { do { uid = this.nextId; this.nextId++; } while (refs.hasOwnProperty(uid)) } if (!refs.hasOwnProperty(uid)) { refs[uid] = gameObject; this.count++; if (uidKey) { gameObject[uidKey] = uid; } if (this.autoRemove && gameObject.on) { gameObject.once('destroy', function () { this.remove(uid); }, this); } } else { uid = null; } if (uidKey) { return this; } else { return uid; } } addMultiple(objects) { for (var i = 0, cnt = objects.length; i < cnt; i++) { this.add(objects[i]); } return this; } get(uid) { return this.refs[uid]; } has(uid) { return this.refs.hasOwnProperty(uid); } remove(uid) { var refs = this.refs; if (refs.hasOwnProperty(uid)) { if (this.uidKey) { var gameObject = refs[uid]; gameObject[this.uidKey] = undefined; } delete refs[uid]; this.count--; } return this; } forEach(callback, scope) { var refs = this.refs, gameObject; for (var uid in refs) { gameObject = refs[uid]; if (scope) { callback.call(scope, gameObject, uid); } else { callback(gameObject, uid); } } } clear() { this.forEach(function (gameObject) { this.remove(gameObject); }, this); } } var ObjBank = new Bank({ uidKey: '$uid', remove: false, // remove uid manually }); var EventEmitterMethods = { 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() { if (this._eventEmitter && this._privateEE) { this._eventEmitter.shutdown(); } return this; }, getEventEmitter() { return this._eventEmitter; }, on() { if (this._eventEmitter) { this._eventEmitter.on.apply(this._eventEmitter, arguments); } return this; }, once() { if (this._eventEmitter) { this._eventEmitter.once.apply(this._eventEmitter, arguments); } return this; }, off() { if (this._eventEmitter) { this._eventEmitter.off.apply(this._eventEmitter, arguments); } return this; }, emit(event) { if (this._eventEmitter && event) { this._eventEmitter.emit.apply(this._eventEmitter, arguments); } return this; }, addListener() { if (this._eventEmitter) { this._eventEmitter.addListener.apply(this._eventEmitter, arguments); } return this; }, removeListener() { if (this._eventEmitter) { this._eventEmitter.removeListener.apply(this._eventEmitter, arguments); } return this; }, removeAllListeners() { if (this._eventEmitter) { this._eventEmitter.removeAllListeners.apply(this._eventEmitter, arguments); } return this; }, listenerCount() { if (this._eventEmitter) { return this._eventEmitter.listenerCount.apply(this._eventEmitter, arguments); } return 0; }, listeners() { if (this._eventEmitter) { return this._eventEmitter.listeners.apply(this._eventEmitter, arguments); } return []; }, eventNames() { if (this._eventEmitter) { return this._eventEmitter.eventNames.apply(this._eventEmitter, arguments); } return []; }, }; const SceneClass = Phaser.Scene; var IsSceneObject = function (object) { return (object instanceof SceneClass); }; var GetSceneObject = function (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; } }; const GameClass = Phaser.Game; var IsGame = function (object) { return (object instanceof GameClass); }; var GetGame = function (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; } }; const GetValue$2 = Phaser.Utils.Objects.GetValue; class ComponentBase { constructor(parent, config) { this.setParent(parent); // gameObject, scene, or game this.isShutdown = false; // Event emitter, default is private event emitter this.setEventEmitter(GetValue$2(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 } } 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; } destroy(fromScene) { this.shutdown(fromScene); } onEnvDestroy() { this.destroy(true); } onParentDestroy(parent, fromScene) { this.destroy(fromScene); } setParent(parent) { this.parent = parent; // gameObject, scene, or game this.scene = GetSceneObject(parent); this.game = GetGame(parent); return this; } } Object.assign( ComponentBase.prototype, EventEmitterMethods ); const uidKey$1 = ObjBank.uidKey; class GraphItemData extends ComponentBase { constructor(parent, uid) { super(parent, { eventEmitter: false }); ObjBank.add(this, uid); // uid is stored in `this.$uid` this.graph = null; } shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } if (this.graph) { this.graph.remove(this[uidKey$1]); } ObjBank.remove(this[uidKey$1]); this.setGraph(null); super.shutdown(fromScene); } setGraph(graph) { this.graph = graph; return this; } get isNode() { if (this.graph) { return this.graph.hasNode(this[uidKey$1]); } return false; } get isEdge() { if (this.graph) { return this.graph.hasEdge(this[uidKey$1]); } return false; } } var methods = { }; Object.assign( GraphItemData.prototype, methods ); var IsUID = function (object) { var type = typeof (object); return (type === 'number') || (type === 'string'); }; var GetGraphItem = function (gameObject, uid) { // game object or uid if (IsUID(gameObject)) { // uid return ObjBank.get(gameObject); } else { // game object if (!gameObject.hasOwnProperty('rexGraph')) { gameObject.rexGraph = new GraphItemData(gameObject, uid); } return gameObject.rexGraph; } }; const uidKey = ObjBank.uidKey; var GetObjUID = function (gameObject, newUID) { if (newUID === undefined) { newUID = true; } // Game object or uid var uid; if (IsUID(gameObject)) { uid = gameObject; } else { if (gameObject.hasOwnProperty('rexGraph')) { uid = gameObject.rexGraph[uidKey]; } else if (newUID) { uid = GetGraphItem(gameObject)[uidKey]; } else { uid = null; } } return uid; }; var AddNodeMethods = { isNode(gameObejct) { // uid or game object var uid = GetObjUID(gameObejct, false); if (uid === null) { return false; } return this.graph.hasNode(uid); }, addNode(gameObejct, attributes, nodeUID) { if (this.isNode(gameObejct)) { return this; } GetGraphItem(gameObejct, nodeUID).setGraph(this); if (nodeUID === undefined) { nodeUID = GetObjUID(gameObejct); } this.graph.addNode(nodeUID, attributes); return this; }, addNodes(gameObjects, attributes) { for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { this.addNode(gameObjects[i], { ...attributes }); } return this; }, }; var RemoveNodeMethods = { removeNode(nodeGameObject, destroy) { if (!this.isNode(nodeGameObject)) { return this; } if (destroy === undefined) { destroy = false; } // Remove node var nodeUID = GetObjUID(nodeGameObject); this.graph.dropNode(nodeUID); // Clear reference of graph GetGraphItem(nodeGameObject).setGraph(null); // Destroy game object if (destroy && nodeGameObject.destroy) { nodeGameObject.destroy(); } return this; }, removeAllNodes(destroy) { for (var nodeUid in this.nodes) { this.removeNode(nodeUid, destroy); } return this; } }; var UIDToObj = function (uid) { if (uid == null) { return null; } else { return ObjBank.get(uid).parent; } }; var UIDListToObjList = function (uidList, out) { if (out === undefined) { out = []; } for (var i = 0, cnt = uidList.length; i < cnt; i++) { var graphItem = ObjBank.get(uidList[i]); if (!graphItem || !graphItem.parent) { continue; } out.push(graphItem.parent); } return out; }; var GetNodeMethods = { getAllNodes(out) { if (out === undefined) { out = []; } this.graph.forEachNode(function (uid) { var nodeGameObject = UIDToObj(uid); if (!nodeGameObject) { return; } out.push(nodeGameObject); }); return out; }, getNodesOfEdge(edgeGameObject, out) { if (out === undefined) { out = []; } var edgeUID = GetObjUID(edgeGameObject); if (!this.graph.hasEdge(edgeUID)) { return out; } var uidList = [ this.graph.source(edgeUID), this.graph.target(edgeUID) ]; return UIDListToObjList(uidList, out); }, getOppositeNode(nodeGameObject, edgeGameObject) { var nodeGameObjects = this.getNodesOfEdge(edgeGameObject); if (nodeGameObjects.length < 2) { return; } return (nodeGameObject === nodeGameObjects[0]) ? nodeGameObjects[1] : nodeGameObjects[0]; }, }; var NeighborNodeMethods = { areNeighborNodes(nodeGameObjectA, nodeGameObjectB) { var nodeUIDA = GetObjUID(nodeGameObjectA), nodeUIDB = GetObjUID(nodeGameObjectB); if (!nodeUIDA || !nodeUIDB) { return false; } return this.graph.areNeighbors(nodeUIDA, nodeUIDB); }, getNeighborNodes(nodeGameObject, out) { if (out === undefined) { out = []; } var nodeUID = GetObjUID(nodeGameObject); if (!nodeUID) { return out; } this.graph.forEachNeighbor(nodeUID, function (neighborUID) { var neighborGameObject = UIDToObj(neighborUID); if (!neighborGameObject) { return; } out.push(neighborGameObject); }); return out; }, }; const IsPlainObject$1 = Phaser.Utils.Objects.IsPlainObject; var NodeAttributeMethods = { getNodeAttribute(gameObject, key) { var nodeUID = GetObjUID(gameObject); if (key === undefined) { return this.graph.getNodeAttributes(nodeUID); } else { return this.graph.getNodeAttribute(nodeUID, key); } }, setNodeAttribute(gameObject, key, value) { var nodeUID = GetObjUID(gameObject); if (IsPlainObject$1(key)) { var data = key; for (var key in data) { this.graph.setNodeAttribute(nodeUID, key, data[key]); } } else { this.graph.setNodeAttribute(nodeUID, key, value); } return this; }, setNodesAttribute(gameObjects, key, value) { for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { this.setNodeAttribute(gameObjects[i], key, value); } return this; } }; Phaser.Utils.Objects.IsPlainObject; const DIRAtoB = 1; const DIRBtoA = 2; const DIRMODE = { '->': DIRAtoB, '<-': DIRBtoA, '<->': (DIRAtoB | DIRBtoA), }; var AddEdgeMethods = { isEdge(gameObejct) { // uid or game object var uid = GetObjUID(gameObejct, false); if (uid === null) { return false; } return this.graph.hasEdge(uid); }, addEdge(edgeGameObject, nodeAGameObject, nodeBGameObject, dir, attributes, edgeUID) { if (this.isEdge(edgeGameObject)) { return this; } if (dir === undefined) { dir = 3; } else if (typeof (dir) === 'string') { dir = DIRMODE[dir]; } // Add node to graph if (typeof (nodeAGameObject) !== 'string') { this.addNode(nodeAGameObject); } if (typeof (nodeBGameObject) !== 'string') { this.addNode(nodeBGameObject); } // Add edge GetGraphItem(edgeGameObject, edgeUID).setGraph(this); var edgeUID = GetObjUID(edgeGameObject); var nodeAUID = GetObjUID(nodeAGameObject); var nodeBUID = GetObjUID(nodeBGameObject); if (!edgeUID || !nodeAUID || !nodeBUID) { return this; } switch (dir) { case DIRAtoB: this.graph.addDirectedEdgeWithKey(edgeUID, nodeAUID, nodeBUID, attributes); break; case DIRBtoA: this.graph.addDirectedEdgeWithKey(edgeUID, nodeBUID, nodeAUID, attributes); break; default: this.graph.addUndirectedEdgeWithKey(edgeUID, nodeAUID, nodeBUID, attributes); break; } return this; }, }; var RemoveEdgeMethods = { removeEdge(edgeGameObject, destroy) { if (!this.isEdge(edgeGameObject)) { return this; } if (destroy === undefined) { destroy = false; } // Remove node var edgeUID = GetObjUID(edgeGameObject); this.graph.dropEdge(edgeUID); // Clear reference of graph GetGraphItem(edgeGameObject).setGraph(null); // Destroy game object if (destroy && edgeGameObject.destroy) { edgeGameObject.destroy(); } return this; }, removeAllEdges(destroy) { for (var edgeUid in this.edges) { this.removeEdge(edgeUid, destroy); } return this; }, }; var GetEdgeMethods = { getAllEdges(out) { if (out === undefined) { out = []; } this.graph.forEachEdge(function (uid) { var edgeGameObject = UIDToObj(uid); if (!edgeGameObject) { return; } out.push(edgeGameObject); }); return out; }, getEdgesOfNode(nodeGameObject, out) { if (out === undefined) { out = []; } var nodeUID = GetObjUID(nodeGameObject); this.graph.forEachEdge(nodeUID, function (edgeUID) { var edgeGameObject = UIDToObj(edgeUID); if (!edgeGameObject) { return; } out.push(edgeGameObject); }); return out; } }; /** * @author samme * @copyright 2013-2024 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ /** * Calculate the distance between two points. * * @function Phaser.Math.Distance.BetweenPoints * @since 3.22.0 * * @param {Phaser.Types.Math.Vector2Like} a - The first point. * @param {Phaser.Types.Math.Vector2Like} b - The second point. * * @return {number} The distance between the points. */ var DistanceBetweenPoints = function (a, b) { var dx = a.x - b.x; var dy = a.y - b.y; return Math.sqrt(dx * dx + dy * dy); }; var GetEdgeLength = function (edgeGameObject) { var nodeGameObjects = this.getNodesOfEdge(edgeGameObject); if (nodeGameObjects.length < 2) { return 0; } return DistanceBetweenPoints(nodeGameObjects[0], nodeGameObjects[1]); }; const IsPlainObject = Phaser.Utils.Objects.IsPlainObject; var EdgeAttributeMethods = { getEdgeAttribute(gameObject, key) { var edgeUID = GetObjUID(gameObject); if (key === undefined) { return this.graph.getEdgeAttributes(edgeUID); } else { return this.graph.getEdgeAttribute(edgeUID, key); } }, setEdgeAttribute(gameObject, key, value) { var edgeUID = GetObjUID(gameObject); if (IsPlainObject(key)) { return this.graph.updateEdgeAttribute(edgeUID, key); } else { return this.graph.setEdgeAttribute(edgeUID, key, value); } }, setEdgesAttribute(gameObjects, key, value) { for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { this.setEdgeAttribute(gameObjects[i], key, value); } return this; } }; var Methods$1 = { getEdgeLength: GetEdgeLength, }; Object.assign( Methods$1, AddNodeMethods, RemoveNodeMethods, GetNodeMethods, NeighborNodeMethods, NodeAttributeMethods, AddEdgeMethods, RemoveEdgeMethods, GetEdgeMethods, EdgeAttributeMethods, ); var graphology_umd_min = {exports: {}}; (function (module, exports) { !function(t,e){module.exports=e();}(commonjsGlobal,(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){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e);}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function i(){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}}function o(t,e,n){return o=i()?Reflect.construct.bind():function(t,e,n){var i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return n&&r(o,n.prototype),o},o.apply(null,arguments)}function a(t){var e="function"==typeof Map?new Map:void 0;return a=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a);}function a(){return o(t,arguments,n(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,t)},a(t)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var u=function(){for(var t=arguments[0],e=1,n=arguments.length;e<n;e++)if(arguments[e])for(var r in arguments[e])t[r]=arguments[e][r];return t};function d(t,e,n,r){var i=t._nodes.get(e),o=null;return i?o="mixed"===r?i.out&&i.out[n]||i.undirected&&i.undirected[n]:"directed"===r?i.out&&i.out[n]:i.undirected&&i.undirected[n]:o}function s(e){return "object"===t(e)&&null!==e}function h(t){var e;for(e in t)return !1;return !0}function p(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n});}function f(t,e,n){var r={enumerable:!0,configurable:!0};"function"==typeof n?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(t,e,r);}function l(t){return !!s(t)&&!(t.attributes&&!Array.isArray(t.attributes))}"function"==typeof Object.assign&&(u=Object.assign);var g,y={exports:{}},w="object"==typeof Reflect?Reflect:null,v=w&&"function"==typeof w.apply?w.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};g=w&&"function"==typeof w.ownKeys?w.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var b=Number.isNaN||function(t){return t!=t};function m(){m.init.call(this);}y.exports=m,y.exports.once=function(t,e){return new Promise((function(n,r){function i(n){t.removeListener(e,o),r(n);}function o(){"function"==typeof t.removeListener&&t.removeListener("error",i),n([].slice.call(arguments));}U(t,e,o,{once:!0}),"error"!==e&&function(t,e,n){"function"==typeof t.on&&U(t,"error",e,n);}(t,i,{once:!0});}))},m.EventEmitter=m,m.prototype._events=void 0,m.prototype._eventsCount=0,m.prototype._maxListeners=void 0;var k=10;function _(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function G(t){return void 0===t._maxListeners?m.defaultMaxListeners:t._maxListeners}function x(t,e,n,r){var i,o,a,c;if(_(n),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),o=t._events),a=o[e]),void 0===a)a=o[e]=n,++t._eventsCount;else if("function"==typeof a?a=o[e]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),(i=G(t))>0&&a.length>i&&!a.warned){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=a.length,c=u,console&&console.warn&&console.warn(c);}return t}function E(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function A(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=E.bind(r);return i.listener=n,r.wrapFn=i,i}function L(t,e,n){var r=t._events;if(void 0===r)return [];var i=r[e];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(i):D(i,i.length)}function S(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function D(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function U(t,e,n,r){if("function"==typeof t.on)r.once?t.once(e,n):t.on(e,n);else {if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function i(o){r.once&&t.removeEventListener(e,i),n(o);}));}}function N(t){if("function"!=typeof t)throw new Error("obliterator/iterator: expecting a function!");this.next=t;}Object.defineProperty(m,"defaultMaxListeners",{enumerable:!0,get:function(){return k},set:function(t){if("number"!=typeof t||t<0||b(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");k=t;}}),m.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0;},m.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||b(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},m.prototype.getMaxListeners=function(){return G(this)},m.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return !1;if(r){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=i[t];if(void 0===c)return !1;if("function"==typeof c)v(c,this,e);else {var u=c.length,d=D(c,u);for(n=0;n<u;++n)v(d[n],this,e);}return !0},m.prototype.addListener=function(t,e){return x(this,t,e,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(t,e){return x(this,t,e,!0)},m.prototype.once=function(t,e){return _(e),this.on(t,A(this,t,e)),this},m.prototype.prependOnceListener=function(t,e){return _(e),this.prependListener(t,A(this,t,e)),this},m.prototype.removeListener=function(t,e){var n,r,i,o,a;if(_(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===e||n[o].listener===e){a=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop();}(n,i),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,a||e);}return this},m.prototype.off=m.prototype.removeListener,m.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},m.prototype.listeners=function(t){return L(this,t,!0)},m.prototype.rawListeners=function(t){return L(this,t,!1)},m.listenerCount=function(t,e){return "function"==typeof t.listenerCount?t.listenerCount(e):S.call(t,e)},m.prototype.listenerCount=S,m.prototype.eventNames=function(){return this._eventsCount>0?g(this._events):[]},"undefined"!=typeof Symbol&&(N.prototype[Symbol.iterator]=function(){return this}),N.of=function(){var t=arguments,e=t.length,n=0;return new N((function(){return n>=e?{done:!0}:{done:!1,value:t[n++]}}))},N.empty=function(){return new N((function(){return {done:!0}}))},N.fromSequence=function(t){var e=0,n=t.length;return new N((function(){return e>=n?{done:!0}:{done:!1,value:t[e++]}}))},N.is=function(t){return t instanceof N||"object"==typeof t&&null!==t&&"function"==typeof t.next};var O=N,j={};j.ARRAY_BUFFER_SUPPORT="undefined"!=typeof ArrayBuffer,j.SYMBOL_SUPPORT="undefined"!=typeof Symbol;var C=O,M=j,z=M.ARRAY_BUFFER_SUPPORT,W=M.SYMBOL_SUPPORT;var P=function(t){var e=function(t){return "string"==typeof t||Array.isArray(t)||z&&ArrayBuffer.isView(t)?C.fromSequence(t):"object"!=typeof t||null===t?null:W&&"function"==typeof t[Symbol.iterator]?t[Symbol.iterator]():"function"==typeof t.next?t:null}(t);if(!e)throw new Error("obliterator: target is not iterable nor a valid iterator.");return e},R=P,K=function(t,e){for(var n,r=arguments.length>1?e:1/0,i=r!==1/0?new Array(r):[],o=0,a=R(t);;){if(o===r)return i;if((n=a.next()).done)return o!==e&&(i.length=o),i;i[o++]=n.value;}},T=function(t){function n(e){var n;return (n=t.call(this)||this).name="GraphError",n.message=e,n}return e(n,t),n}(a(Error)),B=function(t){function n(e){var r;return (r=t.call(this,e)||this).name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(c(r),n.prototype.constructor),r}return e(n,t),n}(T),F=function(t){function n(e){var r;return (r=t.call(this,e)||this).name="NotFoundGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(c(r),n.prototype.constructor),r}return e(n,t),n}(T),I=function(t){function n(e){var r;return (r=t.call(this,e)||this).name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(c(r),n.prototype.constructor),r}return e(n,t),n}(T);function Y(t,e){this.key=t,this.attributes=e,this.clear();}function q(t,e){this.key=t,this.attributes=e,this.clear();}function J(t,e){this.key=t,this.attributes=e,this.clear();}function V(t,e,n,r,i){this.key=e,this.attributes=i,this.undirected=t,this.source=n,this.target=r;}Y.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={};},q.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={};},J.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={};},V.prototype.attach=function(){var t="out",e="in";this.undirected&&(t=e="undirected");var n=this.source.key,r=this.target.key;this.source[t][r]=this,this.undirected&&n===r||(this.target[e][n]=this);},V.prototype.attachMulti=function(){var t="out",e="in",n=this.source.key,r=this.target.key;this.undirected&&(t=e="undirected");var i=this.source[t],o=i[r];if(void 0===o)return i[r]=this,void(this.undirected&&n===r||(this.target[e][n]=this));o.previous=this,this.next=o,i[r]=this,this.target[e][n]=this;},V.prototype.detach=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),delete this.source[n][e],delete this.target[r][t];},V.prototype.detachMulti=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),void 0===this.previous?void 0===this.next?(delete this.source[n][e],delete this.target[r][t]):(this.next.previous=void 0,this.source[n][e]=this.next,this.target[r][t]=this.next):(this.previous.next=this.nex