diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index 8e2d0c85f3..2eae760d1a 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -62,9 +62,7 @@ namespace OpenRa.FileFormats } byte[] data = Convert.FromBase64String(sb.ToString()); - List chunks = new List(); - BinaryReader reader = new BinaryReader(new MemoryStream(data)); try @@ -99,14 +97,19 @@ namespace OpenRa.FileFormats return (byte)ret; } + static ushort ReadWord(Stream s) + { + ushort ret = ReadByte(s); + ret |= (ushort)(ReadByte(s) << 8); + + return ret; + } + void UnpackTileData( MemoryStream ms ) { for( int i = 0 ; i < 128 ; i++ ) for( int j = 0 ; j < 128 ; j++ ) - { - MapTiles[ j, i ].tile = ReadByte( ms ); - MapTiles[ j, i ].tile |= (ushort)( ReadByte( ms ) << 8 ); - } + MapTiles[j, i].tile = ReadWord(ms); for( int i = 0 ; i < 128 ; i++ ) for( int j = 0 ; j < 128 ; j++ ) @@ -132,40 +135,4 @@ namespace OpenRa.FileFormats return (x >= XOffset && y >= YOffset && x < XOffset + Width && y < YOffset + Height); } } - - public struct TileReference - { - public ushort tile; - public byte image; - - public override int GetHashCode() { return tile.GetHashCode() ^ image.GetHashCode(); } - - public override bool Equals(object obj) - { - if (obj == null) - return false; - - TileReference r = (TileReference)obj; - return (r.image == image && r.tile == tile); - } - - public static bool operator ==(TileReference a, TileReference b) { return a.Equals(b); } - public static bool operator !=(TileReference a, TileReference b) { return !a.Equals(b); } - } - - public struct TreeReference - { - public readonly int X; - public readonly int Y; - public readonly string Image; - - public TreeReference(int xy, string image) - { - X = xy % 128; - Y = xy / 128; - Image = image; - } - - public Point Location { get { return new Point(X, Y); } } - } } diff --git a/OpenRa.FileFormats/OpenRa.FileFormats.csproj b/OpenRa.FileFormats/OpenRa.FileFormats.csproj index 97abe4236c..a8633c178e 100644 --- a/OpenRa.FileFormats/OpenRa.FileFormats.csproj +++ b/OpenRa.FileFormats/OpenRa.FileFormats.csproj @@ -51,7 +51,9 @@ + + diff --git a/OpenRa.FileFormats/TileReference.cs b/OpenRa.FileFormats/TileReference.cs new file mode 100644 index 0000000000..836f3173c9 --- /dev/null +++ b/OpenRa.FileFormats/TileReference.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenRa.FileFormats +{ + public struct TileReference + { + public ushort tile; + public byte image; + + public override int GetHashCode() { return tile.GetHashCode() ^ image.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + TileReference r = (TileReference)obj; + return (r.image == image && r.tile == tile); + } + + public static bool operator ==(TileReference a, TileReference b) { return a.Equals(b); } + public static bool operator !=(TileReference a, TileReference b) { return !a.Equals(b); } + } +} diff --git a/OpenRa.FileFormats/TreeReference.cs b/OpenRa.FileFormats/TreeReference.cs new file mode 100644 index 0000000000..994a1bad94 --- /dev/null +++ b/OpenRa.FileFormats/TreeReference.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; + +namespace OpenRa.FileFormats +{ + public struct TreeReference + { + public readonly int X; + public readonly int Y; + public readonly string Image; + + public TreeReference(int xy, string image) + { + X = xy % 128; + Y = xy / 128; + Image = image; + } + + public Point Location { get { return new Point(X, Y); } } + } +}