Ejemplo n.º 1
0
        // These two variables were assigned but never used ...
        //private static string luaFileName = @"ll.txt";
        //private static bool isFirstRun = true;

        //write to a text file here.
        public static void log(string line)
        {
            if (!(System.IO.File.Exists(fullLuaPath)))
            {
                System.IO.Directory.CreateDirectory(luaDirectoryString);
                using (System.IO.StreamWriter sw = System.IO.File.CreateText(fullLuaPath))
                {
                    //only here to create the file and close the stream
                    //if it ain't broke don't fix it
                    GDLog.log("Creating path for lua logger");
                }
            }

            if (System.IO.File.Exists(fullLuaPath))
            {
                GDLog.log("System Path exists for Lua Logger");
                try
                {
                    //opens and automatically closes the file stream once the line is written
                    using (System.IO.StreamWriter fs = System.IO.File.AppendText(fullLuaPath))
                    {
                        fs.WriteLine(line);
                        GDLog.log("Supposedly I wrote a saved a lua command");
                    }
                }

                catch
                {
                    //writes error if log cannot open the file correctly
                    GDLog.log("ERROR: log did not write");
                }
            }
        }
Ejemplo n.º 2
0
 public static void read(Lua L)
 {
     using (System.IO.StreamReader sr = System.IO.File.OpenText(fullLuaPath))
     {
         string line;
         //while the reader is not at the end of text. load a lua line.
         while ((line = sr.ReadLine()) != null)
         {
             luaLines.Add(line);
             L.DoString(line);
             GDLog.log(line);
         }
     }
     luaLines.Clear();
     using (System.IO.StreamWriter sw = System.IO.File.CreateText(fullLuaPath))
     {
         //only here to create the file and close the stream
         //if it ain't broke don't fix it
         GDLog.log("Erasing path for lua logger");
     }
 }
