private static IEnumerable <IEntity> GetFilteredEntities(IEntityPool pool, EntityFilterInfo filter) { var entities = pool.GetAll(); if (filter.Type != null) { entities = entities.Where(e => e.Name == filter.Type); } if (filter.Direction != null) { entities = entities.Where(e => e.Direction == filter.Direction); } if (filter.Position != null) { if (filter.Position.X != null) { if (filter.Position.X.Min.HasValue) { entities = entities.Where(e => { var pos = e.GetComponent <PositionComponent>(); return(pos == null || pos.X >= filter.Position.X.Min.Value); }); } if (filter.Position.X.Max.HasValue) { entities = entities.Where(e => { var pos = e.GetComponent <PositionComponent>(); return(pos == null || pos.X <= filter.Position.X.Max.Value); }); } } if (filter.Position.Y != null) { if (filter.Position.Y.Min.HasValue) { entities = entities.Where(e => { var pos = e.GetComponent <PositionComponent>(); return(pos == null || pos.Y >= filter.Position.Y.Min.Value); }); } if (filter.Position.Y.Max.HasValue) { entities = entities.Where(e => { var pos = e.GetComponent <PositionComponent>(); return(pos == null || pos.Y <= filter.Position.Y.Max.Value); }); } } } return(entities); }
private static string ParseFilteredInfo(EqpDispatchInfo info, ref int filteredWipCnt) { if (info.FilterInfos.Count == 0) { return(string.Empty); } StringBuilder result = new StringBuilder(); foreach (KeyValuePair <string, EntityFilterInfo> filtered in info.FilterInfos) { EntityFilterInfo filterInfo = filtered.Value; filteredWipCnt += filterInfo.FilterWips.Count; StringBuilder fsb = new StringBuilder(); fsb.Append(filterInfo.Reason); fsb.Append(':'); bool first = true; foreach (FabLot fw in filterInfo.FilterWips) { StringBuilder sb = new StringBuilder(); if (!first) { sb.Append(";"); } else { first = false; } SetDefaultLotInfo(sb, fw); fsb.Append(sb); } fsb.Append("\t"); result.Append(fsb); } return(result.ToString()); }
private static Filter GetEntityFilter(EntityFilterInfo filter) { Func<IEntity, bool> f = e => true; if (filter.Type != null) { f = ComposeFilter(f, e => e.Name == filter.Type); } if (filter.State != null) { Func<IEntity, bool> stateFilter = e => { var stateComp = e.GetComponent<StateComponent>(); return stateComp == null || stateComp.CurrentState == filter.State; }; f = ComposeFilter(f, stateFilter); } if (filter.Direction != null) { f = ComposeFilter(f, e => e.Direction == filter.Direction); } if (filter.Position != null) { if (filter.Position.X != null) { Func<IEntity, float?> xFunc = e => { var pos = e.GetComponent<PositionComponent>(); return pos != null ? (float?)pos.X : null; }; Func<IEntity, bool> posXFilter = GetRangeFilter(filter.Position.X, xFunc); f = ComposeFilter(f, posXFilter); } if (filter.Position.Y != null) { Func<IEntity, float?> yFunc = e => { var pos = e.GetComponent<PositionComponent>(); return pos != null ? (float?)pos.Y : null; }; Func<IEntity, bool> posYFilter = GetRangeFilter(filter.Position.Y, yFunc); f = ComposeFilter(f, posYFilter); } } if (filter.Movement != null) { if (filter.Movement.X != null) { Func<IEntity, float?> vxFunc = e => { var move = e.GetComponent<MovementComponent>(); return move != null ? (float?)move.VelocityX : null; }; var vxFilter = GetRangeFilter(filter.Movement.X, vxFunc); f = ComposeFilter(f, vxFilter); } if (filter.Movement.Y != null) { Func<IEntity, float?> vyFunc = e => { var move = e.GetComponent<MovementComponent>(); return move != null ? (float?)move.VelocityY : null; }; var vyFilter = GetRangeFilter(filter.Movement.Y, vyFunc); f = ComposeFilter(f, vyFilter); } } if (filter.Collision != null) { Func<IEntity, bool> collFilter = e => { var coll = e.GetComponent<CollisionComponent>(); var r = true; if (filter.Collision.BlockTop.HasValue) r = r && (coll.BlockTop == filter.Collision.BlockTop.Value); if (filter.Collision.BlockBottom.HasValue) r = r && (coll.BlockTop == filter.Collision.BlockBottom.Value); if (filter.Collision.BlockLeft.HasValue) r = r && (coll.BlockTop == filter.Collision.BlockLeft.Value); if (filter.Collision.BlockRight.HasValue) r = r && (coll.BlockTop == filter.Collision.BlockRight.Value); return r; }; f = ComposeFilter(f, collFilter); } if (filter.Health != null) { Func<IEntity, float?> healthFunc = e => { var health = e.GetComponent<HealthComponent>(); return health != null ? (float?)health.Health : null; }; f = ComposeFilter(f, GetRangeFilter(filter.Health, healthFunc)); } return e => e.Where(f); }