1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Use IBeatmapSkin

This commit is contained in:
Craftplacer 2020-08-30 11:34:50 +02:00
parent 00b68b050c
commit e428144f73
3 changed files with 6 additions and 17 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.IsTrue(decoded.beatmapSkin.Configuration.Equals(decodedAfterEncode.beatmapSkin.Configuration));
}
private void sort((IBeatmap beatmap, LegacyBeatmapSkin beatmapSkin) tuple)
private void sort((IBeatmap beatmap, IBeatmapSkin beatmapSkin) tuple)
{
// Sort control points to ensure a sane ordering, as they may be parsed in different orders. This works because each group contains only uniquely-typed control points.
foreach (var g in tuple.beatmap.ControlPointInfo.Groups)
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
}
}
private Stream encodeToLegacy((IBeatmap beatmap, LegacyBeatmapSkin beatmapSkin) fullBeatmap)
private Stream encodeToLegacy((IBeatmap beatmap, IBeatmapSkin beatmapSkin) fullBeatmap)
{
var (beatmap, beatmapSkin) = fullBeatmap;
var stream = new MemoryStream();

View File

@ -196,22 +196,14 @@ namespace osu.Game.Beatmaps
/// <param name="info">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
/// <param name="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
/// <param name="beatmapSkin">The beatmap <see cref="ISkin"/> content to write, or null if not to be changed.</param>
public void Save(BeatmapInfo info, IBeatmap beatmapContent, LegacyBeatmapSkin beatmapSkin = null)
public void Save(BeatmapInfo info, IBeatmap beatmapContent, IBeatmapSkin beatmapSkin = null)
{
var setInfo = QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == info.ID));
using (var stream = new MemoryStream())
{
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
{
if (beatmapSkin == null)
{
var workingBeatmap = GetWorkingBeatmap(info);
beatmapSkin = (workingBeatmap.Skin is LegacyBeatmapSkin legacy) ? legacy : null;
}
new LegacyBeatmapEncoder(beatmapContent, beatmapSkin).Encode(sw);
}
stream.Seek(0, SeekOrigin.Begin);

View File

@ -25,14 +25,14 @@ namespace osu.Game.Beatmaps.Formats
public const int LATEST_VERSION = 128;
private readonly IBeatmap beatmap;
private readonly LegacyBeatmapSkin skin;
private readonly IBeatmapSkin skin;
/// <summary>
/// Creates a new <see cref="LegacyBeatmapEncoder"/>.
/// </summary>
/// <param name="beatmap">The beatmap to encode.</param>
/// <param name="skin">An optional skin, for encoding the beatmap's combo colours.</param>
public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] LegacyBeatmapSkin skin)
public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] IBeatmapSkin skin)
{
this.beatmap = beatmap;
this.skin = skin;
@ -211,10 +211,7 @@ namespace osu.Game.Beatmaps.Formats
private void handleComboColours(TextWriter writer)
{
if (!(skin is LegacyBeatmapSkin legacySkin))
return;
var colours = legacySkin.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
var colours = skin.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
if (colours == null || colours.Count == 0)
return;