Search in sources :

Example 1 with DependencyResolver

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

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

the class WorldGeneratorManager method refresh.

public void refresh() {
    ModuleManager moduleManager = verifyNotNull(context.get(ModuleManager.class), "no ModuleManager");
    List<WorldGeneratorInfo> infos = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult resolutionResult = resolver.resolve(module.getId());
        if (resolutionResult.isSuccess()) {
            try (ModuleEnvironment tempEnvironment = moduleManager.loadEnvironment(resolutionResult.getModules(), false)) {
                for (Class<?> generatorClass : tempEnvironment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) {
                    if (tempEnvironment.getModuleProviding(generatorClass).equals(module.getId())) {
                        RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class);
                        if (isValidWorldGenerator(generatorClass)) {
                            SimpleUri uri = new SimpleUri(moduleId, annotation.id());
                            infos.add(new WorldGeneratorInfo(uri, annotation.displayName(), annotation.description()));
                        } else {
                            logger.error("{} marked to be registered as a World Generator, " + "but is not a subclass of WorldGenerator or lacks the correct constructor", generatorClass);
                        }
                    }
                }
            } catch (Exception e) {
                logger.error("Error loading world generator in module {}, skipping", module.getId(), e);
            }
        } else {
            logger.warn("Could not resolve dependencies for module: {}", module);
        }
    }
    Collections.sort(infos);
    generatorInfo = ImmutableList.copyOf(infos);
}
Also used : RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 3 with DependencyResolver

use of org.terasology.gestalt.module.dependencyresolution.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) from the following list: {}", moduleIds);
            context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
            return true;
        }
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 4 with DependencyResolver

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = find("main", ColumnLayout.class);
    UIButton azerty = find("azerty", UIButton.class);
    if (azerty != null) {
        azerty.subscribe(event -> {
            BindCommands.AZERTY.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton dvorak = find("dvorak", UIButton.class);
    if (dvorak != null) {
        dvorak.subscribe(event -> {
            BindCommands.DVORAK.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton neo = find("neo", UIButton.class);
    if (neo != null) {
        neo.subscribe(event -> {
            BindCommands.NEO.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    if (mainLayout != null) {
        mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    }
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                    InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                    inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                }
                for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                    if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                        RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                        inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                    }
                }
            }
        }
    }
    if (mainLayout != null) {
        addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
        for (InputCategory category : inputCategories.values()) {
            addInputSection(category, mainLayout, inputsById);
        }
        mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
        List<String> controllers = inputSystem.getControllerDevice().getControllers();
        for (String name : controllers) {
            ControllerInfo cfg = inputDeviceConfiguration.getController(name);
            addInputSection(mainLayout, name, cfg);
        }
    }
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISlider(org.terasology.nui.widgets.UISlider) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) UICheckbox(org.terasology.nui.widgets.UICheckbox) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIButton(org.terasology.nui.widgets.UIButton) RowLayout(org.terasology.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) FromModule(org.terasology.gestalt.module.predicates.FromModule) Module(org.terasology.gestalt.module.Module) FromModule(org.terasology.gestalt.module.predicates.FromModule) ControllerInfo(org.terasology.engine.config.ControllerConfig.ControllerInfo)

Example 5 with DependencyResolver

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

the class ModuleDownloadListGeneratorTest method testSingleModuleNoUpdate.

@Test
public void testSingleModuleNoUpdate() throws DependencyResolutionFailedException {
    ModuleRegistry localRegistry = buildRegistry("1.0.0", buildSimpleModule("myModule", "1.0.0"));
    DependencyResolver resolver = mockResolver(true, buildSimpleModule("myModule", "1.0.0"), buildEngineModule("1.0.0"));
    ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
    assertEquals(Collections.emptySet(), 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)

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