diff --git a/README.md b/README.md index b2fa2f8..3adb739 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ See changelog.txt ## Thanks to - [snouz](https://github.com/snouz) (logo inspiration, ore graphics templates) - [YassineMrabet](https://commons.wikimedia.org/wiki/File:Fullerene.png) (initial fullerene image, CC BY-SA 3.0 license, see link) +- [dodo.the.last](https://mods.factorio.com/mod/big-data-string) (borrowed code for list feature) ### Localization diff --git a/changelog.txt b/changelog.txt index 4707d19..d4964fe 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.10 +Date: 2022-01-05 + Features: + - Add setting to dump modified recipes to file +--------------------------------------------------------------------------------------------------- Version: 0.0.9 Date: 2022-01-04 Changes: diff --git a/control-util.lua b/control-util.lua new file mode 100644 index 0000000..968b924 --- /dev/null +++ b/control-util.lua @@ -0,0 +1,23 @@ +local me = require("me") + +local util = {} +util.me = me + +function decode(data) + if type(data) == "string" then return data end + local str = {} + for i = 2, #data do + str[i-1] = decode(data[i]) + end + return table.concat(str, "") +end + +function util.get_list() + local p = game.item_prototypes[me.name.."-list"] + if p then + data = p.localised_description + return decode(data) + end +end + +return util diff --git a/control.lua b/control.lua new file mode 100644 index 0000000..e5567b2 --- /dev/null +++ b/control.lua @@ -0,0 +1,19 @@ +local util = require("control-util") + +function on_console_chat(event) + if event.message and string.lower(event.message) == "bzlist" then + local player = game.players[event.player_index] + if player and player.connected then + local list = util.get_list() + if list and #list>0 then + local filename = util.me.name..".txt" + game.write_file(filename, list, false, event.player_index) + player.print("Wrote recipes to script-output/"..filename) + end + end + end +end +script.on_event(defines.events.on_console_chat, on_console_chat) + + + diff --git a/data-final-fixes.lua b/data-final-fixes.lua index a453dee..a32065d 100644 --- a/data-final-fixes.lua +++ b/data-final-fixes.lua @@ -4,7 +4,7 @@ require("carbon-recipe-final-se") require("carbon-recipe-final-rrr") require("carbon-recipe-modules") -- Should be last import -local util = require("__bzcarbon__.data-util"); +local util = require("data-util"); -- Green circuits in final fixes due to K2 shenanigans @@ -41,3 +41,6 @@ for i, furnace in pairs(util.me.furnaces) do end end + +-- Must be last +util.create_list() diff --git a/data-updates.lua b/data-updates.lua index 0d28f64..17f5f87 100644 --- a/data-updates.lua +++ b/data-updates.lua @@ -4,3 +4,8 @@ require("carbon-matter") require("strange-matter") -- require("omni") + +local util = require("data-util"); + +-- Must be last +util.create_list() diff --git a/data-util.lua b/data-util.lua index b840c3d..99014b9 100644 --- a/data-util.lua +++ b/data-util.lua @@ -97,6 +97,7 @@ end function util.add_ingredient(recipe_name, ingredient, quantity) if me.bypass[recipe_name] then return end if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then + me.add_modified(recipe_name) 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) @@ -135,6 +136,7 @@ end function util.replace_ingredient(recipe_name, old, new) if me.bypass[recipe_name] then return end if data.raw.recipe[recipe_name] and data.raw.item[new] then + me.add_modified(recipe_name) 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) @@ -160,6 +162,7 @@ end function util.remove_ingredient(recipe_name, old) if me.bypass[recipe_name] then return end if data.raw.recipe[recipe_name] then + me.add_modified(recipe_name) 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) @@ -185,6 +188,7 @@ end function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount) if me.bypass[recipe_name] then return end if data.raw.recipe[recipe_name] and data.raw.item[new] then + me.add_modified(recipe_name) replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount) replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount) replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount) @@ -213,8 +217,9 @@ end -- multiply the cost, energy, and results of a recipe by a multiple function util.multiply_recipe(recipe_name, multiple) - if me.bypass[recipe_name] then return end + me.add_modified(recipe_name) if data.raw.recipe[recipe_name] then + if me.bypass[recipe_name] then return end multiply_recipe(data.raw.recipe[recipe_name], multiple) multiply_recipe(data.raw.recipe[recipe_name].normal, multiple) multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple) @@ -285,8 +290,9 @@ end -- Remove a product from a recipe, WILL NOT remove the only product function util.remove_product(recipe_name, old) - if me.bypass[recipe_name] then return end + me.add_modified(recipe_name) if data.raw.recipe[recipe_name] then + if me.bypass[recipe_name] then return end remove_product(data.raw.recipe[recipe_name], old) remove_product(data.raw.recipe[recipe_name].normal, old) remove_product(data.raw.recipe[recipe_name].expensive, old) @@ -344,8 +350,9 @@ end -- Multiply energy required function util.multiply_time(recipe_name, factor) - if me.bypass[recipe_name] then return end + me.add_modified(recipe_name) if data.raw.recipe[recipe_name] then + if me.bypass[recipe_name] then return end multiply_time(data.raw.recipe[recipe_name], factor) multiply_time(data.raw.recipe[recipe_name].normal, factor) multiply_time(data.raw.recipe[recipe_name].expensive, factor) @@ -362,11 +369,9 @@ end -- Add to energy required function util.add_time(recipe_name, amount) - log("Doing ".. recipe_name) - log(amount) - if me.bypass[recipe_name] then return end - log(1) + me.add_modified(recipe_name) if data.raw.recipe[recipe_name] then + if me.bypass[recipe_name] then return end add_time(data.raw.recipe[recipe_name], amount) add_time(data.raw.recipe[recipe_name].normal, amount) add_time(data.raw.recipe[recipe_name].expensive, amount) @@ -383,18 +388,20 @@ end -- Set recipe category function util.set_category(recipe_name, category) - if me.bypass[recipe_name] then return end - if data.raw.recipe[recipe_name] then - data.raw.recipe[recipe_name].category = category - end + if me.bypass[recipe_name] then return end + if data.raw.recipe[recipe_name] then + me.add_modified(recipe_name) + data.raw.recipe[recipe_name].category = category + end end -- Set recipe subgroup function util.set_subgroup(recipe_name, subgroup) - if me.bypass[recipe_name] then return end - if data.raw.recipe[recipe_name] then - data.raw.recipe[recipe_name].subgroup = subgroup - end + if me.bypass[recipe_name] then return end + if data.raw.recipe[recipe_name] then + me.add_modified(recipe_name) + data.raw.recipe[recipe_name].subgroup = subgroup + end end function util.set_to_founding(recipe) @@ -471,4 +478,74 @@ function util.add_minable_result(t, name, result) end end +local function insert(nodes, node, value) + table.insert(node, value) -- store as parameter + if 21 == #node then + node = {""} + table.insert(nodes, node) + end + return node +end + +local function encode(data) + local node = {""} + local root = {node} + local n = string.len(data) + for i = 1,n,200 do + local value = string.sub(data, i, i+199) + node = insert(root, node, value) + end + while #root > 20 do + local nodes,node = {},{""} + for _, value in ipairs(root) do + node = insert(nodes, node, value) + end + root = nodes + end + if #root == 1 then root = root[1] else + table.insert(root, 1, "") -- no locale template + end + return #root < 3 and (root[2] or "") or root +end + +function decode(data) + if type(data) == "string" then return data end + local str = {} + for i = 2, #data do + str[i-1] = decode(data[i]) + end + return table.concat(str, "") +end + +function util.create_list() + if #me.list>0 then + if not data.raw.item[me.name.."-list"] then + data:extend({{ + type="item", + name=me.name.."-list", + localised_description = "", + enabled=false, + icon = "__core__/graphics/empty.png", + icon_size = 1, + stack_size = 1, + flags = {"hidden", "hide-from-bonus-gui"} + }}) + end + + local have = {} + local list = {} + for i, recipe in pairs(me.list) do + if not have[recipe] then + have[recipe] = true + table.insert(list, recipe) + end + end + + if #list>0 then + data.raw.item[me.name.."-list"].localised_description = + encode(decode(data.raw.item[me.name.."-list"].localised_description).."\n"..table.concat(list, "\n")) + end + end +end + return util diff --git a/data.lua b/data.lua index 8759316..09548c1 100644 --- a/data.lua +++ b/data.lua @@ -7,3 +7,8 @@ require("carbon-recipe") require("carbon-recipe-k2") -- must be after carbon-recipe require("carbon-recipe-se") + +local util = require("data-util"); + +-- Must be last +util.create_list() diff --git a/info.json b/info.json index 478416a..0076d98 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "bzcarbon", - "version": "0.0.9", + "version": "0.0.10", "factorio_version": "1.1", "title": "Graphite & Diamonds", "author": "Brevven", diff --git a/locale/en/carbon.cfg b/locale/en/carbon.cfg index 65ced78..081a858 100644 --- a/locale/en/carbon.cfg +++ b/locale/en/carbon.cfg @@ -32,6 +32,8 @@ diamond-processing=Diamond processing graphene=Graphene fullerenes=Fullerenes nanotubes=Carbon nanotubes +flake-graphite-synthesis=Graphite synthesis +carbon-matter-processing=Elemental carbon conversion [technology-description] graphite-processing=Process flake graphite into usable graphite @@ -60,12 +62,14 @@ graphite-carbon-black=Convert excess carbon black to graphite at a low ratio. [mod-setting-name] bzcarbon-recipe-bypass=Bypass recipes +bzcarbon-list=Make a list of modified recipes bzcarbon-enable-fullerenes=Enable fullerenes & nanotubes bzcarbon-enable-carbon-black=Enable carbon black bzcarbon-enable-rough-diamond=Enable diamond mining [mod-setting-description] bzcarbon-recipe-bypass=Skip modifying these recipes (comma-separated list). +bzcarbon-list=If enabled, the text command [color=orange]BZList[/color] will dump a file to the script-output directory with a full list of recipes modified.\nRecommended to turn this off after you are done configuring your other settings. bzcarbon-enable-fullerenes=Enable the fullerenes & nanotubes intermediate products.\nFullerenes are used primarily in bio-related things. Nanotubes for structures. bzcarbon-enable-carbon-black=Enable carbon black byproduct. Primarily used to make plastics. bzcarbon-enable-rough-diamond=Enables diamond ore patches for new games. diff --git a/me.lua b/me.lua index c5454f9..33cbd14 100644 --- a/me.lua +++ b/me.lua @@ -1,6 +1,7 @@ local me = {} me.name = "bzcarbon" +me.list = {} function me.use_fullerenes() return me.get_setting("bzcarbon-enable-fullerenes") == "yes" @@ -28,6 +29,12 @@ if me.get_setting(me.name.."-recipe-bypass") then end end +function me.add_modified(name) + if me.get_setting(me.name.."-list") then + table.insert(me.list, name) + end +end + me.crucible_ingredients = {"tungsten-plate", "zirconia", "stone-brick", "silica"} me.furnaces = { "electric-furnace", diff --git a/settings.lua b/settings.lua index 5b7459e..26e42f1 100644 --- a/settings.lua +++ b/settings.lua @@ -27,4 +27,10 @@ data:extend({ default_value = mods["rso-mod"] and "yes" or "no", allowed_values = {"no", "yes"}, }, + { + type = "bool-setting", + name = "bzcarbon-list", + setting_type = "startup", + default_value = false, + }, })