Exemplo n.º 1
0
            public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
            {
                var args = node.ToString().Split(',');

                var b = float.Parse(args[0], CultureInfo.InvariantCulture);
                var l = float.Parse(args[1], CultureInfo.InvariantCulture);
                var t = float.Parse(args[2], CultureInfo.InvariantCulture);
                var r = float.Parse(args[3], CultureInfo.InvariantCulture);

                return(new Box2(l, b, r, t));
            }
Exemplo n.º 2
0
        /// <summary>
        /// Turn a YAML node into an integer value with the correct flags set.
        /// </summary>
        public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer objectSerializer)
        {
            // Fallback to just a number, if it's not in flag format yet
            // This is a hack, but it's only for legacy representations, so it's not so bad
            if (node is YamlScalarNode)
            {
                return((int)objectSerializer.NodeToType(typeof(int), node));
            }

            return(base.NodeToType(type, node, objectSerializer));
        }
Exemplo n.º 3
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var color = (Color)obj;

                Int32 hexColor = 0;

                hexColor += color.RByte << 24;
                hexColor += color.GByte << 16;
                hexColor += color.BByte << 8;
                hexColor += color.AByte;

                return(new YamlScalarNode("#" + hexColor.ToString("X")));
            }
Exemplo n.º 4
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                switch (obj)
                {
                case SpriteSpecifier.Texture tex:
                    return(tex.TexturePath.ToString());

                case SpriteSpecifier.Rsi rsi:
                    var mapping = new YamlMappingNode();
                    mapping.Add("sprite", rsi.RsiPath.ToString());
                    mapping.Add("state", rsi.RsiState);
                    return(mapping);
                }
                throw new NotImplementedException();
            }
Exemplo n.º 5
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var node   = new YamlMappingNode();
                var type   = obj.GetType();
                var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                foreach (var field in fields)
                {
                    if (field.IsNotSerialized)
                    {
                        continue;
                    }

                    var fVal = field.GetValue(obj);

                    // Potential recursive infinite loop?
                    var fTypeNode = serializer.TypeToNode(fVal);
                    node.Add(field.Name, fTypeNode);
                }

                return(node);
            }
Exemplo n.º 6
0
 public abstract object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer);
Exemplo n.º 7
0
 public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(SpriteSpecifier.FromYaml(node));
 }
Exemplo n.º 8
0
 public override object NodeToType(Type _type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(_formatter.FromCustomFormat(serializer.NodeToType(_formatter.Format, node)));
 }
Exemplo n.º 9
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var val = (int)(GridId)obj;

                return(new YamlScalarNode(val.ToString()));
            }
Exemplo n.º 10
0
            public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
            {
                var val = int.Parse(node.ToString(), CultureInfo.InvariantCulture);

                return(new MapId(val));
            }
Exemplo n.º 11
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var vec = (Vector4)obj;

                return(new YamlScalarNode($"{vec.X.ToString(CultureInfo.InvariantCulture)},{vec.Y.ToString(CultureInfo.InvariantCulture)},{vec.Z.ToString(CultureInfo.InvariantCulture)},{vec.W.ToString(CultureInfo.InvariantCulture)}"));
            }
Exemplo n.º 12
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var seconds = ((TimeSpan)obj).TotalSeconds;

                return(new YamlScalarNode(seconds.ToString(CultureInfo.InvariantCulture)));
            }
Exemplo n.º 13
0
            public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
            {
                var seconds = double.Parse(node.AsString(), CultureInfo.InvariantCulture);

                return(TimeSpan.FromSeconds(seconds));
            }
 /// <summary>
 /// Turn an integer into a YAML node with the corresponding constant name.
 /// </summary>
 /// <returns>
 /// A string node of the constant corresponding to the given value.
 /// </returns>
 /// <exception cref="ConstantSerializerException">
 /// Thrown if there is no corresponding constant name to the value passed in.
 /// </exception>
 public override YamlNode TypeToNode(object obj, YamlObjectSerializer objectSerializer)
 {
     return(base.TypeToNode(obj, objectSerializer));
 }
Exemplo n.º 15
0
 public abstract YamlNode TypeToNode(object obj, YamlObjectSerializer serializer);
Exemplo n.º 16
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var color = (Color)obj;

                return(new YamlScalarNode(color.ToHex()));
            }
Exemplo n.º 17
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var val = ((Angle)obj).Theta;

                return(new YamlScalarNode($"{val.ToString(CultureInfo.InvariantCulture)} rad"));
            }
Exemplo n.º 18
0
 public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(new GridId(node.AsInt()));
 }
Exemplo n.º 19
0
            public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
            {
                var box = (Box2)obj;

                return(new YamlScalarNode($"{box.Bottom.ToString(CultureInfo.InvariantCulture)},{box.Left.ToString(CultureInfo.InvariantCulture)},{box.Top.ToString(CultureInfo.InvariantCulture)},{box.Right.ToString(CultureInfo.InvariantCulture)}"));
            }
Exemplo n.º 20
0
 public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(node.AsVector2());
 }
Exemplo n.º 21
0
 public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(node.AsResourcePath());
 }
Exemplo n.º 22
0
        public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
        {
            var t = (T)obj;

            return(serializer.TypeToNode(_formatter.ToCustomFormat(t)));
        }
Exemplo n.º 23
0
 public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
 {
     return(new YamlScalarNode(obj.ToString()));
 }