Search in sources :

Example 11 with Module

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

the class ModuleManager method loadModulesFromClassPath.

private void loadModulesFromClassPath() {
    ClasspathCompromisingModuleFactory ccModuleFactory = (ClasspathCompromisingModuleFactory) this.moduleFactory;
    for (String metadataName : ccModuleFactory.getModuleMetadataLoaderMap().keySet()) {
        Enumeration<URL> urls;
        try {
            urls = ClassLoader.getSystemResources(metadataName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            logger.debug("Probably a module in U:{}", url);
            Path path = ccModuleFactory.canonicalModuleLocation(metadataName, url);
            Module module;
            try {
                module = ccModuleFactory.createModule(path.toFile());
            } catch (IOException e) {
                logger.warn("Failed to create module from {}", path, e);
                continue;
            }
            if (registry.add(module)) {
                logger.info("Loaded {} from {}", module.getId(), path);
            } else {
                logger.info("Module {} from {} was a duplicate; not registering this copy.", module.getId(), path);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) Module(org.terasology.gestalt.module.Module) URL(java.net.URL)

Example 12 with Module

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

the class ComponentSystemManager method loadSystems.

public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
    DisplayDevice display = context.get(DisplayDevice.class);
    boolean isHeadless = display.isHeadless();
    ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
    for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
        if (!ComponentSystem.class.isAssignableFrom(type)) {
            logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
            continue;
        }
        Name moduleId = environment.getModuleProviding(type);
        RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
        if (registerInfo.value().isValidFor(netMode.isAuthority(), isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
            systemsByModule.put(moduleId, type);
        }
    }
    for (Module module : environment.getModulesOrderedByDependencies()) {
        for (Class<?> system : systemsByModule.get(module.getId())) {
            String id = module.getId() + ":" + system.getSimpleName();
            logger.debug("Registering system {}", id);
            if (checkOptionalDependenciesPresent(system)) {
                tryToLoadSystem(system, id);
            } else {
                logger.warn("Skip system {} for loading - possibly missing optional dependencies", id);
            }
        }
    }
}
Also used : DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) RegisterSystem(org.terasology.engine.entitySystem.systems.RegisterSystem) ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 13 with Module

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

the class GameDetailsScreen method setUpGameModules.

private void setUpGameModules() {
    gameModules.subscribeSelection((widget, moduleSelectionInfo) -> {
        if (moduleSelectionInfo == null) {
            return;
        }
        descriptionTitle.setText(translationSystem.translate("${engine:menu#game-details-module-description}"));
        description.setText(getModuleDescription(moduleSelectionInfo));
        gameWorlds.setSelection(null);
        blocks.setSelection(null);
    });
    gameModules.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {

        String getString(ModuleSelectionInfo value) {
            if (value.getMetadata() != null) {
                return value.getMetadata().getDisplayName().toString();
            } else if (value.isUnavailableVersion()) {
                return value.getUnavailableModuleName();
            }
            return "";
        }

        @Override
        public void draw(ModuleSelectionInfo value, Canvas canvas) {
            if (value.isStrictVersion()) {
                canvas.setMode("strict");
            } else if (value.isLatestVersion()) {
                canvas.setMode("latest");
            } else {
                canvas.setMode("invalid");
            }
            canvas.drawText(getString(value), canvas.getRegion());
        }

        @Override
        public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
            String text = getString(value);
            return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
        }
    });
    gameModules.subscribe(((widget, item) -> openModuleDetailsScreen()));
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Map(java.util.Map) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Binding(org.terasology.nui.databinding.Binding) SelectGameScreen(org.terasology.engine.rendering.nui.layers.mainMenu.SelectGameScreen) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) UIImage(org.terasology.nui.widgets.UIImage) DateTimeHelper(org.terasology.engine.utilities.time.DateTimeHelper) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) NameVersion(org.terasology.gestalt.naming.NameVersion) GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) UIList(org.terasology.nui.widgets.UIList) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) ModuleManager(org.terasology.engine.core.module.ModuleManager) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) SimpleDateFormat(java.text.SimpleDateFormat) UITabBox(org.terasology.nui.widgets.UITabBox) ArrayList(java.util.ArrayList) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UIImageSlideshow(org.terasology.nui.widgets.UIImageSlideshow) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) Maps(com.google.common.collect.Maps) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i)

Example 14 with Module

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

the class GameDetailsScreen method loadGameModules.

private void loadGameModules() {
    final List<ModuleSelectionInfo> sortedGameModules = gameInfo.getManifest().getModules().stream().sorted(Comparator.comparing(NameVersion::getName)).map(nameVersion -> {
        Module module = moduleManager.getRegistry().getModule(nameVersion.getName(), nameVersion.getVersion());
        if (module != null) {
            return ModuleSelectionInfo.strictVersion(module);
        } else {
            logger.warn("Can't find module in your classpath - {}:{}", nameVersion.getName(), nameVersion.getVersion());
            module = moduleManager.getRegistry().getLatestModuleVersion(nameVersion.getName());
            if (module != null) {
                logger.debug("Get the latest available version of module {} in your classpath", nameVersion.getName());
                errors.add(String.format("Can't find module %s:%s in your classpath; " + "loaded description for the latest available version.", nameVersion.getName(), nameVersion.getVersion()));
                return ModuleSelectionInfo.latestVersion(module);
            }
            logger.error("Can't find any versions of module {} in your classpath!", nameVersion.getName());
            errors.add(String.format("Can't find any versions of module %s in your classpath!", nameVersion.getName()));
            return ModuleSelectionInfo.unavailableVersion(nameVersion.getName().toString(), nameVersion.getVersion().toString());
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    gameModules.setList(sortedGameModules);
    gameModules.select(0);
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) Module(org.terasology.gestalt.module.Module)

Example 15 with Module

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

the class ModuleDetailsScreen method setUpModules.

private void setUpModules() {
    modules.subscribeSelection(((widget, item) -> {
        if (item != null) {
            dependencies.setList(getSortedDependencies(item));
            dependencies.setSelection(null);
            dependencies.select(0);
            this.updateOpenInBrowserButton();
        }
    }));
    modules.setItemRenderer(new StringTextRenderer<Module>() {

        @Override
        public String getString(Module value) {
            if (value != null) {
                return value.getMetadata().getDisplayName().toString();
            }
            return "";
        }

        @Override
        public void draw(Module value, Canvas canvas) {
            if (!validateModuleDependencies(value.getId())) {
                canvas.setMode(("invalid"));
            } else {
                canvas.setMode("available");
            }
            canvas.drawText(getString(value), canvas.getRegion());
        }

        @Override
        public Vector2i getPreferredSize(Module value, Canvas canvas) {
            String text = getString(value);
            return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
        }
    });
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) Arrays(java.util.Arrays) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Version(org.terasology.gestalt.naming.Version) Collectors(java.util.stream.Collectors) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) ExtraDataModuleExtension(org.terasology.engine.core.module.ExtraDataModuleExtension) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) UIButtonWebBrowser(org.terasology.engine.rendering.nui.widgets.UIButtonWebBrowser) SimpleDateFormat(java.text.SimpleDateFormat) DownloadPopupProgressListener(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.DownloadPopupProgressListener) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) HashSet(java.util.HashSet) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) RemoteModuleExtension(org.terasology.engine.core.module.RemoteModuleExtension) Collections(java.util.Collections) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) Module(org.terasology.gestalt.module.Module)

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