1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Merge branch 'master' into realm-ruleset-store-thread-correctness

This commit is contained in:
Dean Herbert 2021-11-08 15:21:30 +09:00
commit dbdae4b033
25 changed files with 297 additions and 338 deletions

View File

@ -408,8 +408,8 @@ namespace osu.Game.Tests.Beatmaps.IO
var manager = osu.Dependencies.Get<BeatmapManager>();
// ReSharper disable once AccessToModifiedClosure
manager.ItemUpdated.BindValueChanged(_ => Interlocked.Increment(ref itemAddRemoveFireCount));
manager.ItemRemoved.BindValueChanged(_ => Interlocked.Increment(ref itemAddRemoveFireCount));
manager.ItemUpdated += _ => Interlocked.Increment(ref itemAddRemoveFireCount);
manager.ItemRemoved += _ => Interlocked.Increment(ref itemAddRemoveFireCount);
var imported = await LoadOszIntoOsu(osu);

View File

@ -10,6 +10,7 @@ using osu.Game.Scoring;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
@ -113,6 +114,36 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
}
[Resolved]
private ScoreManager scoreManager { get; set; }
[Test]
public void TestScoreImportThenDelete()
{
ILive<ScoreInfo> imported = null;
AddStep("create button without replay", () =>
{
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
});
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(true)).Result);
AddUntilStep("state is available", () => downloadButton.State.Value == DownloadState.LocallyAvailable);
AddStep("delete score", () => scoreManager.Delete(imported.Value));
AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
}
[Test]
public void CreateButtonWithNoScore()
{

View File

@ -45,10 +45,10 @@ namespace osu.Game.Tests.Visual.Online
AddStep("import soleily", () => beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()));
AddUntilStep("wait for beatmap import", () => beatmaps.GetAllUsableBeatmapSets().Any(b => b.OnlineBeatmapSetID == 241526));
AddAssert("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
AddUntilStep("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
createButtonWithBeatmap(createSoleily());
AddAssert("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
AddUntilStep("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
ensureSoleilyRemoved();
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
}

View File

@ -10,7 +10,6 @@ using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Framework.Testing;
@ -101,12 +100,20 @@ namespace osu.Game.Beatmaps
/// <summary>
/// Fired when a single difficulty has been hidden.
/// </summary>
public IBindable<WeakReference<BeatmapInfo>> BeatmapHidden => beatmapModelManager.BeatmapHidden;
public event Action<BeatmapInfo> BeatmapHidden
{
add => beatmapModelManager.BeatmapHidden += value;
remove => beatmapModelManager.BeatmapHidden -= value;
}
/// <summary>
/// Fired when a single difficulty has been restored.
/// </summary>
public IBindable<WeakReference<BeatmapInfo>> BeatmapRestored => beatmapModelManager.BeatmapRestored;
public event Action<BeatmapInfo> BeatmapRestored
{
add => beatmapModelManager.BeatmapRestored += value;
remove => beatmapModelManager.BeatmapRestored -= value;
}
/// <summary>
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
@ -198,9 +205,17 @@ namespace osu.Game.Beatmaps
return beatmapModelManager.IsAvailableLocally(model);
}
public IBindable<WeakReference<BeatmapSetInfo>> ItemUpdated => beatmapModelManager.ItemUpdated;
public event Action<BeatmapSetInfo> ItemUpdated
{
add => beatmapModelManager.ItemUpdated += value;
remove => beatmapModelManager.ItemUpdated -= value;
}
public IBindable<WeakReference<BeatmapSetInfo>> ItemRemoved => beatmapModelManager.ItemRemoved;
public event Action<BeatmapSetInfo> ItemRemoved
{
add => beatmapModelManager.ItemRemoved += value;
remove => beatmapModelManager.ItemRemoved -= value;
}
public Task ImportFromStableAsync(StableStorage stableStorage)
{
@ -246,9 +261,17 @@ namespace osu.Game.Beatmaps
#region Implementation of IModelDownloader<BeatmapSetInfo>
public IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> DownloadBegan => beatmapModelDownloader.DownloadBegan;
public event Action<ArchiveDownloadRequest<IBeatmapSetInfo>> DownloadBegan
{
add => beatmapModelDownloader.DownloadBegan += value;
remove => beatmapModelDownloader.DownloadBegan -= value;
}
public IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> DownloadFailed => beatmapModelDownloader.DownloadFailed;
public event Action<ArchiveDownloadRequest<IBeatmapSetInfo>> DownloadFailed
{
add => beatmapModelDownloader.DownloadFailed += value;
remove => beatmapModelDownloader.DownloadFailed -= value;
}
public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) =>
beatmapModelDownloader.Download(model, minimiseDownloadSize);

View File

@ -11,7 +11,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
@ -37,14 +36,12 @@ namespace osu.Game.Beatmaps
/// <summary>
/// Fired when a single difficulty has been hidden.
/// </summary>
public IBindable<WeakReference<BeatmapInfo>> BeatmapHidden => beatmapHidden;
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapHidden = new Bindable<WeakReference<BeatmapInfo>>();
public event Action<BeatmapInfo> BeatmapHidden;
/// <summary>
/// Fired when a single difficulty has been restored.
/// </summary>
public IBindable<WeakReference<BeatmapInfo>> BeatmapRestored => beatmapRestored;
public event Action<BeatmapInfo> BeatmapRestored;
/// <summary>
/// An online lookup queue component which handles populating online beatmap metadata.
@ -56,8 +53,6 @@ namespace osu.Game.Beatmaps
/// </summary>
public IWorkingBeatmapCache WorkingBeatmapCache { private get; set; }
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapRestored = new Bindable<WeakReference<BeatmapInfo>>();
public override IEnumerable<string> HandledExtensions => new[] { ".osz" };
protected override string[] HashableFileTypes => new[] { ".osu" };
@ -75,8 +70,8 @@ namespace osu.Game.Beatmaps
this.rulesets = rulesets;
beatmaps = (BeatmapStore)ModelStore;
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
beatmaps.BeatmapHidden += b => BeatmapHidden?.Invoke(b);
beatmaps.BeatmapRestored += b => BeatmapRestored?.Invoke(b);
beatmaps.ItemRemoved += b => WorkingBeatmapCache?.Invalidate(b);
beatmaps.ItemUpdated += obj => WorkingBeatmapCache?.Invalidate(obj);
}

View File

@ -10,7 +10,6 @@ using System.Threading.Tasks;
using Humanizer;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Logging;
@ -63,17 +62,13 @@ namespace osu.Game.Database
/// Fired when a new or updated <typeparamref name="TModel"/> becomes available in the database.
/// This is not guaranteed to run on the update thread.
/// </summary>
public IBindable<WeakReference<TModel>> ItemUpdated => itemUpdated;
private readonly Bindable<WeakReference<TModel>> itemUpdated = new Bindable<WeakReference<TModel>>();
public event Action<TModel> ItemUpdated;
/// <summary>
/// Fired when a <typeparamref name="TModel"/> is removed from the database.
/// This is not guaranteed to run on the update thread.
/// </summary>
public IBindable<WeakReference<TModel>> ItemRemoved => itemRemoved;
private readonly Bindable<WeakReference<TModel>> itemRemoved = new Bindable<WeakReference<TModel>>();
public event Action<TModel> ItemRemoved;
public virtual IEnumerable<string> HandledExtensions => new[] { @".zip" };
@ -93,8 +88,8 @@ namespace osu.Game.Database
ContextFactory = contextFactory;
ModelStore = modelStore;
ModelStore.ItemUpdated += item => handleEvent(() => itemUpdated.Value = new WeakReference<TModel>(item));
ModelStore.ItemRemoved += item => handleEvent(() => itemRemoved.Value = new WeakReference<TModel>(item));
ModelStore.ItemUpdated += item => handleEvent(() => ItemUpdated?.Invoke(item));
ModelStore.ItemRemoved += item => handleEvent(() => ItemRemoved?.Invoke(item));
exportStorage = storage.GetStorageForDirectory(@"exports");

View File

@ -3,7 +3,6 @@
using System;
using osu.Game.Online.API;
using osu.Framework.Bindables;
namespace osu.Game.Database
{
@ -18,13 +17,13 @@ namespace osu.Game.Database
/// Fired when a <typeparamref name="T"/> download begins.
/// This is NOT run on the update thread and should be scheduled.
/// </summary>
IBindable<WeakReference<ArchiveDownloadRequest<T>>> DownloadBegan { get; }
event Action<ArchiveDownloadRequest<T>> DownloadBegan;
/// <summary>
/// Fired when a <typeparamref name="T"/> download is interrupted, either due to user cancellation or failure.
/// This is NOT run on the update thread and should be scheduled.
/// </summary>
IBindable<WeakReference<ArchiveDownloadRequest<T>>> DownloadFailed { get; }
event Action<ArchiveDownloadRequest<T>> DownloadFailed;
/// <summary>
/// Begin a download for the requested <typeparamref name="T"/>.

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using osu.Framework.Bindables;
using osu.Game.IO;
namespace osu.Game.Database
@ -18,16 +17,14 @@ namespace osu.Game.Database
where TModel : class
{
/// <summary>
/// A bindable which contains a weak reference to the last item that was updated.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// Fired when an item is updated.
/// </summary>
IBindable<WeakReference<TModel>> ItemUpdated { get; }
event Action<TModel> ItemUpdated;
/// <summary>
/// A bindable which contains a weak reference to the last item that was removed.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// Fired when an item is removed.
/// </summary>
IBindable<WeakReference<TModel>> ItemRemoved { get; }
event Action<TModel> ItemRemoved;
/// <summary>
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Humanizer;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Online.API;
@ -20,13 +19,9 @@ namespace osu.Game.Database
{
public Action<Notification> PostNotification { protected get; set; }
public IBindable<WeakReference<ArchiveDownloadRequest<T>>> DownloadBegan => downloadBegan;
public event Action<ArchiveDownloadRequest<T>> DownloadBegan;
private readonly Bindable<WeakReference<ArchiveDownloadRequest<T>>> downloadBegan = new Bindable<WeakReference<ArchiveDownloadRequest<T>>>();
public IBindable<WeakReference<ArchiveDownloadRequest<T>>> DownloadFailed => downloadFailed;
private readonly Bindable<WeakReference<ArchiveDownloadRequest<T>>> downloadFailed = new Bindable<WeakReference<ArchiveDownloadRequest<T>>>();
public event Action<ArchiveDownloadRequest<T>> DownloadFailed;
private readonly IModelImporter<TModel> importer;
private readonly IAPIProvider api;
@ -73,7 +68,7 @@ namespace osu.Game.Database
// for now a failed import will be marked as a failed download for simplicity.
if (!imported.Any())
downloadFailed.Value = new WeakReference<ArchiveDownloadRequest<T>>(request);
DownloadFailed?.Invoke(request);
CurrentDownloads.Remove(request);
}, TaskCreationOptions.LongRunning);
@ -92,14 +87,14 @@ namespace osu.Game.Database
api.PerformAsync(request);
downloadBegan.Value = new WeakReference<ArchiveDownloadRequest<T>>(request);
DownloadBegan?.Invoke(request);
return true;
void triggerFailure(Exception error)
{
CurrentDownloads.Remove(request);
downloadFailed.Value = new WeakReference<ArchiveDownloadRequest<T>>(request);
DownloadFailed?.Invoke(request);
notification.State = ProgressNotificationState.Cancelled;

View File

@ -46,7 +46,7 @@ namespace osu.Game.Graphics.Containers
AddText(text[previousLinkEnd..link.Index]);
string displayText = text.Substring(link.Index, link.Length);
string linkArgument = link.Argument;
object linkArgument = link.Argument;
string tooltip = displayText == link.Url ? null : link.Url;
AddLink(displayText, link.Action, linkArgument, tooltip);
@ -62,16 +62,16 @@ namespace osu.Game.Graphics.Containers
public void AddLink(LocalisableString text, Action action, string tooltipText = null, Action<SpriteText> creationParameters = null)
=> createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action);
public void AddLink(LocalisableString text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
public void AddLink(LocalisableString text, LinkAction action, object argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
=> createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(action, argument), tooltipText);
public void AddLink(IEnumerable<SpriteText> text, LinkAction action, string linkArgument, string tooltipText = null)
public void AddLink(IEnumerable<SpriteText> text, LinkAction action, object linkArgument, string tooltipText = null)
{
createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText);
}
public void AddUserLink(IUser user, Action<SpriteText> creationParameters = null)
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.OnlineID.ToString()), "view profile");
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user), "view profile");
private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
{
@ -83,7 +83,7 @@ namespace osu.Game.Graphics.Containers
game.HandleLink(link);
// fallback to handle cases where OsuGame is not available, ie. tournament client.
else if (link.Action == LinkAction.External)
host.OpenUrlExternally(link.Argument);
host.OpenUrlExternally(link.Argument.ToString());
};
AddPart(new TextLink(textPart, tooltipText, onClickAction));

