Search in sources :

Example 6 with EnvironmentSwitchHandler

use of org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler 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

EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)6 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)3 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)3 Map (java.util.Map)2 ContextImpl (org.terasology.engine.context.internal.ContextImpl)2 GameEngine (org.terasology.engine.core.GameEngine)2 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)2 WorldConfigurator (org.terasology.engine.world.generator.WorldConfigurator)2 TempWorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 Module (org.terasology.gestalt.module.Module)2 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)2 Stopwatch (com.google.common.base.Stopwatch)1 Lists (com.google.common.collect.Lists)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1