use of org.terasology.engine.context.Context 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.context.Context in project Terasology by MovingBlocks.
the class InputSystemTests method setUp.
@BeforeEach
public void setUp() {
Context context = new ContextImpl();
setUpLocalPlayer(context);
setUpDisplayDevice(context);
setUpBindsManager(context);
setUpTargetSystem(context);
context.put(Time.class, new TimeSystem());
inputSystem = new InputSystem();
InjectionHelper.inject(inputSystem, context);
testKeyboard = new TestKeyboard();
inputSystem.setKeyboardDevice(testKeyboard);
clientEntityKeyEvents = new ArrayList<>();
characterEntityKeyEvents = new ArrayList<>();
}
use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class InjectionHelperTest method testDefaultConstructorInjection.
@Test
public void testDefaultConstructorInjection() {
Context context = new ContextImpl();
context.put(ServiceA.class, serviceA);
context.put(ServiceB.class, serviceB);
ConstructorAB constructorAB = InjectionHelper.createWithConstructorInjection(ConstructorAB.class, context);
// the two-arg constructor should be used as it has the most parameters and all can be populated
assertEquals(constructorAB.getServiceA(), serviceA);
assertEquals(constructorAB.getServiceB(), serviceB);
}
use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulatedFallback.
@SuppressWarnings("checkstyle:LocalVariableName")
@Test
public void testConstructorInjectionNotAllParametersPopulatedFallback() {
Context context = new ContextImpl();
context.put(ServiceA.class, serviceA);
// context.put(ServiceB.class, serviceB);
ConstructorA_AB constructorA_AB = InjectionHelper.createWithConstructorInjection(ConstructorA_AB.class, context);
// the one-arg constructor is used as it can be populated with serviceA which is available
assertEquals(constructorA_AB.getServiceA(), serviceA);
assertNull(constructorA_AB.getServiceB());
}
Aggregations