Search in sources :

Example 1 with UnresolvedWorldGeneratorException

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

the class WorldPreGenerationScreen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    try {
        if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
            worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment);
            findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
        } else {
            worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
        }
        if (worldGenerator.getWorldSeed().isEmpty()) {
            worldGenerator.setWorldSeed(createSeed(selectedWorld));
        }
        previewGen = new FacetLayerPreview(environment, worldGenerator);
        updatePreview();
    } catch (UnresolvedWorldGeneratorException e) {
        e.printStackTrace();
    }
}
Also used : UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview)

Example 2 with UnresolvedWorldGeneratorException

use of org.terasology.engine.world.generator.UnresolvedWorldGeneratorException 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 3 with UnresolvedWorldGeneratorException

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

the class WorldPreGenerationScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    zoomSlider = find("zoomSlider", UISlider.class);
    if (zoomSlider != null) {
        zoomSlider.setValue(2f);
        zoomSlider.setUiSliderOnChangeTriggeredListener(this);
    }
    final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
    worldsDropdown.bindSelection(new Binding<String>() {

        @Override
        public String get() {
            return selectedWorld;
        }

        @Override
        public void set(String value) {
            selectedWorld = value;
            try {
                if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
                    worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment);
                    findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
                } else {
                    worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
                }
                if (worldGenerator.getWorldSeed() == null) {
                    worldGenerator.setWorldSeed(createSeed(selectedWorld));
                }
                previewGen = new FacetLayerPreview(environment, worldGenerator);
                updatePreview();
            } catch (UnresolvedWorldGeneratorException e) {
                e.printStackTrace();
            }
        }
    });
    WidgetUtil.trySubscribe(this, "reRoll", button -> {
        worldGenerator.setWorldSeed(createSeed(selectedWorld));
        updatePreview();
    });
    StartPlayingScreen startPlayingScreen = getManager().createScreen(StartPlayingScreen.ASSET_URI, StartPlayingScreen.class);
    WidgetUtil.trySubscribe(this, "continue", button -> {
        startPlayingScreen.setTargetWorld(worldList, findWorldByName(selectedWorld), texture, context);
        triggerForwardAnimation(startPlayingScreen);
    });
    WorldSetupScreen worldSetupScreen = getManager().createScreen(WorldSetupScreen.ASSET_URI, WorldSetupScreen.class);
    WidgetUtil.trySubscribe(this, "config", button -> {
        try {
            if (!selectedWorld.isEmpty()) {
                worldSetupScreen.setWorld(context, findWorldByName(selectedWorld), worldsDropdown);
                triggerForwardAnimation(worldSetupScreen);
            } else {
                getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
            }
        } catch (UnresolvedWorldGeneratorException e) {
            e.printStackTrace();
        }
    });
    WidgetUtil.trySubscribe(this, "close", button -> {
        final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
        UIDropdownScrollable worldsDropdownOfUniverse = universeSetupScreen.find("worlds", UIDropdownScrollable.class);
        universeSetupScreen.refreshWorldDropdown(worldsDropdownOfUniverse);
        triggerBackAnimation();
    });
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
}
Also used : UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) UISlider(org.terasology.nui.widgets.UISlider) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview)

Example 4 with UnresolvedWorldGeneratorException

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

the class WorldGeneratorManager method createGenerator.

/**
 * @param uri uri of the world generator to create.
 * @param context objects from this context will be injected into the
 * @return The instantiated world generator.
 */
public static WorldGenerator createGenerator(SimpleUri uri, Context context) throws UnresolvedWorldGeneratorException {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    Module module = moduleManager.getEnvironment().get(uri.getModuleName());
    if (module == null) {
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(uri.getModuleName());
        if (!result.isSuccess()) {
            if (moduleManager.getRegistry().getLatestModuleVersion(uri.getModuleName()) == null) {
                throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
            } else {
                throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - unable to resolve module dependencies");
            }
        }
        try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
            return createWorldGenerator(uri, context, environment);
        }
    } else {
        return createWorldGenerator(uri, context, moduleManager.getEnvironment());
    }
}
Also used : UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 5 with UnresolvedWorldGeneratorException

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

the class WorldGeneratorManager method createWorldGenerator.

/**
 * @param uri uri of the world generator to create.
 * @param context that will be used to inject teh world generator.
 * @param environment to be searched for the world generator class.
 * @return a new world generator with the specified uri.
 */
public static WorldGenerator createWorldGenerator(SimpleUri uri, Context context, ModuleEnvironment environment) throws UnresolvedWorldGeneratorException {
    for (Class<?> generatorClass : environment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) {
        RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class);
        Name moduleName = environment.getModuleProviding(generatorClass);
        if (moduleName == null) {
            throw new UnresolvedWorldGeneratorException("Cannot find module for world generator " + generatorClass);
        }
        SimpleUri generatorUri = new SimpleUri(moduleName, annotation.id());
        if (generatorUri.equals(uri)) {
            WorldGenerator worldGenerator = loadGenerator(generatorClass, generatorUri);
            InjectionHelper.inject(worldGenerator, context);
            return worldGenerator;
        }
    }
    throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
}
Also used : RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) SimpleUri(org.terasology.engine.core.SimpleUri) Name(org.terasology.gestalt.naming.Name)

Aggregations

UnresolvedWorldGeneratorException (org.terasology.engine.world.generator.UnresolvedWorldGeneratorException)7 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 FacetLayerPreview (org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview)3 WorldGenerator (org.terasology.engine.world.generator.WorldGenerator)3 List (java.util.List)2 WorldGeneratorManager (org.terasology.engine.world.generator.internal.WorldGeneratorManager)2 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)2 UIDropdownScrollable (org.terasology.nui.widgets.UIDropdownScrollable)2 UISlider (org.terasology.nui.widgets.UISlider)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Config (org.terasology.engine.config.Config)1