Search in sources :

Example 26 with ModuleManager

use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.

the class BindsSubsystem method updateDefaultBinds.

private void updateDefaultBinds(Context passedContext, BindsConfiguration config) {
    ModuleManager moduleManager = passedContext.get(ModuleManager.class);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                FromModule filter = new FromModule(environment, moduleId);
                Iterable<Class<?>> buttons = environment.getTypesAnnotatedWith(RegisterBindButton.class, filter);
                Iterable<Class<?>> axes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class, filter);
                addButtonDefaultsFor(moduleId, buttons, config);
                addAxisDefaultsFor(moduleId, axes, config);
            }
        }
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleManager(org.terasology.engine.core.module.ModuleManager) FromModule(org.terasology.gestalt.module.predicates.FromModule) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name)

Example 27 with ModuleManager

use of org.terasology.engine.core.module.ModuleManager 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)

Example 28 with ModuleManager

use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupModuleManager.

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
    TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    context.put(TypeRegistry.class, typeRegistry);
    context.put(ModuleTypeRegistry.class, typeRegistry);
    moduleManager.resolveAndLoadEnvironment(moduleNames);
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) ModuleManager(org.terasology.engine.core.module.ModuleManager)

Example 29 with ModuleManager

use of org.terasology.engine.core.module.ModuleManager 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);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 30 with ModuleManager

use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.

the class RegisterSystems method step.

@Override
public boolean step() {
    componentSystemManager = context.get(ComponentSystemManager.class);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    TerasologyEngine terasologyEngine = (TerasologyEngine) context.get(GameEngine.class);
    for (EngineSubsystem subsystem : terasologyEngine.getSubsystems()) {
        subsystem.registerSystems(componentSystemManager);
    }
    componentSystemManager.loadSystems(moduleManager.getEnvironment(), netMode);
    return true;
}
Also used : EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) TerasologyEngine(org.terasology.engine.core.TerasologyEngine) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager)

Aggregations

ModuleManager (org.terasology.engine.core.module.ModuleManager)35 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)15 Module (org.terasology.gestalt.module.Module)10 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ContextImpl (org.terasology.engine.context.internal.ContextImpl)7 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)7 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)6 Name (org.terasology.gestalt.naming.Name)6 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)5 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)5 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)5 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)5 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)5 GameEngine (org.terasology.engine.core.GameEngine)4 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)4 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)4 TypeRegistry (org.terasology.reflection.TypeRegistry)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3