示例#1
0
        public static TagCompound ParseCompound(JsonReader reader, string rootName = "")
        {
            TagCompound res = new TagCompound(rootName);
            string tagName = null;
            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    tagName = reader.Value as string;
                }

                if (reader.TokenType == JsonToken.Boolean)
                {
                    bool b = (bool)reader.Value;
                    TagByte tag = new TagByte(tagName, b);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    long l = (long)reader.Value;
                    TagLong tag = new TagLong(tagName, l);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    double d = (double)reader.Value;
                    TagDouble tag = new TagDouble(tagName, d);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    string s = reader.Value as string;
                    TagString tag = new TagString(tagName, s);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    TagCompound tag = ParseCompound(reader);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    TagList list = ParseList(reader, tagName);
                    res.Set(list);
                }
                else if (reader.TokenType == JsonToken.EndObject)
                {
                    return res;
                }
            }

            return res;
        }
示例#2
0
    public void ConstructorWithValueTest()
    {
      // arrange
      TagByte tag;
      byte value;

      value = byte.MaxValue;

      // act
      tag = new TagByte(value);

      // assert
      Assert.IsEmpty(tag.Name);
      Assert.AreEqual(value, tag.Value);
    }
示例#3
0
    public void ConstructorTest()
    {
      // arrange
      TagByte tag;
      byte expected;

      expected = 0;

      // act
      tag = new TagByte();

      // assert
      Assert.IsEmpty(tag.Name);
      Assert.AreEqual(expected, tag.Value);
    }
示例#4
0
    public void ConstructorWithNameTest()
    {
      // arrange
      TagByte tag;
      string name;
      byte expected;

      name = "creationDate";
      expected = 0;

      // act
      tag = new TagByte(name);

      // assert
      Assert.AreEqual(name, tag.Name);
      Assert.AreEqual(expected, tag.Value);
    }
示例#5
0
    public void ConstructorWithNameAndValueTest()
    {
      // arrange
      TagByte tag;
      string name;
      byte value;

      name = "creationDate";
      value = byte.MaxValue;

      // act
      tag = new TagByte(name, value);

      // assert
      Assert.AreEqual(name, tag.Name);
      Assert.AreEqual(value, tag.Value);
    }
示例#6
0
        public Tag ExportTag()
        {
            tc ["SleepTimer"] = new TagShort(SleepTimer);

            TagList<TagDouble > motion = new TagList<TagDouble>();
            motion [0] = new TagDouble(Motion [0]);
            motion [1] = new TagDouble(Motion [1]);
            motion [2] = new TagDouble(Motion [2]);
            tc ["Motion"] = motion;
            tc ["OnGround"] = new TagByte(){Byte = OnGround};
            tc ["HurtTime"] = new TagShort(HurtTime);
            tc ["Health"] = new TagShort(Health);

            tc ["Dimension"] = new TagInt(Dimension);
            tc ["Air"] = new TagShort(Air);
			
            if (tc ["Inventory"] is TagList<TagCompound> == false)
            {
                tc ["Inventory"] = new TagList<TagCompound>();
            }
            TagList<TagCompound > inv = tc ["Inventory"] as TagList<TagCompound>;
			
            for (byte n = 0; n < 104; n++)
            {
                SlotItem item = null;
                if (n < 36)
                    item = Inventory [n];
                if (n >= 80 && n < 84)
                    item = InventoryCraft [n - 80];
                if (n >= 100)
                    item = InventoryWear [n - 100];

                TagCompound ti = null;
				
                //Find slot item
                foreach (TagCompound itc in inv)
                {
                    if (itc ["Slot"].Byte == n)
                    {
                        ti = itc;
                        break;
                    }
                }
				
                if (item == null)
                {
                    if (ti != null)
                        inv.Remove(ti);
                    continue;
                }
                if (ti == null)
                {
                    ti = new TagCompound();
                    inv.Add(ti);
                }
				
                ti ["id"] = new TagShort((short)item.ItemID);
                ti ["Damage"] = new TagShort((short)item.Uses);
                ti ["Count"] = new TagByte((byte)item.Count);
                ti ["Slot"] = new TagByte(n);
            }
            inv.Sort((x, y) => x ["Slot"].Byte - y ["Slot"].Byte);

            TagList<TagDouble > p = new TagList<TagDouble>();
            p [0] = new TagDouble(Pos .X);
            p [1] = new TagDouble(Pos .Y);
            p [2] = new TagDouble(Pos .Z);
            tc ["Pos"] = p;
            tc ["AttackTime"] = new TagShort(AttackTime);
            tc ["Sleeping"] = new TagByte(Sleeping);
            tc ["Fire"] = new TagShort(Fire);
            tc ["FallDistance"] = new TagFloat(FallDistance);
            TagList<TagFloat > rot = new TagList<TagFloat>();
            rot [0] = new  TagFloat(Rotation [0]);
            rot [1] = new  TagFloat(Rotation [1]);
            tc ["Rotation"] = rot;
            tc ["DeathTime"] = new TagShort(DeathTime);

            if (Spawn != null)
            {
                tc ["SpawnX"] = new TagInt(Spawn.X);
                tc ["SpawnY"] = new TagInt(Spawn.Y);
                tc ["SpawnZ"] = new TagInt(Spawn.Z);
            }
			
            tc ["foodExhaustionLevel"] = new TagFloat(foodExhaustionLevel);
            tc ["foodTickTimer"] = new TagInt(foodTickTimer);
            tc ["foodSaturationLevel"] = new TagFloat(foodSaturationLevel);
            tc ["foodLevel"] = new TagInt(foodLevel);
            tc ["XpLevel"] = new TagInt(XpLevel);
            tc ["XpTotal"] = new TagInt(XpTotal);
            tc ["Xp"] = new TagInt(Xp);
            tc ["playerGameType"] = new TagInt(playerGameType);
			
            return tc;
        }
