diff --git a/sharedPlugins/researchSync/enableResearch.lua b/sharedPlugins/researchSync/enableResearch.lua new file mode 100644 index 00000000..2231ea8e --- /dev/null +++ b/sharedPlugins/researchSync/enableResearch.lua @@ -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 diff --git a/sharedPlugins/researchSync/index.js b/sharedPlugins/researchSync/index.js index 9a6c4ec0..9da88351 100644 --- a/sharedPlugins/researchSync/index.js +++ b/sharedPlugins/researchSync/index.js @@ -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"), }; } diff --git a/sharedPlugins/researchSync/index.spec.js b/sharedPlugins/researchSync/index.spec.js new file mode 100644 index 00000000..be753362 --- /dev/null +++ b/sharedPlugins/researchSync/index.spec.js @@ -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"); + }); + }); +});