satisfactory/graph.py

57 lines
1.2 KiB
Python
Raw Normal View History

2019-04-27 18:50:04 +10:00
#!/usr/bin/env python3
import satisfactory
2019-04-27 18:50:04 +10:00
import os
from typing import Iterable
def graph(cookbook: satisfactory.Cookbook, targets: Iterable[str]):
print("digraph G {")
seen = set()
remain = set(targets)
while remain:
output = remain.pop()
for need in cookbook.recipes(output)[0].input:
print(f"{need} -> {output}")
if need not in seen:
remain.add(need)
seen.add(output)
print("}")
def graph_all(recipes: dict) -> None:
graph(recipes, recipes.all())
2019-04-27 18:50:04 +10:00
def graph_one(recipes: dict, target: str) -> None:
graph(recipes, [target])
if __name__ == '__main__':
def main():
import argparse
root = os.path.dirname(__file__)
recipe_root = os.path.join(root, 'data', 'recipes')
parser = argparse.ArgumentParser()
parser.add_argument('--data', type=str, default=recipe_root)
2019-07-14 13:25:19 +10:00
parser.add_argument('--target', type=str, nargs="*")
args = parser.parse_args()
recipes = satisfactory.Cookbook(args.data)
if args.target:
2019-07-14 13:25:19 +10:00
graph(recipes, args.target)
else:
graph(recipes, recipes.components())
main()