Resolve review comments

This commit is contained in:
Craftplacer
2020-08-23 15:08:02 +02:00
parent cfd82104db
commit e6646b9877
9 changed files with 59 additions and 42 deletions

View File

@ -195,8 +195,8 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <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="skin">Optional beatmap skin for inline skin configuration in beatmap files.</param>
public void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin skin)
/// <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)
{
var setInfo = QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == info.ID));
@ -204,7 +204,13 @@ namespace osu.Game.Beatmaps
{
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
{
new LegacyBeatmapEncoder(beatmapContent, skin).Encode(sw);
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

@ -8,6 +8,6 @@ namespace osu.Game.Beatmaps.Formats
{
public interface IHasCustomColours
{
Dictionary<string, Color4> CustomColours { get; set; }
IDictionary<string, Color4> CustomColours { get; }
}
}

View File

@ -16,6 +16,7 @@ using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Beatmaps.Formats
{
@ -24,11 +25,14 @@ namespace osu.Game.Beatmaps.Formats
public const int LATEST_VERSION = 128;
private readonly IBeatmap beatmap;
private readonly ISkin skin;
private readonly LegacyBeatmapSkin skin;
/// <param name="beatmap">The beatmap to encode</param>
/// <param name="skin">An optional skin, for encoding the beatmap's combo colours. This will only work if the parameter is a type of <see cref="LegacyBeatmapSkin"/>.</param>
public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] ISkin 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)
{
this.beatmap = beatmap;
this.skin = skin;
@ -210,7 +214,7 @@ namespace osu.Game.Beatmaps.Formats
if (!(skin is LegacyBeatmapSkin legacySkin))
return;
var colours = legacySkin?.Configuration.ComboColours;
var colours = legacySkin.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
if (colours == null || colours.Count == 0)
return;
@ -221,12 +225,11 @@ namespace osu.Game.Beatmaps.Formats
{
var comboColour = colours[i];
var r = (byte)(comboColour.R * byte.MaxValue);
var g = (byte)(comboColour.G * byte.MaxValue);
var b = (byte)(comboColour.B * byte.MaxValue);
var a = (byte)(comboColour.A * byte.MaxValue);
writer.WriteLine($"Combo{i}: {r},{g},{b},{a}");
writer.Write(FormattableString.Invariant($"Combo{i}: "));
writer.Write(FormattableString.Invariant($"{(byte)(comboColour.R * byte.MaxValue)},"));
writer.Write(FormattableString.Invariant($"{(byte)(comboColour.G * byte.MaxValue)},"));
writer.Write(FormattableString.Invariant($"{(byte)(comboColour.B * byte.MaxValue)},"));
writer.WriteLine(FormattableString.Invariant($"{(byte)(comboColour.A * byte.MaxValue)}"));
}
}