Search in sources :

Example 6 with ResolutionResult

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

the class ModuleDownloadListGeneratorTest method mockResolver.

private DependencyResolver mockResolver(boolean success, Module... resolutionResult) {
    DependencyResolver result = mock(DependencyResolver.class);
    DependencyResolver.ResolutionBuilder builder = mock(DependencyResolver.ResolutionBuilder.class);
    when(builder.requireVersion(any(), any())).thenReturn(builder);
    when(builder.requireAll(any(Name[].class))).thenReturn(builder);
    when(builder.build()).thenReturn(new ResolutionResult(success, new HashSet<>(Arrays.asList(resolutionResult))));
    when(result.builder()).thenReturn(builder);
    return result;
}
Also used : ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) HashSet(java.util.HashSet)

Example 7 with ResolutionResult

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

the class GameManifestProvider method createGameManifest.

/**
 * Generates game manifest with default settings (title, seed) if not specified.
 * Uses default world generator, and modules selection.
 * @TODO: rewrite/fix it when code will be more stable
 *
 * @param universeWrapper  contains the universe level properties
 * @param moduleManager    resolves modules
 * @param config           provides default module selection, world generator
 * @return                 game manifest with default settings
 */
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
    GameManifest gameManifest = new GameManifest();
    if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
        gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
    } else {
        gameManifest.setTitle(GameProvider.getNextGameName());
    }
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (!result.isSuccess()) {
        logger.error("Can't resolve dependencies");
        return null;
    }
    for (Module module : result.getModules()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    SimpleUri uri;
    String seed;
    WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
    if (worldSetup != null) {
        uri = worldSetup.getWorldGenerator().getUri();
        seed = worldSetup.getWorldGenerator().getWorldSeed();
    } else {
        uri = config.getWorldGeneration().getDefaultGenerator();
        seed = universeWrapper.getSeed();
    }
    gameManifest.setSeed(seed);
    String targetWorldName = "";
    Map<String, Component> worldConfig = Maps.newHashMap();
    if (worldSetup != null) {
        targetWorldName = worldSetup.getWorldName().toString();
        if (worldSetup.getWorldConfigurator() != null) {
            // horrible hack to get configs into manifest.
            // config driven by CreateWorldEntity.
            // world config set somewhere else as well no clear drive from config --> world
            gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
        }
    }
    // This is multiplied by the number of seconds in a day (86400000) to determine the exact  millisecond at which the game will start.
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
    gameManifest.addWorld(worldInfo);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 8 with ResolutionResult

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

the class BindsSubsystem method updateDefaultBinds.

private void updateDefaultBinds(Context passedContext, BindsConfiguration config) {
    ModuleManager moduleManager = passedContext.get(ModuleManager.class);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                FromModule filter = new FromModule(environment, moduleId);
                Iterable<Class<?>> buttons = environment.getTypesAnnotatedWith(RegisterBindButton.class, filter);
                Iterable<Class<?>> axes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class, filter);
                addButtonDefaultsFor(moduleId, buttons, config);
                addAxisDefaultsFor(moduleId, axes, config);
            }
        }
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleManager(org.terasology.engine.core.module.ModuleManager) FromModule(org.terasology.gestalt.module.predicates.FromModule) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name)

Example 9 with ResolutionResult

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

the class ModuleManager method resolveAndLoadEnvironment.

public void resolveAndLoadEnvironment(Iterable<Name> modules) {
    DependencyResolver resolver = new DependencyResolver(registry);
    ResolutionResult result = resolver.resolve(modules);
    if (!result.isSuccess()) {
        // TODO: worth its own exception class?
        throw new RuntimeException("Failed to resolve dependencies for " + modules);
    }
    loadEnvironment(result.getModules(), true);
}
Also used : ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 10 with ResolutionResult

use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult 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)

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