Add support for "dup" label
authorHugo Villeneuve <hugo@hugovil.com>
Sat, 7 Oct 2023 03:13:52 +0000 (23:13 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Sat, 7 Oct 2023 15:51:24 +0000 (11:51 -0400)
fgen.sh

diff --git a/fgen.sh b/fgen.sh
index 1e92b1e..d60da59 100755 (executable)
--- a/fgen.sh
+++ b/fgen.sh
@@ -79,6 +79,22 @@ function get_group_id()
     echo "${group}"
 }
 
+# Get duplicate from. Ex: "label:dup1-7 planXYZ,geometry..." will return 1
+# Arg1: line
+function get_dup_from()
+{
+    dup=$(echo "${1}" | grep -e "label:dup.*" | ${SED} "s/.*label:dup\([0-9]\+\)-.*,geometry.*/\1/g")
+    echo "${dup}"
+}
+
+# Get duplicate to. Ex: "label:dup1-7 planXYZ,geometry..." will return 7
+# Arg1: line
+function get_dup_to()
+{
+    dup=$(echo "${1}" | grep -e "label:dup.*" | ${SED} "s/.*label:dup[0-9]\+-\([0-9]\+\).*,geometry.*/\1/g")
+    echo "${dup}"
+}
+
 print_usage()
 {
     echo "${PROG_NAME} -- Générateur de séquence d'images PNG à partir d'un fichier Photoshop (PSD)."
@@ -192,6 +208,14 @@ if [ ${trames} -eq 1 ]; then
         nf=$(get_frame_id "${l}")
         ng=$(get_group_id "${l}")
 
+        dup_from=$(get_dup_from "${l}")
+        dup_to=$(get_dup_to "${l}")
+
+        # Also indicate a new frame, but to be copied from..to:
+        if [ x"${dup_from}" != x"" ]; then
+            nf=${dup_from}
+        fi
+
         # Only change group if ng is set...
         if [ x"${ng}" != x"" ]; then
             if which ffmpeg 1> /dev/null 2>&1; then
@@ -244,6 +268,19 @@ if [ ${trames} -eq 1 ]; then
                         ${dest}/${group}-f${nf}.png
             fi
 
+            if [ x"${dup_from}" != x"" ]; then
+                log_dbg "  dup from: ${dup_from}"
+                log_dbg "  dup to:   ${dup_to}"
+
+                dup_start=$((${dup_from} + 1))
+                for w in $(seq ${dup_start} ${dup_to}); do
+                    log_dbg "New frame ID: ${w} (duplicate)"
+
+                    # Use symlink???
+                    cp ${dest}/${group}-f${nf}.png ${dest}/${group}-f${w}.png
+                done
+            fi
+
             files=""
             oldnf="${nf}"
         fi