phaser/src/structs/List.js

836 lines
22 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2023-01-02 17:36:27 +00:00
* @copyright 2013-2023 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
var ArrayUtils = require('../utils/array');
var Class = require('../utils/Class');
var NOOP = require('../utils/NOOP');
var StableSort = require('../utils/array/StableSort');
2018-03-19 21:57:46 +00:00
/**
* @callback EachListCallback<I>
2018-03-19 21:57:46 +00:00
*
* @param {I} item - The item which is currently being processed.
2018-03-28 15:00:19 +00:00
* @param {...*} [args] - Additional arguments that will be passed to the callback, after the child.
2018-03-19 21:57:46 +00:00
*/
2018-02-09 04:35:23 +00:00
/**
* @classdesc
* List is a generic implementation of an ordered list which contains utility methods for retrieving, manipulating, and iterating items.
2018-02-09 04:35:23 +00:00
*
* @class List
2018-10-10 09:49:13 +00:00
* @memberof Phaser.Structs
2018-02-09 04:35:23 +00:00
* @constructor
* @since 3.0.0
*
* @generic T
*
* @param {*} parent - The parent of this list.
2018-02-09 04:35:23 +00:00
*/
var List = new Class({
initialize:
function List (parent)
{
2018-02-09 04:35:23 +00:00
/**
* The parent of this list.
*
* @name Phaser.Structs.List#parent
2018-03-20 16:15:49 +00:00
* @type {*}
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
this.parent = parent;
2018-02-09 04:35:23 +00:00
/**
* The objects that belong to this collection.
*
2018-03-29 10:56:47 +00:00
* @genericUse {T[]} - [$type]
*
2018-02-09 04:35:23 +00:00
* @name Phaser.Structs.List#list
2018-03-23 15:54:12 +00:00
* @type {Array.<*>}
2018-02-09 04:35:23 +00:00
* @default []
* @since 3.0.0
*/
this.list = [];
2018-02-09 04:35:23 +00:00
/**
* The index of the current element.
*
* This is used internally when iterating through the list with the {@link #first}, {@link #last}, {@link #get}, and {@link #previous} properties.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#position
2020-11-23 10:22:13 +00:00
* @type {number}
2018-02-09 04:35:23 +00:00
* @default 0
* @since 3.0.0
*/
this.position = 0;
/**
* A callback that is invoked every time a child is added to this list.
*
* @name Phaser.Structs.List#addCallback
* @type {function}
* @since 3.4.0
*/
this.addCallback = NOOP;
/**
* A callback that is invoked every time a child is removed from this list.
*
* @name Phaser.Structs.List#removeCallback
* @type {function}
* @since 3.4.0
*/
this.removeCallback = NOOP;
/**
* The property key to sort by.
*
* @name Phaser.Structs.List#_sortKey
* @type {string}
* @since 3.4.0
*/
this._sortKey = '';
},
2018-02-09 04:35:23 +00:00
/**
* Adds the given item to the end of the list. Each item must be unique.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#add
* @since 3.0.0
*
* @param {*|Array.<*>} child - The item, or array of items, to add to the list.
* @param {boolean} [skipCallback=false] - Skip calling the List.addCallback if this child is added successfully.
2018-02-09 04:35:23 +00:00
*
* @return {*} The list's underlying array.
2018-02-09 04:35:23 +00:00
*/
add: function (child, skipCallback)
{
if (skipCallback)
{
return ArrayUtils.Add(this.list, child);
}
else
{
return ArrayUtils.Add(this.list, child, 0, this.addCallback, this);
}
},
2018-02-09 04:35:23 +00:00
/**
* Adds an item to list, starting at a specified index. Each item must be unique within the list.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#addAt
* @since 3.0.0
*
* @genericUse {(T|T[])} - [child,$return]
*
* @param {*} child - The item, or array of items, to add to the list.
2020-11-23 10:22:13 +00:00
* @param {number} [index=0] - The index in the list at which the element(s) will be inserted.
* @param {boolean} [skipCallback=false] - Skip calling the List.addCallback if this child is added successfully.
2018-02-09 04:35:23 +00:00
*
* @return {*} The List's underlying array.
2018-02-09 04:35:23 +00:00
*/
addAt: function (child, index, skipCallback)
{
if (skipCallback)
{
return ArrayUtils.AddAt(this.list, child, index);
}
else
{
return ArrayUtils.AddAt(this.list, child, index, 0, this.addCallback, this);
}
},
2018-02-09 04:35:23 +00:00
/**
* Retrieves the item at a given position inside the List.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#getAt
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [$return]
*
2020-11-23 10:22:13 +00:00
* @param {number} index - The index of the item.
2018-02-09 04:35:23 +00:00
*
* @return {*} The retrieved item, or `undefined` if it's outside the List's bounds.
2018-02-09 04:35:23 +00:00
*/
getAt: function (index)
{
return this.list[index];
},
2018-02-09 04:35:23 +00:00
/**
* Locates an item within the List and returns its index.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#getIndex
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [child]
*
* @param {*} child - The item to locate.
2018-02-09 04:35:23 +00:00
*
2020-11-23 10:22:13 +00:00
* @return {number} The index of the item within the List, or -1 if it's not in the List.
2018-02-09 04:35:23 +00:00
*/
getIndex: function (child)
{
// Return -1 if given child isn't a child of this display list
return this.list.indexOf(child);
},
2018-02-09 04:35:23 +00:00
/**
* Sort the contents of this List so the items are in order based on the given property.
* For example, `sort('alpha')` would sort the List contents based on the value of their `alpha` property.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#sort
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T[]} - [children,$return]
*
* @param {string} property - The property to lexically sort by.
* @param {function} [handler] - Provide your own custom handler function. Will receive 2 children which it should compare and return a boolean.
2018-02-09 04:35:23 +00:00
*
* @return {Phaser.Structs.List} This List object.
2018-02-09 04:35:23 +00:00
*/
sort: function (property, handler)
{
if (!property)
{
return this;
}
if (handler === undefined)
{
handler = function (childA, childB)
{
return childA[property] - childB[property];
};
}
StableSort(this.list, handler);
return this;
},
/**
* Searches for the first instance of a child with its `name`
2018-02-09 04:35:23 +00:00
* property matching the given argument. Should more than one child have
* the same name only the first is returned.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#getByName
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T | null} - [$return]
*
2018-02-09 04:35:23 +00:00
* @param {string} name - The name to search for.
*
* @return {?*} The first child with a matching name, or null if none were found.
2018-02-09 04:35:23 +00:00
*/
getByName: function (name)
{
return ArrayUtils.GetFirst(this.list, 'name', name);
},
/**
2018-02-09 04:35:23 +00:00
* Returns a random child from the group.
*
* @method Phaser.Structs.List#getRandom
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T | null} - [$return]
*
2020-11-23 10:22:13 +00:00
* @param {number} [startIndex=0] - Offset from the front of the group (lowest child).
* @param {number} [length=(to top)] - Restriction on the number of values you want to randomly select from.
2018-02-09 04:35:23 +00:00
*
* @return {?*} A random child of this Group.
2018-02-09 04:35:23 +00:00
*/
getRandom: function (startIndex, length)
{
return ArrayUtils.GetRandom(this.list, startIndex, length);
},
2018-02-09 04:35:23 +00:00
/**
* Returns the first element in a given part of the List which matches a specific criterion.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#getFirst
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T | null} - [$return]
*
* @param {string} property - The name of the property to test or a falsey value to have no criterion.
* @param {*} value - The value to test the `property` against, or `undefined` to allow any value and only check for existence.
* @param {number} [startIndex=0] - The position in the List to start the search at.
* @param {number} [endIndex] - The position in the List to optionally stop the search at. It won't be checked.
2018-02-09 04:35:23 +00:00
*
* @return {?*} The first item which matches the given criterion, or `null` if no such item exists.
2018-02-09 04:35:23 +00:00
*/
getFirst: function (property, value, startIndex, endIndex)
{
return ArrayUtils.GetFirst(this.list, property, value, startIndex, endIndex);
},
/**
2018-02-09 04:35:23 +00:00
* Returns all children in this List.
*
* You can optionally specify a matching criteria using the `property` and `value` arguments.
*
* For example: `getAll('parent')` would return only children that have a property called `parent`.
*
* You can also specify a value to compare the property to:
*
* `getAll('visible', true)` would return only children that have their visible property set to `true`.
2018-02-09 04:35:23 +00:00
*
* Optionally you can specify a start and end index. For example if this List had 100 children,
* and you set `startIndex` to 0 and `endIndex` to 50, it would return matches from only
* the first 50 children in the List.
*
* @method Phaser.Structs.List#getAll
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T[]} - [$return]
*
2018-02-09 04:35:23 +00:00
* @param {string} [property] - An optional property to test against the value argument.
2022-11-17 18:40:24 +00:00
* @param {any} [value] - If property is set then Child.property must strictly equal this value to be included in the results.
2020-11-23 10:22:13 +00:00
* @param {number} [startIndex] - The first child index to start the search from.
* @param {number} [endIndex] - The last child index to search up until.
2018-02-09 04:35:23 +00:00
*
* @return {Array.<*>} All items of the List which match the given criterion, if any.
2018-02-09 04:35:23 +00:00
*/
getAll: function (property, value, startIndex, endIndex)
{
return ArrayUtils.GetAll(this.list, property, value, startIndex, endIndex);
},
2018-02-09 04:35:23 +00:00
/**
* Returns the total number of items in the List which have a property matching the given value.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#count
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [value]
*
* @param {string} property - The property to test on each item.
* @param {*} value - The value to test the property against.
2018-02-09 04:35:23 +00:00
*
2020-11-23 10:22:13 +00:00
* @return {number} The total number of matching elements.
2018-02-09 04:35:23 +00:00
*/
count: function (property, value)
{
return ArrayUtils.CountAllMatching(this.list, property, value);
},
2018-02-09 04:35:23 +00:00
/**
* Swaps the positions of two items in the list.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#swap
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [child1,child2]
*
* @param {*} child1 - The first item to swap.
* @param {*} child2 - The second item to swap.
2018-02-09 04:35:23 +00:00
*/
swap: function (child1, child2)
{
ArrayUtils.Swap(this.list, child1, child2);
},
2018-02-09 04:35:23 +00:00
/**
* Moves an item in the List to a new position.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#moveTo
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [child,$return]
*
* @param {*} child - The item to move.
2020-11-23 10:22:13 +00:00
* @param {number} index - Moves an item in the List to a new position.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item that was moved.
2018-02-09 04:35:23 +00:00
*/
moveTo: function (child, index)
{
return ArrayUtils.MoveTo(this.list, child, index);
},
/**
* Moves the given array element above another one in the array.
*
* @method Phaser.Structs.List#moveAbove
* @since 3.55.0
*
* @genericUse {T} - [child1,child2]
*
* @param {*} child1 - The element to move above base element.
* @param {*} child2 - The base element.
*/
moveAbove: function (child1, child2)
{
return ArrayUtils.MoveAbove(this.list, child1, child2);
},
2021-05-24 16:34:06 +00:00
/**
* Moves the given array element below another one in the array.
*
2021-05-24 16:34:06 +00:00
* @method Phaser.Structs.List#moveBelow
* @since 3.55.0
*
* @genericUse {T} - [child1,child2]
*
* @param {*} child1 - The element to move below base element.
* @param {*} child2 - The base element.
*/
moveBelow: function (child1, child2)
{
return ArrayUtils.MoveBelow(this.list, child1, child2);
},
2018-02-09 04:35:23 +00:00
/**
* Removes one or many items from the List.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#remove
* @since 3.0.0
*
* @param {*} child - The item, or array of items, to remove.
* @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item, or array of items, which were successfully removed from the List.
2018-02-09 04:35:23 +00:00
*/
remove: function (child, skipCallback)
{
if (skipCallback)
{
return ArrayUtils.Remove(this.list, child);
}
else
{
return ArrayUtils.Remove(this.list, child, this.removeCallback, this);
}
},
2018-02-09 04:35:23 +00:00
/**
* Removes the item at the given position in the List.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#removeAt
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [$return]
*
2020-11-23 10:22:13 +00:00
* @param {number} index - The position to remove the item from.
* @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item that was removed.
2018-02-09 04:35:23 +00:00
*/
removeAt: function (index, skipCallback)
{
if (skipCallback)
{
return ArrayUtils.RemoveAt(this.list, index);
}
else
{
return ArrayUtils.RemoveAt(this.list, index, this.removeCallback, this);
}
},
2018-02-09 04:35:23 +00:00
/**
* Removes the items within the given range in the List.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#removeBetween
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T[]} - [$return]
*
2020-11-23 10:22:13 +00:00
* @param {number} [startIndex=0] - The index to start removing from.
* @param {number} [endIndex] - The position to stop removing at. The item at this position won't be removed.
* @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback.
2018-02-09 04:35:23 +00:00
*
2018-10-19 14:53:04 +00:00
* @return {Array.<*>} An array of the items which were removed.
2018-02-09 04:35:23 +00:00
*/
removeBetween: function (startIndex, endIndex, skipCallback)
{
if (skipCallback)
{
return ArrayUtils.RemoveBetween(this.list, startIndex, endIndex);
}
else
{
return ArrayUtils.RemoveBetween(this.list, startIndex, endIndex, this.removeCallback, this);
}
},
/**
2018-02-09 04:35:23 +00:00
* Removes all the items.
*
* @method Phaser.Structs.List#removeAll
* @since 3.0.0
*
* @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback.
2018-03-30 12:43:58 +00:00
*
* @return {this} This List object.
2018-02-09 04:35:23 +00:00
*/
removeAll: function (skipCallback)
{
var i = this.list.length;
while (i--)
{
this.remove(this.list[i], skipCallback);
}
return this;
},
/**
2018-02-09 04:35:23 +00:00
* Brings the given child to the top of this List.
*
* @method Phaser.Structs.List#bringToTop
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T} - [child,$return]
*
* @param {*} child - The item to bring to the top of the List.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item which was moved.
2018-02-09 04:35:23 +00:00
*/
bringToTop: function (child)
{
return ArrayUtils.BringToTop(this.list, child);
},
/**
2018-02-09 04:35:23 +00:00
* Sends the given child to the bottom of this List.
*
* @method Phaser.Structs.List#sendToBack
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T} - [child,$return]
*
* @param {*} child - The item to send to the back of the list.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item which was moved.
2018-02-09 04:35:23 +00:00
*/
sendToBack: function (child)
{
return ArrayUtils.SendToBack(this.list, child);
},
/**
2018-02-09 04:35:23 +00:00
* Moves the given child up one place in this group unless it's already at the top.
*
* @method Phaser.Structs.List#moveUp
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T} - [child,$return]
*
* @param {*} child - The item to move up.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item which was moved.
2018-02-09 04:35:23 +00:00
*/
moveUp: function (child)
{
ArrayUtils.MoveUp(this.list, child);
return child;
},
/**
2018-02-09 04:35:23 +00:00
* Moves the given child down one place in this group unless it's already at the bottom.
*
* @method Phaser.Structs.List#moveDown
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T} - [child,$return]
*
* @param {*} child - The item to move down.
2018-02-09 04:35:23 +00:00
*
* @return {*} The item which was moved.
2018-02-09 04:35:23 +00:00
*/
moveDown: function (child)
{
ArrayUtils.MoveDown(this.list, child);
return child;
},
/**
2018-02-09 04:35:23 +00:00
* Reverses the order of all children in this List.
*
* @method Phaser.Structs.List#reverse
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {Phaser.Structs.List.<T>} - [$return]
*
2018-02-09 04:35:23 +00:00
* @return {Phaser.Structs.List} This List object.
*/
reverse: function ()
{
this.list.reverse();
return this;
},
2018-02-09 04:35:23 +00:00
/**
* Shuffles the items in the list.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#shuffle
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {Phaser.Structs.List.<T>} - [$return]
*
2018-02-09 04:35:23 +00:00
* @return {Phaser.Structs.List} This List object.
*/
shuffle: function ()
{
ArrayUtils.Shuffle(this.list);
return this;
},
/**
2018-02-09 04:35:23 +00:00
* Replaces a child of this List with the given newChild. The newChild cannot be a member of this List.
*
* @method Phaser.Structs.List#replace
* @since 3.0.0
*
2018-03-30 12:43:58 +00:00
* @genericUse {T} - [oldChild,newChild,$return]
*
2018-03-23 15:54:12 +00:00
* @param {*} oldChild - The child in this List that will be replaced.
* @param {*} newChild - The child to be inserted into this List.
2018-02-09 04:35:23 +00:00
*
2018-03-23 15:54:12 +00:00
* @return {*} Returns the oldChild that was replaced within this group.
2018-02-09 04:35:23 +00:00
*/
replace: function (oldChild, newChild)
{
return ArrayUtils.Replace(this.list, oldChild, newChild);
},
/**
* Checks if an item exists within the List.
2018-02-09 04:35:23 +00:00
*
* @method Phaser.Structs.List#exists
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [child]
*
* @param {*} child - The item to check for the existence of.
2018-02-09 04:35:23 +00:00
*
* @return {boolean} `true` if the item is found in the list, otherwise `false`.
2018-02-09 04:35:23 +00:00
*/
exists: function (child)
{
return (this.list.indexOf(child) > -1);
},
/**
2018-02-09 04:35:23 +00:00
* Sets the property `key` to the given value on all members of this List.
*
* @method Phaser.Structs.List#setAll
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {T} - [value]
*
* @param {string} property - The name of the property to set.
* @param {*} value - The value to set the property to.
2020-11-23 10:22:13 +00:00
* @param {number} [startIndex] - The first child index to start the search from.
* @param {number} [endIndex] - The last child index to search up until.
2018-02-09 04:35:23 +00:00
*/
setAll: function (property, value, startIndex, endIndex)
{
ArrayUtils.SetAll(this.list, property, value, startIndex, endIndex);
return this;
},
/**
2018-02-09 04:35:23 +00:00
* Passes all children to the given callback.
*
* @method Phaser.Structs.List#each
* @since 3.0.0
*
2018-03-29 10:56:47 +00:00
* @genericUse {EachListCallback.<T>} - [callback]
*
* @param {EachListCallback} callback - The function to call.
2018-06-13 07:37:40 +00:00
* @param {*} [context] - Value to use as `this` when executing callback.
2018-03-28 15:00:19 +00:00
* @param {...*} [args] - Additional arguments that will be passed to the callback, after the child.
2018-02-09 04:35:23 +00:00
*/
each: function (callback, context)
{
var args = [ null ];
for (var i = 2; i < arguments.length; i++)
{
args.push(arguments[i]);
}
for (i = 0; i < this.list.length; i++)
{
args[0] = this.list[i];
callback.apply(context, args);
}
},
/**
* Clears the List and recreates its internal array.
*
* @method Phaser.Structs.List#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.removeAll();
this.list = [];
},
/**
2018-09-28 11:45:01 +00:00
* Destroys this List.
*
* @method Phaser.Structs.List#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.removeAll();
this.parent = null;
this.addCallback = null;
this.removeCallback = null;
},
2018-02-09 04:35:23 +00:00
/**
* The number of items inside the List.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#length
2020-11-23 10:22:13 +00:00
* @type {number}
2018-10-09 12:40:00 +00:00
* @readonly
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
length: {
get: function ()
{
return this.list.length;
}
},
2018-02-09 04:35:23 +00:00
/**
* The first item in the List or `null` for an empty List.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#first
* @genericUse {T} - [$type]
* @type {*}
2018-10-09 12:40:00 +00:00
* @readonly
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
first: {
get: function ()
{
this.position = 0;
if (this.list.length > 0)
{
return this.list[0];
}
else
{
return null;
}
}
},
2018-02-09 04:35:23 +00:00
/**
* The last item in the List, or `null` for an empty List.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#last
* @genericUse {T} - [$type]
* @type {*}
2018-10-09 12:40:00 +00:00
* @readonly
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
last: {
get: function ()
{
if (this.list.length > 0)
{
this.position = this.list.length - 1;
return this.list[this.position];
}
else
{
return null;
}
}
},
2018-02-09 04:35:23 +00:00
/**
* The next item in the List, or `null` if the entire List has been traversed.
*
* This property can be read successively after reading {@link #first} or manually setting the {@link #position} to iterate the List.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#next
* @genericUse {T} - [$type]
* @type {*}
2018-10-09 12:40:00 +00:00
* @readonly
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
next: {
get: function ()
{
if (this.position < this.list.length)
{
this.position++;
return this.list[this.position];
}
else
{
return null;
}
}
},
2018-02-09 04:35:23 +00:00
/**
* The previous item in the List, or `null` if the entire List has been traversed.
*
* This property can be read successively after reading {@link #last} or manually setting the {@link #position} to iterate the List backwards.
2018-02-09 04:35:23 +00:00
*
* @name Phaser.Structs.List#previous
* @genericUse {T} - [$type]
* @type {*}
2018-10-09 12:40:00 +00:00
* @readonly
2018-02-09 04:35:23 +00:00
* @since 3.0.0
*/
previous: {
get: function ()
{
if (this.position > 0)
{
this.position--;
return this.list[this.position];
}
else
{
return null;
}
}
}
});
module.exports = List;