Assignment for RMIT Mixed Reality in 2020
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.

119 lines
2.5 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. namespace AmplifyShaderEditor
  6. {
  7. public class NodeRestrictionsData
  8. {
  9. private bool m_allPorts;
  10. private Dictionary<int, bool> m_portRestrictions;
  11. public NodeRestrictionsData()
  12. {
  13. m_portRestrictions = new Dictionary<int, bool>();
  14. }
  15. public NodeRestrictionsData( int port )
  16. {
  17. m_portRestrictions = new Dictionary<int, bool>();
  18. m_portRestrictions.Add( port, true );
  19. }
  20. public void SetAllPortRestiction( bool value )
  21. {
  22. m_allPorts = value;
  23. }
  24. public void AddRestriction( int port )
  25. {
  26. if ( !m_portRestrictions.ContainsKey( port ) )
  27. m_portRestrictions.Add( port, true );
  28. else
  29. m_portRestrictions[ port ] = true;
  30. }
  31. public void RemoveRestriction( int port )
  32. {
  33. if ( m_portRestrictions.ContainsKey( port ) )
  34. m_portRestrictions[ port ] = true;
  35. }
  36. public bool IsPortRestricted( int port )
  37. {
  38. if ( m_portRestrictions.ContainsKey( port ) )
  39. return m_portRestrictions[ port ];
  40. return false;
  41. }
  42. public void Destroy()
  43. {
  44. m_portRestrictions.Clear();
  45. m_portRestrictions = null;
  46. }
  47. public bool AllPortsRestricted
  48. {
  49. get
  50. {
  51. return m_allPorts;
  52. }
  53. }
  54. }
  55. public class NodeRestrictions
  56. {
  57. private Dictionary<System.Type, NodeRestrictionsData> m_restrictions;
  58. public NodeRestrictions()
  59. {
  60. m_restrictions = new Dictionary<System.Type, NodeRestrictionsData>();
  61. }
  62. public void AddTypeRestriction( System.Type type )
  63. {
  64. if ( !m_restrictions.ContainsKey( type ) )
  65. m_restrictions.Add( type, new NodeRestrictionsData() );
  66. m_restrictions[ type ].SetAllPortRestiction( true );
  67. }
  68. public void AddPortRestriction( System.Type type, int port )
  69. {
  70. if ( !m_restrictions.ContainsKey( type ) )
  71. m_restrictions.Add( type, new NodeRestrictionsData( port ) );
  72. else
  73. {
  74. m_restrictions[ type ].AddRestriction( port );
  75. }
  76. }
  77. public bool GetRestiction( System.Type type, int port )
  78. {
  79. if ( m_restrictions.Count == 0 || type == null )
  80. return false;
  81. if ( m_restrictions.ContainsKey( type ) )
  82. {
  83. if ( m_restrictions[ type ].AllPortsRestricted )
  84. return true;
  85. return m_restrictions[ type ].IsPortRestricted( port );
  86. }
  87. return false;
  88. }
  89. public void Destroy()
  90. {
  91. foreach ( KeyValuePair<System.Type, NodeRestrictionsData> pair in m_restrictions )
  92. {
  93. pair.Value.Destroy();
  94. }
  95. m_restrictions.Clear();
  96. m_restrictions = null;
  97. }
  98. }
  99. }