示例#1
0
        public static string GetProxyPicture(this ICard card)
        {
            var set = card.GetSet();

            Uri uri = new System.Uri(Path.Combine(set.ProxyPackUri, card.GetImageUri() + ".png"));

            var files = Directory.GetFiles(set.ProxyPackUri, card.GetImageUri() + ".png");

            if (files.Length == 0)
            {
                card.GenerateProxyImage(set, uri.LocalPath);
                //set.GetGame().GetCardProxyDef().SaveProxyImage(card.GetProxyMappings(), uri.LocalPath);
            }

            return(uri.LocalPath);
        }
示例#2
0
        /// <summary>
        /// Returns the image file for this card in the image database. If there is no image, generate a proxy generated image and return that file path instead.
        /// <para>Respects this card's current alternate state.</para>
        /// </summary>
        public static string GetPicture(this ICard card)
        {
            if (String.IsNullOrWhiteSpace(card.ImageUri) == false && card.ImageUri.StartsWith("pack://", StringComparison.InvariantCultureIgnoreCase))
            {
                return(card.ImageUri);
            }
            var set = card.GetSet();

            Uri uri = null;

            var imageUri = card.GetImageUri();

            if (Directory.Exists(set.ImagePackUri) == false)
            {
                throw new UserMessageException(L.D.Exception__CanNotFindDirectoryGameDefBroken_Format, set.ImagePackUri);
            }
            var files = Directory.GetFiles(set.ImagePackUri, imageUri + ".*").Where(x => Path.GetFileNameWithoutExtension(x).Equals(imageUri, StringComparison.InvariantCultureIgnoreCase)).OrderBy(x => x.Length).ToArray();

            if (files.Length == 0) //Generate or grab proxy
            {
                files = Directory.GetFiles(set.ProxyPackUri, imageUri + ".png");
                if (files.Length != 0)
                {
                    uri = new Uri(files.First());
                }
            }
            else
            {
                uri = new Uri(files.First());
            }

            if (uri == null)
            {
                uri = new System.Uri(Path.Combine(set.ProxyPackUri, imageUri + ".png"));
                card.GenerateProxyImage(set, uri.LocalPath);
            }
            return(uri.LocalPath);
        }
示例#3
0
        public static string GetPicture(this ICard card)
        {
            if (String.IsNullOrWhiteSpace(card.ImageUri) == false && card.ImageUri.StartsWith("pack://", StringComparison.InvariantCultureIgnoreCase))
            {
                return(card.ImageUri);
            }
            var set = card.GetSet();

            Uri uri = null;

            var path = set.ImagePackUri;

            if (Directory.Exists(path) == false)
            {
                throw new UserMessageException(L.D.Exception__CanNotFindDirectoryGameDefBroken_Format, path);
            }
            var files = Directory.GetFiles(set.ImagePackUri, card.GetImageUri() + ".*").OrderBy(x => x.Length).ToArray();

            if (files.Length == 0) //Generate or grab proxy
            {
                files = Directory.GetFiles(set.ProxyPackUri, card.GetImageUri() + ".png");
                if (files.Length != 0)
                {
                    uri = new Uri(files.First());
                }
            }
            else
            {
                uri = new Uri(files.First());
            }

            if (uri == null)
            {
                uri = new System.Uri(Path.Combine(set.ProxyPackUri, card.GetImageUri() + ".png"));
                if (X.Instance.ReleaseTest || X.Instance.Debug)
                {
                    Stopwatch s = new Stopwatch();
                    s.Start();
                    card.GenerateProxyImage(set, uri.LocalPath);
                    //set.GetGame().GetCardProxyDef().SaveProxyImage(card.GetProxyMappings(), uri.LocalPath);
                    s.Stop();
                    if (s.ElapsedMilliseconds > 200)
                    {
                        //System.Diagnostics.Trace.TraceEvent(TraceEventType.Warning, 1|0, "Proxy gen lagged by " + s.ElapsedMilliseconds - 200 + " ms");
                        Log.WarnFormat("Proxy gen lagged by {0} ms", s.ElapsedMilliseconds - 200);
                    }
                    else
                    {
                        Log.InfoFormat("Proxy gen took {0} ms", s.ElapsedMilliseconds);
                    }
                }
                else
                {
                    card.GenerateProxyImage(set, uri.LocalPath);
                    //set.GetGame().GetCardProxyDef().SaveProxyImage(card.GetProxyMappings(), uri.LocalPath);
                }
                return(uri.LocalPath);
            }
            else
            {
                return(uri.LocalPath);
            }
        }