예제 #1
0
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        public void Initialize()
        {
            var fontsFiles = Directory.GetFiles(FontsFolderPath, "*.txt");

            foreach (var ff in fontsFiles)
            {
                var font = MapFont.LoadFromFile(ff);

                _fonts.Add(font.Name, font);
            }
        }
예제 #2
0
파일: MapFont.cs 프로젝트: giacomelli/Doog
        /// <summary>
        /// Loads the MapFont from file.
        /// </summary>
        /// <param name="fileName">The filename.</param>
        /// <returns>The MapFont.</returns>
        public static MapFont LoadFromFile(string fileName)
        {
            var font            = new MapFont();
            var content         = File.ReadAllLines(fileName).ToArray();
            var currentChar     = '!';
            var currentCharData = new List <string>();

            // METADATA
            // Name:
            // Url:
            // Width:
            // Height:
            font.Name = ReadMetadata(content, 0);
            font.Size = new Point(
                Convert.ToInt32(ReadMetadata(content, 2)),
                Convert.ToInt32(ReadMetadata(content, 3)));

            var currentCharReadLines = 0;

            // Space.
            font._charsData.Add(' ', new List <string> {
                string.Empty.PadRight((int)font.Size.X, ' ')
            });

            for (int i = 4; i < content.Length; i++)
            {
                var line = content[i].TrimEnd();

                if (font.Size.Y.EqualsTo(currentCharReadLines))
                {
                    font._charsData.Add(currentChar, currentCharData);
                    currentChar++;
                    currentCharData      = new List <string>();
                    currentCharReadLines = 0;
                }

                currentCharReadLines++;
                currentCharData.Add(line);
            }

            return(font);
        }