-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateResourceFile.sh
executable file
·77 lines (64 loc) · 2.2 KB
/
generateResourceFile.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
#!/bin/bash
outputFile="resources/graphicResources.rcp"
outputConstantsFile="sauce/resources.h"
assetsPath="resources/assets/"
fileSuffix=".bmp"
fileHiResSuffix="-144.bmp"
fileGraySuffix="-gray.bmp"
hires=0
if [ "$1" == "--hires" ]; then
hires=1
fi
if [ -f $outputFile ]; then
rm $outputFile
fi
if [ -f $outputConstantsFile ]; then
rm $outputConstantsFile
fi
function writeResource() {
local identifier=$1
local name=$2
echo "BITMAPFAMILY ID $identifier" >> $outputFile
echo "BEGIN" >> $outputFile
hiresFile=$assetsPath$name$fileHiResSuffix
grayFile=$assetsPath$name$fileGraySuffix
if [ $hires == 1 ] && [ -f $hiresFile ]; then
echo " BITMAP \"$assetsPath$name$fileHiResSuffix\" BPP 8 TRANSPARENTINDEX 4 DENSITY 144 COMPRESS" >> $outputFile
else
echo " BITMAP \"$assetsPath$name$fileSuffix\" BPP 8 TRANSPARENTINDEX 4 COMPRESS" >> $outputFile
if [ -f $grayFile ]; then
echo " BITMAP \"$assetsPath$name$fileGraySuffix\" BPP 4 TRANSPARENTINDEX 4 COMPRESS" >> $outputFile
else
echo " BITMAP \"$assetsPath$name$fileSuffix\" BPP 4 TRANSPARENTINDEX 4 COMPRESS" >> $outputFile
fi
fi
echo "END" >> $outputFile
}
function writeConstants() {
local identifier=$1
local name=$2
local numParts=$3
echo "#define GFX_RES_${name^^} $identifier" >> $outputConstantsFile
echo "#define GFX_RES_${name^^}_PARTS $numParts" >> $outputConstantsFile
nameSuffix=""
if ((numParts > 1)); then
nameSuffix="0"
fi
local fileName="$assetsPath$name$nameSuffix$fileSuffix"
width=$(identify -format "%w" "$fileName")
height=$(identify -format "%h" "$fileName")
echo "#define GFX_RES_${name^^}_WIDTH $width" >> $outputConstantsFile
echo "#define GFX_RES_${name^^}_HEIGHT $height" >> $outputConstantsFile
}
while IFS=';' read -r identifier name numParts prefWidth
do
writeConstants $identifier $name $numParts
if (( $numParts == 1 )); then
writeResource $identifier $name
else
for ((i=0; i<numParts; i++)); do
writeResource $identifier "${name}${i}"
((identifier+=1))
done
fi
done < "resources/graphicResources.map"