Pārlūkot izejas kodu

添加功能开启枚举

zouweichen 6 mēneši atpakaļ
vecāks
revīzija
add32fa25a

+ 71 - 0
etoy/Components/CodeGenerater/CSharp/CSharpFunctionUnlockTypeGenerater.cs

@@ -0,0 +1,71 @@
+
+namespace etoy
+{
+    /// <summary>
+    /// 客户端特殊定义脚本
+    /// help_帮助转枚举HelpType
+    /// </summary>
+    class CSharpFunctionUnlockTypeGenerater : IGenerater
+    {
+        private const string TableName = "FunctionUnlock";
+        private const string EnumName = "EFunctionUnlockType";
+        public void Generate(Context context)
+        {
+            var tables = context.Blackboard.Tables;
+            foreach (var table in tables)
+            {
+                if (table.Name.Equals(TableName, StringComparison.OrdinalIgnoreCase))
+                {
+                    GenAttributeType(context, table);
+                    break;
+                }
+            }
+        }
+        private void GenAttributeType(Context context, Table table)
+        {
+            var filePath = $"{context.Option.ClientCodeOutput}/{EnumName}.cs";
+            
+            using var writer = new CodeWriter(filePath);
+            writer.WriteLine("// Generate By EToy");
+            writer.WriteLine("// Don't Edit It!!");
+            writer.WriteLine();
+            writer.Bracket("namespace XGame.Database");
+            {
+                writer.Summary($"{TableName} 转枚举 {EnumName}\nName : FunctionUnlock.Name \nValue : FunctionUnlock.Id");
+                writer.Bracket($"public enum {EnumName} : int");
+                {
+                    for (int i = 0, rowCount = table.Rows.Count; i < rowCount; i++)
+                    {
+                        var row = table.Rows[i];
+                        GetEnumProperty(row, out var name, out var value, out var summary);
+                        if (string.IsNullOrEmpty(name)) continue;
+                        writer.Summary(summary);
+                        writer.WriteLine($"{name} = {value},");
+                    }
+                    writer.EndBracket();
+                }
+                writer.EndBracket();
+            }
+        }
+
+        private void GetEnumProperty(Row row, out string name, out string value, out string summary)
+        {
+            name = value = summary = string.Empty;
+            foreach(var cell in  row.Cells)
+            {
+                if ("enumName".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
+                {
+                    name = cell.Value.ToTitleCase();
+                }
+                else if ("id".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
+                {
+                    value = cell.Value;
+                }
+                else if ("name".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
+                {
+                    summary = cell.Value;
+                }
+            }
+        }
+    }
+}

+ 1 - 0
etoy/Pileline/Cmd/CmdExportClientCode.cs

@@ -22,6 +22,7 @@ namespace etoy
                 new CSharpMetadataTableGenerater(),
                 new CSharpAttributeTypeGenerater(),
                 new CSharpHelpTypeGenerater(),
+                new CSharpFunctionUnlockTypeGenerater(),
                 new CSharpVersionConfigGenerater(),
                 new TxtVersionConfigGenerater(),
             };