1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-25 01:32:56 +08:00
osu-lazer/osu.Game/Screens/Edit/Submission/SubmissionBeatmapExporter.cs

54 lines
2.1 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Screens.Edit.Submission
{
public class SubmissionBeatmapExporter : LegacyBeatmapExporter
{
private readonly uint? beatmapSetId;
2025-02-10 16:40:00 +08:00
private readonly HashSet<int>? allocatedBeatmapIds;
public SubmissionBeatmapExporter(Storage storage, PutBeatmapSetResponse putBeatmapSetResponse)
: base(storage)
{
beatmapSetId = putBeatmapSetResponse.BeatmapSetId;
2025-02-10 16:40:00 +08:00
allocatedBeatmapIds = putBeatmapSetResponse.BeatmapIds.Select(id => (int)id).ToHashSet();
}
protected override void MutateBeatmap(BeatmapSetInfo beatmapSet, IBeatmap playableBeatmap)
{
base.MutateBeatmap(beatmapSet, playableBeatmap);
2025-02-10 16:40:00 +08:00
if (beatmapSetId != null && allocatedBeatmapIds != null)
{
playableBeatmap.BeatmapInfo.BeatmapSet = beatmapSet;
playableBeatmap.BeatmapInfo.BeatmapSet!.OnlineID = (int)beatmapSetId;
2025-02-10 16:40:00 +08:00
if (allocatedBeatmapIds.Contains(playableBeatmap.BeatmapInfo.OnlineID))
{
2025-02-10 16:40:00 +08:00
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!");
2025-02-10 16:40:00 +08:00
if (allocatedBeatmapIds.Count == 0)
throw new InvalidOperationException(@"Ran out of new beatmap IDs to assign to unsubmitted beatmaps!");
2025-02-10 16:40:00 +08:00
int newId = allocatedBeatmapIds.First();
allocatedBeatmapIds.Remove(newId);
playableBeatmap.BeatmapInfo.OnlineID = newId;
}
}
}
}