2019-04-27 18:50:04 +10:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-04-28 11:03:27 +10:00
|
|
|
import satisfactory
|
|
|
|
|
2019-04-27 18:50:04 +10:00
|
|
|
import os
|
|
|
|
|
2019-04-28 09:08:03 +10:00
|
|
|
from typing import Iterable
|
2019-04-28 08:26:43 +10:00
|
|
|
|
2019-04-28 09:08:03 +10:00
|
|
|
|
2019-04-28 11:03:27 +10:00
|
|
|
def graph(cookbook: satisfactory.Cookbook, targets: Iterable[str]):
|
2019-04-28 08:53:11 +10:00
|
|
|
print("digraph G {")
|
|
|
|
|
|
|
|
seen = set()
|
2019-04-28 09:08:03 +10:00
|
|
|
remain = set(targets)
|
2019-04-28 08:53:11 +10:00
|
|
|
|
|
|
|
while remain:
|
|
|
|
output = remain.pop()
|
|
|
|
|
2019-07-14 13:17:28 +10:00
|
|
|
for need in cookbook.recipes(output)[0].input:
|
2019-04-28 08:53:11 +10:00
|
|
|
print(f"{need} -> {output}")
|
|
|
|
if need not in seen:
|
|
|
|
remain.add(need)
|
|
|
|
|
|
|
|
seen.add(output)
|
|
|
|
print("}")
|
|
|
|
|
|
|
|
|
2019-04-28 09:08:03 +10:00
|
|
|
def graph_all(recipes: dict) -> None:
|
|
|
|
graph(recipes, recipes.all())
|
2019-04-27 18:50:04 +10:00
|
|
|
|
|
|
|
|
2019-04-28 09:08:03 +10:00
|
|
|
def graph_one(recipes: dict, target: str) -> None:
|
|
|
|
graph(recipes, [target])
|
2019-04-28 08:26:43 +10:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-04-28 08:53:11 +10:00
|
|
|
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="*")
|
2019-04-28 08:53:11 +10:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-04-28 11:03:27 +10:00
|
|
|
recipes = satisfactory.Cookbook(args.data)
|
2019-04-28 08:53:11 +10:00
|
|
|
|
|
|
|
if args.target:
|
2019-07-14 13:25:19 +10:00
|
|
|
graph(recipes, args.target)
|
2019-04-28 08:53:11 +10:00
|
|
|
else:
|
2019-04-28 09:22:41 +10:00
|
|
|
graph(recipes, recipes.components())
|
2019-04-28 08:53:11 +10:00
|
|
|
|
|
|
|
main()
|