Search in sources :

Example 1 with ComponentSerializer

use of org.terasology.engine.persistence.serializers.ComponentSerializer in project Terasology by MovingBlocks.

the class ComponentSerializerTest method setup.

@BeforeEach
public void setup() {
    context = new ContextImpl();
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    context.put(ModuleManager.class, moduleManager);
    CoreRegistry.setContext(context);
    Reflections reflections = new Reflections(getClass().getClassLoader());
    TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
    serializationLibrary.addTypeHandler(Vector3f.class, new Vector3fTypeHandler());
    serializationLibrary.addTypeHandler(Quaternionf.class, new QuaternionfTypeHandler());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "integer"), IntegerComponent.class);
    ComponentLibrary componentLibrary = entityManager.getComponentLibrary();
    componentSerializer = new ComponentSerializer(componentLibrary, serializationLibrary);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) QuaternionfTypeHandler(org.terasology.engine.persistence.typeHandling.mathTypes.QuaternionfTypeHandler) Vector3fTypeHandler(org.terasology.engine.persistence.typeHandling.mathTypes.Vector3fTypeHandler) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) NetworkSystem(org.terasology.engine.network.NetworkSystem) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) TypeHandlerLibraryImpl(org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ComponentSerializer(org.terasology.engine.persistence.serializers.ComponentSerializer) Reflections(org.reflections.Reflections) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)1 Reflections (org.reflections.Reflections)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 ComponentSerializer (org.terasology.engine.persistence.serializers.ComponentSerializer)1 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)1 QuaternionfTypeHandler (org.terasology.engine.persistence.typeHandling.mathTypes.QuaternionfTypeHandler)1 Vector3fTypeHandler (org.terasology.engine.persistence.typeHandling.mathTypes.Vector3fTypeHandler)1 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)1