using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IO;

namespace HaloPlugins
{
    public class Rectangle2d : IMetaNode
    {
        short x = 0, y = 0, w = 0, h = 0;
        string Name = "Rectangle2d";

        public Rectangle2d(string Name)
        {
            this.Name = Name;
        }

        #region MetaNode Members

        public void Read(EndianReader br)
        {
            x = br.ReadInt16();
            y = br.ReadInt16();
            w = br.ReadInt16();
            h = br.ReadInt16();
        }

        public void Read(EndianReader br, int Magic)
        {
            x = br.ReadInt16();
            y = br.ReadInt16();
            w = br.ReadInt16();
            h = br.ReadInt16();
        }

        public void Write(EndianWriter bw)
        {
            bw.Write(x);
            bw.Write(y);
            bw.Write(w);
            bw.Write(h);
        }

        public object GetValue()
        {
            return new object[] { x, y, w, h };
        }

        public void SetValue(object Value)
        {
            x = (short)((object[])Value)[0];
            y = (short)((object[])Value)[1];
            w = (short)((object[])Value)[2];
            h = (short)((object[])Value)[3];
        }

        public int GetSize()
        {
            return 8;
        }

        public void Compile(EndianWriter bw, int Magic)
        {
            bw.Write(x);
            bw.Write(y);
            bw.Write(w);
            bw.Write(h);
        }

        public void Decompile(EndianWriter bw, int Magic)
        {
            bw.Write(x);
            bw.Write(y);
            bw.Write(w);
            bw.Write(h);
        }

        public string GetName()
        {
            return Name;
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            Rectangle2d r = new Rectangle2d(this.Name);
            r.x = this.x;
            r.y = this.y;
            r.w = this.w;
            r.h = this.h;
            return r;
        }

        #endregion

        #region ToString

        public override string ToString()
        {
            return "Rectangle2d: " + Name + ", X: " + x.ToString() + ", Y: " + y.ToString() + ", W: " + w.ToString() + ", H: " + h.ToString();
        }

        #endregion
    }
}
