상속: Tag, ICollectionTag
예제 #1
0
    public override TagCollection ReadCollection(TagList owner)
    {
      TagCollection value;
      TagType listType;
      string listTypeName;

      listTypeName = _reader.GetAttribute("limitType");
      if (string.IsNullOrEmpty(listTypeName))
        throw new InvalidDataException("Missing limitType attribute, unable to determine list contents type.");

      listType = (TagType)Enum.Parse(typeof(TagType), listTypeName, true);
      owner.ListType = listType;
      value = new TagCollection(owner, listType);

      this.LoadChildren(value, NbtOptions.None, listType);

      return value;
    }
예제 #2
0
 public abstract TagCollection ReadCollection(TagList owner);
예제 #3
0
 TagCollection ITagReader.ReadCollection(TagList owner)
 {
   return this.ReadCollection(owner);
 }
예제 #4
0
    public override TagCollection ReadCollection(TagList owner)
    {
      TagCollection tags;
      int length;

      owner.ListType = (TagType)this.ReadByte();
      tags = new TagCollection(owner, owner.ListType);
      length = this.ReadInt();

      for (int i = 0; i < length; i++)
      {
        ITag tag;

        switch (owner.ListType)
        {
          case TagType.Byte:
            tag = TagFactory.CreateTag(TagType.Byte, this.ReadByte());
            break;

          case TagType.ByteArray:
            tag = TagFactory.CreateTag(TagType.ByteArray, this.ReadByteArray());
            break;

          case TagType.Compound:
            tag = TagFactory.CreateTag(TagType.Compound);
            tag.Value = this.ReadDictionary((TagCompound)tag);
            break;

          case TagType.Double:
            tag = TagFactory.CreateTag(TagType.Double, this.ReadDouble());
            break;

          case TagType.End:
            tag = new TagEnd();
            break;

          case TagType.Float:
            tag = TagFactory.CreateTag(TagType.Float, this.ReadFloat());
            break;

          case TagType.Int:
            tag = TagFactory.CreateTag(TagType.Int, this.ReadInt());
            break;

          case TagType.IntArray:
            tag = TagFactory.CreateTag(TagType.IntArray, this.ReadIntArray());
            break;

          case TagType.List:
            tag = TagFactory.CreateTag(TagType.List);
            tag.Value = this.ReadCollection((TagList)tag);
            break;

          case TagType.Long:
            tag = TagFactory.CreateTag(TagType.Long, this.ReadLong());
            break;

          case TagType.Short:
            tag = TagFactory.CreateTag(TagType.Short, this.ReadShort());
            break;

          case TagType.String:
            tag = TagFactory.CreateTag(TagType.String, this.ReadString());
            break;

          default:
            throw new InvalidDataException("Invalid list type.");
        }

        tags.Add(tag);
      }

      return tags;
    }
예제 #5
0
        public static ITag CreateTag(TagType tagType, string name, object defaultValue)
        {
            ITag result;

              switch (tagType)
              {
            case TagType.Byte:
              result = new TagByte();
              break;

            case TagType.Short:
              result = new TagShort();
              break;

            case TagType.Int:
              result = new TagInt();
              break;

            case TagType.Long:
              result = new TagLong();
              break;

            case TagType.Float:
              result = new TagFloat();
              break;

            case TagType.Double:
              result = new TagDouble();
              break;

            case TagType.ByteArray:
              result = new TagByteArray();
              break;

            case TagType.String:
              result = new TagString();
              break;

            case TagType.List:
              result = new TagList();
              break;

            case TagType.Compound:
              result = new TagCompound();
              break;

            case TagType.IntArray:
              result = new TagIntArray();
              break;

            case TagType.End:
              result = new TagEnd();
              break;

            default:
              throw new ArgumentException(string.Format("Unrecognized tag type: {0}", tagType));
              }

              result.Name = name;
              if (defaultValue != null)
              {
            result.Value = defaultValue;
              }

              return result;
        }
예제 #6
0
        /// <summary>
        /// Creates a tag for the specified parameters.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown if <paramref name="tagType"/> is not valid.</exception>
        /// <param name="tagType">Type of the tag to create.</param>
        /// <param name="name">The name of the tag create.</param>
        /// <param name="listType">The type of items a list holds.</param>
        /// <returns>
        /// A new tag using the specified parameters.
        /// </returns>
        public static Tag CreateTag(string name, TagType tagType, TagType listType)
        {
            Tag result;

            if (tagType != TagType.List)
            {
                if (listType != TagType.None)
                {
                    throw new ArgumentException("Only lists can have a list type.", nameof(listType));
                }

                switch (tagType)
                {
                case TagType.Byte:
                    result = new TagByte(name);
                    break;

                case TagType.Short:
                    result = new TagShort(name);
                    break;

                case TagType.Int:
                    result = new TagInt(name);
                    break;

                case TagType.Long:
                    result = new TagLong(name);
                    break;

                case TagType.Float:
                    result = new TagFloat(name);
                    break;

                case TagType.Double:
                    result = new TagDouble(name);
                    break;

                case TagType.ByteArray:
                    result = new TagByteArray(name);
                    break;

                case TagType.String:
                    result = new TagString(name);
                    break;

                case TagType.Compound:
                    result = new TagCompound(name);
                    break;

                case TagType.IntArray:
                    result = new TagIntArray(name);
                    break;

                case TagType.End:
                    result = new TagEnd();
                    break;

                default:
                    throw new ArgumentException("Unrecognized or unsupported tag type.", nameof(tagType));
                }
            }
            else
            {
                result = new TagList(name, listType);
            }

            return(result);
        }