From 056d4560f72a9ec281f8df31aa2a7d8241d6adf1 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 13 Aug 2023 16:02:22 -0400 Subject: Generating a cpp file for shaders --- themes/src/tools/shader.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'themes/src/tools') diff --git a/themes/src/tools/shader.js b/themes/src/tools/shader.js index 27c8682..54ba6e0 100644 --- a/themes/src/tools/shader.js +++ b/themes/src/tools/shader.js @@ -15,16 +15,23 @@ files.forEach(file => { const splitText = text.split('\n'); const splitName = file.split('.'); const def = `SHADER_${splitName.join('_').toUpperCase()}`; - let result = `#ifndef ${def} \n`; - result += `#define ${def} \n`; - result += `const char* ${def.toLowerCase()} = ` + let header_result = `#ifndef ${def} \n`; + const filename = splitName.join('_'); + const header_name = filename + ".h"; + const cpp_name = filename + ".cpp"; + header_result += `#define ${def} \n`; + header_result += `extern const char* ${def.toLowerCase()};\n`; + header_result += '#endif\n'; + fs.writeFileSync(path.join(out_directory, header_name), header_result); + + let cpp_result = `#include "${header_name}"\n\n` + cpp_result += `const char* ${def.toLowerCase()} = ` splitText.forEach((line, index) => { - result += "\"" + line + " \\n\""; + cpp_result += "\"" + line + " \\n\""; if (index == splitText.length - 1) - result += ";\n"; + cpp_result += ";\n"; else - result += "\n"; + cpp_result += "\n"; }); - result += '#endif\n'; - fs.writeFileSync(path.join(out_directory, splitName.join('_') + '.h'), result); + fs.writeFileSync(path.join(out_directory, cpp_name), cpp_result); }); -- cgit v1.2.1