AnimatorClient.AnimationLoader.LoadV2AnimationFromFile C# (CSharp) Метод

LoadV2AnimationFromFile() приватный статический Метод

Loads a v2 animation file from the an already open file. 1. 0.2 2. [framecount] [rowcount] [columncount] 3. [frameduration (double, seconds)] 4. [row 0, col 0 (0 or 1)] [row 0, col 1 (0 or 1)] ... [row 0, col columncount, (0 or 1)] 5. ... 6. [row rowcount, col 0 (0 or 1)] [row rowcount, col 1 (0 or 1)] ... [row rowcount, col columncount, (0 or 1)] 7. (repeat for framecount times)
private static LoadV2AnimationFromFile ( StreamReader file ) : Animation
file System.IO.StreamReader
Результат AnimationModels.Animation
        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;
        }