diff --git a/tools/playsound_finder/README.md b/tools/playsound_finder/README.md new file mode 100644 index 00000000000..5e12e69f515 --- /dev/null +++ b/tools/playsound_finder/README.md @@ -0,0 +1,4 @@ +This script extracts playsound() calls and their arguments and outputs it in a csv format + +In order to use this, open a shell at the root of the git directory and run `node tools/playsound_finder/index.js`. +It's pretty far from perfect, but hey, quicker than extracting playsound parameters by hand. \ No newline at end of file diff --git a/tools/playsound_finder/index.js b/tools/playsound_finder/index.js new file mode 100644 index 00000000000..020dda64468 --- /dev/null +++ b/tools/playsound_finder/index.js @@ -0,0 +1,72 @@ +var fs = require('fs'); + +// List all files in a directory in Node.js recursively in a synchronous fashion +var walkSync = function(dir, filelist) { + var files = fs.readdirSync(dir); + filelist = filelist || []; + files.forEach(function(file) { + if (fs.statSync(dir + file).isDirectory()) { + filelist = walkSync(dir + file + '/', filelist); + } + else { + filelist.push(dir + file); + } + }); + return filelist; +}; + +var findNearestAbsolute = (data, line) => { + for (let i = line; i > 0; i--) { + let str = data[i]; + if (str && str.match(/^\//)) { + return str.trim().replace(/,/g, "|"); + } + } + return null +} + +var main = () => { + let files = walkSync("code/"); + let matches = {}; + for (let file of files) { + const data = fs.readFileSync(file, "utf8"); + + if (!data.match(/playsound.*/)) { + continue + } + + if(!matches[file]) matches[file] = []; + const dataArray = data.split("\n"); + + let i = 1; + for (let line of dataArray) { + i++; + let m = line.match(/playsound.*/) + if (m) { + matches[file].push({line: i, match: m[0], src: findNearestAbsolute(dataArray, i)}); + } + } + } + + Object.keys(matches).map(file => { + let allResults = matches[file]; + allResults.map(obj => { + obj.params = obj.match.split(","); + for (var i = 0; i < obj.params.length; i++) { + obj.params[i] = obj.params[i].trim().replace(/playsound\(/g, "").replace(/\)/g, ""); + } + }) + }); + + // Final loop, spit out a csv + Object.keys(matches).map(file => { + let thisFileCsvEntry = ""; + let allResults = matches[file]; + for (let matchObj of allResults) { + thisFileCsvEntry += `${file},${matchObj.line},${matchObj.src},${matchObj.params.join(",")}\n`; + } + fs.appendFileSync("results.csv", thisFileCsvEntry); + }); +} + +main(); \ No newline at end of file diff --git a/tools/playsound_finder/package.json b/tools/playsound_finder/package.json new file mode 100644 index 00000000000..b7e1961c37f --- /dev/null +++ b/tools/playsound_finder/package.json @@ -0,0 +1,11 @@ +{ + "name": "playsound_finder", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Tigercat2000", + "license": "AGPL 3.0" +}