Package org.terasology.module

Examples of org.terasology.module.Module


    public ModuleManager() {
        metadataReader = new ModuleMetadataReader();
        metadataReader.registerExtension(SERVER_SIDE_ONLY_EXT, Boolean.TYPE);
        metadataReader.registerExtension(IS_GAMEPLAY_EXT, Boolean.TYPE);
        metadataReader.registerExtension(DEFAULT_WORLD_GENERATOR_EXT, String.class);
        Module engineModule;
        try (Reader reader = new InputStreamReader(getClass().getResourceAsStream("/engine-module.txt"))) {
            ModuleMetadata metadata = metadataReader.read(reader);
            engineModule = ClasspathModule.create(metadata, getClass(), Module.class);
        } catch (IOException e) {
            throw new RuntimeException("Failed to read engine metadata", e);
View Full Code Here


        // Prefabs that still need to be created, by their name
        Map<String, EntityData.Prefab> pendingPrefabs = Maps.newHashMap();
        for (EntityData.Prefab prefabData : globalStore.getPrefabList()) {
            if (!prefabManager.exists(prefabData.getName())) {
                if (!prefabData.hasParentName()) {
                    Module module = environment.get(new SimpleUri(prefabData.getName()).getModuleName());
                    try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(module)) {
                        createPrefab(prefabData);
                    } catch (Exception e) {
                        logger.error("Failed to load prefab {}", prefabData.getName(), e);
                    }
View Full Code Here

        Prefab result = Assets.getPrefab(prefabData.getName());
        if (result == null) {
            if (prefabData.hasParentName() && pendingPrefabs.containsKey(prefabData.getParentName())) {
                loadPrefab(pendingPrefabs.get(prefabData.getParentName()), pendingPrefabs);
            }
            Module module = environment.get(new SimpleUri(prefabData.getName()).getModuleName());
            try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(module)) {
                result = createPrefab(prefabData);
            } catch (Exception e) {
                logger.error("Failed to load prefab {}", prefabData.getParentName(), e);
            }
View Full Code Here

        return Lists.newArrayList(uriLookup.row(name).values());
    }

    @Override
    public ClassMetadata<? extends T, ?> resolve(String name, Name context) {
        Module moduleContext = moduleManager.getEnvironment().get(context);
        if (moduleContext != null) {
            return resolve(name, moduleContext);
        }
        return null;
    }
View Full Code Here

                logger.warn("Failed to resolve {}:{}", type, name);
                return null;
            case 1:
                return possibilities.get(0);
            default:
                Module context = ModuleContext.getContext();
                if (context != null) {
                    Set<Name> dependencies = environment.getDependencyNamesOf(context.getId());
                    Iterator<AssetUri> iterator = possibilities.iterator();
                    while (iterator.hasNext()) {
                        AssetUri possibleUri = iterator.next();
                        if (context.getId().equals(possibleUri.getModuleName())) {
                            return possibleUri;
                        }
                        if (!dependencies.contains(possibleUri.getModuleName())) {
                            iterator.remove();
                        }
View Full Code Here

            AssetLoader<?> loader = extensionMap.get(extension);
            if (loader == null) {
                continue;
            }

            Module module = environment.get(uri.getModuleName());
            List<URL> deltas;
            if (uri.getAssetType().isDeltaSupported()) {
                deltas = Lists.newArrayList();
                for (Module deltaModule : environment.getModulesOrderedByDependencies()) {
                    AssetSource source = assetSources.get(deltaModule.getId());
View Full Code Here

    private void sendModules(List<NetData.ModuleRequest> moduleRequestList) {
        for (NetData.ModuleRequest request : moduleRequestList) {
            NetData.ModuleDataHeader.Builder result = NetData.ModuleDataHeader.newBuilder();
            result.setId(request.getModuleId());
            Module module = moduleManager.getEnvironment().get(new Name(request.getModuleId()));
            if (module.isOnClasspath() || module.getLocations().size() != 1 || !Files.isReadable(module.getLocations().get(0))) {
                result.setError("Module not available for download");
            } else {
                Path location = module.getLocations().get(0);
                try {
                    result.setVersion(module.getVersion().toString());
                    result.setSize(Files.size(location));
                    channelHandlerContext.getChannel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
                } catch (IOException e) {
                    logger.error("Error sending module data header", e);
                    channelHandlerContext.getChannel().close();
View Full Code Here

     * @param prefabData
     * @param
     * @return The deserialized prefab
     */
    public PrefabData deserialize(EntityData.Prefab prefabData, List<EntityData.Prefab> deltas) {
        Module context = ModuleContext.getContext();
        PrefabData result = new PrefabData();
        deserializeCommonData(prefabData, result);
        for (EntityData.Prefab delta : deltas) {
            applyCommonDataDelta(delta, result);
        }
View Full Code Here

        }
    }

    private void populateModuleInformation() {
        for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
            Module latestVersion = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
            if (!latestVersion.isOnClasspath()) {
                SelectModulesScreen.ModuleSelectionInfo info = new SelectModulesScreen.ModuleSelectionInfo(latestVersion);
                modulesLookup.put(info.getMetadata().getId(), info);
                sortedModules.add(info);
            }
        }
View Full Code Here

            @Override
            public Module get() {
                // try and be smart about auto selecting a gameplay
                if (selected == null) {
                    // get the default gameplay module from the config.  This is likely to have  a user triggered selection.
                    Module defaultGameplayModule = moduleManager.getRegistry().getLatestModuleVersion(
                            new Name(config.getDefaultModSelection().getDefaultGameplayModuleName()));
                    if (defaultGameplayModule != null) {
                        set(defaultGameplayModule);
                        return selected;
                    }

                    // find the first gameplay module that is available
                    for (Name moduleName : config.getDefaultModSelection().listModules()) {
                        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);

                        // module is null if it is no longer present
                        if (module != null && moduleManager.isGameplayModule(module)) {
                            set(module);
                            return selected;
                        }
                    }

                }

                return selected;
            }

            @Override
            public void set(Module value) {
                setSelectedGameplayModule(selected, value);
                selected = value;
            }
        });
        gameplay.setOptionRenderer(new StringTextRenderer<Module>() {
            @Override
            public String getString(Module value) {
                return value.getMetadata().getDisplayName().value();
            }
        });

        UILabel gameplayDescription = find("gameplayDescription", UILabel.class);
        gameplayDescription.bindText(new ReadOnlyBinding<String>() {
            @Override
            public String get() {
                Module selectedModule = gameplay.getSelection();
                if (selectedModule != null) {
                    return selectedModule.getMetadata().getDescription().value();
                } else {
                    return "";
                }

            }
        });

        final UIDropdown<WorldGeneratorInfo> worldGenerator = find("worldGenerator", UIDropdown.class);
        if (worldGenerator != null) {
            worldGenerator.bindOptions(new ReadOnlyBinding<List<WorldGeneratorInfo>>() {
                @Override
                public List<WorldGeneratorInfo> get() {
                    // grab all the module names and their dependencies
                    Set<Name> enabledModuleNames = Sets.newHashSet();
                    for (Name moduleName : getAllEnabledModuleNames()) {
                        enabledModuleNames.add(moduleName);
                    }

                    List<WorldGeneratorInfo> result = Lists.newArrayList();
                    for (WorldGeneratorInfo option : worldGeneratorManager.getWorldGenerators()) {
                        if (enabledModuleNames.contains(option.getUri().getModuleName())) {
                            result.add(option);
                        }
                    }

                    return result;
                }
            });
            worldGenerator.bindSelection(new Binding<WorldGeneratorInfo>() {
                @Override
                public WorldGeneratorInfo get() {
                    // get the default generator from the config.  This is likely to have  a user triggered selection.
                    WorldGeneratorInfo info = worldGeneratorManager.getWorldGeneratorInfo(config.getWorldGeneration().getDefaultGenerator());
                    if (info != null && getAllEnabledModuleNames().contains(info.getUri().getModuleName())) {
                        return info;
                    }

                    // get the default generator from the selected gameplay module
                    Module selectedGameplayModule = gameplay.getSelection();
                    if (selectedGameplayModule != null) {
                        String defaultWorldGenerator = selectedGameplayModule.getMetadata().getExtension(ModuleManager.DEFAULT_WORLD_GENERATOR_EXT, String.class);
                        if (defaultWorldGenerator != null) {
                            for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
                                if (worldGenInfo.getUri().equals(new SimpleUri(defaultWorldGenerator))) {
                                    set(worldGenInfo);
                                    return worldGenInfo;
View Full Code Here

TOP

Related Classes of org.terasology.module.Module

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.