Skip to content

Instantly share code, notes, and snippets.

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