コード例 #1
0
        /// <summary>
        /// Get an assignment designed to match a given crew member.
        /// </summary>
        /// <param name="crew"></param>
        /// <returns></returns>
        public static Assignment ForCrew(ProtoCrewMember crew)
        {
            if (crew == null)
            {
                return(Empty);
            }
            List <AssignmentNode> nodes = new List <AssignmentNode>(3);

            nodes.Add(AssignmentNode.ByName(crew));
            nodes.Add(AssignmentNode.ByProfession(crew));
            nodes.Add(AssignmentNode.ByType(crew));
            return(new Assignment(nodes));
        }
コード例 #2
0
        /// <summary>
        /// Pops off the head of the assignment node list and returns it (null if none left).
        /// </summary>
        /// <returns></returns>
        private AssignmentNode Pop()
        {
            if (nodes.Count == 0)
            {
                return(null);
            }
            AssignmentNode node = nodes[0];

            if (node.Type != AssignmentType.Empty)
            {
                nodes.RemoveAt(0);
            }
            return(node);
        }
コード例 #3
0
        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }
            AssignmentNode other = obj as AssignmentNode;

            if (other == null)
            {
                return(false);
            }
            return((Type == other.Type) && (value == other.value));
        }
コード例 #4
0
        public override string ToString()
        {
            if (nodes.Count == 0)
            {
                return(string.Empty);
            }
            if (nodes[0].Type == AssignmentType.Empty)
            {
                return(nodes[0].ToString());
            }
            StringBuilder builder = new StringBuilder(nodes[0].ToString());

            for (int index = 1; index < nodes.Count; ++index)
            {
                AssignmentNode node = nodes[index];
                builder.Append("|").Append(node.ToString());
                if (node.Type == AssignmentType.Empty)
                {
                    break;
                }
            }
            return(builder.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Parse an assignment from a text string.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static Assignment Parse(string text)
        {
            List <AssignmentNode> nodes = new List <AssignmentNode>();

            if (text != null)
            {
                text = text.Trim();
                string[] tokens = text.Split('|');
                foreach (string token in tokens)
                {
                    AssignmentNode node = AssignmentNode.Parse(token);
                    if (node == null)
                    {
                        break;
                    }
                    nodes.Add(node);
                    if (node.Type == AssignmentType.Empty)
                    {
                        break;
                    }
                }
            }
            return((nodes.Count == 0) ? null : new Assignment(nodes));
        }