void RunCommandLine() { var commandLine = commandHistory[currentCommandHistoryIndex]; if (emptyCommandLineArea) { if (commandHistory.Last() != "") { commandHistory.Add(""); currentCommandHistoryIndex = commandHistory.Count - 1; } else { currentCommandHistoryIndex = commandHistory.Count - 1; } } emptyCommandLineArea = true; var source = String.Format(defaultSource, commandLine); var file = new ScriptEditorFile() { path = "ModToolsCommandLineScript.cs", source = source }; string errorMessage; IModEntryPoint instance; if (!ScriptCompiler.RunSource(new List <ScriptEditorFile>() { file }, out errorMessage, out instance)) { Log.Error("Failed to compile command-line!"); } else { if (instance != null) { Log.Message("Executing command-line.."); instance.OnModLoaded(); } else { Log.Error("Error executing command-line.."); } } commandLine = ""; focusCommandLineArea = true; }
void DrawFooter() { footerArea.Begin(); GUILayout.BeginHorizontal(); if (currentMod != null) { GUI.enabled = false; } if (GUILayout.Button("Compile")) { string dllPath; if (ScriptCompiler.CompileSource(projectFiles, out dllPath)) { Log.Message("Source compiled to \"" + dllPath + "\""); } else { Log.Error("Failed to compile script!"); } } if (GUILayout.Button("Run")) { string errorMessage; if (ScriptCompiler.RunSource(projectFiles, out errorMessage, out currentMod)) { Log.Message("Running IModEntryPoint.OnModLoaded()"); try { currentMod.OnModLoaded(); } catch (Exception ex) { Log.Error($"Exception while calling IModEntryPoint.OnModLoaded() - {ex.Message}"); } } else { lastError = errorMessage; Log.Error("Failed to compile or run source, reason: " + errorMessage); } } GUI.enabled = false; if (currentMod != null) { GUI.enabled = true; } if (GUILayout.Button("Stop")) { Log.Message("Running IModEntryPoint.OnModUnloaded()"); try { currentMod.OnModUnloaded(); } catch (Exception ex) { Log.Error($"Exception while calling IModEntryPoint.OnModUnloaded() - {ex.Message}"); } currentMod = null; } GUI.enabled = true; GUILayout.Label("Last error: " + lastError); GUILayout.FlexibleSpace(); if (currentFile == null) { GUI.enabled = false; } if (GUILayout.Button("Save")) { try { SaveProjectFile(currentFile); } catch (Exception ex) { lastError = ex.Message; return; } lastError = ""; } GUI.enabled = true; if (GUILayout.Button("Save all")) { SaveAllProjectFiles(); } GUILayout.EndHorizontal(); footerArea.End(); }