aboutsummaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2023-12-24 16:19:13 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2023-12-24 16:25:11 +0100
commitf2c745de664f8cc0592a66b0663bb2869e7f1467 (patch)
tree1bd02840bdf68d0b4a0c5fe8307c795e14d3ba3f /games
parentff111234882691d1678ffb3b8d4d2c95ed65e84f (diff)
downloadscripts-f2c745de664f8cc0592a66b0663bb2869e7f1467.tar.gz
scripts-f2c745de664f8cc0592a66b0663bb2869e7f1467.zip
showKingdom.sh now uses local files and other minor fixes.
Diffstat (limited to 'games')
-rwxr-xr-xgames/dominion/showKingdom.sh74
1 files changed, 53 insertions, 21 deletions
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