CSharpGuideTargetKeyGenerater.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. namespace etoy
  2. {
  3. /// <summary>
  4. /// 客户端特殊定义脚本
  5. /// guide_引导 target 目标key
  6. /// </summary>
  7. class CSharpGuideTargetKeyGenerater : IGenerater
  8. {
  9. private const string TableName = "guideStep";
  10. private const string KeyName = "GuideTargetKey";
  11. public void Generate(Context context)
  12. {
  13. var tables = context.Blackboard.Tables;
  14. foreach (var table in tables)
  15. {
  16. if (table.Name.Equals(TableName, StringComparison.OrdinalIgnoreCase))
  17. {
  18. GenGuideTargetKey(context, table);
  19. break;
  20. }
  21. }
  22. }
  23. private void GenGuideTargetKey(Context context, Table table)
  24. {
  25. var filePath = $"{context.Option.ClientCodeOutput}/{KeyName}.cs";
  26. var hashTable = new List<string>();
  27. using var writer = new CodeWriter(filePath);
  28. writer.WriteLine("// Generate By EToy");
  29. writer.WriteLine("// Don't Edit It!!");
  30. writer.WriteLine();
  31. writer.Bracket("namespace XGame.Database");
  32. {
  33. writer.Summary($"生成引导UI对象Key");
  34. writer.Bracket($"public static class {KeyName}");
  35. {
  36. for (int i = 0, rowCount = table.Rows.Count; i < rowCount; i++)
  37. {
  38. var row = table.Rows[i];
  39. GetKeyProperty(row, out var key, out var summary);
  40. if (string.IsNullOrEmpty(key))
  41. continue;
  42. if (hashTable.Contains(key))
  43. continue;
  44. writer.Summary(summary);
  45. writer.WriteLine($"public readonly static string {key} = \"{key}\";");
  46. hashTable.Add(key);
  47. }
  48. writer.EndBracket();
  49. }
  50. writer.EndBracket();
  51. }
  52. }
  53. private void GetKeyProperty(Row row, out string key, out string summary)
  54. {
  55. key = summary = string.Empty;
  56. foreach (var cell in row.Cells)
  57. {
  58. if ("target".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
  59. {
  60. key = cell.Value.ToTitleCase();
  61. }
  62. else if ("id".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
  63. {
  64. summary = cell.Value;
  65. }
  66. }
  67. }
  68. }
  69. }