Skip to content

Instantly share code, notes, and snippets.

@PROPHESSOR PROPHESSOR/deparser.js
Last active Dec 16, 2018

Embed
What would you like to do?
Doom 3 MAP text deparser (translation patch applier)
/*
* Doom 3 MAP text deparser (translation patch applier)
*
* Copyright (c) PROPHESSOR 10.12.2018
* MIT License
*
*/
const fs = require('fs');
const EXPORT_DIR = 'export';
function deparse(json, filename) {
let map = fs.readFileSync(filename, 'utf8');
for(const string of json) {
// [0] - filename, [1] - input string, [2] - array { [0] - translation, [1] - translator, [2] - rating, [3] - comment}, [3] - checkers
string[2].sort((a, b) => (b[2] || 0) - (a[2] || 0));
const bestTranslation = string[2][0][0];
map = map.replace(`"${string[1]}"`, `"${bestTranslation}"`);
}
fs.writeFileSync(`${EXPORT_DIR}/${filename}`, map.replace(/я/g, '`').replace(/ё/g, 'е').replace(/Ё/g, 'Е'), 'utf8');
}
const filelist = [
"maps\\ep1\\e1m1.map"
// Put here pathes to .map files
// NOTE: Translated .map.json files must be in same folder
]
function main() {
for(const filename of filelist) {
deparse(require(`./${filename}.json`), filename);
console.log(filename, 'OK');
}
}
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.