Esempio n. 1
0
        public void DoSearch()
        {
            foreach (var card in Cards)
            {
                card.IsDisplayed = true;
            }

            foreach (var card in Cards)
            {
                var isNameMatch          = string.IsNullOrEmpty(CardNameSearch) ? true : card.Info.Name.ToLower().Contains(CardNameSearch.ToLower());
                var isPatchMatch         = string.IsNullOrEmpty(PatchSearch) ? true : card.Info.Patch.Contains(PatchSearch);
                var isNpcMatch           = string.IsNullOrEmpty(NPCNameSearch) ? true : card.Info.NPCs.FirstOrDefault(n => n.ToLower().Contains(NPCNameSearch.ToLower())) != null;
                var isMinDifficultyMatch = string.IsNullOrEmpty(MinDifficultySearch) ? true : card.Difficulty >= int.Parse(MinDifficultySearch);
                var isMaxDifficultyMatch = string.IsNullOrEmpty(MaxDifficultySearch) ? true : card.Difficulty <= int.Parse(MaxDifficultySearch);
                var isCollectionMatch    = string.IsNullOrEmpty(CollectedSearch) || CollectedSearch == "No Preference" ? true : (CollectedSearch == "Collected" && card.IsCollected) || (CollectedSearch == "Uncollected" && !card.IsCollected);

                card.IsDisplayed = isNameMatch && isPatchMatch && isNpcMatch && isMinDifficultyMatch && isMaxDifficultyMatch && isCollectionMatch;
            }

            // store fields for resetting later
            var cardName = CardNameSearch;
            var patch    = PatchSearch;
            var npcName  = NPCNameSearch;

            CardNames.Clear();
            Patches.Clear();
            NPCNames.Clear();

            var displayedCards = Cards.Where(c => c.IsDisplayed);

            foreach (var displayedCard in displayedCards)
            {
                if (!CardNames.Contains(displayedCard.Info.Name))
                {
                    CardNames.Add(displayedCard.Info.Name);
                }

                if (!Patches.Contains(displayedCard.Info.Patch))
                {
                    Patches.Add(displayedCard.Info.Patch);
                }

                foreach (var npc in displayedCard.Info.NPCs)
                {
                    if (!NPCNames.Contains(npc))
                    {
                        NPCNames.Add(npc);
                    }
                }
            }

            // set fields back after the search
            CardNameSearch = cardName;
            PatchSearch    = patch;
            NPCNameSearch  = npcName;
        }