View File

@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
@ -23,11 +22,6 @@ namespace osu.Game.Online
{
}
private IBindable<WeakReference<BeatmapSetInfo>>? managerUpdated;
private IBindable<WeakReference<BeatmapSetInfo>>? managerRemoved;
private IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>>? managerDownloadBegan;
private IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>>? managerDownloadFailed;
[BackgroundDependencyLoader(true)]
private void load()
{
@ -42,39 +36,23 @@ namespace osu.Game.Online
else
attachDownload(Manager.GetExistingDownload(beatmapSetInfo));
managerDownloadBegan = Manager.DownloadBegan.GetBoundCopy();
managerDownloadBegan.BindValueChanged(downloadBegan);
managerDownloadFailed = Manager.DownloadFailed.GetBoundCopy();
managerDownloadFailed.BindValueChanged(downloadFailed);
managerUpdated = Manager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(itemUpdated);
managerRemoved = Manager.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(itemRemoved);
Manager.DownloadBegan += downloadBegan;
Manager.DownloadFailed += downloadFailed;
Manager.ItemUpdated += itemUpdated;
Manager.ItemRemoved += itemRemoved;
}
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> weakRequest)
private void downloadBegan(ArchiveDownloadRequest<IBeatmapSetInfo> request) => Schedule(() =>
{
if (weakRequest.NewValue.TryGetTarget(out var request))
{
Schedule(() =>
{
if (checkEquality(request.Model, TrackedItem))
attachDownload(request);
});
}
}
if (checkEquality(request.Model, TrackedItem))
attachDownload(request);
});
private void downloadFailed(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> weakRequest)
private void downloadFailed(ArchiveDownloadRequest<IBeatmapSetInfo> request) => Schedule(() =>
{
if (weakRequest.NewValue.TryGetTarget(out var request))
{
Schedule(() =>
{
if (checkEquality(request.Model, TrackedItem))
attachDownload(null);
});
}
}
if (checkEquality(request.Model, TrackedItem))
attachDownload(null);
});
private void attachDownload(ArchiveDownloadRequest<IBeatmapSetInfo>? request)
{
@ -116,29 +94,17 @@ namespace osu.Game.Online
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));
private void itemUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakItem)
private void itemUpdated(BeatmapSetInfo item) => Schedule(() =>
{
if (weakItem.NewValue.TryGetTarget(out var item))
{
Schedule(() =>
{
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.LocallyAvailable);
});
}
}
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.LocallyAvailable);
});
private void itemRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakItem)
private void itemRemoved(BeatmapSetInfo item) => Schedule(() =>
{
if (weakItem.NewValue.TryGetTarget(out var item))
{
Schedule(() =>
{
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.NotDownloaded);
});
}
}
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.NotDownloaded);
});
private bool checkEquality(IBeatmapSetInfo x, IBeatmapSetInfo y) => x.OnlineID == y.OnlineID;
@ -148,6 +114,14 @@ namespace osu.Game.Online
{
base.Dispose(isDisposing);
attachDownload(null);
if (Manager != null)
{
Manager.DownloadBegan -= downloadBegan;
Manager.DownloadFailed -= downloadFailed;
Manager.ItemUpdated -= itemUpdated;
Manager.ItemRemoved -= itemRemoved;
}
}
#endregion

