2017-02-14 15:13:25 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2016-10-10 22:17:18 +08:00
|
|
|
|
using System.IO;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
using NUnit.Framework;
|
2016-10-11 01:08:07 +08:00
|
|
|
|
using OpenTK;
|
2016-10-11 01:00:16 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-10-10 22:17:18 +08:00
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2016-11-14 17:03:20 +08:00
|
|
|
|
using osu.Game.Modes;
|
2016-10-10 22:17:18 +08:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2017-03-14 17:06:32 +08:00
|
|
|
|
using osu.Game.Modes.Osu;
|
|
|
|
|
using osu.Game.Modes.Objects.Legacy;
|
2017-04-05 20:59:07 +08:00
|
|
|
|
using System.Linq;
|
2017-04-06 11:14:06 +08:00
|
|
|
|
using osu.Game.Audio;
|
2016-10-10 22:17:18 +08:00
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
namespace osu.Game.Tests.Beatmaps.Formats
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class OsuLegacyDecoderTest
|
|
|
|
|
{
|
2016-10-28 15:09:55 +08:00
|
|
|
|
[OneTimeSetUpAttribute]
|
2016-10-14 11:33:58 +08:00
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
|
|
|
|
OsuLegacyDecoder.Register();
|
2016-11-14 21:03:39 +08:00
|
|
|
|
Ruleset.Register(new OsuRuleset());
|
2016-10-10 22:17:18 +08:00
|
|
|
|
}
|
2017-01-09 21:05:01 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
2016-10-14 11:33:58 +08:00
|
|
|
|
public void TestDecodeMetadata()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmap = decoder.Decode(new StreamReader(stream));
|
|
|
|
|
var meta = beatmap.BeatmapInfo.Metadata;
|
2017-01-09 21:05:01 +08:00
|
|
|
|
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
|
2016-10-14 11:33:58 +08:00
|
|
|
|
Assert.AreEqual("Soleily", meta.Artist);
|
|
|
|
|
Assert.AreEqual("Soleily", meta.ArtistUnicode);
|
|
|
|
|
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
|
|
|
|
|
Assert.AreEqual("Gamu", meta.Author);
|
|
|
|
|
Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile);
|
|
|
|
|
Assert.AreEqual(164471, meta.PreviewTime);
|
|
|
|
|
Assert.AreEqual(string.Empty, meta.Source);
|
|
|
|
|
Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags);
|
|
|
|
|
Assert.AreEqual("Renatus", meta.Title);
|
|
|
|
|
Assert.AreEqual("Renatus", meta.TitleUnicode);
|
|
|
|
|
}
|
2016-10-11 01:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeGeneral()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmapInfo = decoder.Decode(new StreamReader(stream)).BeatmapInfo;
|
|
|
|
|
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
|
|
|
|
|
Assert.AreEqual(false, beatmapInfo.Countdown);
|
|
|
|
|
Assert.AreEqual(0.7f, beatmapInfo.StackLeniency);
|
|
|
|
|
Assert.AreEqual(false, beatmapInfo.SpecialStyle);
|
|
|
|
|
Assert.AreEqual(PlayMode.Osu, beatmapInfo.Mode);
|
|
|
|
|
Assert.AreEqual(false, beatmapInfo.LetterboxInBreaks);
|
|
|
|
|
Assert.AreEqual(false, beatmapInfo.WidescreenStoryboard);
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2016-10-11 01:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeEditor()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmap = decoder.Decode(new StreamReader(stream)).BeatmapInfo;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
int[] expectedBookmarks =
|
|
|
|
|
{
|
|
|
|
|
11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351,
|
|
|
|
|
95901, 106450, 116999, 119637, 130186, 140735, 151285,
|
|
|
|
|
161834, 164471, 175020, 185570, 196119, 206669, 209306
|
|
|
|
|
};
|
|
|
|
|
Assert.AreEqual(expectedBookmarks.Length, beatmap.Bookmarks.Length);
|
|
|
|
|
for (int i = 0; i < expectedBookmarks.Length; i++)
|
|
|
|
|
Assert.AreEqual(expectedBookmarks[i], beatmap.Bookmarks[i]);
|
|
|
|
|
Assert.AreEqual(1.8, beatmap.DistanceSpacing);
|
|
|
|
|
Assert.AreEqual(4, beatmap.BeatDivisor);
|
|
|
|
|
Assert.AreEqual(4, beatmap.GridSize);
|
|
|
|
|
Assert.AreEqual(2, beatmap.TimelineZoom);
|
|
|
|
|
}
|
2016-10-11 01:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeDifficulty()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmap = decoder.Decode(new StreamReader(stream));
|
2017-03-16 22:18:02 +08:00
|
|
|
|
var difficulty = beatmap.BeatmapInfo.Difficulty;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
Assert.AreEqual(6.5f, difficulty.DrainRate);
|
|
|
|
|
Assert.AreEqual(4, difficulty.CircleSize);
|
|
|
|
|
Assert.AreEqual(8, difficulty.OverallDifficulty);
|
|
|
|
|
Assert.AreEqual(9, difficulty.ApproachRate);
|
|
|
|
|
Assert.AreEqual(1.8f, difficulty.SliderMultiplier);
|
|
|
|
|
Assert.AreEqual(2, difficulty.SliderTickRate);
|
|
|
|
|
}
|
2016-10-11 01:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeColors()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmap = decoder.Decode(new StreamReader(stream));
|
2016-10-11 01:00:16 +08:00
|
|
|
|
Color4[] expected =
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
|
|
|
|
new Color4(142, 199, 255, 255),
|
|
|
|
|
new Color4(255, 128, 128, 255),
|
|
|
|
|
new Color4(128, 255, 255, 255),
|
|
|
|
|
new Color4(128, 255, 128, 255),
|
|
|
|
|
new Color4(255, 187, 255, 255),
|
|
|
|
|
new Color4(255, 177, 140, 255),
|
|
|
|
|
};
|
|
|
|
|
Assert.AreEqual(expected.Length, beatmap.ComboColors.Count);
|
|
|
|
|
for (int i = 0; i < expected.Length; i++)
|
|
|
|
|
Assert.AreEqual(expected[i], beatmap.ComboColors[i]);
|
|
|
|
|
}
|
2016-10-11 01:08:07 +08:00
|
|
|
|
}
|
2016-10-14 11:33:58 +08:00
|
|
|
|
|
2017-01-09 21:05:01 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeHitObjects()
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
|
|
|
|
var decoder = new OsuLegacyDecoder();
|
|
|
|
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var beatmap = decoder.Decode(new StreamReader(stream));
|
2017-03-14 17:06:32 +08:00
|
|
|
|
var slider = beatmap.HitObjects[0] as LegacySlider;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
Assert.IsNotNull(slider);
|
|
|
|
|
Assert.AreEqual(new Vector2(192, 168), slider.Position);
|
|
|
|
|
Assert.AreEqual(956, slider.StartTime);
|
2017-04-06 11:14:06 +08:00
|
|
|
|
Assert.IsTrue(slider.Samples.Any(s => s.Name == SampleInfo.HIT_NORMAL));
|
2017-03-14 17:06:32 +08:00
|
|
|
|
var hit = beatmap.HitObjects[1] as LegacyHit;
|
|
|
|
|
Assert.IsNotNull(hit);
|
|
|
|
|
Assert.AreEqual(new Vector2(304, 56), hit.Position);
|
|
|
|
|
Assert.AreEqual(1285, hit.StartTime);
|
2017-04-06 11:14:06 +08:00
|
|
|
|
Assert.IsTrue(hit.Samples.Any(s => s.Name == SampleInfo.HIT_CLAP));
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-10 22:17:18 +08:00
|
|
|
|
}
|