mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Add silent import parameter
This commit is contained in:
parent
d07a724970
commit
a8ad7d4670
@ -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);
|
||||
|
@ -78,7 +78,7 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
}
|
||||
}
|
||||
|
||||
private void setAdded(BeatmapSetInfo s, bool existing) => Schedule(() =>
|
||||
private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => Schedule(() =>
|
||||
{
|
||||
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
|
||||
DownloadState.Value = DownloadStatus.Downloaded;
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Database
|
||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||
where TFileModel : INamedFileInfo, new()
|
||||
{
|
||||
public delegate void ItemAddedDelegate(TModel model, bool existing);
|
||||
public delegate void ItemAddedDelegate(TModel model, bool existing, bool silent);
|
||||
|
||||
/// <summary>
|
||||
/// Set an endpoint for notifications to be posted to.
|
||||
@ -110,7 +110,7 @@ namespace osu.Game.Database
|
||||
ContextFactory = contextFactory;
|
||||
|
||||
ModelStore = modelStore;
|
||||
ModelStore.ItemAdded += s => handleEvent(() => ItemAdded?.Invoke(s, false));
|
||||
ModelStore.ItemAdded += (item, silent) => handleEvent(() => ItemAdded?.Invoke(item, false, silent));
|
||||
ModelStore.ItemRemoved += s => handleEvent(() => ItemRemoved?.Invoke(s));
|
||||
|
||||
Files = new FileStore(contextFactory, storage);
|
||||
@ -211,7 +211,7 @@ namespace osu.Game.Database
|
||||
|
||||
model.Hash = computeHash(archive);
|
||||
|
||||
return Import(model, archive);
|
||||
return Import(model, false, archive);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -245,8 +245,9 @@ namespace osu.Game.Database
|
||||
/// Import an item from a <see cref="TModel"/>.
|
||||
/// </summary>
|
||||
/// <param name="item">The model to be imported.</param>
|
||||
/// <param name="silent">Whether the user should be notified fo the import.</param>
|
||||
/// <param name="archive">An optional archive to use for model population.</param>
|
||||
public TModel Import(TModel item, ArchiveReader archive = null)
|
||||
public TModel Import(TModel item, bool silent = false, ArchiveReader archive = null)
|
||||
{
|
||||
delayEvents();
|
||||
|
||||
@ -266,7 +267,7 @@ namespace osu.Game.Database
|
||||
{
|
||||
Undelete(existing);
|
||||
Logger.Log($"Found existing {typeof(TModel)} for {item} (ID {existing.ID}). Skipping import.", LoggingTarget.Database);
|
||||
handleEvent(() => ItemAdded?.Invoke(existing, true));
|
||||
handleEvent(() => ItemAdded?.Invoke(existing, true, silent));
|
||||
return existing;
|
||||
}
|
||||
|
||||
@ -276,7 +277,7 @@ namespace osu.Game.Database
|
||||
Populate(item, archive);
|
||||
|
||||
// import to store
|
||||
ModelStore.Add(item);
|
||||
ModelStore.Add(item, silent);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -16,7 +16,9 @@ namespace osu.Game.Database
|
||||
public abstract class MutableDatabaseBackedStore<T> : DatabaseBackedStore
|
||||
where T : class, IHasPrimaryKey, ISoftDelete
|
||||
{
|
||||
public event Action<T> ItemAdded;
|
||||
public delegate void ItemAddedDelegate(T model, bool silent);
|
||||
|
||||
public event ItemAddedDelegate ItemAdded;
|
||||
public event Action<T> ItemRemoved;
|
||||
|
||||
protected MutableDatabaseBackedStore(IDatabaseContextFactory contextFactory, Storage storage = null)
|
||||
@ -33,7 +35,8 @@ namespace osu.Game.Database
|
||||
/// Add a <see cref="T"/> to the database.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to add.</param>
|
||||
public void Add(T item)
|
||||
/// <param name="silent">Whether the user should be notified of the addition.</param>
|
||||
public void Add(T item, bool silent)
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
{
|
||||
@ -41,7 +44,7 @@ namespace osu.Game.Database
|
||||
context.Attach(item);
|
||||
}
|
||||
|
||||
ItemAdded?.Invoke(item);
|
||||
ItemAdded?.Invoke(item, silent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -54,7 +57,7 @@ namespace osu.Game.Database
|
||||
usage.Context.Update(item);
|
||||
|
||||
ItemRemoved?.Invoke(item);
|
||||
ItemAdded?.Invoke(item);
|
||||
ItemAdded?.Invoke(item, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -89,7 +92,7 @@ namespace osu.Game.Database
|
||||
item.DeletePending = false;
|
||||
}
|
||||
|
||||
ItemAdded?.Invoke(item);
|
||||
ItemAdded?.Invoke(item, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace osu.Game
|
||||
{
|
||||
this.frameworkConfig = frameworkConfig;
|
||||
|
||||
ScoreManager.ItemAdded += (score, _) => Schedule(() => LoadScore(score));
|
||||
ScoreManager.ItemAdded += (score, _, silent) => Schedule(() => LoadScore(score, silent));
|
||||
|
||||
if (!Host.IsPrimaryInstance)
|
||||
{
|
||||
@ -248,15 +248,18 @@ namespace osu.Game
|
||||
/// <param name="beatmapId">The beatmap to show.</param>
|
||||
public void ShowBeatmap(int beatmapId) => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId);
|
||||
|
||||
protected void LoadScore(ScoreInfo score)
|
||||
protected void LoadScore(ScoreInfo score, bool silent)
|
||||
{
|
||||
if (silent)
|
||||
return;
|
||||
|
||||
scoreLoad?.Cancel();
|
||||
|
||||
var menu = intro.ChildScreen;
|
||||
|
||||
if (menu == null)
|
||||
{
|
||||
scoreLoad = Schedule(() => LoadScore(score));
|
||||
scoreLoad = Schedule(() => LoadScore(score, false));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace osu.Game.Overlays.Direct
|
||||
};
|
||||
}
|
||||
|
||||
private void setAdded(BeatmapSetInfo s, bool existing) => Schedule(() =>
|
||||
private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => Schedule(() =>
|
||||
{
|
||||
if (s.OnlineBeatmapSetID == SetInfo.OnlineBeatmapSetID)
|
||||
progressBar.FadeOut(500);
|
||||
|
@ -75,7 +75,7 @@ namespace osu.Game.Overlays.Music
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BeatmapManager beatmaps, IBindableBeatmap beatmap)
|
||||
{
|
||||
beatmaps.GetAllUsableBeatmapSets().ForEach(b => addBeatmapSet(b, false));
|
||||
beatmaps.GetAllUsableBeatmapSets().ForEach(b => addBeatmapSet(b, false, false));
|
||||
beatmaps.ItemAdded += addBeatmapSet;
|
||||
beatmaps.ItemRemoved += removeBeatmapSet;
|
||||
|
||||
@ -83,7 +83,7 @@ namespace osu.Game.Overlays.Music
|
||||
beatmapBacking.ValueChanged += _ => updateSelectedSet();
|
||||
}
|
||||
|
||||
private void addBeatmapSet(BeatmapSetInfo obj, bool existing) => Schedule(() =>
|
||||
private void addBeatmapSet(BeatmapSetInfo obj, bool existing, bool silent) => Schedule(() =>
|
||||
{
|
||||
if (existing)
|
||||
return;
|
||||
|
@ -214,7 +214,7 @@ namespace osu.Game.Overlays
|
||||
beatmapSets.Insert(index, beatmapSetInfo);
|
||||
}
|
||||
|
||||
private void handleBeatmapAdded(BeatmapSetInfo obj, bool existing)
|
||||
private void handleBeatmapAdded(BeatmapSetInfo obj, bool existing, bool silent)
|
||||
{
|
||||
if (existing)
|
||||
return;
|
||||
|
@ -72,7 +72,7 @@ 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, bool existing)
|
||||
private void itemAdded(SkinInfo s, bool existing, bool silent)
|
||||
{
|
||||
if (existing)
|
||||
return;
|
||||
|
@ -278,7 +278,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
var score = CreateScoreInfo();
|
||||
if (RulesetContainer.Replay == null)
|
||||
scoreManager.Import(score);
|
||||
scoreManager.Import(score, true);
|
||||
|
||||
Push(new Results(score));
|
||||
|
||||
|
@ -505,7 +505,7 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
private void onBeatmapSetAdded(BeatmapSetInfo s, bool existing) => Carousel.UpdateBeatmapSet(s);
|
||||
private void onBeatmapSetAdded(BeatmapSetInfo s, bool existing, bool silent) => 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));
|
||||
|
Loading…
Reference in New Issue
Block a user