Search in sources :

Example 1 with TempWorldGeneratorPluginLibrary

use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.

the class WorldPreGenerationScreen method setEnvironment.

/**
 * A function called before the screen comes to the forefront to setup the environment
 * and extract necessary objects from the new Context.
 *
 * @param subContext The new environment created in {@link UniverseSetupScreen}
 * @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
 */
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
    context = subContext;
    environment = context.get(ModuleEnvironment.class);
    context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
    worldList = context.get(UniverseSetupScreen.class).getWorldsList();
    selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
    worldNames = context.get(UniverseSetupScreen.class).worldNames();
    setWorldGenerators();
    worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
    final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
    worldsDropdown.setOptions(worldNames);
    genTexture();
    List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
    if (previewZones.isEmpty()) {
        previewGen = new FacetLayerPreview(environment, worldGenerator);
    }
}
Also used : MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UISlider(org.terasology.nui.widgets.UISlider) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Texture(org.terasology.engine.rendering.assets.texture.Texture) In(org.terasology.engine.registry.In) ModuleManager(org.terasology.engine.core.module.ModuleManager) LoggerFactory(org.slf4j.LoggerFactory) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) WidgetUtil(org.terasology.nui.WidgetUtil) ByteBuffer(java.nio.ByteBuffer) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) TeraMath(org.terasology.math.TeraMath) Binding(org.terasology.nui.databinding.Binding) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Logger(org.slf4j.Logger) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Assets(org.terasology.engine.utilities.Assets) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) NUIManager(org.terasology.engine.rendering.nui.NUIManager) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) UISliderOnChangeTriggeredListener(org.terasology.nui.widgets.UISliderOnChangeTriggeredListener) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Zone(org.terasology.engine.world.zones.Zone) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview)

Example 2 with TempWorldGeneratorPluginLibrary

use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.

the class WorldSetupScreen method setWorld.

/**
 * This method sets the world whose properties are to be changed. This function is called before the screen comes
 * to the forefront.
 *
 * @param subContext    the new environment created in {@link UniverseSetupScreen}
 * @param worldSelected the world whose configurations are to be changed.
 * @throws UnresolvedWorldGeneratorException
 */
public void setWorld(Context subContext, WorldSetupWrapper worldSelected, UIDropdownScrollable dropDown) throws UnresolvedWorldGeneratorException {
    world = worldSelected;
    context = subContext;
    worldsDropdown = dropDown;
    SimpleUri worldGenUri = worldSelected.getWorldGeneratorInfo().getUri();
    environment = context.get(ModuleEnvironment.class);
    context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
    if (world.getWorldGenerator() == null) {
        worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, context, environment);
        world.setWorldGenerator(worldGenerator);
    } else {
        worldGenerator = world.getWorldGenerator();
    }
    configureProperties();
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) SimpleUri(org.terasology.engine.core.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)

Example 3 with TempWorldGeneratorPluginLibrary

use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.

the class PreviewWorldScreen method setEnvironment.

public void setEnvironment() throws Exception {
    // TODO: pass world gen and module list directly rather than using the config
    SimpleUri worldGenUri = config.getWorldGeneration().getDefaultGenerator();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        subContext = new ContextImpl(context);
        CoreRegistry.setContext(subContext);
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        subContext.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, subContext));
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        environmentSwitchHandler.handleSwitchToPreviewEnvironment(subContext, environment);
        genTexture();
        worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, subContext, environment);
        worldGenerator.setWorldSeed(seed.getText());
        List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
        if (previewZones.isEmpty()) {
            zoneSelector.setVisible(false);
            previewGen = new FacetLayerPreview(environment, worldGenerator);
        } else {
            zoneSelector.setVisible(true);
            zoneSelector.setOptions(previewZones);
            zoneSelector.setSelection(previewZones.get(0));
        }
        configureProperties();
    } else {
        throw new UnresolvedDependencyException("Unable to resolve dependencies for " + worldGenUri);
    }
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Component(org.terasology.gestalt.entitysystem.component.Component) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ByteBuffer(java.nio.ByteBuffer) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) Map(java.util.Map) TeraMath(org.terasology.math.TeraMath) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) Property(org.terasology.nui.properties.Property) Binding(org.terasology.nui.databinding.Binding) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) NUIManager(org.terasology.engine.rendering.nui.NUIManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) CoreRegistry(org.terasology.engine.registry.CoreRegistry) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UIDropdown(org.terasology.nui.widgets.UIDropdown) UISlider(org.terasology.nui.widgets.UISlider) ModuleManager(org.terasology.engine.core.module.ModuleManager) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) PropertyProvider(org.terasology.nui.properties.PropertyProvider) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) PropertyOrdering(org.terasology.nui.properties.PropertyOrdering) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) Zone(org.terasology.engine.world.zones.Zone) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) ContextImpl(org.terasology.engine.context.internal.ContextImpl) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 4 with TempWorldGeneratorPluginLibrary

use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary 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

TempWorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)4 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 Lists (com.google.common.collect.Lists)2 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Config (org.terasology.engine.config.Config)2 Context (org.terasology.engine.context.Context)2 ContextImpl (org.terasology.engine.context.internal.ContextImpl)2 SimpleUri (org.terasology.engine.core.SimpleUri)2 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 In (org.terasology.engine.registry.In)2 Texture (org.terasology.engine.rendering.assets.texture.Texture)2 TextureData (org.terasology.engine.rendering.assets.texture.TextureData)2 CoreScreenLayer (org.terasology.engine.rendering.nui.CoreScreenLayer)2 NUIManager (org.terasology.engine.rendering.nui.NUIManager)2