fix load error

This commit is contained in:
Brevven 2021-01-24 04:25:27 -08:00
parent 4346425610
commit 1db2ff551d
3 changed files with 27 additions and 14 deletions

View file

@ -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 Version: 0.1.3
Date: 2021-01-19 Date: 2021-01-19
Changes: Changes:

View file

@ -1,6 +1,6 @@
{ {
"name": "bzlead", "name": "bzlead",
"version": "0.1.3", "version": "0.1.4",
"factorio_version": "1.1", "factorio_version": "1.1",
"title": "Lead", "title": "Lead",
"author": "Brevven", "author": "Brevven",

View file

@ -33,10 +33,12 @@ end
-- Add a given quantity of ingredient to a given recipe -- Add a given quantity of ingredient to a given recipe
function util.add_ingredient(recipe_name, ingredient, quantity) function util.add_ingredient(recipe_name, 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], ingredient, quantity)
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
end end
end
function add_ingredient(recipe, ingredient, quantity) function add_ingredient(recipe, ingredient, quantity)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then
@ -44,12 +46,14 @@ function add_ingredient(recipe, ingredient, quantity)
end end
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) function util.replace_ingredient(recipe_name, 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], old, new)
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new) replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new) replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new)
end end
end
function replace_ingredient(recipe, old, new) function replace_ingredient(recipe, old, new)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then
@ -64,10 +68,12 @@ end
-- Remove an ingredient from a recipe -- Remove an ingredient from a recipe
function util.remove_ingredient(recipe_name, old) function util.remove_ingredient(recipe_name, old)
if data.raw.recipe[recipe_name] then
remove_ingredient(data.raw.recipe[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].normal, old)
remove_ingredient(data.raw.recipe[recipe_name].expensive, old) remove_ingredient(data.raw.recipe[recipe_name].expensive, old)
end end
end
function remove_ingredient(recipe, old) function remove_ingredient(recipe, old)
index = -1 index = -1
@ -87,10 +93,12 @@ end
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old. -- 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) function util.replace_some_ingredient(recipe_name, 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], old, new, amount)
replace_some_ingredient(data.raw.recipe[recipe_name].normal, 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) replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount)
end end
end
function replace_some_ingredient(recipe, old, new, amount) function replace_some_ingredient(recipe, old, new, amount)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then