-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-assets.sh
executable file
·78 lines (67 loc) · 3.12 KB
/
export-assets.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
asset_directory="assets/animals"
sizes=($(jq -r '.[]' "scripts/sizes.json"))
function export_sizes {
find "$asset_directory" -type f -name "*.svg" | while read -r old; do
for size in "${sizes[@]}"; do
new=$(echo "$old" | sed -e "s/assets\/animals/resources\/drawables\/characters\/$size/")
directory_path="$(dirname "$new")"
filename="$(basename "$new")"
if [ ! -e "$new" ]; then
mkdir -p "$directory_path"
touch "$filename"
fi
rsvg-convert "$old" -w "$size" -h "$size" -f svg -o "$new"
echo
echo "✅ Finished converting $old to $new"
done
echo
done
}
function update_drawables_xml {
python3 scripts/update_drawables_xml.py
}
function update_garmagotchi_assets_mc {
# Clear file
> source/garmagotchiAssets.mc
echo "class GarmagotchiAssets {" >> source/garmagotchiAssets.mc
echo " public var characters;" >> source/garmagotchiAssets.mc
echo " function initialize() {" >> source/garmagotchiAssets.mc
echo " self.characters = {" >> source/garmagotchiAssets.mc
animal_names=($(find "$asset_directory" -type d -mindepth 1 -maxdepth 1 -exec basename {} \;))
for animal_name in "${animal_names[@]}"; do
animal_pascal_case=$(echo "$animal_name" | awk 'BEGIN{FS="-";OFS=""}{for(i=1;i<=NF;i++)$i=toupper(substr($i,1,1)) substr($i,2)}1')
animal_camel_case=$(echo $animal_name | awk 'BEGIN{FS="-";OFS=""}{for(i=1;i<=NF;i++){if(i>1)$i=toupper(substr($i,1,1)) substr($i,2)}}1')
echo " \""$animal_camel_case"\" => {" >> source/garmagotchiAssets.mc
file_names=($(find "$asset_directory/$animal_name" -type f -name "*.svg" -exec basename {} \;))
for file_name in "${file_names[@]}"; do
stripped_file_name="${file_name%.svg}"
file_pascal_case=$(echo "$stripped_file_name" | awk 'BEGIN{FS="_";OFS=""}{for(i=1;i<=NF;i++)$i=toupper(substr($i,1,1)) substr($i,2)}1')
file_camel_case=$(echo $stripped_file_name | awk 'BEGIN{FS="_";OFS=""}{for(i=1;i<=NF;i++){if(i>1)$i=toupper(substr($i,1,1)) substr($i,2)}}1')
echo " \""$file_camel_case"\" => new BitmapAsset({" >> source/garmagotchiAssets.mc
for size in "${sizes[@]}"; do
echo " \""$size"\" => Rez.Drawables."$animal_pascal_case""$file_pascal_case""$size"," >> source/garmagotchiAssets.mc
done
echo " })," >> source/garmagotchiAssets.mc
done
echo " }," >> source/garmagotchiAssets.mc
done
echo " };" >> source/garmagotchiAssets.mc
echo " }" >> source/garmagotchiAssets.mc
echo "}" >> source/garmagotchiAssets.mc
}
echo
echo "✨ Starting to export all character sizes!"
export_sizes
echo
echo "🎉 Finished exporting all character sizes!"
echo
echo "✨ Starting to update drawables.xml!"
update_drawables_xml
echo
echo "🎉 Finished updating drawables.xml!"
echo
echo "✨ Starting to update garmagotchiAssets.xml!"
update_garmagotchi_assets_mc
echo
echo "🎉 Finished updating garmagotchiAssets.xml!"