If you just want a picture of your full tech tree, like the 3rd screenshot above, you don't need this mod. You can just run this command in the in-game console to create a screenshot in your .factorio/script-output
folder:
/c game.take_technology_screenshot{player=game.player}
You only need this mod if you want a text-file with the nodes and arrows.
How to use
This mod creates a new file in your Factorio folder (the parent of the mods
folder), in script-output/TechTreeDiagram.gv
. This is a text file with nodes representing tech IDs and arrows for prereqs.
To generate the file you will need to actually start a new game including generating a world in freeplay/sandbox. The code runs in control.lua, not data, because it needs to run after all other mods that modify the tech tree.
To turn the .gv file into a PNG image, like the 2nd image above, install GraphViz and then run:
dot -Tpng -o output.png TechTreeDiagram.gv
For a better diagram, you can convert to a GML file:
- Windows:
dot -Tgml -o TechTreeDiagram.gml TechTreeDiagram.gv
- Linux:
gv2gml TechTreeDiagram.gv >TechTreeDiagram.gml
Once you have a GML file, you can open it in an application like yEd, then use one of yEd's auto-layout options. See the 1st image above.
The dot
and gv2gml
commands are from the GraphViz package. GraphViz and yEd are available on both Windows and Linux, and the instructions above should work for both of them.
Alternative: Just copy-paste this script
Instead of this mod, you can do exactly the same thing by just running this command in the in-game console:
/c local techIds = {}
local techEdges = {}
for id, tech in pairs(prototypes.technology) do
table.insert(techIds, id)
for prereqId, _ in pairs(tech.prerequisites) do
if techEdges[prereqId] == nil then
techEdges[prereqId] = {}
end
table.insert(techEdges[prereqId], id)
end
end
local lines = {"digraph G {"}
for _, id in ipairs(techIds) do
table.insert(lines, string.format('"%s" [label="%s"];', id, id))
end
for prereqId, postreqIds in pairs(techEdges) do
table.insert(lines, string.format('"%s" -> {"%s"};', prereqId, table.concat(postreqIds, '" "')))
end
table.insert(lines, "}")
helpers.write_file("TechTreeDiagram.gv", table.concat(lines, '\n'))
Wishlist: Script to report tech tree info
It would be nice to have a script to report information about the tech tree useful to modpack-makers, such as: redundant tech dependencies, recipes that are unlocked before their ingredients are unlocked, a list of techs that are "dead ends" (nothing has them as prereq), and so on. If you have one, upload it as your own mod, or put it in the wiki. Or you could send me a pull request to add that script to this mod.
I have implemented some of this stuff in the auto-debugger in Legendary Space Age.
Wishlist: Item/recipe graph
It would be nice to have a mod that makes a graph with nodes for items and recipes, and with arrows item=>recipe if the item is an ingredient, and also arrows recipe=>item if the item is a product. As a separate mod, because this mod is already named "Tech Tree Diagram". I'm not currently working on making this mod, but maybe I will in the future. If you are a programmer, feel free to make this mod.
Update: I implemented a basic version of this, but it was not very useful. The graph is very dense, with e.g. iron plates having arrows to half the items on the graph. Maybe what we really need is a graph of all techs, items, buildings, and recipes, with some intuitive simplifications (like unifying a recipe node with an item node, if the item can only be produced by that one recipe, and the recipe only has one output). For the modpack I'm working on, I've given up on trying to automate all this graphing etc., and am instead taking the approach of manually charting everything in yEd, then moving around all the nodes to decide visually how the modpack's progression should be structured.
Also, here is a mod that does something like this: https://mods.factorio.com/mod/dana