CSharpGuideTargetKeyGenerater.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. using var writer = new CodeWriter(filePath);
  27. writer.WriteLine("// Generate By EToy");
  28. writer.WriteLine("// Don't Edit It!!");
  29. writer.WriteLine();
  30. writer.Bracket("namespace XGame.Database");
  31. {
  32. writer.Summary($"生成引导UI对象Key");
  33. writer.Bracket($"public static class {KeyName}");
  34. {
  35. for (int i = 0, rowCount = table.Rows.Count; i < rowCount; i++)
  36. {
  37. var row = table.Rows[i];
  38. GetKeyProperty(row, out var key, out var summary);
  39. if (string.IsNullOrEmpty(key))
  40. continue;
  41. writer.Summary(summary);
  42. writer.WriteLine($"public readonly static string {key} = \"{key}\";");
  43. }
  44. writer.EndBracket();
  45. }
  46. writer.EndBracket();
  47. }
  48. }
  49. private void GetKeyProperty(Row row, out string key, out string summary)
  50. {
  51. key = summary = string.Empty;
  52. foreach (var cell in row.Cells)
  53. {
  54. if ("target".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
  55. {
  56. key = cell.Value.ToTitleCase();
  57. }
  58. else if ("id".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
  59. {
  60. summary = cell.Value;
  61. }
  62. }
  63. }
  64. }
  65. }