mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 23:59:16 +08:00
Implement special exporter intended specifically for submission flows
This commit is contained in:
parent
b6731ff773
commit
fff99a8b40
@ -61,6 +61,20 @@ namespace osu.Game.Database
|
||||
Configuration = new LegacySkinDecoder().Decode(skinStreamReader)
|
||||
};
|
||||
|
||||
MutateBeatmap(model, playableBeatmap);
|
||||
|
||||
// Encode to legacy format
|
||||
var stream = new MemoryStream();
|
||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
new LegacyBeatmapEncoder(playableBeatmap, beatmapSkin).Encode(sw);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
protected virtual void MutateBeatmap(BeatmapSetInfo beatmapSet, IBeatmap playableBeatmap)
|
||||
{
|
||||
// Convert beatmap elements to be compatible with legacy format
|
||||
// So we truncate time and position values to integers, and convert paths with multiple segments to Bézier curves
|
||||
|
||||
@ -145,15 +159,6 @@ namespace osu.Game.Database
|
||||
hasPath.Path.ControlPoints.Add(new PathControlPoint(position));
|
||||
}
|
||||
}
|
||||
|
||||
// Encode to legacy format
|
||||
var stream = new MemoryStream();
|
||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
new LegacyBeatmapEncoder(playableBeatmap, beatmapSkin).Encode(sw);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
protected override string FileExtension => @".osz";
|
||||
|
@ -0,0 +1,58 @@
|
||||
// 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;
|
||||
private readonly HashSet<int>? beatmapIds;
|
||||
|
||||
public SubmissionBeatmapExporter(Storage storage)
|
||||
: base(storage)
|
||||
{
|
||||
}
|
||||
|
||||
public SubmissionBeatmapExporter(Storage storage, PutBeatmapSetResponse putBeatmapSetResponse)
|
||||
: base(storage)
|
||||
{
|
||||
beatmapSetId = putBeatmapSetResponse.BeatmapSetId;
|
||||
beatmapIds = putBeatmapSetResponse.BeatmapIds.Select(id => (int)id).ToHashSet();
|
||||
}
|
||||
|
||||
protected override void MutateBeatmap(BeatmapSetInfo beatmapSet, IBeatmap playableBeatmap)
|
||||
{
|
||||
base.MutateBeatmap(beatmapSet, playableBeatmap);
|
||||
|
||||
if (beatmapSetId != null && beatmapIds != null)
|
||||
{
|
||||
playableBeatmap.BeatmapInfo.BeatmapSet = beatmapSet;
|
||||
playableBeatmap.BeatmapInfo.BeatmapSet!.OnlineID = (int)beatmapSetId;
|
||||
|
||||
if (beatmapIds.Contains(playableBeatmap.BeatmapInfo.OnlineID))
|
||||
{
|
||||
beatmapIds.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)
|
||||
throw new InvalidOperationException(@"Ran out of new beatmap IDs to assign to unsubmitted beatmaps!");
|
||||
|
||||
int newId = beatmapIds.First();
|
||||
beatmapIds.Remove(newId);
|
||||
playableBeatmap.BeatmapInfo.OnlineID = newId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user