예제 #1
0
        public bool ReadProperty(Property prop, XmlNode token)
        {
            // BrickColors are represented by ints, see if
            // we can infer when they should be a BrickColor.

            if (prop.Name.Contains("Color") || prop.Instance.ClassName.Contains("Color"))
            {
                var brickColorToken = XmlPropertyTokens.GetHandler <BrickColorToken>();
                return(brickColorToken.ReadProperty(prop, token));
            }
            else
            {
                return(XmlPropertyTokens.ReadPropertyGeneric <int>(prop, PropertyType.Int, token));
            }
        }
예제 #2
0
        public bool ReadProperty(Property prop, XmlNode token)
        {
            bool success = true;

            float[] fields = new float[XmlFields.Length];

            for (int i = 0; i < fields.Length; i++)
            {
                string key = XmlFields[i];

                try
                {
                    var    coord = token[key];
                    string text  = coord?.InnerText;

                    if (text == null)
                    {
                        text    = "0";
                        success = false;
                    }

                    fields[i] = Formatting.ParseFloat(text);
                }
                catch
                {
                    success = false;
                    break;
                }
            }

            if (success)
            {
                float r = fields[0],
                      g = fields[1],
                      b = fields[2];

                prop.Type  = PropertyType.Color3;
                prop.Value = new Color3(r, g, b);
            }
            else
            {
                // Try falling back to the Color3uint8 technique...
                var color3uint8 = XmlPropertyTokens.GetHandler <Color3uint8Token>();
                success = color3uint8.ReadProperty(prop, token);
            }

            return(success);
        }
예제 #3
0
        public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
        {
            ProtectedString value = prop.CastValue <ProtectedString>();

            if (value.IsCompiled)
            {
                var binary = XmlPropertyTokens.GetHandler <BinaryStringToken>();
                binary.WriteProperty(prop, doc, node);
            }
            else
            {
                string contents = Encoding.UTF8.GetString(value.RawBuffer);

                if (contents.Contains("\r") || contents.Contains("\n"))
                {
                    XmlCDataSection cdata = doc.CreateCDataSection(contents);
                    node.AppendChild(cdata);
                }
                else
                {
                    node.InnerText = contents;
                }
            }
        }