using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Halo3Map.IO;

namespace Cartographer.Scripts
{
    public class ScriptStrings
    {
        public static string strings;
        //public static EndianReader er;
        public static void Load(EndianReader br, int size)
        {
            strings = Encoding.UTF8.GetString(br.ReadBytes(size));
            //er = new EndianReader(new MemoryStream(br.ReadBytes(size)));
        }
    }

    public class ScriptString
    {
        public string text;
        public int offset;
        public int mapNumber;

        public ScriptString(int pos)
        {

            offset = pos;
            string table = ScriptStrings.strings;
            int end = table.IndexOf('\xCD') >= 0 ? table.IndexOf('\xCD') : table.Length;
            if (pos > end || pos < 0)
            {
                pos = -1;
                text = "INVALID";
                return;
            }
            table = table.Substring(pos);
            if (table.Contains("\0"))
                table = table.Remove(table.IndexOf('\0'));
            else
                table = "INVALID";
            text = table;

            //text = ScriptStrings.GetString(pos);
        }

        public ScriptString(string str)
        {
            text = str;
            string table = "";// ScriptStrings.strings;
            offset = table.IndexOf(str + '\0');
            if (offset < 0)
            {
                //Add it
            }
        }
    }
}
