private static Animation LoadV2AnimationFromFile(StreamReader file)
{
Animation newAnimation;
// The first line has information on the number of frames, rows and columns
string[] size = file.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int numFrames = Convert.ToInt32(size[0]);
int numRows = Convert.ToInt32(size[1]);
int numCols = Convert.ToInt32(size[2]);
// Now that we know the columncount and rowcount, create the animation class
newAnimation = new Animation(numRows, numCols);
// The rest of the file is frame information. Load in [numFrames] frames.
TimeSpan frameStartTime;
double totalDuration = 0;
for (int grid = 0; grid < numFrames; ++grid)
{
// The first line is frame duration in seconds
string durationString = file.ReadLine();
double duration = Convert.ToDouble(durationString);
// add 0.5 to round instead of simple truncate
frameStartTime = new TimeSpan(0, 0, 0, 0, (int)(totalDuration * 1000 + 0.5));
totalDuration += duration;
// The next lines are grid information
KeyFrame newKeyFrame = new KeyFrame(numRows, numCols, frameStartTime, null);
for (int row = 0; row < numRows; ++row)
{
string[] line = file.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int col = 0; col < numCols; ++col)
{
Color c = (line[col] == "0") ? new Color(0, 0, 0) : new Color(byte.MaxValue, byte.MaxValue, byte.MaxValue);
newKeyFrame.Set(row, col, c);
}
}
newAnimation.Frames.Add(newKeyFrame);
}
file.Close();
return newAnimation;
}