예제 #1
0
        /// <summary>
        /// Creates a Dictionary who's Keys are the normalized first name of the Card, and who's Values are all of the matching ConverterCard/ConverterSet Tuples.
        /// </summary>
        /// <param name="converterSets">The ConverterSets to look through to build the normalized ConverterCard Dictionary</param>
        /// <returns>a Dictionary who's Keys are the normalized first name of the Card, and who's Values are all of the matching ConverterCard/ConverterSet Tuples.</returns>
        public static Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > NormalizeConverterCards(IEnumerable <ConverterSet> converterSets)
        {
            Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > normalizedConverterCards = new Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > >();

            foreach (ConverterSet converterSet in converterSets)
            {
                if (converterSet.IncludeInSearches)
                {
                    foreach (ConverterCard converterCard in converterSet.ConverterCards)
                    {
                        string normalizedFirstName = ConverterMapping.NormalizeName(converterCard.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).First());
                        if (!normalizedConverterCards.ContainsKey(normalizedFirstName))
                        {
                            normalizedConverterCards.Add(normalizedFirstName, new List <Tuple <ConverterCard, ConverterSet> >());
                        }

                        normalizedConverterCards[normalizedFirstName].Add(new Tuple <ConverterCard, ConverterSet>(converterCard, converterSet));
                    }
                }
            }
            return(normalizedConverterCards);
        }
예제 #2
0
        /// <summary>
        /// Searches through all converterSets for Cards which potentially match this CardName/CardSet.
        /// Each potential card is added as a potential Card.
        /// </summary>
        /// <param name="converterCardDictionary">
        /// A Dictionary of ConverterCards which are potential matches, where the Key is the normalized first name
        /// of the card and the value is a collection of all corresponding ConverterCards-ConverterSet tuples.  Only sets which are
        /// included in searches should be in this.</param>
        public void PopulateWithPotentialCards(Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > converterCardDictionary)//(Dictionary<Guid, ConverterSet> converterSets)
        {
            // Some cards have 2+ names, so create an array of all the names in order
            List <string> converterMappingNames =
                (from string mappingName in this.CardName.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                 select ConverterMapping.NormalizeName(mappingName)).ToList();

            if (converterCardDictionary.ContainsKey(converterMappingNames.First()))
            {
                foreach (Tuple <ConverterCard, ConverterSet> converterCardAndSet in converterCardDictionary[converterMappingNames.First()])
                {
                    ConverterCard converterCard = converterCardAndSet.Item1;

                    List <string> converterCardNames =
                        (from string cardName in converterCard.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                         select ConverterMapping.NormalizeName(cardName)).ToList();
                    int numIndexToCompare = Math.Min(converterMappingNames.Count, converterCardNames.Count);

                    // Compare all names.  If one card has less names than the other, then just compare indexes where
                    // both names are present because sometimes another format only includes the first name
                    bool isNameMatch = true;
                    for (int i = 0; i < numIndexToCompare; i++)
                    {
                        if (!converterCardNames[i].Equals(converterMappingNames[i]))
                        {
                            isNameMatch = false;
                            break;
                        }
                    }

                    bool isSetMatch = true;
                    if (isNameMatch && !string.IsNullOrWhiteSpace(this.CardSet))
                    {
                        ConverterSet converterSet = converterCardAndSet.Item2;

                        // LoTR - Pay attention to Set
                        if (converterSet.OctgnSet.GameId == ConvertEngine.Game.LoTR.GameGuidStatic)
                        {
                            string converterCardSet    = converterCard.Set;
                            string converterMappingSet = this.CardSet;

                            // Some sources omit 'The Hobbit - ' in the set name, so remove it from the comparison
                            if (converterCardSet.StartsWith("The Hobbit", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterCardSet = converterCardSet.Substring(13);
                            }
                            if (converterMappingSet.StartsWith("The Hobbit", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterMappingSet = converterMappingSet.Substring(13);
                            }

                            // Some sources omit 'The ' in the set name, so remove it from the comparison
                            if (converterCardSet.StartsWith("The ", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterCardSet = converterCardSet.Substring(4);
                            }
                            if (converterMappingSet.StartsWith("The ", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterMappingSet = converterMappingSet.Substring(4);
                            }

                            // Remove all Diacritics from names for comparison
                            converterCardSet    = ConverterMapping.NormalizeName(converterCardSet);
                            converterMappingSet = ConverterMapping.NormalizeName(converterMappingSet);

                            if (!converterCardSet.Equals(converterMappingSet))
                            {
                                isSetMatch = false;
                            }
                        }
                    }

                    if (isNameMatch && isSetMatch)
                    {
                        this.AddPotentialOCTGNCard(converterCard);
                    }
                }
            }
        }