Search in sources :

Example 6 with Context

use of org.terasology.engine.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.engine.context.Context) Metrics(org.terasology.engine.telemetry.Metrics) SystemContextMetric(org.terasology.engine.telemetry.metrics.SystemContextMetric) Metric(org.terasology.engine.telemetry.metrics.Metric)

Example 7 with Context

use of org.terasology.engine.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.engine.context.Context) Metrics(org.terasology.engine.telemetry.Metrics) ModulesMetric(org.terasology.engine.telemetry.metrics.ModulesMetric) Metric(org.terasology.engine.telemetry.metrics.Metric)

Example 8 with Context

use of org.terasology.engine.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.engine.context.Context) TelemetryCategory(org.terasology.engine.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 9 with Context

use of org.terasology.engine.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());
    }
    /*FrameBuffersManager renderingProcess = ingameContext.get(FrameBuffersManager.class);
        if (renderingProcess != null) {
            result.addAll(new ReflectionProvider(renderingProcess, ingameContext).getProperties());
        }*/
    return result;
}
Also used : Context(org.terasology.engine.context.Context) StateIngame(org.terasology.engine.core.modes.StateIngame) GameState(org.terasology.engine.core.modes.GameState) BackdropProvider(org.terasology.engine.rendering.backdrop.BackdropProvider)

Example 10 with Context

use of org.terasology.engine.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.engine.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.engine.context.Context) TelemetryCategory(org.terasology.engine.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) HashMap(java.util.HashMap)

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