more info in the tileset file (load only the tiles that are in the current tile-set)
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1298 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -11,36 +11,62 @@ namespace OpenRa.FileFormats
|
||||
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
|
||||
public readonly Package MixFile;
|
||||
|
||||
string NextLine( StreamReader reader )
|
||||
{
|
||||
string ret;
|
||||
do
|
||||
{
|
||||
ret = reader.ReadLine();
|
||||
if( ret == null )
|
||||
return null;
|
||||
ret = ret.Trim();
|
||||
}
|
||||
while( ret.Length == 0 || ret[ 0 ] == ';' );
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TileSet( Package mixFile, string suffix )
|
||||
{
|
||||
char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] );
|
||||
MixFile = mixFile;
|
||||
StreamReader tileIdFile = File.OpenText( "../../../tileSet.til" );
|
||||
|
||||
while( true )
|
||||
{
|
||||
string countStr = tileIdFile.ReadLine();
|
||||
string startStr = tileIdFile.ReadLine();
|
||||
string pattern = tileIdFile.ReadLine() + suffix;
|
||||
if( countStr == null || startStr == null || pattern == null )
|
||||
string tileSetStr = NextLine( tileIdFile );
|
||||
string countStr = NextLine( tileIdFile );
|
||||
string startStr = NextLine( tileIdFile );
|
||||
string pattern = NextLine( tileIdFile ) + suffix;
|
||||
if( tileSetStr == null || countStr == null || startStr == null || pattern == null )
|
||||
break;
|
||||
|
||||
if( tileSetStr.IndexOf( tileSetChar.ToString() ) == -1 )
|
||||
continue;
|
||||
|
||||
int count = int.Parse( countStr );
|
||||
int start = int.Parse( startStr, NumberStyles.HexNumber );
|
||||
for( int i = 0 ; i < count ; i++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream s = mixFile.GetContent(string.Format(pattern, i + 1));
|
||||
if (!tiles.ContainsKey((ushort)(start + i)))
|
||||
tiles.Add((ushort)(start + i), new Terrain(s));
|
||||
}
|
||||
catch { }
|
||||
Stream s = mixFile.GetContent(string.Format(pattern, i + 1));
|
||||
if (!tiles.ContainsKey((ushort)(start + i)))
|
||||
tiles.Add((ushort)(start + i), new Terrain(s));
|
||||
}
|
||||
}
|
||||
|
||||
tileIdFile.Close();
|
||||
}
|
||||
|
||||
public byte[] GetBytes(TileReference r) { return tiles[r.tile].TileBitmapBytes[r.image]; }
|
||||
public byte[] GetBytes(TileReference r)
|
||||
{
|
||||
Terrain tile;
|
||||
if( tiles.TryGetValue( r.tile, out tile ) )
|
||||
return tile.TileBitmapBytes[ r.image ];
|
||||
|
||||
byte[] missingTile = new byte[ 24 * 24 ];
|
||||
for( int i = 0 ; i < missingTile.Length ; i++ )
|
||||
missingTile[ i ] = 0x36;
|
||||
|
||||
return missingTile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user