Updating make tree so you can add ingredients later in the process.

This commit is contained in:
gamerdonkey 2025-09-10 03:55:53 +00:00
parent ba6d5f4255
commit dd9f0f80d3

View File

@ -8,38 +8,30 @@ def print_ingredients():
ingredients = {} ingredients = {}
ingredient = "start"
i = 0 i = 0
while ingredient: node = "start"
while node:
print_ingredients() print_ingredients()
ingredient = input("Add ingredient: ") node = input("Add node: ")
if ingredient: if node:
ingredients[i] = Node(ingredient, result=ingredient)
i += 1
task = "start"
while task:
print_ingredients()
task = input("Add task: ")
if task:
needs = input("List needs (comma-separated): ") needs = input("List needs (comma-separated): ")
description = input("Detailed description: ") description = input("Detailed description: ")
result = input("Result of task (e.g. chopped carrots): ")
new_task = Node(task, description=description, result=result) if needs:
result = input("Result of node (e.g. chopped carrots): ")
ingredients[i] = new_task new_node = Node(node, description=description, result=result)
i += 1
for e in [int(key.strip()) for key in needs.split(",")]: for e in [int(key.strip()) for key in needs.split(",")]:
ingredients.pop(e).parent = new_task ingredients.pop(e).parent = new_node
else:
new_node = Node(node, description=description, result=node)
for pre, _, node in RenderTree(new_task): ingredients[i] = new_node
i += 1
for pre, _, node in RenderTree(new_node):
print(f"{pre}{node.name}") print(f"{pre}{node.name}")
name = input("Recipe name: ") name = input("Recipe name: ")
@ -48,5 +40,5 @@ if name:
name = name.replace(" ", "_") name = name.replace(" ", "_")
with open(f"{name}.json", 'w') as f: with open(f"{name}.json", 'w') as f:
JsonExporter(indent=2).write(new_task, f) JsonExporter(indent=2).write(new_node, f)