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

namespace HaloObjects
{
    public class Unicode256 : MetaNode 
    {
        string Value = "", Name = "Unicode256";

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

        #region MetaNode Members

        public void Read(System.IO.BinaryReader br)
        {
            for (int i = 0; i < 128; i++)
            {
                Value += Convert.ToChar(br.ReadByte());
                br.BaseStream.Position++;
            }
        }

        public void Read(System.IO.BinaryReader br, int Magic)
        {
            for (int i = 0; i < 128; i++)
            {
                Value += Convert.ToChar(br.ReadByte());
                br.BaseStream.Position++;
            }
        }

        public void Write(System.IO.BinaryWriter bw)
        {
            for (int i = 0; i < 128; i++)
            {
                try { bw.Write((byte)Value[i]); }
                catch { bw.Write((byte)0); }
                bw.BaseStream.Position++;
            }
        }

        public object GetValue()
        {
            return Value;
        }

        public void SetValue(object Value)
        {
            this.Value = (string)Value;
        }

        public int GetSize()
        {
            return 256;
        }

        public void Compile(System.IO.BinaryWriter bw, int Magic)
        {
            for (int i = 0; i < 128; i++)
            {
                try { bw.Write((byte)Value[i]); }
                catch { bw.Write((byte)0); }
                bw.BaseStream.Position++;
            }
        }

        public void Decompile(System.IO.BinaryWriter bw, int Magic)
        {
            for (int i = 0; i < 128; i++)
            {
                try { bw.Write((byte)Value[i]); }
                catch { bw.Write((byte)0); }
                bw.BaseStream.Position++;
            }
        }

        public string GetName()
        {
            return Name;
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            Unicode256 u = new Unicode256(this.Name);
            u.Value = Value;
            return u;
        }

        #endregion
    }
}
