Search in sources :

Example 21 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class PojoEntityPoolTest method setupClass.

@BeforeAll
public static void setupClass() throws Exception {
    context = new ContextImpl();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 22 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl 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 23 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl 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)

Example 24 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class NUIManagerInternal method initialiseControlWidget.

private <T extends ControlWidget> void initialiseControlWidget(T overlay, ResourceUrn screenUri) {
    ContextImpl timedContextForModulesWidgets = new ContextImpl(this.context);
    Module declaringModule = moduleEnvironment.get(screenUri.getModuleName());
    TypeWidgetLibrary moduleLibrary = new TypeWidgetLibraryImpl(typeWidgetFactoryRegistry, declaringModule, this.context);
    context.put(TypeWidgetLibrary.class, moduleLibrary);
    InjectionHelper.inject(overlay, timedContextForModulesWidgets);
    overlay.initialise();
}
Also used : TypeWidgetLibrary(org.terasology.nui.widgets.types.TypeWidgetLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Module(org.terasology.gestalt.module.Module)

Example 25 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl 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)

Aggregations

ContextImpl (org.terasology.engine.context.internal.ContextImpl)26 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)8 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)8 Context (org.terasology.engine.context.Context)7 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)7 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)6 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)6 BeforeAll (org.junit.jupiter.api.BeforeAll)5 Test (org.junit.jupiter.api.Test)4 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)4 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)4 Reflections (org.reflections.Reflections)3 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)3 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)3 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)3 Config (org.terasology.engine.config.Config)2 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2