Closed Xp-speit2018 closed 1 year ago
When I'm saying "dependency graph" I mean a directed graph where:
When this graph is acyclic, we can easily visualize it in a hierarchical layout by a simple topological sort, as is illustrated above. This layout could be much helpful when we are actually designing a factory.
Looks like a cool idea! Not easy to implement though. Especially as it would need to support complicated loops somehow.
Personally, I doubt I'll have the time or dedication to implement this. If you want to implement it, I'm sure that it could be merged in to Helmod.
Thank you for your affirmation. Since I am familiar with python
and its module networkx
, which contains useful functions for graph theory, I will firstly research this problem in python
. Afterward I'll have a try to implement in lua
(never used before but looks good to me).
I have successfully parsed helmod sharing code. It turns out to be a lua table data structure, which can be transformed to json with a little effort. It seems that this code does not contain recipe information...
For example in the field R8
(which stands for the 8-th row I guess), It only tells us to use "recipe", but I don't know how to get it...
exactly, helmod model don't contain détail of recipe only the necessary information.
1) for the graph: we can't draw the graph in the UI I don't know if we can put image in the runtime 2) I see only one solution to retrieve information from recipes when the game run, RCON but someone must do the interface. I have build a little mod for that HelfimaRCON_0.1.0.zip
Thanks. Inspired by the source code of your mods, I typed the code below in console:
/c local list = {}
for _, recipe in pairs(game.player.force.recipes) do
local tmp = {}
tmp.name = recipe.name
tmp.enabled = recipe.enabled
tmp.energy = recipe.energy
tmp.ingredients = recipe.ingredients
tmp.products = recipe.products
table.insert(list, tmp)
end
local json = game.table_to_json(list)
game.write_file("recipes.json", json, true)
And I got a recipes.json
in %appdata%\Factorio
folder, which would be enough to continue my research. The head of it looks like:
[
{
"name": "aai-signal-receiver",
"enabled": true,
"energy": 10,
"ingredients": [
{
"type": "item",
"amount": 10,
"name": "electric-engine-unit"
},
{
"type": "item",
"amount": 20,
"name": "processing-unit"
},
{
"type": "item",
"amount": 20,
"name": "steel-plate"
},
{
"type": "item",
"amount": 20,
"name": "copper-plate"
}
],
"products": [
{
"type": "item",
"name": "aai-signal-receiver",
"probability": 1,
"amount": 1
}
]
},
As for plotting the graph I will take a look at the official api later to confirm the viability.
I'd recommend checking out this mod to see how they are drawing arbitrary lines https://mods.factorio.com/mod/belt-visualizer
It uses LuaRendering.draw_line. This api provides interface to draw lines on the ground as an object.
According to LuaGuiElement, it seems that drawing arbitrary arrows is temporarily not possible. As an alternative way we can use a SpritePath
of Sprite Gui Element which can load a picture file.
It is officially stated that "This file is not preloaded so it will be slower" so I infer that it's possible to dynamically load a picture. If we choose this way, a light-weighted plotting library should be included.
why I say RCON :) https://github.com/mark9064/factorio-rcon-py
Oh, that could be a perfect online solution. But as long as I got an offline json file it's ok. Thank you anyway.
Although helmod can help us calculate the number of factories we should use in a block, we still need to analyze the dependency between recipes to design block layout, which is usually painful for a large block with complex recipes... A dependency graph UI could be much helpful.