using ImGuiNET; using MoonTools.ECS; using Nerfed.Runtime.Components; namespace Nerfed.Editor.Systems { internal class EditorHierarchyWindow : MoonTools.ECS.DebugSystem { private readonly Filter rootEntitiesWithTransformFilter; private readonly Filter rootEntitiesFilterBroken; private readonly Filter rootEntitiesFilter; public EditorHierarchyWindow(World world) : base(world) { rootEntitiesWithTransformFilter = FilterBuilder.Include().Exclude().Build(); // TODO: this doesn't work. rootEntitiesFilterBroken = FilterBuilder.Exclude().Build(); // Maybe the parent/child functions should add a root component when not being a child. rootEntitiesFilter = FilterBuilder.Include().Build(); // Maybe instead of a root, if we need a component that is always on an entity and has some use we could create something like a VersionComponent which only hold an int. // The version would update each time something changes on the entity. // } public override void Update(TimeSpan delta) { ImGui.Begin("Hierarchy"); foreach (Entity entity in rootEntitiesWithTransformFilter.Entities) { DrawEntityAndChildren(entity); } ImGui.NewLine(); foreach (Entity entity in rootEntitiesFilter.Entities) { DrawEntityAndChildren(entity); } ImGui.End(); } private void DrawEntityAndChildren(in Entity entity, int depth = 0) { string label = new string(' ', depth); ImGui.Text($"{label}{entity.ID} | {GetTag(entity)}"); depth++; ReverseSpanEnumerator childEntities = World.InRelations(entity); foreach (Entity childEntity in childEntities) { DrawEntityAndChildren(childEntity, depth); } } } }