Search in sources :

Example 11 with ResolutionResult

use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult in project Terasology by MovingBlocks.

the class UniverseSetupScreen method setEnvironment.

/**
 * This method switches the environment of the game to a temporary one needed for
 * creating a game. It creates a new {@link Context} and only puts the minimum classes
 * needed for successful game creation.
 * @param wrapper takes the {@link AdvancedGameSetupScreen} and pushes it into the new context.
 */
public void setEnvironment(UniverseWrapper wrapper) {
    context = new ContextImpl();
    CoreRegistry.setContext(context);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    context.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    context.put(NUIManager.class, getManager());
    context.put(UniverseSetupScreen.class, this);
    assetTypeManager = new AutoReloadAssetTypeManager();
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    context.put(ModuleManager.class, moduleManager);
    context.put(UniverseWrapper.class, wrapper);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        context.put(ModuleEnvironment.class, environment);
        context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
        initAssets();
        EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
        context.put(EnvironmentSwitchHandler.class, environmentSwitcher);
        environmentSwitcher.handleSwitchToPreviewEnvironment(context, environment);
    }
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Aggregations

ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)11 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)10 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)6 ModuleManager (org.terasology.engine.core.module.ModuleManager)5 Module (org.terasology.gestalt.module.Module)5 SimpleUri (org.terasology.engine.core.SimpleUri)4 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)3 Name (org.terasology.gestalt.naming.Name)3 ContextImpl (org.terasology.engine.context.internal.ContextImpl)2 UnresolvedWorldGeneratorException (org.terasology.engine.world.generator.UnresolvedWorldGeneratorException)2 TempWorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)2 Lists (com.google.common.collect.Lists)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1