public void Entity_With_Component_Changes_Should_Not_Be_Added_Unless_It_Is_A_Match()
 {
     var e1 = new DefaultEntity("e1", "test").AddComponent(new XYComponent());
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentAddedToEntity(e1, typeof (XYComponent));
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void IsInChannel_Should_Be_False_For_Incorrect_Channel()
 {
     var channelName = "channelName";
     var notChannelName = "notChannelname";
     var e = new DefaultEntity("test", channelName);
     Assert.False(e.IsInChannel(notChannelName));
 }
 public void Get_Should_Add_To_ChannelAspects_If_Entity_Is_In_Current_Channel()
 {
     Assert.Equal(0, _aspectManager.Aspects.Count());
     var e = new DefaultEntity("Test", "default").CreateLabelAspect("Test", 0, 0);
     _aspectManager.Get(e);
     Assert.Equal(1, _aspectManager.ChannelAspects.Count());
 }
 public void Get_Should_Add_To_Aspects()
 {
     Assert.Equal(0, _aspectManager.Aspects.Count());
     var e = new DefaultEntity("Test", "irrelevant").CreateLabelAspect("Test", 0, 0);
     _aspectManager.Get(e);
     Assert.Equal(1, _aspectManager.Aspects.Count());
 }
 public void AddComponent_Should_Increase_Component_Count()
 {
     var e = new DefaultEntity("Test", "teset");
     Assert.Equal(0, e.Components.Count);
     e.AddComponent(new StringComponent {Value = "test"});
     Assert.Equal(1, e.Components.Count);
 }
 public void Entity_Should_Not_Be_In_Entities_After_Removed()
 {
     var entity = new DefaultEntity();
     _gameManager.AddEntity(entity);
     Assert.True(_gameManager.EntityManager.Entities.ContainsKey(entity.ID));
     _gameManager.RemoveEntity(entity);
     Assert.False(_gameManager.EntityManager.Entities.ContainsKey(entity.ID));
 }
 public void AddEntity_Should_Notify_EntityAdded()
 {
     var notified = false;
     var entity = new DefaultEntity();
     _gameManager.EntityAdded += (s, e) => notified = true;
     _gameManager.AddEntity(entity);
     Assert.True(notified);
 }
 public void AddEntity_Should_Increase_Entity_Count()
 {
     var expected = 1;
     var entity = new DefaultEntity();
     Assert.Equal(0, _gameManager.EntityManager.Entities.Count);
     _gameManager.AddEntity(entity);
     Assert.Equal(expected, _gameManager.EntityManager.Entities.Count);
 }
 public void Init_Should_Apply_Entity_Channels_To_Aspect()
 {
     var expected = new[] {"one", "two", "three"};
     var e = new DefaultEntity("Test", expected).CreateLabelAspect("Label", 0, 0);
     var aspect = new LabelAspect();
     aspect.Init(e);
     Assert.True(aspect.Channels.All(s => expected.Contains(s)));
 }
示例#10
0
 public void AddComponent_Should_Raise_OnComponentAdded()
 {
     var called = false;
     var e = new DefaultEntity("name", "test");
     e.ComponentAdded += (s, arg) => { called = true; };
     e.AddComponent(new StringComponent {Value = "test"});
     Assert.True(called);
 }
 public void NewEntity_Should_Not_Allow_An_Entity_To_Be_Added_More_Than_Once()
 {
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void GetAspectList_Should_Register_Existing_Entities()
 {
     var entity = new DefaultEntity("TestEntity", "all");
     entity.CreateLabelAspect("Test", 0, 0);
     _entityManager.Entities.Add(entity.ID, entity);
     _entityAspectManager.RegisterEntity(entity);
     var aspectList = _entityAspectManager.GetAspectList<LabelAspect>();
     Assert.Equal(1, aspectList.Count());
 }
 public IEntity Clone()
 {
     var e = new DefaultEntity(Name, Channels.ToArray());
     foreach (var c in Components.Values)
     {
         e.Components.Add(c.GetType(), c.Clone());
     }
     return e;
 }
 public void RemoveEntity_Should_Decrease_Entity_Count()
 {
     var entity = new DefaultEntity();
     Assert.Equal(0, _gameManager.EntityManager.Entities.Count);
     _gameManager.AddEntity(entity);
     Assert.Equal(1, _gameManager.EntityManager.Entities.Count);
     _gameManager.RemoveEntity(entity);
     Assert.Equal(0, _gameManager.EntityManager.Entities.Count);
 }
 public void Aspect_Should_Be_Removed_From_Channel_List_When_In_Channel_And_Deleted()
 {
     var e = new DefaultEntity("Test", "default").CreateLabelAspect("Test", 0, 0);
     var aspect = _aspectManager.Get(e);
     Assert.Equal(1, _aspectManager.ChannelAspects.Count());
     Assert.Equal(aspect, _aspectManager.ChannelAspects.First());
     aspect.Delete();
     Assert.Equal(0, _aspectManager.ChannelAspects.Count());
 }
 public void NewEntity_Should_Not_Allow_An_Entity_That_Fails_To_Match_AspectComponents()
 {
     var e1 = new DefaultEntity("e1", "test");
     var e2 = new DefaultEntity("e2", "Test").CreateLabelAspect("Test", 0, 0);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.NewEntity(e2);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
 }
示例#17
0
 public void Init_Should_Create_Pointers_To_Entity_Components_From_Aspect()
 {
     var e = new DefaultEntity("Test", "default").CreateLabelAspect("Label", 0, 0);
     var aspect = new LabelAspect();
     aspect.Init(e);
     foreach (var component in e.Components.Values)
     {
         Assert.Equal(component, aspect.Components[component.GetType()]);
     }
 }
        public void Get_Should_Return_A_New_Aspect_Of_Appropriate_Type()
        {
            var expected = typeof (LabelAspect);
            var e = new DefaultEntity("Test", "all");
            e.CreateLabelAspect("Test", 0, 0);

            var actual = _aspectManager.Get(e);
            Assert.Equal(expected, actual.GetType());
            Assert.Equal(actual, _aspectManager.Aspects.First());
        }
        public IEntity Clone()
        {
            var e = new DefaultEntity(Name, Channels.ToArray());

            foreach (var c in Components.Values)
            {
                e.Components.Add(c.GetType(), c.Clone());
            }
            return(e);
        }
 public void RemoveEntity_Should_Delete_Associated_Aspect()
 {
     var deleted = false;
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("label", 0, 0);
     _aspectMatchingFamily.NewEntity(e1);
     _aspectMatchingFamily.EntireAspectList.First().Deleted += (s, ea) => deleted = true;
     _aspectMatchingFamily.RemoveEntity(e1);
     Assert.True(deleted);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
 }
示例#21
0
 public void Reset_Should_Clear_Components_and_Channels()
 {
     var e = new DefaultEntity("Test", "default").CreateLabelAspect("Label", 0, 0);
     var aspect = new LabelAspect();
     aspect.Init(e);
     Assert.True(aspect.Components.Count > 0);
     Assert.True(aspect.Channels.Count > 0);
     aspect.Reset();
     Assert.Equal(0, aspect.Components.Count);
     Assert.Equal(0, aspect.Channels.Count);
 }
 public void ReleaseAspectList_Should_Remove_All_Aspects_And_Remove_AspectFamily()
 {
     var entity = new DefaultEntity("TestEntity", "all");
     entity.CreateLabelAspect("Test", 0, 0);
     _entityManager.Entities.Add(entity.ID, entity);
     _entityAspectManager.RegisterEntity(entity);
     var aspectList = _entityAspectManager.GetAspectList<LabelAspect>();
     Assert.Equal(1, aspectList.Count());
     _entityAspectManager.ReleaseAspectList<LabelAspect>();
     Assert.Equal(0, aspectList.Count());
     var aspectList2 = _entityAspectManager.GetAspectList<LabelAspect>();
     Assert.NotEqual(aspectList, aspectList2);
 }
示例#23
0
        public void AddComponent_Should_Overwrite_Component_If_Parameter_Set()
        {
            var labelOne = "label one";
            var labelTwo = "label two";
            var e = new DefaultEntity("test", "test");
            e.AddComponent(new StringComponent {Value = labelOne});

            Assert.Equal(labelOne, ((StringComponent) e.Components[typeof (StringComponent)]).Value);

            e.AddComponent(new StringComponent {Value = labelTwo}, true);

            Assert.Equal(labelTwo, ((StringComponent) e.Components[typeof (StringComponent)]).Value);
        }
 public void CleanUp_Should_Delete_All_Aspects()
 {
     var deleteCount = 0;
     var expectedDeleteCount = 3;
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0);
     var e2 = new DefaultEntity("e2", "Test").CreateLabelAspect("test", 0, 0);
     var e3 = new DefaultEntity("e3", "test").CreateLabelAspect("test", 0, 0);
     _aspectMatchingFamily.NewEntity(e1);
     _aspectMatchingFamily.NewEntity(e2);
     _aspectMatchingFamily.NewEntity(e3);
     Assert.Equal(3, _aspectMatchingFamily.EntireAspectList.Count());
     foreach (var aspect in _aspectMatchingFamily.EntireAspectList)
     {
         aspect.Deleted += (s, ea) => deleteCount++;
     }
     _aspectMatchingFamily.CleanUp();
     Assert.Equal(expectedDeleteCount, deleteCount);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void Entity_With_Component_Changes_Should_Be_Added_If_Component_Is_Right_Type_And_Is_Match()
 {
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentAddedToEntity(e1, typeof (XYComponent));
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
 }
示例#26
0
 public void IsInChannel_Should_Validate_Entity_Channel()
 {
     var channelName = "channelName";
     var e = new DefaultEntity("test", channelName);
     Assert.True(e.IsInChannel(channelName));
 }
示例#27
0
 public void Can_Find_Component_By_String()
 {
     var e = new DefaultEntity("name", "channel");
     e.AddComponent(new StringComponent());
     Assert.True(e.HasComponent(typeof (StringComponent)));
 }
 public void Entity_With_Component_Changes_Should_Not_Be_Removed_If_Family_Does_Not_Contain_Entity()
 {
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0);
     var e2 = new DefaultEntity("e2", "test").CreateLabelAspect("test", 0, 0);
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentRemovedFromEntity(e2, typeof (XYComponent));
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void Entity_With_Non_Matching_Component_Type_Should_Not_Trigger_Remove()
 {
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0);
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentRemovedFromEntity(e1, typeof (SomeOtherComponent));
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void Entity_That_Is_A_Match_And_Has_Matching_Component_Type_Removed_Should_Be_Removed()
 {
     var e1 = new DefaultEntity("e1", "test").CreateLabelAspect("label", 0, 0);
     _aspectMatchingFamily.NewEntity(e1);
     Assert.Equal(1, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentRemovedFromEntity(e1, typeof (XYComponent));
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
 }
 public void Entity_With_Component_Changes_Should_Not_Be_Added_If_Component_Is_Wrong_Type()
 {
     var e1 =
         new DefaultEntity("e1", "test").CreateLabelAspect("test", 0, 0).AddComponent(new SomeOtherComponent());
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
     _aspectMatchingFamily.ComponentAddedToEntity(e1, typeof (SomeOtherComponent));
     Assert.Equal(0, _aspectMatchingFamily.EntireAspectList.Count());
 }