From 19bf37de7642ae8cdefd8fc6b4fadac3ac96ea9b Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 26 Sep 2018 23:49:26 +0200 Subject: ported most code to WebApiProject everything except the user identification and file locations should be somewhat functional --- DSACore/Commands/Help.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 DSACore/Commands/Help.cs (limited to 'DSACore/Commands/Help.cs') diff --git a/DSACore/Commands/Help.cs b/DSACore/Commands/Help.cs new file mode 100644 index 0000000..1575b36 --- /dev/null +++ b/DSACore/Commands/Help.cs @@ -0,0 +1,76 @@ +using System.Linq; +using System.Threading.Tasks; +using DSACore.Auxiliary; + +namespace DSACore.Commands +{ + public class Help + { + static Help() + { + /*TextReader stream = new StreamReader(@"..\..\Help.json"); // Load command-description file + var reader = new JsonTextReader(stream); // create stream reader + + reader.Read(); // step into structure, until the array starts + reader.Read(); + reader.Read(); + + try + { + var test = new JsonSerializer().Deserialize>(reader); // Deserialize Data and create CommandInfo Struct + + Commands.AddRange(test); // Add new CommandInfos to List + } + catch (Exception e) + { + // ignored + }*/ + } + + //public static List Commands { get; } = new List(); + + + public static string Get_Specific_Help(string command) + { + // return command specific help + var com = DSACore.DSA_Game.Save.Properties.CommandInfos.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command + return com.GetDescription(); + } + + public static string Get_Generic_Help() + { + string res = ""; + foreach (var com in DSACore.DSA_Game.Save.Properties.CommandInfos) + { + int first_column_width = 8; + res += ("!" + com.Name + ": ").AddSpaces(first_column_width) + com.Brief; + + if (com.Description.Length > 1) + { + res += "\n" + "".AddSpaces(first_column_width) + "(\"!man " + com.Name + "\" gibt genauere Informationen)"; + } + + res += "\n\n"; + } + return res; + } + + public static string ShowHelp(params string[] commandList) + { + var command = ""; + if (commandList.Length > 0) { + command = commandList.Aggregate((s, c) => s + " " + c); + } + + if (command.Equals(string.Empty)) // return generic Help + { + string res = Get_Generic_Help(); + + return res; + } + + + return Get_Specific_Help(command); + } + } +} -- cgit v1.2.3-54-g00ecf