Search in sources :

Example 21 with ModuleEnvironment

use of org.terasology.gestalt.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class SettingWidgetFactoryTest method testCreateWidgetFor.

@Test
void testCreateWidgetFor() {
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(environment.getSubtypesOf(eq(ConstraintWidgetFactory.class))).thenReturn(Lists.newArrayList(NumberRangeConstraintWidgetFactory.class));
    AssetManager assetManager = new AssetManager(mock(AssetTypeManager.class));
    SettingWidgetFactory settingWidgetFactory = new SettingWidgetFactory(environment, assetManager, null);
    Setting<Integer> setting = mock(Setting.class);
    when(setting.getConstraint()).thenReturn(new NumberRangeConstraint<>(0, 10, false, false));
    Optional<ConstraintWidgetFactory<Integer, ?>> widget = settingWidgetFactory.getConstraintWidgetFactory(setting);
    assertTrue(widget.isPresent());
    assertTrue(widget.get() instanceof NumberRangeConstraintWidgetFactory);
}
Also used : AssetManager(org.terasology.gestalt.assets.management.AssetManager) AssetTypeManager(org.terasology.gestalt.assets.management.AssetTypeManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Test(org.junit.jupiter.api.Test)

Example 22 with ModuleEnvironment

use of org.terasology.gestalt.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class BindsSubsystemTest method test.

@Test
public void test() {
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class), any())).thenReturn(registerBindButtonClasses);
    registerBindButtonClasses.add(TestEventButton.class);
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) Test(org.junit.jupiter.api.Test)

Example 23 with ModuleEnvironment

use of org.terasology.gestalt.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class EnvironmentSwitchHandler method handleSwitchToEmptyEnvironment.

public void handleSwitchToEmptyEnvironment(Context context) {
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    cheapAssetManagerUpdate(context, environment);
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ModuleManager(org.terasology.engine.core.module.ModuleManager)

Example 24 with ModuleEnvironment

use of org.terasology.gestalt.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class StateIngame method dispose.

@Override
public void dispose(boolean shuttingDown) {
    ChunkProvider chunkProvider = context.get(ChunkProvider.class);
    chunkProvider.dispose();
    AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
    // dispose all module assets
    assetTypeManager.getAssetTypes().forEach(assetType -> {
        for (ResourceUrn urn : assetType.getLoadedAssetUrns()) {
            if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) {
                assetType.getAsset(urn).ifPresent(Asset::dispose);
            }
        }
    });
    // dispose engine assets that should not be kept when switching game states
    assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll);
    assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll);
    boolean save = networkSystem.getMode().isAuthority();
    if (save && storageManager != null) {
        storageManager.waitForCompletionOfPreviousSaveAndStartSaving();
    }
    networkSystem.shutdown();
    // TODO: Shutdown background threads
    eventSystem.process();
    GameThread.processWaitingProcesses();
    if (nuiManager != null) {
        nuiManager.clear();
    }
    context.get(AudioManager.class).stopAllSounds();
    if (worldRenderer != null) {
        worldRenderer.dispose();
        worldRenderer = null;
    }
    componentSystemManager.shutdown();
    context.get(PhysicsEngine.class).dispose();
    entityManager.clear();
    if (storageManager != null) {
        storageManager.finishSavingAndShutdown();
    }
    ModuleEnvironment oldEnvironment = context.get(ModuleManager.class).getEnvironment();
    context.get(ModuleManager.class).loadEnvironment(Collections.<Module>emptySet(), true);
    if (!shuttingDown) {
        context.get(EnvironmentSwitchHandler.class).handleSwitchToEmptyEnvironment(context);
    }
    if (oldEnvironment != null) {
        oldEnvironment.close();
    }
    console.dispose();
    GameThread.clearWaitingProcesses();
    if (nuiManager != null) {
        /*
             * Clear the binding as otherwise the complete ingame state would be
             * referenced.
             */
        nuiManager.getHUD().clearVisibleBinding();
    }
}
Also used : PhysicsEngine(org.terasology.engine.physics.engine.PhysicsEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) AudioManager(org.terasology.engine.audio.AudioManager) AssetType(org.terasology.gestalt.assets.AssetType) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) AssetTypeManager(org.terasology.gestalt.assets.management.AssetTypeManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Asset(org.terasology.gestalt.assets.Asset) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 25 with ModuleEnvironment

use of org.terasology.gestalt.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class AutoConfigManager method loadConfigsIn.

public void loadConfigsIn(Context context) {
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    for (Class<? extends AutoConfig> configClass : environment.getSubtypesOf(AutoConfig.class)) {
        if (context.get(configClass) != null) {
            // We've already initialized this config before
            continue;
        }
        SimpleUri configId = verifyNotNull(ReflectionUtil.getFullyQualifiedSimpleUriFor(configClass, environment), "Could not find ID for %s", configClass.getSimpleName());
        loadConfig(configClass, configId, context);
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleManager(org.terasology.engine.core.module.ModuleManager)

Aggregations

ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)31 ModuleManager (org.terasology.engine.core.module.ModuleManager)24 Module (org.terasology.gestalt.module.Module)6 Name (org.terasology.gestalt.naming.Name)6 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)5 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)5 SimpleUri (org.terasology.engine.core.SimpleUri)4 RegisterBindButton (org.terasology.engine.input.RegisterBindButton)4 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)4 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)4 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)4 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)3 NetworkSystem (org.terasology.engine.network.NetworkSystem)3 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)3 BlockManager (org.terasology.engine.world.block.BlockManager)3 BlockFamilyLibrary (org.terasology.engine.world.block.family.BlockFamilyLibrary)3 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 Path (java.nio.file.Path)2