Search in sources :

Example 1 with LoadMetadata

use of com.helospark.tactview.core.save.LoadMetadata in project tactview by helospark.

the class GraphProviderFactory method deserialize.

@Override
public GraphProvider deserialize(JsonNode data, SavedContentAddable<?> currentFieldValue, LoadMetadata loadMetadata) {
    ObjectMapper mapper = loadMetadata.getObjectMapperUsed();
    Map<ConnectionIndex, List<ConnectionIndex>> connections = mapper.convertValue(data.get("connections"), new TypeReference<Map<ConnectionIndex, List<ConnectionIndex>>>() {
    });
    List<GraphElementFactory> factories = loadMetadata.getLightDiContext().getListOfBeans(GraphElementFactory.class);
    Map<GraphIndex, GraphElement> graph = new LinkedHashMap<>();
    for (var element : data.get("graph")) {
        String factoryId = element.get("factoryId").asText();
        GraphElement restoredElement = factories.stream().filter(a -> a.getId().equals(factoryId)).findFirst().get().restoreElement(element.get("object"), loadMetadata);
        GraphIndex id = new GraphIndex(element.get("id").asText());
        graph.put(id, restoredElement);
    }
    return new GraphProvider(new EffectGraph(graph, connections));
}
Also used : EffectGraph(com.helospark.tactview.core.timeline.effect.interpolation.graph.EffectGraph) GraphElement(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElement) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ArrayList(java.util.ArrayList) DesSerFactory(com.helospark.tactview.core.util.DesSerFactory) LinkedHashMap(java.util.LinkedHashMap) ConnectionIndex(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.ConnectionIndex) List(java.util.List) GraphIndex(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.GraphIndex) GraphElementFactory(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElementFactory) Map(java.util.Map) SaveMetadata(com.helospark.tactview.core.save.SaveMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SavedContentAddable(com.helospark.tactview.core.util.SavedContentAddable) EffectGraph(com.helospark.tactview.core.timeline.effect.interpolation.graph.EffectGraph) GraphElementFactory(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElementFactory) ConnectionIndex(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.ConnectionIndex) LinkedHashMap(java.util.LinkedHashMap) GraphIndex(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.GraphIndex) GraphElement(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElement) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with LoadMetadata

use of com.helospark.tactview.core.save.LoadMetadata in project tactview by helospark.

the class CommonEffectTest method testThatEffectCanBeSavedAndRestored.

@Test
public void testThatEffectCanBeSavedAndRestored() throws IOException {
    LightDiContext lightDi = IntegrationTestUtil.startContext();
    List<EffectFactory> effectFactories = lightDi.getListOfBeans(EffectFactory.class);
    FakeUi fakeUi = lightDi.getBean(FakeUi.class);
    VisualTimelineClip clip = (VisualTimelineClip) fakeUi.dragProceduralClipToFirstChannel("singlecolor", TimelinePosition.ofZero());
    for (var effectFactory : effectFactories) {
        StatelessEffect effect = effectFactory.createEffect(new CreateEffectRequest(TimelinePosition.ofZero(), effectFactory.getEffectId(), TimelineClipType.VIDEO, clip.getInterval()));
        if (!(effect instanceof StatelessVideoEffect)) {
            continue;
        }
        if (!(effect instanceof StatelessVideoEffect) || effectFactory.getEffectId().equals("lensdistort")) /**
         * trello.201, check why this occasionally fails
         */
        {
            continue;
        }
        ReadOnlyClipImage originalFrame = getFrame((StatelessVideoEffect) effect, clip);
        SaveMetadata saveMetadata = new SaveMetadata(false);
        Object savedEffect = effect.generateSavedContent(saveMetadata);
        String saveData = createObjectMapper(saveMetadata).writeValueAsString(savedEffect);
        JsonNode readData = StaticObjectMapper.objectMapper.readTree(saveData);
        StatelessEffect restoredEffect = effectFactory.restoreEffect(readData, new LoadMetadata("filepath", StaticObjectMapper.objectMapper, lightDi));
        ReadOnlyClipImage clonedFrame = getFrame((StatelessVideoEffect) restoredEffect, clip);
        IntegrationTestUtil.assertFrameEquals(originalFrame, clonedFrame, effectFactory.getEffectId() + " is generating different image after save and restore");
        freeFrame(originalFrame);
        freeFrame(clonedFrame);
    }
    lightDi.close();
}
Also used : LightDiContext(com.helospark.lightdi.LightDiContext) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) SaveMetadata(com.helospark.tactview.core.save.SaveMetadata) FakeUi(com.helospark.tactview.core.it.util.ui.FakeUi) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) StatelessVideoEffect(com.helospark.tactview.core.timeline.StatelessVideoEffect) CreateEffectRequest(com.helospark.tactview.core.timeline.effect.CreateEffectRequest) Test(org.junit.jupiter.api.Test)

Example 3 with LoadMetadata

use of com.helospark.tactview.core.save.LoadMetadata in project tactview by helospark.

the class SubtimelineLoadFileService method getLoadData.

public LoadData getLoadData(AddClipRequest request, String nodeName) {
    try {
        ObjectMapper mapper = StaticObjectMapper.objectMapper;
        File tmpDir = new File(System.getProperty("java.io.tmpdir"));
        File rootDirectory = new File(tmpDir, "tactview_save_" + System.currentTimeMillis());
        ZipUtil.unpack(new File(request.getFile().getAbsolutePath()), rootDirectory);
        File fileName = new File(rootDirectory.getAbsolutePath(), TemplateSaveAndLoadHandler.TEMPLATE_FILE_NAME);
        String content = new String(Files.readAllBytes(Paths.get(fileName.getAbsolutePath())), StandardCharsets.UTF_8);
        JsonNode tree = mapper.readTree(content);
        LoadMetadata loadMetadata = new LoadMetadata(rootDirectory.getAbsolutePath(), mapper, context);
        LoadData loadData = new LoadData(tree.get(nodeName), loadMetadata);
        return loadData;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StaticObjectMapper(com.helospark.tactview.core.util.StaticObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LoadMetadata (com.helospark.tactview.core.save.LoadMetadata)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SaveMetadata (com.helospark.tactview.core.save.SaveMetadata)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 LightDiContext (com.helospark.lightdi.LightDiContext)1 FakeUi (com.helospark.tactview.core.it.util.ui.FakeUi)1 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)1 StatelessVideoEffect (com.helospark.tactview.core.timeline.StatelessVideoEffect)1 VisualTimelineClip (com.helospark.tactview.core.timeline.VisualTimelineClip)1 CreateEffectRequest (com.helospark.tactview.core.timeline.effect.CreateEffectRequest)1 EffectFactory (com.helospark.tactview.core.timeline.effect.EffectFactory)1 EffectGraph (com.helospark.tactview.core.timeline.effect.interpolation.graph.EffectGraph)1 ConnectionIndex (com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.ConnectionIndex)1 GraphIndex (com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.GraphIndex)1 GraphElement (com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElement)1 GraphElementFactory (com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElementFactory)1 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)1 DesSerFactory (com.helospark.tactview.core.util.DesSerFactory)1 SavedContentAddable (com.helospark.tactview.core.util.SavedContentAddable)1