1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 23:22:55 +08:00

Notify of existing imports

This commit is contained in:
smoogipoo 2018-11-28 20:19:21 +09:00
parent aaf3e650a5
commit a88b69ec43
9 changed files with 31 additions and 11 deletions

View File

@ -102,7 +102,7 @@ namespace osu.Game.Tests.Beatmaps.IO
int fireCount = 0;
// ReSharper disable once AccessToModifiedClosure
manager.ItemAdded += _ => fireCount++;
manager.ItemAdded += (_, __) => fireCount++;
manager.ItemRemoved += _ => fireCount++;
var imported = loadOszIntoOsu(osu);

View File

@ -78,7 +78,7 @@ namespace osu.Game.Beatmaps.Drawables
}
}
private void setAdded(BeatmapSetInfo s) => Schedule(() =>
private void setAdded(BeatmapSetInfo s, bool existing) => Schedule(() =>
{
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
DownloadState.Value = DownloadStatus.Downloaded;

View File

@ -31,6 +31,8 @@ namespace osu.Game.Database
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
where TFileModel : INamedFileInfo, new()
{
public delegate void ItemAddedDelegate(TModel model, bool existing);
/// <summary>
/// Set an endpoint for notifications to be posted to.
/// </summary>
@ -40,7 +42,7 @@ namespace osu.Game.Database
/// Fired when a new <see cref="TModel"/> becomes available in the database.
/// This is not guaranteed to run on the update thread.
/// </summary>
public event Action<TModel> ItemAdded;
public event ItemAddedDelegate ItemAdded;
/// <summary>
/// Fired when a <see cref="TModel"/> is removed from the database.
@ -107,7 +109,7 @@ namespace osu.Game.Database
ContextFactory = contextFactory;
ModelStore = modelStore;
ModelStore.ItemAdded += s => handleEvent(() => ItemAdded?.Invoke(s));
ModelStore.ItemAdded += s => handleEvent(() => ItemAdded?.Invoke(s, false));
ModelStore.ItemRemoved += s => handleEvent(() => ItemRemoved?.Invoke(s));
Files = new FileStore(contextFactory, storage);
@ -236,6 +238,7 @@ namespace osu.Game.Database
if (existing != null)
{
Logger.Log($"Found existing {typeof(TModel)} for {item} (ID {existing.ID}). Skipping import.", LoggingTarget.Database);
handleEvent(() => ItemAdded?.Invoke(existing, true));
return existing;
}

View File

@ -148,7 +148,7 @@ namespace osu.Game
{
this.frameworkConfig = frameworkConfig;
ScoreManager.ItemAdded += score => Schedule(() => LoadScore(score));
ScoreManager.ItemAdded += (score, _) => Schedule(() => LoadScore(score));
if (!Host.IsPrimaryInstance)
{

View File

@ -174,7 +174,7 @@ namespace osu.Game.Overlays.Direct
};
}
private void setAdded(BeatmapSetInfo s) => Schedule(() =>
private void setAdded(BeatmapSetInfo s, bool existing) => Schedule(() =>
{
if (s.OnlineBeatmapSetID == SetInfo.OnlineBeatmapSetID)
progressBar.FadeOut(500);

View File

@ -75,7 +75,7 @@ namespace osu.Game.Overlays.Music
[BackgroundDependencyLoader]
private void load(BeatmapManager beatmaps, IBindableBeatmap beatmap)
{
beatmaps.GetAllUsableBeatmapSets().ForEach(addBeatmapSet);
beatmaps.GetAllUsableBeatmapSets().ForEach(b => addBeatmapSet(b, false));
beatmaps.ItemAdded += addBeatmapSet;
beatmaps.ItemRemoved += removeBeatmapSet;
@ -83,8 +83,11 @@ namespace osu.Game.Overlays.Music
beatmapBacking.ValueChanged += _ => updateSelectedSet();
}
private void addBeatmapSet(BeatmapSetInfo obj) => Schedule(() =>
private void addBeatmapSet(BeatmapSetInfo obj, bool existing) => Schedule(() =>
{
if (existing)
return;
var newItem = new PlaylistItem(obj) { OnSelect = set => Selected?.Invoke(set) };
items.Add(newItem);

View File

@ -214,7 +214,14 @@ namespace osu.Game.Overlays
beatmapSets.Insert(index, beatmapSetInfo);
}
private void handleBeatmapAdded(BeatmapSetInfo obj) => Schedule(() => beatmapSets.Add(obj));
private void handleBeatmapAdded(BeatmapSetInfo obj, bool existing)
{
if (existing)
return;
Schedule(() => beatmapSets.Add(obj));
}
private void handleBeatmapRemoved(BeatmapSetInfo obj) => Schedule(() => beatmapSets.RemoveAll(s => s.ID == obj.ID));
protected override void LoadComplete()

View File

@ -71,7 +71,14 @@ namespace osu.Game.Overlays.Settings.Sections
}
private void itemRemoved(SkinInfo s) => Schedule(() => skinDropdown.Items = skinDropdown.Items.Where(i => i.ID != s.ID).ToArray());
private void itemAdded(SkinInfo s) => Schedule(() => skinDropdown.Items = skinDropdown.Items.Append(s).ToArray());
private void itemAdded(SkinInfo s, bool existing)
{
if (existing)
return;
Schedule(() => skinDropdown.Items = skinDropdown.Items.Append(s).ToArray());
}
protected override void Dispose(bool isDisposing)
{

View File

@ -503,7 +503,7 @@ namespace osu.Game.Screens.Select
}
}
private void onBeatmapSetAdded(BeatmapSetInfo s) => Carousel.UpdateBeatmapSet(s);
private void onBeatmapSetAdded(BeatmapSetInfo s, bool existing) => Carousel.UpdateBeatmapSet(s);
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Carousel.RemoveBeatmapSet(s);
private void onBeatmapRestored(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
private void onBeatmapHidden(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));