mkxp/extra/make_mapping.sh

37 lines
788 B
Bash
Raw Normal View History

2020-05-07 06:57:51 +00:00
#!/bin/bash
echo "var mapping = {" > mapping.js
2020-10-19 21:43:10 +00:00
echo "var bitmapSizeMapping = {" > bitmap-map.js
2020-05-07 06:57:51 +00:00
2020-10-20 06:25:29 +00:00
for file in {*,*/*,*/**/*,*/**/**/*}
2020-05-07 06:57:51 +00:00
do
filename="${file%.*}"
fl="$(echo "$filename" | tr '[:upper:]' '[:lower:]')"
2020-10-18 19:22:59 +00:00
2020-10-20 06:25:29 +00:00
if [ -f "${file}" ]
2020-10-18 19:22:59 +00:00
then
md5=`md5sum "${file}" | awk '{ print $1 }'`
2020-05-07 06:57:51 +00:00
2020-10-19 21:43:10 +00:00
sz=`identify -format "%w,%h" "${file}" 2>/dev/null`
if [ $? -eq 0 ]; then
2020-10-20 00:18:27 +00:00
convert "$file" -resize 64x64\> "conv.png"
mimetype=$(file -bN --mime-type "conv.png")
content=$(base64 -w0 < "conv.png")
duri="data:$mimetype;base64,$content"
rm "conv.png"
echo "\"$fl\": [${sz},\"${duri}\"]," >> bitmap-map.js
2020-10-19 21:43:10 +00:00
fi
2020-10-20 06:25:29 +00:00
else
md5=''
2020-10-19 21:43:10 +00:00
fi
2020-10-20 06:25:29 +00:00
echo "\"$fl\": \"${file}?h=${md5}\"," >> mapping.js
2020-05-07 06:57:51 +00:00
done
echo "};" >> mapping.js
2020-10-19 21:43:10 +00:00
echo "};" >> bitmap-map.js
2020-05-07 06:57:51 +00:00