Пример #1
0
        internal static int DeSerializeInt(StreamReader sr)
        {
            string s = sr.ReadLine();

            if (s == null)
            {
                CCLog.Log("DeSerializeInt: null");
                return(0);
            }
            return(CCUtils.CCParseInt(s));
        }
Пример #2
0
        public int GetIntegerForKey(string key, int defaultValue = 0)
        {
            string value = GetValueForKey(key);
            int    ret   = defaultValue;

            if (value != null)
            {
                ret = CCUtils.CCParseInt(value);
            }

            return(ret);
        }
Пример #3
0
        void ParseInternalProperties()
        {
            string vertexZStr = PropertyNamed("cc_vertexz");

            if (!String.IsNullOrEmpty(vertexZStr))
            {
                if (vertexZStr == "automatic")
                {
                    useAutomaticVertexZ = true;
                }
                else
                {
                    defaultTileVertexZ = CCUtils.CCParseInt(vertexZStr);
                }
            }
        }
Пример #4
0
        void ParseInternalProperties()
        {
            string vertexz = PropertyNamed("cc_vertexz");

            if (!String.IsNullOrEmpty(vertexz))
            {
                if (vertexz == "automatic")
                {
                    useAutomaticVertexZ = true;
                }
                else
                {
                    vertexZvalue = CCUtils.CCParseInt(vertexz);
                }
            }
        }
Пример #5
0
        public bool ParseContent(TextReader sr)
        {
            var setting = new XmlReaderSettings();

            setting.DtdProcessing = DtdProcessing.Ignore;

            XmlReader xmlReader = XmlReader.Create(sr, setting);
            int       dataindex = 0;

            int Width  = 0;
            int Height = 0;

            while (xmlReader.Read())
            {
                string name = xmlReader.Name;

                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:

                    string[] attrs = null;

                    if (name == "map")
                    {
                        Width  = CCUtils.CCParseInt(xmlReader.GetAttribute("width"));
                        Height = CCUtils.CCParseInt(xmlReader.GetAttribute("height"));
                    }

                    if (xmlReader.HasAttributes)
                    {
                        attrs = new string[xmlReader.AttributeCount * 2];
                        xmlReader.MoveToFirstAttribute();
                        int i = 0;
                        attrs[0] = xmlReader.Name;
                        attrs[1] = xmlReader.Value;
                        i       += 2;

                        while (xmlReader.MoveToNextAttribute())
                        {
                            attrs[i]     = xmlReader.Name;
                            attrs[i + 1] = xmlReader.Value;
                            i           += 2;
                        }

                        // Move the reader back to the element node.
                        xmlReader.MoveToElement();
                    }
                    StartElement(this, name, attrs);

                    byte[] buffer = null;

                    //read data content of tmx file
                    if (name == "data")
                    {
                        if (attrs != null)
                        {
                            string encoding = "";
                            for (int i = 0; i < attrs.Length; i++)
                            {
                                if (attrs [i] == "encoding")
                                {
                                    encoding = attrs [i + 1];
                                }
                            }

                            if (encoding == "base64")
                            {
                                int dataSize = (Width * Height * 4) + 1024;
                                buffer = new byte[dataSize];
                                xmlReader.ReadElementContentAsBase64(buffer, 0, dataSize);
                            }
                            else
                            {
                                string value = xmlReader.ReadElementContentAsString();
                                buffer = Encoding.UTF8.GetBytes(value);
                            }
                        }
                        // Pure XML TileMap
                        else
                        {
                            int dataSize = (Width * Height * 4) + 1024;
                            buffer = new byte[dataSize];
                        }

                        TextHandler(this, buffer, buffer.Length);
                        EndElement(this, name);
                    }
                    else if (name == "key" || name == "integer" || name == "real" || name == "string")
                    {
                        string value = xmlReader.ReadElementContentAsString();
                        buffer = Encoding.UTF8.GetBytes(value);
                        TextHandler(this, buffer, buffer.Length);
                        EndElement(this, name);
                    }
                    else if (xmlReader.IsEmptyElement)
                    {
                        EndElement(this, name);
                    }
                    break;

                case XmlNodeType.EndElement:
                    EndElement(this, xmlReader.Name);
                    dataindex++;
                    break;

                default:
                    break;
                }
            }

            return(true);
        }