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);
}
}
}
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);
}
}
}
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;
}
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);
}
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()));
}
Aggregations