aboutsummaryrefslogtreecommitdiff
path: root/mapGen/mapGen.sh
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2020-05-17 21:05:36 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2020-05-17 21:05:36 +0200
commitdffcc04d93ea8aa1331f8bb3dbb97875f84e0926 (patch)
tree51a9fb7be677bdb75f8da65a1ea84183c7432e43 /mapGen/mapGen.sh
parent4e7cf6c285f1e932a04e16cf144917333b78e579 (diff)
downloadscripts-dffcc04d93ea8aa1331f8bb3dbb97875f84e0926.tar.gz
scripts-dffcc04d93ea8aa1331f8bb3dbb97875f84e0926.zip
Organized mapGen.sh
Diffstat (limited to 'mapGen/mapGen.sh')
-rwxr-xr-xmapGen/mapGen.sh28
1 files changed, 26 insertions, 2 deletions
diff --git a/mapGen/mapGen.sh b/mapGen/mapGen.sh
index 1be77f7..bf4bac3 100755
--- a/mapGen/mapGen.sh
+++ b/mapGen/mapGen.sh
@@ -3,13 +3,37 @@
# mapGen.sh
#
# Generate a map with ImageMagick from an input text file
+#
+# Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] SOURCE_FILE
-inputFile="$1"
+usageMsg="Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] SOURCE_FILE"
cellSize=8
tilesDir="./tiles"
+while echo "$1" | grep '^-' >/dev/null; do
+ case "$1" in
+ "-s")
+ [ -z "$2" ] && echo "Missing argument for -s. $usageMsg" >&2 && exit 1
+ cellSize="$2"
+ shift 2
+ ;;
+ "-f")
+ [ -z "$2" ] && echo "Missing argument for -f. $usageMsg" >&2 && exit 1
+ tilesDir="$2"
+ shift 2
+ ;;
+ esac
+done
+
+[ -z "$1" ] && echo "$usageMsg" >&2 && exit 1
+
+inputFile="$1"
+
+[ ! -f "$inputFile" ] && echo "File not found: $inputFile" >&2 && exit 1
+[ ! -d "$tilesDir" ] && echo "Directory not found: $tilesDir" >&2 && exit 1
+
height="$(wc -l <"$inputFile")"
width="$(awk '{print length($0)}' "$inputFile" | sort -nr | sed 1q)"
@@ -26,7 +50,7 @@ col=0
while read line; do
echo "$line" | (
while read -n1 char; do
- tileFile="$(find $tilesDir | sed 's|.*/||' | grep "^$char")"
+ tileFile="$(find $tilesDir | sed 's|.*/||' | grep "^$char" | shuf | sed 1q)"
tileFile="${tilesDir}/${tileFile}"
echo "$tileFile" | wc -l | grep 1 >/dev/null || continue
convert out.jpg "$tileFile" -geometry +"$col"+"$row" -composite out.jpg ||