PackageNode.DependencyInfo.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. namespace TBL.GodotSharp.Content
  3. {
  4. public partial class PackageNode
  5. {
  6. /// <summary>
  7. /// 包信息
  8. /// </summary>
  9. public struct Info
  10. {
  11. /// <summary>
  12. /// 包名称
  13. /// </summary>
  14. public readonly string Name;
  15. /// <summary>
  16. /// 作者信息
  17. /// </summary>
  18. public readonly string AuthorInfo;
  19. /// <summary>
  20. /// 版本信息
  21. /// </summary>
  22. public readonly Version VersionInfo;
  23. public Info(string name, string author, string version)
  24. {
  25. Name = name;
  26. AuthorInfo = author;
  27. if (!Version.TryParse(version, out VersionInfo))
  28. VersionInfo = new Version();
  29. }
  30. public Info(string name, string author, Version version)
  31. {
  32. Name = name;
  33. AuthorInfo = author;
  34. VersionInfo = version;
  35. }
  36. /// <summary>
  37. /// 判断本信息能否满足 <paramref name="target"/> 的版本要求
  38. /// </summary>
  39. /// <param name="target">依赖项信息</param>
  40. public bool IsCompatibleWith(DependencyInfo target)
  41. {
  42. return Content.IsCompatibleWith(VersionInfo, target.Target.VersionInfo,
  43. (target.Flags & DependencyInfo.FlagsEnum.Strict) != 0 ? 1 : 0);
  44. }
  45. public override string ToString() => $"[{Name}][{AuthorInfo}][{VersionInfo}]";
  46. }
  47. /// <summary>
  48. /// 包依赖信息
  49. /// </summary>
  50. public struct DependencyInfo
  51. {
  52. /// <summary>
  53. /// 依赖目标
  54. /// </summary>
  55. public readonly Info Target;
  56. /// <summary>
  57. /// 依赖属性
  58. /// </summary>
  59. public readonly FlagsEnum Flags;
  60. /// <summary>
  61. /// 依赖项属性
  62. /// </summary>
  63. [Flags]
  64. public enum FlagsEnum
  65. {
  66. /// <summary>
  67. /// 无属性
  68. /// </summary>
  69. None,
  70. /// <summary>
  71. /// 非必须依赖项
  72. /// </summary>
  73. Unnecessary,
  74. /// <summary>
  75. /// 严格(次版本号)兼容依赖项
  76. /// </summary>
  77. Strict
  78. }
  79. public DependencyInfo(Info target, FlagsEnum flags = FlagsEnum.None)
  80. {
  81. Target = target;
  82. Flags = flags;
  83. }
  84. }
  85. }
  86. }