Search in sources :

Example 6 with Context

use of org.terasology.context.Context in project Terasology by MovingBlocks.

the class VisualCharacterSystemTest method setup.

@Before
public void setup() throws Exception {
    this.system = new VisualCharacterSystem();
    Context context = new ContextImpl();
    this.localPlayer = Mockito.mock(LocalPlayer.class);
    context.put(LocalPlayer.class, localPlayer);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return clientEntityReturnedByLocalPlayer;
        }
    }).when(localPlayer).getClientEntity();
    this.entityManager = Mockito.mock(EntityManager.class);
    Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
    context.put(EntityManager.class, this.entityManager);
    InjectionHelper.inject(system, context);
    system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
Also used : Context(org.terasology.context.Context) Answer(org.mockito.stubbing.Answer) EntityManager(org.terasology.entitySystem.entity.EntityManager) LocalPlayer(org.terasology.logic.players.LocalPlayer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) ContextImpl(org.terasology.context.internal.ContextImpl) EntityRef(org.terasology.entitySystem.entity.EntityRef) Before(org.junit.Before)

Example 7 with Context

use of org.terasology.context.Context in project Terasology by MovingBlocks.

the class ComponentSystemManagerTest method setUp.

@Before
public void setUp() {
    Context context = mock(Context.class);
    EntityManager entityManager = mock(EntityManager.class);
    when(entityManager.getEventSystem()).thenReturn(mock(EventSystem.class));
    when(context.get(EntityManager.class)).thenReturn(entityManager);
    console = mock(Console.class);
    when(context.get(Console.class)).thenReturn(console);
    systemUnderTest = new ComponentSystemManager(context);
}
Also used : Context(org.terasology.context.Context) EntityManager(org.terasology.entitySystem.entity.EntityManager) Console(org.terasology.logic.console.Console) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) Before(org.junit.Before)

Example 8 with Context

use of org.terasology.context.Context in project Terasology by MovingBlocks.

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * @param bindingMap the binding map.
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(Map<String, Boolean> bindingMap) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (bindingMap.containsKey(fieldNameWithID)) {
            if (bindingMap.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 9 with Context

use of org.terasology.context.Context in project Terasology by MovingBlocks.

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * This method could be used in module since {@link org.terasology.config.facade.TelemetryConfiguration} is exposed to modules
 * @param telemetryConfiguration the telemetry configuration exposed modules
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(TelemetryConfiguration telemetryConfiguration) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (telemetryConfiguration.containsField(fieldNameWithID)) {
            if (telemetryConfiguration.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 10 with Context

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

Aggregations

Context (org.terasology.context.Context)13 ContextImpl (org.terasology.context.internal.ContextImpl)7 Test (org.junit.Test)4 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 DisplayDevice (org.terasology.engine.subsystem.DisplayDevice)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 Metrics (org.terasology.telemetry.Metrics)2 TelemetryCategory (org.terasology.telemetry.TelemetryCategory)2 Metric (org.terasology.telemetry.metrics.Metric)2 Lists (com.google.common.collect.Lists)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 Logger (org.slf4j.Logger)1