Structs.Map.setAll is a new method that allows you to pass an array of elements to be set into the Map. This is a chainable method.

This commit is contained in:
Richard Davey 2023-11-08 12:09:05 +00:00
parent b111d64097
commit eea31c7be8

View file

@ -66,6 +66,27 @@ var Map = new Class({
*/
this.size = 0;
this.setAll(elements);
},
/**
* Adds all the elements in the given array to this Map.
*
* If the element already exists, the value will be skipped.
*
* @method Phaser.Structs.Map#setAll
* @since 3.61.0
*
* @generic K
* @generic V
* @genericUse {V[]} - [elements]
*
* @param {Array.<*>} elements - An array of key-value pairs to populate this Map with.
*
* @return {this} This Map object.
*/
setAll: function (elements)
{
if (Array.isArray(elements))
{
for (var i = 0; i < elements.length; i++)
@ -73,12 +94,17 @@ var Map = new Class({
this.set(elements[i][0], elements[i][1]);
}
}
return this;
},
/**
* Adds an element with a specified `key` and `value` to this Map.
*
* If the `key` already exists, the value will be replaced.
*
* If you wish to add multiple elements in a single call, use the `setAll` method instead.
*
* @method Phaser.Structs.Map#set
* @since 3.0.0
*
@ -89,7 +115,7 @@ var Map = new Class({
* @param {string} key - The key of the element to be added to this Map.
* @param {*} value - The value of the element to be added to this Map.
*
* @return {Phaser.Structs.Map} This Map object.
* @return {this} This Map object.
*/
set: function (key, value)
{
@ -175,7 +201,7 @@ var Map = new Class({
*
* @param {string} key - The key of the element to delete from this Map.
*
* @return {Phaser.Structs.Map} This Map object.
* @return {this} This Map object.
*/
delete: function (key)
{
@ -196,7 +222,7 @@ var Map = new Class({
*
* @genericUse {Phaser.Structs.Map.<K, V>} - [$return]
*
* @return {Phaser.Structs.Map} This Map object.
* @return {this} This Map object.
*/
clear: function ()
{
@ -284,7 +310,7 @@ var Map = new Class({
*
* @param {EachMapCallback} callback - The callback which will receive the keys and entries held in this Map.
*
* @return {Phaser.Structs.Map} This Map object.
* @return {this} This Map object.
*/
each: function (callback)
{
@ -340,7 +366,7 @@ var Map = new Class({
* @param {Phaser.Structs.Map} map - The Map to merge in to this Map.
* @param {boolean} [override=false] - Set to `true` to replace values in this Map with those from the source map, or `false` to skip them.
*
* @return {Phaser.Structs.Map} This Map object.
* @return {this} This Map object.
*/
merge: function (map, override)
{