A few years ago I looked at crafting graphs[1] for Minecraft. I’ve been playing modded Factorio lately and wanted to see what the graph looked like in Factorio. The main mods are Krastorio2 and Space Exploration, but there are a bunch of others thrown in there too.
I ran Factorio and exported the recipes (type: LuaRecipePrototype[2]) to factorio-recipes.txt.
/c lines = {} for k, v in pairs(game.recipe_prototypes) do table.insert(lines, serpent.line({name=v.name, group=v.group.name, subgroup=v.subgroup.name, ingredients=v.ingredients, products=v.products})) end game.write_file("factorio-recipes.txt", table.concat(lines, "\n"))
I then hackily converted this to factorio-recipes.json:
echo '[' >build/factorio-recipes.json perl -p -e 's/ = /: /g;' -e 's/{{/[{/g;' -e 's/}}/}]/g;' -e 's/$/,/;' -e 's/(\w+):/"\1":/g' <factorio-recipes.txt >>build/factorio-recipes.json echo '{}]' >>build/factorio-recipes.json
Now I want to convert it to graphviz format. I tried rendering one category at a time with viz.js[3] but it was kind of slow for some categories so I decided it’d be better to do it offline and save it to images.
node factorio-crafting-graph.js >build/factorio-crafting-graph.html
1 Output#
fluid-filtration#
space-astrometrics#
space-supercomputing-1#
space-supercomputing-2#
space-supercomputing-3#
space-growth#
space-biochemical#
space-decontamination#
space-accelerator#
space-materialisation#
space-recycling#
space-thermodynamics#
crafting#
skipped for size: 472
crafting-with-fluid#
condenser-turbine#
spaceship-antimatter-engine#
spaceship-rocket-engine#
space-electromagnetics#
space-manufacturing#
space-spectrometry#
space-genetics#
space-observation-radio#
space-mechanical#
space-observation-microwave#
space-plasma#
space-radiation#
space-collider#
space-observation-infrared#
lifesupport#
space-gravimetrics#
space-observation-visible#
space-laser#
space-observation-uv#
space-observation-xray#
space-observation-gammaray#
growing#
t3-tech-cards#
core-fragment-processing#
smelting#
chemistry#
atmosphere-condensation#
bioprocessing#
smelting-crafting#
fuel-burning#
oil-processing#
crushing#
skipped for size: 1081
space-radiator#
t2-tech-cards#
fuel-refining#
space-hypercooling#
electrolysis#
centrifuging#
fuel-processing#
fuel-refinery#
rocket-building#
matter-deconversion#
stabilizer-charging#
matter-conversion#
nuclear-fusion#
air-purification#
2 More#
Some of these were interesting but graph layout is just hard. I generated graphviz circo
, neato
, twopi
, dot
with vertical, dot
with horizontal, and fdp
. Of these, circo
was pretty useless, and neato
and twopi
were not readable because the nodes overlapped. So I generated the remaining three and chose the most compact output to show here.
I think it’d be useful to have an interactive version here using viz.js that lets you choose an item and then it shows you what creates and also what you can do with it, but I wasn’t thrilled with the graphs so far and didn’t end up making the interactive version.