Start with a fresh beatmap when entering editor from main menu

This commit is contained in:
Dean Herbert 2020-08-24 19:38:05 +09:00
parent d8a25f5247
commit e032844570
5 changed files with 42 additions and 3 deletions

View File

@ -27,6 +27,7 @@
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Users;
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
namespace osu.Game.Beatmaps
@ -94,6 +95,30 @@ protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == ".osz";
public WorkingBeatmap CreateNew(RulesetInfo ruleset)
{
var set = new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Artist = "unknown",
Title = "unknown",
Author = User.SYSTEM_USER,
},
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
{
BaseDifficulty = new BeatmapDifficulty(),
Ruleset = ruleset
}
}
};
var working = Import(set).Result;
return GetWorkingBeatmap(working.Beatmaps.First());
}
protected override async Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
{
if (archive != null)

View File

@ -33,6 +33,9 @@ public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore t
protected override IBeatmap GetBeatmap()
{
if (BeatmapInfo.Path == null)
return BeatmapInfo.Ruleset.CreateInstance().CreateBeatmapConverter(new Beatmap()).Beatmap;
try
{
using (var stream = new LineBufferedReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))

View File

@ -32,8 +32,6 @@ public ScreenSelectionTabControl()
Height = 1,
Colour = Color4.White.Opacity(0.2f),
});
Current.Value = EditorScreenMode.Compose;
}
[BackgroundDependencyLoader]

View File

@ -89,6 +89,14 @@ private void load(OsuColour colours, GameHost host)
// todo: remove caching of this and consume via editorBeatmap?
dependencies.Cache(beatDivisor);
bool isNewBeatmap = false;
if (Beatmap.Value is DummyWorkingBeatmap)
{
isNewBeatmap = true;
Beatmap.Value = beatmapManager.CreateNew(Ruleset.Value);
}
try
{
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
@ -148,6 +156,7 @@ private void load(OsuColour colours, GameHost host)
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Mode = { Value = isNewBeatmap ? EditorScreenMode.SongSetup : EditorScreenMode.Compose },
Items = new[]
{
new MenuItem("File")

View File

@ -98,7 +98,11 @@ private void load(BeatmapListingOverlay beatmapListing, SettingsOverlay settings
{
buttons = new ButtonSystem
{
OnEdit = delegate { this.Push(new Editor()); },
OnEdit = delegate
{
Beatmap.SetDefault();
this.Push(new Editor());
},
OnSolo = onSolo,
OnMulti = delegate { this.Push(new Multiplayer()); },
OnExit = confirmAndExit,