-
Notifications
You must be signed in to change notification settings - Fork 1
/
genscript.sh
172 lines (130 loc) Β· 5.53 KB
/
genscript.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# This script generates useable resourcepacks for every respack-compatible minecraft version in .zip format.
# Output located in ./generated
# Pack formats to generate.
FORMATS=(34 32 22 18 15 13 12 9 8 7 6 5 4 3 2 1 0)
# Minecraft version ranges for each pack format. Used for pack zip naming.
MCVER=(1.6.1-1.7.10 1.8-1.8.9 1.9β1.10.2 1.11β1.12.2 1.13β1.14.4 1.15β1.16.1 1.16.2β1.16.5 1.17β1.17.1 1.18β1.18.2 1.19β1.19.2 0 0 1.19.3 1.19.4 0 1.20β1.20.1 0 0 1.20.2 0 0 0 1.20.3-1.20.4 0 0 0 0 0 0 0 0 0 1.20.5 0 1.21)
# DPI range for GUI sizes.
DPI=(0 24 48 72 96 120 144 168 192)
# GUI Scales to generate.
SCALES=(2 3 4 5 6 7 8)
# Exit if running under root.
[ "${EUID}" = 0 ] && {
echo
echo ":: Please run without root privileges."
echo
exit 1
}
# Exit if running in wrong directory.
[ -e "./dev/script_enabler" ] || {
echo
echo ":: Please run inside source folder."
echo
exit 1
}
# Check deps.
MISSING=0
hash inkscape 2>/dev/null || {
echo "Inkscape is not installed."
MISSING=$((${MISSING}+1))
}
hash 7z 2>/dev/null || {
echo "7z (7-Zip, p7zip) is not installed."
MISSING=$((${MISSING}+1))
}
hash mogrify 2>/dev/null || {
echo "imagemagick is not installed."
MISSING=$((${MISSING}+1))
}
hash optipng 2>/dev/null || {
echo "optipng is not installed."
MISSING=$((${MISSING}+1))
}
# Exit if dependencies aren't met.
[ "${MISSING}" -gt "0" ] && {
echo
echo ":: ${MISSING} dependencies are missing. Exiting."
echo
exit 1
}
# Check if ./temp directory exists.
if [ -d ./temp ]; then
INPUT=0
while [ "$INPUT" != "y" ]; do
echo
echo ":: ./temp directory already exists (script error?). Remove? [y/n]"
read -s -n 1 INPUT
[ "${INPUT}" = "n" ] && exit 1
[ "${INPUT}" = "y" ] && \rm -r ./temp
done
fi
# Check if generated packs already exist.
if [ -d ./generated ]; then
INPUT=0
while [ "${INPUT}" != "y" ]; do
echo
echo ":: Generated packs already exist. Regenerate? [y/n]"
read -s -n 1 INPUT
[ "${INPUT}" = "n" ] && exit 1
[ "${INPUT}" = "y" ] && \rm -r ./generated
done
fi
# Get pack version to use
while [ "$PACKVER" = "" ]; do
echo
read -p ":: Enter the pack version (eg: 'v2.x' or 'Dev'): " PACKVER
done
echo ":: Starting generation (this may take a while!)"
shopt -s globstar # Enable globstar during script.
mkdir ./temp
for SCALE in ${SCALES[@]}; do # Loop through provided GUI scales.
echo "Generating images for scale ${SCALE}..."
rsync -a --exclude="*.svg" ./src/ ./temp/${SCALE} # Copy all files EXCEPT SVGs to current ./temp/scale directory.
for SVG in ./src/**/*.svg; do # Loop through SVGs present in source directory.
PNG=$(sed "s~src/~temp/$SCALE/~" <<< ${SVG} | sed -e "s~.svg~.png~") # Set output filepath corresponding to input SVG.
echo "file-open:${SVG}; export-filename:${PNG}; export-dpi:${DPI[$SCALE]}; export-do" >> ./temp/${SCALE}/inkscape.txt # Add file to be processed in an inkscape script.
done
echo "quit" >> ./temp/${SCALE}/inkscape.txt # Add quit command to end of inkscape script.
inkscape --shell < ./temp/${SCALE}/inkscape.txt &>/dev/null # Enter inkscape shell and run previously created script.
done
# Remove almost fully transparent pixels that don't play nice with Minecraft's texture rendering.
for SCALE in ${SCALES[@]}; do
echo "Removing redundant pixels for scale ${SCALE}..."
for PNG in ./temp/${SCALE}/**/*.png; do
mogrify -fuzz 7% -channel RGBA -fill "#ffffff" -transparent "#88888800" ${PNG}
done
done
# Compress generated PNG files.
for SCALE in ${SCALES[@]}; do
echo "Optimizing images for scale ${SCALE}..."
for PNG in ./temp/${SCALE}/**/*.png; do
optipng -q ${PNG}
done
done
# Sort and compress files.
mkdir ./generated
for SCALE in ${SCALES[@]}; do
echo "Sorting files and creating zipped packs for scale ${SCALE}..."
sed -i "s~SCALE~${SCALE}~" ./temp/${SCALE}/pack.mcmeta # Change scale to currently looped number in pack description.
for FORMAT in ${FORMATS[@]}; do
[ ${SCALE} = 2 ] && mkdir ./generated/${FORMAT} # Create output folder for format if on first main loop pass.
sed -i "s/FORMAT/${FORMAT}/g" ./temp/${SCALE}/pack.mcmeta # Edit pack.mcmeta with current format.
if [ -e ./temp/${SCALE}/${FORMAT}.exclude ]; then # Check if exclusion list exists.
for LINE in $(cat ./temp/${SCALE}/${FORMAT}.exclude); do # Loop through lines in exclusion list.
\rm -r ./temp/${SCALE}/assets/${LINE} # Remove file from list.
done
fi
if [ -d ./temp/${SCALE}/${FORMAT} ]; then # Check if inclusion directory exists.
\cp -r ./temp/${SCALE}/${FORMAT}/* ./temp/${SCALE}/assets # Copy directory into assets
[ "${FORMAT}" = 0 ] && sed -i "s~: 0~: 1~" ./temp/${SCALE}/pack.mcmeta # Change format number in pack.mcmeta from 0 to 1. "Format 0" packs are created due to a mechanic change with enchanting tables in 1.7 without a format change.
fi
7z a "./generated/${FORMAT}/Dracula ${PACKVER} GUI Scale ${SCALE} MC ${MCVER[$FORMAT]}.zip" ./temp/${SCALE}/assets ./temp/${SCALE}/LICENSE.md ./temp/${SCALE}/pack.mcmeta ./temp/${SCALE}/pack.png &>/dev/null # Create zipped pack.
sed -i "s~: ${FORMAT}~: FORMAT~" ./temp/${SCALE}/pack.mcmeta # Change format number back to search key in pack.mcmeta.
done
done
# Clean up and send finished message.
\rm -r ./temp
echo
echo ":: Done. Output available in ./generated"
echo