Fix typo in comment.
[bsnes:xml-shaders.git] / make-bsnes-shaders
1 #!/bin/sh
2 set -e
3
4 BASEDIR=$(dirname "$0")
5 INPUT="$BASEDIR/shaders"
6 OUTPUT="$BASEDIR/bsnes-shaders"
7
8 available_shaders() {
9         find "$INPUT" -type f -name '*.shader' |
10         while read -r SHADERFILE; do
11                 # Grab the name of the shader
12                 SHADERNAME=$(basename "$SHADERFILE" .shader)
13
14                 # Grab the version of the shader
15                 TEMP=$(dirname "$SHADERFILE")
16                 SHADERVERSION=${TEMP##*/}
17
18                 # Grab the target of the shader.
19                 TEMP=${TEMP%/*}
20                 SHADERTARGET=${TEMP##*/}
21
22                 printf "%s\t%s\t%s\n" "$SHADERTARGET" "$SHADERVERSION" "$SHADERNAME"
23         done
24 }
25
26 filter_shaders() {
27         (
28                 IFS=$(printf "\t")
29                 while read -r TARGET VERSION NAME; do
30                         # bsnes v082 only understands v1.0 shaders.
31                         if [ "$VERSION" != "v1.0" ] ; then
32                                 continue
33                         fi
34
35                         printf "%s\t%s\t%s\n" "$TARGET" "$VERSION" "$NAME"
36                 done
37         )
38 }
39
40 mkdir -p "$OUTPUT"
41
42 available_shaders | filter_shaders | (
43         IFS=$(printf "\t")
44         while read -r TARGET VERSION NAME; do
45                 cp "$INPUT/$TARGET/$VERSION/$NAME.shader" "$OUTPUT/$NAME.$TARGET.shader"
46         done
47 )
48
49 echo "bsnes compatible shaders are now in $OUTPUT"