use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class PojoEntityPoolTest method setupClass.
@BeforeAll
public static void setupClass() throws Exception {
context = new ContextImpl();
ModuleManager moduleManager = ModuleManagerFactory.create();
context.put(ModuleManager.class, moduleManager);
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
CoreRegistry.setContext(context);
}
use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class InjectionHelperTest method testDefaultConstructorInjection.
@Test
public void testDefaultConstructorInjection() {
Context context = new ContextImpl();
context.put(ServiceA.class, serviceA);
context.put(ServiceB.class, serviceB);
ConstructorAB constructorAB = InjectionHelper.createWithConstructorInjection(ConstructorAB.class, context);
// the two-arg constructor should be used as it has the most parameters and all can be populated
assertEquals(constructorAB.getServiceA(), serviceA);
assertEquals(constructorAB.getServiceB(), serviceB);
}
use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulatedFallback.
@SuppressWarnings("checkstyle:LocalVariableName")
@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
assertEquals(constructorA_AB.getServiceA(), serviceA);
assertNull(constructorA_AB.getServiceB());
}
use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class NUIManagerInternal method initialiseControlWidget.
private <T extends ControlWidget> void initialiseControlWidget(T overlay, ResourceUrn screenUri) {
ContextImpl timedContextForModulesWidgets = new ContextImpl(this.context);
Module declaringModule = moduleEnvironment.get(screenUri.getModuleName());
TypeWidgetLibrary moduleLibrary = new TypeWidgetLibraryImpl(typeWidgetFactoryRegistry, declaringModule, this.context);
context.put(TypeWidgetLibrary.class, moduleLibrary);
InjectionHelper.inject(overlay, timedContextForModulesWidgets);
overlay.initialise();
}
use of org.terasology.engine.context.internal.ContextImpl 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 dependencies for " + worldGenUri);
}
}
Aggregations