public static List <TileCountPair> CalculateSurfaceTiles(Dictionary <int, TileViewModel> tiles, int internalLength, int internalWidth) { for (int y = 1; y <= internalLength; y++) { for (int x = 1; x <= internalWidth; x++) { int hash = TilePosition.Hash(x, y); TileViewModel tile = tiles[hash]; if (Tiles.TryGetValue(tile.CurrentType, out TileCountPair pair)) { pair.Count++; } else { Tiles.Add(tile.CurrentType, new TileCountPair(tile.CurrentType, 1)); } } } List <TileCountPair> values = new List <TileCountPair>(Tiles.Values); Tiles.Clear(); return(values); }
public void SetTile(TileType type, int x, int y) { if (SurfaceTiles.TryGetValue(TilePosition.Hash(x, y), out TileViewModel tile)) { //TileType previous = tile.CurrentType; tile.CurrentType = type; tile.OnTileChanged = this.OnTileChanged; //OnTileChangedEvent?.Invoke(previous, type); } else { tile = CreateChangableTile(); AddTile(TilePosition.Hash(x, y), tile); tile.CurrentType = type; AddTileCallback(tile, x, y); } }
public void SetUneditableTile(TileType type, int x, int y) { int hash = TilePosition.Hash(x, y); if (SurfaceTiles.TryGetValue(hash, out TileViewModel tile)) { // this case should never be reached because its slow // there should never be an existing tile at the given X and Y coords // instead you should add uneditable tiles in a clever way such that the // tile will always be uneditable unfortunately.... i think // tho tbh this will never be reached because this is only used by the // casing and thats only generated after everythings been cleared // i have no clue if this actually works... probably doesnt lol // could instead of removing the tile and adding back (in the // control) could instead change its datacontext from a // changable to unchangable tileviewmodel, but thats not mvvmey so... // "SwapViewModel" fuyction... mioght add later SurfaceTiles.Remove(hash); tile = CreateUnchangableTile(); AddTile(hash, tile); //TileType previous = tile.CurrentType; tile.CurrentType = type; RemoveTileCallback(tile, x, y); AddTileCallback(tile, x, y); //OnTileChangedEvent?.Invoke(previous, type); } else { tile = CreateUnchangableTile(); AddTile(hash, tile); //TileType previous = tile.CurrentType; tile.CurrentType = type; AddTileCallback(tile, x, y); //OnTileChangedEvent?.Invoke(previous, type); } }