Skip to content

Commit

Permalink
Add method to fetch a collection of all components on an entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlord committed Oct 4, 2012
1 parent b933e7d commit baf6cd4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/net/richardlord/ash/core/Entity.as
Expand Up @@ -106,6 +106,21 @@ package net.richardlord.ash.core
{
return components[ componentClass ];
}

/**
* Get all components from the entity.
*
* @return An array containing all the components that are on the entity.
*/
public function getAll() : Array
{
var componentArray : Array = new Array();
for each( var component : * in components )
{
componentArray.push( component );
}
return componentArray;
}

/**
* Does the entity have a component of a particular type.
Expand Down
14 changes: 14 additions & 0 deletions test/src/net/richardlord/ash/core/EntityTests.as
Expand Up @@ -3,6 +3,7 @@ package net.richardlord.ash.core
import asunit.framework.IAsync;

import org.hamcrest.assertThat;
import org.hamcrest.collection.hasItems;
import org.hamcrest.object.equalTo;
import org.hamcrest.object.isFalse;
import org.hamcrest.object.isTrue;
Expand Down Expand Up @@ -90,6 +91,19 @@ package net.richardlord.ash.core
assertThat( entity.get( MockComponent ), nullValue() );
}

[Test]
public function willRetrieveAllComponents() : void
{
var component1 : MockComponent = new MockComponent();
entity.add( component1 );
var component2 : MockComponent2 = new MockComponent2();
entity.add( component2 );
var all : Array = entity.getAll();
assertThat( all.length, equalTo( 2 ) );
assertThat( all, hasItems( component1, component2 ) );

}

[Test]
public function hasComponentIsFalseIfComponentTypeNotPresent() : void
{
Expand Down

0 comments on commit baf6cd4

Please sign in to comment.