View File

@ -320,9 +320,9 @@ namespace osu.Game.Online.Chat
{
public readonly LinkAction Action;
public readonly string Argument;
public readonly object Argument;
public LinkDetails(LinkAction action, string argument)
public LinkDetails(LinkAction action, object argument)
{
Action = action;
Argument = argument;
@ -351,9 +351,9 @@ namespace osu.Game.Online.Chat
public int Index;
public int Length;
public LinkAction Action;
public string Argument;
public object Argument;
public Link(string url, int startIndex, int length, LinkAction action, string argument)
public Link(string url, int startIndex, int length, LinkAction action, object argument)
{
Url = url;
Index = startIndex;

View File

@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online.API;
using osu.Game.Scoring;
@ -23,11 +22,6 @@ namespace osu.Game.Online
{
}
private IBindable<WeakReference<ScoreInfo>>? managerUpdated;
private IBindable<WeakReference<ScoreInfo>>? managerRemoved;
private IBindable<WeakReference<ArchiveDownloadRequest<IScoreInfo>>>? managerDownloadBegan;
private IBindable<WeakReference<ArchiveDownloadRequest<IScoreInfo>>>? managerDownloadFailed;
[BackgroundDependencyLoader(true)]
private void load()
{
@ -46,39 +40,23 @@ namespace osu.Game.Online
else
attachDownload(Manager.GetExistingDownload(scoreInfo));
managerDownloadBegan = Manager.DownloadBegan.GetBoundCopy();
managerDownloadBegan.BindValueChanged(downloadBegan);
managerDownloadFailed = Manager.DownloadFailed.GetBoundCopy();
managerDownloadFailed.BindValueChanged(downloadFailed);
managerUpdated = Manager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(itemUpdated);
managerRemoved = Manager.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(itemRemoved);
Manager.DownloadBegan += downloadBegan;
Manager.DownloadFailed += downloadFailed;
Manager.ItemUpdated += itemUpdated;
Manager.ItemRemoved += itemRemoved;
}
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<IScoreInfo>>> weakRequest)
private void downloadBegan(ArchiveDownloadRequest<IScoreInfo> request) => Schedule(() =>
{
if (weakRequest.NewValue.TryGetTarget(out var request))
{
Schedule(() =>
{
if (checkEquality(request.Model, TrackedItem))
attachDownload(request);
});
}
}
if (checkEquality(request.Model, TrackedItem))
attachDownload(request);
});
private void downloadFailed(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<IScoreInfo>>> weakRequest)
private void downloadFailed(ArchiveDownloadRequest<IScoreInfo> request) => Schedule(() =>
{
if (weakRequest.NewValue.TryGetTarget(out var request))
{
Schedule(() =>
{
if (checkEquality(request.Model, TrackedItem))
attachDownload(null);
});
}
}
if (checkEquality(request.Model, TrackedItem))
attachDownload(null);
});
private void attachDownload(ArchiveDownloadRequest<IScoreInfo>? request)
{
@ -120,29 +98,17 @@ namespace osu.Game.Online
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));
private void itemUpdated(ValueChangedEvent<WeakReference<ScoreInfo>> weakItem)
private void itemUpdated(ScoreInfo item) => Schedule(() =>
{
if (weakItem.NewValue.TryGetTarget(out var item))
{
Schedule(() =>
{
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.LocallyAvailable);
});
}
}
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.LocallyAvailable);
});
private void itemRemoved(ValueChangedEvent<WeakReference<ScoreInfo>> weakItem)
private void itemRemoved(ScoreInfo item) => Schedule(() =>
{
if (weakItem.NewValue.TryGetTarget(out var item))
{
Schedule(() =>
{
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.NotDownloaded);
});
}
}
if (checkEquality(item, TrackedItem))
UpdateState(DownloadState.NotDownloaded);
});
private bool checkEquality(IScoreInfo x, IScoreInfo y) => x.OnlineID == y.OnlineID;
@ -152,6 +118,14 @@ namespace osu.Game.Online
{
base.Dispose(isDisposing);
attachDownload(null);
if (Manager != null)
{
Manager.DownloadBegan -= downloadBegan;
Manager.DownloadFailed -= downloadFailed;
Manager.ItemUpdated -= itemUpdated;
Manager.ItemRemoved -= itemRemoved;
}
}
#endregion

