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 diff --git a/lib/data-stage.lua b/lib/data-stage.lua index 0999e1b..3d54173 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_prerequisite_replacer = function(old, new) + if not data.raw.technology[old] then + 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_prerequisite_replacer(): Technology " .. new .. " does not exist") + return + end + if new then + for _, tech in pairs(data.raw.technology) do + for i, prereq in pairs(tech.prerequisites or {}) do + if prereq == old then + tech.prerequisites[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