BlueGit

timfa frameworkv3

Files

frameworkv3 / buildShaders.sh

buildShaders.sh

It begins
timfa Tim · pushed by timfa · 2 years ago
8e521cb1 History
buildShaders.sh 930 B Download Raw
1#!/bin/bash
2
3# Directory containing the shader files
4SHADER_DIR="framework/shaders"
5# Output file for the JavaScript shader object
6OUTPUT_FILE="framework/shaders.js"
7
8echo "const game_shaders_builtin = {" > "$OUTPUT_FILE"
9
10for 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"
22done
23
24# Close the JSON object
25echo "};" >> "$OUTPUT_FILE"
26sed -i '$ s/,$//' "$OUTPUT_FILE"
27
28echo "Shader object created in $OUTPUT_FILE"