View File

@ -289,25 +289,27 @@ namespace osu.Game
/// <param name="link">The link to load.</param>
public void HandleLink(LinkDetails link) => Schedule(() =>
{
string argString = link.Argument.ToString();
switch (link.Action)
{
case LinkAction.OpenBeatmap:
// TODO: proper query params handling
if (int.TryParse(link.Argument.Contains('?') ? link.Argument.Split('?')[0] : link.Argument, out int beatmapId))
if (int.TryParse(argString.Contains('?') ? argString.Split('?')[0] : argString, out int beatmapId))
ShowBeatmap(beatmapId);
break;
case LinkAction.OpenBeatmapSet:
if (int.TryParse(link.Argument, out int setId))
if (int.TryParse(argString, out int setId))
ShowBeatmapSet(setId);
break;
case LinkAction.OpenChannel:
ShowChannel(link.Argument);
ShowChannel(argString);
break;
case LinkAction.SearchBeatmapSet:
SearchBeatmapSet(link.Argument);
SearchBeatmapSet(argString);
break;
case LinkAction.OpenEditorTimestamp:
@ -321,26 +323,31 @@ namespace osu.Game
break;
case LinkAction.External:
OpenUrlExternally(link.Argument);
OpenUrlExternally(argString);
break;
case LinkAction.OpenUserProfile:
ShowUser(int.TryParse(link.Argument, out int userId)
? new APIUser { Id = userId }
: new APIUser { Username = link.Argument });
if (!(link.Argument is IUser user))
{
user = int.TryParse(argString, out int userId)
? new APIUser { Id = userId }
: new APIUser { Username = argString };
}
ShowUser(user);
break;
case LinkAction.OpenWiki:
ShowWiki(link.Argument);
ShowWiki(argString);
break;
case LinkAction.OpenChangelog:
if (string.IsNullOrEmpty(link.Argument))
if (string.IsNullOrEmpty(argString))
ShowChangelogListing();
else
{
string[] changelogArgs = link.Argument.Split("/");
string[] changelogArgs = argString.Split("/");
ShowChangelogBuild(changelogArgs[0], changelogArgs[1]);
}

View File

@ -207,17 +207,11 @@ namespace osu.Game
dependencies.CacheAs<ISkinSource>(SkinManager);
// needs to be done here rather than inside SkinManager to ensure thread safety of CurrentSkinInfo.
SkinManager.ItemRemoved.BindValueChanged(weakRemovedInfo =>
SkinManager.ItemRemoved += item => Schedule(() =>
{
if (weakRemovedInfo.NewValue.TryGetTarget(out var removedInfo))
{
Schedule(() =>
{
// check the removed skin is not the current user choice. if it is, switch back to default.
if (removedInfo.ID == SkinManager.CurrentSkinInfo.Value.ID)
SkinManager.CurrentSkinInfo.Value = SkinInfo.Default;
});
}
// check the removed skin is not the current user choice. if it is, switch back to default.
if (item.ID == SkinManager.CurrentSkinInfo.Value.ID)
SkinManager.CurrentSkinInfo.Value = SkinInfo.Default;
});
EndpointConfiguration endpoints = UseDevelopmentServer ? (EndpointConfiguration)new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
@ -252,17 +246,8 @@ namespace osu.Game
return ScoreManager.QueryScores(s => beatmapIds.Contains(s.BeatmapInfo.ID)).ToList();
}
BeatmapManager.ItemRemoved.BindValueChanged(i =>
{
if (i.NewValue.TryGetTarget(out var item))
ScoreManager.Delete(getBeatmapScores(item), true);
});
BeatmapManager.ItemUpdated.BindValueChanged(i =>
{
if (i.NewValue.TryGetTarget(out var item))
ScoreManager.Undelete(getBeatmapScores(item), true);
});
BeatmapManager.ItemRemoved += item => ScoreManager.Delete(getBeatmapScores(item), true);
BeatmapManager.ItemUpdated += item => ScoreManager.Undelete(getBeatmapScores(item), true);
dependencies.Cache(difficultyCache = new BeatmapDifficultyCache());
AddInternal(difficultyCache);

View File

@ -209,7 +209,7 @@ namespace osu.Game.Overlays.Chat
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
// remove non-existent channels from the link list
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument) != true);
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);
ContentFlow.Clear();
ContentFlow.AddLinks(message.DisplayContent, message.Links);

