#!/bin/bash if [[ $# -ne 2 ]] then echo "Usage: ./render-timelapse " echo -e "\texample: ./render-images ./file_path/FOO.WAD out" 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" 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 WAD_DIR=~/doom/DOOM2.WAD mkdir -p "$OUTPUT_DIR" echo -n "Collecting up map versions " 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} done echo \ done echo -n "Converting map versions to SVGs " for file in $OUTPUT_DIR/.*.WAD do echo -n . # TODO Branch on optional param (wad2svg|wadimage|etc) #wad2svg $file MAP01 --image_height 640 --image_width 480 > "${file}.svg" 2>/dev/null wad2image $file -c yadex -n 1 -i "$WAD_DIR" -o "$OUTPUT_DIR" --thing-scale 2 -t 3 mv "$OUTPUT_DIR/map01.png" -- "${file}.png" done echo \ done echo -n "Combining SVGs into animated GIF ... " OUTPUT_ARTEFACT_PATH="${OUTPUT_DIR}/${MAP_FILENAME}.gif" shopt -s extglob nullglob magick "$OUTPUT_DIR"/.*.@(svg|png) -gravity center -crop 1:1 +repage -resize 800x800 -loop 1 -delay 10 "$OUTPUT_ARTEFACT_PATH" echo \ done echo -e "Output: '${OUTPUT_ARTEFACT_PATH}'"