Search in sources :

Example 1 with ModuleTypeRegistry

use of org.terasology.reflection.ModuleTypeRegistry in project Terasology by MovingBlocks.

the class VectorEventSerializer method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    context.put(ReflectFactory.class, reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategies);
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
    entitySystemLibrary = new EntitySystemLibrary(context, typeHandlerLibrary);
    serializer = new EventSerializer(entitySystemLibrary.getEventLibrary(), typeHandlerLibrary);
    registerEvent(Vector3fTestEvent.class);
    serializer.setIdMapping(eventMap);
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) EventSerializer(org.terasology.engine.persistence.serializers.EventSerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ModuleTypeRegistry

use of org.terasology.reflection.ModuleTypeRegistry in project Terasology by MovingBlocks.

the class TestModuleEnvironmentSandbox method provideSandbox.

@BeforeEach
protected void provideSandbox(PathManager pathManager) throws Exception {
    when(pathManager.getModulePaths()).thenReturn(Collections.emptyList());
    moduleManager = ModuleManagerFactory.create();
    environment = moduleManager.getEnvironment();
    // TODO: make unit test more focused by not relying on complex ModuleManager interactions
    typeRegistry = new ModuleTypeRegistry(environment);
    sandbox = new ModuleEnvironmentSandbox(moduleManager, typeRegistry);
// module = environment.get(new Name("unittest"));
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ModuleTypeRegistry

use of org.terasology.reflection.ModuleTypeRegistry in project Terasology by MovingBlocks.

the class EnvironmentSwitchHandler method handleSwitchToGameEnvironment.

public void handleSwitchToGameEnvironment(Context context) {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ModuleTypeRegistry typeRegistry = context.get(ModuleTypeRegistry.class);
    typeRegistry.reload(environment);
    CopyStrategyLibrary copyStrategyLibrary = context.get(CopyStrategyLibrary.class);
    copyStrategyLibrary.clear();
    for (CopyStrategyEntry<?> entry : typesWithCopyConstructors) {
        entry.registerWith(copyStrategyLibrary);
    }
    // TODO: find a permanent fix over just creating a new typehandler
    // https://github.com/Terasology/JoshariasSurvival/issues/31
    // TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    // typeHandlerLibrary.addTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler(context.get(CollisionGroupManager.class)));
    TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
    typeHandlerLibrary.addTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler(context.get(CollisionGroupManager.class)));
    context.put(TypeHandlerLibrary.class, typeHandlerLibrary);
    // Entity System Library
    EntitySystemLibrary library = new EntitySystemLibrary(context, typeHandlerLibrary);
    context.put(EntitySystemLibrary.class, library);
    ComponentLibrary componentLibrary = library.getComponentLibrary();
    context.put(ComponentLibrary.class, componentLibrary);
    context.put(EventLibrary.class, library.getEventLibrary());
    context.put(ClassMetaLibrary.class, new ClassMetaLibraryImpl(context));
    registerComponents(componentLibrary, environment);
    registerTypeHandlers(context, typeHandlerLibrary, environment);
    // Load configs for the new environment
    AutoConfigManager autoConfigManager = context.get(AutoConfigManager.class);
    autoConfigManager.loadConfigsIn(context);
    ModuleAwareAssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
    /*
         * The registering of the prefab formats is done in this method, because it needs to be done before
         * the environment of the asset manager gets changed.
         *
         * It can't be done before this method gets called because the ComponentLibrary isn't
         * existing then yet.
         */
    unregisterPrefabFormats(assetTypeManager);
    registeredPrefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
    assetTypeManager.getAssetFileDataProducer(assetTypeManager.getAssetType(Prefab.class).orElseThrow(() -> new RuntimeException("Cannot get Prefab Asset typee"))).addAssetFormat(registeredPrefabFormat);
    registeredPrefabDeltaFormat = new PrefabDeltaFormat(componentLibrary, typeHandlerLibrary);
    assetTypeManager.getAssetFileDataProducer(assetTypeManager.getAssetType(Prefab.class).orElseThrow(() -> new RuntimeException("Cannot get Prefab Asset type"))).addDeltaFormat(registeredPrefabDeltaFormat);
    assetTypeManager.switchEnvironment(environment);
    assetTypeManager.reloadAssets();
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) PrefabFormat(org.terasology.engine.entitySystem.prefab.internal.PrefabFormat) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) PrefabDeltaFormat(org.terasology.engine.entitySystem.prefab.internal.PrefabDeltaFormat) ModuleManager(org.terasology.engine.core.module.ModuleManager) CollisionGroupTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.CollisionGroupTypeHandler) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) AutoConfigManager(org.terasology.engine.config.flexible.AutoConfigManager) Prefab(org.terasology.engine.entitySystem.prefab.Prefab)

Example 4 with ModuleTypeRegistry

use of org.terasology.reflection.ModuleTypeRegistry in project Terasology by MovingBlocks.

the class TerasologyEngine method initManagers.

private void initManagers() {
    changeStatus(TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER);
    TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
    TypeRegistry.WHITELISTED_PACKAGES = ExternalApiWhitelist.PACKAGES;
    ModuleManager moduleManager = new ModuleManager(rootContext.get(Config.class), classesOnClasspathsToAddToEngine);
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    rootContext.put(ModuleTypeRegistry.class, typeRegistry);
    rootContext.put(TypeRegistry.class, typeRegistry);
    rootContext.put(ModuleManager.class, moduleManager);
    changeStatus(TerasologyEngineStatus.INITIALIZING_LOWLEVEL_OBJECT_MANIPULATION);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    rootContext.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    rootContext.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    rootContext.put(TypeHandlerLibrary.class, TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry));
    changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_TYPES);
    assetTypeManager = new AutoReloadAssetTypeManager();
    rootContext.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    rootContext.put(AssetManager.class, assetTypeManager.getAssetManager());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) Config(org.terasology.engine.config.Config) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ModuleManager(org.terasology.engine.core.module.ModuleManager) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)

Example 5 with ModuleTypeRegistry

use of org.terasology.reflection.ModuleTypeRegistry 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)

Aggregations

ModuleTypeRegistry (org.terasology.reflection.ModuleTypeRegistry)6 ModuleManager (org.terasology.engine.core.module.ModuleManager)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)2 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)2 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)2 Config (org.terasology.engine.config.Config)1 AutoConfigManager (org.terasology.engine.config.flexible.AutoConfigManager)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 PrefabDeltaFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabDeltaFormat)1 PrefabFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabFormat)1 EventSerializer (org.terasology.engine.persistence.serializers.EventSerializer)1 CollisionGroupTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.CollisionGroupTypeHandler)1 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)1 AutoReloadAssetTypeManager (org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)1 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)1 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)1 ReflectionReflectFactory (org.terasology.reflection.reflect.ReflectionReflectFactory)1