TestPair.Prototypes.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #nullable enable
  2. using System.Collections.Generic;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Utility;
  5. using Robust.UnitTesting;
  6. namespace Content.IntegrationTests.Pair;
  7. // This partial class contains helper methods to deal with yaml prototypes.
  8. public sealed partial class TestPair
  9. {
  10. private Dictionary<Type, HashSet<string>> _loadedPrototypes = new();
  11. private HashSet<string> _loadedEntityPrototypes = new();
  12. public async Task LoadPrototypes(List<string> prototypes)
  13. {
  14. await LoadPrototypes(Server, prototypes);
  15. await LoadPrototypes(Client, prototypes);
  16. }
  17. private async Task LoadPrototypes(RobustIntegrationTest.IntegrationInstance instance, List<string> prototypes)
  18. {
  19. var changed = new Dictionary<Type, HashSet<string>>();
  20. foreach (var file in prototypes)
  21. {
  22. instance.ProtoMan.LoadString(file, changed: changed);
  23. }
  24. await instance.WaitPost(() => instance.ProtoMan.ReloadPrototypes(changed));
  25. foreach (var (kind, ids) in changed)
  26. {
  27. _loadedPrototypes.GetOrNew(kind).UnionWith(ids);
  28. }
  29. if (_loadedPrototypes.TryGetValue(typeof(EntityPrototype), out var entIds))
  30. _loadedEntityPrototypes.UnionWith(entIds);
  31. }
  32. public bool IsTestPrototype(EntityPrototype proto)
  33. {
  34. return _loadedEntityPrototypes.Contains(proto.ID);
  35. }
  36. public bool IsTestEntityPrototype(string id)
  37. {
  38. return _loadedEntityPrototypes.Contains(id);
  39. }
  40. public bool IsTestPrototype<TPrototype>(string id) where TPrototype : IPrototype
  41. {
  42. return IsTestPrototype(typeof(TPrototype), id);
  43. }
  44. public bool IsTestPrototype<TPrototype>(TPrototype proto) where TPrototype : IPrototype
  45. {
  46. return IsTestPrototype(typeof(TPrototype), proto.ID);
  47. }
  48. public bool IsTestPrototype(Type kind, string id)
  49. {
  50. return _loadedPrototypes.TryGetValue(kind, out var ids) && ids.Contains(id);
  51. }
  52. }