From 8c850d22b41039feba541b57b4eef29fbd97e672 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Mon, 12 Sep 2022 11:20:07 +0200 Subject: [PATCH] Add parse_offsets utility script --- app/parse_offsets.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/parse_offsets.py diff --git a/app/parse_offsets.py b/app/parse_offsets.py new file mode 100644 index 0000000..0b3e5b2 --- /dev/null +++ b/app/parse_offsets.py @@ -0,0 +1,45 @@ +import json +import logging +import argparse +import sys + +logger = logging.getLogger("svganim.fixer") +argParser = argparse.ArgumentParser( + description="Helper tool to fix timings after glitch" +) +argParser.add_argument( + "--input", type=str, help="Filename to run on (.json_appendable)" +) +args = argParser.parse_args() + + +with open(args.input, "r") as fp: + events = json.loads("[" + fp.read() + "]") + time_offset = 0 + for i, event in enumerate(events): + if type(event) is list: + pass + elif event['event'] == "offset": + time_offset += event['offset'] + # print a reverseable event that is ignored by this script + event = { + 'event': 'added_offset', + 'offset': event['offset'] + } + elif event['event'] == 'added_offset': + logger.warning('ignore existing offset') + continue + + elif event["event"] == "viewbox": + for key, box in enumerate(event['viewboxes']): + event['viewboxes'][key]['t'] += time_offset + elif event["event"] == "stroke": + event['points'] = [[p[0], p[1], p[2], p[3] + time_offset] + for p in event['points']] + + if i>0: + sys.stdout.write(",\n") + sys.stdout.write(json.dumps(event)) + +if time_offset == 0: + logger.warning('\n\nNo offset defined in file, please do so by adding {"event":"offset", "offset": miliseconds} at the line from which the offset should be added.') \ No newline at end of file