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_Should_Be_In_Entities_After_Added() { var entity = new DefaultEntity(); _gameManager.AddEntity(entity); Assert.True(_gameManager.EntityManager.Entities.ContainsKey(entity.ID)); }
public void AddItem(DefaultEntity def) { Items.Add(def); lib.Class.ObjectAttribute obj = new lib.Class.ObjectAttribute(def); string[] item = new string [Columns.Count]; for (int i = 0; i < Columns.Count; i++) { if (Columns[i].Type == enmFieldType.Date) { item[i] = ((DateTime)obj.GetAttribute(Columns[i].Name)).ToString("dd/MM/yyyy"); } else if (Columns[i].Type == enmFieldType.DateTime) { item[i] = ((DateTime)obj.GetAttribute(Columns[i].Name)).ToString("dd/MM/yyyy HH:mm:ss"); } else if (Columns[i].Type == enmFieldType.Decimal) { item[i] = ((DateTime)obj.GetAttribute(Columns[i].Name)).ToString("#,##0.00"); } else { item[i] = obj.GetAttribute(Columns[i].Name).ToString(); } } AddItem(item); }
public void IsInChannel_Should_Validate_Entity_Channel() { var channelName = "channelName"; var e = new DefaultEntity("test", channelName); Assert.True(e.IsInChannel(channelName)); }
public ActionResult Create(DefaultCreate model) { if (!ModelState.IsValid) { return(View(ModelState)); } var defaultEntity = new DefaultEntity { Name = model.Name, Items = model.Items?.Select(i => new ItemEntity { Name = i.Name, Number = i.Number }).ToList() }; var context = new ApplicationDbContext(); context.Defaults.Add(defaultEntity); var itemCount = model.Items is null ? 0 : model.Items.Count; var expectedChangeCount = 1 + itemCount; if (context.SaveChanges() != expectedChangeCount) { return(View(model)); } return(RedirectToAction(nameof(Index))); }
/** * Collide as camadas envia para os objetos dessa camada as entidades que esta colidiu */ public void collideEntity(DefaultEntity target, Layer layerCollide) { DefaultEntity collider; DefaultEntity mycollider; LinkedList <DefaultEntity> inCollideList = new LinkedList <DefaultEntity>(); mycollider = target; for (int j = 0; j < entityList.Count; j++) { if (mycollider != layerCollide.entityList.ElementAt(j) && mycollider.collidable) { collider = layerCollide.entityList.ElementAt(j); if (collider.collidable && collider != mycollider) { if (Vector2.Distance(new Vector2(mycollider.position.X + mycollider.centerPosition.X, mycollider.position.Y + mycollider.centerPosition.Y), new Vector2(collider.position.X + collider.centerPosition.X, collider.position.Y + collider.centerPosition.Y)) < mycollider.range + collider.range) { inCollideList.AddFirst(collider); } } } mycollider.collide(inCollideList); } }
public void Is_Deleted_Should_Be_False_After_Delete() { var e = new DefaultEntity("Test", "test"); e.Delete(); Assert.Equal(true, e.IsDeleted); }
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()); }
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 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 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 Can_Find_Multiple_Components_By_String() { var e = new DefaultEntity("name", "channel"); e.AddComponent(new StringComponent()); e.AddComponent(new XYComponent()); Assert.True(e.HasComponents(new[] { typeof(StringComponent), typeof(XYComponent) })); }
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 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))); }
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 Should_Remove_A_Component_By_String() { var e = new DefaultEntity("name", "channel"); e.AddComponent(new StringComponent()); Assert.True(e.HasComponent <StringComponent>()); Assert.True(e.RemoveComponent(typeof(StringComponent))); Assert.False(e.HasComponent <StringComponent>()); }
public void Should_Raise_Deleted_Event_When_Deletedd() { var e = new DefaultEntity("name", "channel"); var called = false; e.Deleted += (s, ea) => { called = true; }; e.Delete(); Assert.True(called); }
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 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 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()); }
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 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 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 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 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); }
/// <summary> /// Constructs a new ball. /// </summary> /// <param name="initialPosition">The initial position of the ball.</param> /// <param name="initialOrientation">The initial orientation of the ball.</param> /// <param name="mass">The mass of the ball.</param> /// <param name="ballRadius">The radius of the ball.</param> /// <param name="ballHull">The ball's hull.</param> /// <param name="collisionHandler">The ball's collision handler.</param> /// <param name="physics">The physics engine environment to which the ball belongs.</param> /// <param name="airResistance">The air resistance of the ball.</param> /// <param name="number">The ball's number.</param> /// <param name="ballModel">The ball's model.</param> public Ball(Vector3 initialPosition, Vector3 initialOrientation, float mass, float ballRadius, Hull ballHull, CollisionHandler collisionHandler, PhysicsEngine.Environment physics, float airResistance, int number, Model ballModel) { physicsReference = new BallEntity(initialPosition, initialOrientation, mass, ballRadius, ballHull, collisionHandler, physics, airResistance); physics.Add(physicsReference); this.number = number; this.ballModel = ballModel; }
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 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 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); }