tools/render-timelapse (view raw, download)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#!/bin/bash
if [[ $# -lt 1 ]]
then
echo "Usage: ./render-timelapse <FILE_PATH> [OUTPUT_DIR]"
echo -e "\texample: ./render-images ./file_path/FOO.WAD"
echo -e "\texample: ./render-images ./FOO.WAD /tmp/output"
exit 1
fi
if ! [ -x "$(command -v wad2svg)" ]
then
echo "This script requires the program 'wad2svg'"
exit 1
fi
MAP_FILENAME=$(basename "$1")
GIT_DIR=$(echo ${1::-"$((${#MAP_FILENAME} + 1))"})
OUTPUT_DIR="${2-"${GIT_DIR}/timelapse-output"}"
if [ ! -d "$GIT_DIR/.git" ] || ! git -C "$GIT_DIR" rev-parse 2>/dev/null
then
echo "'${GIT_DIR}' must be an initialised GIT directory"
fi
IWAD_PATH=~/doom/DOOM2.WAD
map_name="map01"
shopt -s nocasematch
if [[ "$IWAD_PATH" =~ doom\.wad$ ]]
then
map_name="e1m1"
fi
shopt -u nocasematch
mkdir -p "$OUTPUT_DIR"
echo -n "Collecting up map versions "
count=$((0))
for commit in $(git -C "$GIT_DIR" log --reverse --format=format:%at_%h)
do
echo -n .
timestamp=$(echo $commit | cut -d_ -f1)
sha=$(echo $commit | cut -d_ -f2)
git -C "$GIT_DIR" show \
${sha}:${MAP_FILENAME} \
> ${OUTPUT_DIR}/.${timestamp}_${sha}.${MAP_FILENAME}
((count++))
done
echo "done ($count)"
echo -n "Converting map versions to SVGs "
count=$((0))
shopt -s nocaseglob
for file in $OUTPUT_DIR/.*.WAD
do
echo -n .
wad2image $file -c yadex -i "$IWAD_PATH" -o "$OUTPUT_DIR" --thing-scale 2 --scale 0.1 --thickness 2 --width 640 --height 480
mv "$OUTPUT_DIR/${map_name}.png" -- "${file}.png"
((count++))
done
echo "done ($count)"
echo -n "Combining images into animated GIF ... "
OUTPUT_ARTEFACT_PATH="${OUTPUT_DIR}/${MAP_FILENAME}.gif"
shopt -s extglob nullglob
magick "$OUTPUT_DIR"/.*.@(svg|png) +repage -delay 10 "$OUTPUT_ARTEFACT_PATH"
echo \ done
echo -e "Output: '${OUTPUT_ARTEFACT_PATH}'"
|