Skip to content

Commit

Permalink
Adding method to SystemManager
Browse files Browse the repository at this point in the history
Adding GetSystems and changing GetSystem
  • Loading branch information
tpastor committed Jul 29, 2013
1 parent 9834a19 commit d3f59e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Artemis_UnitTests/TestGeneral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public void TestAttributes()
Debug.WriteLine("OK");

// TestNormalEntityProcessingSystem2 and TestNormalEntityProcessingSystem3 are autoloaded (marked with ArtemisEntitySystem attribute)
List<TestNormalEntityProcessingSystem2> listOfTestNormalEntityProcessingSystem2 = entityWorld.SystemManager.GetSystem<TestNormalEntityProcessingSystem2>();
List<TestNormalEntityProcessingSystem2> listOfTestNormalEntityProcessingSystem2 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem2>();
Assert.IsNotNull(listOfTestNormalEntityProcessingSystem2, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem2 system.");
Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem2.Count, "Invalid count of TestNormalEntityProcessingSystem2 systems");
Debug.WriteLine("OK");

List<TestNormalEntityProcessingSystem3> listOfTestNormalEntityProcessingSystem3 = entityWorld.SystemManager.GetSystem<TestNormalEntityProcessingSystem3>();
List<TestNormalEntityProcessingSystem3> listOfTestNormalEntityProcessingSystem3 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem3>();
Assert.IsNotNull(listOfTestNormalEntityProcessingSystem3, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem3 system.");
Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem3.Count, "Invalid count of TestNormalEntityProcessingSystem3 systems");
Debug.WriteLine("OK");
Expand Down
30 changes: 26 additions & 4 deletions Artemis_XNA_INDEPENDENT/Manager/SystemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ public T SetSystem<T>(T system, GameLoopType gameLoopType, int layer = 0, Execut
return (T)this.SetSystem(system.GetType(), system, gameLoopType, layer, executionType);
}

/// <summary>Gets the system.</summary>
/// <typeparam name="T">The <see langword="Type"/> T.</typeparam>
/// <returns>The List{EntitySystem} of systems.</returns>
public List<T> GetSystem<T>() where T : EntitySystem
/// <summary>
/// Gets the systems.
/// </summary>
/// <typeparam name="T">The EntitySystem</typeparam>
/// <returns>A List of System Instances</returns>
public List<T> GetSystems<T>() where T : EntitySystem
{
IList system;

Expand All @@ -128,6 +130,26 @@ public List<T> GetSystem<T>() where T : EntitySystem
return (List<T>)system;
}

/// <summary>
/// Gets the system.
/// </summary>
/// <typeparam name="T">The EntitySystem</typeparam>
/// <returns>The system instance</returns>
/// <exception cref="InvalidOperationException">There are more or none systems of the type passed</exception>
public T GetSystem<T>() where T : EntitySystem
{
IList systems;

this.systems.TryGetValue(typeof(T), out systems);

if (systems != null && systems.Count > 1)
{
throw new InvalidOperationException(string.Format("System list contains more than one element of type {0}", typeof(T)));
}

return (T)systems[0];
}

/// <summary>Initializes all.</summary>
/// <param name="processAttributes">if set to <see langword="true" /> [process attributes].</param>
/// <param name="assembliesToScan">The assemblies to scan.</param>
Expand Down

0 comments on commit d3f59e7

Please sign in to comment.