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;
}
use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult 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.ResolutionResult in project Terasology by MovingBlocks.
the class ModuleDownloadListGenerator method getAllModulesToDownloadFor.
Set<Module> getAllModulesToDownloadFor(Name... modulesToInstall) throws DependencyResolutionFailedException {
Version currentEngineVersion = localRegistry.getLatestModuleVersion(TerasologyConstants.ENGINE_MODULE).getVersion();
ResolutionResult resolutionResult = remoteDependencyResolver.builder().requireVersion(TerasologyConstants.ENGINE_MODULE, currentEngineVersion).requireAll(modulesToInstall).build();
return processResolutionResult(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;
}
use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult 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());
}
Aggregations