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

namespace HaloPlugins
{
    public class ColorRgb : IMetaNode
    {
        byte r = 0, g = 0, b = 0;
        string Name = "ColorRgb";

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

        #region MetaNode Members

        public void Read(EndianReader br)
        {
            r = br.ReadByte();
            g = br.ReadByte();
            b = br.ReadByte();
            br.BaseStream.Position++;
        }

        public void Read(EndianReader br, int Magic)
        {
            r = br.ReadByte();
            g = br.ReadByte();
            b = br.ReadByte();
            br.BaseStream.Position++;
        }

        public void Write(EndianWriter bw)
        {
            bw.Write(new byte[] { r, g, b });
            bw.BaseStream.Position++;
        }

        public object GetValue()
        {
            return new object[] { r, g, b };
        }

        public void SetValue(object Value)
        {
            r = (byte)((object[])Value)[0];
            g = (byte)((object[])Value)[1];
            b = (byte)((object[])Value)[2];
        }

        public int GetSize()
        {
            return 4;
        }

        public void Compile(EndianWriter bw, int Magic)
        {
            bw.Write(new byte[] { r, g, b });
            bw.BaseStream.Position++;
        }

        public void Decompile(EndianWriter bw, int Magic)
        {
            bw.Write(new byte[] { r, g, b });
            bw.BaseStream.Position++;
        }

        public string GetName()
        {
            return Name;
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            ColorRgb c = new ColorRgb(this.Name);
            c.r = this.r;
            c.g = this.g;
            c.b = this.b;
            return c;
        }

        #endregion

        #region ToString

        public override string ToString()
        {
            return "ColorRgb: " + Name + ", R: " + r.ToString() + ", G: " + g.ToString() + ", B: " + b.ToString();
        }

        #endregion
    }
}
