Page 1 of 1

Dump all recipes from the game

Posted: Sun Sep 06, 2015 4:52 pm
by Vilsol
I was wondering if there was a way to dump all recipes, technologies, etc, so that I could use them in an external tool.

Thanks in advance

Re: Dump all recipes from the game

Posted: Sun Sep 06, 2015 4:56 pm
by prg
Those are already stored in a convenient format in data/base/prototypes/.

Re: Dump all recipes from the game

Posted: Sun Sep 06, 2015 5:14 pm
by Vilsol
yes, but if I have tons of mods, means I have to go through so many folders, its insane, also, many mods use variables in their recipes, where extracting them would take quite some time

Re: Dump all recipes from the game

Posted: Sun Sep 06, 2015 5:52 pm
by prg
Iterate over game.forces.player.recipes/technologies and pull out the stuff you care for.

Code: Select all

/c local foo = "" for k, v in pairs(game.forces.player.recipes) do foo = foo .. "recipe "..k.." has "..tostring(#v.ingredients).." ingredients\n" end game.makefile("recepies", foo)
See https://forums.factorio.com/wiki/inde ... Lua/Recipe and https://forums.factorio.com/wiki/inde ... Technology for what keys to find in there, iterate over tables therein and format output to taste. The "recepies" file will be put into the script-output directory.

Re: Dump all recipes from the game

Posted: Mon Sep 07, 2015 8:25 am
by cpy
Heh that's what i was looking for too! Saving just recipe names is good enough for me.

Re: Dump all recipes from the game

Posted: Fri Sep 25, 2015 10:16 pm
by antropod
Hey guys, I made a lua script to dump all recipes to a json file.
Just copy and paste in game console, then check file named `recipes` in script-output directory.
It's not formatted though.

Code: Select all

/c
local out = ""

function write(...)
  local arg = {...}
  for i, v in ipairs(arg) do
    out = out .. tostring(v)
  end
end

function item_count(node)
  local count = 0
  for k, v in pairs(node) do
    count = count + 1
  end
  return count
end

function traverse_table(node)
  write("{")
  level = level + 1
  local i = 1
  local count = item_count(node)
  for k, v in pairs(node) do
    write("\"", tostring(k), "\": ")
    traverse(v)
    if i < count then
      write(",")
    end
    i = i + 1
  end
  write("}")
end

function traverse_array(node)
  local count = item_count(node)
  write("[")
  for k, v in ipairs(node) do
    traverse(v)
    if k < count then
      write(",")
    end
  end
  write("]")
end

function traverse(node)
  if type(node) == "table" then
    if type(next(node)) == "number" then
      traverse_array(node)
    else
      traverse_table(node)
    end
  elseif type(node) == "string" then
    write("\"", node, "\"")
  else
    write(node)
  end
end

function inspect_recipe(node)
  return {
    name=node.name,
    category=node.category,
    products=node.products,
    ingredients=node.ingredients,
    hidden=node.hidden,
    energy=node.energy,
    order=node.order
  }
end


function inspect_all(recipes)
  local r = {}
  for k, v in pairs(recipes) do
    r[k] = inspect_recipe(v)
  end
  traverse(r)
end

inspect_all(game.player.force.recipes)

game.makefile("recipes", out)

Re: Dump all recipes from the game

Posted: Fri Sep 25, 2015 10:17 pm
by antropod

Re: Dump all recipes from the game

Posted: Fri Sep 25, 2015 10:58 pm
by orzelek
You can take a look here:
serpent

Would make part of your scripts much easier to do I think and it's available by default.

Re: Dump all recipes from the game

Posted: Sun Sep 27, 2015 4:00 pm
by ssilk
Moved from general to gameplay help