Search in sources :

Example 6 with ReflectionReflectFactory

use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.

the class PojoPrefabManagerTest method setup.

@Before
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    TypeSerializationLibrary lib = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
    lib.add(Vector3f.class, new Vector3fTypeHandler());
    lib.add(Quat4f.class, new Quat4fTypeHandler());
    entitySystemLibrary = new EntitySystemLibrary(context, lib);
    componentLibrary = entitySystemLibrary.getComponentLibrary();
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
    assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ContextImpl(org.terasology.context.internal.ContextImpl) ModuleManager(org.terasology.engine.module.ModuleManager) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) Vector3fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Vector3fTypeHandler) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) Quat4fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) Before(org.junit.Before)

Example 7 with ReflectionReflectFactory

use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method addReflectionBasedLibraries.

public static void addReflectionBasedLibraries(Context context) {
    ReflectionReflectFactory reflectFactory = new ReflectionReflectFactory();
    context.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    TypeRegistry typeRegistry = context.get(TypeRegistry.class);
    TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
    context.put(TypeHandlerLibrary.class, typeHandlerLibrary);
    EntitySystemLibrary library = new EntitySystemLibrary(context, typeHandlerLibrary);
    context.put(EntitySystemLibrary.class, library);
    context.put(ComponentLibrary.class, library.getComponentLibrary());
    context.put(EventLibrary.class, library.getEventLibrary());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry)

Example 8 with ReflectionReflectFactory

use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.

the class UniverseSetupScreen method setEnvironment.

/**
 * This method switches the environment of the game to a temporary one needed for
 * creating a game. It creates a new {@link Context} and only puts the minimum classes
 * needed for successful game creation.
 * @param wrapper takes the {@link AdvancedGameSetupScreen} and pushes it into the new context.
 */
public void setEnvironment(UniverseWrapper wrapper) {
    context = new ContextImpl();
    CoreRegistry.setContext(context);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    context.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    context.put(NUIManager.class, getManager());
    context.put(UniverseSetupScreen.class, this);
    assetTypeManager = new AutoReloadAssetTypeManager();
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    context.put(ModuleManager.class, moduleManager);
    context.put(UniverseWrapper.class, wrapper);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        context.put(ModuleEnvironment.class, environment);
        context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
        initAssets();
        EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
        context.put(EnvironmentSwitchHandler.class, environmentSwitcher);
        environmentSwitcher.handleSwitchToPreviewEnvironment(context, environment);
    }
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Aggregations

ReflectionReflectFactory (org.terasology.reflection.reflect.ReflectionReflectFactory)8 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)7 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)5 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)4 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)3 Before (org.junit.Before)2 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)2 ContextImpl (org.terasology.context.internal.ContextImpl)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 ModuleManager (org.terasology.engine.module.ModuleManager)2 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)2 AutoReloadAssetTypeManager (org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)2 Benchmark (org.terasology.benchmark.Benchmark)1 PrintToConsoleCallback (org.terasology.benchmark.PrintToConsoleCallback)1 Config (org.terasology.config.Config)1 Config (org.terasology.engine.config.Config)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)1 ModuleManagerImpl (org.terasology.engine.module.ModuleManagerImpl)1