Search in sources :

Example 21 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 22 with ModuleManager

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

the class ApiScraper 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();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new);
    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        // System.out.println("Processing: " + apiClass);
        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) {
            System.out.println("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();
                // System.out.println("category fragment as path: " + categoryFragment);
                int bang = categoryFragment.lastIndexOf("!");
                int hyphen = categoryFragment.lastIndexOf("-", bang);
                int slash = categoryFragment.lastIndexOf("/", hyphen);
                category = categoryFragment.substring(slash + 1, hyphen);
                if (isPackage) {
                    // System.out.println("Jar-based Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Jar-based Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            case "file":
                // If file based we know it is local so organize it like that
                category = "terasology engine";
                if (isPackage) {
                    // System.out.println("Local Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Local Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            default:
                System.out.println("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
    System.out.println("# Modding API:\n");
    for (String key : sortedApi.keySet()) {
        System.out.println("## " + key + "\n");
        for (String value : sortedApi.get(key)) {
            System.out.println("* " + value);
        }
        System.out.println("");
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) TreeSet(java.util.TreeSet) ModuleManager(org.terasology.engine.core.module.ModuleManager) URL(java.net.URL)

Example 23 with ModuleManager

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

the class BindsSubsystem method registerBinds.

@Override
public void registerBinds() {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment environment = moduleManager.getEnvironment();
    clearBinds();
    registerButtonBinds(environment);
    registerAxisBinds(environment);
    registerRealAxisBinds(environment);
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ModuleManager(org.terasology.engine.core.module.ModuleManager)

Example 24 with ModuleManager

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

the class NetworkOwnershipTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EngineTime mockTime = mock(EngineTime.class);
    networkSystem = new NetworkSystemImpl(mockTime, context);
    networkSystem.setContext(context);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = (PojoEntityManager) context.get(EntityManager.class);
    context.put(ComponentSystemManager.class, new ComponentSystemManager(context));
    entityManager.clear();
    client = mock(NetClient.class);
    NetworkComponent clientNetComp = new NetworkComponent();
    clientNetComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    clientEntity = entityManager.create(clientNetComp);
    when(client.getEntity()).thenReturn(clientEntity);
    when(client.getId()).thenReturn("dummyID");
    networkSystem.mockHost();
    networkSystem.connectToEntitySystem(entityManager, context.get(EventLibrary.class), mock(BlockEntityRegistry.class));
    networkSystem.registerNetworkEntity(clientEntity);
    context.put(ServerConnectListManager.class, new ServerConnectListManager(context));
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EventLibrary(org.terasology.engine.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.core.EngineTime) BlockEntityRegistry(org.terasology.engine.world.BlockEntityRegistry) ModuleManager(org.terasology.engine.core.module.ModuleManager) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with ModuleManager

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

the class BaseEntityRefTest 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)

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