mirror of
https://github.com/ppy/osu.git
synced 2026-05-25 23:30:51 +08:00
Minor code refactors
This commit is contained in:
@@ -76,7 +76,6 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
private uint? beatmapSetId;
|
||||
private MemoryStream? beatmapPackageStream;
|
||||
|
||||
private SubmissionBeatmapExporter legacyBeatmapExporter = null!;
|
||||
private ProgressNotification? exportProgressNotification;
|
||||
private ProgressNotification? updateProgressNotification;
|
||||
|
||||
@@ -214,8 +213,7 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
}).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
legacyBeatmapExporter = new SubmissionBeatmapExporter(storage, response);
|
||||
await createBeatmapPackage(response.Files).ConfigureAwait(true);
|
||||
await createBeatmapPackage(response).ConfigureAwait(true);
|
||||
};
|
||||
createRequest.Failure += ex =>
|
||||
{
|
||||
@@ -228,7 +226,7 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
api.Queue(createRequest);
|
||||
}
|
||||
|
||||
private async Task createBeatmapPackage(ICollection<BeatmapSetFile> onlineFiles)
|
||||
private async Task createBeatmapPackage(PutBeatmapSetResponse response)
|
||||
{
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
@@ -237,8 +235,13 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
try
|
||||
{
|
||||
beatmapPackageStream = new MemoryStream();
|
||||
await legacyBeatmapExporter.ExportToStreamAsync(Beatmap.Value.BeatmapSetInfo.ToLive(realmAccess), beatmapPackageStream, exportProgressNotification = new ProgressNotification())
|
||||
.ConfigureAwait(true);
|
||||
exportProgressNotification = new ProgressNotification();
|
||||
|
||||
var legacyBeatmapExporter = new SubmissionBeatmapExporter(storage, response);
|
||||
|
||||
await legacyBeatmapExporter
|
||||
.ExportToStreamAsync(Beatmap.Value.BeatmapSetInfo.ToLive(realmAccess), beatmapPackageStream, exportProgressNotification)
|
||||
.ConfigureAwait(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -253,8 +256,8 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
|
||||
await Task.Delay(200).ConfigureAwait(true);
|
||||
|
||||
if (onlineFiles.Count > 0)
|
||||
await patchBeatmapSet(onlineFiles).ConfigureAwait(true);
|
||||
if (response.Files.Count > 0)
|
||||
await patchBeatmapSet(response.Files).ConfigureAwait(true);
|
||||
else
|
||||
replaceBeatmapSet();
|
||||
}
|
||||
|
||||
@@ -14,43 +14,38 @@ namespace osu.Game.Screens.Edit.Submission
|
||||
public class SubmissionBeatmapExporter : LegacyBeatmapExporter
|
||||
{
|
||||
private readonly uint? beatmapSetId;
|
||||
private readonly HashSet<int>? beatmapIds;
|
||||
|
||||
public SubmissionBeatmapExporter(Storage storage)
|
||||
: base(storage)
|
||||
{
|
||||
}
|
||||
private readonly HashSet<int>? allocatedBeatmapIds;
|
||||
|
||||
public SubmissionBeatmapExporter(Storage storage, PutBeatmapSetResponse putBeatmapSetResponse)
|
||||
: base(storage)
|
||||
{
|
||||
beatmapSetId = putBeatmapSetResponse.BeatmapSetId;
|
||||
beatmapIds = putBeatmapSetResponse.BeatmapIds.Select(id => (int)id).ToHashSet();
|
||||
allocatedBeatmapIds = putBeatmapSetResponse.BeatmapIds.Select(id => (int)id).ToHashSet();
|
||||
}
|
||||
|
||||
protected override void MutateBeatmap(BeatmapSetInfo beatmapSet, IBeatmap playableBeatmap)
|
||||
{
|
||||
base.MutateBeatmap(beatmapSet, playableBeatmap);
|
||||
|
||||
if (beatmapSetId != null && beatmapIds != null)
|
||||
if (beatmapSetId != null && allocatedBeatmapIds != null)
|
||||
{
|
||||
playableBeatmap.BeatmapInfo.BeatmapSet = beatmapSet;
|
||||
playableBeatmap.BeatmapInfo.BeatmapSet!.OnlineID = (int)beatmapSetId;
|
||||
|
||||
if (beatmapIds.Contains(playableBeatmap.BeatmapInfo.OnlineID))
|
||||
if (allocatedBeatmapIds.Contains(playableBeatmap.BeatmapInfo.OnlineID))
|
||||
{
|
||||
beatmapIds.Remove(playableBeatmap.BeatmapInfo.OnlineID);
|
||||
allocatedBeatmapIds.Remove(playableBeatmap.BeatmapInfo.OnlineID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (playableBeatmap.BeatmapInfo.OnlineID > 0)
|
||||
throw new InvalidOperationException(@"Encountered beatmap with ID that has not been assigned to it by the server!");
|
||||
|
||||
if (beatmapIds.Count == 0)
|
||||
if (allocatedBeatmapIds.Count == 0)
|
||||
throw new InvalidOperationException(@"Ran out of new beatmap IDs to assign to unsubmitted beatmaps!");
|
||||
|
||||
int newId = beatmapIds.First();
|
||||
beatmapIds.Remove(newId);
|
||||
int newId = allocatedBeatmapIds.First();
|
||||
allocatedBeatmapIds.Remove(newId);
|
||||
playableBeatmap.BeatmapInfo.OnlineID = newId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user