-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-legemdary-moves.js
68 lines (59 loc) · 1.76 KB
/
get-legemdary-moves.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
const folder = './dist/pokemongo-game-master/versions';
const folder_old = './dist/old/';
const fs = require('fs');
let versions = [];
let outputJSON = (json = {}, fileName = '', jsonSpace = 2) => {
let fileContent = JSON.stringify(json, null, jsonSpace);
fs.writeFileSync(fileName, fileContent);
console.log(`JSON saved as ${fileName}! ( ${fileContent.length / 1000} kb )`);
};
fs.readdirSync(folder).forEach(version => {
if (isNaN(version)) {
return;
}
let fileName = `${folder}/${version}/GAME_MASTER.json`;
console.log(fileName);
versions.push([
version,
JSON.parse(fs.readFileSync(fileName, 'utf8')),
]);
});
let collectPMWithMoves = (data) => {
return data[1].itemTemplates.filter(d => d.pokemonSettings)
.map(pm => {
return {
templateId: pm.templateId,
cinematicMoves: pm.pokemonSettings.cinematicMoves,
quickMoves: pm.pokemonSettings.quickMoves,
}
});
};
let uniArr = (arr) => {
return [...new Set(arr)];
};
let allPmWithMoves = versions
.map(v => collectPMWithMoves(v))
.flat()
.reduce((all, pm, index) => {
let target = all[pm.templateId];
if (!all[pm.templateId]) {
all[pm.templateId] = {... pm};
}
if (index < 10) {
// console.log(all);
}
all[pm.templateId].cinematicMoves = uniArr(
(all[pm.templateId].cinematicMoves || []).concat(pm.cinematicMoves)
);
all[pm.templateId].quickMoves = uniArr(
(all[pm.templateId].quickMoves || []).concat(pm.quickMoves)
);
return all;
}, {});
let op = Object.values(allPmWithMoves)
.sort((a, b) => +a.templateId.slice(2, 5) - b.templateId.slice(2, 5))
.reduce((all, item) => {
all[item.templateId] = item;
return all;
}, {});
outputJSON(op, 'pm-moves.json', 2);