private PlistFile dict_to_plist(Dictionary <string, XmlNode> dict)
        {
            PlistFile plistFile = new PlistFile();

            //metadata
            plistFile.metadata.format = 0;
            if (dict.ContainsKey("metadata"))
            {
                PlistDictionary metadata = new PlistDictionary(dict["metadata"]);
                plistFile.metadata.format = metadata.GetInt("format");
                plistFile.metadata.realTextureFileName = metadata.GetString("realTextureFileName");
                plistFile.metadata.smartupdate         = metadata.GetString("smartupdate");
                plistFile.metadata.textureFileName     = metadata.GetString("textureFileName");

                plistFile.metadata.size = metadata.GetSize("size");
            }

            //frames
            PlistDictionary frames = new PlistDictionary(dict["frames"]);
            int             format = plistFile.metadata.format;

            foreach (KeyValuePair <string, XmlNode> node in frames)
            {
                PlistDictionary d     = new PlistDictionary(node.Value);
                PlistFrame      frame = new PlistFrame
                {
                    name = node.Key
                };

                if (format == 0)
                {
                    frame.frame  = d.ToRectangle();
                    frame.offset = d.ToPoint("offsetX", "offsetY");

                    frame.sourceSize        = d.ToSize("originalWidth", "originalWidth");
                    frame.sourceSize.Width  = Math.Abs(frame.sourceSize.Width);
                    frame.sourceSize.Height = Math.Abs(frame.sourceSize.Height);

                    frame.rotated = false;
                }
                else if (format == 1 || format == 2)
                {
                    frame.rotated = format == 2 ? d.GetBool("rotated") : false;

                    frame.frame = d.GetRectangle("frame");

                    frame.offset = d.GetPoint("offset");

                    frame.sourceSize = d.GetSize("sourceSize");
                }
                else if (format == 3)
                {
                    frame.rotated = d.GetBool("textureRotated");

                    frame.sourceSize = d.GetSize("spriteSourceSize");

                    frame.offset = d.GetPoint("spriteOffset");

                    Size      s = d.GetSize("spriteSize");
                    Rectangle b = d.GetRectangle("textureRect");
                    frame.frame = new Rectangle(b.X, b.Y, s.Width, s.Height);
                }
                plistFile.frames.Add(frame);
            }
            return(plistFile);
        }
Beispiel #2
0
        private PlistFile dict_to_plist(Dictionary <string, XmlNode> dict)
        {
            PlistFile plistFile = new PlistFile();

            //metadata
            plistFile.metadata.format = 0;
            if (dict.ContainsKey("metadata"))
            {
                Dictionary <string, XmlNode> metadata = tree_to_dict(dict["metadata"]);
                plistFile.metadata.format = Int32.Parse(metadata["format"].InnerText);
                plistFile.metadata.realTextureFileName = metadata["realTextureFileName"].InnerText;
                plistFile.metadata.smartupdate         = metadata["smartupdate"].InnerText;
                plistFile.metadata.textureFileName     = metadata["textureFileName"].InnerText;

                List <int> li = to_list(metadata["size"].InnerText);
                plistFile.metadata.size = new Size(li[0], li[1]);
            }

            //frames
            Dictionary <string, XmlNode> frames = tree_to_dict(dict["frames"]);
            int format = plistFile.metadata.format;

            foreach (KeyValuePair <string, XmlNode> node in frames)
            {
                Dictionary <string, XmlNode> d = tree_to_dict(node.Value);
                PlistFrame frame = new PlistFrame();
                frame.name = node.Key;
                if (format == 0)
                {
                    frame.frame = new Rectangle(
                        Int32.Parse(d["x"].InnerText),
                        Int32.Parse(d["y"].InnerText),
                        Int32.Parse(d["width"].InnerText),
                        Int32.Parse(d["height"].InnerText)
                        );

                    frame.offset = new Point(
                        Int32.Parse(d["offsetX"].InnerText),
                        Int32.Parse(d["offsetY"].InnerText)
                        );

                    frame.sourceSize = new Size(
                        Math.Abs(Int32.Parse(d["originalWidth"].InnerText)),
                        Math.Abs(Int32.Parse(d["originalHeight"].InnerText))
                        );

                    frame.rotated = false;
                }
                else if (format == 1 || format == 2)
                {
                    frame.rotated = format == 2 ? (d["rotated"].Name == "true") : false;

                    List <int> li = to_list(d["frame"].InnerText);
                    frame.frame = new Rectangle(li[0], li[1], li[2], li[3]);

                    li           = to_list(d["offset"].InnerText);
                    frame.offset = new Point(li[0], li[1]);

                    li = to_list(d["sourceSize"].InnerText);
                    frame.sourceSize = new Size(li[0], li[1]);
                }
                else if (format == 3)
                {
                    frame.rotated = bool.Parse(d["textureRotated"].InnerText);

                    List <int> li = to_list(d["spriteSourceSize"].InnerText);
                    frame.sourceSize = new Size(li[0], li[1]);

                    li           = to_list(d["spriteOffset"].InnerText);
                    frame.offset = new Point(li[0], li[1]);

                    li = to_list(d["spriteSize"].InnerText);
                    Size s = new Size(li[0], li[1]);

                    li = to_list(d["frame"].InnerText);
                    Rectangle b = new Rectangle(li[0], li[1], li[2], li[3]);

                    frame.frame = new Rectangle(b.X, b.Y, s.Width, s.Height);
                }
                plistFile.frames.Add(frame);
            }
            return(plistFile);
        }