Search in sources :

Example 1 with Context

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

the class ModulesJsonProvider method writeTo.

@Override
public void writeTo(JsonGenerator generator, ILoggingEvent iLoggingEvent) throws IOException {
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    Context context = appender.getGameContext();
    if (context != null) {
        Metrics metrics = context.get(Metrics.class);
        Optional<Metric> optional = metrics.getMetric(ModulesMetric.class);
        if (optional.isPresent()) {
            Metric modulesMetric = optional.get();
            Map<String, ?> map = modulesMetric.createTelemetryFieldToValue();
            Map<String, String> stringMap = TelemetryUtils.toStringMap(map);
            JsonWritingUtils.writeMapStringFields(generator, getFieldName(), stringMap);
        }
    }
}
Also used : Context(org.terasology.context.Context) Metrics(org.terasology.telemetry.Metrics) Metric(org.terasology.telemetry.metrics.Metric) ModulesMetric(org.terasology.telemetry.metrics.ModulesMetric)

Example 2 with Context

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

the class SystemContextJsonProvider method writeTo.

public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    Context context = appender.getGameContext();
    if (context != null) {
        Metrics metrics = context.get(Metrics.class);
        Optional<Metric> optional = metrics.getMetric(SystemContextMetric.class);
        if (optional.isPresent()) {
            Metric systemContextMetric = optional.get();
            Map<String, ?> map = systemContextMetric.createTelemetryFieldToValue();
            Map<String, String> stringMap = TelemetryUtils.toStringMap(map);
            JsonWritingUtils.writeMapStringFields(generator, getFieldName(), stringMap);
        }
    }
}
Also used : Context(org.terasology.context.Context) Metrics(org.terasology.telemetry.Metrics) Metric(org.terasology.telemetry.metrics.Metric) SystemContextMetric(org.terasology.telemetry.metrics.SystemContextMetric)

Example 3 with Context

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

the class SceneProperties method getProperties.

@Override
public List<Property<?>> getProperties() {
    List<Property<?>> result = Lists.newArrayList();
    GameState gameState = engine.getState();
    if (!(gameState instanceof StateIngame)) {
        return result;
    }
    StateIngame ingameState = (StateIngame) gameState;
    Context ingameContext = ingameState.getContext();
    BackdropProvider backdropProvider = ingameContext.get(BackdropProvider.class);
    if (backdropProvider != null) {
        result.addAll(new ReflectionProvider(backdropProvider, ingameContext).getProperties());
    }
    BackdropRenderer backdropRenderer = ingameContext.get(BackdropRenderer.class);
    if (backdropRenderer != null) {
        result.addAll(new ReflectionProvider(backdropRenderer, ingameContext).getProperties());
    }
    /*FrameBuffersManager renderingProcess = ingameContext.get(FrameBuffersManager.class);
        if (renderingProcess != null) {
            result.addAll(new ReflectionProvider(renderingProcess, ingameContext).getProperties());
        }*/
    return result;
}
Also used : Context(org.terasology.context.Context) StateIngame(org.terasology.engine.modes.StateIngame) GameState(org.terasology.engine.modes.GameState) BackdropProvider(org.terasology.rendering.backdrop.BackdropProvider) BackdropRenderer(org.terasology.rendering.backdrop.BackdropRenderer)

Example 4 with Context

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

the class InjectionHelperTest method testConstructorInjectionNoDefaultConstructorForFallback.

@Test(expected = NoSuchElementException.class)
public void testConstructorInjectionNoDefaultConstructorForFallback() {
    Context context = new ContextImpl();
    context.put(ServiceA.class, serviceA);
    // context.put(ServiceB.class, serviceB);
    // there is only one constructor for serviceB which is not present on the context.
    // a default constructor is not available, so the injection fails.
    InjectionHelper.createWithConstructorInjection(ConstructorB.class, context);
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

Example 5 with Context

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

the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulatedFallback.

@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
    assertThat(constructorA_AB.getServiceA(), is(serviceA));
    assertThat(constructorA_AB.getServiceB(), is(nullValue()));
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

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