Search in sources :

Example 11 with Context

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);
    }
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Component(org.terasology.gestalt.entitysystem.component.Component) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ByteBuffer(java.nio.ByteBuffer) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) Map(java.util.Map) TeraMath(org.terasology.math.TeraMath) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) Property(org.terasology.nui.properties.Property) Binding(org.terasology.nui.databinding.Binding) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) NUIManager(org.terasology.engine.rendering.nui.NUIManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) CoreRegistry(org.terasology.engine.registry.CoreRegistry) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UIDropdown(org.terasology.nui.widgets.UIDropdown) UISlider(org.terasology.nui.widgets.UISlider) ModuleManager(org.terasology.engine.core.module.ModuleManager) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) PropertyProvider(org.terasology.nui.properties.PropertyProvider) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) PropertyOrdering(org.terasology.nui.properties.PropertyOrdering) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) Zone(org.terasology.engine.world.zones.Zone) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) ContextImpl(org.terasology.engine.context.internal.ContextImpl) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 12 with Context

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<>();
}
Also used : Context(org.terasology.engine.context.Context) InputSystem(org.terasology.engine.input.InputSystem) ContextImpl(org.terasology.engine.context.internal.ContextImpl) TimeSystem(org.terasology.engine.core.subsystem.headless.device.TimeSystem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with Context

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);
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Example 14 with Context

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());
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Aggregations

Context (org.terasology.engine.context.Context)14 ContextImpl (org.terasology.engine.context.internal.ContextImpl)7 Test (org.junit.jupiter.api.Test)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Lists (com.google.common.collect.Lists)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Config (org.terasology.engine.config.Config)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 DisplayDevice (org.terasology.engine.core.subsystem.DisplayDevice)2 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)2 In (org.terasology.engine.registry.In)2 Texture (org.terasology.engine.rendering.assets.texture.Texture)2 TextureData (org.terasology.engine.rendering.assets.texture.TextureData)2 CoreScreenLayer (org.terasology.engine.rendering.nui.CoreScreenLayer)2