Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1KB

  1. using System;
  2. using Svelto.DataStructures;
  3. namespace Svelto.ECS
  4. {
  5. public static class ExclusiveGroupStructExtensions
  6. {
  7. public static ExclusiveBuildGroup RemoveTag<T>(this ExclusiveGroupStruct group) where T : GroupTag<T>
  8. {
  9. if (ExclusiveBuildGroupExtensions._removeTransitions.TryGetValue(@group, out var transitions))
  10. {
  11. var type = new RefWrapper<Type>(typeof(T));
  12. if (transitions.TryGetValue(type, out var result))
  13. {
  14. return result;
  15. }
  16. }
  17. throw new ECSException("No remove transition found for type "
  18. .FastConcat(typeof(T).ToString())
  19. .FastConcat(" in group ").FastConcat(@group.ToString())
  20. );
  21. }
  22. public static ExclusiveBuildGroup AddTag<T>(this ExclusiveGroupStruct group) where T : GroupTag<T>
  23. {
  24. if (ExclusiveBuildGroupExtensions._addTransitions.TryGetValue(group, out var transitions))
  25. {
  26. var type = new RefWrapper<Type>(typeof(T));
  27. if (transitions.TryGetValue(type, out var result))
  28. {
  29. return result;
  30. }
  31. }
  32. throw new ECSException("No add transition found for type "
  33. .FastConcat(typeof(T).ToString())
  34. .FastConcat(" in group ").FastConcat(@group.ToString())
  35. );
  36. }
  37. public static ExclusiveBuildGroup SwapTag<TTarget>(this ExclusiveGroupStruct group)
  38. where TTarget : GroupTag<TTarget>
  39. {
  40. var type = new RefWrapper<Type>(typeof(TTarget));
  41. if (ExclusiveBuildGroupExtensions._swapTransitions.TryGetValue(@group, out var transitions))
  42. {
  43. if (transitions.TryGetValue(type, out var result))
  44. {
  45. return result;
  46. }
  47. }
  48. throw new ECSException("No swap transition found for type "
  49. .FastConcat(typeof(TTarget).ToString())
  50. .FastConcat(" in group ").FastConcat(@group.ToString())
  51. );
  52. }
  53. }
  54. }