Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: Phaser.Utils.getProperty / Phaser.Utils.setProperty; added: Phase... #1013

Merged
merged 1 commit into from
Jul 18, 2014

Conversation

ada-lovecraft
Copy link
Contributor

...r.Group.checkAll

Added deep-property getting and setting via strings:

Phaser.Util.getProperty(someObj, 'foo.bar.baz');

Phaser.Util.setProperty(someObj, 'foo.bar.baz', 'lol');

Added a "checkAll" method to Phaser.Group that returns true/false if all of the children's given properties match the value passed in.

this.someGroup.checkAll('foo.bar.baz', 'lol'); // will return true if child[n].foo.bar.baz === 'lol'

Comes with standard 'force' ability.

…aser.Group.checkAll

Added deep-property getting and setting via strings:

Phaser.Util.getProperty(someObj, 'foo.bar.baz');

Phaser.Util.setProperty(someObj, 'foo.bar.baz', 'lol');

Added a "checkAll" method to Phaser.Group that returns true/false if all of the children's given properties match the value passed in.

this.someGroup.checkAll('foo.bar.baz', 'lol'); // will return true if child[n].foo.bar.baz === 'lol'

Comes with standard 'force' ability.
@lucbloom
Copy link
Contributor

  • Maybe instead of having dedicated booleans (checkAlive, checkVisible), you could have a node validation callback passed in:

    var child = this.children[i]; // Temp var to save an extra array lookup...
    if (!validate || validate(child))

  • Expert challenge: Could you extend the .split(.) with logic that finds [" ... "]?

  • What if a user inputs "this.frame . x" (which is valid JavaScript)? \t\n< space >

@ada-lovecraft
Copy link
Contributor Author

A few questions/observations about your comments:

  1. The current implementation of checkAlive and checkVisible is standard across all of Phaser.Group's "all" methods. I didn't want to break the paradigm for this implementation. I completely agree with passing in validation callbacks, however, as previously stated, that's not the current paradigm. With the addition of Phaser.Utils.getProperty/setProperty, a lot of redundant code in Group can be re-written. This would need to be implemented across the Group api, and would be a severely breaking change. I'm ok with this, due to the up-coming 2.1 release, however, I don't want to move forward without getting the go-ahead from @photonstorm
  2. I'm not sure what you mean... could you give me an example?
  3. Checking for spaces in a string would be a fairly simple regex to implement, but as a framework, do we really want to sacrifice performance to accommodate for what is widely accepted as bad coding style?

Dr. Ian Malcolm: Yeah, yeah, but your scientists were so preoccupied with whether or not they could that they didn't stop to think if they should.

@lucbloom
Copy link
Contributor

All valid points. I was thinking from a pure utility function standpoint, like when a game author would use it. Not if it were intended for the core engine implementation.

(Example: this["frame"].x = 3 <--- again, misunderstood the intended audience...)

@ada-lovecraft
Copy link
Contributor Author

I am curious as to what your second point meant. I'm imagining something like:

var value = Phaser.Utils.getProperty(someObj, 'params.position...');

and I have no idea how or what you would do with that?

@photonstorm
Copy link
Collaborator

I'm going to merge this for now, as it's a non-breaking change and a nice feature to add. We can iterate on it for a 2.1 release.

photonstorm added a commit that referenced this pull request Jul 18, 2014
added: Phaser.Utils.getProperty / Phaser.Utils.setProperty; added: Phase...
@photonstorm photonstorm merged commit 3da788b into phaserjs:dev Jul 18, 2014
photonstorm added a commit that referenced this pull request Jul 18, 2014
… 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants