From b7019b6166e4ce7042bd80b5f370e7959212a86a Mon Sep 17 00:00:00 2001 From: DogooFalchion Date: Tue, 25 Oct 2016 18:58:04 -0400 Subject: [PATCH] Add a few more dumps to TShock, to facilitate keeping the documentation up to date. --- TShockAPI/TShock.cs | 9 ++- TShockAPI/Utils.cs | 150 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 9e459ec2..5e9d5807 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -633,11 +633,18 @@ namespace TShockAPI break; } case "-dump": - { + { + Utils.PrepareLangForDump(); + Lang.setLang(true); ConfigFile.DumpDescriptions(); Permissions.DumpDescriptions(); ServerSideConfig.DumpDescriptions(); RestManager.DumpDescriptions(); + Utils.DumpBuffs("BuffList.txt"); + Utils.DumpItems("Items.txt"); + Utils.DumpNPCs("NPCs.txt"); + Utils.DumpProjectiles("Projectiles.txt"); + Utils.DumpPrefixes("Prefixes.txt"); Environment.Exit(1); break; } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index be20bf1e..a9c3ed45 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1166,5 +1166,155 @@ namespace TShockAPI return points; } + + 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("\t\"data\": {"); + buffer.AppendLine("\t\t\"h-0\":\"ID\","); + buffer.AppendLine("\t\t\"h-1\":\"Name\","); + buffer.AppendLine("\t\t\"h-2\":\"Description\","); + + var row = 0; + for(int i = 0; i < Main.maxBuffTypes; i++) + { + if (!String.IsNullOrEmpty(Main.buffName[i])) + { + if (row > 0) + buffer.AppendLine(","); + + buffer.AppendLine(String.Format("\t\t\"{0}-0\": \"{1}\",", row, i)); + buffer.AppendLine(String.Format("\t\t\"{0}-1\": \"{1}\",", row, Main.buffName[i])); + buffer.Append(String.Format("\t\t\"{0}-2\": \"{1}\"", row++, Main.buffTip[i])); + } + } + + buffer.AppendLine(); + buffer.AppendLine("\t}").AppendLine("}"); + + File.WriteAllText(path, buffer.ToString()); + } + + public void DumpItems(string path) + { + Main.player[Main.myPlayer] = new Player(); + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block: parameters]").AppendLine("{").AppendLine("\t\"data\": {"); + buffer.AppendLine("\t\t\"h-0\":\"ID\","); + buffer.AppendLine("\t\t\"h-1\":\"Name\","); + buffer.AppendLine("\t\t\"h-2\":\"Tooltip\","); + buffer.AppendLine("\t\t\"h-2\":\"Tooltip 2\","); + + var row = 0; + for (int i = -48; i < Main.maxItemTypes; i++) + { + Item item = new Item(); + item.netDefaults(i); + if (!String.IsNullOrEmpty(item.name)) + { + if (row > 0) + buffer.AppendLine(","); + + buffer.AppendLine(String.Format("\t\t\"{0}-0\": \"{1}\",", row, i)); + buffer.AppendLine(String.Format("\t\t\"{0}-1\": \"{1}\",", row, item.name)); + buffer.AppendLine(String.Format("\t\t\"{0}-1\": \"{1}\",", row, item.toolTip)); + buffer.Append(String.Format("\t\t\"{0}-1\": \"{1}\"", row++, item.toolTip2)); + } + } + buffer.AppendLine(); + buffer.AppendLine("\t}").AppendLine("}"); + + File.WriteAllText(path, buffer.ToString()); + } + + public void DumpNPCs(string path) + { + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block: parameters]").AppendLine("{").AppendLine("\t\"data\": {"); + buffer.AppendLine("\t\t\"h-0\":\"ID\","); + buffer.AppendLine("\t\t\"h-1\":\"Name\","); + buffer.AppendLine("\t\t\"h-2\":\"Display Name\","); + + var row = 0; + for (int i = -65; i < Main.maxNPCTypes; i++) + { + NPC npc = new NPC(); + npc.netDefaults(i); + if (!String.IsNullOrEmpty(npc.name)) + { + if (row > 0) + buffer.AppendLine(","); + + buffer.AppendLine(String.Format("\t\t\"{0}-0\": \"{1}\",", row, i)); + buffer.AppendLine(String.Format("\t\t\"{0}-1\": \"{1}\",", row, npc.name)); + buffer.Append(String.Format("\t\t\"{0}-1\": \"{1}\"", row++, npc.displayName)); + } + } + buffer.AppendLine(); + buffer.AppendLine("\t}").AppendLine("}"); + + File.WriteAllText(path, buffer.ToString()); + } + + public void DumpProjectiles(string path) + { + Main.rand = new Random(); + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block: parameters]").AppendLine("{").AppendLine("\t\"data\": {"); + buffer.AppendLine("\t\t\"h-0\":\"ID\","); + buffer.AppendLine("\t\t\"h-1\":\"Name\","); + + var row = 0; + for (int i = 0; i < Main.maxProjectileTypes; i++) + { + Projectile projectile = new Projectile(); + projectile.SetDefaults(i); + if (!String.IsNullOrEmpty(projectile.name)) + { + if (row > 0) + buffer.AppendLine(","); + + buffer.AppendLine(String.Format("\t\t\"{0}-0\": \"{1}\",", row, i)); + buffer.Append(String.Format("\t\t\"{0}-1\": \"{1}\"", row++, projectile.name)); + } + } + buffer.AppendLine(); + buffer.AppendLine("\t}").AppendLine("}"); + + File.WriteAllText(path, buffer.ToString()); + } + + public void DumpPrefixes(string path) + { + StringBuilder buffer = new StringBuilder(); + buffer.AppendLine("[block: parameters]").AppendLine("{").AppendLine("\t\"data\": {"); + buffer.AppendLine("\t\t\"h-0\":\"ID\","); + buffer.AppendLine("\t\t\"h-1\":\"Name\","); + + var row = 0; + for (int i = 0; i < Item.maxPrefixes; i++) + { + string prefix = Lang.prefix[i]; + + if (!String.IsNullOrEmpty(prefix)) + { + if (row > 0) + buffer.AppendLine(","); + + buffer.AppendLine(String.Format("\t\t\"{0}-0\": \"{1}\",", row, i)); + buffer.Append(String.Format("\t\t\"{0}-1\": \"{1}\"", row++, prefix)); + } + } + buffer.AppendLine(); + buffer.AppendLine("\t}").AppendLine("}"); + + File.WriteAllText(path, buffer.ToString()); + } } }