Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge last few changes + version bump
Browse files Browse the repository at this point in the history
Qwasyx committed Nov 28, 2023
2 parents c798496 + c3ec957 commit c86c911
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 22 additions & 13 deletions ScoreSaber/UI/Elements/Leaderboard/ProfilePictureView.cs
Original file line number Diff line number Diff line change
@@ -39,59 +39,68 @@ public void Parsed() {

public void setProfileImage(string url, int pos, CancellationToken cancellationToken) {
try {
cancellationToken.ThrowIfCancellationRequested();
if (SpriteCache.cachedSprites.ContainsKey(url)) {
profileImage.gameObject.SetActive(true);
profileImage.sprite = SpriteCache.cachedSprites[url];
loadingIndicator.gameObject.SetActive(false);
return;
}

loadingIndicator.gameObject.SetActive(true);
SharedCoroutineStarter.instance.StartCoroutine(GetSpriteAvatar(url, OnAvatarDownloadSuccess, OnAvatarDownloadFailure, cancellationToken, pos));
} catch (OperationCanceledException) {
OnAvatarDownloadFailure("Cancelled", pos);
OnAvatarDownloadFailure("Cancelled", pos, cancellationToken);
} finally {
SpriteCache.MaintainSpriteCache();
}
}

internal static IEnumerator GetSpriteAvatar(string url, Action<Sprite, int, string> onSuccess, Action<string, int> onFailure, CancellationToken cancellationToken, int pos) {
internal static IEnumerator GetSpriteAvatar(string url, Action<Sprite, int, string, CancellationToken> onSuccess, Action<string, int, CancellationToken> onFailure, CancellationToken cancellationToken, int pos) {
var handler = new DownloadHandlerTexture();
var www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
www.downloadHandler = handler;
cancellationToken.ThrowIfCancellationRequested();
yield return www.SendWebRequest();

while (!www.isDone) {
if (cancellationToken.IsCancellationRequested) {
onFailure?.Invoke("Cancelled", pos);
onFailure?.Invoke("Cancelled", pos, cancellationToken);
yield break;
}

yield return null;
}
if (www.isNetworkError || www.isHttpError) {
onFailure?.Invoke(www.error, pos);
yield break;
}
if (!string.IsNullOrEmpty(www.error)) {
onFailure?.Invoke(www.error, pos);
onFailure?.Invoke(www.error, pos, cancellationToken);
yield break;
}

Sprite sprite = Sprite.Create(handler.texture, new Rect(0, 0, handler.texture.width, handler.texture.height), Vector2.one * 0.5f);
onSuccess?.Invoke(sprite, pos, url);
onSuccess?.Invoke(sprite, pos, url, cancellationToken);
yield break;
}

internal void OnAvatarDownloadSuccess(Sprite a, int pos, string url) {
internal void OnAvatarDownloadSuccess(Sprite a, int pos, string url, CancellationToken cancellationToken) {
SpriteCache.AddSpriteToCache(url, a);
if (cancellationToken != null) {
if (cancellationToken.IsCancellationRequested) {
return;
}
}
profileImage.gameObject.SetActive(true);
profileImage.sprite = a;
loadingIndicator.gameObject.SetActive(false);
SpriteCache.AddSpriteToCache(url, a);
}

internal void OnAvatarDownloadFailure(string error, int pos) {
loadingIndicator.gameObject.SetActive(false);
profileImage.gameObject.SetActive(false);
internal void OnAvatarDownloadFailure(string error, int pos, CancellationToken cancellationToken) {
if (cancellationToken != null) {
if (cancellationToken.IsCancellationRequested) {
return;
}
}
ClearSprite();
}

public void ClearSprite() {
2 changes: 1 addition & 1 deletion ScoreSaber/manifest.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
"icon": "ScoreSaber.logo.png",
"id": "ScoreSaber",
"name": "ScoreSaber",
"version": "3.2.15",
"version": "3.3.0",
"dependsOn": {
"BSIPA": "^4.1.6",
"BeatSaberMarkupLanguage": "^1.5.3",

0 comments on commit c86c911

Please sign in to comment.