Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-write warframe module #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions lib/WarframeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand All @@ -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);
Expand All @@ -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, " ")));
}

/**
Expand All @@ -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 });
}

/**
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions lib/parseState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down