Permalink
Browse files

Add method to get a system based on its class type.

  • Loading branch information...
1 parent aaf30fe commit ada7501197b4425bb0747ab4fba6f03917c3f940 @richardlord committed May 6, 2012
@@ -141,6 +141,18 @@ package net.richardlord.ash.core
}
/**
+ * Get the system instance of a particular type from within the game.
+ *
+ * @param type The type of system
+ * @return The instance of the system type that is in the game, or
+ * null if no systems of this type are in the game.
+ */
+ public function getSystem( type : Class ) : System
+ {
+ return systems.get( type );
+ }
+
+ /**
* Remove a system from the game.
*
* @param system The system to remove from the game.
@@ -78,5 +78,17 @@ package net.richardlord.ash.core
}
tail = null;
}
+
+ internal function get( type : Class ) : System
+ {
+ for( var system : System = head; system; system = system.next )
+ {
+ if ( system is type )
+ {
+ return system;
+ }
+ }
+ return null;
+ }
}
}
@@ -6,6 +6,7 @@ package net.richardlord.ash.core
import org.hamcrest.object.equalTo;
import org.hamcrest.object.isFalse;
import org.hamcrest.object.isTrue;
+ import org.hamcrest.object.nullValue;
import org.hamcrest.object.sameInstance;
public class SystemTests
@@ -138,6 +139,22 @@ package net.richardlord.ash.core
game.update( 0.1 );
}
+ [Test]
+ public function getSystemReturnsTheSystem() : void
+ {
+ var system1 : System = new MockSystem( this );
+ game.addSystem( system1, 0 );
+ game.addSystem( new System(), 0 );
+ assertThat( game.getSystem( MockSystem ), sameInstance( system1 ) );
+ }
+
+ [Test]
+ public function getSystemReturnsNullIfNoSuchSystem() : void
+ {
+ game.addSystem( new System(), 0 );
+ assertThat( game.getSystem( MockSystem ), nullValue() );
+ }
+
private function addedCallbackMethod( system : System, action : String, systemGame : Game ) : void
{
assertThat( action, equalTo( "added" ) );

0 comments on commit ada7501

Please sign in to comment.