mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-30 16:57:13 +09:00
Formatting and logging adjustments
This commit is contained in:
1 parent
0afe35b67c
commit
b666a909ab
2 files changed
+29
-14
No files matched your search
@@ -8,8 +8,8 @@ if game.forces['player'].technologies['{tech_name}'] then
|
||||
script.raise_event(defines.events.on_research_finished, {research=game.forces['player'].technologies['{tech_name}'], by_script=true})
|
||||
game.play_sound({path="utility/research_completed"})
|
||||
if 1 == {tech_infinite} then
|
||||
game.print("Technology {tech_name} synced at level {tech_level}")
|
||||
game.print("Infinite technology {tech_name} level {tech_level} unlocked")
|
||||
else
|
||||
game.print("Technology {tech_name} synced")
|
||||
game.print("Technology {tech_name} researched")
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const needle = require("needle");
|
||||
|
||||
|
||||
class ResearchSync {
|
||||
constructor(slaveConfig, messageInterface, extras = {}) {
|
||||
this.config = slaveConfig;
|
||||
@@ -10,7 +9,8 @@ class ResearchSync {
|
||||
|
||||
this.research = {};
|
||||
|
||||
setInterval(() => {
|
||||
setInterval(
|
||||
() => {
|
||||
this.pollResearch();
|
||||
setTimeout(this.doSync.bind(this), 5000);
|
||||
},
|
||||
@@ -40,23 +40,31 @@ class ResearchSync {
|
||||
if (slaveData[instanceKey].unique === this.config.unique.toString()) {
|
||||
return;
|
||||
}
|
||||
if (!slaveData[instanceKey].hasOwnProperty('meta') || !slaveData[instanceKey].meta.hasOwnProperty('research')) {
|
||||
if (!slaveData[instanceKey].hasOwnProperty('meta')
|
||||
|| !slaveData[instanceKey].meta.hasOwnProperty('research')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let researchList = slaveData[instanceKey].meta.research;
|
||||
if (researchList) {
|
||||
Object.keys(researchList).forEach(researchName => {
|
||||
if (isNaN(researchList[researchName].researched) || isNaN(researchList[researchName].level) || isNaN(researchList[researchName].infinite)) {
|
||||
if (
|
||||
isNaN(researchList[researchName].researched)
|
||||
|| isNaN(researchList[researchName].level)
|
||||
|| isNaN(researchList[researchName].infinite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (needResearch.hasOwnProperty(researchName)) {
|
||||
if (needResearch[researchName].infinite === 1
|
||||
&& needResearch[researchName].level < parseInt(researchList[researchName].level))
|
||||
{
|
||||
if (
|
||||
needResearch[researchName].infinite === 1
|
||||
&& needResearch[researchName].level < parseInt(researchList[researchName].level)
|
||||
) {
|
||||
needResearch[researchName].level = parseInt(researchList[researchName].level);
|
||||
} else if (needResearch[researchName].researched === 0
|
||||
&& parseInt(researchList[researchName].researched) === 1)
|
||||
{
|
||||
} else if (
|
||||
needResearch[researchName].researched === 0
|
||||
&& parseInt(researchList[researchName].researched) === 1
|
||||
) {
|
||||
needResearch[researchName].researched = 1
|
||||
}
|
||||
} else {
|
||||
@@ -82,8 +90,14 @@ class ResearchSync {
|
||||
command = command.replace("{tech_infinite}", difference[key].infinite);
|
||||
}
|
||||
this.messageInterface(command);
|
||||
console.log('Unlocking '+ key + ': ' + (difference[key].researched === 0 ? 'false' : 'true') + ' and level ' + difference[key].level + ', was '+ (this.research[key].researched === 0 ? 'false' : 'true') + ' at level ' + this.research[key].level);
|
||||
this.messageInterface("Unlocking research: " + key + " at research state = " + (difference[key].researched === 0 ? 'false' : 'true') + ' and level ' + difference[key].level);
|
||||
let log_message = '';
|
||||
if (difference[key].infinite === 1) {
|
||||
log_message = 'Unlocking infinite research ' + key + 'at level ' + this.research[key].level;
|
||||
} else {
|
||||
log_message = 'Unlocking research ' + key;
|
||||
}
|
||||
console.log(log_message);
|
||||
this.messageInterface(log_message);
|
||||
this.research[key] = difference[key];
|
||||
}
|
||||
});
|
||||
@@ -126,6 +140,7 @@ class ResearchSync {
|
||||
loadFunc(path) {
|
||||
return fs.readFileSync("sharedPlugins/researchSync/" + path, 'utf-8').replace(/\r?\n|\r/g, ' ');
|
||||
}
|
||||
|
||||
scriptOutput(data) {
|
||||
let kv = data.split(":");
|
||||
let name = kv[0];
|
||||
|
||||
Reference in new issue
Block a user