mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add more decoding (including full BeatmapMetadata)
This commit is contained in:
committed by
Dean Herbert
parent
2a3f047895
commit
32ab8f97bb
@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Game.GameModes.Play;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Beatmaps.IO
|
||||
@ -41,6 +42,27 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Assert.Contains(map, maps);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadMetadata()
|
||||
{
|
||||
using (var osz = File.OpenRead(Resource.GetPath("241526 Soleily - Renatus.osz")))
|
||||
{
|
||||
var reader = new OszArchiveReader(osz);
|
||||
var meta = reader.ReadMetadata();
|
||||
Assert.AreEqual(241526, meta.BeatmapSetID);
|
||||
Assert.AreEqual("Soleily", meta.Artist);
|
||||
Assert.AreEqual("Soleily", meta.ArtistUnicode);
|
||||
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
|
||||
Assert.AreEqual("Deif", 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps.Objects;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
using osu.Game.Users;
|
||||
using SQLite;
|
||||
|
||||
@ -26,6 +27,7 @@ namespace osu.Game.Beatmaps
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
[Ignore]
|
||||
public BaseDifficulty BaseDifficulty { get; set; }
|
||||
public PlayMode Mode { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ namespace osu.Game.Beatmaps
|
||||
public string Author { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public PlayMode Mode { get; set; }
|
||||
public int PreviewTime { get; set; }
|
||||
public string AudioFile { get; set; }
|
||||
public string BackgroundFile { get; set; }
|
||||
|
14
osu.Game/Beatmaps/Events/EventType.cs
Normal file
14
osu.Game/Beatmaps/Events/EventType.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
namespace osu.Game.Beatmaps.Events
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
Background = 0,
|
||||
Video = 1,
|
||||
Break = 2,
|
||||
Colour = 3,
|
||||
Sprite = 4,
|
||||
Sample = 5,
|
||||
Animation = 6
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Game.Beatmaps.Events;
|
||||
using osu.Game.Beatmaps.Objects;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
@ -18,7 +19,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
AddDecoder<OsuLegacyDecoder>("osu file format v10");
|
||||
// TODO: Not sure how far back to go, or differences between versions
|
||||
}
|
||||
|
||||
|
||||
private enum Section
|
||||
{
|
||||
None,
|
||||
General,
|
||||
@ -30,7 +32,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
Colours,
|
||||
HitObjects,
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleGeneral(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@ -53,7 +56,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
// TODO
|
||||
break;
|
||||
case "Mode":
|
||||
break;
|
||||
beatmap.Mode = (PlayMode)int.Parse(val);
|
||||
break;
|
||||
case "LetterboxInBreaks":
|
||||
// TODO
|
||||
@ -67,11 +70,69 @@ namespace osu.Game.Beatmaps.Formats
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleMetadata(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case "Title":
|
||||
beatmap.Metadata.Title = val;
|
||||
break;
|
||||
case "TitleUnicode":
|
||||
beatmap.Metadata.TitleUnicode = val;
|
||||
break;
|
||||
case "Artist":
|
||||
beatmap.Metadata.Artist = val;
|
||||
break;
|
||||
case "ArtistUnicode":
|
||||
beatmap.Metadata.ArtistUnicode = val;
|
||||
break;
|
||||
case "Creator":
|
||||
beatmap.Metadata.Author = val;
|
||||
break;
|
||||
case "Version":
|
||||
beatmap.Version = val;
|
||||
break;
|
||||
case "Source":
|
||||
beatmap.Metadata.Source = val;
|
||||
break;
|
||||
case "Tags":
|
||||
beatmap.Metadata.Tags = val;
|
||||
break;
|
||||
case "BeatmapID":
|
||||
beatmap.BeatmapID = int.Parse(val);
|
||||
break;
|
||||
case "BeatmapSetID":
|
||||
beatmap.BeatmapSetID = int.Parse(val);
|
||||
beatmap.Metadata.BeatmapSetID = int.Parse(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEvents(Beatmap beatmap, string val)
|
||||
{
|
||||
if (val.StartsWith("//"))
|
||||
return;
|
||||
string[] split = val.Split(',');
|
||||
EventType type;
|
||||
int _type;
|
||||
if (!int.TryParse(split[0], out _type))
|
||||
{
|
||||
if (!Enum.TryParse(split[0], out type))
|
||||
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
||||
}
|
||||
else
|
||||
type = (EventType)_type;
|
||||
// TODO: Parse and store the rest of the event
|
||||
if (type == EventType.Background)
|
||||
beatmap.Metadata.BackgroundFile = split[2].Trim('"');
|
||||
}
|
||||
|
||||
public override Beatmap Decode(TextReader stream)
|
||||
{
|
||||
var beatmap = new Beatmap
|
||||
{
|
||||
Metadata = new BeatmapMetadata(),
|
||||
BaseDifficulty = new BaseDifficulty(),
|
||||
HitObjects = new List<HitObject>(),
|
||||
ControlPoints = new List<ControlPoint>(),
|
||||
};
|
||||
@ -89,7 +150,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
if (line.StartsWith("[") && line.EndsWith("]"))
|
||||
{
|
||||
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
||||
{
|
||||
throw new InvalidDataException($@"Unknown osu section {line}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -109,13 +170,13 @@ namespace osu.Game.Beatmaps.Formats
|
||||
// TODO
|
||||
break;
|
||||
case Section.Metadata:
|
||||
break;
|
||||
HandleMetadata(beatmap, key, val);
|
||||
break;
|
||||
case Section.Difficulty:
|
||||
// TODO
|
||||
break;
|
||||
case Section.Events:
|
||||
break;
|
||||
HandleEvents(beatmap, val);
|
||||
break;
|
||||
case Section.TimingPoints:
|
||||
// TODO
|
||||
|
@ -169,6 +169,7 @@
|
||||
<Compile Include="Beatmaps\Formats\OsuLegacyDecoder.cs" />
|
||||
<Compile Include="Beatmaps\IO\OszArchiveReader.cs" />
|
||||
<Compile Include="Beatmaps\BaseDifficulty.cs" />
|
||||
<Compile Include="Beatmaps\Events\EventType.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||
@ -191,6 +192,7 @@
|
||||
<Folder Include="Database\" />
|
||||
<Folder Include="Beatmaps\Formats\" />
|
||||
<Folder Include="Beatmaps\IO\" />
|
||||
<Folder Include="Beatmaps\Events\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
Reference in New Issue
Block a user