Search in sources :

Example 1 with PrefabData

use of org.terasology.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.entitySystem.prefab.PrefabData) EntityData(org.terasology.protobuf.EntityData) Module(org.terasology.module.Module)

Example 2 with PrefabData

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

the class WorldSerializerImpl method createPrefab.

private void createPrefab(EntityData.Prefab prefabData) {
    SimpleUri uri = new SimpleUri(prefabData.getName());
    try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(moduleManager.getEnvironment().get(uri.getModuleName()))) {
        PrefabData protoPrefab = prefabSerializer.deserialize(prefabData);
        Assets.generateAsset(new ResourceUrn(prefabData.getName()), protoPrefab, Prefab.class);
    } catch (Exception e) {
        logger.error("Failed to create prefab {}", prefabData.getName());
    }
}
Also used : PrefabData(org.terasology.entitySystem.prefab.PrefabData) SimpleUri(org.terasology.engine.SimpleUri) ModuleContext(org.terasology.persistence.ModuleContext) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 3 with PrefabData

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

the class EntitySerializerTest method setup.

@Before
public void setup() {
    context.put(NetworkSystem.class, mock(NetworkSystem.class));
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "integer"), IntegerComponent.class);
    entitySerializer = new EntitySerializer(entityManager);
    componentLibrary = entityManager.getComponentLibrary();
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Value"));
    prefab = Assets.generateAsset(new ResourceUrn("test:Test"), prefabData, Prefab.class);
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) NetworkSystem(org.terasology.network.NetworkSystem) SimpleUri(org.terasology.engine.SimpleUri) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) EntitySerializer(org.terasology.persistence.serializers.EntitySerializer) Before(org.junit.Before)

Example 4 with PrefabData

use of org.terasology.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.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 5 with PrefabData

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

the class PojoEntityManagerTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    context = new ContextImpl();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
    assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    CoreRegistry.setContext(context);
}
Also used : PrefabData(org.terasology.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) ContextImpl(org.terasology.context.internal.ContextImpl) ModuleManager(org.terasology.engine.module.ModuleManager) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) BeforeClass(org.junit.BeforeClass)

Aggregations

PrefabData (org.terasology.entitySystem.prefab.PrefabData)16 Prefab (org.terasology.entitySystem.prefab.Prefab)13 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)12 ResourceUrn (org.terasology.assets.ResourceUrn)7 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)7 ContextImpl (org.terasology.context.internal.ContextImpl)6 ModuleManager (org.terasology.engine.module.ModuleManager)6 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)4 NetworkSystem (org.terasology.network.NetworkSystem)4 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)3 StringComponent (org.terasology.entitySystem.stubs.StringComponent)3 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)3 Test (org.junit.Test)2 AssetManager (org.terasology.assets.management.AssetManager)2 SimpleUri (org.terasology.engine.SimpleUri)2 BehaviorTree (org.terasology.logic.behavior.asset.BehaviorTree)2 BehaviorTreeData (org.terasology.logic.behavior.asset.BehaviorTreeData)2 UIData (org.terasology.rendering.nui.asset.UIData)2 UIElement (org.terasology.rendering.nui.asset.UIElement)2