Search in sources :

Example 1 with ModuleManager

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

the class HeadlessEnvironment method setupStorageManager.

@Override
protected void setupStorageManager() throws IOException {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    EngineEntityManager engineEntityManager = context.get(EngineEntityManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
    Path savePath = PathManager.getInstance().getSavePath("world1");
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment, context));
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockFamilyLibrary(org.terasology.engine.world.block.family.BlockFamilyLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer)

Example 2 with ModuleManager

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

the class ModuleManagerFactory method create.

public static ModuleManager create() throws Exception {
    // Loading screens, among other things, break when NUI classes are not added to engine.
    ModuleManager moduleManager = new ModuleManager("", ImmutableList.of(UIWidget.class));
    Module unittestModule = moduleManager.registerPackageModule("org.terasology.unittest");
    moduleManager.resolveAndLoadEnvironment(unittestModule.getId());
    return moduleManager;
}
Also used : ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) UIWidget(org.terasology.nui.UIWidget)

Example 3 with ModuleManager

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

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

the class BindingScraper method main.

/**
 * @param args (ignored)
 * @throws Exception if the module environment cannot be loaded
 */
public static void main(String[] args) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    // Holds normal input mappings where there is only one key
    Multimap<InputCategory, String> categories = ArrayListMultimap.create();
    Multimap<String, Input> keys = ArrayListMultimap.create();
    Map<String, String> desc = new HashMap<>();
    for (Class<?> holdingType : moduleManager.getEnvironment().getTypesAnnotatedWith(InputCategory.class)) {
        InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
        categories.put(inputCategory, null);
        for (String button : inputCategory.ordering()) {
            categories.put(inputCategory, button);
        }
    }
    for (Class<?> buttonEvent : moduleManager.getEnvironment().getTypesAnnotatedWith(RegisterBindButton.class)) {
        DefaultBinding defBinding = buttonEvent.getAnnotation(DefaultBinding.class);
        RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
        String cat = info.category();
        String id = "engine:" + info.id();
        desc.put(id, info.description());
        if (cat.isEmpty()) {
            InputCategory inputCategory = findEntry(categories, id);
            if (inputCategory == null) {
                System.out.println("Invalid category for: " + info.id());
            }
        } else {
            InputCategory inputCategory = findCategory(categories, cat);
            if (inputCategory != null) {
                categories.put(inputCategory, id);
            } else {
                System.out.println("Invalid category for: " + info.id());
            }
        }
        if (defBinding != null) {
            // This handles bindings with just one key
            Input input = defBinding.type().getInput(defBinding.id());
            keys.put(id, input);
        } else {
            // See if there is a multi-mapping for this button
            DefaultBindings multiBinding = buttonEvent.getAnnotation(DefaultBindings.class);
            // Annotation math magic. We're expecting a DefaultBindings containing one DefaultBinding pair
            if (multiBinding != null && multiBinding.value().length == 2) {
                DefaultBinding[] bindings = multiBinding.value();
                Input primary = bindings[0].type().getInput(bindings[0].id());
                Input secondary = bindings[1].type().getInput(bindings[1].id());
                keys.put(id, primary);
                keys.put(id, secondary);
            }
        }
    }
    for (InputCategory row : categories.keySet()) {
        System.out.println("# " + row.displayName());
        categories.get(row).stream().filter(entry -> entry != null).forEach(entry -> System.out.println(desc.get(entry) + ": " + keys.get(entry)));
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) DefaultBindings(org.terasology.engine.input.DefaultBindings) InputCategory(org.terasology.input.InputCategory) ModuleManager(org.terasology.engine.core.module.ModuleManager) DefaultBinding(org.terasology.engine.input.DefaultBinding) Map(java.util.Map) Input(org.terasology.input.Input) HashMap(java.util.HashMap) ModuleManagerFactory(org.terasology.engine.testUtil.ModuleManagerFactory) Multimap(com.google.common.collect.Multimap) DefaultBinding(org.terasology.engine.input.DefaultBinding) HashMap(java.util.HashMap) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) ModuleManager(org.terasology.engine.core.module.ModuleManager) Input(org.terasology.input.Input) InputCategory(org.terasology.input.InputCategory) DefaultBindings(org.terasology.engine.input.DefaultBindings)

Example 5 with ModuleManager

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

the class CompleteApiScraper method getApi.

/**
 * @return Project's Packages, Interfaces, Classes and Methods
 * @throws Exception if the module environment cannot be loaded
 */
static StringBuffer getApi() throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Multimap<String, String> api = Multimaps.newMultimap(new HashMap<String, Collection<String>>(), ArrayList::new);
    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        boolean isPackage = apiClass.isSynthetic();
        URL location;
        String category;
        String apiPackage = "";
        if (isPackage) {
            apiPackage = apiClass.getPackage().getName();
            location = classLoader.getResource(apiPackage.replace('.', '/'));
        } else {
            location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class");
        }
        if (location == null) {
            logger.error("Failed to get a class/package location, skipping " + apiClass);
            continue;
        }
        switch(location.getProtocol()) {
            case "jar":
                // Find out what jar it came from and consider that the category
                String categoryFragment = location.getPath();
                int bang = categoryFragment.lastIndexOf("!");
                int hyphen = categoryFragment.lastIndexOf("-", bang);
                int slash = categoryFragment.lastIndexOf("/", hyphen);
                category = categoryFragment.substring(slash + 1, hyphen);
                if (isPackage) {
                    api.put(category, apiPackage + " (PACKAGE)");
                } else {
                    addToApi(category, apiClass, api);
                }
                break;
            case "file":
                // If file based we know it is local so organize it like that
                category = TERASOLOGY_API_CLASS_CATEGORY;
                if (isPackage) {
                    api.put(category, apiPackage + " (PACKAGE)");
                } else {
                    addToApi(category, apiClass, api);
                }
                break;
            default:
                logger.error("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    api.putAll(EXTERNAL, ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    api.putAll(EXTERNAL, ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
    // Puts the information in the StringBuffer
    StringBuffer stringApi = new StringBuffer();
    stringApi.append("# Modding API:\n");
    for (String key : api.keySet()) {
        stringApi.append("## ");
        stringApi.append(key);
        stringApi.append("\n");
        for (String value : api.get(key)) {
            stringApi.append("* ");
            stringApi.append(value);
            stringApi.append("\n");
        }
        stringApi.append("\n");
    }
    return stringApi;
}
Also used : ArrayList(java.util.ArrayList) ModuleManager(org.terasology.engine.core.module.ModuleManager) URL(java.net.URL) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection)

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