Change dumper to dump to markdown-ish files

This commit is contained in:
Lucas Nicodemus 2022-10-18 23:11:38 -07:00
parent 78087d1dc9
commit fa9717debf
No known key found for this signature in database
4 changed files with 15 additions and 227 deletions

View file

@ -101,14 +101,14 @@ namespace TShockAPI.Configuration
var def = field.GetValue(defaults);
sb.AppendLine("{0} ".SFormat(name));
sb.AppendLine("Type: {0} ".SFormat(type));
sb.AppendLine("Description: {0} ".SFormat(desc));
sb.AppendLine("Default: \"{0}\" ".SFormat(def));
sb.AppendLine("## {0} ".SFormat(name));
sb.AppendLine("{0}".SFormat(desc));
sb.AppendLine("* *Field type*: `{0}`".SFormat(type));
sb.AppendLine("* *Default*: `{0}`".SFormat(def));
sb.AppendLine();
}
File.WriteAllText("ServerSideConfigDescriptions.txt", sb.ToString());
File.WriteAllText("docs/ssc-config.md", sb.ToString());
}
}
}

View file

@ -631,14 +631,14 @@ namespace TShockAPI.Configuration
var def = field.GetValue(defaults);
sb.AppendLine("{0} ".SFormat(name));
sb.AppendLine("Type: {0} ".SFormat(type));
sb.AppendLine("Description: {0} ".SFormat(desc));
sb.AppendLine("Default: \"{0}\" ".SFormat(def));
sb.AppendLine("## {0} ".SFormat(name));
sb.AppendLine("{0}".SFormat(desc));
sb.AppendLine("* **Field type**: `{0}`".SFormat(type));
sb.AppendLine("* **Default**: `{0}`".SFormat(def));
sb.AppendLine();
}
File.WriteAllText("ConfigDescriptions.txt", sb.ToString());
File.WriteAllText("docs/config-file-descriptions.md", sb.ToString());
}
}
}

View file

@ -537,15 +537,15 @@ namespace TShockAPI
var strs =
commands.Select(
c =>
c.Name + (c.Names.Count > 1 ? "({0})".SFormat(string.Join(" ", c.Names.ToArray(), 1, c.Names.Count - 1)) : ""));
c.Name + (c.Names.Count > 1 ? " ({0})".SFormat(string.Join(" ", c.Names.ToArray(), 1, c.Names.Count - 1)) : ""));
sb.AppendLine("{0}".SFormat(name));
sb.AppendLine("Description: {0} ".SFormat(desc));
sb.AppendLine("Commands: {0} ".SFormat(strs.Count() > 0 ? string.Join(" ", strs) : "None"));
sb.AppendLine("## {0}".SFormat(name));
sb.AppendLine("{0}".SFormat(desc));
sb.AppendLine("* **Commands**: `{0}`".SFormat(strs.Count() > 0 ? string.Join(", ", strs) : "None"));
sb.AppendLine();
}
File.WriteAllText("PermissionsDescriptions.txt", sb.ToString());
File.WriteAllText("docs/permission-descriptions.md", sb.ToString());
}
}
}

View file

@ -949,14 +949,6 @@ namespace TShockAPI
Permissions.DumpDescriptions();
Configuration.ServerSideConfig.DumpDescriptions();
RestManager.DumpDescriptions();
DumpBuffs("BuffList.txt");
DumpItems("Items-1_0.txt", 1, 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)
{
@ -1018,210 +1010,6 @@ namespace TShockAPI
File.WriteAllText(path, output.ToString());
}
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<object[]> elements = new List<object[]>();
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);
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());
}
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<object[]> elements = new List<object[]>();
for (int i = start; i < end; i++)
{
Item item = new Item();
item.SetDefaults(i);
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);
}
}
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]");
File.WriteAllText(path, buffer.ToString());
}
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\",");
List<object[]> elements = new List<object[]>();
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);
}
}
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]");
File.WriteAllText(path, buffer.ToString());
}
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\",");
List<object[]> elements = new List<object[]>();
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);
}
}
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]");
File.WriteAllText(path, buffer.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\",");
List<object[]> elements = new List<object[]>();
for (int i = 0; i < PrefixID.Count; i++)
{
string prefix = Lang.prefix[i].ToString();
if (!String.IsNullOrEmpty(prefix))
{
object[] element = new object[] {i, prefix};
elements.Add(element);
}
}
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]");
File.WriteAllText(path, buffer.ToString());
}
private void OutputElementsForDump(StringBuilder buffer, List<object[]> 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(",");
}
}
}
}
/// <summary>Starts an invasion on the server.</summary>
/// <param name="type">The invasion type id.</param>
internal void StartInvasion(int type)