Skip to content

Commit

Permalink
Automatically Injecting when adding system to game
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Sep 19, 2014
1 parent 03bfcf8 commit 3624f33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public EventExecutor getEvents() {

public void addSystem(ECSSystem system) {
this.systems.add(system);
Retrievers.inject(system, this);
}

public void startGame() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.*;
import net.zomis.cardshifter.ecs.base.ComponentRetriever;
import net.zomis.cardshifter.ecs.base.ECSGame;
import net.zomis.cardshifter.ecs.base.ECSSystem;
import net.zomis.cardshifter.ecs.base.Entity;
import net.zomis.cardshifter.ecs.base.Retriever;
import net.zomis.cardshifter.ecs.base.RetrieverSingleton;
Expand All @@ -21,6 +22,26 @@ public class InjectionTest {
@Retriever
private ComponentRetriever<PlayerComponent> playerData;

private int test;

@Test
public void injectOnAdd() {
ECSGame game = new ECSGame();
game.newEntity().addComponent(new PlayerComponent(21, "Test"));
game.addSystem(new ECSSystem() {
@RetrieverSingleton
private PlayerComponent player;

@Override
public void startGame(ECSGame game) {
assertEquals(21, player.getIndex());
test++;
}
});
game.startGame();
assertEquals(1, test);
}

@Test
public void inject() {
ECSGame game = new ECSGame();
Expand Down

0 comments on commit 3624f33

Please sign in to comment.