コード例 #1
0
        public static void LoadSprites(GorillaModel gorilla, StreamReader sr, string line)
        {
            while ((line = sr.ReadLine()) != null)
            {
                if (line.Contains("[Texture]") || line.Contains("[Font."))
                {
                    return;
                }

                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                var spriteTextData = line.Split(' ');

                SpriteModel newSprite = new SpriteModel();

                newSprite.Name   = spriteTextData[0];
                newSprite.posX   = convertToInt(spriteTextData[1]);
                newSprite.posY   = convertToInt(spriteTextData[2]);
                newSprite.width  = convertToInt(spriteTextData[3]);
                newSprite.height = convertToInt(spriteTextData[4]);

                gorilla.Sprites.Add(newSprite);
            }
        }
コード例 #2
0
        public static void LoadGorillaFont(String filepath, GorillaModel gorilla)
        {
            // create reader & open file
            using (StreamReader sr = new StreamReader(filepath))
            {
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);  // read a line of text

                    //load font data
                    if (line.Contains("[Font."))
                    {
                        LoadFont(gorilla, sr, line);
                    }

                    if (line.Contains("[Sprites]"))
                    {
                        LoadSprites(gorilla, sr, line);
                    }

                    if (line.Contains("[Texture]"))
                    {
                        LoadTexture(gorilla, sr);
                    }
                }

                // close the stream
                sr.Close();
            }
        }
コード例 #3
0
        public static void LoadTexture(GorillaModel gorilla, StreamReader sr)
        {
            string line = null;

            while (!String.IsNullOrEmpty(line = sr.ReadLine()))
            {
                if (line.Contains("[Sprites]") || line.Contains("[Font."))
                {
                    return;
                }

                if (line.Contains("file"))
                {
                    gorilla.GorillaTexture.file = line;
                }
                else if (line.Contains("whitepixel"))
                {
                    String[] whitePixel = line.Split(' ');
                    gorilla.GorillaTexture.whitepixel = new Position()
                    {
                        x = convertToInt(whitePixel[1]), y = convertToInt(whitePixel[2])
                    };
                }
            }
            //[Texture]
            //file arial.png
            //whitepixel 34 22
        }
コード例 #4
0
        public static void LoadFont(GorillaModel gorilla, StreamReader sr, string line)
        {
            //// TODO load Angelcode's BmFont tool.

            FontModel font = new FontModel();

            //font.size = convertToInt(line.Replace("[Font.", "").Replace("]", ""));
            //font.Id = convertToUShort(line.Replace("[Font.", "").Replace("]", ""));
            //font.Name = line;
            while (!String.IsNullOrEmpty(line = sr.ReadLine()))
            {
                if (line.StartsWith("info"))
                {
                    string[] info = line.Split(' ');
                    font.size = convertToInt(info[2].Split('=')[1]);
                    font.Id   = convertToUShort(info[2].Split('=')[1]);
                    // font.padding = convertToUShort(info[2].Split('=')[1]);
                    // font.spacing = convertToUShort(info[2].Split('=')[1]);
                }
                else if (line.StartsWith("common"))
                {
                    string[] info = line.Split(' ');
                    font.lineheight = convertToInt(info[1].Split('=')[1]);
                }


                //else if (line.StartsWith("glyph"))
                //{
                //    String[] glyphString = line.Split(' ');
                //    font.SetGlyph(convertToUInt(glyphString[0].Split('_')[1]), new Glyph() { X = convertToInt(glyphString[1]), Y = convertToInt(glyphString[2]), width = convertToInt(glyphString[3]), height = convertToInt(glyphString[4]), advance = convertToInt(glyphString[5]) }, "");
                //}
                //else if (line.Contains("verticaloffset_"))
                //{
                //    String[] verticaloffset_String = line.Split(' ');
                //    font.SetVerticalOffset(convertToUInt(verticaloffset_String[0].Split('_')[1]), convertToInt(verticaloffset_String[1]));
                //}
                //else if (line.Contains("kerning_"))
                //{
                //    String[] kerning_String = line.Split(' ');
                //    font.SetKerning(convertToUInt(kerning_String[0].Split('_')[1]), new Kerning() { RightGlyphID = convertToUInt(kerning_String[1]), KerningValue = convertToInt(kerning_String[2]) });
                //}
                //glyph_33 0 0 8 21
                //verticaloffset_33 -11
                //            glyph_121 101 270 25 37
                //verticaloffset_121 -18
                //kerning_121 65 1
                //kerning_121 76 1
                //kerning_121 84 2
                //kerning_121 86 1
            }

            gorilla.Fonts.Add(font);
            gorilla.Items.Add(font);
        }