Beispiel #1
0
        private BitmapImage GetImageFromFile(int cardBaseId, int level, CharacterImageFormat format)
        {
            string formatString = "";

            switch (format)
            {
            case CharacterImageFormat.Color800x640:
                formatString = CharacterImageFileFormatString.Color800x640;
                break;

            case CharacterImageFormat.Color140x112:
                formatString = CharacterImageFileFormatString.Color140x112;
                break;

            case CharacterImageFormat.Gray140x112:
                formatString = CharacterImageFileFormatString.Gray140x112;
                break;
            }
            string filename = String.Format(formatString, cardBaseId, level);
            string fullPath = Path.Combine(FilepathManager.ImagesDirectory, filename);

            try
            {
                return(new BitmapImage(new Uri(fullPath)));
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        public CharacterImageIdentifier(int cardBaseId, string cardName, string clanName, int level, CharacterImageFormat format)
        {
            if (cardBaseId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(cardBaseId), cardBaseId, "Must be greater than 0");
            }
            if (String.IsNullOrWhiteSpace(cardName))
            {
                throw new ArgumentNullException("Can't be null or empty", nameof(cardName));
            }
            if (String.IsNullOrWhiteSpace(clanName))
            {
                throw new ArgumentNullException("Can't be null or empty", nameof(clanName));
            }
            if (level < 1 || level > 5)
            {
                throw new ArgumentOutOfRangeException(nameof(level), level, "Must be between 1 and 5 inclusive");
            }
            if ((int)format < 0 || (int)format > Constants.EnumMaxAllowedValues.CharacterImageFormat)
            {
                throw new ArgumentOutOfRangeException(nameof(format), format, "Must be a valid " + nameof(CharacterImageFormat));
            }

            CardBaseId = cardBaseId;
            CardName   = cardName;
            ClanName   = clanName;
            Level      = level;
            Format     = format;
        }
Beispiel #3
0
 public void AddCardBaseToDownloadQueue(CardBase card, CharacterImageFormat imageFormat)
 {
     for (int level = card.MinLevel; level <= card.MaxLevel; level++)
     {
         ImagesQueue.Enqueue(new CharacterImageIdentifier(card, level, imageFormat));
     }
 }
 public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     try
     {
         int cardBaseId = (int)values[0];
         int level      = (int)values[1];
         CharacterImageFormat format = CharacterImageFormat.Color800x640; // TODO: allow different formats
         return(ImageRetriever.GetImage(cardBaseId, level, format));
     }
     catch
     {
         return(null);
     }
 }
Beispiel #5
0
        public BitmapImage GetImage(int cardBaseId, int level, CharacterImageFormat format)
        {
            BitmapImage result = ImageCache.GetImage(cardBaseId, level, format);

            if (result == null)
            {
                result = GetImageFromFile(cardBaseId, level, format);
                if (result != null)
                {
                    ImageCache.SetImage(cardBaseId, level, result, format);
                }
            }

            return(result);
        }
Beispiel #6
0
        public void CheckAndEnqueueNotDownloadedImages(CharacterImageFormat format)
        {
            List <CharacterImageIdentifier> images = new List <CharacterImageIdentifier>();

            foreach (CardBase cardBase in InMemoryManagerInstance.GetAllCardBases())
            {
                for (int level = cardBase.MinLevel; level <= cardBase.MaxLevel; level++)
                {
                    images.Add(new CharacterImageIdentifier(cardBase, level, format));
                }
            }

            foreach (CharacterImageIdentifier image in images)
            {
                string pathToImage = Path.Combine(FilepathManagerInstance.ImagesDirectory, image.Filename);
                if (!File.Exists(pathToImage))
                {
                    ImagesQueue.Enqueue(image);
                }
            }
        }
 private string GetId(int cardBaseId, int level, CharacterImageFormat format)
 {
     return(cardBaseId.ToString() + level.ToString() + format.ToString());
 }
        public void SetImage(int cardBaseId, int level, BitmapImage image, CharacterImageFormat format)
        {
            string identifier = GetId(cardBaseId, level, format);

            Cache.Set(identifier, image, ItemPolicy);
        }
        public BitmapImage GetImage(int cardBaseId, int level, CharacterImageFormat format)
        {
            string identifier = GetId(cardBaseId, level, format);

            return(Cache.Get(identifier) as BitmapImage);
        }
Beispiel #10
0
 public CharacterImageIdentifier(CardBase cardBase, int level, CharacterImageFormat format)
     : this(cardBase.CardBaseId, cardBase.Name, cardBase.Clan.Name, level, format)
 {
 }
Beispiel #11
0
 public CharacterImageIdentifier(CardInstance cardInstance, CharacterImageFormat format)
     : this(cardInstance.CardBaseId, cardInstance.Name, cardInstance.Clan.Name, cardInstance.Level, format)
 {
 }