From c8f05d5e5eab8fa950dfc3c2f66657a227e861e1 Mon Sep 17 00:00:00 2001 From: Brevven Date: Tue, 9 Aug 2022 12:35:30 -0700 Subject: [PATCH] more compat --- aluminum-burner-phase.lua | 1 + changelog.txt | 3 +++ data-util.lua | 41 ++++++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/aluminum-burner-phase.lua b/aluminum-burner-phase.lua index fd67810..538736c 100644 --- a/aluminum-burner-phase.lua +++ b/aluminum-burner-phase.lua @@ -93,6 +93,7 @@ util.add_prerequisite("heavy-armor", "copper-processing") util.set_enabled("deadlock-copper-lamp", false) util.add_effect("copper-processing", { type = "unlock-recipe", recipe = "deadlock-copper-lamp" }) +util.add_unlock_force("electronics", "electronic-circuit") util.replace_ingredients_prior_to("electronics", "electronic-circuit", "aluminum-cable") util.replace_ingredients_prior_to("copper-processing", "copper-cable", "aluminum-cable") util.replace_ingredients_prior_to("copper-processing", "copper-plate", "aluminum-plate") diff --git a/changelog.txt b/changelog.txt index 195e1b0..53f6d51 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,9 @@ Version: 0.4.3 Date: 2022-08-10 Changes: - Lamp only requires 1 aluminum cable now. + Fixes: + - Some more general compatibility fixes, thanks to U.N.Owen, including improved compatibility + with their fork of Research Desk. --------------------------------------------------------------------------------------------------- Version: 0.4.2 Date: 2022-08-08 diff --git a/data-util.lua b/data-util.lua index d4fabec..3c8d6a5 100644 --- a/data-util.lua +++ b/data-util.lua @@ -137,21 +137,25 @@ function util.add_unlock(technology_name, recipe) util.add_effect(technology_name, {type="unlock-recipe", recipe=recipe}) end --- remove recipe unlock effect from a given technology +-- remove recipe unlock effect from a given technology, multiple times if necessary function util.remove_recipe_effect(technology_name, recipe_name) - local technology = data.raw.technology[technology_name] - local index = -1 - if technology and technology.effects then - for i, effect in pairs(technology.effects) do - if effect.type == "unlock-recipe" and effect.recipe == recipe_name then - index = i - break - end + local technology = data.raw.technology[technology_name] + local index = -1 + local cnt = 0 + if technology and technology.effects then + for i, effect in pairs(technology.effects) do + if effect.type == "unlock-recipe" and effect.recipe == recipe_name then + index = i + cnt = cnt + 1 + end + end + if index > -1 then + table.remove(technology.effects, index) + if cnt > 1 then -- not over yet, do it again + util.remove_recipe_effect(technology_name, recipe_name) + end + end end - if index > -1 then - table.remove(technology.effects, index) - end - end end -- Set technology ingredients @@ -964,5 +968,16 @@ function replace_ingredients_prior_to(tech, old, new, multiplier) end end +function util.remove_all_recipe_effects(recipe_name) + for name, _ in pairs(data.raw.technology) do + util.remove_recipe_effect(name, recipe_name) + end +end + +function util.add_unlock_force(technology_name, recipe) + util.set_enabled(recipe, false) + util.remove_all_recipe_effects(recipe) + util.add_unlock(technology_name, recipe) +end return util