2014-09-28 05:53:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# See https://developer.apple.com/library/ios/qa/qa1686/_index.html
|
2014-09-30 04:01:33 +00:00
|
|
|
cd "${BASH_SOURCE%/*}"
|
2014-09-28 05:53:50 +00:00
|
|
|
source bashlib
|
2018-06-05 18:44:54 +00:00
|
|
|
trap 'echo >&2 "ERROR: $?: $BASH_COMMAND"' ERR
|
2018-06-05 19:09:11 +00:00
|
|
|
set -e
|
2014-09-30 04:01:33 +00:00
|
|
|
cd ..
|
2017-03-06 22:25:59 +00:00
|
|
|
export PATH+=:/usr/local/bin
|
2014-09-28 05:53:50 +00:00
|
|
|
|
|
|
|
# icons format: [pixel size]@[scale]@[idiom]@[os]:[filename] -- if os is "anything lower", omit it
|
|
|
|
icons=(
|
2014-10-26 17:26:41 +00:00
|
|
|
# Mac
|
|
|
|
16@1@mac@:
|
|
|
|
32@2@mac@:
|
|
|
|
32@1@mac@:
|
|
|
|
64@2@mac@:
|
|
|
|
128@1@mac@:
|
|
|
|
256@2@mac@:
|
|
|
|
256@1@mac@:
|
|
|
|
512@2@mac@:
|
|
|
|
512@1@mac@:
|
|
|
|
1024@2@mac@:
|
|
|
|
# iPhone
|
2014-09-28 05:53:50 +00:00
|
|
|
180@3@iphone@8.0:Icon-60@3x.png
|
|
|
|
120@3@iphone@8.0:Icon-Small-40@3x.png
|
|
|
|
120@2@iphone@7.0:Icon-60@2x.png
|
|
|
|
80@2@iphone@7.0:Icon-Small-40@2x.png
|
|
|
|
# 114@2@iphone@:Icon@2x.png
|
|
|
|
87@3@iphone@:Icon-Small@3x.png
|
|
|
|
58@2@iphone@:Icon-Small@2x.png
|
|
|
|
# 57@1@iphone@:Icon.png
|
|
|
|
# 29@1@iphone@:Icon-Small.png
|
2014-10-26 17:26:41 +00:00
|
|
|
# iPad
|
2014-09-28 05:53:50 +00:00
|
|
|
76@1@ipad@7.0:Icon-76.png
|
|
|
|
152@2@ipad@7.0:Icon-76@2x.png
|
|
|
|
40@1@ipad@7.0:Icon-Small-40.png
|
|
|
|
80@2@ipad@7.0:Icon-Small-40@2x.png
|
|
|
|
29@1@ipad@:Icon-Small.png
|
|
|
|
58@2@ipad@:Icon-Small@2x.png
|
|
|
|
# 72@1@ipad@:Icon-72.png
|
|
|
|
# 144@2@ipad@:Icon-72@2x.png
|
|
|
|
# 50@1@ipad@:Icon-Small-50.png
|
|
|
|
# 100@2@ipad@:Icon-Small-50@2x.png
|
|
|
|
)
|
|
|
|
# splashes format: [size name]@[scale]@[idiom]@[os] -- if scale is 1, omit it. if os is "anything lower", omit it
|
|
|
|
splashes=(
|
|
|
|
414-736@3@iphone@8.0
|
|
|
|
375-667@2@iphone@8.0
|
|
|
|
320-568@2@iphone@7.0
|
|
|
|
320-568@2@iphone@
|
|
|
|
320-480@2@iphone@7.0
|
|
|
|
320-480@2@iphone@
|
|
|
|
320-480@@iphone@
|
|
|
|
)
|
|
|
|
|
|
|
|
copyImage() {
|
2018-06-05 19:09:11 +00:00
|
|
|
trap 'echo >&2 "ERROR: $?: $BASH_COMMAND"' ERR
|
|
|
|
set -e
|
2014-09-28 05:53:50 +00:00
|
|
|
local src=$1 dst=$2
|
|
|
|
|
|
|
|
if [[ $src = *.9.png || $src = *.9@*.png ]]; then
|
2014-11-18 12:21:56 +00:00
|
|
|
pinf '%s -> %s (ninepatch)' "${src##*/}" "${dst##*/}"
|
2014-11-18 12:17:28 +00:00
|
|
|
niftyNinePatch=$(java -Dapple.awt.UIElement=true -jar Scripts/NiftyNinePatchHelper.jar "$src" "$dst") || return
|
2014-09-28 05:53:50 +00:00
|
|
|
while IFS='=' read var value; do
|
|
|
|
[[ $var = imageMode ]] && value=${value#'"resize:'} value=${value%'"'} && IFS=, read capLeft capWidth capRight capTop _ _ _ capHeight _ _ _ capBottom <<< "$value"
|
|
|
|
[[ $var = padding ]] && IFS=, read paddingTop paddingRight paddingBottom paddingLeft <<< "${value//[px\"]}"
|
|
|
|
uinf 'caps: [%d, %d, %d, %d], padding: [%d, %d, %d, %d]' "$capTop" "$capRight" "$capBottom" "$capLeft" "$paddingTop" "$paddingRight" "$paddingBottom" "$paddingLeft"
|
|
|
|
printf ',"resizing":{"capInsets":{"bottom":%d,"left":%d,"right":%d,"top":%d},"center":{"height":%d,"mode":"fill","width":%d},"mode":"9-part"}' \
|
|
|
|
"$capBottom" "$capLeft" "$capRight" "$capTop" "$capHeight" "$capWidth"
|
|
|
|
done <<< "$niftyNinePatch"
|
|
|
|
fnip
|
|
|
|
else
|
2018-06-05 19:09:11 +00:00
|
|
|
echo >&2 'pinf'
|
2014-11-18 12:23:26 +00:00
|
|
|
pinf '%s -> %s' "${src##*/}" "${dst##*/}"
|
2018-06-05 19:09:11 +00:00
|
|
|
echo >&2 'cp <$src> <$dst>'
|
2014-09-28 05:53:50 +00:00
|
|
|
cp "$src" "$dst"
|
2018-06-05 19:09:11 +00:00
|
|
|
echo >&2 'fnip'
|
2014-09-28 05:53:50 +00:00
|
|
|
fnip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-06 22:25:59 +00:00
|
|
|
xcassets=Resources/Media/Images.xcassets
|
2014-09-28 05:53:50 +00:00
|
|
|
appiconset="$xcassets/AppIcon.appiconset"
|
|
|
|
launchimage="$xcassets/LaunchImage.launchimage"
|
2017-03-06 22:25:59 +00:00
|
|
|
ios_icon=Resources/Media/ios/icon
|
|
|
|
ios_launch=Resources/Media/ios/launch
|
|
|
|
mac_icon=Resources/Media/mac/icon
|
2014-09-28 05:53:50 +00:00
|
|
|
|
2014-10-26 17:26:41 +00:00
|
|
|
if [[ "$(latest "$ios_icon"/*)" -nt "$appiconset/Contents.json" ]] ||
|
|
|
|
[[ "$(latest "$mac_icon"/*)" -nt "$appiconset/Contents.json" ]]; then
|
2014-09-28 05:53:50 +00:00
|
|
|
rm -rf "$appiconset"; mkdir -p "$appiconset"
|
|
|
|
{
|
|
|
|
comma=
|
|
|
|
printf '{"images":['
|
|
|
|
for icon in "${icons[@]}"; do
|
|
|
|
IFS=: read icon filename <<< "$icon"
|
|
|
|
IFS=@ read px scale idiom os <<< "$icon"
|
|
|
|
pt=$(( px / scale ))
|
|
|
|
|
2014-10-26 17:26:41 +00:00
|
|
|
suffix=
|
|
|
|
[[ $scale != 1 ]] && suffix=@${scale}x
|
|
|
|
[[ $filename ]] || filename="icon_${pt}x${pt}${suffix}.png"
|
|
|
|
source=$ios_icon/$filename
|
|
|
|
if [[ ! -e $source ]]; then
|
|
|
|
source=$mac_icon/$filename
|
2018-06-05 18:12:10 +00:00
|
|
|
[[ -e $source ]] || ftl 'No icon for: %s' "$filename"
|
2014-10-26 17:26:41 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-05 18:12:10 +00:00
|
|
|
imageProps=$(copyImage "$source" "$appiconset/$filename")
|
|
|
|
printf '%s{"size":"%dx%d","filename":"%s","scale":"%sx"' \
|
|
|
|
"$comma" "$pt" "$pt" "$filename" "$scale"
|
|
|
|
[[ $idiom ]] && printf ',"idiom":"%s"' "$idiom"
|
|
|
|
[[ $os ]] && printf ',"minimum-system-version":"%s"' "$os"
|
|
|
|
[[ $imageProps ]] && printf '%s' "$imageProps"
|
|
|
|
printf '}'
|
2014-09-28 05:53:50 +00:00
|
|
|
|
2018-06-05 18:12:10 +00:00
|
|
|
comma=,
|
2014-09-28 05:53:50 +00:00
|
|
|
done
|
|
|
|
printf '],"info":{"version":1,"author":"genassets"},"properties":{"pre-rendered":true}}\n'
|
|
|
|
} > "$appiconset/Contents.json"
|
2014-09-30 04:01:33 +00:00
|
|
|
fi
|
2014-09-28 05:53:50 +00:00
|
|
|
|
2014-09-30 04:01:33 +00:00
|
|
|
if [[ "$(latest "$ios_launch"/*)" -nt "$launchimage/Contents.json" ]]; then
|
2014-09-28 05:53:50 +00:00
|
|
|
rm -rf "$launchimage"; mkdir -p "$launchimage"
|
|
|
|
{
|
|
|
|
comma=
|
|
|
|
printf '{"images":['
|
|
|
|
for splash in "${splashes[@]}"; do
|
|
|
|
IFS=@ read name scale idiom os <<< "$splash"
|
|
|
|
case "$name" in
|
|
|
|
*-568) subtype=retina4 ;;
|
|
|
|
*-667) subtype=667h ;;
|
|
|
|
*-736) subtype=736h ;;
|
|
|
|
*) subtype= ;;
|
|
|
|
esac
|
|
|
|
filename="Default${os:+-$os}${subtype:+-$subtype}${scale:+@${scale}x}${idiom:+~$idiom}.png"
|
|
|
|
|
2018-06-05 18:12:10 +00:00
|
|
|
imageProps=$(copyImage "$ios_launch/$name${scale:+@${scale}x}.png" "$launchimage/$filename"); then
|
|
|
|
printf '%s{"extent":"full-screen","filename":"%s","orientation":"portrait","scale":"%sx"' \
|
|
|
|
"$comma" "$filename" "${scale:-1}"
|
|
|
|
[[ $idiom ]] && printf ',"idiom":"%s"' "$idiom"
|
|
|
|
[[ $os ]] && printf ',"minimum-system-version":"%s"' "$os"
|
|
|
|
[[ $subtype ]] && printf ',"subtype":"%s"' "$subtype"
|
|
|
|
[[ $imageProps ]] && printf '%s' "$imageProps"
|
|
|
|
printf '}'
|
2014-09-28 05:53:50 +00:00
|
|
|
|
2018-06-05 18:12:10 +00:00
|
|
|
comma=,
|
2014-09-28 05:53:50 +00:00
|
|
|
done
|
|
|
|
printf '],"info":{"version":1,"author":"genassets"}}\n'
|
|
|
|
} > "$launchimage/Contents.json"
|
2014-09-30 04:01:33 +00:00
|
|
|
fi
|
2014-09-28 05:53:50 +00:00
|
|
|
|
|
|
|
#for file in resources/images/mdpi/*.png; do
|
|
|
|
# name=${file##*/} name=${name%.*} name=${name/.9/}
|
|
|
|
# mdpiFile=$file
|
|
|
|
# xhdpiFile=${file%/*/*.*}/xhdpi/${file##*/}
|
|
|
|
# mdpiFilename=$name.png
|
|
|
|
# xhdpiFilename=$name@2x.png
|
|
|
|
#
|
|
|
|
# [[ -e "$xcassets/$name.imageset/$mdpiFilename" && $mdpiFile -ot "$xcassets/$name.imageset/$mdpiFilename" &&
|
|
|
|
# -e "$xcassets/$name.imageset/$xhdpiFilename" && $xhdpiFile -ot "$xcassets/$name.imageset/$xhdpiFilename" ]] && continue
|
|
|
|
# rm -rf "$xcassets/$name.imageset"; mkdir -p "$xcassets/$name.imageset"
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# comma=
|
|
|
|
# printf '{"images":['
|
|
|
|
# if imageProps=$(copyImage "$mdpiFile" "$xcassets/$name.imageset/$mdpiFilename"); then
|
|
|
|
# printf '%s{"idiom":"universal","scale":"1x","filename":"%s"' "$comma" "$mdpiFilename"
|
|
|
|
# [[ $imageProps ]] && printf '%s' "$imageProps"
|
|
|
|
# printf '}'
|
|
|
|
# comma=,
|
|
|
|
# fi
|
|
|
|
# if imageProps=$(copyImage "$xhdpiFile" "$xcassets/$name.imageset/$xhdpiFilename"); then
|
|
|
|
# printf '%s{"idiom":"universal","scale":"2x","filename":"%s"' "$comma" "$xhdpiFilename"
|
|
|
|
# [[ $imageProps ]] && printf '%s' "$imageProps"
|
|
|
|
# printf '}'
|
|
|
|
# comma=,
|
|
|
|
# fi
|
|
|
|
# printf '],"info":{"version":1,"author":"genassets"}}\n'
|
|
|
|
# } > "$xcassets/$name.imageset/Contents.json"
|
|
|
|
#done
|