Ejemplo n.º 3
0
    // Here is where we can present the console and handle input
    void OnGUI()
    {
        // button to toggle on/off the console
        if (GUI.Button(new Rect(0, 0, 110, 25), "Toggle Console"))
        {
            showConsole = !showConsole;
            GDLog.log("LuaConsole.cs: showConsole = " + showConsole.ToString());
        }

        if (showConsole)
        {
            toolbarInt = GUI.Toolbar(new Rect(0, 30, 230, 25), toolbarInt, toolbarStrings);

            bool timeToExecute = false;
            // Check to see if user has pressed the "return" key
            if (Event.current.Equals(Event.KeyboardEvent("return")))
            {
                timeToExecute = true;
            }

            float displayHeight = 0;             // height of display
            float scrollHeight  = 0;             // height of scrollbar

            // calculate height of display and scrollbar based on
            // how many commands have been entered
            if (textHeight < 170)
            {
                displayHeight = textHeight;
                scrollHeight  = 0;
            }
            else
            {
                displayHeight = 170;
                scrollHeight  = textHeight;
            }

            // Create display area with (or possibly without) scrollbar
            scrollPosition = GUI.BeginScrollView(new Rect(5, 60, 500, displayHeight), scrollPosition, new Rect(0, 0, 0, scrollHeight));
            GUI.TextArea(new Rect(0, 0, 500, textHeight), myDisplay);
            GUI.EndScrollView();

            // Create the console for entering in commands
            GUI.SetNextControlName("the_console");
            myConsole = GUI.TextField(new Rect(5, 60 + displayHeight, 500, 22), myConsole);

            // If nothing is typed in console, and console is out of focus,
            // display the default text
            if (UnityEngine.Event.current.type == EventType.Repaint)
            {
                if (GUI.GetNameOfFocusedControl() == "the_console")
                {
                    if (myConsole == myConsoleDefault)
                    {
                        myConsole = "";
                    }
                }
                else
                {
                    if (myConsole == "")
                    {
                        myConsole = myConsoleDefault;
                    }
                }
            }

            // Ensures commands are only executed when "enter" is pressed
            // and the user has focus on the console
            if (timeToExecute && GUI.GetNameOfFocusedControl() != "the_console")
            {
                timeToExecute = false;
            }

            switch (toolbarInt)
            {
            // Single mode
            case 0:
                // detect if we are now exiting Lua Script mode
                if (!newScript)
                {
                    myDisplay         += "\n" + "**********EXITED: LUA SCRIPT NOT SAVED***********";
                    myMultiLineCommand = "";
                    textHeight        += 15;
                    scrollPosition     = new Vector2(0, Mathf.Infinity);
                    newScript          = true;
                }

                if (timeToExecute)
                {
                    myDisplay += "\n" + myConsole;
                    if (!myLua.ExecuteCommand(myConsole))
                    {
                        myDisplay     += "\n" + "ERROR: INVALID COMMAND. REFER TO LOG FOR MORE DETAILS.";
                        textHeight    += 15;
                        scrollPosition = new Vector2(0, Mathf.Infinity);
                        myLua          = new LuaAPI();
                        myConsole      = "";
                    }
                    else
                    {
                        myConsole = "";
                    }
                    textHeight    += 15;
                    scrollPosition = new Vector2(0, Mathf.Infinity);
                }
                break;

            case 1:
                // detect if we are now exiting Lua Script mode
                if (!newScript)
                {
                    myDisplay += "\n" + "**********EXITED: LUA SCRIPT NOT SAVED***********";
                    GDLog.log("LuaConsole.cs: Lua Script Not Saved");
                    myMultiLineCommand = "";
                    textHeight        += 15;
                    scrollPosition     = new Vector2(0, Mathf.Infinity);
                    newScript          = true;
                }

                if (timeToExecute)
                {
                    myDisplay += "\n" + myConsole;
                    if (myConsole == "Execute()")
                    {
                        GDLog.log("LuaConsole.cs:" + myDisplay + " " + myConsole);
                        if (!myLua.ExecuteCommand(myMultiLineCommand))
                        {
                            myDisplay += "\n" + "ERROR: INVALID COMMAND. REFER TO LOG FOR MORE DETAILS.";

                            myLua = new LuaAPI();
                            GDLog.log("LuaConsole.cs: New Lua instance created");
                        }
                        else
                        {
                            myDisplay += "\n" + "Lua Command successfully executed!";

                            GDLog.log("LuaConsole.cs: Lua Command successfully executed.");
                        }
                        textHeight        += 15;
                        scrollPosition     = new Vector2(0, Mathf.Infinity);
                        myConsole          = "";
                        myMultiLineCommand = "";
                    }
                    else
                    {
                        if (myMultiLineCommand == "")
                        {
                            myMultiLineCommand = myConsole;
                        }
                        else
                        {
                            myMultiLineCommand += "\n" + myConsole;
                        }

                        myConsole = "";
                    }
                    textHeight    += 15;
                    scrollPosition = new Vector2(0, Mathf.Infinity);
                }
                break;

            case 2:
                if (newScript)
                {
                    myDisplay     += "\n" + "**********BEGIN WRITING LUA SCRIPT**********";
                    textHeight    += 15;
                    scrollPosition = new Vector2(0, Mathf.Infinity);
                    newScript      = false;
                    GDLog.log("LuaConsole.cs: New Lua script being created.");
                }

                if (GUI.Button(new Rect(300, 30, 150, 25), "Change Filename"))
                {
                    LS.changeFileName(myMultiLineCommand);
                    myDisplay  += "\n" + "**filename Changed**";
                    textHeight += 15;
                }

                if (GUI.Button(new Rect(455, 30, 50, 25), "Save"))
                {
                    try
                    {
                        LS.write(myMultiLineCommand);
                        myDisplay += "\n" + "**********SUCCESS: LUA SCRIPT SAVED**********";
                        GDLog.log("LuaConsole.cs: Lua Script Saved");
                    }
                    catch
                    {
                        myDisplay += "\n" + "**********ERROR: COULD NOT SAVE LUA SCRIPT***********";
                        GDLog.log("LuaConsole.cs: Lua script cannot be saved");
                        myLua = new LuaAPI();
                    }
                    finally
                    {
                        toolbarInt         = 0;                 // go back to single mode
                        myMultiLineCommand = "";
                        textHeight        += 15;
                        scrollPosition     = new Vector2(0, Mathf.Infinity);
                        newScript          = true;
                    }
                }
                if (timeToExecute)
                {
                    myDisplay += "\n" + myConsole;
                    if (myMultiLineCommand == "")
                    {
                        myMultiLineCommand = myConsole;
                    }
                    else
                    {
                        myMultiLineCommand += "\n" + myConsole;
                    }

                    myConsole      = "";
                    textHeight    += 15;
                    scrollPosition = new Vector2(0, Mathf.Infinity);
                }
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     // pass boat reference to Lua API
     myLua = new LuaAPI();
     GDLog.log("LuaConsole.cs: Lua instance created.");
 }