TreeRecursiveMoveEvent -> C# event (#4733)

* TreeRecursiveMoveEvent -> C# event

* entity query

* Make query protected
This commit is contained in:
Kara
2023-12-19 12:19:19 +11:00
committed by GitHub
parent ed9a0b4812
commit fb98eb1a0c
3 changed files with 26 additions and 23 deletions
@@ -27,6 +27,7 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
private readonly Queue<ComponentTreeEntry<TComp>> _updateQueue = new();
private readonly HashSet<EntityUid> _updated = new();
protected EntityQuery<TComp> Query;
/// <summary>
/// If true, this system will update the tree positions every frame update. See also <see cref="DoTickUpdate"/>. Some systems may need to do both.
@@ -65,7 +66,7 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
if (Recursive)
{
SubscribeLocalEvent<TComp, TreeRecursiveMoveEvent>(HandleRecursiveMove);
_recursiveMoveSys.OnTreeRecursiveMove += HandleRecursiveMove;
_recursiveMoveSys.AddSubscription();
}
else
@@ -76,11 +77,25 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
SubscribeLocalEvent<TTreeComp, EntityTerminatingEvent>(OnTerminating);
SubscribeLocalEvent<TTreeComp, ComponentAdd>(OnTreeAdd);
SubscribeLocalEvent<TTreeComp, ComponentRemove>(OnTreeRemove);
Query = GetEntityQuery<TComp>();
}
public override void Shutdown()
{
if (Recursive)
{
_recursiveMoveSys.OnTreeRecursiveMove -= HandleRecursiveMove;
}
}
#region Queue Update
private void HandleRecursiveMove(EntityUid uid, TComp component, ref TreeRecursiveMoveEvent args)
=> QueueTreeUpdate(uid, component, args.Xform);
private void HandleRecursiveMove(EntityUid uid, TransformComponent xform)
{
if (Query.TryGetComponent(uid, out var component))
QueueTreeUpdate(uid, component, xform);
}
private void HandleMove(EntityUid uid, TComp component, ref MoveEvent args)
=> QueueTreeUpdate(uid, component, args.Component);