Enhance Hierarchy Population to Support Nodes with Multiple Parents

This commit refines the `populateSelectedNodeHierarchy` method in the `SkillTreeViewModel` to accurately represent nodes that possess multiple parent nodes, ensuring a comprehensive and non-redundant representation of the entire hierarchy leading back to the root nodes.

Modifications and Features:
- The method now employs recursion to traverse all possible paths back to the root nodes from a selected node, capturing every unique node in the hierarchies.
- A `Set` is utilized to monitor and ensure that each node is only added once to the `_selectedNodeHierarchy` list, eliminating the possibility of duplicates.
- The finalized `_selectedNodeHierarchy` list is constructed such that the root of the tree is the last item in the list, providing a more logical representation of the hierarchy.

These enhancements ensure a more accurate and efficient representation of the skill tree structure, particularly in scenarios where nodes have multiple parents, facilitating better navigation and interaction within the skill tree.
This commit is contained in:
hunteraraujo
2023-09-22 17:26:47 -07:00
parent 078559182a
commit ecc8d9430c
2 changed files with 35 additions and 34 deletions

View File

@@ -11,9 +11,8 @@ class TaskQueueView extends StatelessWidget {
Widget build(BuildContext context) {
final viewModel = Provider.of<SkillTreeViewModel>(context);
// Reverse the node hierarchy
final reversedHierarchy =
viewModel.selectedNodeHierarchy?.reversed.toList() ?? [];
// Node hierarchy
final nodeHierarchy = viewModel.selectedNodeHierarchy ?? [];
return Material(
color: Colors.white,
@@ -21,9 +20,9 @@ class TaskQueueView extends StatelessWidget {
children: [
// The list of tasks (tiles)
ListView.builder(
itemCount: reversedHierarchy.length,
itemCount: nodeHierarchy.length,
itemBuilder: (context, index) {
final node = reversedHierarchy[index];
final node = nodeHierarchy[index];
// Choose the appropriate leading widget based on the task status
Widget leadingWidget;