Search in sources :

Example 6 with PrefabData

use of org.terasology.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"));
    Prefab prefab = 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.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) Test(org.junit.Test)

Example 7 with PrefabData

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

the class PrefabTest method setup.

@Before
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
    assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
    ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
    TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
    PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary);
    assetTypeManager.registerCoreFormat(Prefab.class, 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 : PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) NetworkSystem(org.terasology.network.NetworkSystem) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) PrefabFormat(org.terasology.entitySystem.prefab.internal.PrefabFormat) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) 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) Before(org.junit.Before)

Example 8 with PrefabData

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

the class TerasologyEngine method initAssets.

private void initAssets() {
    DefaultBlockFamilyFactoryRegistry familyFactoryRegistry = new DefaultBlockFamilyFactoryRegistry();
    rootContext.put(BlockFamilyFactoryRegistry.class, familyFactoryRegistry);
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, false, "prefabs");
    assetTypeManager.registerCoreAssetType(BlockShape.class, (AssetFactory<BlockShape, BlockShapeData>) BlockShapeImpl::new, "shapes");
    assetTypeManager.registerCoreAssetType(BlockSounds.class, (AssetFactory<BlockSounds, BlockSoundsData>) BlockSounds::new, "blockSounds");
    assetTypeManager.registerCoreAssetType(BlockTile.class, (AssetFactory<BlockTile, TileData>) BlockTile::new, "blockTiles");
    assetTypeManager.registerCoreAssetType(BlockFamilyDefinition.class, (AssetFactory<BlockFamilyDefinition, BlockFamilyDefinitionData>) BlockFamilyDefinition::new, "blocks");
    assetTypeManager.registerCoreFormat(BlockFamilyDefinition.class, new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager(), familyFactoryRegistry));
    assetTypeManager.registerCoreAssetType(UISkin.class, (AssetFactory<UISkin, UISkinData>) UISkin::new, "skins");
    assetTypeManager.registerCoreAssetType(BehaviorTree.class, (AssetFactory<BehaviorTree, BehaviorTreeData>) BehaviorTree::new, false, "behaviors");
    assetTypeManager.registerCoreAssetType(UIElement.class, (AssetFactory<UIElement, UIData>) UIElement::new, "ui");
    for (EngineSubsystem subsystem : allSubsystems) {
        subsystem.registerCoreAssetTypes(assetTypeManager);
    }
}
Also used : UIElement(org.terasology.rendering.nui.asset.UIElement) PrefabData(org.terasology.entitySystem.prefab.PrefabData) BehaviorTreeData(org.terasology.logic.behavior.asset.BehaviorTreeData) BlockShape(org.terasology.world.block.shapes.BlockShape) BlockFamilyDefinitionFormat(org.terasology.world.block.loader.BlockFamilyDefinitionFormat) UISkin(org.terasology.rendering.nui.skin.UISkin) UISkinData(org.terasology.rendering.nui.skin.UISkinData) BlockTile(org.terasology.world.block.tiles.BlockTile) DefaultBlockFamilyFactoryRegistry(org.terasology.world.block.family.DefaultBlockFamilyFactoryRegistry) BehaviorTree(org.terasology.logic.behavior.asset.BehaviorTree) BlockShapeData(org.terasology.world.block.shapes.BlockShapeData) UIData(org.terasology.rendering.nui.asset.UIData) BlockSounds(org.terasology.world.block.sounds.BlockSounds) BlockSoundsData(org.terasology.world.block.sounds.BlockSoundsData) TileData(org.terasology.world.block.tiles.TileData) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab)

Example 9 with PrefabData

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

the class EntitySerializerTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    context = new ContextImpl();
    CoreRegistry.setContext(context);
    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());
}
Also used : PrefabData(org.terasology.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) ContextImpl(org.terasology.context.internal.ContextImpl) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) BeforeClass(org.junit.BeforeClass)

Example 10 with PrefabData

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

the class EntityAwareWorldProviderTest method setup.

@Before
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, null);
    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.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.assets.management.AssetManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.entitySystem.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.world.block.BlockManager) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.testUtil.WorldProviderCoreStub) Before(org.junit.Before)

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