Add random playsound dump script

This commit is contained in:
ShadowLarkens
2020-08-21 09:33:03 -07:00
parent 5c50080377
commit dbbaaca434
3 changed files with 87 additions and 0 deletions
+4
View File
@@ -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.
+72
View File
@@ -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();
+11
View File
@@ -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"
}