mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add required parameters and other various changes
This commit is contained in:
@ -28,13 +28,25 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class LegacyBeatmapEncoderTest
|
public class LegacyBeatmapEncoderTest
|
||||||
{
|
{
|
||||||
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
private static readonly DllResourceStore resource_store = TestResources.GetStore();
|
||||||
|
|
||||||
|
private static IEnumerable<string> allBeatmaps = resource_store.GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
||||||
|
|
||||||
|
private static Stream beatmapSkinStream = resource_store.GetStream("skin.ini");
|
||||||
|
|
||||||
|
private ISkin skin;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
skin = decodeSkinFromLegacy(beatmapSkinStream);
|
||||||
|
}
|
||||||
|
|
||||||
[TestCaseSource(nameof(allBeatmaps))]
|
[TestCaseSource(nameof(allBeatmaps))]
|
||||||
public void TestEncodeDecodeStability(string name)
|
public void TestEncodeDecodeStability(string name)
|
||||||
{
|
{
|
||||||
var decoded = decodeFromLegacy(TestResources.GetStore().GetStream(name));
|
var decoded = decodeBeatmapFromLegacy(TestResources.GetStore().GetStream(name));
|
||||||
var decodedAfterEncode = decodeFromLegacy(encodeToLegacy(decoded));
|
var decodedAfterEncode = decodeBeatmapFromLegacy(encodeToLegacy(decoded, skin));
|
||||||
|
|
||||||
sort(decoded);
|
sort(decoded);
|
||||||
sort(decodedAfterEncode);
|
sort(decodedAfterEncode);
|
||||||
@ -52,20 +64,24 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBeatmap decodeFromLegacy(Stream stream)
|
private IBeatmap decodeBeatmapFromLegacy(Stream stream)
|
||||||
{
|
{
|
||||||
using (var reader = new LineBufferedReader(stream))
|
using (var reader = new LineBufferedReader(stream))
|
||||||
return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader));
|
return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream encodeToLegacy(IBeatmap beatmap)
|
private ISkin decodeSkinFromLegacy(Stream stream)
|
||||||
|
{
|
||||||
|
using (var reader = new LineBufferedReader(stream))
|
||||||
|
return new LegacySkin(SkinInfo.Default, resource_store, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream encodeToLegacy(IBeatmap beatmap, ISkin skin)
|
||||||
{
|
{
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
|
|
||||||
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
using (var rs = new ResourceStore<byte[]>())
|
|
||||||
{
|
{
|
||||||
var skin = new LegacyBeatmapSkin(beatmap.BeatmapInfo, rs, null);
|
|
||||||
new LegacyBeatmapEncoder(beatmap, skin).Encode(writer);
|
new LegacyBeatmapEncoder(beatmap, skin).Encode(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,7 +730,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
||||||
|
|
||||||
var beatmapInfo = setToUpdate.Beatmaps.First(b => b.RulesetID == 0);
|
var beatmapInfo = setToUpdate.Beatmaps.First(b => b.RulesetID == 0);
|
||||||
Beatmap beatmapToUpdate = (Beatmap)manager.GetWorkingBeatmap(setToUpdate.Beatmaps.First(b => b.RulesetID == 0)).Beatmap;
|
var workingBeatmap = manager.GetWorkingBeatmap(setToUpdate.Beatmaps.First(b => b.RulesetID == 0));
|
||||||
|
Beatmap beatmapToUpdate = (Beatmap)workingBeatmap.Beatmap;
|
||||||
BeatmapSetFileInfo fileToUpdate = setToUpdate.Files.First(f => beatmapToUpdate.BeatmapInfo.Path.Contains(f.Filename));
|
BeatmapSetFileInfo fileToUpdate = setToUpdate.Files.First(f => beatmapToUpdate.BeatmapInfo.Path.Contains(f.Filename));
|
||||||
|
|
||||||
string oldMd5Hash = beatmapToUpdate.BeatmapInfo.MD5Hash;
|
string oldMd5Hash = beatmapToUpdate.BeatmapInfo.MD5Hash;
|
||||||
@ -738,7 +739,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
beatmapToUpdate.HitObjects.Clear();
|
beatmapToUpdate.HitObjects.Clear();
|
||||||
beatmapToUpdate.HitObjects.Add(new HitCircle { StartTime = 5000 });
|
beatmapToUpdate.HitObjects.Add(new HitCircle { StartTime = 5000 });
|
||||||
|
|
||||||
manager.Save(beatmapInfo, beatmapToUpdate);
|
manager.Save(beatmapInfo, beatmapToUpdate, workingBeatmap.Skin);
|
||||||
|
|
||||||
// Check that the old file reference has been removed
|
// Check that the old file reference has been removed
|
||||||
Assert.That(manager.QueryBeatmapSet(s => s.ID == setToUpdate.ID).Files.All(f => f.ID != fileToUpdate.ID));
|
Assert.That(manager.QueryBeatmapSet(s => s.ID == setToUpdate.ID).Files.All(f => f.ID != fileToUpdate.ID));
|
||||||
|
@ -13,7 +13,7 @@ namespace osu.Game.Tests.Editing
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestSaveRestoreState()
|
public void TestSaveRestoreState()
|
||||||
{
|
{
|
||||||
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
||||||
|
|
||||||
Assert.That(handler.CanUndo.Value, Is.False);
|
Assert.That(handler.CanUndo.Value, Is.False);
|
||||||
Assert.That(handler.CanRedo.Value, Is.False);
|
Assert.That(handler.CanRedo.Value, Is.False);
|
||||||
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Editing
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMaxStatesSaved()
|
public void TestMaxStatesSaved()
|
||||||
{
|
{
|
||||||
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
||||||
|
|
||||||
Assert.That(handler.CanUndo.Value, Is.False);
|
Assert.That(handler.CanUndo.Value, Is.False);
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ namespace osu.Game.Tests.Editing
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMaxStatesExceeded()
|
public void TestMaxStatesExceeded()
|
||||||
{
|
{
|
||||||
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
||||||
|
|
||||||
Assert.That(handler.CanUndo.Value, Is.False);
|
Assert.That(handler.CanUndo.Value, Is.False);
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.IO.Stores;
|
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
@ -15,7 +14,6 @@ using osu.Game.Rulesets.Osu;
|
|||||||
using osu.Game.Rulesets.Osu.Beatmaps;
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Screens.Edit;
|
using osu.Game.Screens.Edit;
|
||||||
using osu.Game.Skinning;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
||||||
|
|
||||||
@ -353,11 +351,7 @@ namespace osu.Game.Tests.Editing
|
|||||||
using (var encoded = new MemoryStream())
|
using (var encoded = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var sw = new StreamWriter(encoded))
|
using (var sw = new StreamWriter(encoded))
|
||||||
using (var rs = new ResourceStore<byte[]>())
|
new LegacyBeatmapEncoder(beatmap, null).Encode(sw);
|
||||||
{
|
|
||||||
var skin = new LegacyBeatmapSkin(beatmap.BeatmapInfo, rs, null);
|
|
||||||
new LegacyBeatmapEncoder(beatmap, skin).Encode(sw);
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoded.ToArray();
|
return encoded.ToArray();
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,8 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </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="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="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
|
||||||
public void Save(BeatmapInfo info, IBeatmap beatmapContent)
|
/// <param name="skin">Optional beatmap skin for inline skin configuration in beatmap files.</param>
|
||||||
|
public void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin skin)
|
||||||
{
|
{
|
||||||
var setInfo = QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == info.ID));
|
var setInfo = QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == info.ID));
|
||||||
|
|
||||||
@ -203,7 +204,6 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
{
|
{
|
||||||
var skin = new LegacyBeatmapSkin(info, Files.Store, audioManager);
|
|
||||||
new LegacyBeatmapEncoder(beatmapContent, skin).Encode(sw);
|
new LegacyBeatmapEncoder(beatmapContent, skin).Encode(sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
public const int LATEST_VERSION = 128;
|
public const int LATEST_VERSION = 128;
|
||||||
|
|
||||||
private readonly IBeatmap beatmap;
|
private readonly IBeatmap beatmap;
|
||||||
private readonly LegacyBeatmapSkin beatmapSkin;
|
private readonly ISkin skin;
|
||||||
|
|
||||||
/// <param name="beatmap">The beatmap to encode</param>
|
/// <param name="beatmap">The beatmap to encode</param>
|
||||||
/// <param name="beatmapSkin">An optional beatmap skin, for encoding the beatmap's combo colours.</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] LegacyBeatmapSkin beatmapSkin)
|
public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] ISkin skin)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
this.beatmap = beatmap;
|
||||||
this.beatmapSkin = beatmapSkin;
|
this.skin = skin;
|
||||||
|
|
||||||
if (beatmap.BeatmapInfo.RulesetID < 0 || beatmap.BeatmapInfo.RulesetID > 3)
|
if (beatmap.BeatmapInfo.RulesetID < 0 || beatmap.BeatmapInfo.RulesetID > 3)
|
||||||
throw new ArgumentException("Only beatmaps in the osu, taiko, catch, or mania rulesets can be encoded to the legacy beatmap format.", nameof(beatmap));
|
throw new ArgumentException("Only beatmaps in the osu, taiko, catch, or mania rulesets can be encoded to the legacy beatmap format.", nameof(beatmap));
|
||||||
@ -207,7 +207,10 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
|
|
||||||
private void handleComboColours(TextWriter writer)
|
private void handleComboColours(TextWriter writer)
|
||||||
{
|
{
|
||||||
var colours = beatmapSkin?.Configuration.ComboColours;
|
if (!(skin is LegacyBeatmapSkin legacySkin))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var colours = legacySkin?.Configuration.ComboColours;
|
||||||
|
|
||||||
if (colours == null || colours.Count == 0)
|
if (colours == null || colours.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -33,6 +33,7 @@ using osu.Game.Screens.Edit.Compose;
|
|||||||
using osu.Game.Screens.Edit.Setup;
|
using osu.Game.Screens.Edit.Setup;
|
||||||
using osu.Game.Screens.Edit.Timing;
|
using osu.Game.Screens.Edit.Timing;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit
|
namespace osu.Game.Screens.Edit
|
||||||
@ -64,6 +65,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
private IBeatmap playableBeatmap;
|
private IBeatmap playableBeatmap;
|
||||||
private EditorBeatmap editorBeatmap;
|
private EditorBeatmap editorBeatmap;
|
||||||
private EditorChangeHandler changeHandler;
|
private EditorChangeHandler changeHandler;
|
||||||
|
private ISkin beatmapSkin;
|
||||||
|
|
||||||
private DependencyContainer dependencies;
|
private DependencyContainer dependencies;
|
||||||
|
|
||||||
@ -92,6 +94,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
|
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
|
||||||
|
beatmapSkin = Beatmap.Value.Skin;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -104,7 +107,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap));
|
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap));
|
||||||
dependencies.CacheAs(editorBeatmap);
|
dependencies.CacheAs(editorBeatmap);
|
||||||
|
|
||||||
changeHandler = new EditorChangeHandler(editorBeatmap);
|
changeHandler = new EditorChangeHandler(editorBeatmap, beatmapSkin);
|
||||||
dependencies.CacheAs<IEditorChangeHandler>(changeHandler);
|
dependencies.CacheAs<IEditorChangeHandler>(changeHandler);
|
||||||
|
|
||||||
EditorMenuBar menuBar;
|
EditorMenuBar menuBar;
|
||||||
@ -399,7 +402,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
clock.SeekForward(!clock.IsRunning, amount);
|
clock.SeekForward(!clock.IsRunning, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveBeatmap() => beatmapManager.Save(playableBeatmap.BeatmapInfo, editorBeatmap);
|
private void saveBeatmap() => beatmapManager.Save(playableBeatmap.BeatmapInfo, editorBeatmap, Beatmap.Value.Skin);
|
||||||
|
|
||||||
private void exportBeatmap()
|
private void exportBeatmap()
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.IO.Stores;
|
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -27,6 +26,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
private int currentState = -1;
|
private int currentState = -1;
|
||||||
|
|
||||||
private readonly EditorBeatmap editorBeatmap;
|
private readonly EditorBeatmap editorBeatmap;
|
||||||
|
private readonly ISkin beatmapSkin;
|
||||||
private int bulkChangesStarted;
|
private int bulkChangesStarted;
|
||||||
private bool isRestoring;
|
private bool isRestoring;
|
||||||
|
|
||||||
@ -36,7 +36,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
/// Creates a new <see cref="EditorChangeHandler"/>.
|
/// Creates a new <see cref="EditorChangeHandler"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="editorBeatmap">The <see cref="EditorBeatmap"/> to track the <see cref="HitObject"/>s of.</param>
|
/// <param name="editorBeatmap">The <see cref="EditorBeatmap"/> to track the <see cref="HitObject"/>s of.</param>
|
||||||
public EditorChangeHandler(EditorBeatmap editorBeatmap)
|
/// <param name="beatmapSkin">The skin to track the inline skin configuration of.</param>
|
||||||
|
public EditorChangeHandler(EditorBeatmap editorBeatmap, ISkin beatmapSkin)
|
||||||
{
|
{
|
||||||
this.editorBeatmap = editorBeatmap;
|
this.editorBeatmap = editorBeatmap;
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
patcher = new LegacyEditorBeatmapPatcher(editorBeatmap);
|
patcher = new LegacyEditorBeatmapPatcher(editorBeatmap);
|
||||||
|
|
||||||
|
this.beatmapSkin = beatmapSkin;
|
||||||
|
|
||||||
// Initial state.
|
// Initial state.
|
||||||
SaveState();
|
SaveState();
|
||||||
}
|
}
|
||||||
@ -87,10 +90,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
using (var rs = new ResourceStore<byte[]>())
|
|
||||||
{
|
{
|
||||||
var skin = new LegacyBeatmapSkin(editorBeatmap.BeatmapInfo, rs, null);
|
new LegacyBeatmapEncoder(editorBeatmap, beatmapSkin).Encode(sw);
|
||||||
new LegacyBeatmapEncoder(editorBeatmap, skin).Encode(sw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
savedStates.Add(stream.ToArray());
|
savedStates.Add(stream.ToArray());
|
||||||
|
Reference in New Issue
Block a user