Adding extra nicety attributes to nodes, and a sorting bugfix to ensure proper rendering.

This commit is contained in:
gamerdonkey 2025-08-27 00:15:14 -05:00
parent d993a70ac7
commit 1dcdd10996
2 changed files with 7 additions and 5 deletions

View File

@ -4,7 +4,7 @@ from anytree.exporter import JsonExporter
def print_ingredients(): def print_ingredients():
for i, node in ingredients.items(): for i, node in ingredients.items():
print(f" {i}.) {node.name}") print(f" {i}.) {node.result}")
ingredients = {} ingredients = {}
@ -17,7 +17,7 @@ while ingredient:
ingredient = input("Add ingredient: ") ingredient = input("Add ingredient: ")
if ingredient: if ingredient:
ingredients[i] = Node(ingredient) ingredients[i] = Node(ingredient, result=ingredient)
i += 1 i += 1
task = "start" task = "start"
@ -28,8 +28,10 @@ while task:
if task: if task:
needs = input("List needs (comma-separated): ") needs = input("List needs (comma-separated): ")
description = input("Detailed description: ")
result = input("Result of task (e.g. chopped carrots): ")
new_task = Node(task) new_task = Node(task, description=description, result=result)
ingredients[i] = new_task ingredients[i] = new_task
i += 1 i += 1

View File

@ -5,7 +5,7 @@ from sys import argv
def build_rows_depth_first(node, rows, leaf_count=0): def build_rows_depth_first(node, rows, leaf_count=0):
for child in sorted(node.children, key=lambda x: x.size, reverse=True): for child in sorted(node.children, key=lambda x: x.height, reverse=True):
leaf_count = build_rows_depth_first(child, rows, leaf_count) leaf_count = build_rows_depth_first(child, rows, leaf_count)
if node.is_leaf: if node.is_leaf:
@ -15,7 +15,7 @@ def build_rows_depth_first(node, rows, leaf_count=0):
else: else:
child_leaves = len(node.leaves) child_leaves = len(node.leaves)
cur_row = leaf_count - child_leaves cur_row = leaf_count - child_leaves
rows[cur_row].append(f'<td rowspan="{child_leaves}">{node.name}</td>') rows[cur_row].append(f'<td rowspan="{child_leaves}" title="{node.description}">{node.name}</td>')
return leaf_count return leaf_count