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 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 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);
}
}
}
}
use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult in project Terasology by MovingBlocks.
the class ModuleManager method resolveAndLoadEnvironment.
public void resolveAndLoadEnvironment(Iterable<Name> modules) {
DependencyResolver resolver = new DependencyResolver(registry);
ResolutionResult result = resolver.resolve(modules);
if (!result.isSuccess()) {
// TODO: worth its own exception class?
throw new RuntimeException("Failed to resolve dependencies for " + modules);
}
loadEnvironment(result.getModules(), true);
}
use of org.terasology.gestalt.module.dependencyresolution.ResolutionResult in project Terasology by MovingBlocks.
the class PreviewWorldScreen method setEnvironment.
public void setEnvironment() throws Exception {
// TODO: pass world gen and module list directly rather than using the config
SimpleUri worldGenUri = config.getWorldGeneration().getDefaultGenerator();
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (result.isSuccess()) {
subContext = new ContextImpl(context);
CoreRegistry.setContext(subContext);
environment = moduleManager.loadEnvironment(result.getModules(), false);
subContext.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, subContext));
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
environmentSwitchHandler.handleSwitchToPreviewEnvironment(subContext, environment);
genTexture();
worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, subContext, environment);
worldGenerator.setWorldSeed(seed.getText());
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
zoneSelector.setVisible(false);
previewGen = new FacetLayerPreview(environment, worldGenerator);
} else {
zoneSelector.setVisible(true);
zoneSelector.setOptions(previewZones);
zoneSelector.setSelection(previewZones.get(0));
}
configureProperties();
} else {
throw new UnresolvedDependencyException("Unable to resolve dependencies for " + worldGenUri);
}
}
Aggregations