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));
}
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();
}
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);
}
}
Aggregations