Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yzngo committed Aug 7, 2020
1 parent 9699acf commit 455acba
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Binary file modified bin/tablegen2.exe
Binary file not shown.
11 changes: 11 additions & 0 deletions tablegen2/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,23 @@ private bool _genSingleFileImpl(string filePath, string exportDir, TableExportFo
break;
case TableExportFormat.Json:
{
// export json
exportPath = Path.Combine(exportDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(filePath)));
TableExcelExportJson.exportExcelFile(data, exportPath);

// export cs
string fileName = Path.GetFileNameWithoutExtension(filePath);
fileName = fileName.Substring(0, 1).ToUpper() + fileName.Substring(1);
exportPath = Path.Combine(exportDir, string.Format($"{ fileName }.cs"));
TableExcelExportCs.ExportExcelFile(data, exportPath);

// export csEx
exportPath = Path.Combine(exportDir, string.Format($"{ fileName }.Ex.cs"));
if (!File.Exists(exportPath))
{
TableExcelExportCsEx.ExportExcelFile(data, exportPath, fileName);
}

}
break;
case TableExportFormat.Xml:
Expand Down
4 changes: 3 additions & 1 deletion tablegen2/logic/parser/TableExcelExportCs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ namespace Feamber.Data
//-- 构造类名 ---------------------------------------------------------------------------------------------------------------------------
private static void AppendTitle(this StringBuilder sb, string path)
{
sb.AppendLine($" public sealed class {Path.GetFileNameWithoutExtension(path)} : IData");
sb.AppendLine($" // 此文件自动生成, 勿修改.");
sb.AppendLine($" // 如需自定义方法, 写在SkillList.Ex.cs");
sb.AppendLine($" public sealed partial class {Path.GetFileNameWithoutExtension(path)} : IBaseData");
sb.AppendLine(" {");
}

Expand Down
46 changes: 46 additions & 0 deletions tablegen2/logic/parser/TableExcelExportCsEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace tablegen2.logic
{
public static class TableExcelExportCsEx
{
public static void ExportExcelFile(TableExcelData data, string filePath, string fileName)
{
var csString = new StringBuilder();
csString.AppendTemplate(fileName);

File.WriteAllBytes(filePath, Encoding.UTF8.GetBytes(csString.ToString()));
}

private static void AppendTemplate(this StringBuilder sb, string className)
{
sb.AppendLine(@"using System.Collections.Generic;");
sb.AppendLine(@"using UnityEngine;");
sb.AppendLine(@"");
sb.AppendLine(@"namespace Feamber.Data");
sb.AppendLine(@"{");
sb.AppendLine($" public sealed partial class { className } : IBaseData");
sb.AppendLine(@" {");
sb.AppendLine($" public void OnValidate()");
sb.AppendLine(@" {");
sb.AppendLine(@" Debug.Assert(Index > 0, $""{ nameof(Index)}{ Index} (excel-id) must greater than 0"");");
sb.AppendLine(@" }");
sb.AppendLine(@" }");
sb.AppendLine(@"");
sb.AppendLine(@" public static partial class DataListExtensioMethods");
sb.AppendLine(@" {");
sb.AppendLine($" public static void Demo(this DataList<{ className }> dataList)");
sb.AppendLine(@" {");
sb.AppendLine(@" }");
sb.AppendLine(@" }");
sb.AppendLine(@"}");
sb.AppendLine(@"");
}
}
}
1 change: 1 addition & 0 deletions tablegen2/tablegen2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
<Compile Include="logic\parser\TableExportFormat.cs" />
<Compile Include="logic\parser\TableExcelHeader.cs" />
<Compile Include="logic\parser\TableGenConfig.cs" />
<Compile Include="logic\parser\TableExcelExportCsEx.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down

0 comments on commit 455acba

Please sign in to comment.