From f2c745de664f8cc0592a66b0663bb2869e7f1467 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Sun, 24 Dec 2023 16:19:13 +0100 Subject: showKingdom.sh now uses local files and other minor fixes. --- games/dominion/showKingdom.sh | 74 +++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'games/dominion/showKingdom.sh') diff --git a/games/dominion/showKingdom.sh b/games/dominion/showKingdom.sh index e405867..dd4b3a2 100755 --- a/games/dominion/showKingdom.sh +++ b/games/dominion/showKingdom.sh @@ -2,11 +2,13 @@ # showKingdom.sh: Shows the images of a card list received as input # -# Usage: showKingdom.sh +# Needs card images in ./local/share/dominion/cards +# +# Usage: showKingdom.sh [-oi] scriptName="${0##*/}" -usageMessage="Usage: ${scriptName}" +usageMessage="Usage: ${scriptName} [-oi]" error() { printf '%s error: %s\n' "$scriptName" "$*" >&2 @@ -16,27 +18,57 @@ errorAndUsage() { printf '%s error: %s\n%s\n' "$scriptName" "$*" "$usageMessage" >&2 } -outputDirBase='/tmp/showKingdom' -outputDir="${outputDirBase}/$(date '+%y%m%d%H%M%S')" -[ -d "$outputDir" ] || mkdir -p "$outputDir" +dir="${HOME}/.local/share/dominion/cards" -counter=1 +if ! [ -d "$dir" ]; then + error "Needed ${dir} directory not found." + exit 1 +fi -while read -r card; do - name="$(echo "$card" | grep -Eo '[A-Za-z][A-Za-z ]*[A-Za-z]' | sed 's/ /_/g')" - - # Avoid redownload if image exists already - existingFile="$(find "$outputDirBase" -name "${name}.jpg" | sed 1q)" - if [ -n "$existingFile" ]; then - if ! cp "$existingFile" "$outputDir"; then - # If copy fails, assume file exists and copy it with an appended counter - cp "$existingFile" "${outputDir}/${name}${counter}.jpg" - counter=$((counter+1)) - fi - else - wget "https://robinzigmond.github.io/Dominion-app/images/card_images/${name}.jpg" --directory-prefix="$outputDir" - fi +PRINT_SELECTION='' +OUTPUT_AS_IMAGE='' +TMP_IMAGE='showKingdom.jpg' + +# Process options +while getopts 'oi' opt; do + case $opt in + + 'o' ) + PRINT_SELECTION='y' + ;; + + 'i' ) + OUTPUT_AS_IMAGE='y' + ;; + '?' ) + printf '%s\n' "$usageMessage" >&2 + exit 1 + + esac done -sxiv -tb "$outputDir" & +shift $((OPTIND - 1)) + +if [ -n "$PRINT_SELECTION" ] && [ -n "$OUTPUT_AS_IMAGE" ]; then + error 'Can not use visually filter cards with this configuration.' + exit 1 +fi + +while read -r card; do + name="$(echo "$card" | grep -Eo '[A-Za-z].*[A-Za-z]' | sed 's/[ \/]/_/g')" + find "${dir}" -name "${name}.jpg" +done | + if [ -n "$OUTPUT_AS_IMAGE" ]; then + oldIFS="$IFS" + IFS=$'\n' + montage $(cat -) -tile '5x' -mode 'concatenate' -background 'black' "$TMP_IMAGE" + magick "$TMP_IMAGE" -trim "$TMP_IMAGE" + sxiv "$TMP_IMAGE" || termux-open "$TMP_IMAGE" + rm "$TMP_IMAGE" + IFS="$oldIFS" + elif [ -n "$PRINT_SELECTION" ]; then + sxiv -iotb | sed 's|^/.*/||;s|_| |g;s|.jpg$||' + else + sxiv -itb & + fi -- cgit v1.2.1