mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
researchSync: Tried to avoid errors when research doesn't exist
This commit is contained in:
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
|
||||||
@@ -8,7 +8,8 @@ class ResearchSync {
|
|||||||
this.functions = this.loadFunctions();
|
this.functions = this.loadFunctions();
|
||||||
this.config = slaveConfig;
|
this.config = slaveConfig;
|
||||||
this.messageInterface = messageInterface;
|
this.messageInterface = messageInterface;
|
||||||
|
console.log = messageInterface;
|
||||||
|
|
||||||
this.research = {};
|
this.research = {};
|
||||||
|
|
||||||
messageInterface("ResearchSync enabled");
|
messageInterface("ResearchSync enabled");
|
||||||
@@ -26,7 +27,7 @@ class ResearchSync {
|
|||||||
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) {
|
}, (err, resp, body) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
if (resp.statusCode != 200){
|
if (resp.statusCode != 200){
|
||||||
@@ -50,7 +51,12 @@ class ResearchSync {
|
|||||||
|
|
||||||
Object.keys(difference).forEach((key) => {
|
Object.keys(difference).forEach((key) => {
|
||||||
if (difference[key] == 1) {
|
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) {
|
}, function (err, resp) {
|
||||||
// success?
|
// success?
|
||||||
});
|
});
|
||||||
}.bind(this));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
diff(array1, array2) {
|
diff(array1, array2) {
|
||||||
@@ -77,7 +83,8 @@ class ResearchSync {
|
|||||||
|
|
||||||
loadFunctions() {
|
loadFunctions() {
|
||||||
return {
|
return {
|
||||||
dumpResearch: this.loadFunc("dumpResearch.lua")
|
dumpResearch: this.loadFunc("dumpResearch.lua"),
|
||||||
|
enableResearch: this.loadFunc("enableResearch.lua"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user