Support tmp(ts) templates with empty tiles.

This commit is contained in:
Paul Chote
2014-10-05 16:53:27 +13:00
parent 6a72e87028
commit fff8c7680b

View File

@@ -30,26 +30,31 @@ namespace OpenRA.Mods.TS.SpriteLoaders
public TmpTSFrame(Stream s, Size size) public TmpTSFrame(Stream s, Size size)
{ {
Size = size; if (s.Position != 0)
// Ignore tile header for now
s.Position += 52;
Data = new byte[size.Width * size.Height];
// Unpack tile data
var width = 4;
for (var i = 0; i < size.Height; i++)
{ {
var start = i * size.Width + (size.Width - width) / 2; Size = size;
for (var j = 0; j < width; j++)
Data[start + j] = s.ReadUInt8();
width += (i < size.Height / 2 - 1 ? 1 : -1) * 4; // Ignore tile header for now
s.Position += 52;
Data = new byte[size.Width * size.Height];
// Unpack tile data
var width = 4;
for (var i = 0; i < size.Height; i++)
{
var start = i * size.Width + (size.Width - width) / 2;
for (var j = 0; j < width; j++)
Data[start + j] = s.ReadUInt8();
width += (i < size.Height / 2 - 1 ? 1 : -1) * 4;
}
// Ignore Z-data for now
// Ignore extra data for now
} }
else
// Ignore Z-data for now Data = new byte[0];
// Ignore extra data for now
} }
} }
@@ -60,8 +65,10 @@ namespace OpenRA.Mods.TS.SpriteLoaders
var sx = s.ReadUInt32(); var sx = s.ReadUInt32();
var sy = s.ReadUInt32(); var sy = s.ReadUInt32();
// Find the first frame // Find the first non-empty frame
var offset = s.ReadUInt32(); var offset = s.ReadUInt32();
while (offset == 0)
offset = s.ReadUInt32();
if (offset > s.Length - 52) if (offset > s.Length - 52)
{ {