コード例 #1
0
        public static Dictionary<char, CharacterData> Parse(string filePath)
        {
            // create a dictionary that will be filled and returned by Parse
            Dictionary<char, CharacterData> charDictionary = new Dictionary<char, CharacterData>();

            // fill string array with lines from the specified file
            string[] lines = File.ReadAllLines(filePath);

            for (int i = HeaderSize /*ignore header lines*/; i < lines.Length; i++)
            {
                string firstLine = lines[i];

                // splits each line into an array using " " as the delimiter
                string[] typesAndValues = firstLine.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                // All the data comes in a certain order
                // used to make the parser shorter
                CharacterData charData = new CharacterData
                {
                    Id = GetValue(typesAndValues[1]),
                    X = GetValue(typesAndValues[2]),
                    Y = GetValue(typesAndValues[3]),
                    Width = GetValue(typesAndValues[4]),
                    Height = GetValue(typesAndValues[5]),
                    XOffset = GetValue(typesAndValues[6]),
                    YOffset = GetValue(typesAndValues[7]),
                    XAdvance = GetValue(typesAndValues[8]),
                };
                charDictionary.Add((char)charData.Id, charData);
            }

            return charDictionary;
        }
コード例 #2
0
 public CharacterSprite(Sprite sprite, CharacterData data)
 {
     Sprite = sprite;
     Data = data;
 }