#!/bin/bash # Directory containing the shader files SHADER_DIR="framework/shaders" # Output file for the JavaScript shader object OUTPUT_FILE="framework/shaders.js" echo "const game_shaders_builtin = {" > "$OUTPUT_FILE" for shader_file in "$SHADER_DIR"/*; do base_name=$(basename "$shader_file") name_without_ext="${base_name%.*}" # Convert the filename to the desired key format shader_name="${name_without_ext}_$(echo "$base_name" | awk -F. '{print $2}')" # Strip comments, replace newlines with spaces, and escape double quotes shader_content=$(sed -e 's/\/\/.*$//g' -e '/\/\*/,/\*\//d' "$shader_file" | tr '\n' ' ' | sed 's/"/\\"/g') # Append the shader content to the output file echo " \"$shader_name\": \"$shader_content\"," >> "$OUTPUT_FILE" done # Close the JSON object echo "};" >> "$OUTPUT_FILE" sed -i '$ s/,$//' "$OUTPUT_FILE" echo "Shader object created in $OUTPUT_FILE"