private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using (var bitmap = new Image <Rgba32>(0x100, 0x100)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = Rgba32.Black; if (terrain.SafezoneMap[y, x]) { color = Rgba32.Gray; } else if (terrain.WalkMap[y, x]) { color = Rgba32.SpringGreen; } else { // we use the default color. } bitmap[x, y] = color; } } var memoryStream = new MemoryStream(); bitmap.SaveAsPng(memoryStream); memoryStream.Position = 0; return(memoryStream); } }
/// <inheritdoc /> public void MapAdded(int serverId, IGameMapInfo mapInfo) { this.HubContext.Clients.All.MapAdded(new GameServerInfo.GameMapInfo() { Id = mapInfo.MapNumber, Name = mapInfo.MapName, PlayerCount = mapInfo.Players.Count, ServerId = serverId, }); }
private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using var bitmap = terrain.ToImage(); var memoryStream = new MemoryStream(); bitmap.SaveAsPng(memoryStream); memoryStream.Position = 0; return(memoryStream); }
/// <inheritdoc /> public void MapAdded(int serverId, IGameMapInfo mapInfo) { var gameMapInfo = new GameServerInfo.GameMapInfo { Id = mapInfo.MapNumber, Name = mapInfo.MapName, PlayerCount = mapInfo.Players.Count, ServerId = serverId, }; this.HubContext?.Clients.All.SendAsync(nameof(IServerListClient.MapAdded), gameMapInfo); }
private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using (var bitmap = new SkiaSharp.SKBitmap(0x100, 0x100)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = SKColors.Black; if (terrain.SafezoneMap[y, x]) { color = SKColors.Gray; } else if (terrain.WalkMap[y, x]) { color = SKColors.SpringGreen; } else { // we use the default color. } bitmap.SetPixel(x, y, color); } } using (var memoryStream = new SKDynamicMemoryWStream()) { if (SKPixmap.Encode(memoryStream, bitmap, SKEncodedImageFormat.Png, 100)) { return(memoryStream.DetachAsData().AsStream()); } } return(null); } }