From 8820f379264222dcb83ff88ba36ab9cf546a4deb Mon Sep 17 00:00:00 2001 From: Brevven Date: Sat, 25 Jun 2022 23:43:03 -0700 Subject: [PATCH] upd --- data-util.lua | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/data-util.lua b/data-util.lua index d700645..1dc5fef 100644 --- a/data-util.lua +++ b/data-util.lua @@ -54,6 +54,19 @@ function util.contains(table, sought) return false end +-- Set/override a technology's prerequisites +function util.set_prerequisite(technology_name, prerequisites) + local technology = data.raw.technology[technology_name] + if technology then + technology.prerequisites = {} + for i, prerequisite in pairs(prerequisites) do + if data.raw.technology[prerequisite] then + table.insert(technology.prerequisites, prerequisite) + end + end + end +end + -- Add a prerequisite to a given technology function util.add_prerequisite(technology_name, prerequisite) local technology = data.raw.technology[technology_name] @@ -444,14 +457,19 @@ function util.replace_product(recipe_name, old, new) end function replace_product(recipe, old, new) - if recipe ~= nil and recipe.results ~= nil then + if recipe then + if recipe.main_product == old then + recipe.main_product = new + end if recipe.result == old then - recipe.results = new + recipe.result = new return end - for i, result in pairs(recipe.results) do - if result.name == old then result.name = new end - if result[1] == old then result[1] = new end + if recipe.results then + for i, result in pairs(recipe.results) do + if result.name == old then result.name = new end + if result[1] == old then result[1] = new end + end end end end