From 7f82680511225b8324a3becddb08c6d2388e96e7 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 12 Oct 2019 01:45:41 +0200 Subject: [PATCH] Port set progress when completing infinite researches Set the progress for the next level of an infinite research when unlocking it via a script. This is necessary when the research is actively being researched as Factorio will carry over the progress for the current level into the next one when set via a script. It's possible for the new progress to be non-zero if the next level was on the research queue. This is a port of 62f3a99. --- CHANGELOG.md | 2 ++ sharedPlugins/researchSync/enableResearch.lua | 17 ++++++++++++----- sharedPlugins/researchSync/index.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac4de35..c35883c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Version 1.2.2 - Fixed possible crash with modded technologies named the same as a built-in Object prototype property in researchSync. +- Fixed progress of a current infinite tech carrying over to the next one + when researching it and another node completes it in researchSync. Version 1.2.1 diff --git a/sharedPlugins/researchSync/enableResearch.lua b/sharedPlugins/researchSync/enableResearch.lua index f83a1e93..8c8b7329 100644 --- a/sharedPlugins/researchSync/enableResearch.lua +++ b/sharedPlugins/researchSync/enableResearch.lua @@ -11,15 +11,22 @@ local function updateTech() end end -if game.forces['player'].technologies['{tech_name}'] then +local force = game.forces['player'] +local tech = force.technologies['{tech_name}'] +if tech then if 1 == {tech_infinite} then - if (game.forces['player'].technologies['{tech_name}'].level ~= level) then - game.forces['player'].technologies['{tech_name}'].level = {tech_level} + if (tech.level ~= level) then + tech.level = {tech_level} + if tech == force.current_research then + force.research_progress = {tech_progress} + else + force.set_saved_technology_progress(tech.name, {tech_progress}); + end updateTech() end else - if not game.forces['player'].technologies['{tech_name}'].researched then - game.forces['player'].technologies['{tech_name}'].researched = true + if not tech.researched then + tech.researched = true updateTech() end end diff --git a/sharedPlugins/researchSync/index.js b/sharedPlugins/researchSync/index.js index 1efcf93f..37fb7a0d 100644 --- a/sharedPlugins/researchSync/index.js +++ b/sharedPlugins/researchSync/index.js @@ -271,9 +271,9 @@ class ResearchSync { this.research[name].progress = null let command = this.functions.enableResearch; command = command.replace(/{tech_name}/g, name); - command = command.replace(/{tech_researched}/g, tech.researched); command = command.replace(/{tech_level}/g, tech.level); command = command.replace(/{tech_infinite}/g, tech.infinite); + command = command.replace(/{tech_progress}/g, tech.progress) command = command.replace(/{notify}/g, notify); this.messageInterface(command); let log_message = tech.infinite