From f82ea2cb51b50e94ab5adfde078214a16baa92ea Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 8 Feb 2022 21:01:57 +1100 Subject: [PATCH] Compiling now includes source filenames at end in success message (thanks Venk) --- MCGalaxy/Commands/Scripting/CmdCmdCreate.cs | 2 +- MCGalaxy/Commands/Scripting/CmdCompile.cs | 2 +- MCGalaxy/Commands/Scripting/CmdPlugin.cs | 4 ++-- MCGalaxy/Scripting/Scripting.cs | 15 +-------------- MCGalaxy/Scripting/ScriptingOperations.cs | 18 +++++++++++++++++- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs b/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs index edbf748dc..83d891204 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Scripting { if (!Formatter.ValidFilename(p, args[0])) return; string language = args.Length > 1 ? args[1] : ""; - ICompiler engine = ICompiler.Lookup(language, p); + ICompiler engine = ScriptingOperations.GetCompiler(p, language); if (engine == null) return; string path = engine.CommandPath(args[0]); diff --git a/MCGalaxy/Commands/Scripting/CmdCompile.cs b/MCGalaxy/Commands/Scripting/CmdCompile.cs index c263fc24d..9408b7bb3 100644 --- a/MCGalaxy/Commands/Scripting/CmdCompile.cs +++ b/MCGalaxy/Commands/Scripting/CmdCompile.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Scripting { if (!Formatter.ValidFilename(p, args[0])) return; string language = args.Length > 1 ? args[1] : ""; - ICompiler compiler = ICompiler.Lookup(language, p); + ICompiler compiler = ScriptingOperations.GetCompiler(p, language); if (compiler == null) return; // either "source" or "source1,source2,source3" diff --git a/MCGalaxy/Commands/Scripting/CmdPlugin.cs b/MCGalaxy/Commands/Scripting/CmdPlugin.cs index 08c1b8ea8..84d5dbc55 100644 --- a/MCGalaxy/Commands/Scripting/CmdPlugin.cs +++ b/MCGalaxy/Commands/Scripting/CmdPlugin.cs @@ -61,7 +61,7 @@ namespace MCGalaxy.Commands.Scripting { } static void CompilePlugin(Player p, string name, string language) { - ICompiler compiler = ICompiler.Lookup(language, p); + ICompiler compiler = ScriptingOperations.GetCompiler(p, language); if (compiler == null) return; // either "source" or "source1,source2,source3" @@ -110,7 +110,7 @@ namespace MCGalaxy.Commands.Scripting { } static void CreatePlugin(Player p, string name, string language) { - ICompiler engine = ICompiler.Lookup(language, p); + ICompiler engine = ScriptingOperations.GetCompiler(p, language); if (engine == null) return; string path = engine.PluginPath(name); diff --git a/MCGalaxy/Scripting/Scripting.cs b/MCGalaxy/Scripting/Scripting.cs index f08566c25..5bb75baf9 100644 --- a/MCGalaxy/Scripting/Scripting.cs +++ b/MCGalaxy/Scripting/Scripting.cs @@ -200,20 +200,7 @@ namespace MCGalaxy.Scripting public static ICompiler VB = new VBCompiler(); public static List Compilers = new List() { CS, VB }; - - - public static ICompiler Lookup(string name, Player p) { - if (name.Length == 0) return Compilers[0]; - - foreach (ICompiler comp in Compilers) { - if (comp.ShortName.CaselessEq(name)) return comp; - } - - p.Message("&WUnknown language \"{0}\"", name); - p.Message("&HAvailable languages: &f{0}", - Compilers.Join(c => c.ShortName + " (" + c.FullName + ")")); - return null; - } + static string FormatSource(string source, params string[] args) { // Always use \r\n line endings so it looks correct in Notepad diff --git a/MCGalaxy/Scripting/ScriptingOperations.cs b/MCGalaxy/Scripting/ScriptingOperations.cs index 30b5cd3f3..928511409 100644 --- a/MCGalaxy/Scripting/ScriptingOperations.cs +++ b/MCGalaxy/Scripting/ScriptingOperations.cs @@ -28,6 +28,21 @@ namespace MCGalaxy.Scripting { public static class ScriptingOperations { + public static ICompiler GetCompiler(Player p, string name) { + if (name.Length == 0) return ICompiler.Compilers[0]; + + foreach (ICompiler comp in ICompiler.Compilers) + { + if (comp.ShortName.CaselessEq(name)) return comp; + } + + p.Message("&WUnknown language \"{0}\"", name); + p.Message("&HAvailable languages: &f{0}", + ICompiler.Compilers.Join(c => c.ShortName + " (" + c.FullName + ")")); + return null; + } + + const int MAX_LOG = 2; /// Attempts to compile the given source code files into a .dll @@ -48,7 +63,8 @@ namespace MCGalaxy.Scripting CompilerResults results = compiler.Compile(srcs, dst); if (!results.Errors.HasErrors) { - p.Message("{0} compiled successfully.", type); + p.Message("{0} compiled successfully from {1}", + type, srcs.Join(file => Path.GetFileName(file))); return results; }