protected override void Execute(List <GameEntity> entities) { GridSize size = _config.Unique.Get <MapSizeComponent>().Component.Value; //foreach (var entity in entities) //{ // if (entity.HasComponent<PositionComponent>()) // { // Debug.Log($"AddElementSystem Collected: Position={entity.Get<PositionComponent>().value}"); // } //} // _game.CreateIndex<PositionComponent>((e,c) => c.Value); for (int x = 0; x < size.x; x++) { var position = new GridPosition(x, size.y - 1); //if (!_game.TryFindEntity<PositionComponent>(p => p.Value = position, out var candidate)) //{ // //Debug.Log($"AddElementSystem Index Not Found for position {position}, Adding"); // _elementService.CreateRandomElement(position); //} //var entity = _game.GetSearchIndex<PositionComponent>().FindEntity(position); //query.Add //_game.GetEntityIndex<PositionComponent>().WithValue(); if (!_game.TryFindEntity <PositionComponent, GridPosition>(position, out var candidate)) { //Debug.Log($"AddElementSystem Index Not Found for position {position} - Adding"); _elementService.CreateRandomElement(position); } //if (!_game.TryFindEntity2<PositionComponent>(p => p.value = position, out var candidate)) //if (!_game.TryFindEntity<PositionComponent, GridPosition>(position, out var candidate)) //{ // Debug.Log($"AddElementSystem Index Not Found for position {position}, Adding"); // _elementService.CreateRandomElement(position); //} //else //{ // Debug.Log($"AddElementSystem Index Found: Position={position}"); //} } }
public static int ToIndex(this GridPosition position, GridSize size) { return(position.x * size.y + position.y); }
public GridPosition Reverse(GridSize size) { return(new GridPosition(size.x - 1 - x, size.y - 1 - y)); }