diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index a019b8bc..873254ce 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1166,237 +1166,240 @@ namespace TShockAPI return points; } - // /// - // /// Dumps information and optionally exits afterwards - // /// - // /// - // public void Dump(bool exit = true) - // { - // PrepareLangForDump(); - // Lang.setLang(true); - // ConfigFile.DumpDescriptions(); - // Permissions.DumpDescriptions(); - // ServerSideCharacters.ServerSideConfig.DumpDescriptions(); - // RestManager.DumpDescriptions(); - // DumpBuffs("BuffList.txt"); - // DumpItems("Items-1_0.txt", -48, 235); - // DumpItems("Items-1_1.txt", 235, 604); - // DumpItems("Items-1_2.txt", 604, 2749); - // DumpItems("Items-1_3.txt", 2749, Main.maxItemTypes); - // DumpNPCs("NPCs.txt"); - // DumpProjectiles("Projectiles.txt"); - // DumpPrefixes("Prefixes.txt"); - // if (exit) - // { - // Environment.Exit(1); - // } - // } + /// + /// Dumps information and optionally exits afterwards + /// + /// + public void Dump(bool exit = true) + { + PrepareLangForDump(); + // Lang.setLang(true); + ConfigFile.DumpDescriptions(); + Permissions.DumpDescriptions(); + ServerSideCharacters.ServerSideConfig.DumpDescriptions(); + RestManager.DumpDescriptions(); + DumpBuffs("BuffList.txt"); + DumpItems("Items-1_0.txt", -48, 235); + DumpItems("Items-1_1.txt", 235, 604); + DumpItems("Items-1_2.txt", 604, 2749); + DumpItems("Items-1_3.txt", 2749, Main.maxItemTypes); + DumpNPCs("NPCs.txt"); + DumpProjectiles("Projectiles.txt"); + DumpPrefixes("Prefixes.txt"); + if (exit) + { + Environment.Exit(1); + } + } - // internal void PrepareLangForDump() - // { - // for(int i = 0; i < Main.recipe.Length; i++) - // Main.recipe[i] = new Recipe(); - // } + internal void PrepareLangForDump() + { + for(int i = 0; i < Main.recipe.Length; i++) + Main.recipe[i] = new Recipe(); + } - // public void DumpBuffs(string path) - // { - // StringBuilder buffer = new StringBuilder(); - // buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); - // buffer.AppendLine(" \"h-0\": \"ID\","); - // buffer.AppendLine(" \"h-1\": \"Name\","); - // buffer.AppendLine(" \"h-2\": \"Description\","); + public void DumpBuffs(string path) + { + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); + buffer.AppendLine(" \"h-0\": \"ID\","); + buffer.AppendLine(" \"h-1\": \"Name\","); + buffer.AppendLine(" \"h-2\": \"Description\","); - // List elements = new List(); - // for (int i = 0; i < Main.maxBuffTypes; i++) - // { - // if (!String.IsNullOrEmpty(Lang.GetBuffName(i))) - // { - // object[] element = new object[] { i, Lang.GetBuffName(i), Main.buffTip[i] }; - // elements.Add(element); - // } - // } + List elements = new List(); + for (int i = 0; i < Main.maxBuffTypes; i++) + { + if (!String.IsNullOrEmpty(Lang.GetBuffName(i))) + { + object[] element = new object[] { i, Lang.GetBuffName(i), Lang.GetBuffDescription(i) }; + elements.Add(element); + } + } - // var rows = elements.Count; - // var columns = 0; - // if (rows > 0) - // { - // columns = elements[0].Length; - // } - // OutputElementsForDump(buffer, elements, rows, columns); + var rows = elements.Count; + var columns = 0; + if (rows > 0) + { + columns = elements[0].Length; + } + OutputElementsForDump(buffer, elements, rows, columns); - // buffer.AppendLine(); - // buffer.AppendLine(" },"); - // buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); - // buffer.AppendLine("}").Append("[/block]"); + buffer.AppendLine(); + buffer.AppendLine(" },"); + buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); + buffer.AppendLine("}").Append("[/block]"); - // File.WriteAllText(path, buffer.ToString()); - // } + File.WriteAllText(path, buffer.ToString()); + } - // public void DumpItems(string path, int start, int end) - // { - // Main.player[Main.myPlayer] = new Player(); - // StringBuilder buffer = new StringBuilder(); - // Regex newLine = new Regex(@"\n"); - // buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); - // buffer.AppendLine(" \"h-0\": \"ID\","); - // buffer.AppendLine(" \"h-1\": \"Name\","); - // buffer.AppendLine(" \"h-2\": \"Tooltip\","); - // buffer.AppendLine(" \"h-3\": \"Tooltip 2\","); + public void DumpItems(string path, int start, int end) + { + Main.player[Main.myPlayer] = new Player(); + StringBuilder buffer = new StringBuilder(); + Regex newLine = new Regex(@"\n"); + buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); + buffer.AppendLine(" \"h-0\": \"ID\","); + buffer.AppendLine(" \"h-1\": \"Name\","); + buffer.AppendLine(" \"h-2\": \"Tooltip\","); - // List elements = new List(); - // for (int i = start; i < end; i++) - // { - // Item item = new Item(); - // item.netDefaults(i); - // if (!String.IsNullOrEmpty(item.Name)) - // { - // object[] element = new object[] { i, - // newLine.Replace(item.Name, @" "), - // newLine.Replace(item.toolTip, @" "), - // newLine.Replace(item.toolTip2, @" ") - // }; - // elements.Add(element); - // } - // } + List elements = new List(); + for (int i = start; i < end; i++) + { + Item item = new Item(); + item.SetDefaults(i); - // var rows = elements.Count; - // var columns = 0; - // if (rows > 0) - // { - // columns = elements[0].Length; - // } - // OutputElementsForDump(buffer, elements, rows, columns); + string tt = ""; + for (int x = 0; x < item.ToolTip.Lines; x++) { + tt += item.ToolTip.GetLine(x) + "\n"; + } + if (!String.IsNullOrEmpty(item.Name)) + { + object[] element = new object[] { i, + newLine.Replace(item.Name, @" "), + newLine.Replace(tt, @" "), + }; + elements.Add(element); + } + } - // buffer.AppendLine(); - // buffer.AppendLine(" },"); - // buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); - // buffer.AppendLine("}").Append("[/block]"); + var rows = elements.Count; + var columns = 0; + if (rows > 0) + { + columns = elements[0].Length; + } + OutputElementsForDump(buffer, elements, rows, columns); - // File.WriteAllText(path, buffer.ToString()); - // } + buffer.AppendLine(); + buffer.AppendLine(" },"); + buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); + buffer.AppendLine("}").Append("[/block]"); - // public void DumpNPCs(string path) - // { - // StringBuilder buffer = new StringBuilder(); - // buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); - // buffer.AppendLine(" \"h-0\": \"ID\","); - // buffer.AppendLine(" \"h-1\": \"Name\","); - // buffer.AppendLine(" \"h-2\": \"Display Name\","); + File.WriteAllText(path, buffer.ToString()); + } - // List elements = new List(); - // for (int i = -65; i < Main.maxNPCTypes; i++) - // { - // NPC npc = new NPC(); - // npc.netDefaults(i); - // if (!String.IsNullOrEmpty(npc.FullName)) - // { - // object[] element = new object[] { i, npc.FullName, npc.displayName }; - // elements.Add(element); - // } - // } + public void DumpNPCs(string path) + { + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); + buffer.AppendLine(" \"h-0\": \"ID\","); + buffer.AppendLine(" \"h-1\": \"Full Name\","); + buffer.AppendLine(" \"h-2\": \"Type Name\","); - // var rows = elements.Count; - // var columns = 0; - // if (rows > 0) - // { - // columns = elements[0].Length; - // } - // OutputElementsForDump(buffer, elements, rows, columns); + List elements = new List(); + for (int i = -65; i < Main.maxNPCTypes; i++) + { + NPC npc = new NPC(); + npc.SetDefaults(i); + if (!String.IsNullOrEmpty(npc.FullName)) + { + object[] element = new object[] { i, npc.FullName, npc.TypeName }; + elements.Add(element); + } + } - // buffer.AppendLine(); - // buffer.AppendLine(" },"); - // buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); - // buffer.AppendLine("}").Append("[/block]"); + var rows = elements.Count; + var columns = 0; + if (rows > 0) + { + columns = elements[0].Length; + } + OutputElementsForDump(buffer, elements, rows, columns); - // File.WriteAllText(path, buffer.ToString()); - // } + buffer.AppendLine(); + buffer.AppendLine(" },"); + buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); + buffer.AppendLine("}").Append("[/block]"); - // public void DumpProjectiles(string path) - // { - // Main.rand = new UnifiedRandom(); - // StringBuilder buffer = new StringBuilder(); - // buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); - // buffer.AppendLine(" \"h-0\": \"ID\","); - // buffer.AppendLine(" \"h-1\": \"Name\","); + File.WriteAllText(path, buffer.ToString()); + } - // List elements = new List(); - // for (int i = 0; i < Main.maxProjectileTypes; i++) - // { - // Projectile projectile = new Projectile(); - // projectile.SetDefaults(i); - // if (!String.IsNullOrEmpty(projectile.Name)) - // { - // object[] element = new object[] { i, projectile.Name }; - // elements.Add(element); - // } - // } + public void DumpProjectiles(string path) + { + Main.rand = new UnifiedRandom(); + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); + buffer.AppendLine(" \"h-0\": \"ID\","); + buffer.AppendLine(" \"h-1\": \"Name\","); - // var rows = elements.Count; - // var columns = 0; - // if (rows > 0) - // { - // columns = elements[0].Length; - // } - // OutputElementsForDump(buffer, elements, rows, columns); + List elements = new List(); + for (int i = 0; i < Main.maxProjectileTypes; i++) + { + Projectile projectile = new Projectile(); + projectile.SetDefaults(i); + if (!String.IsNullOrEmpty(projectile.Name)) + { + object[] element = new object[] { i, projectile.Name }; + elements.Add(element); + } + } - // buffer.AppendLine(); - // buffer.AppendLine(" },"); - // buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); - // buffer.AppendLine("}").Append("[/block]"); + var rows = elements.Count; + var columns = 0; + if (rows > 0) + { + columns = elements[0].Length; + } + OutputElementsForDump(buffer, elements, rows, columns); - // File.WriteAllText(path, buffer.ToString()); - // } + buffer.AppendLine(); + buffer.AppendLine(" },"); + buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); + buffer.AppendLine("}").Append("[/block]"); - // public void DumpPrefixes(string path) - // { - // StringBuilder buffer = new StringBuilder(); - // buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); - // buffer.AppendLine(" \"h-0\": \"ID\","); - // buffer.AppendLine(" \"h-1\": \"Name\","); + File.WriteAllText(path, buffer.ToString()); + } - // List elements = new List(); - // for (int i = 0; i < Item.maxPrefixes; i++) - // { - // string prefix = Lang.prefix[i].ToString(); + public void DumpPrefixes(string path) + { + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block:parameters]").AppendLine("{").AppendLine(" \"data\": {"); + buffer.AppendLine(" \"h-0\": \"ID\","); + buffer.AppendLine(" \"h-1\": \"Name\","); - // if (!String.IsNullOrEmpty(prefix)) - // { - // object[] element = new object[] {i, prefix}; - // elements.Add(element); - // } - // } + List elements = new List(); + for (int i = 0; i < PrefixID.Count; i++) + { + string prefix = Lang.prefix[i].ToString(); - // var rows = elements.Count; - // var columns = 0; - // if (rows > 0) - // { - // columns = elements[0].Length; - // } - // OutputElementsForDump(buffer, elements, rows, columns); + if (!String.IsNullOrEmpty(prefix)) + { + object[] element = new object[] {i, prefix}; + elements.Add(element); + } + } - // buffer.AppendLine(); - // buffer.AppendLine(" },"); - // buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); - // buffer.AppendLine("}").Append("[/block]"); + var rows = elements.Count; + var columns = 0; + if (rows > 0) + { + columns = elements[0].Length; + } + OutputElementsForDump(buffer, elements, rows, columns); - // File.WriteAllText(path, buffer.ToString()); - // } + buffer.AppendLine(); + buffer.AppendLine(" },"); + buffer.AppendLine(String.Format(" \"cols\": {0},", columns)).AppendLine(String.Format(" \"rows\": {0}", rows)); + buffer.AppendLine("}").Append("[/block]"); - // private void OutputElementsForDump(StringBuilder buffer, List elements, int rows, int columns) - // { - // if (rows > 0) - // { - // columns = elements[0].Length; - // for (int i = 0; i < columns; i++) - // { - // for (int j = 0; j < rows; j++) - // { - // buffer.Append(String.Format(" \"{0}-{1}\": \"{2}\"", j, i, elements[j][i])); - // if (j != rows - 1 || i != columns - 1) - // buffer.AppendLine(","); - // } - // } - // } - // } + File.WriteAllText(path, buffer.ToString()); + } + + private void OutputElementsForDump(StringBuilder buffer, List elements, int rows, int columns) + { + if (rows > 0) + { + columns = elements[0].Length; + for (int i = 0; i < columns; i++) + { + for (int j = 0; j < rows; j++) + { + buffer.Append(String.Format(" \"{0}-{1}\": \"{2}\"", j, i, elements[j][i])); + if (j != rows - 1 || i != columns - 1) + buffer.AppendLine(","); + } + } + } + } } }