internal static string ToJson(TagBase tag, JsonOptions ops)
 {
     if (tag.TagType == TagType.Compound)
     {
         return(GetFromCompound((TagCompound)tag, ops));
     }
     else if (tag.TagType == TagType.List)
     {
         return(GetFromList((TagList)tag, ops));
     }
     return(string.Empty);
 }
        private static string GetFromList(TagList tag, JsonOptions ops)
        {
            StringBuilder sb    = new StringBuilder();
            int           index = 0;

            sb.Append('[');
            foreach (TagBase _tag in tag.Value)
            {
                sb.Append(GetJsonValue(_tag, ops));
                if (tag.Count - 1 != index)
                {
                    sb.Append(',');
                }
                index++;
            }
            sb.Append(']');
            return(sb.ToString());
        }
        private static string GetFromCompound(TagCompound tag, JsonOptions ops)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append('{');
            int index = 0;

            foreach (string key in tag.Keys)
            {
                sb.Append(ops.GetKeyText(key));
                sb.Append(GetJsonValue(tag[key], ops));

                if (tag.Count - 1 != index)
                {
                    sb.Append(',');
                }
                index++;
            }
            sb.Append('}');
            return(sb.ToString());
        }
 private static string GetJsonValue(TagBase tag, JsonOptions ops)
 {
     if (tag.TagType == TagType.Byte)
     {
         return(((TagByte)tag).Value + ops.GetDigit(TagType.Byte));
     }
     if (tag.TagType == TagType.Short)
     {
         return(((TagShort)tag).Value + ops.GetDigit(TagType.Short));
     }
     if (tag.TagType == TagType.Int)
     {
         return(((TagInt)tag).Value + ops.GetDigit(TagType.Int));
     }
     if (tag.TagType == TagType.Long)
     {
         return(((TagLong)tag).Value + ops.GetDigit(TagType.Long));
     }
     if (tag.TagType == TagType.Float)
     {
         return(((TagFloat)tag).Value + ops.GetDigit(TagType.Float));
     }
     if (tag.TagType == TagType.Double)
     {
         return(((TagDouble)tag).Value + ops.GetDigit(TagType.Double));
     }
     if (tag.TagType == TagType.String)
     {
         return(ops.Quotation + ops.EscapeString(((TagString)tag).Value, ops.Quotation) + ops.Quotation);
     }
     if (tag.TagType == TagType.ByteArray)
     {
         byte[]        ary = ((TagByteArray)tag).Value;
         StringBuilder sb  = new StringBuilder();
         sb.Append('[');
         for (int i = 0; i < ary.Length; i++)
         {
             sb.Append(ary[i]);
             sb.Append(ops.GetDigit(TagType.Byte));
             if (i != ary.Length - 1)
             {
                 sb.Append(',');
             }
         }
         sb.Append(']');
         return(sb.ToString());
     }
     if (tag.TagType == TagType.Compound)
     {
         return(GetFromCompound((TagCompound)tag, ops));
     }
     if (tag.TagType == TagType.List)
     {
         return(GetFromList((TagList)tag, ops));
     }
     if (tag.TagType == TagType.IntArray)
     {
         int[]         ary = ((TagIntArray)tag).Value;
         StringBuilder sb  = new StringBuilder();
         sb.Append('[');
         for (int i = 0; i < ary.Length; i++)
         {
             sb.Append(ary[i]);
             if (i != ary.Length - 1)
             {
                 sb.Append(',');
             }
         }
         sb.Append(']');
         return(sb.ToString());
     }
     return(string.Empty);
 }
Пример #5
0
 public static string ToJson(TagBase tag, JsonOptions ops)
 {
     return(NBTJsonSerializerFizzy.ToJson(tag, ops));
 }