using Ghost.Entities; using System.Collections.ObjectModel; namespace Ghost.Editor.Core.SceneGraph; /// /// Represents an Entity node in the editor hierarchy. /// Contains editor-only metadata like name and selection state. /// References the actual entity data in the ECS world via EntityId. /// public class EntityNode { public string Name { get; set; } public Entity EntityId { get; private set; } /// /// File-local ID within the scene (used for serialization). /// Only set when loaded from a scene file; may be -1 if not yet assigned. /// public int FileLocalId { get; set; } = -1; /// /// Child entity nodes (parent-child relationships in hierarchy). /// public ObservableCollection Children { get; } /// /// Reference to parent entity node, if any. /// public EntityNode? ParentNode { get; set; } /// /// Whether this node is expanded in the editor UI. /// public bool IsExpanded { get; set; } /// /// Whether this node is selected in the editor UI. /// public bool IsSelected { get; set; } public EntityNode(string name, Entity entityId) { Name = name; EntityId = entityId; Children = new ObservableCollection(); IsExpanded = false; IsSelected = false; } /// /// Finds a child entity node recursively by its global entity ID. /// public EntityNode? FindRecursive(Entity entityId) { foreach (var child in Children) { if (child.EntityId == entityId) return child; var found = child.FindRecursive(entityId); if (found != null) return found; } return null; } /// /// Gets the depth of this node in the hierarchy. /// Root nodes have depth 0. /// public int GetDepth() { int depth = 0; var current = ParentNode; while (current != null) { depth++; current = current.ParentNode; } return depth; } /// /// Gets all descendant nodes in breadth-first order. /// public IEnumerable GetAllDescendants() { var queue = new Queue(); queue.Enqueue(this); while (queue.Count > 0) { var node = queue.Dequeue(); foreach (var child in node.Children) { yield return child; queue.Enqueue(child); } } } public override string ToString() => $"Entity: {Name} (ID: {EntityId})"; }