Esempio n. 1
0
        public PartMessageListener(Type delegateType, PartRelationship relations = PartRelationship.Self, GameSceneFilter scenes = GameSceneFilter.Any)
        {
            if (delegateType == null)
                throw new ArgumentException("Message argument is null");
            if (!delegateType.IsSubclassOf(typeof(Delegate)))
                throw new ArgumentException("Message is not a delegate type: " + typeof(Delegate).AssemblyQualifiedName + "\n" + Debugging.DumpTypeHeirachy(delegateType));
            if (delegateType.GetCustomAttributes(typeof(PartMessageDelegate), true).Length == 0)
                throw new ArgumentException("Message does not have the PartMessageDelegate attribute");

            DelegateType = delegateType;
            Scenes = scenes;
            Relations = relations;
        }
        public PartMessageListener(Type delegateType, PartRelationship relations = PartRelationship.Self, GameSceneFilter scenes = GameSceneFilter.Any)
        {
            if (delegateType == null)
            {
                throw new ArgumentException("Message argument is null");
            }
            if (!delegateType.IsSubclassOf(typeof(Delegate)))
            {
                throw new ArgumentException("Message is not a delegate type: " + typeof(Delegate).AssemblyQualifiedName + "\n" + Debugging.DumpTypeHeirachy(delegateType));
            }
            if (delegateType.GetCustomAttributes(typeof(PartMessageDelegate), true).Length == 0)
            {
                throw new ArgumentException("Message does not have the PartMessageDelegate attribute");
            }

            DelegateType = delegateType;
            Scenes       = scenes;
            Relations    = relations;
        }
Esempio n. 3
0
		/// <summary>
		/// Test if two parts are related by a set of criteria. Because PartRelationship is a flags
		/// enumeration, multiple flags can be tested at the same time.
		/// </summary>
		public static bool RelationTest(this Part part, Part other, PartRelationship relation)
		{
			if (relation == PartRelationship.Unknown)
				return true;
			if(part == null || other == null)
				return false;

			if (TestFlag(relation, PartRelationship.Self) && part == other)
				return true;
			if (TestFlag(relation, PartRelationship.Vessel) && part.localRoot == other.localRoot)
				return true;
			if (TestFlag(relation, PartRelationship.Unrelated) && part.localRoot != other.localRoot)
				return true;
			if (TestFlag(relation, PartRelationship.Sibling) && part.parent == other.parent)
				return true;
			if (TestFlag(relation, PartRelationship.Ancestor))
			{
				for (Part upto = other.parent; upto != null; upto = upto.parent)
					if (upto == part)
						return true;
			}
			else if (TestFlag(relation, PartRelationship.Parent) && part == other.parent)
				return true;

			if (TestFlag(relation, PartRelationship.Decendent))
			{
				for (Part upto = part.parent; upto != null; upto = upto.parent)
					if (upto == other)
						return true;
			}
			else if (TestFlag(relation, PartRelationship.Child) && part.parent == other)
				return true;

			if (TestFlag(relation, PartRelationship.Symmetry))
				return other.symmetryCounterparts.Any(sym => part == sym);
			return false;
		}
Esempio n. 4
0
 internal static bool TestFlag(this PartRelationship e, PartRelationship flags)
 {
     return((e & flags) == flags);
 }