diff --git a/changelog.txt b/changelog.txt index ae0291d..fa82ace 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.1.4 +Date: 2021-01-22 + Fixes: + - Attempt to fix a load error by failing gracefully +--------------------------------------------------------------------------------------------------- Version: 0.1.3 Date: 2021-01-19 Changes: diff --git a/info.json b/info.json index 36eb4b8..32d4101 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "bzlead", - "version": "0.1.3", + "version": "0.1.4", "factorio_version": "1.1", "title": "Lead", "author": "Brevven", diff --git a/util.lua b/util.lua index 2d7a6ca..c862a17 100644 --- a/util.lua +++ b/util.lua @@ -33,9 +33,11 @@ end -- Add a given quantity of ingredient to a given recipe function util.add_ingredient(recipe_name, ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) + if data.raw.recipe[recipe_name] then + add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity) + add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) + add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) + end end function add_ingredient(recipe, ingredient, quantity) @@ -44,11 +46,13 @@ function add_ingredient(recipe, ingredient, quantity) end end --- Replace one ingredien with another in a recipe +-- Replace one ingredient with another in a recipe function util.replace_ingredient(recipe_name, old, new) - replace_ingredient(data.raw.recipe[recipe_name], old, new) - replace_ingredient(data.raw.recipe[recipe_name].normal, old, new) - replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new) + if data.raw.recipe[recipe_name] then + replace_ingredient(data.raw.recipe[recipe_name], old, new) + replace_ingredient(data.raw.recipe[recipe_name].normal, old, new) + replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new) + end end function replace_ingredient(recipe, old, new) @@ -64,9 +68,11 @@ end -- Remove an ingredient from a recipe function util.remove_ingredient(recipe_name, old) - remove_ingredient(data.raw.recipe[recipe_name], old) - remove_ingredient(data.raw.recipe[recipe_name].normal, old) - remove_ingredient(data.raw.recipe[recipe_name].expensive, old) + if data.raw.recipe[recipe_name] then + remove_ingredient(data.raw.recipe[recipe_name], old) + remove_ingredient(data.raw.recipe[recipe_name].normal, old) + remove_ingredient(data.raw.recipe[recipe_name].expensive, old) + end end function remove_ingredient(recipe, old) @@ -87,9 +93,11 @@ end -- Replace an amount of an ingredient in a recipe. Keep at least 1 of old. function util.replace_some_ingredient(recipe_name, old, new, amount) - replace_some_ingredient(data.raw.recipe[recipe_name], old, new, amount) - replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount) - replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount) + if data.raw.recipe[recipe_name] then + replace_some_ingredient(data.raw.recipe[recipe_name], old, new, amount) + replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount) + replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount) + end end function replace_some_ingredient(recipe, old, new, amount)