Search in sources :

Example 1 with EntityRefComponent

use of org.terasology.entitySystem.stubs.EntityRefComponent in project Terasology by MovingBlocks.

the class StorageManagerTest method testReferenceRemainsValidOverStorageRestoral.

@Test
public void testReferenceRemainsValidOverStorageRestoral() throws Exception {
    EntityRef someEntity = entityManager.create();
    character.addComponent(new EntityRefComponent(someEntity));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    PlayerStore restored = newSM.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.getCharacter().getComponent(EntityRefComponent.class).entityRef.exists());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) EntityRefComponent(org.terasology.entitySystem.stubs.EntityRefComponent) PlayerStore(org.terasology.persistence.PlayerStore) StorageManager(org.terasology.persistence.StorageManager) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 2 with EntityRefComponent

use of org.terasology.entitySystem.stubs.EntityRefComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testDestroyingEntityInvalidatesEntityRefs.

@Test
public void testDestroyingEntityInvalidatesEntityRefs() {
    EntityRef main = entityManager.create();
    main.addComponent(new StringComponent());
    EntityRef reference = entityManager.create();
    EntityRefComponent refComp = reference.addComponent(new EntityRefComponent());
    refComp.entityRef = entityManager.getEntitiesWith(StringComponent.class).iterator().next();
    assertTrue(main.exists());
    entityManager.getEntitiesWith(StringComponent.class).iterator().next().destroy();
    assertFalse(main.exists());
    assertFalse(refComp.entityRef.exists());
}
Also used : EntityRefComponent(org.terasology.entitySystem.stubs.EntityRefComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 StringComponent (org.terasology.entitySystem.stubs.StringComponent)1 PlayerStore (org.terasology.persistence.PlayerStore)1 StorageManager (org.terasology.persistence.StorageManager)1