示例#1
0
    public bool IsCardUIDFavorited(string cardUID)
    {
        LocalUserCardData data = null;

        if (localUserCards.TryGetValue(cardUID, out data))
        {
            return(data.Favorited);
        }
        else
        {
            return(false);
        }
    }
示例#2
0
    public LocalUserCardData GetOrCreateLocalCardData(string UID, bool placeInDictionary = true)
    {
        LocalUserCardData data = null;

        if (!localUserCards.TryGetValue(UID, out data))
        {
            data = new LocalUserCardData {
                CardUID = UID
            };
            if (placeInDictionary)
            {
                localUserCards.Add(UID, data);
            }
        }
        return(data);
    }
    /// <summary>
    /// Sort List of CardData by their scores
    /// </summary>
    /// <param name="cardDataList">List to sort from</param>
    /// <param name="ascending">Sort by score ascending or descending (default = ascending)</param>
    /// <returns></returns>
    public static List <CardData> SortByScore(this List <CardData> cardDataList, bool ascending = true)
    {
        UserData user = UserManager.Instance.GetCurrentUser();

        var userCards = user.GetLocalUserCards();

        //Use an empty LocalUserCardData to be used in the case that value is missing
        //This prevents needless allocations of LocalUserCardData's from user.GetOrCreateLocalCardData(UID, false)
        LocalUserCardData             localDefault = new LocalUserCardData();
        IOrderedEnumerable <CardData> ordered;

        if (ascending)
        {
            ordered = cardDataList.OrderBy(x => userCards.GetValueOrDefault(x.UID, localDefault).Progress);
        }
        else
        {
            ordered = cardDataList.OrderByDescending(x => userCards.GetValueOrDefault(x.UID, localDefault).Progress);
        }

        return(ordered.ToList());
    }
示例#4
0
    /// <summary>
    /// Remove CardUID from list of cards User has favorited
    /// </summary>
    /// <param name="CardUID"></param>
    /// <returns>true if the element is removed from the HashSet<T> object; false if the element didn't exist.</returns>
    public bool UnfavoriteCardUID(string cardUID)
    {
        LocalUserCardData data = GetOrCreateLocalCardData(cardUID);

        return(data.Favorited = false);
    }