fix false positive on filter remove callback

pull/4/head
cosmonaut 2023-01-27 09:48:27 -08:00
parent 1438188dca
commit 4ff546538b
1 changed files with 15 additions and 9 deletions

View File

@ -118,11 +118,13 @@ namespace MoonTools.ECS
{ {
if (!EntityStorage.HasComponent(entityID, type)) if (!EntityStorage.HasComponent(entityID, type))
{ {
filterSignatureToEntityIDs[filterSignature].Remove(entityID); if (filterSignatureToEntityIDs[filterSignature].Remove(entityID))
{
if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback)) if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback))
{ {
removeCallback(entityID); removeCallback(entityID);
} }
}
return; return;
} }
} }
@ -131,11 +133,13 @@ namespace MoonTools.ECS
{ {
if (EntityStorage.HasComponent(entityID, type)) if (EntityStorage.HasComponent(entityID, type))
{ {
filterSignatureToEntityIDs[filterSignature].Remove(entityID); if (filterSignatureToEntityIDs[filterSignature].Remove(entityID))
{
if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback)) if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback))
{ {
removeCallback(entityID); removeCallback(entityID);
} }
}
return; return;
} }
} }
@ -153,7 +157,8 @@ namespace MoonTools.ECS
{ {
foreach (var filterSignature in filterSignatures) foreach (var filterSignature in filterSignatures)
{ {
filterSignatureToEntityIDs[filterSignature].Remove(entityID); if (filterSignatureToEntityIDs[filterSignature].Remove(entityID))
{
if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback)) if (removeCallbacks.TryGetValue(filterSignature, out var removeCallback))
{ {
removeCallback(entityID); removeCallback(entityID);
@ -161,6 +166,7 @@ namespace MoonTools.ECS
} }
} }
} }
}
public void RegisterAddCallback(FilterSignature filterSignature, Action<Entity> callback) public void RegisterAddCallback(FilterSignature filterSignature, Action<Entity> callback)
{ {