-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
321 lines (284 loc) · 8.6 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
require("dotenv").config();
const fs = require("fs-extra");
const comparator = require("./controllers/comparator");
const fileParser = require("./controllers/fileParsers");
const dataParser = require("./controllers/dataParsers");
let allItems = [];
const SHOW_DEV_ITEMS = process.env.SHOW_DEV_ITEMS === "true";
const CONTENT_FOLDER_PATH = process.env.CONTENT_FOLDER_PATH
? process.env.CONTENT_FOLDER_PATH
: "./";
const folderPatch = "./exported/";
const orderByCategoryAndName = (a, b) => {
if (a.category < b.category) {
return -1;
}
if (a.category > b.category) {
return 1;
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
};
const orderByName = (a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
};
console.info("Loading StringTables");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/StringTables`, "stringtables");
console.info("Loading Localization");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Localization/Game/en`, "translation");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Localization/Game`, "translationOthers");
console.info("Loading Loot sites");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Characters/Creatures/Monkey`, "lootsites");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Characters/Creatures/Okkam`, "lootsites");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Characters/Creatures/Papak`, "lootsites");
console.info("Loading TechTree");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/TechTree`, "tech");
console.info("Loading Items");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Items`, "item");
console.info("Loading Placeables");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Placeables`, "placeables");
console.info("Loading Recipes");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Recipes`, "item");
console.info("Loading Trade");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Trade`, "trade");
//console.info("Loading Placeables Cached");
//loadDirData("./Content/Mist/Data/Placeables", "cached");
console.info("Loading Walkers Upgrades");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Walkers`, "upgrages");
console.info("Loading Damages");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/DamageTypes`, "damagetypes");
console.info("Loading Schematics");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/Items/Schematics`, "schematics");
if (process.env.EXTRACT_LOOT_TABLES === "true") {
console.info("Loading LootTables");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/LootTables`, "loottables");
loadDirData(`${CONTENT_FOLDER_PATH}Content/Mist/Data/LootTables`, "blueprintsloot");
fileParser.parseBlueprintsToItems();
}
console.info("Parse Upgrades to Items");
fileParser.parseUpgradesToItems();
allItems = fileParser.getItems();
const translator = fileParser.getTranslator();
if (!SHOW_DEV_ITEMS) {
allItems = allItems.filter((item) => !item.onlyDevs);
}
console.info("Translating the items");
allItems = translator.addDescriptions(allItems);
allItems = translator.translateItems(allItems);
for (const item of allItems) {
for (const key of Object.keys(item)) {
if (item[key] === undefined) {
delete item[key];
}
if (item?.drops !== undefined && item.drops.length <= 0) {
delete item.drops;
}
if (
item?.toolInfo !== undefined &&
item.toolInfo.length <= 0
) {
delete item.toolInfo;
}
}
}
allItems = allItems
.map((item) => {
const countItems = allItems.filter((item2) => item.name === item2.name);
if (countItems.length > 1) {
return { ...countItems[0], ...countItems[1] };
}
return item;
})
.filter((item) => item.name && Object.keys(item).length > 2)
.filter((item) => !item.name.includes("Packing"))
.reduce((acc, current) => {
const x = acc.find((item) => item.name === current.name);
if (!x) {
return acc.concat([current]);
}
return acc;
}, []);
allItems = dataParser.itemMerger(allItems, "Long Sawblade", "Sawblade_Tier2");
allItems.sort(orderByName);
if (allItems.length > 0) {
fs.writeFile(
`${folderPatch}items.json`,
JSON.stringify(allItems, null, 2),
(err) => {
if (err) {
console.error("Error creating the file");
} else {
console.log("Items exported");
}
}
);
for (const item of allItems) {
for (const key of Object.keys(item)) {
if (item[key] === undefined) {
delete item[key];
}
if (item?.translation !== undefined) {
delete item.translation;
} else if (item?.type !== undefined) {
delete item.type;
} else if (item?.schematicName !== undefined) {
delete item.schematicName;
} else if (item?.damageType !== undefined) {
delete item.damageType;
}
}
}
allItems.sort(orderByCategoryAndName);
fs.writeFile(
`${folderPatch}items_min.json`,
JSON.stringify(allItems),
(err) => {
if (err) {
console.error("Error creating the file");
} else {
console.log("Items.min exported");
}
}
);
}
let creatures = fileParser.getCreatures();
for (const creature of creatures) {
for (const key of Object.keys(creature)) {
if (creature[key] === undefined) {
delete creature[key];
}
}
}
creatures = creatures.filter((item) => item.name && Object.keys(item).length > 2);
creatures.sort(orderByName);
if (creatures.length > 0) {
fs.writeFile(
`${folderPatch}creatures.json`,
JSON.stringify(creatures, null, 2),
(err) => {
if (err) {
console.error("Error creating the file");
} else {
console.log("Creatures exported");
}
}
);
for (const creature of creatures) {
for (const key of Object.keys(creature)) {
if (creature[key] === undefined) {
delete creature[key];
}
if (creature?.lootTable !== undefined) {
delete creature.lootTable;
}
if (creature?.type !== undefined) {
delete creature.type;
}
}
}
fs.writeFile(
`${folderPatch}creatures_min.json`,
JSON.stringify(creatures),
(err) => {
if (err) {
console.error("Error creating the file");
} else {
console.log("Creatures.min exported");
}
}
);
}
if (process.env.TRANSLATE_FILES === "true") {
const translateData = translator.getTranslateFiles();
for (const languaje in translateData) {
const fileData = translateData[languaje];
const languajeArray = languaje.split("-");
fs.outputFile(
`${folderPatch}locales/${languajeArray[0].toLowerCase()}/items.json`,
JSON.stringify(fileData, null, 2),
(err) => {
if (err) {
console.error(`Error creating the file: ${languaje}`, err);
} else {
console.log(`Translated files ${languaje} exported`);
}
}
);
}
}
if (process.env.COMPARE === "true") {
comparator.compareItems(allItems, folderPatch);
}
function loadDirData(techTreeDir, folderType) {
if (!fs.exists(techTreeDir)) {
return;
}
let files = [];
try {
files = fs.readdirSync(techTreeDir);
} catch (error) {
console.error(`The folder ${techTreeDir} not exists`);
}
for (const file of files) {
const path = `${techTreeDir}/${file}`;
const fileData = fs.statSync(path);
if (fileData.isDirectory()) {
loadDirData(path, folderType);
} else if (file.includes(".json")) {
switch (folderType) {
case "tech":
fileParser.parseTechData(path);
break;
case "item":
fileParser.parseItemData(path);
break;
case "stringtables":
fileParser.parseTranslations(path);
break;
case "trade":
fileParser.parsePrices(path);
break;
case "placeables":
fileParser.parsePlaceableData(path);
break;
case "cached":
if (file.includes("CachedPlaceablesCosts.json")) {
fileParser.parseCachedItems(path);
}
break;
case "loottables":
fileParser.parseLootTable(path);
break;
case "upgrages":
fileParser.parseUpgrades(path);
break;
case "blueprintsloot":
fileParser.parseLootBlueprint(path);
break;
case "damagetypes":
fileParser.parseDamage(path);
break;
case "schematics":
fileParser.parseSchematicItemData(path);
break;
case "translationOthers":
fileParser.parseOtherTranslations(path);
break;
case "lootsites":
fileParser.parseLootSites(path);
break;
}
}
}
}