git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1197 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -8,18 +8,12 @@ namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Terrain
|
||||
{
|
||||
public readonly int Width;
|
||||
public readonly int Height;
|
||||
public readonly int XDim;
|
||||
public readonly int YDim;
|
||||
public readonly int NumTiles;
|
||||
|
||||
readonly byte[] index;
|
||||
readonly List<Bitmap> TileBitmaps = new List<Bitmap>();
|
||||
public readonly List<byte[]> TileBitmapBytes = new List<byte[]>();
|
||||
|
||||
public Terrain( Stream stream, Palette pal )
|
||||
{
|
||||
int Width, Height, XDim, YDim, NumTiles;
|
||||
|
||||
BinaryReader reader = new BinaryReader( stream );
|
||||
Width = reader.ReadUInt16();
|
||||
Height = reader.ReadUInt16();
|
||||
@@ -40,45 +34,17 @@ namespace OpenRa.FileFormats
|
||||
int IndexStart = reader.ReadInt32();
|
||||
|
||||
stream.Position = IndexStart;
|
||||
index = new byte[ IndexEnd - IndexStart ];
|
||||
stream.Read( index, 0, IndexEnd - IndexStart );
|
||||
|
||||
for( int i = 0 ; i < index.Length ; i++ )
|
||||
foreach( byte b in new BinaryReader(stream).ReadBytes(IndexEnd - IndexStart) )
|
||||
{
|
||||
if (index[i] != 255)
|
||||
if (b != 255)
|
||||
{
|
||||
byte[] tileData = new byte[24 * 24];
|
||||
stream.Position = ImgStart + index[i] * 24 * 24;
|
||||
stream.Read(tileData, 0, 24 * 24);
|
||||
TileBitmaps.Add(BitmapBuilder.FromBytes(tileData, new Size(24, 24), pal));
|
||||
TileBitmapBytes.Add(tileData);
|
||||
stream.Position = ImgStart + b * 24 * 24;
|
||||
TileBitmapBytes.Add(new BinaryReader(stream).ReadBytes(24 * 24));
|
||||
}
|
||||
else
|
||||
{
|
||||
TileBitmaps.Add(null);
|
||||
TileBitmapBytes.Add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap GetTile( int index )
|
||||
{
|
||||
if( index < TileBitmaps.Count )
|
||||
return TileBitmaps[ index ];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bitmap[ , ] GetTiles( int tileNum )
|
||||
{
|
||||
int startIndex = tileNum * XDim * YDim;
|
||||
Bitmap[ , ] ret = new Bitmap[ XDim, YDim ];
|
||||
|
||||
for( int x = 0 ; x < XDim ; x++ )
|
||||
for( int y = 0 ; y < YDim ; y++ )
|
||||
ret[ x, y ] = GetTile( startIndex + x + XDim * y );
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user