示例#7
0
        public static TagList ParseList(JsonReader reader, string rootName)
        {
            TagList list = new TagList(rootName);
            bool foundGeneric = false;
            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.Boolean)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Byte;
                    }

                    bool b = (bool)reader.Value;
                    TagByte tag = new TagByte(null, b);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Long;
                    }

                    long l = (long)reader.Value;
                    TagLong tag = new TagLong(null, l);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Float;
                    }
                    else if (list.GenericType == ETagType.Long)
                    {
                        List<TagDouble> buf = new List<TagDouble>();
                        foreach (TagLong tl in list)
                        {
                            buf.Add(new TagDouble(tl.Name, tl.Value));
                        }
                        list.Clear();
                        list.GenericType = ETagType.Double;
                        foreach (TagDouble td in buf)
                        {
                            list.Add(td);
                        }
                    }

                    double d = (double)reader.Value;
                    TagDouble tag = new TagDouble(null, d);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.String;
                    }

                    string s = reader.Value as string;
                    TagString tag = new TagString(null, s);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Compound;
                    }

                    TagCompound tag = ParseCompound(reader, null);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.List;
                    }

                    TagList inner = ParseList(reader, null);
                    list.Add(inner);
                }
                else if (reader.TokenType == JsonToken.EndArray)
                {
                    return list;
                }
                else
                {
                    throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString());
                }
            }

            return list;
        }
示例#8
0
    public void NameTest()
    {
      // arrange
      TagByte target;
      string expected;

      target = new TagByte();
      expected = "newvalue";

      // act
      target.Name = expected;

      // assert
      Assert.AreEqual(expected, target.Name);
    }
示例#9
0
    public void ValueTest()
    {
      // arrange
      TagByte target;
      byte expected;

      target = new TagByte();
      expected = byte.MaxValue;

      // act
      target.Value = expected;

      // assert
      Assert.AreEqual(expected, target.Value);
    }
示例#10
0
    public void TypeTest()
    {
      // arrange
      TagType expected;
      TagType actual;

      expected = TagType.Byte;

      // act
      actual = new TagByte().Type;

      // assert
      Assert.AreEqual(expected, actual);
    }
示例#11
0
    public void ToValueStringTest()
    {
      // arrange
      ITag target;
      string expected;
      string actual;
      byte value;

      value = byte.MaxValue;
      expected = value.ToString(CultureInfo.InvariantCulture);
      target = new TagByte(value);

      // act
      actual = target.ToValueString();

      // assert
      Assert.AreEqual(expected, actual);
    }
示例#12
0
    public void ToStringWithIndentTest()
    {
      // arrange
      TagByte target;
      string expected;
      string actual;
      string name;
      byte value;
      string prefix;

      prefix = "test";
      name = "tagname";
      value = byte.MaxValue;
      expected = string.Format("{2}[Byte: {0}={1}]", name, value, prefix);
      target = new TagByte(name, value);

      // act
      actual = target.ToString(prefix);

      // assert
      Assert.AreEqual(expected, actual);
    }
示例#13
0
    public void ToStringTest()
    {
      // arrange
      TagByte target;
      string expected;
      string actual;
      string name;
      byte value;

      name = "tagname";
      value = byte.MaxValue;
      expected = string.Format("[Byte: {0}={1}]", name, value);
      target = new TagByte(name, value);

      // act
      actual = target.ToString();

      // assert
      Assert.AreEqual(expected, actual);
    }
示例#14
0
        public static TagList ParseList(JsonReader reader, string rootName)
        {
            TagList list         = new TagList(rootName);
            bool    foundGeneric = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.Boolean)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Byte;
                    }

                    bool    b   = (bool)reader.Value;
                    TagByte tag = new TagByte(null, b);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Long;
                    }

                    long    l   = (long)reader.Value;
                    TagLong tag = new TagLong(null, l);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Float;
                    }
                    else if (list.GenericType == ETagType.Long)
                    {
                        List <TagDouble> buf = new List <TagDouble>();
                        foreach (TagLong tl in list)
                        {
                            buf.Add(new TagDouble(tl.Name, tl.Value));
                        }
                        list.Clear();
                        list.GenericType = ETagType.Double;
                        foreach (TagDouble td in buf)
                        {
                            list.Add(td);
                        }
                    }

                    double    d   = (double)reader.Value;
                    TagDouble tag = new TagDouble(null, d);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.String;
                    }

                    string    s   = reader.Value as string;
                    TagString tag = new TagString(null, s);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Compound;
                    }

                    TagCompound tag = ParseCompound(reader, null);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.List;
                    }

                    TagList inner = ParseList(reader, null);
                    list.Add(inner);
                }
                else if (reader.TokenType == JsonToken.EndArray)
                {
                    return(list);
                }
                else
                {
                    throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString());
                }
            }

            return(list);
        }