researchSync: Tried to avoid errors when research doesn't exist

This commit is contained in:
Danielv123 committed 2018-04-12 07:49:40 +02:00
1 parent 7a4ea69cbb
commit c8f2a67845
3 files changed
+51 -5

No files matched your search

@@ -0,0 +1,5 @@
/silent-command
if game.forces['player'].technologies['£key'] then
game.forces['player'].technologies['£key'].researched=true
game.print("researcSync enabled research: £key")
end
+12 -5
View File
@@ -8,7 +8,8 @@ class ResearchSync {
this.functions = this.loadFunctions();
this.config = slaveConfig;
this.messageInterface = messageInterface;
console.log = messageInterface;
this.research = {};
messageInterface("ResearchSync enabled");
@@ -26,7 +27,7 @@ class ResearchSync {
doSync() {
needle.post(this.config.masterIP + ':' + this.config.masterPort + '/api/getSlavesMeta', {
password: this.config.clientPassword,
}, function (err, resp, body) {
}, (err, resp, body) => {
if (err) throw err;
if (resp.statusCode != 200){
@@ -50,7 +51,12 @@ class ResearchSync {
Object.keys(difference).forEach((key) => {
if (difference[key] == 1) {
this.messageInterface("/c game.forces['player'].technologies['" + key + "'].researched=true");
let command = this.functions.enableResearch;
while(command.includes("£key")){
command = command.replace("£key", key);
}
this.messageInterface(command);
// this.messageInterface("/c game.forces['player'].technologies['" + key + "'].researched=true");
}
})
@@ -62,7 +68,7 @@ class ResearchSync {
}, function (err, resp) {
// success?
});
}.bind(this));
});
}
diff(array1, array2) {
@@ -77,7 +83,8 @@ class ResearchSync {
loadFunctions() {
return {
dumpResearch: this.loadFunc("dumpResearch.lua")
dumpResearch: this.loadFunc("dumpResearch.lua"),
enableResearch: this.loadFunc("enableResearch.lua"),
};
}
+34
View File
@@ -0,0 +1,34 @@
const assert = require("assert");
const researchSync = require("./index.js");
describe("researchSync/index.js", ()=>{
it("exports a single class (or at least a function)", ()=>{
assert.equal(typeof researchSync, "function");
});
describe("class researchSync()", ()=>{
it(".diff(object1, object2) returns key:value pairs that exist in object2 but not object1", ()=>{
let reSync = new researchSync();
let obj1 = {
a:"str",
b:123,
c:console.log,
d:"apple cake",
}
let obj2 = {
a:"str",
b:9999,
c:console.log,
e:"truthy",
}
assert(typeof reSync.diff == "function");
let diffResult = reSync.diff(obj1, obj2);
assert(diffResult.a === undefined);
assert(diffResult.b === 9999);
assert(diffResult.d === undefined);
assert(diffResult.e === "truthy");
});
});
});