Exemplo n.º 1
0
 public static bool AsBool(this YamlNode node)
 {
     if (bool.TryParse(node.AsString(), out var result))
     {
         return(result);
     }
     throw new ArgumentException($"{node.AsString()} isn't a valid boolean value.");
 }
Exemplo n.º 2
0
            public override bool TryNodeToType(YamlNode node, Type type, out object obj)
            {
                if (type == typeof(GridId))
                {
                    if (node.AsString() == "null")
                    {
                        obj = GridId.Invalid;
                        return(true);
                    }

                    var val = node.AsInt();
                    if (val >= Grids.Count)
                    {
                        Logger.ErrorS("map", "Error in map file: found local grid ID '{0}' which does not exist.", val);
                    }
                    else
                    {
                        obj = Grids[val].Index;
                        return(true);
                    }
                }
                if (type == typeof(EntityUid))
                {
                    if (node.AsString() == "null")
                    {
                        obj = EntityUid.Invalid;
                        return(true);
                    }

                    var val = node.AsInt();
                    if (val >= Entities.Count)
                    {
                        Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.", val);
                    }
                    else
                    {
                        obj = UidEntityMap[val];
                        return(true);
                    }
                }
                if (typeof(IEntity).IsAssignableFrom(type))
                {
                    var val = node.AsInt();
                    if (val >= Entities.Count)
                    {
                        Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.", val);
                    }
                    else
                    {
                        obj = Entities[val];
                        return(true);
                    }
                }
                obj = null;
                return(false);
            }
Exemplo n.º 3
0
 public static Color AsColor(this YamlNode node, Color?fallback = null)
 {
     if (Color.TryFromName(node.AsString(), out var color))
     {
         return(color);
     }
     return(node.AsHexColor(fallback));
 }
Exemplo n.º 4
0
            public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
            {
                var nodeContents = node.AsString();

                if (nodeContents.EndsWith("rad"))
                {
                    return(new Angle(double.Parse(nodeContents.Substring(0, nodeContents.Length - 3), CultureInfo.InvariantCulture)));
                }
                return(Angle.FromDegrees(double.Parse(nodeContents, CultureInfo.InvariantCulture)));
            }
Exemplo n.º 5
0
        public static bool IsNull(this YamlNode node)
        {
            var value = node.AsString();

            switch (value)
            {
            case "null":
            case "Null":
            case "NULL":
            case "~":
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 6
0
 public static T AsEnum <T>(this YamlNode node)
 {
     return((T)Enum.Parse(typeof(T), node.AsString(), true));
 }
Exemplo n.º 7
0
 public static Color AsHexColor(this YamlNode node, Color4?fallback = null)
 {
     return(Color.FromHex(node.AsString(), fallback));
 }
Exemplo n.º 8
0
            public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
            {
                var seconds = double.Parse(node.AsString(), CultureInfo.InvariantCulture);

                return(TimeSpan.FromSeconds(seconds));
            }
Exemplo n.º 9
0
 public override object NodeToType(Type type, YamlNode node)
 {
     return(Color.FromHex(node.AsString()));
 }
Exemplo n.º 10
0
 public static bool AsBool(this YamlNode node)
 {
     return(bool.Parse(node.AsString()));
 }
Exemplo n.º 11
0
 public static float AsFloat(this YamlNode node)
 {
     return(float.Parse(node.AsString(), CultureInfo.InvariantCulture));
 }
Exemplo n.º 12
0
 public static int AsInt(this YamlNode node)
 {
     return(int.Parse(node.AsString(), CultureInfo.InvariantCulture));
 }
Exemplo n.º 13
0
 public static Color AsColor(this YamlNode node)
 {
     return(ColorTranslator.FromHtml(node.AsString()));
 }