diff --git a/lib/WarframeData.js b/lib/WarframeData.js index c941b0f..a03631e 100644 --- a/lib/WarframeData.js +++ b/lib/WarframeData.js @@ -3,9 +3,10 @@ */ "use strict"; -let fs = require("fs"); -let path = require("path"); -let https = require("https"); +const fs = require("fs"); +const fsp = fs.promises; +const path = require("path"); +const fetch = require("node-fetch"); /** * Source for constant (between updates) copies of warframe data, eg languages and other data @@ -17,10 +18,10 @@ class WarframeData { * @param {Object} options * @param {string} options.fileName */ - constructor({fileName}) { + constructor({ fileName }) { this._fileName = fileName; this._filePath = path.join(__dirname, `../warframeData/${this._fileName}.json`); - this._fileExampleUrl = `https://raw.githubusercontent.com/VoiDGlitch/WarframeData/master/JSON/${this._fileName}.json`; + this._fileExampleUrl = `http://content.warframe.com/MobileExport/Manifest/${this._fileName}.json`; this.reload(); } @@ -32,7 +33,7 @@ class WarframeData { if (err.code === "ENOENT") { console.error(`Config file ${this._fileName} not found in ${this._filePath} attempting to copy default from ${this._fileExampleUrl} Please download it if it does not exist.`); downloadPromise = this.downloadAndWrite(); - downloadPromise.then(()=> { + downloadPromise.then(() => { console.error(`Warframe resource file ${this._fileName} was copied to ${this._filePath}.`); }).catch((error) => { console.error(error); @@ -50,15 +51,15 @@ class WarframeData { } downloadAndWrite() { - return new Promise((resolve) => { - https.get(this._fileExampleUrl, (response) => { - let file = fs.createWriteStream(this._filePath); - response.pipe(file); - response.on("end", () => { - resolve(file); - }) - }); - }) + return fetch(this._fileExampleUrl) + .then(res => res.json()) + .then(json => { + return json[this._fileName].reduce((acc, region) => { + acc[region.uniqueName] = region; + return acc; + }, {}) + }) + .then(json => fsp.writeFile(this._filePath, JSON.stringify(json, null, " "))); } /** @@ -73,7 +74,7 @@ class WarframeData { let failThrow; if (options.hasOwnProperty("failThrow")) failThrow = `Error Property ${key} does not exist on ${this._fileName}`; let keys = key.split("."); - return this._recursiveGet(keys, this._data, {fallback: options.fallBack, failThrow}); + return this._recursiveGet(keys, this._data, { fallback: options.fallBack, failThrow }); } /** @@ -93,13 +94,13 @@ class WarframeData { * @returns {*} * @private */ - _recursiveGet(keys, data, {fallback, failThrow}) { + _recursiveGet(keys, data, { fallback, failThrow }) { if (keys.length === 0) { return data; } let key = keys.shift(); if (typeof data === "object" && data.hasOwnProperty(key)) { - return this._recursiveGet(keys, data[key], {fallback, failThrow}); + return this._recursiveGet(keys, data[key], { fallback, failThrow }); } else { if (fallback) return fallback; if (failThrow) throw failThrow; diff --git a/lib/parseState.js b/lib/parseState.js index 17f01ad..9ad5454 100644 --- a/lib/parseState.js +++ b/lib/parseState.js @@ -5,8 +5,7 @@ let WarframeData = require("./WarframeData"); let languages = new WarframeData({fileName: "Languages"}); -let missionDecks = new WarframeData({fileName: "MissionDecks"}); -let starChart = new WarframeData({fileName: "StarChart"}); +let Regions = new WarframeData({fileName: "ExportRegions"}); let paths = require('../../Paths.json'); const utils = require('./utils'); @@ -114,14 +113,14 @@ class ParseState { * Get's the locations a thing can drop from * @param {string} part */ - static getLocations(part) { + /*static getLocations(part) { let data = missionDecks.getData(); let partsList = []; let lvl2Keys = ["Rotation A", "Rotation B", "Rotation C"]; Object.keys(data).forEach(a => { }); - } + }*/ /** * Get's the name of a item from it's filepath as provided in the worldstate @@ -226,7 +225,7 @@ class ParseState { try { let node = starChart.get(name); if (!node) return name; - return node.name; + return `${node.name} [${node.systemName}]`; } catch (error) { console.error(error); console.error(name);