use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method setEnvironment.
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
*
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
context = subContext;
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
worldList = context.get(UniverseSetupScreen.class).getWorldsList();
selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
worldNames = context.get(UniverseSetupScreen.class).worldNames();
setWorldGenerators();
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.setOptions(worldNames);
genTexture();
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
}
}
use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.
the class WorldSetupScreen method setWorld.
/**
* This method sets the world whose properties are to be changed. This function is called before the screen comes
* to the forefront.
*
* @param subContext the new environment created in {@link UniverseSetupScreen}
* @param worldSelected the world whose configurations are to be changed.
* @throws UnresolvedWorldGeneratorException
*/
public void setWorld(Context subContext, WorldSetupWrapper worldSelected, UIDropdownScrollable dropDown) throws UnresolvedWorldGeneratorException {
world = worldSelected;
context = subContext;
worldsDropdown = dropDown;
SimpleUri worldGenUri = worldSelected.getWorldGeneratorInfo().getUri();
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
if (world.getWorldGenerator() == null) {
worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, context, environment);
world.setWorldGenerator(worldGenerator);
} else {
worldGenerator = world.getWorldGenerator();
}
configureProperties();
}
use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary 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);
}
}
use of org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary in project Terasology by MovingBlocks.
the class UniverseSetupScreen method setEnvironment.
/**
* This method switches the environment of the game to a temporary one needed for
* creating a game. It creates a new {@link Context} and only puts the minimum classes
* needed for successful game creation.
* @param wrapper takes the {@link AdvancedGameSetupScreen} and pushes it into the new context.
*/
public void setEnvironment(UniverseWrapper wrapper) {
context = new ContextImpl();
CoreRegistry.setContext(context);
ReflectFactory reflectFactory = new ReflectionReflectFactory();
context.put(ReflectFactory.class, reflectFactory);
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
context.put(NUIManager.class, getManager());
context.put(UniverseSetupScreen.class, this);
assetTypeManager = new AutoReloadAssetTypeManager();
context.put(AssetManager.class, assetTypeManager.getAssetManager());
context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
context.put(ModuleManager.class, moduleManager);
context.put(UniverseWrapper.class, wrapper);
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (result.isSuccess()) {
environment = moduleManager.loadEnvironment(result.getModules(), false);
context.put(ModuleEnvironment.class, environment);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
initAssets();
EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
context.put(EnvironmentSwitchHandler.class, environmentSwitcher);
environmentSwitcher.handleSwitchToPreviewEnvironment(context, environment);
}
}
Aggregations