Search in sources :

Example 1 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testCharacterSurvivesStorage.

@Test
public void testCharacterSurvivesStorage() {
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restored = esm.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.hasCharacter());
    assertEquals(character, restored.getCharacter());
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Test(org.junit.Test)

Example 2 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testPlayerRelevanceLocationSurvivesStorage.

@Test
public void testPlayerRelevanceLocationSurvivesStorage() {
    Vector3f loc = new Vector3f(1, 2, 3);
    character.addComponent(new LocationComponent(loc));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restored = esm.loadPlayerStore(PLAYER_ID);
    assertEquals(loc, restored.getRelevanceLocation());
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent) Test(org.junit.Test)

Example 3 with PlayerStore

use of org.terasology.persistence.PlayerStore 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 4 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class NetworkSystemImpl method connectClient.

private void connectClient(Client client) {
    PlayerStore entityStore = storageManager.loadPlayerStore(client.getId());
    client.getEntity().send(new ConnectedEvent(entityStore));
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) ConnectedEvent(org.terasology.network.events.ConnectedEvent)

Example 5 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testStoreAndRestoreOfPlayerWithoutCharacter.

@Test
public void testStoreAndRestoreOfPlayerWithoutCharacter() {
    // remove character from player:
    character.destroy();
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restoredStore = esm.loadPlayerStore(PLAYER_ID);
    assertNotNull(restoredStore);
    assertFalse(restoredStore.hasCharacter());
    assertEquals(new Vector3f(), restoredStore.getRelevanceLocation());
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Vector3f(org.terasology.math.geom.Vector3f) Test(org.junit.Test)

Aggregations

PlayerStore (org.terasology.persistence.PlayerStore)8 Test (org.junit.Test)5 Vector3f (org.terasology.math.geom.Vector3f)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)3 LocationComponent (org.terasology.logic.location.LocationComponent)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Client (org.terasology.network.Client)1 ConnectedEvent (org.terasology.network.events.ConnectedEvent)1 StorageManager (org.terasology.persistence.StorageManager)1