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());
}
}
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);
}
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;
}
}
}
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());
}
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));
}
Aggregations