Search in sources :

Example 6 with DependencyResolver

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

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

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

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

the class ModuleDownloadListGeneratorTest method testResolverFailed.

@Test
public void testResolverFailed() throws DependencyResolutionFailedException {
    ModuleRegistry localRegistry = buildRegistry("1.0.0", buildSimpleModule("myModule", "1.0.0"));
    DependencyResolver resolver = mockResolver(false);
    ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
    Assertions.assertThrows(DependencyResolutionFailedException.class, () -> buildList(listGenerator));
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 10 with DependencyResolver

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

the class ModuleDownloadListGeneratorTest method testMultipleModulesPartialUpdate.

@Test
public void testMultipleModulesPartialUpdate() throws DependencyResolutionFailedException {
    Module moduleAV1 = buildSimpleModule("myModuleA", "1.0.0");
    Module moduleBV1 = buildSimpleModule("myModuleB", "1.0.0");
    Module moduleBV2 = buildSimpleModule("myModuleB", "2.0.0");
    ModuleRegistry localRegistry = buildRegistry("1.0.0", moduleAV1, moduleBV1);
    DependencyResolver resolver = mockResolver(true, moduleBV1, moduleBV2, buildEngineModule("1.0.0"));
    ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
    assertEquals(Collections.singleton(moduleBV2), buildList(listGenerator));
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) Module(org.terasology.gestalt.module.Module) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Test(org.junit.jupiter.api.Test)

Aggregations

DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)15 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)11 Module (org.terasology.gestalt.module.Module)8 ModuleManager (org.terasology.engine.core.module.ModuleManager)6 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)6 SimpleUri (org.terasology.engine.core.SimpleUri)5 Name (org.terasology.gestalt.naming.Name)5 Test (org.junit.jupiter.api.Test)4 ModuleRegistry (org.terasology.gestalt.module.ModuleRegistry)4 TableModuleRegistry (org.terasology.gestalt.module.TableModuleRegistry)4 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)3 UIButton (org.terasology.nui.widgets.UIButton)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Config (org.terasology.engine.config.Config)2