mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 00:21:04 +00:00
Group.checkAll allows you to check if the same property exists across all children of the Group and is set to the given value (thanks @codevinsky #1013)
Group.checkProperty allows you to check if the property exists on the given child of the Group and is set to the value specified (thanks @codevinsky #1013) Phaser.Utils.setProperty will set an Objects property regardless of depth (thanks @codevinsky #1013) Phaser.Utils.setProperty will set an Objects property regardless of depth (thanks @codevinsky #1013) Phaser.Utils.getProperty will get an Objects property regardless of depth (thanks @codevinsky #1013)
This commit is contained in:
parent
3da788bd1d
commit
24527eac3e
4 changed files with 42 additions and 29 deletions
10
README.md
10
README.md
|
@ -67,6 +67,11 @@ Version 2.0.7 - "Amadicia" - -in development-
|
||||||
* Animation.updateFrameData allows you to load a new FrameData object into an existing animation, even if currently running (based on #1029)
|
* Animation.updateFrameData allows you to load a new FrameData object into an existing animation, even if currently running (based on #1029)
|
||||||
* AnimationManager.loadFrameData will now update all existing Animations to use the newly loaded FrameData (based on #1029)
|
* AnimationManager.loadFrameData will now update all existing Animations to use the newly loaded FrameData (based on #1029)
|
||||||
* Sprite.loadTexture will store the `smoothed` property of the Sprite and re-apply it once the new texture is loaded.
|
* Sprite.loadTexture will store the `smoothed` property of the Sprite and re-apply it once the new texture is loaded.
|
||||||
|
* Group.checkAll allows you to check if the same property exists across all children of the Group and is set to the given value (thanks @codevinsky #1013)
|
||||||
|
* Group.checkProperty allows you to check if the property exists on the given child of the Group and is set to the value specified (thanks @codevinsky #1013)
|
||||||
|
* Phaser.Utils.setProperty will set an Objects property regardless of depth (thanks @codevinsky #1013)
|
||||||
|
* Phaser.Utils.setProperty will set an Objects property regardless of depth (thanks @codevinsky #1013)
|
||||||
|
* Phaser.Utils.getProperty will get an Objects property regardless of depth (thanks @codevinsky #1013)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
@ -84,8 +89,7 @@ Version 2.0.7 - "Amadicia" - -in development-
|
||||||
* Animation now guards against _frameData being null (thanks @lucbloom #1033)
|
* Animation now guards against _frameData being null (thanks @lucbloom #1033)
|
||||||
* Tilemap.swap now accurately swaps from A to B and from B to A (thanks @noidexe #1034)
|
* Tilemap.swap now accurately swaps from A to B and from B to A (thanks @noidexe #1034)
|
||||||
* BitmapData.resize fixed to update the crop property too, resolves issues with images getting cut off with BitmapData.load.
|
* BitmapData.resize fixed to update the crop property too, resolves issues with images getting cut off with BitmapData.load.
|
||||||
|
* OrientationSprite fix as it's not using PIXI.TextureCache anymore (thanks @DarkDev- #1036)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Migration Guide
|
### Migration Guide
|
||||||
|
@ -122,7 +126,7 @@ You can [clone the Phaser repo in Koding](https://koding.com/Teamwork?import=htt
|
||||||
|
|
||||||
If you use bower you can install phaser with:
|
If you use bower you can install phaser with:
|
||||||
|
|
||||||
`bower install phaser`
|
`bower install phaser-official`
|
||||||
|
|
||||||
Nice and easy :)
|
Nice and easy :)
|
||||||
|
|
||||||
|
|
4
build/phaser.d.ts
vendored
4
build/phaser.d.ts
vendored
|
@ -2282,6 +2282,8 @@ declare module Phaser {
|
||||||
callAll(method: string, context: any, ...parameters: any[]): void;
|
callAll(method: string, context: any, ...parameters: any[]): void;
|
||||||
callAllExists(callback: Function, existsValue: boolean, ...parameters: any[]): void;
|
callAllExists(callback: Function, existsValue: boolean, ...parameters: any[]): void;
|
||||||
callbackFromArray(child: Object, callback: Function, length: number): void;
|
callbackFromArray(child: Object, callback: Function, length: number): void;
|
||||||
|
checkAll(key: string[], value: any, checkAlive?: boolean, checkVisible?: boolean, force?: boolean): boolean;
|
||||||
|
checkProperty(child: Object, key: string[], value: any, force?: boolean): boolean;
|
||||||
countDead(): number;
|
countDead(): number;
|
||||||
countLiving(): number;
|
countLiving(): number;
|
||||||
create(x: number, y: number, key: string, frame?: any, exists?: boolean): any;
|
create(x: number, y: number, key: string, frame?: any, exists?: boolean): any;
|
||||||
|
@ -5099,11 +5101,13 @@ declare module Phaser {
|
||||||
class Utils {
|
class Utils {
|
||||||
|
|
||||||
static extend(deep: boolean, target: Object): Object;
|
static extend(deep: boolean, target: Object): Object;
|
||||||
|
static getProperty(obj: Object, prop: string): any;
|
||||||
static isPlainObject(object: Object): boolean;
|
static isPlainObject(object: Object): boolean;
|
||||||
static mixin(from: Object, to: Object): Object;
|
static mixin(from: Object, to: Object): Object;
|
||||||
static pad(str: string, len: number, pad: number, dir?: number): string;
|
static pad(str: string, len: number, pad: number, dir?: number): string;
|
||||||
static parseDimension(size: any, dimension: number): number;
|
static parseDimension(size: any, dimension: number): number;
|
||||||
static rotateArray<T>(array: T[], direction: any): T;
|
static rotateArray<T>(array: T[], direction: any): T;
|
||||||
|
static setProperty(obj: Object, prop: string, value: any): Object;
|
||||||
static shuffle<T>(array: T[]): T;
|
static shuffle<T>(array: T[]): T;
|
||||||
static transposeArray<T>(array: T[]): T;
|
static transposeArray<T>(array: T[]): T;
|
||||||
|
|
||||||
|
|
|
@ -760,24 +760,14 @@ Phaser.Group.prototype.checkProperty = function (child, key, value, force) {
|
||||||
|
|
||||||
if (typeof force === 'undefined') { force = false; }
|
if (typeof force === 'undefined') { force = false; }
|
||||||
|
|
||||||
|
|
||||||
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's much faster than a for loop or object iteration.
|
|
||||||
|
|
||||||
// 0 = Equals
|
|
||||||
// 1 = Add
|
|
||||||
// 2 = Subtract
|
|
||||||
// 3 = Multiply
|
|
||||||
// 4 = Divide
|
|
||||||
|
|
||||||
// We can't force a property in and the child doesn't have it, so abort.
|
// We can't force a property in and the child doesn't have it, so abort.
|
||||||
// Equally we can't add, subtract, multiply or divide a property value if it doesn't exist, so abort in those cases too.
|
|
||||||
if (!Phaser.Utils.getProperty(child, key) && force)
|
if (!Phaser.Utils.getProperty(child, key) && force)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(Phaser.Utils.getProperty(child,key) !== value) {
|
if (Phaser.Utils.getProperty(child, key) !== value)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -891,10 +881,9 @@ Phaser.Group.prototype.setAllChildren = function (key, value, checkAlive, checkV
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function allows you to quickly check that the same property across all children of this Group is equal to the given value
|
* This function allows you to quickly check that the same property across all children of this Group is equal to the given value.
|
||||||
* This call doesn't descend down children, so if you have a Group inside of this Group, the property will be checked on the Group but not its children.
|
* This call doesn't descend down children, so if you have a Group inside of this Group, the property will be checked on the Group but not its children.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @method Phaser.Group#checkAll
|
* @method Phaser.Group#checkAll
|
||||||
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
|
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
|
||||||
* @param {*} value - The value that will be checked.
|
* @param {*} value - The value that will be checked.
|
||||||
|
@ -903,6 +892,7 @@ Phaser.Group.prototype.setAllChildren = function (key, value, checkAlive, checkV
|
||||||
* @param {boolean} [force=false] - If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
|
* @param {boolean} [force=false] - If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.checkAll = function (key, value, checkAlive, checkVisible, force) {
|
Phaser.Group.prototype.checkAll = function (key, value, checkAlive, checkVisible, force) {
|
||||||
|
|
||||||
if (typeof checkAlive === 'undefined') { checkAlive = false; }
|
if (typeof checkAlive === 'undefined') { checkAlive = false; }
|
||||||
if (typeof checkVisible === 'undefined') { checkVisible = false; }
|
if (typeof checkVisible === 'undefined') { checkVisible = false; }
|
||||||
if (typeof force === 'undefined') { force = false; }
|
if (typeof force === 'undefined') { force = false; }
|
||||||
|
@ -911,7 +901,8 @@ Phaser.Group.prototype.checkAll = function (key, value, checkAlive, checkVisible
|
||||||
{
|
{
|
||||||
if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible)))
|
if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible)))
|
||||||
{
|
{
|
||||||
if(!this.checkProperty(this.children[i], key, value, force)) {
|
if (!this.checkProperty(this.children[i], key, value, force))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,55 +13,69 @@
|
||||||
Phaser.Utils = {
|
Phaser.Utils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an object's property by string.
|
* Gets an objects property by string.
|
||||||
*
|
*
|
||||||
* @method Phaser.Utils.getProperty
|
* @method Phaser.Utils.getProperty
|
||||||
* @param {object} obj - The object to traverse
|
* @param {object} obj - The object to traverse.
|
||||||
* @param {string} prop - The property whose value will be returned
|
* @param {string} prop - The property whose value will be returned.
|
||||||
* @return {*} the value of the property or null if property isn't found
|
* @return {*} the value of the property or null if property isn't found .
|
||||||
*/
|
*/
|
||||||
getProperty: function(obj, prop) {
|
getProperty: function(obj, prop) {
|
||||||
|
|
||||||
var parts = prop.split('.'),
|
var parts = prop.split('.'),
|
||||||
last = parts.pop(),
|
last = parts.pop(),
|
||||||
l = parts.length,
|
l = parts.length,
|
||||||
i = 1,
|
i = 1,
|
||||||
current = parts[0];
|
current = parts[0];
|
||||||
|
|
||||||
while(i < l && (obj = obj[current]) ) {
|
while (i < l && (obj = obj[current]))
|
||||||
|
{
|
||||||
current = parts[i];
|
current = parts[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(obj) {
|
if (obj)
|
||||||
|
{
|
||||||
return obj[last];
|
return obj[last];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an object's property by string.
|
* Sets an objects property by string.
|
||||||
*
|
*
|
||||||
* @method Phaser.Utils.setProperty
|
* @method Phaser.Utils.setProperty
|
||||||
* @param {object} obj - The object to traverse
|
* @param {object} obj - The object to traverse
|
||||||
* @param {string} prop - The property whose value will be changed
|
* @param {string} prop - The property whose value will be changed
|
||||||
|
* @return {object} The object on which the property was set.
|
||||||
*/
|
*/
|
||||||
setProperty: function(obj, prop, value) {
|
setProperty: function(obj, prop, value) {
|
||||||
|
|
||||||
var parts = prop.split('.'),
|
var parts = prop.split('.'),
|
||||||
last = parts.pop(),
|
last = parts.pop(),
|
||||||
l = parts.length,
|
l = parts.length,
|
||||||
i = 1,
|
i = 1,
|
||||||
current = parts[0];
|
current = parts[0];
|
||||||
|
|
||||||
while(i < l && (obj = obj[current]) ) {
|
while (i < l && (obj = obj[current]))
|
||||||
|
{
|
||||||
current = parts[i];
|
current = parts[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(obj) {
|
if (obj)
|
||||||
|
{
|
||||||
obj[last] = value;
|
obj[last] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transposes the elements of the given Array.
|
* Transposes the elements of the given Array.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue