Skip to content

Commit 6101c48

Browse files
committed
get presets json from data manager
1 parent 6ca404e commit 6101c48

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

generate.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getJson = require('./get-json');
1414

1515
let bsgData = false;
1616
let presets = false;
17-
let sptPresets = false;
17+
let bsgPresets = false;
1818
const itemsByHash = {};
1919
const itemsById = {};
2020

@@ -322,11 +322,11 @@ const loadBsgData = async () => {
322322
};
323323

324324
const loadPresets = async () => {
325-
presets = await getJson.tt_presets();
325+
presets = await getJson.td_presets();
326326
};
327327

328-
const loadSptPresets = async () => {
329-
sptPresets = await getJson.presets();
328+
const loadBsgPresets = async () => {
329+
bsgPresets = await getJson.presets();
330330
};
331331

332332
const setBackgroundColor = (item) => {
@@ -379,14 +379,19 @@ const hashItems = async (options) => {
379379
id
380380
}
381381
}
382+
...on ItemPropertiesWeapon {
383+
slots {
384+
name
385+
}
386+
}
382387
}
383388
}
384389
}`
385390
}),
386391
responseType: 'json',
387392
resolveBodyOnly: true
388393
});
389-
hashCalc.init(bsgData, sptPresets, presets);
394+
hashCalc.init(bsgData, bsgPresets, presets);
390395
let missingGridImage = 0;
391396
let missingIcon = 0;
392397
let missingBaseImage = 0;
@@ -420,7 +425,7 @@ const hashItems = async (options) => {
420425
console.log(`Error hashing ${itemData.id}: ${error}`);
421426
}
422427
itemsById[itemData.id] = itemData;
423-
if (itemData.id == options.targetItemId) {
428+
if (itemData.id == options.targetItemId && itemData.hash) {
424429
console.log(itemData.hash);
425430
break;
426431
}
@@ -445,7 +450,7 @@ const initialize = async (options) => {
445450
if (options.SCANNER_NAME) process.env.SCANNER_NAME = options.SCANNER_NAME;
446451
await loadBsgData();
447452
await loadPresets();
448-
await loadSptPresets();
453+
await loadBsgPresets();
449454
if (!options.skipHashing) {
450455
await hashItems(opts);
451456
}
@@ -486,8 +491,8 @@ const generate = async (options, forceImageIndex) => {
486491
if (!presets) {
487492
await loadPresets();
488493
}
489-
if (!sptPresets) {
490-
await loadSptPresets();
494+
if (!bsgPresets) {
495+
await loadBsgPresets();
491496
}
492497
if (!cacheIsLoaded()) {
493498
refreshCache();
@@ -531,7 +536,7 @@ const generate = async (options, forceImageIndex) => {
531536
setBackgroundColor(item);
532537
}
533538
try {
534-
hashCalc.init(bsgData, sptPresets, presets);
539+
hashCalc.init(bsgData, bsgPresets, presets);
535540
item.hash = hashCalc.getItemHash(item.id);
536541
if (!itemsByHash[item.hash.toString()]) {
537542
itemsByHash[item.hash.toString()] = item;

get-json.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
}
5959
return presets;
6060
},
61-
tt_presets: async () => {
61+
td_presets: async () => {
6262
let presets = false;
6363
try {
6464
presets = JSON.parse(fs.readFileSync('./item_presets.json', 'utf8'));
@@ -68,7 +68,11 @@ module.exports = {
6868
}
6969
} catch (error) {
7070
try {
71-
presets = JSON.parse((await got('https://raw.githubusercontent.com/Razzmatazzz/tarkovdata/master/item_presets.json')).body);
71+
if (process.env.API_USERNAME && process.env.API_PASSWORD && process.env.SCANNER_NAME) {
72+
downloadedPresets = await api.getJson('presets.json').catch(() => { return false; });
73+
if (downloadedPresets) presets = downloadedPresets;
74+
}
75+
if (!presets) throw new Error('Error downloading Tarkov.dev presets');
7276
fs.writeFileSync('./item_presets.json', JSON.stringify(presets, null, 4));
7377
} catch (downloadError) {
7478
if (error.message != 'stale') {

hash-calculator.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let presets = false;
33
let ttPresets = false;
44

55
const isWeapon = (item) => {
6+
if (item._props?.Slots?.length < 1) return false;
67
let category = item._parent;
78
while (category) {
89
if (category === '5422acb9af1c889c16000029') return true;

0 commit comments

Comments
 (0)