Search in sources :

Example 6 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class PojoEventSystemTests method setup.

@Before
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);
    TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies);
    EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
    compLibrary = entitySystemLibrary.getComponentLibrary();
    entityManager = new PojoEntityManager();
    entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
    entityManager.setPrefabManager(new PojoPrefabManager(context));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    eventSystem = new EventSystemImpl(entitySystemLibrary.getEventLibrary(), networkSystem);
    entityManager.setEventSystem(eventSystem);
    entity = entityManager.create();
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) NetworkSystem(org.terasology.network.NetworkSystem) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) ContextImpl(org.terasology.context.internal.ContextImpl) EventSystemImpl(org.terasology.entitySystem.event.internal.EventSystemImpl) Before(org.junit.Before)

Example 7 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary 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 TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupBlockManager.

@Override
protected void setupBlockManager(AssetManager assetManager) {
    WorldAtlas worldAtlas = new NullWorldAtlas();
    BlockManagerImpl blockManager = new BlockManagerImpl(worldAtlas, assetManager);
    context.put(BlockManager.class, blockManager);
    TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
    typeSerializationLibrary.add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
    typeSerializationLibrary.add(Block.class, new BlockTypeHandler(blockManager));
}
Also used : NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) BlockTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockTypeHandler) WorldAtlas(org.terasology.world.block.tiles.WorldAtlas) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) BlockFamilyTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockFamilyTypeHandler)

Example 9 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class UIFormat method load.

public UIData load(JsonElement element, Locale otherLocale) throws IOException {
    NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
    TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
    TypeSerializationLibrary library = new TypeSerializationLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
    library.add(UISkin.class, new AssetTypeHandler<>(UISkin.class));
    library.add(Border.class, new BorderTypeHandler());
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
    for (Class<?> handledType : library.getCoreTypes()) {
        gsonBuilder.registerTypeAdapter(handledType, new JsonTypeHandlerAdapter<>(library.getHandlerFor(handledType)));
    }
    // override the String TypeAdapter from the serialization library
    gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
    Gson gson = gsonBuilder.create();
    return gson.fromJson(element, UIData.class);
}
Also used : TranslationSystem(org.terasology.i18n.TranslationSystem) GsonBuilder(com.google.gson.GsonBuilder) UISkin(org.terasology.rendering.nui.skin.UISkin) Gson(com.google.gson.Gson) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) BorderTypeHandler(org.terasology.persistence.typeHandling.mathTypes.BorderTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) NUIManager(org.terasology.rendering.nui.NUIManager)

Example 10 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class TerasologyEngine method initManagers.

private void initManagers() {
    changeStatus(TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER);
    ModuleManager moduleManager = new ModuleManagerImpl(rootContext.get(Config.class));
    rootContext.put(ModuleManager.class, moduleManager);
    changeStatus(TerasologyEngineStatus.INITIALIZING_LOWLEVEL_OBJECT_MANIPULATION);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    rootContext.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    rootContext.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    rootContext.put(TypeSerializationLibrary.class, new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));
    changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_TYPES);
    assetTypeManager = new ModuleAwareAssetTypeManager();
    rootContext.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    rootContext.put(AssetManager.class, assetTypeManager.getAssetManager());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ModuleManagerImpl(org.terasology.engine.module.ModuleManagerImpl) Config(org.terasology.config.Config) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) ModuleManager(org.terasology.engine.module.ModuleManager)

Aggregations

TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)13 ModuleManager (org.terasology.engine.module.ModuleManager)5 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)5 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)5 Before (org.junit.Before)4 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)4 ContextImpl (org.terasology.context.internal.ContextImpl)4 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.network.NetworkSystem)4 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)4 ReflectionReflectFactory (org.terasology.reflection.reflect.ReflectionReflectFactory)4 SimpleUri (org.terasology.engine.SimpleUri)3 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)3 Test (org.junit.Test)2 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)2 EventSystemImpl (org.terasology.entitySystem.event.internal.EventSystemImpl)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 PrefabData (org.terasology.entitySystem.prefab.PrefabData)2 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)2 PrefabFormat (org.terasology.entitySystem.prefab.internal.PrefabFormat)2