mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-23 20:17:15 +01:00
Add random playsound dump script
This commit is contained in:
@@ -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.
|
||||
@@ -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();
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user