Search in sources :

Example 6 with PrefabData

use of org.terasology.engine.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testPrefabPersistedRetainedCorrectly.

@Test
public void testPrefabPersistedRetainedCorrectly() {
    PrefabData protoPrefab = new PrefabData();
    protoPrefab.setPersisted(false);
    prefab = Assets.generateAsset(new ResourceUrn("unittest:nonpersistentPrefab"), protoPrefab, Prefab.class);
    EntityRef entity1 = entityManager.create(prefab);
    assertFalse(entity1.isPersistent());
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 7 with PrefabData

use of org.terasology.engine.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.

the class PojoPrefabManagerTest method testRetrievePrefab.

@Test
public void testRetrievePrefab() {
    PrefabData data = new PrefabData();
    data.addComponent(new StringComponent("Test"));
    Assets.generateAsset(new ResourceUrn(PREFAB_NAME), data, Prefab.class);
    Prefab ref = prefabManager.getPrefab(PREFAB_NAME);
    assertNotNull(ref);
    assertEquals(PREFAB_NAME, ref.getName());
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) Test(org.junit.jupiter.api.Test)

Example 8 with PrefabData

use of org.terasology.engine.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method createPrefabWithString.

private Prefab createPrefabWithString(String urn, String text, AssetManager assetManager) {
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent(text));
    return assetManager.loadAsset(new ResourceUrn(urn), prefabData, Prefab.class);
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 9 with PrefabData

use of org.terasology.engine.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.

the class PrefabSerializer method deserialize.

/**
 * Deserializes a prefab
 *
 * @param prefabData
 * @param deltas
 * @return The deserialized prefab
 */
public PrefabData deserialize(EntityData.Prefab prefabData, List<EntityData.Prefab> deltas) {
    Module context = ModuleContext.getContext();
    PrefabData result = new PrefabData();
    deserializeCommonData(prefabData, result);
    for (EntityData.Prefab delta : deltas) {
        applyCommonDataDelta(delta, result);
    }
    addInheritedComponents(result);
    applyComponentChanges(context, prefabData, result);
    for (EntityData.Prefab delta : deltas) {
        applyComponentChanges(context, delta, result);
    }
    return result;
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) EntityData(org.terasology.protobuf.EntityData) Module(org.terasology.gestalt.module.Module)

Aggregations

PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)9 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)7 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)6 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 StringComponent (org.terasology.unittest.stubs.StringComponent)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)3 Test (org.junit.jupiter.api.Test)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 SimpleUri (org.terasology.engine.core.SimpleUri)1 ModuleContext (org.terasology.engine.core.module.ModuleContext)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)1 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)1 PrefabFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabFormat)1 EntitySerializer (org.terasology.engine.persistence.serializers.EntitySerializer)1 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)1 WorldProviderCoreStub (org.terasology.engine.testUtil.WorldProviderCoreStub)1