| 1 | #!/bin/bash |
| 2 | |
| 3 | # Directory containing the shader files |
| 4 | SHADER_DIR="framework/shaders" |
| 5 | # Output file for the JavaScript shader object |
| 6 | OUTPUT_FILE="framework/shaders.js" |
| 7 | |
| 8 | echo "const game_shaders_builtin = {" > "$OUTPUT_FILE" |
| 9 | |
| 10 | for shader_file in "$SHADER_DIR"/*; do |
| 11 | base_name=$(basename "$shader_file") |
| 12 | name_without_ext="${base_name%.*}" |
| 13 | |
| 14 | # Convert the filename to the desired key format |
| 15 | shader_name="${name_without_ext}_$(echo "$base_name" | awk -F. '{print $2}')" |
| 16 | |
| 17 | # Strip comments, replace newlines with spaces, and escape double quotes |
| 18 | shader_content=$(sed -e 's/\/\/.*$//g' -e '/\/\*/,/\*\//d' "$shader_file" | tr '\n' ' ' | sed 's/"/\\"/g') |
| 19 | |
| 20 | # Append the shader content to the output file |
| 21 | echo " \"$shader_name\": \"$shader_content\"," >> "$OUTPUT_FILE" |
| 22 | done |
| 23 | |
| 24 | # Close the JSON object |
| 25 | echo "};" >> "$OUTPUT_FILE" |
| 26 | sed -i '$ s/,$//' "$OUTPUT_FILE" |
| 27 | |
| 28 | echo "Shader object created in $OUTPUT_FILE" |