コード例 #1
0
        /// <summary>
        /// Reads the file which has Sideboard cards denoted on each line, and returns a ConverterDeck which is populated with all cards and deck name.
        /// </summary>
        /// <param name="lines">An array of all the lines of text from a Deck file</param>
        /// <returns>A ConverterDeck object populated with all cards and deck name</returns>
        private static ConverterDeck ConvertDeckWithSideBoardCardsListedEachLine(IEnumerable<string> lines)
        {
            ConverterDeck converterDeck = new ConverterDeck();

            foreach (string line in lines)
            {
                // The line is the Deck Name?  Record it.
                string potentialDeckName = ConvertEngine.RegexMatch_DeckName(line);

                if (potentialDeckName != null)
                {
                    converterDeck.DeckName = potentialDeckName;
                }
                else
                {
                    // The line is not a Comment?
                    if (ConvertEngine.RegexMatch_Comment(line) == null)
                    {
                        // The line is a regular main deck Card/Quantity entry, without any Set info?  Record it
                        ConverterMapping potentialRegularMainDeckCard = RegexMatch_RegularMainDeckCard(line);
                        if (potentialRegularMainDeckCard != null)
                        {
                            converterDeck.AddMainDeckConverterMapping(potentialRegularMainDeckCard);
                        }
                        else
                        {
                            // The line is a regular sideboard Card/Quantity entry, without any Set info?  Record it
                            ConverterMapping potentialRegularSideBoardCard = RegexMatch_RegularSideBoardCard(line);
                            if (potentialRegularSideBoardCard != null)
                            {
                                converterDeck.AddSideBoardConverterMapping(potentialRegularSideBoardCard);
                            }
                            else
                            {
                                // The line is a MWS main deck Card/Quantity entry with Set info?  Record it
                                ConverterMapping potentialMWSMainDeckCard = RegexMatch_MWSMainDeckCard(line);
                                if (potentialMWSMainDeckCard != null)
                                {
                                    converterDeck.AddMainDeckConverterMapping(potentialMWSMainDeckCard);
                                }
                                else
                                {
                                    // The line is a MWS sideboard Card/Quantity entry, without any Set info?  Record it
                                    ConverterMapping potentialMWSSideBoardCard = RegexMatch_MWSSideBoardCard(line);
                                    if (potentialMWSSideBoardCard != null)
                                    {
                                        converterDeck.AddSideBoardConverterMapping(potentialMWSSideBoardCard);
                                    }
                                    else
                                    {
                                        // The line is not a valid card entry
                                    }
                                }
                            }
                        }
                    }
                }
            }

            converterDeck.ConversionSuccessful = true;
            return converterDeck;
        }
コード例 #2
0
        /// <summary>
        /// Reads the file which has Sideboard cards in a section below the MainDeck cards, and returns a ConverterDeck which is populated with all cards and deck name.
        /// </summary>
        /// <param name="mainDecklines">An array of all the lines of text which are MainDeck cards</param>
        /// <param name="sideBoardLines">An array of all the lines of text which are SideBoard cards</param>
        /// <returns>A ConverterDeck object populated with all cards and deck name</returns>
        private static ConverterDeck ConvertDeckWithSeparateSections(IEnumerable<string> mainDecklines, IEnumerable<string> sideBoardLines)
        {
            ConverterDeck converterDeck = new ConverterDeck();
            List<ConverterMapping> mainDeckMappings = new List<ConverterMapping>();
            List<ConverterMapping> sideBoardMappings = new List<ConverterMapping>();

            List<Tuple<IEnumerable<string>, List<ConverterMapping>>> sectionsMap = new List<Tuple<IEnumerable<string>, List<ConverterMapping>>>();
            sectionsMap.Add(new Tuple<IEnumerable<string>, List<ConverterMapping>>(mainDecklines, mainDeckMappings));
            sectionsMap.Add(new Tuple<IEnumerable<string>, List<ConverterMapping>>(sideBoardLines, sideBoardMappings));

            foreach (var section in sectionsMap)
            {
                foreach (string line in section.Item1)
                {
                    // The line is the Deck Name?  Record it.
                    string potentialDeckName = ConvertEngine.RegexMatch_DeckName(line);

                    if (potentialDeckName != null)
                    {
                        converterDeck.DeckName = potentialDeckName;
                    }
                    else
                    {
                        // The line is not a Comment?
                        if (ConvertEngine.RegexMatch_Comment(line) == null)
                        {
                            // The line is a regular main deck Card/Quantity entry, without any Set info?  Record it
                            ConverterMapping potentialRegularMainDeckCard = RegexMatch_RegularMainDeckCard(line);
                            if (potentialRegularMainDeckCard != null)
                            {
                                section.Item2.Add(potentialRegularMainDeckCard);
                            }
                            else
                            {
                                // The line is a MWS main deck Card/Quantity entry with Set info?  Record it
                                ConverterMapping potentialMWSMainDeckCard = RegexMatch_MWSMainDeckCard(line);
                                if (potentialMWSMainDeckCard != null)
                                {
                                    section.Item2.Add(potentialMWSMainDeckCard);
                                }
                                else
                                {
                                    // The line is not a valid card entry
                                }
                            }
                        }
                    }
                }
            }

            foreach (var mainDeckMapping in mainDeckMappings)
            {
                converterDeck.AddMainDeckConverterMapping(mainDeckMapping);
            }

            foreach (var sideBoardMapping in sideBoardMappings)
            {
                converterDeck.AddSideBoardConverterMapping(sideBoardMapping);
            }

            converterDeck.ConversionSuccessful = true;
            return converterDeck;
        }
コード例 #3
0
        /// <summary>
        /// Reads the OCTGN format file, and returns a ConverterDeck which is populated with all cards.
        /// </summary>
        /// <param name="fullPathName">The full path name of the OCTGN Deck file to convert</param>
        /// <returns>A ConverterDeck object populated with all cards and deck name</returns>
        /// <remarks>This will purposely ignore the Guids, which may help importing from OCTGN2 or other unofficial sets</remarks>
        private static ConverterDeck ConvertOctgn(string fullPathName)
        {
            ConverterDeck converterDeck = new ConverterDeck();

            XmlTextReader reader = new XmlTextReader(fullPathName);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            XmlDocument xd = new XmlDocument();
            xd.Load(reader);

            XmlNode xnodDE = xd.DocumentElement;

            if (xnodDE.Name != "deck")
            {
                throw new InvalidOperationException("File is not a Octgn Deck");
            }

            foreach (XmlNode child in xnodDE.ChildNodes)
            {
                if (child.Name.Equals("section", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (child.Attributes.GetNamedItem("name").Value.Equals("Main", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foreach (XmlNode cardXmlNode in child.ChildNodes)
                        {
                            converterDeck.AddMainDeckConverterMapping
                            (
                                new ConverterMapping
                                (
                                    cardXmlNode.InnerText,
                                    string.Empty,
                                    int.Parse(cardXmlNode.Attributes.GetNamedItem("qty").Value)
                                )
                            );
                        }
                    }
                    else if (child.Attributes.GetNamedItem("name").Value.Equals("Sideboard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foreach (XmlNode cardXmlNode in child.ChildNodes)
                        {
                            converterDeck.AddSideBoardConverterMapping
                            (
                                new ConverterMapping
                                (
                                    cardXmlNode.InnerText,
                                    string.Empty,
                                    int.Parse(cardXmlNode.Attributes.GetNamedItem("qty").Value)
                                )
                            );
                        }
                    }
                }
            }

            converterDeck.ConversionSuccessful = true;
            return converterDeck;
        }