Beispiel #1
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

            // set loading function
            Func <Texture2D> loadFromDisk = () => CacheClient.LoadModLogo(modId, locator.GetFileName(), size);

            // set saving function
            Action <Texture2D> saveToDisk = null;

            if (this.storeIfSubscribed)
            {
                saveToDisk = (t) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModLogo(modId, locator.GetFileName(), size, t);
                    }
                };
            }

            // do the work
            this.RequestImage_Internal(locator, size, loadFromDisk, saveToDisk,
                                       onLogoReceived, onFallbackFound, onError);
        }
        // ---------[ GENERATION ]---------
        /// <summary>Creates the ImageDisplayData for a mod logo.</summary>
        public static ImageDisplayData CreateForModLogo(int modId, LogoImageLocator locator)
        {
            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = modId,
                descriptor   = ImageDescriptor.ModLogo,
                imageId      = locator.GetFileName(),
                originalURL  = locator.GetSizeURL(LogoSize.Original),
                thumbnailURL = locator.GetSizeURL(ImageDisplayData.logoThumbnailSize),
            };

            return(retVal);
        }
Beispiel #3
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

            string url      = locator.GetSizeURL(size);
            string fileName = locator.GetFileName();

            // check cache and existing callbacks
            if (this.TryGetCacheOrSetCallbacks(url, onLogoReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onLogoReceived, onError);

            // check for fallback
            callbacks.fallback = this.FindFallbackTexture(locator);

            if (onFallbackFound != null &&
                callbacks.fallback != null)
            {
                onFallbackFound.Invoke(callbacks.fallback);
            }

            // add save function to download callback
            if (this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModLogo(modId, fileName, size, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModLogo(modId, fileName, size, (texture) =>
            {
                if (this == null)
                {
                    return;
                }

                if (texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }