diff --git a/ui/inspector_tree.py b/ui/inspector_tree.py index 00728a1..3482687 100644 --- a/ui/inspector_tree.py +++ b/ui/inspector_tree.py @@ -23,7 +23,11 @@ class TreeNode(ABC): def add_child(self, child: 'TreeNode') -> None: """Add a child node to this node.""" child.parent = self + old_depth = child.depth child.depth = self.depth + 1 + # Debug: check if depth changed incorrectly + if hasattr(child, 'entity') and isinstance(child, EntityNode) and old_depth != child.depth: + print(f"EntityNode depth changed from {old_depth} to {child.depth} when added to {self.label}") self.children.append(child) def remove_child(self, child: 'TreeNode') -> None: @@ -77,7 +81,12 @@ class TreeNode(ABC): def get_indent(self) -> int: """Get the indentation width for this node.""" - return self.depth * 20 + indent = self.depth * 20 + # Debug: print inconsistent depths (only for EntityNodes) + if hasattr(self, 'entity') and isinstance(self, EntityNode): + if self.depth != 2: # EntityNodes should always be depth 2 (Simulation -> EntityType -> Entity) + print(f"Entity {self.entity_id} has inconsistent depth: {self.depth}, indent: {indent}") + return indent class SimulationNode(TreeNode): @@ -122,7 +131,9 @@ class SimulationNode(TreeNode): else: # Create new type node type_node = EntityTypeNode(type_name, entities) + print(f"SimulationNode: adding {type_name} with current depth {type_node.depth}, my depth is {self.depth}") self.add_child(type_node) + print(f"SimulationNode: after adding, {type_name} has depth {type_node.depth}") class EntityTypeNode(TreeNode): @@ -131,7 +142,9 @@ class EntityTypeNode(TreeNode): def __init__(self, entity_type: str, entities: List[Any]): super().__init__(entity_type) self.entities = entities - self._update_children() + # Debug: check depth + print(f"EntityTypeNode {entity_type} created with depth {self.depth}") + # Don't call _update_children() here - parent will call after adding this node def _update_children(self) -> None: """Update child entity nodes to match current entities.""" @@ -149,6 +162,9 @@ class EntityTypeNode(TreeNode): # Update existing node entity_node = existing_ids[entity_id] entity_node.entity = entity + # Debug: verify depth is correct for updated nodes + if entity_node.depth != self.depth + 1: + print(f"Updated EntityNode {entity_id} has wrong depth: {entity_node.depth}, should be {self.depth + 1}") else: # Create new entity node entity_node = EntityNode(entity) diff --git a/ui/tree_widget.py b/ui/tree_widget.py index c153c0b..1334674 100644 --- a/ui/tree_widget.py +++ b/ui/tree_widget.py @@ -133,6 +133,7 @@ class TreeWidget(UIElement): elif node == self.hovered_node: pygame.draw.rect(surface, self.hover_color, node.rect) + # Expand/collapse icon if node.can_expand(): icon_rect = self._get_expand_collapse_rect(node)