using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Halo3Map.Scripting
{
    public class Script
    {
        public ScriptHeader header;
        public SyntaxChunk firstChunk;
        public Syntax syntax;

        public int scriptChunkNumber;
        public string script;

        public ScriptsData sd;

        public void Decompile()
        {
            if (scriptChunkNumber < 0)
            {
                MessageBox.Show("Error!  Invalid Script chunk!");
                return;
            }
            if (header == null) //when decompiling from the list, headers are already there
            {
                header = new ScriptHeader(sd.scripts[scriptChunkNumber]);
            }
            syntax = new Syntax();
            syntax.chunks = new List<SyntaxChunk>();
            syntax.script = this;
            syntax.scriptText = header.text;
            firstChunk = new SyntaxChunk(ref sd, ref syntax, header.chunkNumber, " ");
            syntax.scriptText += "\r\n)";
            script = syntax.scriptText;
        }
    }

    public class ScriptHeader 
    {
        public string text;
        public string name;
        public ScriptType type;
        public ReturnType returnType;
        public int chunkNumber;

        public ScriptHeader(Scripts script)
        {
            name = script.Name.TrimEnd('\0');
            chunkNumber = script.ChunkNum;
            type = script.scriptType;
            returnType = script.returnType;

            text = "(script " + type.ToString() + " " + name;
        }
    }
}
