Search in sources :

Example 1 with ModuleAwareAssetTypeManager

use of org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupEmptyAssetManager.

@Override
protected AssetManager setupEmptyAssetManager() {
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
    context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    return assetTypeManager.getAssetManager();
}
Also used : ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)

Example 2 with ModuleAwareAssetTypeManager

use of org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager in project Terasology by MovingBlocks.

the class PojoPrefabManagerTest method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ModuleAwareAssetTypeManager

use of org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager in project Terasology by MovingBlocks.

the class PrefabTest method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    AssetType<Prefab, PrefabData> prefabDataAssetType = assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
    TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
    assetTypeManager.getAssetFileDataProducer(prefabDataAssetType).addAssetFormat(prefabFormat);
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) PrefabFormat(org.terasology.engine.entitySystem.prefab.internal.PrefabFormat) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ModuleAwareAssetTypeManager

use of org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager in project Terasology by MovingBlocks.

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

Example 5 with ModuleAwareAssetTypeManager

use of org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager 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)

Aggregations

ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)12 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)8 ModuleManager (org.terasology.engine.core.module.ModuleManager)7 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)7 ContextImpl (org.terasology.engine.context.internal.ContextImpl)6 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)6 BeforeAll (org.junit.jupiter.api.BeforeAll)4 Context (org.terasology.engine.context.Context)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RenderingSubsystemFactory (org.terasology.engine.core.subsystem.RenderingSubsystemFactory)2 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)2 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)2 PrefabFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabFormat)2 MeshAnimation (org.terasology.engine.rendering.assets.animation.MeshAnimation)2 MeshAnimationImpl (org.terasology.engine.rendering.assets.animation.MeshAnimationImpl)2 Atlas (org.terasology.engine.rendering.assets.atlas.Atlas)2 Font (org.terasology.engine.rendering.assets.font.Font)2 FontImpl (org.terasology.engine.rendering.assets.font.FontImpl)2 Material (org.terasology.engine.rendering.assets.material.Material)2