Skip to content

Commit

Permalink
Remove System.Drawing.Common for better cross platform support
Browse files Browse the repository at this point in the history
Wouldn't run on linux or mac without installing some libraries
  • Loading branch information
Fenyx4 committed Aug 27, 2020
1 parent e94a733 commit 98587c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion U4DosRandomizer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.CommandLineUtils;
using Newtonsoft.Json;
using SixLabors.ImageSharp;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -128,7 +129,7 @@ private static void Randomize(int seed, string path)
worldMap.Save(path);

var image = worldMap.ToBitmap();
image.Save("worldMap.bmp");
image.SaveAsBmp("worldMap.bmp");

//PrintWorldMapInfo();
}
Expand Down
2 changes: 1 addition & 1 deletion U4DosRandomizer/U4DosRandomizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 18 additions & 18 deletions U4DosRandomizer/WorldMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void AddBridges(Random random, List<River> rivers)
}
}

while (bridgeCount < totalNumOBridgedRivers)
while (bridgeCount < totalNumOBridgedRivers && riverCollections.Count > 0)
{
var index = random.Next(0, riverCollections.Count());
AddBridge(random, riverCollections[index], false);
Expand Down Expand Up @@ -605,20 +605,20 @@ public void WriteMapToOriginalFormat(System.IO.BinaryWriter worldFile)
}
}

public Bitmap ToBitmap()
public SixLabors.ImageSharp.Image ToBitmap()
{
var image = new Bitmap(WorldMap.SIZE, WorldMap.SIZE);
var image = new SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32>(WorldMap.SIZE, WorldMap.SIZE);
for (int x = 0; x < WorldMap.SIZE; x++)
{
for (int y = 0; y < WorldMap.SIZE; y++)
{
if (colorMap.ContainsKey(_worldMapTiles[x, y]))
{
image.SetPixel(x, y, colorMap[_worldMapTiles[x, y]]);
image[x, y] = colorMap[_worldMapTiles[x, y]];
}
else
{
image.SetPixel(x, y, Color.White);
image[x, y] = SixLabors.ImageSharp.Color.White;
}

}
Expand All @@ -627,20 +627,20 @@ public Bitmap ToBitmap()
return image;
}

static private Dictionary<byte, Color> colorMap = new Dictionary<byte, Color>()
static private Dictionary<byte, SixLabors.ImageSharp.Color> colorMap = new Dictionary<byte, SixLabors.ImageSharp.Color>()
{
{0, Color.FromArgb(0,0,112) },
{1, Color.FromArgb(20,20,112) },
{2, Color.FromArgb(60,60,112) },
{3, Color.FromArgb(112, 0, 112) },
{4, Color.FromArgb(18, 112+18, 18) },
{5, Color.FromArgb(68, 112+68, 68) },
{6, Color.FromArgb(108,112+108,108) },
{7, Color.FromArgb(112+45,112+45,112+45) },
{8, Color.FromArgb(112+15,112+15,112+15) },
{70, Color.Orange },
{76, Color.Red },
{0xA1, Color.Purple },
{0, SixLabors.ImageSharp.Color.FromRgb(0, 0, 112) },
{1, SixLabors.ImageSharp.Color.FromRgb(20,20,112) },
{2, SixLabors.ImageSharp.Color.FromRgb(60,60,112) },
{3, SixLabors.ImageSharp.Color.FromRgb(112, 0, 112) },
{4, SixLabors.ImageSharp.Color.FromRgb(18, 112+18, 18) },
{5, SixLabors.ImageSharp.Color.FromRgb(68, 112+68, 68) },
{6, SixLabors.ImageSharp.Color.FromRgb(108,112+108,108) },
{7, SixLabors.ImageSharp.Color.FromRgb(112+45,112+45,112+45) },
{8, SixLabors.ImageSharp.Color.FromRgb(112+15,112+15,112+15) },
{70, SixLabors.ImageSharp.Color.Orange },
{76, SixLabors.ImageSharp.Color.Red },
{0xA1, SixLabors.ImageSharp.Color.Purple },
};
}
}

0 comments on commit 98587c8

Please sign in to comment.