max
91b4f5fafb
- started working on an editor hierarchy window - testing filters - testing parent child relations without system - testing root component - thinking about how to get all entities that are not a child, but also don't have an other identifying component
67 lines
3.0 KiB
C#
67 lines
3.0 KiB
C#
using MoonTools.ECS;
|
|
using Nerfed.Runtime.Components;
|
|
|
|
namespace Nerfed.Runtime.Systems
|
|
{
|
|
//public class ParentSystem : MoonTools.ECS.System
|
|
//{
|
|
// private readonly Filter parentsAddedFilter;
|
|
// private readonly Filter parentsRemovedFilter;
|
|
// private readonly Filter parentsFilter;
|
|
|
|
// public ParentSystem(World world) : base(world)
|
|
// {
|
|
// parentsAddedFilter = FilterBuilder.Include<Parent>().Exclude<PreviousParent>().Build();
|
|
// parentsRemovedFilter = FilterBuilder.Include<PreviousParent>().Exclude<Parent>().Build();
|
|
// parentsFilter = FilterBuilder.Include<Parent>().Include<PreviousParent>().Build();
|
|
// }
|
|
|
|
// public override void Update(TimeSpan delta)
|
|
// {
|
|
// // Update removed parents.
|
|
// foreach (Entity entity in parentsRemovedFilter.Entities)
|
|
// {
|
|
// // Do stuff here to update/remove child relations etc.
|
|
// //PreviousParent previousParent = Get<PreviousParent>(entity);
|
|
// //World.Unrelate<ChildParentRelation>(previousParent.parentEntity, entity);
|
|
// Remove<PreviousParent>(entity);
|
|
// }
|
|
|
|
// // Update added parents.
|
|
// foreach (Entity entity in parentsAddedFilter.Entities)
|
|
// {
|
|
// Parent parent = Get<Parent>(entity);
|
|
|
|
// if (Has<Parent>(parent.parentEntity) && Get<Parent>(parent.parentEntity).parentEntity == entity)
|
|
// {
|
|
// Log.Warning($"Entity {entity} cannot be a parent of entity {parent.parentEntity}, because {parent.parentEntity} is the parent of {entity}");
|
|
// Remove<Parent>(entity);
|
|
// continue;
|
|
// }
|
|
|
|
// PreviousParent previousParent = new(parent.parentEntity);
|
|
// Set(entity, previousParent);
|
|
// World.Relate(parent.parentEntity, entity, new ChildParentRelation());
|
|
// }
|
|
|
|
// // Update relations if the parent has changed.
|
|
// foreach (Entity entity in parentsFilter.Entities)
|
|
// {
|
|
// Parent parent = Get<Parent>(entity);
|
|
// PreviousParent previousParent = Get<PreviousParent>(entity);
|
|
|
|
// if(parent.parentEntity != previousParent.parentEntity)
|
|
// {
|
|
// World.Unrelate<ChildParentRelation>(previousParent.parentEntity, entity);
|
|
// Set(entity, new PreviousParent(parent.parentEntity));
|
|
// World.Relate(parent.parentEntity, entity, new ChildParentRelation());
|
|
// }
|
|
// }
|
|
|
|
// // TODO:
|
|
// // What if an parent entity gets destroyed?
|
|
// // How does the child know if the parent is in valid. Also we need to remove the parent component.
|
|
// // Maybe if we also relate the other way around child -> parent via relations, and the relation is gone that means the parent is gone so we should remove the component.
|
|
// }
|
|
//}
|
|
} |