Skip to content

Instantly share code, notes, and snippets.

@PROPHESSOR
Created December 5, 2018 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PROPHESSOR/e04ec38d09c99b1fab8dbf168fc036f3 to your computer and use it in GitHub Desktop.
Save PROPHESSOR/e04ec38d09c99b1fab8dbf168fc036f3 to your computer and use it in GitHub Desktop.
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