mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 09:02:58 +08:00
Merge pull request #266 from kizayoi/master
Add support for old beatmaps
This commit is contained in:
commit
ee0b6be84b
@ -49,12 +49,12 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
{
|
||||
return new BeatmapSetInfo
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
OnlineBeatmapSetID = 1234 + i,
|
||||
Hash = "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||
Path = string.Empty,
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
OnlineBeatmapSetID = 1234 + i,
|
||||
Artist = "MONACA",
|
||||
Title = "Black Song",
|
||||
Author = "Some Guy",
|
||||
@ -63,7 +63,7 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1234 + i,
|
||||
OnlineBeatmapID = 1234 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "normal.osu",
|
||||
Version = "Normal",
|
||||
@ -74,7 +74,7 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1235 + i,
|
||||
OnlineBeatmapID = 1235 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "hard.osu",
|
||||
Version = "Hard",
|
||||
@ -85,7 +85,7 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1236 + i,
|
||||
OnlineBeatmapID = 1236 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "insane.osu",
|
||||
Version = "Insane",
|
||||
|
@ -23,7 +23,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
OsuLegacyDecoder.Register();
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
}
|
||||
[Test]
|
||||
|
||||
[Test]
|
||||
public void TestDecodeMetadata()
|
||||
{
|
||||
var decoder = new OsuLegacyDecoder();
|
||||
@ -31,7 +32,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
{
|
||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
||||
var meta = beatmap.BeatmapInfo.Metadata;
|
||||
Assert.AreEqual(241526, meta.BeatmapSetID);
|
||||
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
|
||||
Assert.AreEqual("Soleily", meta.Artist);
|
||||
Assert.AreEqual("Soleily", meta.ArtistUnicode);
|
||||
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
|
||||
@ -125,7 +126,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
public void TestDecodeHitObjects()
|
||||
[Test]
|
||||
public void TestDecodeHitObjects()
|
||||
{
|
||||
var decoder = new OsuLegacyDecoder();
|
||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||
|
@ -83,7 +83,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Action waitAction = () =>
|
||||
{
|
||||
while ((resultSets = osu.Dependencies.Get<BeatmapDatabase>()
|
||||
.Query<BeatmapSetInfo>().Where(s => s.BeatmapSetID == 241526)).Count() != 1)
|
||||
.Query<BeatmapSetInfo>().Where(s => s.OnlineBeatmapSetID == 241526)).Count() != 1)
|
||||
Thread.Sleep(1);
|
||||
};
|
||||
|
||||
@ -100,7 +100,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
waitAction = () =>
|
||||
{
|
||||
while ((resultBeatmaps = osu.Dependencies.Get<BeatmapDatabase>()
|
||||
.Query<BeatmapInfo>().Where(s => s.BeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
|
||||
.Query<BeatmapInfo>().Where(s => s.OnlineBeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
|
||||
Thread.Sleep(1);
|
||||
};
|
||||
|
||||
@ -113,7 +113,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Assert.IsTrue(set.Beatmaps.Count == resultBeatmaps.Count());
|
||||
|
||||
foreach (BeatmapInfo b in resultBeatmaps)
|
||||
Assert.IsTrue(set.Beatmaps.Any(c => c.BeatmapID == b.BeatmapID));
|
||||
Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineBeatmapID == b.OnlineBeatmapID));
|
||||
|
||||
Assert.IsTrue(set.Beatmaps.Count > 0);
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
var reader = new OszArchiveReader(osz);
|
||||
var meta = reader.ReadMetadata();
|
||||
Assert.AreEqual(241526, meta.BeatmapSetID);
|
||||
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
|
||||
Assert.AreEqual("Soleily", meta.Artist);
|
||||
Assert.AreEqual("Soleily", meta.ArtistUnicode);
|
||||
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
|
||||
@ -65,7 +65,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Assert.AreEqual("Renatus", meta.TitleUnicode);
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
|
||||
[Test]
|
||||
public void TestReadFile()
|
||||
{
|
||||
using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz"))
|
||||
|
@ -26,6 +26,10 @@ namespace osu.Game.Beatmaps.Formats
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v11");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v10");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v9");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v8");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v7");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v6");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v5");
|
||||
// TODO: Not sure how far back to go, or differences between versions
|
||||
}
|
||||
|
||||
@ -132,11 +136,11 @@ namespace osu.Game.Beatmaps.Formats
|
||||
beatmap.BeatmapInfo.Metadata.Tags = val;
|
||||
break;
|
||||
case @"BeatmapID":
|
||||
beatmap.BeatmapInfo.BeatmapID = int.Parse(val);
|
||||
beatmap.BeatmapInfo.OnlineBeatmapID = int.Parse(val);
|
||||
break;
|
||||
case @"BeatmapSetID":
|
||||
beatmap.BeatmapInfo.BeatmapSetID = int.Parse(val);
|
||||
metadata.BeatmapSetID = int.Parse(val);
|
||||
beatmap.BeatmapInfo.OnlineBeatmapSetID = int.Parse(val);
|
||||
metadata.OnlineBeatmapSetID = int.Parse(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ namespace osu.Game.Database
|
||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||
metadata = reader.ReadMetadata();
|
||||
|
||||
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
if (metadata.OnlineBeatmapSetID.HasValue &&
|
||||
connection.Table<BeatmapSetInfo>().Count(b => b.OnlineBeatmapSetID == metadata.OnlineBeatmapSetID) != 0)
|
||||
return; // TODO: Update this beatmap instead
|
||||
|
||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||
@ -86,7 +87,7 @@ namespace osu.Game.Database
|
||||
}
|
||||
var beatmapSet = new BeatmapSetInfo
|
||||
{
|
||||
BeatmapSetID = metadata.BeatmapSetID,
|
||||
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
|
||||
Beatmaps = new List<BeatmapInfo>(),
|
||||
Path = path,
|
||||
Hash = hash,
|
||||
@ -139,18 +140,18 @@ namespace osu.Game.Database
|
||||
|
||||
public BeatmapSetInfo GetBeatmapSet(int id)
|
||||
{
|
||||
return Query<BeatmapSetInfo>().FirstOrDefault(s => s.BeatmapSetID == id);
|
||||
return Query<BeatmapSetInfo>().FirstOrDefault(s => s.OnlineBeatmapSetID == id);
|
||||
}
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null)
|
||||
{
|
||||
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.BeatmapSetID == beatmapInfo.BeatmapSetID);
|
||||
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID);
|
||||
|
||||
//we need metadata
|
||||
GetChildren(beatmapSetInfo);
|
||||
|
||||
if (beatmapSetInfo == null)
|
||||
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
|
||||
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database.");
|
||||
|
||||
if (beatmapInfo.Metadata == null)
|
||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||
|
@ -13,11 +13,15 @@ namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapInfo : IEquatable<BeatmapInfo>
|
||||
{
|
||||
[PrimaryKey]
|
||||
public int BeatmapID { get; set; }
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
|
||||
public int? OnlineBeatmapID { get; set; } = null;
|
||||
|
||||
public int? OnlineBeatmapSetID { get; set; } = null;
|
||||
|
||||
[ForeignKey(typeof(BeatmapSetInfo))]
|
||||
public int BeatmapSetID { get; set; }
|
||||
public int BeatmapSetInfoID { get; set; }
|
||||
|
||||
[ManyToOne]
|
||||
public BeatmapSetInfo BeatmapSet { get; set; }
|
||||
@ -71,7 +75,7 @@ namespace osu.Game.Database
|
||||
|
||||
public bool Equals(BeatmapInfo other)
|
||||
{
|
||||
return BeatmapID == other?.BeatmapID;
|
||||
return ID == other?.ID;
|
||||
}
|
||||
|
||||
public bool AudioEquals(BeatmapInfo other) => other != null &&
|
||||
|
@ -9,8 +9,9 @@ namespace osu.Game.Database
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
|
||||
public int BeatmapSetID { get; set; }
|
||||
|
||||
public int? OnlineBeatmapSetID { get; set; } = null;
|
||||
|
||||
public string Title { get; set; }
|
||||
public string TitleUnicode { get; set; }
|
||||
public string Artist { get; set; }
|
||||
|
@ -10,20 +10,22 @@ namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapSetInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public int BeatmapSetID { get; set; }
|
||||
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
|
||||
public int? OnlineBeatmapSetID { get; set; } = null;
|
||||
|
||||
[OneToOne(CascadeOperations = CascadeOperation.All)]
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
|
||||
[NotNull, ForeignKey(typeof(BeatmapMetadata))]
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
|
||||
[NotNull, ForeignKey(typeof(BeatmapMetadata))]
|
||||
public int BeatmapMetadataID { get; set; }
|
||||
|
||||
[OneToMany(CascadeOperations = CascadeOperation.All)]
|
||||
public List<BeatmapInfo> Beatmaps { get; set; }
|
||||
|
||||
public string Hash { get; set; }
|
||||
|
||||
[OneToMany(CascadeOperations = CascadeOperation.All)]
|
||||
public List<BeatmapInfo> Beatmaps { get; set; }
|
||||
|
||||
public string Hash { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
if (!beatmap.Equals(Beatmap?.BeatmapInfo))
|
||||
{
|
||||
if (beatmap.BeatmapSetID == Beatmap?.BeatmapInfo.BeatmapSetID)
|
||||
if (beatmap.BeatmapSetInfoID == Beatmap?.BeatmapInfo.BeatmapSetInfoID)
|
||||
sampleChangeDifficulty.Play();
|
||||
else
|
||||
{
|
||||
@ -331,7 +331,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet, BaseGame game)
|
||||
{
|
||||
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.ID);
|
||||
beatmapSet.Beatmaps.ForEach(b =>
|
||||
{
|
||||
database.GetChildren(b);
|
||||
|
Loading…
Reference in New Issue
Block a user