fix issue where ReadComponents would read inactive components

pull/5/head
Evan Hemsley 2019-07-10 09:53:38 -07:00
parent 0b07e146ac
commit caac238ff9
3 changed files with 7 additions and 3 deletions

View File

@ -89,14 +89,14 @@ namespace Encompass
internal IEnumerable<ValueTuple<Guid, TComponent>> GetActiveComponentsByType<TComponent>() where TComponent : struct, IComponent internal IEnumerable<ValueTuple<Guid, TComponent>> GetActiveComponentsByType<TComponent>() where TComponent : struct, IComponent
{ {
return typeToComponentIDs.ContainsKey(typeof(TComponent)) ? return typeToComponentIDs.ContainsKey(typeof(TComponent)) ?
typeToComponentIDs[typeof(TComponent)].Select((id) => new ValueTuple<Guid, TComponent>(id, (TComponent)IDToComponent[id])) : typeToComponentIDs[typeof(TComponent)].Intersect(activeComponents).Select((id) => new ValueTuple<Guid, TComponent>(id, (TComponent)IDToComponent[id])) :
Enumerable.Empty<ValueTuple<Guid, TComponent>>(); Enumerable.Empty<ValueTuple<Guid, TComponent>>();
} }
internal IEnumerable<ValueTuple<Guid, IComponent>> GetActiveComponentsByType(Type type) internal IEnumerable<ValueTuple<Guid, IComponent>> GetActiveComponentsByType(Type type)
{ {
return typeToComponentIDs.ContainsKey(type) ? return typeToComponentIDs.ContainsKey(type) ?
typeToComponentIDs[type].Select((id) => new ValueTuple<Guid, IComponent>(id, IDToComponent[id])) : typeToComponentIDs[type].Intersect(activeComponents).Select((id) => new ValueTuple<Guid, IComponent>(id, IDToComponent[id])) :
Enumerable.Empty<ValueTuple<Guid, IComponent>>(); Enumerable.Empty<ValueTuple<Guid, IComponent>>();
} }

View File

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Encompass</RootNamespace> <RootNamespace>Encompass</RootNamespace>
<PackageId>EncompassECS.Framework</PackageId> <PackageId>EncompassECS.Framework</PackageId>
<Version>0.6.1</Version> <Version>0.6.2</Version>
<Authors>Evan Hemsley</Authors> <Authors>Evan Hemsley</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Company>Moonside Games</Company> <Company>Moonside Games</Company>

View File

@ -51,6 +51,9 @@ namespace Tests
var componentAID = entity.AddComponent(mockComponent); var componentAID = entity.AddComponent(mockComponent);
var componentBID = entity.AddComponent(mockComponentB); var componentBID = entity.AddComponent(mockComponentB);
var inactiveComponentAID = entity.AddComponent(mockComponent);
entity.DeactivateComponent(inactiveComponentAID);
var world = worldBuilder.Build(); var world = worldBuilder.Build();
@ -59,6 +62,7 @@ namespace Tests
var resultComponentValues = resultComponents.Select((kv) => kv.Item2); var resultComponentValues = resultComponents.Select((kv) => kv.Item2);
resultComponentValues.Should().Contain(mockComponent); resultComponentValues.Should().Contain(mockComponent);
resultComponentValues.Should().Contain(mockComponentB); resultComponentValues.Should().Contain(mockComponentB);
resultComponents.Should().NotContain((inactiveComponentAID, mockComponent));
} }
[Test] [Test]