From 97ab6a5832441e5cccfbcc149e5062a070286e35 Mon Sep 17 00:00:00 2001 From: skybldev Date: Fri, 30 Aug 2024 10:22:46 -0400 Subject: [PATCH] backup commit --- index.js | 9 ++++++--- test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test.js diff --git a/index.js b/index.js index f1b1f48..35a0678 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ program .option("-i, --stdin", "read the base keyframe data from stdin") .option("-r, --round", "round all generated values.\nyou can set this in the KE_ROUND environment variable", KE_ROUND) .addHelpText("beforeAll", "kdenease.js - generate eases for kdenlive using a cubic bezier curve") - .addHelpText("after", "you can use -i to read keyframe data from stdin and overwrite the selected values to the generated values."); + .addHelpText("after", "\nyou can use -i to read keyframe data from stdin and overwrite the selected values to the generated values."); function decodeKeyframes(kfString) { let out = {}; @@ -191,8 +191,11 @@ async function main() { } else { for (let frame in newValues) { if (!baseJSON.value.hasOwnProperty(frame)) { - const lastFrame = (frame - 1).toString(); - const l = baseJSON.value[lastFrame]; + const l = (() => { // last existing keyframe's value + for (let f = parseInt(frame); f >= firstFrame; f--) { + if (baseJSON.value.hasOwnProperty(f)) return baseJSON.value[f]; + } + })(); baseJSON.value[frame] = { x: l.x, y: l.y, w: l.w, h: l.h }; } diff --git a/test.js b/test.js new file mode 100644 index 0000000..2c4f203 --- /dev/null +++ b/test.js @@ -0,0 +1,26 @@ +const a = { + "2100": 30, + "2101": 31, + "2102": 32, + "2103": 33, +}; + +const b = { + "2100": 31, + "2101": 32, + "2102": 33, + "2103": 34, + "2104": 35, + "2105": 36, + "2106": 37 +}; + +for (let el in b) { + if (!a[el]) { + a[el] = a[el - 1]; + } + + a[el] = b[el]; + console.dir({ element: el, value: a }); +} +