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);
}
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);
}
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);
}
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();
}
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());
}
}
Aggregations