use of org.terasology.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 depencencies for " + worldGenUri);
}
}
use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class EntitySerializerTest method setupClass.
@BeforeClass
public static void setupClass() throws Exception {
context = new ContextImpl();
CoreRegistry.setContext(context);
moduleManager = ModuleManagerFactory.create();
context.put(ModuleManager.class, moduleManager);
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
}
use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class InjectionHelperTest method setUp.
@Before
public void setUp() {
serviceA = new ServiceAImpl();
serviceB = new ServiceBImpl();
// injection helper uses the core registry,
// make sure the shared classes are not used over multiple tests
CoreRegistry.setContext(new ContextImpl());
}
use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulated.
@Test
public void testConstructorInjectionNotAllParametersPopulated() {
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 can't be populated because serviceB is not available
// there is no fallback for a constructor with only serviceA, so the default constructor is called
assertThat(constructorAB.getServiceA(), is(nullValue()));
assertThat(constructorAB.getServiceB(), is(nullValue()));
}
use of org.terasology.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
assertThat(constructorAB.getServiceA(), is(serviceA));
assertThat(constructorAB.getServiceB(), is(serviceB));
}
Aggregations