Search in sources :

Example 1 with Context

use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.

the class ComponentSystemManagerTest method setUp.

@BeforeEach
public void setUp() {
    Context context = mock(Context.class);
    EntityManager entityManager = mock(EntityManager.class);
    when(entityManager.getEventSystem()).thenReturn(mock(EventSystem.class));
    when(context.get(EntityManager.class)).thenReturn(entityManager);
    console = mock(Console.class);
    when(context.get(Console.class)).thenReturn(console);
    systemUnderTest = new ComponentSystemManager(context);
}
Also used : Context(org.terasology.engine.context.Context) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) Console(org.terasology.engine.logic.console.Console) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Context

use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.

the class VisualCharacterSystemTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.system = new VisualCharacterSystem();
    Context context = new ContextImpl();
    this.localPlayer = Mockito.mock(LocalPlayer.class);
    context.put(LocalPlayer.class, localPlayer);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return clientEntityReturnedByLocalPlayer;
        }
    }).when(localPlayer).getClientEntity();
    this.entityManager = Mockito.mock(EntityManager.class);
    Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
    context.put(EntityManager.class, this.entityManager);
    InjectionHelper.inject(system, context);
    system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
Also used : Context(org.terasology.engine.context.Context) Answer(org.mockito.stubbing.Answer) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ContextImpl(org.terasology.engine.context.internal.ContextImpl) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Context

use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.

the class InjectionHelperTest method testConstructorInjectionNoDefaultConstructorForFallback.

@Test
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.
    Assertions.assertThrows(NoSuchElementException.class, () -> InjectionHelper.createWithConstructorInjection(ConstructorB.class, context));
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Example 4 with Context

use of org.terasology.engine.context.Context 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
    assertNull(constructorAB.getServiceA());
    assertNull(constructorAB.getServiceB());
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Example 5 with Context

use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.

the class WorldPreGenerationScreen method setEnvironment.

/**
 * A function called before the screen comes to the forefront to setup the environment
 * and extract necessary objects from the new Context.
 *
 * @param subContext The new environment created in {@link UniverseSetupScreen}
 * @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
 */
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
    context = subContext;
    environment = context.get(ModuleEnvironment.class);
    context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
    worldList = context.get(UniverseSetupScreen.class).getWorldsList();
    selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
    worldNames = context.get(UniverseSetupScreen.class).worldNames();
    setWorldGenerators();
    worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
    final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
    worldsDropdown.setOptions(worldNames);
    genTexture();
    List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
    if (previewZones.isEmpty()) {
        previewGen = new FacetLayerPreview(environment, worldGenerator);
    }
}
Also used : MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UISlider(org.terasology.nui.widgets.UISlider) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Texture(org.terasology.engine.rendering.assets.texture.Texture) In(org.terasology.engine.registry.In) ModuleManager(org.terasology.engine.core.module.ModuleManager) LoggerFactory(org.slf4j.LoggerFactory) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) WidgetUtil(org.terasology.nui.WidgetUtil) ByteBuffer(java.nio.ByteBuffer) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) TeraMath(org.terasology.math.TeraMath) Binding(org.terasology.nui.databinding.Binding) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Logger(org.slf4j.Logger) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Assets(org.terasology.engine.utilities.Assets) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) NUIManager(org.terasology.engine.rendering.nui.NUIManager) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) UISliderOnChangeTriggeredListener(org.terasology.nui.widgets.UISliderOnChangeTriggeredListener) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Zone(org.terasology.engine.world.zones.Zone) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview)

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