Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Doom 3 GUI text parser
/*
* Doom 3 GUI Text parser
*
* Copyright (c) PROPHESSOR 05.12.2018
* MIT License
*
*/
const fs = require('fs');
const REGEX = {
textField: /text\s+"(.*)"\r\n/g
}
function parse(file, filename) {
const out = [];
let match;
while ((match = REGEX.textField.exec(file)) !== null) {
if(match[1].trim() && !/^[0-9]+$/.test(match[1]) && !match[1].includes('::') && !match[1].includes('#str_')) {
console.log(match[1]);
out.push([filename, match[1].replace(/\n/g, '\\n'), []]);
}
}
return out;
}
const filelist = [
// Put here pathes to .gui files
]
function main() {
let output = [];
for(const filename of filelist) {
const parsed = parse(fs.readFileSync(filename, 'utf8'), filename);
output = output.concat(parsed);
fs.writeFileSync(filename + '.json', JSON.stringify(parsed, 0, 4), 'utf8');
}
fs.writeFileSync('parsed.json', JSON.stringify(output, 0, 4), 'utf8');
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.