use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.
the class EntitySerializerTest method testDeltaLoadAddedComponent.
@Test
public void testDeltaLoadAddedComponent() throws Exception {
EntityRef entity = entityManager.create("test:Test");
entity.addComponent(new IntegerComponent(2));
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
EntityRef loadedEntity = entitySerializer.deserialize(entityData);
assertTrue(loadedEntity.exists());
assertTrue(loadedEntity.hasComponent(StringComponent.class));
assertEquals("Value", loadedEntity.getComponent(StringComponent.class).value);
assertTrue(loadedEntity.hasComponent(IntegerComponent.class));
assertEquals(2, loadedEntity.getComponent(IntegerComponent.class).value);
}
use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs.
@Test
public void testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs() {
worldStub.setBlock(Vector3i.zero(), blockWithString);
EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
entity.addComponent(new IntegerComponent(1));
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), IntegerComponent.class);
worldProvider.update(1.0f);
assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.
the class PojoEventSystemTests method testChildEventReceivedByUnfilteredHandler.
@Test
public void testChildEventReceivedByUnfilteredHandler() {
entity.addComponent(new IntegerComponent());
TestEventHandler handler = new TestEventHandler();
eventSystem.registerEvent(new SimpleUri("test:childEvent"), TestChildEvent.class);
eventSystem.registerEventHandler(handler);
TestChildEvent event = new TestChildEvent();
eventSystem.send(entity, event);
assertEquals(1, handler.unfilteredEvents.size());
}
use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.
the class PojoEventSystemTests method testReceiveEventRequiringMultipleComponents.
@Test
public void testReceiveEventRequiringMultipleComponents() {
StringComponent stringComponent = entity.addComponent(new StringComponent());
IntegerComponent intComponent = entity.addComponent(new IntegerComponent());
TestCompoundComponentEventHandler handler = new TestCompoundComponentEventHandler();
eventSystem.registerEventHandler(handler);
TestEvent event = new TestEvent();
eventSystem.send(entity, event);
assertEquals(1, handler.receivedList.size());
assertEquals(event, handler.receivedList.get(0).event);
assertEquals(entity, handler.receivedList.get(0).entity);
}
Aggregations