Search in sources :

Example 26 with Module

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

the class ClasspathCompromisingModuleFactoryTest method directoryModuleContainsClass.

@Test
public void directoryModuleContainsClass() {
    // This test assumes that the unittest module is under the current working directory (`engine-test/`)
    File engineTestDirectory = new File(System.getProperty("user.dir", "."));
    ModuleMetadata metadata = new ModuleMetadata(new Name("unittest"), new Version("1.0.0"));
    Module module = factory.createDirectoryModule(metadata, engineTestDirectory);
    // and that ExampleClass is inside that directory
    assertTrue(module.getClassPredicate().test(ExampleClass.class));
    // and that this other class (in engine, not engine-test) is outside that directory.
    assertFalse(module.getClassPredicate().test(someClassOutsideTheModule));
// These assumptions could break if things get moved around enough.
}
Also used : ExampleClass(org.terasology.unittest.ExampleClass) Version(org.terasology.gestalt.naming.Version) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Module(org.terasology.gestalt.module.Module) File(java.io.File) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Example 27 with Module

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

the class BindsSubsystemTest method setUpMockModuleEnvironment.

private void setUpMockModuleEnvironment() {
    ModuleManager moduleManager = mock(ModuleManager.class);
    ModuleRegistry moduleRegistry = new TableModuleRegistry();
    Module module = mock(Module.class);
    when(module.getId()).thenReturn(new Name(TEST_MODULE));
    when(module.getVersion()).thenReturn(new Version(0, 0, 1, true));
    when(module.getMetadata()).thenReturn(new ModuleMetadata());
    moduleRegistry.add(module);
    when(moduleManager.getRegistry()).thenReturn(moduleRegistry);
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(moduleManager.loadEnvironment(any(), anyBoolean())).thenReturn(environment);
    when(moduleManager.getEnvironment()).thenReturn(environment);
    registerBindButtonClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class))).thenReturn(registerBindButtonClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class), any())).thenReturn(registerBindButtonClasses);
    registerRealBindAxisClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class))).thenReturn(registerRealBindAxisClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class), any())).thenReturn(registerRealBindAxisClasses);
    when(environment.getModuleProviding(any())).thenReturn(new Name(TEST_MODULE));
    context.put(ModuleManager.class, moduleManager);
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Version(org.terasology.gestalt.naming.Version) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 28 with Module

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

the class WithUnittestModule method initialise.

@Override
public void initialise(GameEngine engine, Context rootContext) {
    EngineSubsystem.super.initialise(engine, rootContext);
    ModuleManager manager = rootContext.get(ModuleManager.class);
    Module unittestModule = manager.registerPackageModule("org.terasology.unittest");
    manager.resolveAndLoadEnvironment(unittestModule.getId());
}
Also used : ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module)

Example 29 with Module

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

the class GameManifestProvider method createGameManifest.

/**
 * Generates game manifest with default settings (title, seed) if not specified.
 * Uses default world generator, and modules selection.
 * @TODO: rewrite/fix it when code will be more stable
 *
 * @param universeWrapper  contains the universe level properties
 * @param moduleManager    resolves modules
 * @param config           provides default module selection, world generator
 * @return                 game manifest with default settings
 */
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
    GameManifest gameManifest = new GameManifest();
    if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
        gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
    } else {
        gameManifest.setTitle(GameProvider.getNextGameName());
    }
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (!result.isSuccess()) {
        logger.error("Can't resolve dependencies");
        return null;
    }
    for (Module module : result.getModules()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    SimpleUri uri;
    String seed;
    WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
    if (worldSetup != null) {
        uri = worldSetup.getWorldGenerator().getUri();
        seed = worldSetup.getWorldGenerator().getWorldSeed();
    } else {
        uri = config.getWorldGeneration().getDefaultGenerator();
        seed = universeWrapper.getSeed();
    }
    gameManifest.setSeed(seed);
    String targetWorldName = "";
    Map<String, Component> worldConfig = Maps.newHashMap();
    if (worldSetup != null) {
        targetWorldName = worldSetup.getWorldName().toString();
        if (worldSetup.getWorldConfigurator() != null) {
            // horrible hack to get configs into manifest.
            // config driven by CreateWorldEntity.
            // world config set somewhere else as well no clear drive from config --> world
            gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
        }
    }
    // This is multiplied by the number of seconds in a day (86400000) to determine the exact  millisecond at which the game will start.
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
    gameManifest.addWorld(worldInfo);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 30 with Module

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

the class StateHeadlessSetup method createGameManifest.

public GameManifest createGameManifest() {
    GameManifest gameManifest = new GameManifest();
    Config config = context.get(Config.class);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    for (Name moduleName : config.getDefaultModSelection().listModules()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
        if (module != null) {
            gameManifest.addModule(module.getId(), module.getVersion());
        } else {
            logger.warn("ModuleRegistry has no latest version for module {}", moduleName);
        }
    }
    WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
    // If no valid default world generator set then try to find one - no option to pick one manually in headless
    if (!worldGenConfig.getDefaultGenerator().isValid()) {
        // find the first gameplay module that is available, it should have a preferred world gen
        for (Name moduleName : config.getDefaultModSelection().listModules()) {
            Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
            if (StandardModuleExtension.isGameplayModule(module)) {
                SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
                worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
                break;
            }
        }
    }
    SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
    gameManifest.setTitle(worldGenConfig.getWorldTitle());
    gameManifest.setSeed(worldGenConfig.getDefaultSeed());
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, worldGenConfig.getWorldTitle(), gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), worldGeneratorUri);
    gameManifest.addWorld(worldInfo);
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Name(org.terasology.gestalt.naming.Name)

Aggregations

Module (org.terasology.gestalt.module.Module)51 ModuleManager (org.terasology.engine.core.module.ModuleManager)18 Name (org.terasology.gestalt.naming.Name)17 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)13 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)11 List (java.util.List)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 SimpleUri (org.terasology.engine.core.SimpleUri)9 UILabel (org.terasology.nui.widgets.UILabel)9 UIText (org.terasology.nui.widgets.UIText)9 DependencyInfo (org.terasology.gestalt.module.dependencyresolution.DependencyInfo)8 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)8 Canvas (org.terasology.nui.Canvas)8 Collection (java.util.Collection)7 Comparator (java.util.Comparator)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)7 In (org.terasology.engine.registry.In)7