uniniform anomaly table fix

This commit is contained in:
rfi
2023-10-18 21:45:13 +07:00
parent c00ea3bd2c
commit dfaca9d238
7 changed files with 177 additions and 44 deletions

View File

@@ -79,6 +79,7 @@ namespace AscNet.Table
string file = $@"// <auto-generated/>
namespace AscNet.Table{ns}
{{
#nullable enable
public class {Path.GetFileName(table.Path).Split('.').First()}Table
{{
{string.Join("\r\n\t\t", properties.Values)}
@@ -87,14 +88,34 @@ namespace AscNet.Table{ns}
public class {Path.GetFileName(table.Path).Split('.').First()}TableReader : global::AscNet.Common.Util.TableReader<{Path.GetFileName(table.Path).Split('.').First()}TableReader, {Path.GetFileName(table.Path).Split('.').First()}Table>
{{
protected override string FilePath {{ get {{ return ""{string.Join("", table.Path.Replace("\\", "/").Split(new string[] {"/Resources/"}, StringSplitOptions.None).Skip(1))}""; }} }}
protected override void Load()
public override void Load()
{{
string tsvStr = global::System.Text.Encoding.UTF8.GetString(global::System.IO.File.ReadAllBytes(FilePath).Skip(128).ToArray());
using var reader = new global::System.IO.StringReader(tsvStr.Replace(""\t"", "",""));
string[] tsvValues = tsvStr.Split('\t');
string[] csvValues = new string[tsvValues.Length];
for (int i = 0; i < tsvValues.Length; i++)
{{
if (tsvValues[i].Contains("",""))
{{
csvValues[i] = ""\"""" + tsvValues[i].Replace(""\"""", ""\""\"""") + ""\"""";
}}
else
{{
csvValues[i] = tsvValues[i];
}}
}}
using var reader = new global::System.IO.StringReader(string.Join("","", csvValues));
using var csv = new global::CsvHelper.CsvReader(reader, new global::CsvHelper.Configuration.CsvConfiguration(global::System.Globalization.CultureInfo.InvariantCulture) {{ BadDataFound = null, HeaderValidated = null, MissingFieldFound = null }});
csv.Context.RegisterClassMap<{Path.GetFileName(table.Path).Split('.').First()}TableMap>();
All = csv.GetRecords<{Path.GetFileName(table.Path).Split('.').First()}Table>().ToList();
}}
{string.Join("\r\n", properties.Values.Select(x => x.Split(' ')).Where(x => !x[1].Contains("<")).Select(property => $@"
public {Path.GetFileName(table.Path).Split('.').First()}Table? From{property[2]}({property[1]} val)
{{
return All.FirstOrDefault(x => x.{property[2]} == val);
}}
"))}
}}
public sealed class {Path.GetFileName(table.Path).Split('.').First()}TableMap : global::CsvHelper.Configuration.ClassMap<{Path.GetFileName(table.Path).Split('.').First()}Table>
@@ -106,10 +127,9 @@ namespace AscNet.Table{ns}
Map(m => m.{x}).Convert(args =>
{{
{properties[x].Split(' ')[1]} tags = new {properties[x].Split(' ')[1]}();
for (int i = 1; i <= {listCount[x]}; i++)
{(nameList.Contains($"{x}[0]") ? $"for (int i = 0; i < {listCount[x]}; i++)" : $"for (int i = 1; i <= {listCount[x]}; i++)")}
{{
string tagValue = args.Row.GetField<string>($""{x}[{{i}}]"");
string? tagValue = args.Row.GetField<string>($""{x}[{{i}}]"");
if (!string.IsNullOrEmpty(tagValue))
{{
{(properties[x].Split('<')[1].StartsWith("global::System.Int32") ? @"