Search in sources :

Example 1 with PrefabData

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

the class PrefabTest method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    AssetType<Prefab, PrefabData> prefabDataAssetType = assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
    TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
    assetTypeManager.getAssetFileDataProducer(prefabDataAssetType).addAssetFormat(prefabFormat);
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) PrefabFormat(org.terasology.engine.entitySystem.prefab.internal.PrefabFormat) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with PrefabData

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

the class PojoEntityManagerTest method setup.

@BeforeEach
public void setup() {
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = (PojoEntityManager) context.get(EntityManager.class);
    PrefabData protoPrefab = new PrefabData();
    protoPrefab.addComponent(new StringComponent("Test"));
    prefab = Assets.generateAsset(new ResourceUrn("unittest:myprefab"), protoPrefab, Prefab.class);
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) NetworkSystem(org.terasology.engine.network.NetworkSystem) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with PrefabData

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

the class EntitySerializerTest method setup.

@BeforeEach
public void setup() {
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("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.engine.entitySystem.entity.internal.EngineEntityManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) NetworkSystem(org.terasology.engine.network.NetworkSystem) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) EntitySerializer(org.terasology.engine.persistence.serializers.EntitySerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PrefabData

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

the class EntityAwareWorldProviderTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    GameThread.setToCurrentThread();
    this.entityManager = context.get(EngineEntityManager.class);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    worldStub = new WorldProviderCoreStub(airBlock);
    worldProvider = new EntityAwareWorldProvider(worldStub, context);
    plainBlock = createBlock("test:plainblock", assetManager, blockManager);
    prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
    blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
    keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
    Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
    blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
    BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
    Iterator<Block> iterator = blockFamily.getBlocks().iterator();
    blockInFamilyOne = iterator.next();
    blockInFamilyTwo = iterator.next();
    PrefabData retainedPrefabData = new PrefabData();
    retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);
    blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
    worldProvider.initialise();
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.engine.world.block.BlockManager) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.engine.testUtil.WorldProviderCoreStub) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with PrefabData

use of org.terasology.engine.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.engine.entitySystem.prefab.PrefabData) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleContext(org.terasology.engine.core.module.ModuleContext) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

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