Search in sources :

Example 6 with DisplayDevice

use of org.terasology.engine.core.subsystem.DisplayDevice 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

DisplayDevice (org.terasology.engine.core.subsystem.DisplayDevice)6 HashMap (java.util.HashMap)2 Context (org.terasology.engine.context.Context)2 TelemetryCategory (org.terasology.engine.telemetry.TelemetryCategory)2 Path (java.nio.file.Path)1 JFileChooser (javax.swing.JFileChooser)1 Config (org.terasology.engine.config.Config)1 ComponentSystem (org.terasology.engine.entitySystem.systems.ComponentSystem)1 RegisterSystem (org.terasology.engine.entitySystem.systems.RegisterSystem)1 Module (org.terasology.gestalt.module.Module)1 Name (org.terasology.gestalt.naming.Name)1