mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 09:37:23 +08:00
Add overridable method for verifying models in database
This commit is contained in:
parent
d9034eab26
commit
04d17aadfa
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -65,6 +66,15 @@ namespace osu.Game.Online
|
|||||||
managerRemoved.BindValueChanged(itemRemoved);
|
managerRemoved.BindValueChanged(itemRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that the given databased model is in a correct state to be considered available.
|
||||||
|
/// </summary>
|
||||||
|
/// <example>
|
||||||
|
/// In the case of multiplayer/playlists, this has to verify that the databased beatmap set with the selected beatmap matches what's online.
|
||||||
|
/// </example>
|
||||||
|
/// <param name="databasedModel">The model in database.</param>
|
||||||
|
protected virtual bool VerifyDatabasedModel([NotNull] TModel databasedModel) => true;
|
||||||
|
|
||||||
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest)
|
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest)
|
||||||
{
|
{
|
||||||
if (weakRequest.NewValue.TryGetTarget(out var request))
|
if (weakRequest.NewValue.TryGetTarget(out var request))
|
||||||
@ -134,23 +144,35 @@ namespace osu.Game.Online
|
|||||||
private void itemUpdated(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
private void itemUpdated(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
||||||
{
|
{
|
||||||
if (weakItem.NewValue.TryGetTarget(out var item))
|
if (weakItem.NewValue.TryGetTarget(out var item))
|
||||||
setDownloadStateFromManager(item, DownloadState.LocallyAvailable);
|
{
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
if (!item.Equals(Model.Value))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!VerifyDatabasedModel(item))
|
||||||
|
{
|
||||||
|
State.Value = DownloadState.NotDownloaded;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
State.Value = DownloadState.LocallyAvailable;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void itemRemoved(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
private void itemRemoved(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
||||||
{
|
{
|
||||||
if (weakItem.NewValue.TryGetTarget(out var item))
|
if (weakItem.NewValue.TryGetTarget(out var item))
|
||||||
setDownloadStateFromManager(item, DownloadState.NotDownloaded);
|
{
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
if (item.Equals(Model.Value))
|
||||||
|
State.Value = DownloadState.NotDownloaded;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() =>
|
|
||||||
{
|
|
||||||
if (!s.Equals(Model.Value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
State.Value = state;
|
|
||||||
});
|
|
||||||
|
|
||||||
#region Disposal
|
#region Disposal
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user