Tech Tree Diagram


For creators of mods and modpacks. Creates a GraphViz file with a diagram of the game's tech tree. Requires external tools to view the diagram, see description.

Utilities
5 months ago
1.1
50
Owner:
StephenB
Source:
https://github.com/StephenBarnes/Tech...
Homepage:
N/A
License:
MIT
Created:
5 months ago
Latest Version:
1.0.0 (5 months ago)
Factorio version:
1.1
Downloaded by:
50 users

If you just want a picture of your full tech tree, like the 3rd screenshot above, you do NOT need this mod. You can simply run this in-game to create a screenshot in your .factorio/script-output folder:

/c game.take_technology_screenshot{}

EDIT: in Factorio 2.0, this command needs to be: /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(game.technology_prototypes) 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, "}")
game.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, paste it in the discussion section and I'll put it here. Or 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.

Wishlist: Item/recipe graph

It would be nice to have a similar 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. Probably release 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, which isn't terribly hard. The graph requires extensive cleanup to remove recipes for barrelling, etc., and some mods (like IR3) will create multiple numbered recipes that are basically the same. On top of that, the graph isn't terribly useful because it's very dense, with e.g. iron plates having arrows to half the items on the graph. Also on further thought, 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