From 86b98f8bc9f9f5f340c60bc82e1d84069f343e80 Mon Sep 17 00:00:00 2001 From: Wyrrrd Date: Wed, 22 Mar 2023 13:38:44 +0100 Subject: [PATCH] Rewrite against bugs and for performance --- .vscode/settings.json | 9 +++++ changelog.txt | 7 ++++ data-final-fixes.lua | 77 +++++++++++++++++++++++++++++++++---------- info.json | 5 +-- 4 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1505ae5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "factorio.versions": [ + { + "name": "Factorio", + "factorioPath": "d:\\Modding\\Factorio\\bin\\x64\\factorio.exe", + "active": true + } + ] +} \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index 62f1af6..e6e0cad 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,11 @@ --------------------------------------------------------------------------------------------------- +Version: 1.1.3 +Date: 2023-03-22 + Changes: + - Complete rewrite to enable copying rail recipe result amount, and for performance + Features: + - Added "gravel" from IR3 to overwritten materials +--------------------------------------------------------------------------------------------------- Version: 1.1.2 Date: 2021-09-06 Changes: diff --git a/data-final-fixes.lua b/data-final-fixes.lua index 3b533d8..586e5be 100644 --- a/data-final-fixes.lua +++ b/data-final-fixes.lua @@ -1,25 +1,66 @@ -local base_recipe = {} --- grab rail recipe ingredients except stone -for _,component in pairs(data.raw["recipe"]["rail"].ingredients) do - cname = component[1] or component["name"] - camount = component[2] or component["amount"] - if cname ~= "stone" then - table.insert(base_recipe,{cname,camount}) +-- setup id helper maps +ingredients_id_map = {old = false} +for id, item in pairs(data.raw["recipe"]["rail"].ingredients) do + ingredients_id_map[item[1] or item["name"]] = id + if item[1] then + ingredients_id_map["old"] = true end end -data.raw["recipe"]["bbr-rail-wood"].ingredients = table.deepcopy(base_recipe) -data.raw["recipe"]["bbr-rail-iron"].ingredients = table.deepcopy(base_recipe) -data.raw["recipe"]["bbr-rail-brick"].ingredients = table.deepcopy(base_recipe) +if data.raw["recipe"]["rail"].products then + products_id_map = {} + print(tprint(data.raw["recipe"]["rail"])) + for id, item in pairs(data.raw["recipe"]["rail"].products) do products_id_map[item[1] or item["name"]] = id end +end + +-- mod integrations +if mods["IndustrialRevolution3"] then + replace_item = "gravel" +else + replace_item = "stone" +end + + +-- get multiplier multiplier = settings.startup["bbr-fix-cost"].value -if multiplier>0 then - table.insert(data.raw["recipe"]["bbr-rail-wood"].ingredients,{"wood",multiplier}) - table.insert(data.raw["recipe"]["bbr-rail-iron"].ingredients,{"iron-plate",multiplier}) - table.insert(data.raw["recipe"]["bbr-rail-brick"].ingredients,{"stone-brick",multiplier}) -else - table.insert(data.raw["recipe"]["bbr-rail-wood"].ingredients,{"wood",1}) - table.insert(data.raw["recipe"]["bbr-rail-iron"].ingredients,{"iron-plate",1}) - table.insert(data.raw["recipe"]["bbr-rail-brick"].ingredients,{"stone-brick",1}) + +-- setup bridge material list +bridges = { + {name = "wood", item = "wood"}, + {name = "iron", item = "iron-plate"}, + {name = "brick", item = "stone-brick"} +} + +for _, bridge in pairs(bridges) do + -- copy rail recipe to bridge + data.raw["recipe"]["bbr-rail-"..bridge.name] = table.deepcopy(data.raw["recipe"]["rail"]) + + -- fix recipe name + data.raw["recipe"]["bbr-rail-"..bridge.name].name = "bbr-rail-"..bridge.name + + -- replace stone with multiplied bridge material + if ingredients_id_map.old then + data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]][1] = bridge.item + + -- apply multiplier + if multiplier > 1 then + data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]][2] = multiplier * data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]][2] + end + else + data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]].name = bridge.item + + -- apply multiplier + if multiplier > 1 then + data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]].amount = multiplier * data.raw["recipe"]["bbr-rail-"..bridge.name].ingredients[ingredients_id_map[replace_item]].amount + end + end + + -- replace rails with bridges + if products_id_map then + data.raw["recipe"]["bbr-rail-"..bridge.name].products[products_id_map["rail"]].name = "bbr-rail-"..bridge.name + else + data.raw["recipe"]["bbr-rail-"..bridge.name].result = "bbr-rail-"..bridge.name + end end \ No newline at end of file diff --git a/info.json b/info.json index ed77187..c32c996 100644 --- a/info.json +++ b/info.json @@ -1,12 +1,13 @@ { "name": "bbr-fix", - "version": "1.1.2", + "version": "1.1.3", "title": "Beautiful Bridge Railway - Recipe Fix", "author": "Wyrrrd", "factorio_version": "1.1", "dependencies": [ "base >= 1.1.0", - "beautiful_bridge_railway >= 1.1.1" + "beautiful_bridge_railway >= 1.1.1", + "(?) IndustrialRevolution3 >= 3.0.1" ], "description": "Adds rails to recipes." } \ No newline at end of file