From c51df8a2d5c78fedb23b1fef2ba3e0da06d886a4 Mon Sep 17 00:00:00 2001 From: Nexela Date: Fri, 21 Jul 2017 17:29:40 -0400 Subject: [PATCH] Better Recipe Handling Former-commit-id: 6537aebc0a64a3318d35fdae365af7b8d1324216 [formerly 4db285d61a1fcec5bbc032aaf597051decd6f436] Former-commit-id: 6537aebc0a64a3318d35fdae365af7b8d1324216 Former-commit-id: 3c740a4c1eded43991b11066eed38b19cc809e85 --- makefile | 4 + prototypes/updates/bob-updates.lua | 20 +++-- prototypes/updates/recipe-updates.lua | 112 ++++++++++++++------------ 3 files changed, 77 insertions(+), 59 deletions(-) diff --git a/makefile b/makefile index ca89b207..81ce2761 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,6 @@ PACKAGE_NAME := $(shell cat info.json|jq -r .name) VERSION_STRING := $(shell cat info.json|jq -r .version) +TOKEN := $(shell cat .token) OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING) BUILD_DIR := .build OUTPUT_DIR := $(BUILD_DIR)/$(OUTPUT_NAME) @@ -33,6 +34,9 @@ git: tag git push --all git push --tags +github-release: + curl --data '{"tag_name": "v$(VERSION_STRING)","target_commitish": "master","name": "vv$(VERSION_STRING)","body": "Release of version $(VERSION_STRING)","draft": true,"prerelease": false}' https://api.github.com/repos/:owner/:repository/releases?access_token=:$TOKEN + package-copy: $(PKG_DIRS) $(PKG_FILES) @mkdir -p $(OUTPUT_DIR) ifneq ($(PKG_COPY),) diff --git a/prototypes/updates/bob-updates.lua b/prototypes/updates/bob-updates.lua index fa16ea33..d1a563ee 100644 --- a/prototypes/updates/bob-updates.lua +++ b/prototypes/updates/bob-updates.lua @@ -8,6 +8,13 @@ local add_result = bobmods.lib.recipe.add_result local remove_result = bobmods.lib.recipe.remove_result local add_prerequisite = bobmods.lib.tech.add_prerequisite +local change_value = function(recipe_str, field, val) + local recipe = data.raw.recipe[recipe_str] + if recipe then + recipe[field] = val + end +end + ------------------------------------------------------------------------------- --[[Entities]]-- ------------------------------------------------------------------------------- @@ -229,14 +236,11 @@ foundry.crafting_categories[#foundry.crafting_categories+1] = "mixing-furnace" ------------------------------------------------------------------------------- add_prerequisite("coal-processing-2", "electrolysis-1") - ------------------------------------------------------------------------------- --[[Categories]]-- ------------------------------------------------------------------------------- - -data.raw.recipe["bob-resin-wood"].energy_required = 10 -data.raw.recipe["bob-resin-wood"].category = "wpu" -data.raw.recipe["polishing-wheel"].category = "wpu" -data.raw.recipe["wooden-board"].energy_required = 10 -data.raw.recipe["phenolic-board"].category = "wpu" - +change_value("bob-resin-wood", "energy_required", 10) +change_value("bob-resin-wood", "category", "wpu") +change_value("polishing-wheel", "category", "wpu") +change_value("wooden-board", "energy_required", 10) +change_value("phenolic-board", "category", "wpu") diff --git a/prototypes/updates/recipe-updates.lua b/prototypes/updates/recipe-updates.lua index 1e153b78..7113bcb4 100644 --- a/prototypes/updates/recipe-updates.lua +++ b/prototypes/updates/recipe-updates.lua @@ -1,93 +1,103 @@ local PYC = require("config") +local function add_ing(str_recipe, normal, expensive) + expensive = expensive or normal + local recipe = data.raw.recipe[str_recipe] + if recipe then + if recipe.normal then + recipe.normal.ingredients[#recipe.normal.ingredients + 1] = normal + if recipe.expensive then + recipe.expensive.ingredients[#recipe.expensive.ingredients + 1] = expensive + end + else + recipe.ingredients[#recipe.ingredients + 1] = normal + end + end +end + +local function rep_ings(str_recipe, normal, expensive) + expensive = expensive or normal + local recipe = data.raw.recipe[str_recipe] + if recipe then + if recipe.normal then + recipe.normal.ingredients = table.deepcopy(normal) + if recipe.expensive then + recipe.expensive.ingredients = table.deepcopy(expensive) + end + else + recipe.ingredients = normal + end + end +end + if PYC.USE_CREOSOTE_RECIPES then -- flag from config.lua if PYC.USE_CREOSOTE_IN.rail then if not data.raw.recipe["bi-rail-wood"] then - local newrail=data.raw.recipe["rail"] - newrail.ingredients = { - {"stone", 1}, - {"iron-stick", 2}, - {"treated-wood", 2} - } + rep_ings("rail", { + {"stone", 1}, + {"iron-stick", 2}, + {"treated-wood", 2} + } + ) end --Bio Industries - if data.raw.recipe["bi-rail-wood"] then - local biwoodrail = data.raw.recipe["bi-rail-wood"] - biwoodrail.ingredients = { + rep_ings("bi-rail-wood", { {"stone", 1}, {"iron-stick", 2}, {"treated-wood", 2} } - end + ) end if PYC.USE_CREOSOTE_IN.power_poles then - local newpole=table.deepcopy(data.raw.recipe["medium-electric-pole"]) + local newpole = data.raw.recipe["medium-electric-pole"] newpole.category = "crafting-with-fluid" - newpole.ingredients[#newpole.ingredients +1] = { - type="fluid", name="creosote", amount=10 - } - data:extend({newpole}) + add_ing("medium-electric-pole", {type="fluid", name="creosote", amount=10}) --Big Wooden Pole Mod - if data.raw.recipe["big-wooden-pole"] then - local bigpole = data.raw.recipe["big-wooden-pole"] - bigpole.ingredients = { + rep_ings("big-wooden-pole", + { {"treated-wood", 5}, {"copper-cable", 8} } - end - - --Bio Industries - if data.raw.recipe["bi-big-wooden-pole"] then - local bibigpole = data.raw.recipe["bi-big-wooden-pole"] - bibigpole.ingredients = { - {"treated-wood", 5}, - {"small-electric-pole", 2}, - } - end + ) end + --Bio Industries + rep_ings("bi-big-wooden-pole", + { + {"treated-wood", 5}, + {"small-electric-pole", 2}, + } + ) + --More Floors - if data.raw.recipe["wood-floor"] then - local woodfloor = data.raw.recipe["wood-floor"] - woodfloor.ingredients = { - {"treated-wood", 10}, + rep_ings("wood-floor", + { + {"treated-wood", 10} } - end + ) --Bio Industries - if data.raw.recipe["bi-wooden-fence"] then - local fence = data.raw.recipe["bi-wooden-fence"] - fence.ingredients = + rep_ings("bi-wooden-fence", { {"treated-wood", 2}, {"raw-wood", 2}, } - end + ) end --ADDING NIOBIUM INTO LOW DENSITY STRUCTURE do - local part - part = data.raw.recipe["low-density-structure"] - part.normal.ingredients[#part.normal.ingredients + 1] = {type = "item", name = "niobium-plate", amount = 5} - part = data.raw.recipe["low-density-structure"] - part.expensive.ingredients[#part.expensive.ingredients + 1] = {type = "item", name = "niobium-plate", amount = 10} + local normal = {type = "item", name = "niobium-plate", amount = 5} + local expensive = {type = "item", name = "niobium-plate", amount = 10} + add_ing("low-density-structure", normal, expensive) end --ADDING FUELROD INTO ROCKET-FUEL INTO ROCKET-FUEL do - local part = data.raw.recipe["rocket-fuel"] local normal = {type = "item", name = "fuelrod-mk01", amount = 2} local expensive = {type = "item", name = "fuelrod-mk01", amount = 4} - if part.normal then - part.normal.ingredients[#part.normal.ingredients + 1] = normal - if part.expensive then - part.expensive.ingredients[#part.expensive.ingredients + 1] = expensive - end - else - part.ingredients[#part.ingredients + 1] = normal - end + add_ing("rocket-fuel", normal, expensive) end