Fix intro and duplicate inserts

This commit is contained in:
Dean Herbert 2017-10-17 11:10:55 +09:00
parent ef10bb73db
commit 31dc5c97f2
5 changed files with 21 additions and 25 deletions

View File

@ -501,7 +501,7 @@ namespace osu.Game.Beatmaps
public List<BeatmapSetInfo> GetAllUsableBeatmapSets() public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
{ {
lock (beatmaps) lock (beatmaps)
return beatmaps.BeatmapSets.ToList(); return beatmaps.BeatmapSets.Where(s => !s.DeletePending).ToList();
} }
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap

View File

@ -50,7 +50,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap to add.</param> /// <param name="beatmapSet">The beatmap to add.</param>
public void Add(BeatmapSetInfo beatmapSet) public void Add(BeatmapSetInfo beatmapSet)
{ {
Connection.BeatmapSetInfo.Add(beatmapSet); Connection.BeatmapSetInfo.Attach(beatmapSet);
Connection.SaveChanges(); Connection.SaveChanges();
BeatmapSetAdded?.Invoke(beatmapSet); BeatmapSetAdded?.Invoke(beatmapSet);
@ -135,8 +135,7 @@ namespace osu.Game.Beatmaps
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset) .Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
.Include(s => s.Beatmaps).ThenInclude(b => b.Difficulty) .Include(s => s.Beatmaps).ThenInclude(b => b.Difficulty)
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata) .Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
.Include(s => s.Files).ThenInclude(f => f.FileInfo) .Include(s => s.Files).ThenInclude(f => f.FileInfo);
.Where(s => !s.DeletePending);
public IEnumerable<BeatmapInfo> Beatmaps => Connection.BeatmapInfo public IEnumerable<BeatmapInfo> Beatmaps => Connection.BeatmapInfo
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata) .Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)

View File

@ -66,10 +66,8 @@ namespace osu.Game.IO
} }
if (existing == null) if (existing == null)
{ // SaveChanges is performed in Reference.
Connection.FileInfo.Add(info); Connection.FileInfo.Add(info);
Connection.SaveChanges();
}
if (reference || existing == null) if (reference || existing == null)
Reference(info); Reference(info);

View File

@ -89,7 +89,6 @@ namespace osu.Game.Screens.Menu
{ {
// we need to import the default menu background beatmap // we need to import the default menu background beatmap
setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"))); setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz")));
setInfo.Protected = true; setInfo.Protected = true;
} }
} }

View File

@ -26,7 +26,7 @@ namespace osu.Game.Screens.Select
{ {
public abstract class SongSelect : OsuScreen public abstract class SongSelect : OsuScreen
{ {
private BeatmapManager manager; private BeatmapManager beatmaps;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap();
private readonly BeatmapCarousel carousel; private readonly BeatmapCarousel carousel;
@ -108,9 +108,9 @@ namespace osu.Game.Screens.Select
SelectionChanged = carouselSelectionChanged, SelectionChanged = carouselSelectionChanged,
BeatmapsChanged = carouselBeatmapsLoaded, BeatmapsChanged = carouselBeatmapsLoaded,
DeleteRequested = promptDelete, DeleteRequested = promptDelete,
RestoreRequested = s => { foreach (var b in s.Beatmaps) manager.Restore(b); }, RestoreRequested = s => { foreach (var b in s.Beatmaps) beatmaps.Restore(b); },
EditRequested = editRequested, EditRequested = editRequested,
HideDifficultyRequested = b => manager.Hide(b), HideDifficultyRequested = b => beatmaps.Hide(b),
StartRequested = () => carouselRaisedStart(), StartRequested = () => carouselRaisedStart(),
}); });
Add(FilterControl = new FilterControl Add(FilterControl = new FilterControl
@ -171,16 +171,16 @@ namespace osu.Game.Screens.Select
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => promptDelete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => promptDelete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue);
} }
if (manager == null) if (this.beatmaps == null)
manager = beatmaps; this.beatmaps = beatmaps;
if (osu != null) if (osu != null)
Ruleset.BindTo(osu.Ruleset); Ruleset.BindTo(osu.Ruleset);
manager.BeatmapSetAdded += onBeatmapSetAdded; this.beatmaps.BeatmapSetAdded += onBeatmapSetAdded;
manager.BeatmapSetRemoved += onBeatmapSetRemoved; this.beatmaps.BeatmapSetRemoved += onBeatmapSetRemoved;
manager.BeatmapHidden += onBeatmapHidden; this.beatmaps.BeatmapHidden += onBeatmapHidden;
manager.BeatmapRestored += onBeatmapRestored; this.beatmaps.BeatmapRestored += onBeatmapRestored;
dialogOverlay = dialog; dialogOverlay = dialog;
@ -189,7 +189,7 @@ namespace osu.Game.Screens.Select
initialAddSetsTask = new CancellationTokenSource(); initialAddSetsTask = new CancellationTokenSource();
carousel.Beatmaps = manager.GetAllUsableBeatmapSets(); carousel.Beatmaps = this.beatmaps.GetAllUsableBeatmapSets();
Beatmap.ValueChanged += beatmap_ValueChanged; Beatmap.ValueChanged += beatmap_ValueChanged;
@ -199,7 +199,7 @@ namespace osu.Game.Screens.Select
private void editRequested(BeatmapInfo beatmap) private void editRequested(BeatmapInfo beatmap)
{ {
Beatmap.Value = manager.GetWorkingBeatmap(beatmap, Beatmap); Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap);
Push(new Editor()); Push(new Editor());
} }
@ -248,7 +248,7 @@ namespace osu.Game.Screens.Select
{ {
bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value.BeatmapInfo.BeatmapSetInfoID; bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value.BeatmapInfo.BeatmapSetInfoID;
Beatmap.Value = manager.GetWorkingBeatmap(beatmap, Beatmap); Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap);
ensurePlayingSelected(preview); ensurePlayingSelected(preview);
} }
@ -357,12 +357,12 @@ namespace osu.Game.Screens.Select
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (manager != null) if (beatmaps != null)
{ {
manager.BeatmapSetAdded -= onBeatmapSetAdded; beatmaps.BeatmapSetAdded -= onBeatmapSetAdded;
manager.BeatmapSetRemoved -= onBeatmapSetRemoved; beatmaps.BeatmapSetRemoved -= onBeatmapSetRemoved;
manager.BeatmapHidden -= onBeatmapHidden; beatmaps.BeatmapHidden -= onBeatmapHidden;
manager.BeatmapRestored -= onBeatmapRestored; beatmaps.BeatmapRestored -= onBeatmapRestored;
} }
initialAddSetsTask?.Cancel(); initialAddSetsTask?.Cancel();