View File

@ -65,16 +65,11 @@ namespace osu.Game.Overlays
[NotNull]
public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000));
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
[BackgroundDependencyLoader]
private void load()
{
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(beatmapRemoved);
beatmaps.ItemUpdated += beatmapUpdated;
beatmaps.ItemRemoved += beatmapRemoved;
beatmapSets.AddRange(beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal, true).OrderBy(_ => RNG.Next()));
@ -110,28 +105,13 @@ namespace osu.Game.Overlays
/// </summary>
public bool TrackLoaded => CurrentTrack.TrackLoaded;
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
private void beatmapUpdated(BeatmapSetInfo set) => Schedule(() =>
{
if (weakSet.NewValue.TryGetTarget(out var set))
{
Schedule(() =>
{
beatmapSets.Remove(set);
beatmapSets.Add(set);
});
}
}
beatmapSets.Remove(set);
beatmapSets.Add(set);
});
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
{
if (weakSet.NewValue.TryGetTarget(out var set))
{
Schedule(() =>
{
beatmapSets.RemoveAll(s => s.ID == set.ID);
});
}
}
private void beatmapRemoved(BeatmapSetInfo set) => Schedule(() => beatmapSets.RemoveAll(s => s.ID == set.ID));
private ScheduledDelegate seekDelegate;
@ -437,6 +417,17 @@ namespace osu.Game.Overlays
mod.ApplyToTrack(CurrentTrack);
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmaps != null)
{
beatmaps.ItemUpdated -= beatmapUpdated;
beatmaps.ItemRemoved -= beatmapRemoved;
}
}
}
public enum TrackChangeDirection

