mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
researchSync: Fixed importing research
This commit is contained in:
1 parent
c9bd26a01e
commit
1d0d9765bd
4 files changed
+43
-37
No files matched your search
@@ -238,7 +238,9 @@ app.post("/api/editSlaveMeta", function(req,res) {
|
||||
slaves[req.body.instanceID].meta = {};
|
||||
}
|
||||
slaves[req.body.instanceID].meta = deepmerge(slaves[req.body.instanceID].meta, req.body.meta, {clone:true});
|
||||
console.log("Updating slave: " + slaves[req.body.instanceID].mac + " : " + slaves[req.body.instanceID].serverPort+" at " + slaves[req.body.instanceID].publicIP, req.body.meta);
|
||||
let metaPortion = JSON.stringify(req.body.meta);
|
||||
if(metaPortion.length > 50) metaPortion = metaPortion.substring(0,20) + "...";
|
||||
console.log("Updating slave "+slaves[req.body.instanceID].instanceName+": " + slaves[req.body.instanceID].mac + " : " + slaves[req.body.instanceID].serverPort+" at " + slaves[req.body.instanceID].publicIP, metaPortion);
|
||||
} else {
|
||||
res.send("ERROR: Invalid instanceID or password")
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
local lines = "";
|
||||
|
||||
for _, tech in pairs(game.forces["player"].technologies) do
|
||||
local dict = {};
|
||||
dict[tech.name] = tech.researched;
|
||||
lines = lines .. serpent.line(dict) .. "\n";
|
||||
lines = lines .. tech.name .. ":" .. tostring(tech.researched) .. "\n";
|
||||
end
|
||||
|
||||
game.write_file("researchSync.txt",lines)
|
||||
|
||||
@@ -35,17 +35,20 @@ class ResearchSync {
|
||||
|
||||
let needResearch = {};
|
||||
|
||||
Object.entries(allmeta).map((instance) => {
|
||||
if (instance[1] == null || instance[1].research == null) return;
|
||||
Object.entries(instance[1].research).map((research) => {
|
||||
if (research[1] == 1) {
|
||||
needResearch[research[0]] = 1;
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
allmeta.forEach(instance => {
|
||||
if(instance){
|
||||
let researchList = instance.research;
|
||||
if(researchList){
|
||||
Object.keys(researchList).forEach(researchName => {
|
||||
let researched = researchList[researchName];
|
||||
if(JSON.parse(researched)){
|
||||
needResearch[researchName] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
var difference = this.diff(this.research, needResearch);
|
||||
|
||||
Object.keys(difference).forEach((key) => {
|
||||
if (difference[key] == 1) {
|
||||
let command = this.functions.enableResearch;
|
||||
@@ -53,6 +56,7 @@ class ResearchSync {
|
||||
command = command.replace("£key", key);
|
||||
}
|
||||
this.messageInterface(command);
|
||||
this.messageInterface("Unlocking research: "+key)
|
||||
// this.messageInterface("/c game.forces['player'].technologies['" + key + "'].researched=true");
|
||||
}
|
||||
})
|
||||
@@ -91,16 +95,10 @@ class ResearchSync {
|
||||
}
|
||||
scriptOutput(data){
|
||||
try {
|
||||
// remove Lua table junk
|
||||
let currentResearch = data.replace("=",":").replace("[","").replace("]","").replace('"', "").replace('"', "");
|
||||
// add first " before key
|
||||
currentResearch = '{"' + currentResearch.slice(1);
|
||||
// add second " after the key to make it a string
|
||||
currentResearch = currentResearch.split(" ")[0] + '"' + currentResearch.slice(currentResearch.split(" ")[0].length);
|
||||
// turn our constructed JSON string into an object
|
||||
currentResearch = JSON.parse(currentResearch);
|
||||
// console.log(currentResearch)
|
||||
this.research = Object.assign(this.research, currentResearch);
|
||||
let kv = data.split(":");
|
||||
let name = kv[0];
|
||||
let value = JSON.parse(kv[1]);
|
||||
this.research[name] = value;
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,23 +47,32 @@ describe("researchSync/index.js", ()=>{
|
||||
assert(ioRecieved);
|
||||
});
|
||||
describe(".scriptOutput(data) handles file writes from factorio", ()=>{
|
||||
it("wants a Lua table of a single research, parses and saves it", ()=>{
|
||||
it("wants a key:value pair of a single research, parses and saves it", ()=>{
|
||||
let reSync = new researchSync({hi:"hello"}, console.log);
|
||||
let researches = [
|
||||
'{automation = false}',
|
||||
'{["automation-2"] = false}',
|
||||
'{["automation-3"] = false}',
|
||||
'{electronics = false}',
|
||||
'{["advanced-electronics"] = false}',
|
||||
'{["advanced-electronics-2"] = false}',
|
||||
'{["circuit-network"] = false}',
|
||||
'{explosives = false}',
|
||||
'{logistics = false}',
|
||||
'{["logistics-2"] = false}',
|
||||
'automation:false',
|
||||
'automation-2:false',
|
||||
'automation-3:false',
|
||||
'electronics:false',
|
||||
'advanced-electronics:false',
|
||||
'advanced-electronics-2:false',
|
||||
'circuit-network:false',
|
||||
'explosives:false',
|
||||
'logistics:false',
|
||||
'logistics-2:false',
|
||||
'logistics-3:false',
|
||||
'optics:false',
|
||||
'laser:false',
|
||||
'solar-energy:false',
|
||||
'turrets:false',
|
||||
'laser-turrets:false',
|
||||
'stone-walls:false',
|
||||
'gates:false',
|
||||
'engine:false',
|
||||
]
|
||||
researches.forEach(research => {
|
||||
reSync.scriptOutput(research);
|
||||
assert(isFactorioCommand("/c x = "+research));
|
||||
assert(!isFactorioCommand("/c x = "+research));
|
||||
});
|
||||
assert(Object.keys(reSync.research).length == researches.length);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user