Skip to content

Commit ba0b7b1

Browse files
committed
More region work
1 parent 954ff9e commit ba0b7b1

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

SC4Parser/Region/Bitmap.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ namespace SC4Parser.Region
99
{
1010
/// <summary>
1111
/// Very simple Bitmap implementation, parses specifically the type of bitmap used by SimCity 4
12-
/// (non compressed, BITMAPINFOHEADER)
1312
/// </summary>
1413
/// <remarks>
15-
///
14+
/// https://upload.wikimedia.org/wikipedia/commons/7/75/BMPfileFormat.svg
15+
/// (non compressed, BITMAPINFOHEADER)
1616
/// </remarks>
17+
///
1718
internal class Bitmap
1819
{
1920
internal static class EndinessHelper
@@ -115,10 +116,9 @@ public void Dump()
115116

116117
public struct RGB
117118
{
118-
byte R;
119-
byte G;
120-
byte B;
121-
119+
public byte R { get; private set; }
120+
public byte G { get; private set; }
121+
public byte B { get; private set; }
122122

123123
public static RGB Parse(BinaryReader reader)
124124
{
@@ -142,23 +142,12 @@ public string ToString()
142142

143143
public Bitmap(string path)
144144
{
145-
Parse(path);
146-
}
147-
148-
public void Parse(string path)
149-
{
150-
Parse(File.ReadAllBytes(path));
151-
}
152-
public void Parse(byte[] data)
153-
{
154-
using (MemoryStream stream = new MemoryStream(data))
145+
using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(path)))
155146
using (BinaryReader reader = new BinaryReader(stream))
156147
{
157148
// Parse headers
158149
Header = new FileHeader(reader);
159-
Header.Dump();
160150
DiBHeader = new InformationHeader(reader);
161-
DiBHeader.Dump();
162151

163152
// Parse pixels
164153
PixelMap = new RGB[DiBHeader.Height][];

SC4Parser/Region/Region.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace SC4Parser.Region
1010
{
11+
using RGB = Bitmap.RGB;
12+
1113
public class Region
1214
{
1315
public Building[] Buildings { get; private set; }
@@ -16,6 +18,7 @@ public class Region
1618

1719
public Dictionary<int, string> CityNameDictionary { get; private set; }
1820

21+
public string[][] RegionLayout;
1922

2023
public void Load(string path)
2124
{
@@ -25,10 +28,33 @@ public void Load(string path)
2528
Logger.Log(LogLevel.Error, "Could not find config.bmp file for region @ {0}", path);
2629
return;
2730
}
31+
// TODO: Wrap in try
32+
Bitmap regionBitmap = new Bitmap(configImagePath);
33+
34+
RegionLayout = new string[regionBitmap.DiBHeader.Height][];
35+
for (int y = 0; y < regionBitmap.DiBHeader.Height; y++)
36+
{
37+
RegionLayout[y] = new string[regionBitmap.DiBHeader.Width];
38+
for (int x = 0; x < regionBitmap.DiBHeader.Width; x++)
39+
{
40+
RGB pixelColor = regionBitmap.PixelMap[y][x];
41+
42+
if (pixelColor.R == 255)
43+
{
44+
// Small city
45+
}
46+
else if (pixelColor.G == 255)
47+
{
48+
// Medium city
49+
}
50+
else if (pixelColor.B == 255)
51+
{
52+
// Large city
53+
}
54+
}
55+
}
2856

29-
Bitmap b = new Bitmap(configImagePath);
3057

31-
3258
//using (Bitmap image = new Bitmap(path))
3359
//{
3460
// for (int i = 0; i < image.Width; i++)

0 commit comments

Comments
 (0)