Rename research to tech

Use tech as the loop variable for researches as this is consistent with
the rest of the researchSync module.
This commit is contained in:
Hornwitser committed 2019-10-12 17:07:08 +02:00
1 parent 6a6274e85c
commit 3b1ed1a667
1 file changed
+37 -29
+37 -29
View File
@@ -169,22 +169,24 @@ class ResearchSync {
}) })
} }
clear_contribution_to_researched_techs() { clear_contribution_to_researched_techs() {
for (let [name, research] of Object.entries(this.research)) { for (let [name, tech] of Object.entries(this.research)) {
if (!Object.hasOwnProperty.call(this.prev_research, name)) { if (!Object.hasOwnProperty.call(this.prev_research, name)) {
continue; continue;
} }
let researched let researched;
if (research.infinite) if (tech.infinite) {
researched = this.prev_research[name].level < research.level researched = this.prev_research[name].level < tech.level;
else } else {
researched = this.prev_research[name].researched < research.researched researched = this.prev_research[name].researched < tech.researched;
}
if (researched) if (researched) {
research.contribution = 0 tech.contribution = 0;
} }
} }
}
get_cluster_techs(slavesData) { get_cluster_techs(slavesData) {
let cluster_techs = {} let cluster_techs = {}
@@ -209,32 +211,38 @@ class ResearchSync {
} }
recount_cluster_research_progress(slaves_data, cluster_researches) { recount_cluster_research_progress(slaves_data, cluster_researches) {
for (let [name, research] of Object.entries(cluster_researches)) for (let [name, tech] of Object.entries(cluster_researches))
research.progress = this.research[name].contribution tech.progress = this.research[name].contribution
for (let slave_data of slaves_data) { for (let slave_data of slaves_data) {
for (let [name, research] of Object.entries(slave_data.meta.research)) { for (let [name, tech] of Object.entries(slave_data.meta.research)) {
if (!Object.hasOwnProperty.call(cluster_researches, name)) { if (!Object.hasOwnProperty.call(cluster_researches, name)) {
continue; continue;
} }
if (isNaN(cluster_researches[name].progress)
|| isNaN(research.contribution) if (
|| isNaN(research.level) isNaN(cluster_researches[name].progress)
|| isNaN(cluster_researches[name].level)) || isNaN(tech.contribution)
continue || isNaN(tech.level)
if (cluster_researches[name].level === research.level) || isNaN(cluster_researches[name].level)
cluster_researches[name].progress += research.contribution ) {
continue;
}
if (cluster_researches[name].level === tech.level) {
cluster_researches[name].progress += tech.contribution;
}
} }
} }
for (let [name, research] of Object.entries(cluster_researches)) { for (let [name, tech] of Object.entries(cluster_researches)) {
if (research.progress > 1) { if (tech.progress > 1) {
research.progress = null tech.progress = null
research.researched = 1 tech.researched = 1
this.research[name].contribution = 0 this.research[name].contribution = 0
research.contribution = 0 tech.contribution = 0
if (this.research[name].level >= research.level) if (this.research[name].level >= tech.level)
research.level = this.research[name].level + 1 tech.level = this.research[name].level + 1
} }
} }
} }
@@ -353,7 +361,7 @@ class ResearchSync {
return return
if (Object.hasOwnProperty.call(this.research, name)) { if (Object.hasOwnProperty.call(this.research, name)) {
this.prev_research[name] = this.research[name] this.prev_research[name] = this.research[name];
} else { } else {
this.prev_research[name] = { this.prev_research[name] = {
researched: null, researched: null,