-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
81 lines (56 loc) · 1.68 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const fs = require('fs');
function splitLine(line) {
const idx1 = line.lastIndexOf(':') + 1;
const idx2 = line.lastIndexOf(',');
const prefix = line.substr(0, idx1);
const value = line.substr(idx1, idx2);
const suffix = line.substr(idx2);
return [ prefix, value, suffix ];
}
try {
// read config file
const configFileData = fs.readFileSync('./config.json', 'utf-8');
const {
HIDEOUT_FILE,
NEW_HIDEOUT_NAME,
NEW_HIDEOUT_HASH,
DIFF_X,
DIFF_Y
} = JSON.parse(configFileData);
// read input file
const data = fs.readFileSync(HIDEOUT_FILE, 'utf-8');
// convert data
const lines = data.split('\n');
for (const i in lines) {
const line = lines[i];
if (line.includes('"hideout_name"')) {
const arr = splitLine(line);
lines[i] = `${arr[0]} "${NEW_HIDEOUT_NAME}"${arr[2]}`;
}
else if (line.includes('"hideout_hash"')) {
const arr = splitLine(line);
lines[i] = `${arr[0]} ${NEW_HIDEOUT_HASH}${arr[2]}`;
}
else if (line.includes('"x"')) {
const arr = splitLine(line);
let value = parseInt(arr[1]);
value += DIFF_X;
lines[i] = `${arr[0]} ${value}${arr[2]}`;
}
else if (line.includes('"y"')) {
const arr = splitLine(line);
let value = parseInt(arr[1]);
value += DIFF_Y;
lines[i] = `${arr[0]} ${value}${arr[2]}`;
}
}
// process output file
const filePrefix = HIDEOUT_FILE.substr(0, HIDEOUT_FILE.lastIndexOf('.hideout'));
const outputFile = `${filePrefix} (${NEW_HIDEOUT_NAME}).hideout`;
const outputData = lines.join('\n');
fs.writeFileSync(outputFile, outputData);
console.log('done');
} catch (err) {
console.error(err);
}