/// <summary>Creates the ImageDisplayData for a mod gallery image.</summary>
        public static ImageDisplayData CreateForModGalleryImage(int modId, GalleryImageLocator locator)
        {
            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = modId,
                descriptor   = ImageDescriptor.ModGalleryImage,
                imageId      = locator.GetFileName(),
                originalURL  = locator.GetSizeURL(ModGalleryImageSize.Original),
                thumbnailURL = locator.GetSizeURL(ImageDisplayData.galleryThumbnailSize),
            };

            return(retVal);
        }
Example #2
0
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModGalleryImage(int modId, GalleryImageLocator locator,
                                                   ModGalleryImageSize size,
                                                   Action <Texture2D> onImageReceived,
                                                   Action <Texture2D> onFallbackFound,
                                                   Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onImageReceived != null);

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

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

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onImageReceived, 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.SaveModGalleryImage(modId, fileName, size, texture, null);
                    }
                };
            }

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

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