CSharpGuideTargetKeyGenerater.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 value, 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} = \"{value}\";");
  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 value, out string summary)
  54. {
  55. key = value = 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. value = cell.Value;
  62. }
  63. else if ("id".Equals(cell.FieldInfo.FieldName, StringComparison.OrdinalIgnoreCase))
  64. {
  65. summary = cell.Value;
  66. }
  67. }
  68. }
  69. }
  70. }