Created
December 5, 2018 16:02
-
-
Save PROPHESSOR/e04ec38d09c99b1fab8dbf168fc036f3 to your computer and use it in GitHub Desktop.
Doom 3 GUI text parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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