View File

@ -216,7 +216,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
private void addBeatmapsetLink()
=> content.AddLink(activity.Beatmapset?.Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset?.Url), creationParameters: t => t.Font = getLinkFont());
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument;
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument.ToString();
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);

View File

@ -56,9 +56,6 @@ namespace osu.Game.Overlays.Settings.Sections
[Resolved]
private SkinManager skins { get; set; }
private IBindable<WeakReference<SkinInfo>> managerUpdated;
private IBindable<WeakReference<SkinInfo>> managerRemoved;
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuConfigManager config, [CanBeNull] SkinEditorOverlay skinEditor)
{
@ -76,11 +73,8 @@ namespace osu.Game.Overlays.Settings.Sections
new ExportSkinButton(),
};
managerUpdated = skins.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(itemUpdated);
managerRemoved = skins.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(itemRemoved);
skins.ItemUpdated += itemUpdated;
skins.ItemRemoved += itemRemoved;
config.BindWith(OsuSetting.Skin, configBindable);
@ -129,11 +123,7 @@ namespace osu.Game.Overlays.Settings.Sections
skinDropdown.Items = skinItems;
}
private void itemUpdated(ValueChangedEvent<WeakReference<SkinInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var item))
Schedule(() => addItem(item));
}
private void itemUpdated(SkinInfo item) => Schedule(() => addItem(item));
private void addItem(SkinInfo item)
{
@ -142,11 +132,7 @@ namespace osu.Game.Overlays.Settings.Sections
skinDropdown.Items = newDropdownItems;
}
private void itemRemoved(ValueChangedEvent<WeakReference<SkinInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var item))
Schedule(() => skinDropdown.Items = skinDropdown.Items.Where(i => i.ID != item.ID).ToArray());
}
private void itemRemoved(SkinInfo item) => Schedule(() => skinDropdown.Items = skinDropdown.Items.Where(i => i.ID != item.ID).ToArray());
private void sortUserSkins(List<SkinInfo> skinsList)
{
@ -155,6 +141,17 @@ namespace osu.Game.Overlays.Settings.Sections
Comparer<SkinInfo>.Create((a, b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)));
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (skins != null)
{
skins.ItemUpdated -= itemUpdated;
skins.ItemRemoved -= itemRemoved;
}
}
private class SkinSettingsDropdown : SettingsDropdown<SkinInfo>
{
protected override OsuDropdown<SkinInfo> CreateDropdown() => new SkinDropdownControl();

View File

@ -246,9 +246,17 @@ namespace osu.Game.Scoring
#region Implementation of IModelManager<ScoreInfo>
public IBindable<WeakReference<ScoreInfo>> ItemUpdated => scoreModelManager.ItemUpdated;
public event Action<ScoreInfo> ItemUpdated
{
add => scoreModelManager.ItemUpdated += value;
remove => scoreModelManager.ItemUpdated -= value;
}
public IBindable<WeakReference<ScoreInfo>> ItemRemoved => scoreModelManager.ItemRemoved;
public event Action<ScoreInfo> ItemRemoved
{
add => scoreModelManager.ItemRemoved += value;
remove => scoreModelManager.ItemRemoved -= value;
}
public Task ImportFromStableAsync(StableStorage stableStorage)
{
@ -348,11 +356,19 @@ namespace osu.Game.Scoring
#endregion
#region Implementation of IModelDownloader<ScoreInfo>
#region Implementation of IModelDownloader<IScoreInfo>
public IBindable<WeakReference<ArchiveDownloadRequest<IScoreInfo>>> DownloadBegan => scoreModelDownloader.DownloadBegan;
public event Action<ArchiveDownloadRequest<IScoreInfo>> DownloadBegan
{
add => scoreModelDownloader.DownloadBegan += value;
remove => scoreModelDownloader.DownloadBegan -= value;
}
public IBindable<WeakReference<ArchiveDownloadRequest<IScoreInfo>>> DownloadFailed => scoreModelDownloader.DownloadFailed;
public event Action<ArchiveDownloadRequest<IScoreInfo>> DownloadFailed
{
add => scoreModelDownloader.DownloadFailed += value;
remove => scoreModelDownloader.DownloadFailed -= value;
}
public bool Download(IScoreInfo model, bool minimiseDownloadSize) =>
scoreModelDownloader.Download(model, minimiseDownloadSize);

View File

@ -62,8 +62,6 @@ namespace osu.Game.Screens.OnlinePlay.Match
[Resolved(canBeNull: true)]
protected OnlinePlayScreen ParentScreen { get; private set; }
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
[Cached]
private OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker { get; set; }
@ -246,8 +244,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
beatmapManager.ItemUpdated += beatmapUpdated;
UserMods.BindValueChanged(_ => Scheduler.AddOnce(UpdateMods));
}
@ -362,7 +359,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
}
}
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap);
private void beatmapUpdated(BeatmapSetInfo set) => Schedule(updateWorkingBeatmap);
private void updateWorkingBeatmap()
{
@ -431,6 +428,14 @@ namespace osu.Game.Screens.OnlinePlay.Match
/// <param name="room">The room to change the settings of.</param>
protected abstract RoomSettingsOverlay CreateRoomSettingsOverlay(Room room);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmapManager != null)
beatmapManager.ItemUpdated -= beatmapUpdated;
}
public class UserModSelectButton : PurpleTriangleButton
{
}

