예제 #1
0
        public void Move(GameBaseObject currentParent, RelationshipType relationshipType, GameBaseObject newParent)
        {
            // if a relationship exists between this and the soon-to-be old parent
            if (currentParent.HasDirectRelationshipWith(this, relationshipType, RelationshipDirection.ParentToChild))
            {
                //remove that relationship
                currentParent.RemoveRelationship(relationshipType, RelationshipDirection.ParentToChild, this);

                //add a new one
                newParent.AddRelationship(relationshipType, RelationshipDirection.ParentToChild, this);
            }
        }
예제 #2
0
        public bool HasDirectRelationshipWith(GameBaseObject baseObject, RelationshipType type, RelationshipDirection direction)
        {
            if (Relationships == null)
            {
                return(false);
            }

            var objectRelationship = new GameObjectRelationship(type, direction, baseObject);

            // Identifies object equality by ID.
            // Returns whether the object's Relationships contains a relationship with the other object in the specified direction.
            return(Relationships.Any(gameObjectRelationship => gameObjectRelationship.RelationshipTo.ID == objectRelationship.RelationshipTo.ID));
        }
예제 #3
0
        public bool HasIndirectRelationshipWith(GameBaseObject baseObject, RelationshipType type, RelationshipDirection direction)
        {
            if (Relationships == null)
            {
                return(false);
            }

            if (HasDirectRelationshipWith(baseObject, type, direction))
            {
                return(false);
            }

            // check child objects for direct relationship
            // check each child's child's child's ...
            // ...

            return(false);
        }
예제 #4
0
        public void RemoveRelationship(RelationshipType relationshipType, RelationshipDirection relationshipDirection, GameBaseObject relationshipTo)
        {
            // if null instanciate Relationships
            if (Relationships == null)
            {
                Relationships = new List <GameObjectRelationship>();
            }

            // if relationshipTo's Relationships is null instanciate Relationships
            if (relationshipTo.Relationships == null)
            {
                relationshipTo.Relationships = new List <GameObjectRelationship>();
            }

            // remove new relationship
            Relationships.Remove(new GameObjectRelationship(relationshipType, relationshipDirection, relationshipTo));

            // remove other type of relationship
            if (relationshipDirection == RelationshipDirection.ParentToChild)
            {
                relationshipTo.Relationships.Remove(new GameObjectRelationship(relationshipType, RelationshipDirection.ChildToParent, this));
            }
            else if (relationshipDirection == RelationshipDirection.ChildToParent)
            {
                relationshipTo.Relationships.Remove(new GameObjectRelationship(relationshipType, RelationshipDirection.ParentToChild, this));
            }
        }
예제 #5
0
 public GameObjectRelationship(RelationshipType relationshipType, RelationshipDirection relationshipDirection, GameBaseObject relationshipTo)
 {
     RelationshipType      = relationshipType;
     RelationshipDirection = relationshipDirection;
     RelationshipTo        = relationshipTo;
 }