From 7c65df526cb349975782ed74b08f91545cacc004 Mon Sep 17 00:00:00 2001 From: protocol-1903 Date: Sun, 7 Dec 2025 10:59:37 -0700 Subject: [PATCH 1/4] py.global_replace_prerequesite --- lib/data-stage.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/data-stage.lua b/lib/data-stage.lua index 0999e1b..ec38ba2 100644 --- a/lib/data-stage.lua +++ b/lib/data-stage.lua @@ -328,6 +328,34 @@ py.global_item_replacer = function(old, new, blackrecipe) end end +---replaces every instance of the old prerequesite with the new one. if the new one is omitted, removes the old prerequesite instead +---@param old string +---@param new string +py.global_replace_prerequesite = function(old, new) + if not data.raw.technology[old] then + log("WARNING @ py.global_replace_prerequesite(): Technology " .. old .. " does not exist") + return + end + if new and not data.raw.technology[new] then + log("WARNING @ py.global_replace_prerequesite(): Technology " .. new .. " does not exist") + return + end + if new then + for _, tech in pairs(data.raw.technology) do + for i, prereq in pairs(tech.prerequesites or {}) do + if prereq == old then + tech.prerequesites[i] = new + break + end + end + end + else -- no need to do fancy checks, just remove it + for tech in pairs(data.raw.technology) do + TECHNOLOGY(tech):remove_prereq(old) + end + end +end + ---adds a small icon to the top right corner of a recipe ---@param recipe data.RecipePrototype ---@param corner table From 28aa0eaea948e553744b0590d59c946386840498 Mon Sep 17 00:00:00 2001 From: protocol-1903 Date: Sun, 7 Dec 2025 11:07:00 -0700 Subject: [PATCH 2/4] fix spelling error, renamed for consistency to py.global_prerequisite_replacer --- lib/data-stage.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/data-stage.lua b/lib/data-stage.lua index ec38ba2..c5bc197 100644 --- a/lib/data-stage.lua +++ b/lib/data-stage.lua @@ -330,8 +330,8 @@ end ---replaces every instance of the old prerequesite with the new one. if the new one is omitted, removes the old prerequesite instead ---@param old string ----@param new string -py.global_replace_prerequesite = function(old, new) +---@param new? string +py.global_prerequisite_replacer = function(old, new) if not data.raw.technology[old] then log("WARNING @ py.global_replace_prerequesite(): Technology " .. old .. " does not exist") return @@ -342,9 +342,9 @@ py.global_replace_prerequesite = function(old, new) end if new then for _, tech in pairs(data.raw.technology) do - for i, prereq in pairs(tech.prerequesites or {}) do + for i, prereq in pairs(tech.prerequisites or {}) do if prereq == old then - tech.prerequesites[i] = new + tech.prerequisites[i] = new break end end From b6d1d0a46040ddc61551c1b2af468ed1d425cb37 Mon Sep 17 00:00:00 2001 From: protocol-1903 Date: Sun, 7 Dec 2025 13:16:25 -0700 Subject: [PATCH 3/4] fix spelling errors --- lib/data-stage.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/data-stage.lua b/lib/data-stage.lua index c5bc197..3d54173 100644 --- a/lib/data-stage.lua +++ b/lib/data-stage.lua @@ -333,11 +333,11 @@ end ---@param new? string py.global_prerequisite_replacer = function(old, new) if not data.raw.technology[old] then - log("WARNING @ py.global_replace_prerequesite(): Technology " .. old .. " does not exist") + log("WARNING @ py.global_prerequisite_replacer(): Technology " .. old .. " does not exist") return end if new and not data.raw.technology[new] then - log("WARNING @ py.global_replace_prerequesite(): Technology " .. new .. " does not exist") + log("WARNING @ py.global_prerequisite_replacer(): Technology " .. new .. " does not exist") return end if new then From 0292bc0eca902a28be6145be2ed2ac70cd29fb46 Mon Sep 17 00:00:00 2001 From: protocol-1903 Date: Sun, 7 Dec 2025 23:52:44 -0700 Subject: [PATCH 4/4] update changelog --- changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 85403ac..325bf34 100644 --- a/changelog.txt +++ b/changelog.txt @@ -9,6 +9,8 @@ Date: ???? - Fix a crash with Schall Machine Scaling - Fixed a crash when cleaning up recycling recipes created by quality that had no results. Resolves https://github.com/pyanodon/pybugreports/issues/1284 - Added process to automatically set spoil level of spoilable items. Resolves https://github.com/pyanodon/pybugreports/issues/1260 + - Added py.global_prerequisite_replacer + - Updated metas LuaLS --------------------------------------------------------------------------------------------------- Version: 3.0.39 Date: 2025-09-15