View File

@ -143,11 +143,6 @@ namespace osu.Game.Screens.Select
private CarouselRoot root;
private IBindable<WeakReference<BeatmapSetInfo>> itemUpdated;
private IBindable<WeakReference<BeatmapSetInfo>> itemRemoved;
private IBindable<WeakReference<BeatmapInfo>> itemHidden;
private IBindable<WeakReference<BeatmapInfo>> itemRestored;
private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100);
public BeatmapCarousel()
@ -179,14 +174,10 @@ namespace osu.Game.Screens.Select
RightClickScrollingEnabled.ValueChanged += enabled => Scroll.RightMouseScrollbar = enabled.NewValue;
RightClickScrollingEnabled.TriggerChange();
itemUpdated = beatmaps.ItemUpdated.GetBoundCopy();
itemUpdated.BindValueChanged(beatmapUpdated);
itemRemoved = beatmaps.ItemRemoved.GetBoundCopy();
itemRemoved.BindValueChanged(beatmapRemoved);
itemHidden = beatmaps.BeatmapHidden.GetBoundCopy();
itemHidden.BindValueChanged(beatmapHidden);
itemRestored = beatmaps.BeatmapRestored.GetBoundCopy();
itemRestored.BindValueChanged(beatmapRestored);
beatmaps.ItemUpdated += beatmapUpdated;
beatmaps.ItemRemoved += beatmapRemoved;
beatmaps.BeatmapHidden += beatmapHidden;
beatmaps.BeatmapRestored += beatmapRestored;
if (!beatmapSets.Any())
loadBeatmapSets(GetLoadableBeatmaps());
@ -675,29 +666,10 @@ namespace osu.Game.Screens.Select
return (firstIndex, lastIndex);
}
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var item))
RemoveBeatmapSet(item);
}
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var item))
UpdateBeatmapSet(item);
}
private void beatmapRestored(ValueChangedEvent<WeakReference<BeatmapInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var b))
UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
}
private void beatmapHidden(ValueChangedEvent<WeakReference<BeatmapInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var b))
UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
}
private void beatmapRemoved(BeatmapSetInfo item) => RemoveBeatmapSet(item);
private void beatmapUpdated(BeatmapSetInfo item) => UpdateBeatmapSet(item);
private void beatmapRestored(BeatmapInfo b) => UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
private void beatmapHidden(BeatmapInfo b) => UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
{
@ -956,5 +928,18 @@ namespace osu.Game.Screens.Select
return base.OnDragStart(e);
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmaps != null)
{
beatmaps.ItemUpdated -= beatmapUpdated;
beatmaps.ItemRemoved -= beatmapRemoved;
beatmaps.BeatmapHidden -= beatmapHidden;
beatmaps.BeatmapRestored -= beatmapRestored;
}
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -28,9 +27,6 @@ namespace osu.Game.Screens.Select.Carousel
[Resolved]
private IAPIProvider api { get; set; }
private IBindable<WeakReference<ScoreInfo>> itemUpdated;
private IBindable<WeakReference<ScoreInfo>> itemRemoved;
public TopLocalRank(BeatmapInfo beatmapInfo)
: base(null)
{
@ -40,24 +36,18 @@ namespace osu.Game.Screens.Select.Carousel
[BackgroundDependencyLoader]
private void load()
{
itemUpdated = scores.ItemUpdated.GetBoundCopy();
itemUpdated.BindValueChanged(scoreChanged);
itemRemoved = scores.ItemRemoved.GetBoundCopy();
itemRemoved.BindValueChanged(scoreChanged);
scores.ItemUpdated += scoreChanged;
scores.ItemRemoved += scoreChanged;
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
fetchAndLoadTopScore();
}
private void scoreChanged(ValueChangedEvent<WeakReference<ScoreInfo>> weakScore)
private void scoreChanged(ScoreInfo score)
{
if (weakScore.NewValue.TryGetTarget(out var score))
{
if (score.BeatmapInfoID == beatmapInfo.ID)
fetchAndLoadTopScore();
}
if (score.BeatmapInfoID == beatmapInfo.ID)
fetchAndLoadTopScore();
}
private ScheduledDelegate scheduledRankUpdate;
@ -86,5 +76,16 @@ namespace osu.Game.Screens.Select.Carousel
.OrderByDescending(s => s.TotalScore)
.FirstOrDefault();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scores != null)
{
scores.ItemUpdated -= scoreChanged;
scores.ItemRemoved -= scoreChanged;
}
}
}
}

