7 OUT_DIR=../../../data/xonotic-data.pk3dir/
12 # Converts images into $FORMAT
13 # Synopsis: convert_image input.png output
14 # Genreates output.jpg and output_alpha.jpg
15 function convert_image()
17 local covert_flags="-layers flatten"
18 if [ "$FORMAT" = "jpg" ]
20 covert_flags="$covert_flags -quality $JPEG_QUALITY"
22 convert -background none "$1" $covert_flags "$2.$FORMAT"
23 if [ "$FORMAT" = "jpg" ]
25 convert -background none "$1" $covert_flags -alpha Extract "$2_alpha.jpg"
29 # Ensure that the output jpg are of the appropriate size
30 # Synopsis: scale_image output
31 # Where "output" is the same as $2 in convert_image
32 function scale_image()
34 let max_w=$TEXTURE_SIZE
36 if echo -n "$1" | grep -q ".*/piece.*"
43 let img_w=$(identify -format %w "$1.$FORMAT")
44 if [ "$img_w" -gt "$max_w" ]
46 local scale=$(echo "scale=10; $max_w/$img_w*100" | bc)
47 convert "$1.$FORMAT" -resize "$scale%" "$1.$FORMAT"
48 if [ "$FORMAT" = "jpg" ]
50 convert "$1_alpha.jpg" -resize "$scale%" "$1_alpha.jpg"
56 # handle_file src_file out_dir
57 function handle_file()
61 local out_file="$out_dir/$src_file"
62 $MKDIR "$out_dir/$(dirname "$src_file")"
64 local file_extension="$(echo "$src_file" | sed -r "s/^(.*)\.([^.]+)$/\2/")"
65 local base_file="$(echo "$out_file" | sed -r "s/^(.*)\.([^.]+)$/\1/")"
67 if echo -n "$file_extension" | grep -Eq "^(png|svg|tga|xcf)$" &&
68 [ "$file_extension" != "$FORMAT" ]
70 out_file="$base_file.$FORMAT"
71 if [ "$src_file" -nt "$out_file" ]
73 echo -e "Converting \x1b[1m$src_file\x1b[0m"
74 convert_image "$src_file" "$base_file"
75 scale_image "$base_file"
78 elif [ "$src_file" -nt "$out_file" ]
80 echo -e "Copying \x1b[1m$src_file\x1b[0m"
81 cp -T "$src_file" "$out_file"
85 echo -e "Skipping \x1b[1m$src_file\x1b[0m"
88 # Create the files for packaging
91 for src_file in $(git ls-files '*/*')
93 handle_file "$src_file" "$OUT_DIR/gfx/hud/default/minigames/"
96 for src_file in $(git ls-files '../../models/sprites/minigame*')
98 handle_file "$src_file" "$OUT_DIR/models/sprites/"
103 if [ "$SYSTEM_NAME" = Darwin -o "$SYSTEM_NAME" = FreeBSD ]
120 echo -e "Removing old files"
121 [ -n "$OUT_DIR" -a -e "$OUT_DIR" ] && rm -rf "$OUT_DIR"
124 echo 1>&2 "Unknown option: $1"