Search in sources :

Example 11 with DependencyResolver

use of org.terasology.module.DependencyResolver 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.world.generator.UnresolvedWorldGeneratorException) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) DependencyResolver(org.terasology.module.DependencyResolver)

Example 12 with DependencyResolver

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

the class RegisterMods method step.

@Override
public boolean step() {
    if (applyModulesThread != null) {
        if (!applyModulesThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else {
        ModuleManager moduleManager = context.get(ModuleManager.class);
        List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(moduleIds);
        if (result.isSuccess()) {
            oldEnvironment = moduleManager.getEnvironment();
            ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
            for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
                logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
            }
            EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
            applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
            applyModulesThread.start();
            return false;
        } else {
            logger.warn("Missing at least one required module or dependency: {}", moduleIds);
            context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
            return true;
        }
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.modes.StateMainMenu) ResolutionResult(org.terasology.module.ResolutionResult) GameEngine(org.terasology.engine.GameEngine) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) Name(org.terasology.naming.Name) DependencyResolver(org.terasology.module.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler)

Example 13 with DependencyResolver

use of org.terasology.module.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()) {
        if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
            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.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleManager(org.terasology.engine.module.ModuleManager) FromModule(org.terasology.module.predicates.FromModule) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name)

Example 14 with DependencyResolver

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

the class ModuleDownloadListGeneratorTest method testResolverFailed.

@Test(expected = DependencyResolutionFailedException.class)
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);
    buildList(listGenerator);
}
Also used : TableModuleRegistry(org.terasology.module.TableModuleRegistry) ModuleRegistry(org.terasology.module.ModuleRegistry) DependencyResolver(org.terasology.module.DependencyResolver) Test(org.junit.Test)

Example 15 with DependencyResolver

use of org.terasology.module.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.module.TableModuleRegistry) ModuleRegistry(org.terasology.module.ModuleRegistry) BaseModule(org.terasology.module.BaseModule) Module(org.terasology.module.Module) DependencyResolver(org.terasology.module.DependencyResolver) Test(org.junit.Test)

Aggregations

DependencyResolver (org.terasology.module.DependencyResolver)16 ResolutionResult (org.terasology.module.ResolutionResult)11 Module (org.terasology.module.Module)10 ModuleEnvironment (org.terasology.module.ModuleEnvironment)9 ModuleManager (org.terasology.engine.module.ModuleManager)7 Name (org.terasology.naming.Name)7 ModuleRegistry (org.terasology.module.ModuleRegistry)5 Test (org.junit.Test)4 TableModuleRegistry (org.terasology.module.TableModuleRegistry)4 FromModule (org.terasology.module.predicates.FromModule)4 List (java.util.List)3 SimpleUri (org.terasology.engine.SimpleUri)3 HashSet (java.util.HashSet)2 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)2 Vector2i (org.terasology.math.geom.Vector2i)2 BaseModule (org.terasology.module.BaseModule)2 Canvas (org.terasology.rendering.nui.Canvas)2 ReadOnlyBinding (org.terasology.rendering.nui.databinding.ReadOnlyBinding)2 UIButton (org.terasology.rendering.nui.widgets.UIButton)2 UILabel (org.terasology.rendering.nui.widgets.UILabel)2