// ---------[ 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); }
// ---------[ 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); } }); }