View File

@ -44,10 +44,6 @@ namespace osu.Game.Screens.Select.Leaderboards
private bool filterMods;
private IBindable<WeakReference<ScoreInfo>> itemRemoved;
private IBindable<WeakReference<ScoreInfo>> itemAdded;
/// <summary>
/// Whether to apply the game's currently selected mods as a filter when retrieving scores.
/// </summary>
@ -90,11 +86,8 @@ namespace osu.Game.Screens.Select.Leaderboards
UpdateScores();
};
itemRemoved = scoreManager.ItemRemoved.GetBoundCopy();
itemRemoved.BindValueChanged(onScoreRemoved);
itemAdded = scoreManager.ItemUpdated.GetBoundCopy();
itemAdded.BindValueChanged(onScoreAdded);
scoreManager.ItemRemoved += scoreStoreChanged;
scoreManager.ItemUpdated += scoreStoreChanged;
}
protected override void Reset()
@ -103,22 +96,13 @@ namespace osu.Game.Screens.Select.Leaderboards
TopScore = null;
}
private void onScoreRemoved(ValueChangedEvent<WeakReference<ScoreInfo>> score) =>
scoreStoreChanged(score);
private void onScoreAdded(ValueChangedEvent<WeakReference<ScoreInfo>> score) =>
scoreStoreChanged(score);
private void scoreStoreChanged(ValueChangedEvent<WeakReference<ScoreInfo>> score)
private void scoreStoreChanged(ScoreInfo score)
{
if (Scope != BeatmapLeaderboardScope.Local)
return;
if (score.NewValue.TryGetTarget(out var scoreInfo))
{
if (BeatmapInfo?.ID != scoreInfo.BeatmapInfoID)
return;
}
if (BeatmapInfo?.ID != score.BeatmapInfoID)
return;
RefreshScores();
}
@ -215,5 +199,16 @@ namespace osu.Game.Screens.Select.Leaderboards
{
Action = () => ScoreSelected?.Invoke(model)
};
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scoreManager != null)
{
scoreManager.ItemRemoved -= scoreStoreChanged;
scoreManager.ItemUpdated -= scoreStoreChanged;
}
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -45,8 +44,6 @@ namespace osu.Game.Screens.Spectate
private readonly Dictionary<int, APIUser> userMap = new Dictionary<int, APIUser>();
private readonly Dictionary<int, SpectatorGameplayState> gameplayStates = new Dictionary<int, SpectatorGameplayState>();
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
/// <summary>
/// Creates a new <see cref="SpectatorScreen"/>.
/// </summary>
@ -73,20 +70,16 @@ namespace osu.Game.Screens.Spectate
playingUserStates.BindTo(spectatorClient.PlayingUserStates);
playingUserStates.BindCollectionChanged(onPlayingUserStatesChanged, true);
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
beatmaps.ItemUpdated += beatmapUpdated;
foreach ((int id, var _) in userMap)
spectatorClient.WatchUser(id);
}));
}
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> e)
private void beatmapUpdated(BeatmapSetInfo beatmapSet)
{
if (!e.NewValue.TryGetTarget(out var beatmapSet))
return;
foreach ((int userId, var _) in userMap)
foreach ((int userId, _) in userMap)
{
if (!playingUserStates.TryGetValue(userId, out var userState))
continue;
@ -223,7 +216,8 @@ namespace osu.Game.Screens.Spectate
spectatorClient.StopWatchingUser(userId);
}
managerUpdated?.UnbindAll();
if (beatmaps != null)
beatmaps.ItemUpdated -= beatmapUpdated;
}
}
}