fix cast bug in Entity.GetComponents
parent
74ec2f6320
commit
987b30ceae
|
@ -107,9 +107,9 @@ namespace Encompass
|
|||
|
||||
internal IEnumerable<KeyValuePair<Guid, TComponent>> GetComponentsByEntityAndType<TComponent>(Guid entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
var entity_components = GetComponentsByEntity(entityID).Select((kv) => new KeyValuePair<Guid, TComponent>(kv.Key, (TComponent)kv.Value));
|
||||
var active_components_by_type = GetActiveComponentsByType<TComponent>();
|
||||
return entity_components.Intersect(active_components_by_type);
|
||||
var entityComponentsByType = GetComponentsByEntity(entityID).Where((pair) => componentIDToType[pair.Key] == typeof(TComponent)).Select((pair) => new KeyValuePair<Guid, TComponent>(pair.Key, (TComponent)pair.Value));
|
||||
var activeComponentsByType = GetActiveComponentsByType<TComponent>();
|
||||
return activeComponentsByType.Intersect(entityComponentsByType);
|
||||
}
|
||||
|
||||
internal IEnumerable<KeyValuePair<Guid, IComponent>> GetComponentsByEntityAndType(Guid entityID, Type type)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
|
||||
using NUnit.Framework;
|
||||
using FluentAssertions;
|
||||
using Encompass;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
|
@ -93,11 +95,13 @@ namespace Tests
|
|||
}
|
||||
|
||||
static bool calledOnDraw = false;
|
||||
static IEnumerable<KeyValuePair<Guid, TestDrawComponent>> resultComponents;
|
||||
[Renders(typeof(TestDrawComponent), typeof(AComponent), typeof(CComponent))]
|
||||
class CalledRenderer : EntityRenderer
|
||||
{
|
||||
public override void Render(Entity entity)
|
||||
{
|
||||
resultComponents = entity.GetComponents<TestDrawComponent>();
|
||||
calledOnDraw = true;
|
||||
}
|
||||
}
|
||||
|
@ -110,12 +114,12 @@ namespace Tests
|
|||
|
||||
AComponent aComponent;
|
||||
CComponent cComponent;
|
||||
TestDrawComponent testDrawComponent = default(TestDrawComponent);
|
||||
TestDrawComponent testDrawComponent;
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
entity.AddComponent(aComponent);
|
||||
entity.AddComponent(cComponent);
|
||||
entity.AddDrawComponent(testDrawComponent, 2);
|
||||
var testDrawComponentID = entity.AddDrawComponent(testDrawComponent, 2);
|
||||
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
|
@ -124,6 +128,7 @@ namespace Tests
|
|||
|
||||
Assert.IsTrue(renderer.IsTracking(entity.id));
|
||||
Assert.IsTrue(calledOnDraw);
|
||||
resultComponents.Should().Contain(new KeyValuePair<Guid, TestDrawComponent>(testDrawComponentID, testDrawComponent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue