From 5fd066c610295cba10f9db92022205e4d14634f6 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Sun, 22 Feb 2015 19:30:23 +0000 Subject: [PATCH] ArraySet.getByKey gets an item from the set based on the property strictly equaling the value given. --- README.md | 1 + src/utils/ArraySet.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 0cd49bdb9..1b04dff64 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ We've also removed functions and properties from Pixi classes that Phaser doesn' * Tween.repeat has a new parameter `repeatDelay` which allows you to set the delay (in ms) before a tween will repeat itself. * Tween.yoyo has a new parameter `yoyoDelay` which allows you to set the delay (in ms) before a tween will start a yoyo. * Tween.interpolation has a new parameter `context` which allows you to define the context in which the interpolation function will run. +* ArraySet.getByKey gets an item from the set based on the property strictly equaling the value given. ### Bug Fixes diff --git a/src/utils/ArraySet.js b/src/utils/ArraySet.js index d5e223a76..62dcc14a2 100644 --- a/src/utils/ArraySet.js +++ b/src/utils/ArraySet.js @@ -67,6 +67,31 @@ Phaser.ArraySet.prototype = { }, + /** + * Gets an item from the set based on the property strictly equaling the value given. + * Returns null if not found. + * + * @method Phaser.ArraySet#getByKey + * @param {string} property - The property to check against the value. + * @param {any} value - The value to check if the property strictly equals. + * @return {any} The item that was found, or null if nothing matched. + */ + getByKey: function (property, value) { + + var i = this.list.length; + + while (i--) + { + if (this.list[i][property] === value) + { + return this.list[i]; + } + } + + return null; + + }, + /** * Checks for the item within this list. *