Esempio n. 2
0
        public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode)
        {
            if (cardJToken == null)
            {
                UnityEngine.Debug.LogWarning("LoadCardFromJToken::NullCardJToken");
                return;
            }

            string cardId = cardJToken.Value <string>(CardIdIdentifier) ?? string.Empty;

            if (string.IsNullOrEmpty(cardId))
            {
                UnityEngine.Debug.LogWarning("LoadCardFromJToken::InvalidCardId:" + cardJToken.ToString());
                return;
            }

            string cardName = cardJToken.Value <string>(CardNameIdentifier) ?? string.Empty;
            Dictionary <string, PropertyDefValuePair> cardProperties = new Dictionary <string, PropertyDefValuePair>();

            foreach (PropertyDef property in CardProperties)
            {
                PropertyDefValuePair newPropertyEntry = new PropertyDefValuePair()
                {
                    Def = property
                };
                try
                {
                    string  listValue = string.Empty;
                    JObject jObject   = null;
                    switch (property.Type)
                    {
                    case PropertyType.ObjectEnumList:
                        listValue = string.Empty;
                        foreach (JToken jToken in cardJToken[property.Name])
                        {
                            if (!string.IsNullOrEmpty(listValue))
                            {
                                listValue += EnumDef.Delimiter;
                            }
                            jObject    = jToken as JObject;
                            listValue += jObject?.Value <string>("id") ?? string.Empty;
                        }
                        newPropertyEntry.Value = listValue;
                        break;

                    case PropertyType.ObjectList:
                        listValue = string.Empty;
                        foreach (JToken jToken in cardJToken[property.Name])
                        {
                            if (!string.IsNullOrEmpty(listValue))
                            {
                                listValue += EnumDef.Delimiter;
                            }
                            jObject    = jToken as JObject;
                            listValue += jObject?.ToString() ?? string.Empty;
                        }
                        newPropertyEntry.Value = listValue;
                        break;

                    case PropertyType.ObjectEnum:
                        jObject = cardJToken[property.Name] as JObject;
                        newPropertyEntry.Value = jObject.Value <string>("id") ?? string.Empty;
                        break;

                    case PropertyType.Object:
                        jObject = cardJToken[property.Name] as JObject;
                        newPropertyEntry.Value = jObject?.ToString() ?? string.Empty;
                        break;

                    case PropertyType.StringEnumList:
                    case PropertyType.StringList:
                        listValue = string.Empty;
                        foreach (JToken jToken in cardJToken[property.Name])
                        {
                            if (!string.IsNullOrEmpty(listValue))
                            {
                                listValue += EnumDef.Delimiter;
                            }
                            listValue += jToken.Value <string>() ?? string.Empty;
                        }
                        newPropertyEntry.Value = listValue;
                        break;

                    case PropertyType.EscapedString:
                        newPropertyEntry.Value = (cardJToken.Value <string>(property.Name) ?? string.Empty).Replace("\\", "");
                        break;

                    case PropertyType.StringEnum:
                    case PropertyType.Number:
                    case PropertyType.Integer:
                    case PropertyType.Boolean:
                    case PropertyType.String:
                    default:
                        newPropertyEntry.Value = cardJToken.Value <string>(property.Name) ?? string.Empty;
                        break;
                    }
                }
                catch
                {
                    newPropertyEntry.Value = string.Empty;
                }
                cardProperties[property.Name] = newPropertyEntry;
            }

            HashSet <string> setCodes = new HashSet <string>();

            if (SetsInCardObject)
            {
                JToken        setContainer = cardJToken[CardSetIdentifier];
                List <JToken> setJTokens   = (setContainer as JArray)?.ToList() ?? new List <JToken>();
                if (setJTokens.Count == 0)
                {
                    setJTokens.Add(setContainer);
                }
                foreach (JToken jToken in setJTokens)
                {
                    JObject setObject = jToken as JObject;
                    string  setCode   = setObject?.Value <string>(SetCodeIdentifier);
                    if (setCode == null)
                    {
                        UnityEngine.Debug.LogWarning("LoadCardFromJToken::InvalidSetObject:" + setContainer.ToString());
                    }
                    else
                    {
                        setCodes.Add(setCode);
                    }
                }
            }
            else
            {
                setCodes.Add(cardJToken.Value <string>(CardSetIdentifier) ?? defaultSetCode);
            }

            foreach (string cardSet in setCodes)
            {
                bool isReprint = CardNames.Contains(cardName);
                if (!isReprint)
                {
                    CardNames.Add(cardName);
                }
                Card newCard = new Card(this, setCodes.Count > 1 ? (cardId + "_" + cardSet) : cardId, cardName, cardSet, cardProperties, isReprint);
                LoadedCards[newCard.Id] = newCard;
                if (!Sets.ContainsKey(cardSet))
                {
                    LoadedSets[cardSet] = new Set(cardSet);
                }
            }
        }
        public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode)
        {
            if (cardJToken == null)
            {
                UnityEngine.Debug.LogError("LoadCardFromJToken::NullCardJToken");
                return;
            }

            Dictionary <string, PropertyDefValuePair> metaProperties = new Dictionary <string, PropertyDefValuePair>();
            PropertyDef idDef = new PropertyDef(CardIdIdentifier, PropertyType.String);

            PopulateCardProperty(metaProperties, cardJToken, idDef, idDef.Name);
            string cardId = string.Empty;

            if (metaProperties.TryGetValue(CardIdIdentifier, out PropertyDefValuePair cardIdEntry))
            {
                cardId = cardIdEntry.Value;
                if (string.IsNullOrEmpty(cardId))
                {
                    UnityEngine.Debug.LogWarning("LoadCardFromJToken::MissingCardId");
                    return;
                }
                if (!string.IsNullOrEmpty(CardIdStop))
                {
                    cardId = cardId.Split(CardIdStop[0])[0];
                }
            }
            else
            {
                UnityEngine.Debug.LogWarning("LoadCardFromJToken::ParseIdError");
                return;
            }

            PropertyDef nameDef = new PropertyDef(CardNameIdentifier, PropertyType.String);

            PopulateCardProperty(metaProperties, cardJToken, nameDef, nameDef.Name);
            string cardName = string.Empty;

            if (metaProperties.TryGetValue(CardNameIdentifier, out PropertyDefValuePair cardNameEntry))
            {
                cardName = cardNameEntry.Value ?? string.Empty;
            }
            else
            {
                UnityEngine.Debug.LogWarning("LoadCardFromJToken::ParseNameError");
            }

            Dictionary <string, PropertyDefValuePair> cardProperties = new Dictionary <string, PropertyDefValuePair>();

            PopulateCardProperties(cardProperties, cardJToken, CardProperties);

            Dictionary <string, string> cardSets = new Dictionary <string, string>();

            PopulateCardSets(cardSets, cardJToken, defaultSetCode);

            string cardImageWebUrl = string.Empty;

            if (!string.IsNullOrEmpty(CardImageProperty))
            {
                PropertyDef imageDef = new PropertyDef(CardImageProperty, PropertyType.String);
                PopulateCardProperty(metaProperties, cardJToken, imageDef, imageDef.Name);
                if (metaProperties.TryGetValue(CardImageProperty, out PropertyDefValuePair cardImageEntry))
                {
                    cardImageWebUrl = cardImageEntry.Value ?? string.Empty;
                }
            }

            if (string.IsNullOrEmpty(CardImageProperty) || !string.IsNullOrEmpty(cardImageWebUrl) || !string.IsNullOrEmpty(CardImageUrl))
            {
                foreach (var set in cardSets)
                {
                    bool isReprint = CardNameIsUnique && CardNames.Contains(cardName);
                    if (!isReprint)
                    {
                        CardNames.Add(cardName);
                    }
                    string cardDuplicateId = cardSets.Count > 1 && isReprint
                        ? (cardId + PropertyDef.ObjectDelimiter + set.Key) : cardId;
                    Card newCard = new Card(this, cardDuplicateId, cardName, set.Key, cardProperties, isReprint);
                    newCard.ImageWebUrl     = cardImageWebUrl;
                    LoadedCards[newCard.Id] = newCard;
                    if (!Sets.ContainsKey(set.Key))
                    {
                        LoadedSets[set.Key] = new Set(set.Key, set.Value);
                    }
                }
            }
            else
            {
                UnityEngine.Debug.Log("LoadCardFromJToken::MissingCardImageWebUrl"); // TODO: HANDLE DIFFERENTLY?
            }
        }