Esempio n. 1
0
        protected override List <ImageInfo> OnToImageList(PListDict plistDict)
        {
            List <ImageInfo> imageInfoList = new List <ImageInfo>();

            foreach (KeyValuePair <string, IPListElement> keyValuePair in (Dictionary <string, IPListElement>)(plistDict["frames"] as PListDict))
            {
                string    key        = keyValuePair.Key;
                PListDict plistDict1 = keyValuePair.Value as PListDict;
                Rectangle rect       = PlistFormatHelp.ConvertToRect(((PListElement <string>)plistDict1["frame"]).Value);
                Point     point      = PlistFormatHelp.ConvertToPoint(((PListElement <string>)plistDict1["offset"]).Value);
                Size      size       = PlistFormatHelp.ConvertToSize(((PListElement <string>)plistDict1["sourceSize"]).Value);
                int       x          = (size.Width - rect.Width) / 2 + point.X;
                int       y          = (size.Height - rect.Height) / 2 - point.Y;
                ImageInfo imageInfo  = new ImageInfo(key, rect, size, new Point(x, y));
                imageInfoList.Add(imageInfo);
            }
            return(imageInfoList);
        }
Esempio n. 2
0
        public static Rectangle ConvertToRect(string plistString)
        {
            int num1 = plistString.IndexOf('{');
            int num2 = 0;
            int index;

            for (index = 0; index < plistString.Length; ++index)
            {
                if ((int)plistString[index] == 125)
                {
                    ++num2;
                }
                if (num2 == 3)
                {
                    break;
                }
            }
            int num3 = index;

            if (num1 < 0 || num2 != 3)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            plistString = plistString.Substring(num1 + 1, num3 - num1 - 1);
            int startIndex = plistString.IndexOf('}');

            if (startIndex < 0)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            int length = plistString.IndexOf(',', startIndex);

            if (length < 0)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            return(new Rectangle(PlistFormatHelp.ConvertToPoint(plistString.Substring(0, length)), PlistFormatHelp.ConvertToSize(plistString.Substring(length + 1, plistString.Length - length - 1))));
        }
        protected override List <ImageInfo> OnToImageList(PListDict plistDict)
        {
            List <ImageInfo> imageInfoList = new List <ImageInfo>();

            foreach (KeyValuePair <string, IPListElement> keyValuePair in (Dictionary <string, IPListElement>)(plistDict["frames"] as PListDict))
            {
                string    key        = keyValuePair.Key;
                PListDict plistDict1 = keyValuePair.Value as PListDict;
                Rectangle rect1      = PlistFormatHelp.ConvertToRect(((PListElement <string>)plistDict1["spriteColorRect"]).Value);
                Rectangle rect2      = PlistFormatHelp.ConvertToRect(((PListElement <string>)plistDict1["textureRect"]).Value);
                Size      size       = PlistFormatHelp.ConvertToSize(((PListElement <string>)plistDict1["spriteSourceSize"]).Value);
                bool      isRotation = ((PListElement <bool>)plistDict1["textureRotated"]).Value;
                if (isRotation)
                {
                    int width = rect2.Width;
                    rect2.Width  = rect2.Height;
                    rect2.Height = width;
                }
                ImageInfo imageInfo = new ImageInfo(key, rect2, size, rect1.Location, isRotation);
                imageInfoList.Add(imageInfo);
            }
            return(imageInfoList);
        }
        protected override PListRoot OnToPlist(List <ImageInfo> imageList, Size size, string imageKey)
        {
            PListRoot plistRoot  = new PListRoot();
            PListDict plistDict1 = new PListDict();

            plistRoot.Root = (IPListElement)plistDict1;
            PListDict plistDict2 = new PListDict();

            plistDict1.Add("frames", (IPListElement)plistDict2);
            foreach (ImageInfo image in imageList)
            {
                PListDict plistDict3 = new PListDict();
                plistDict2.Add(image.Name, (IPListElement)plistDict3);
                string str1 = PlistFormatHelp.ConvertToString(image.Bounding);
                plistDict3.Add("frame", (IPListElement) new PListString(str1));
                string str2 = PlistFormatHelp.ConvertToString(new Point(image.SourceLocation.X + image.Bounding.Width / 2 - image.SourceSize.Width / 2, image.SourceSize.Height / 2 - (image.SourceLocation.Y + image.Bounding.Height / 2)));
                plistDict3.Add("offset", (IPListElement) new PListString(str2));
                plistDict3.Add("rotated", (IPListElement) new PListBool(image.IsRotation));
                string str3 = PlistFormatHelp.ConvertToString(image.SourceSize);
                plistDict3.Add("sourceSize", (IPListElement) new PListString(str3));
            }
            PListDict plistDict4 = new PListDict();

            plistDict1.Add("metadata", (IPListElement)plistDict4);
            plistDict4.Add("format", (IPListElement) new PListInteger(2L));
            plistDict4.Add("textureFileName", (IPListElement) new PListString(imageKey));
            plistDict4.Add("realTextureFileName", (IPListElement) new PListString(imageKey));
            string str = "{" + (object)size.Width + "," + (object)size.Height + "}";

            plistDict4.Add("size", (IPListElement) new PListString(str));
            PListDict plistDict5 = new PListDict();

            plistDict1.Add("texture", (IPListElement)plistDict5);
            plistDict5.Add("width", (IPListElement) new PListInteger((long)size.Width));
            plistDict5.Add("height", (IPListElement) new PListInteger((long)size.Height));
            return(plistRoot);
        }
Esempio n. 5
0
 public static Size ConvertToSize(string plistString)
 {
     string[] strArray = PlistFormatHelp.SplitWithForm(plistString);
     return(new Size(Convert.ToInt32(strArray[0]), Convert.ToInt32(strArray[1])));
 }
Esempio n. 6
0
 public static Point ConvertToPoint(string plistString)
 {
     string[] strArray = PlistFormatHelp.SplitWithForm(plistString);
     return(new Point(Convert.ToInt32(strArray[0]), Convert.ToInt32(strArray[1])));
 }
Esempio n. 7
0
 public static string ConvertToString(Rectangle rect)
 {
     return("{" + PlistFormatHelp.ConvertToString(rect.Location) + "," + PlistFormatHelp.ConvertToString(rect.Size) + "}");
 }