From 6652ec2b869fef5acc42778ebe84b718a1d34753 Mon Sep 17 00:00:00 2001 From: Brevven Date: Wed, 16 Sep 2020 16:26:09 -0700 Subject: [PATCH] Integrate into vanilla --- data-final-fixes.lua | 1 + data-updates.lua | 1 + info.json | 2 +- recipe-updates.lua | 37 +++++++++++++++++++ util.lua | 86 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 data-final-fixes.lua create mode 100644 data-updates.lua create mode 100644 recipe-updates.lua create mode 100644 util.lua diff --git a/data-final-fixes.lua b/data-final-fixes.lua new file mode 100644 index 0000000..e697401 --- /dev/null +++ b/data-final-fixes.lua @@ -0,0 +1 @@ +-- require("silicon-recipe-final") diff --git a/data-updates.lua b/data-updates.lua new file mode 100644 index 0000000..02f820b --- /dev/null +++ b/data-updates.lua @@ -0,0 +1 @@ +require("recipe-updates") diff --git a/info.json b/info.json index a70d8e3..f8f08a7 100644 --- a/info.json +++ b/info.json @@ -9,6 +9,6 @@ "dependencies": [ "base >= 0.18" ], - "description": "Adds simple Silica and Silicon to the game." + "description": "Adds simple Silica and Silicon to the game, along with basic fiber optics." } diff --git a/recipe-updates.lua b/recipe-updates.lua new file mode 100644 index 0000000..1b5f203 --- /dev/null +++ b/recipe-updates.lua @@ -0,0 +1,37 @@ +local util = require("__bzsilicon__.util"); + +util.remove_ingredient("concrete", "stone-brick"); +util.add_ingredient("concrete", "silica", 25); +util.add_prerequisite("concrete", "silica-processing") + +util.replace_some_ingredient("processing-unit", "electronic-circuit", "silicon", 10) +util.add_prerequisite("advanced-electronics-2", "silicon-processing") + +util.replace_some_ingredient("solar-panel", "electronic-circuit", "silicon", 10) +util.add_prerequisite("solar-energy", "silicon-processing") + +util.replace_ingredient("effectivity-module", "electronic-circuit", "silicon") +util.replace_ingredient("productivity-module", "electronic-circuit", "silicon") +util.replace_ingredient("speed-module", "electronic-circuit", "silicon") +util.add_prerequisite("modules", "silicon-processing") + +util.replace_ingredient("beacon", "copper-cable", "optical-fiber") +util.add_prerequisite("effect-transmission", "fiber-optics") + + +-- Circuit network changes +util.replace_ingredient("green-wire", "copper-cable", "optical-fiber") +util.replace_ingredient("green-wire", "electronic-circuit", "silicon") +util.replace_ingredient("red-wire", "copper-cable", "optical-fiber") +util.replace_ingredient("red-wire", "electronic-circuit", "silicon") + +util.add_ingredient("arithmetic-combinator", "silicon", 1); +util.add_ingredient("arithmetic-combinator", "optical-fiber", 1); +util.add_ingredient("constant-combinator", "silicon", 1); +util.add_ingredient("constant-combinator", "optical-fiber", 1); +util.add_ingredient("decider-combinator", "silicon", 1); +util.add_ingredient("decider-combinator", "optical-fiber", 1); +util.add_ingredient("programmable-speaker", "optical-fiber", 1); + +util.add_prerequisite("circuit-network", "fiber-optics") +util.add_prerequisite("circuit-network", "silicon-processing") diff --git a/util.lua b/util.lua new file mode 100644 index 0000000..d4d492a --- /dev/null +++ b/util.lua @@ -0,0 +1,86 @@ +local util = {} + +-- Add a prerequisite to a given technology +function util.add_prerequisite(technology_name, prerequisite) + technology = data.raw.technology[technology_name] + table.insert(technology.prerequisites, prerequisite) +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) +end + +function add_ingredient(recipe, ingredient, quantity) + if recipe ~= nil and recipe.ingredients ~= nil then + table.insert(recipe.ingredients, {ingredient, quantity}) + end +end + +-- Replace one ingredien 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) +end + +function replace_ingredient(recipe, old, new) + if recipe ~= nil and recipe.ingredients ~= nil then + for i, ingredient in pairs(recipe.ingredients) do + -- For final fixes + if ingredient.name == old then ingredient.name = new end + -- For updates + if ingredient[1] == old then ingredient[1] = new end + end + end +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) +end + +function remove_ingredient(recipe, old) + index = -1 + if recipe ~= nil and recipe.ingredients ~= nil then + for i, ingredient in pairs(recipe.ingredients) do + if ingredient.name == old or ingredient[1] == old then + index = i + break + end + end + if index > -1 then + table.remove(recipe.ingredients, index) + end + end +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) +end + +function replace_some_ingredient(recipe, old, new, amount) + if recipe ~= nil and recipe.ingredients ~= nil then + for i, ingredient in pairs(recipe.ingredients) do + -- For final fixes + if ingredient.name == old then + ingredient.amount = math.max(1, ingredient.amount - amount) + end + -- For updates + if ingredient[1] == old then + ingredient[2] = math.max(1, ingredient[2] - amount) + end + end + add_ingredient(recipe, new, amount) + end +end + +return util