Add personal info table dump

Make generic type editor dump out the derived class in the event the
array type is a base class
This commit is contained in:
Kurt
2018-11-21 10:13:23 -08:00
parent 09a4385842
commit 37286326f1
4 changed files with 45 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ public static class TableUtil
private const string sep = "\t";
private static IEnumerable<string> GetTableRaw<T>(IEnumerable<T> arr) => Table(arr).Select(row => string.Join(sep, row));
private static IEnumerable<string> GetTableRaw<T>(IEnumerable<T> arr, Type t) => Table(arr, t).Select(row => string.Join(sep, row));
public static string GetNamedTable<T>(IEnumerable<T> arr, IList<string> names, string name = null)
{
@@ -31,6 +32,21 @@ public static string GetNamedTable<T>(IEnumerable<T> arr, IList<string> names, s
return string.Join(Environment.NewLine, list);
}
public static string GetNamedTypeTable<T>(IList<T> arr, IList<string> names, string name = null)
{
var t = arr[0].GetType();
var list = GetTableRaw(arr, t).ToArray();
// slap in name to column header
list[0] = $"Index{sep}{name ?? t.Name}{sep}{list[0]}";
// slap in row name to row
for (int i = 1; i < list.Length; i++)
list[i] = $"{i - 1}{sep}{names[i - 1]}{sep}{list[i]}";
return string.Join(Environment.NewLine, list);
}
private static IEnumerable<IEnumerable<string>> Table<T>(IEnumerable<T> arr)
{
var type = typeof(T);
@@ -39,6 +55,13 @@ private static IEnumerable<IEnumerable<string>> Table<T>(IEnumerable<T> arr)
yield return GetValues(z, type);
}
private static IEnumerable<IEnumerable<string>> Table<T>(IEnumerable<T> arr, Type type)
{
yield return GetNames(type);
foreach (var z in arr)
yield return GetValues(z, type);
}
private static IEnumerable<string> GetNames(Type type)
{
foreach (var z in type.GetProperties())

View File

@@ -36,7 +36,7 @@ private void B_Save_Click(object sender, EventArgs e)
private void B_Dump_Click(object sender, EventArgs e)
{
var arr = Cache.LoadAll();
var result = TableUtil.GetNamedTable(arr, Names, Text.Split(' ')[0]);
var result = TableUtil.GetNamedTypeTable(arr, Names, Text.Split(' ')[0]);
Clipboard.SetText(result);
System.Media.SystemSounds.Asterisk.Play();
}

View File

@@ -121,6 +121,7 @@ private void InitializeComponent()
this.Tab_Extra = new System.Windows.Forms.TabPage();
this.CB_Species = new System.Windows.Forms.ComboBox();
this.PB_MonSprite = new System.Windows.Forms.PictureBox();
this.B_PDumpTable = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.Tab_Personal.SuspendLayout();
this.Tab_Learn.SuspendLayout();
@@ -155,6 +156,7 @@ private void InitializeComponent()
//
// Tab_Personal
//
this.Tab_Personal.Controls.Add(this.B_PDumpTable);
this.Tab_Personal.Controls.Add(this.L_GoID);
this.Tab_Personal.Controls.Add(this.MT_GoID);
this.Tab_Personal.Controls.Add(this.TB_RawColor);
@@ -1109,6 +1111,16 @@ private void InitializeComponent()
this.PB_MonSprite.TabIndex = 91;
this.PB_MonSprite.TabStop = false;
//
// B_PDumpTable
//
this.B_PDumpTable.Location = new System.Drawing.Point(451, 492);
this.B_PDumpTable.Name = "B_PDumpTable";
this.B_PDumpTable.Size = new System.Drawing.Size(75, 23);
this.B_PDumpTable.TabIndex = 502;
this.B_PDumpTable.Text = "Dump Table";
this.B_PDumpTable.UseVisualStyleBackColor = true;
this.B_PDumpTable.Click += new System.EventHandler(this.B_PDumpTable_Click);
//
// PokeDataUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1228,5 +1240,6 @@ private void InitializeComponent()
private System.Windows.Forms.CheckedListBox CLB_TM;
private System.Windows.Forms.PictureBox PB_MonSprite;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button B_PDumpTable;
}
}

View File

@@ -418,6 +418,14 @@ public void SaveMegas()
row.SaveEvolution();
}
private void B_PDumpTable_Click(object sender, EventArgs e)
{
var arr = Editor.Personal.Table;
var result = TableUtil.GetNamedTypeTable(arr, entryNames, "Species");
Clipboard.SetText(result);
System.Media.SystemSounds.Asterisk.Play();
}
private void B_Save_Click(object sender, EventArgs e)
{
Modified = true;