researchSync removed node-lua dependency

This commit is contained in:
Danielv123 committed 2018-04-11 21:38:28 +02:00
1 parent 12bf445579
commit 7a4ea69cbb
2 files changed
+7 -26

No files matched your search

-1
View File
@@ -47,7 +47,6 @@
"node-factorio-api": "^0.3.1-alpha", "node-factorio-api": "^0.3.1-alpha",
"node-forge": "^0.7.1", "node-forge": "^0.7.1",
"prom-client": "^10.2.3", "prom-client": "^10.2.3",
"node-lua": "^1.0.4",
"request": "^2.83.0", "request": "^2.83.0",
"right-pad": "^1.0.1", "right-pad": "^1.0.1",
"rmdir-sync": "^1.0.1", "rmdir-sync": "^1.0.1",
+7 -25
View File
@@ -1,5 +1,4 @@
var fs = require('fs'); const fs = require('fs');
const nodelua = require('node-lua');
const needle = require("needle"); const needle = require("needle");
@@ -11,32 +10,24 @@ class ResearchSync {
this.messageInterface = messageInterface; this.messageInterface = messageInterface;
this.research = {}; this.research = {};
this.lua = new nodelua.LuaState();
messageInterface("ResearchSync enabled"); messageInterface("ResearchSync enabled");
setInterval(function () { setInterval(() => {
this.pollResearch.call(this); this.pollResearch();
setTimeout(this.doSync.bind(this), 2) setTimeout(this.doSync, 2)
}.bind(this), 2000); }, 2000);
} }
pollResearch() { pollResearch() {
this.messageInterface("Polling Research\n") this.messageInterface("Polling Research\n")
this.messageInterface(this.functions.dumpResearch); this.messageInterface(this.functions.dumpResearch);
} }
doSync() { doSync() {
needle.post(this.config.masterIP + ':' + this.config.masterPort + '/api/getSlavesMeta', { needle.post(this.config.masterIP + ':' + this.config.masterPort + '/api/getSlavesMeta', {
password: this.config.clientPassword, password: this.config.clientPassword,
}, function (err, resp, body) { }, function (err, resp, body) {
if (err) { if (err) throw err;
throw err;
}
if (resp.statusCode != 200){ if (resp.statusCode != 200){
console.log("got error when calling getSlaveMeta", resp.statusCode, resp.body); console.log("got error when calling getSlaveMeta", resp.statusCode, resp.body);
@@ -55,7 +46,6 @@ class ResearchSync {
}); });
}) })
var difference = this.diff(this.research, needResearch); var difference = this.diff(this.research, needResearch);
Object.keys(difference).forEach((key) => { Object.keys(difference).forEach((key) => {
@@ -73,20 +63,15 @@ class ResearchSync {
// success? // success?
}); });
}.bind(this)); }.bind(this));
} }
diff(array1, array2) { diff(array1, array2) {
var diff = {}; var diff = {};
Object.keys(array2).forEach((element) => { Object.keys(array2).forEach((element) => {
if (array2[element] != array1[element]){ if (array2[element] != array1[element]){
diff[element] = array2[element]; diff[element] = array2[element];
} }
}); });
return diff; return diff;
} }
@@ -101,11 +86,8 @@ class ResearchSync {
} }
scriptOutput(data){ scriptOutput(data){
try { try {
this.lua.DoString("a = " + data); let research = JSON.parse(data.replace("=",":").replace("[","").replace("]",""));
this.lua.GetGlobal("a");
let currentResearch = this.lua.ToValue(-1);
this.research = Object.assign(this.research, currentResearch); this.research = Object.assign(this.research, currentResearch);
this.lua.Pop();
} catch (e) { } catch (e) {
} }
} }