mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:02:54 +08:00
Start implementing legacy decoder
This commit is contained in:
parent
c9a057b510
commit
2a3f047895
46
osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs
Normal file
46
osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
[TestFixture]
|
||||
public class OszArchiveReaderTest
|
||||
{
|
||||
[TestFixtureSetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
OszArchiveReader.Register();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadBeatmaps()
|
||||
{
|
||||
using (var osz = File.OpenRead(Resource.GetPath("241526 Soleily - Renatus.osz")))
|
||||
{
|
||||
var reader = new OszArchiveReader(osz);
|
||||
string[] expected =
|
||||
{
|
||||
"Soleily - Renatus (Deif) [Platter].osu",
|
||||
"Soleily - Renatus (Deif) [Rain].osu",
|
||||
"Soleily - Renatus (Deif) [Salad].osu",
|
||||
"Soleily - Renatus (ExPew) [Another].osu",
|
||||
"Soleily - Renatus (ExPew) [Hyper].osu",
|
||||
"Soleily - Renatus (ExPew) [Normal].osu",
|
||||
"Soleily - Renatus (Gamu) [Hard].osu",
|
||||
"Soleily - Renatus (Gamu) [Insane].osu",
|
||||
"Soleily - Renatus (Gamu) [Normal].osu",
|
||||
"Soleily - Renatus (MMzz) [Futsuu].osu",
|
||||
"Soleily - Renatus (MMzz) [Muzukashii].osu",
|
||||
"Soleily - Renatus (MMzz) [Oni].osu"
|
||||
};
|
||||
var maps = reader.ReadBeatmaps();
|
||||
foreach (var map in expected)
|
||||
Assert.Contains(map, maps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
osu.Game.Tests/Resources/Resource.cs
Normal file
15
osu.Game.Tests/Resources/Resource.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace osu.Game.Tests.Resources
|
||||
{
|
||||
public static class Resource
|
||||
{
|
||||
public static string GetPath(string path)
|
||||
{
|
||||
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
return Path.Combine(assemblyDir, "Resources", path);
|
||||
}
|
||||
}
|
||||
}
|
57
osu.Game.Tests/osu.Game.Tests.csproj
Normal file
57
osu.Game.Tests/osu.Game.Tests.csproj
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{54377672-20B1-40AF-8087-5CF73BF3953A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>osu.Game.Tests</RootNamespace>
|
||||
<AssemblyName>osu.Game.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources\241526 Soleily - Renatus.osz">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\osu.Game\osu.Game.csproj">
|
||||
<Project>{0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}</Project>
|
||||
<Name>osu.Game</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
<Folder Include="Beatmaps\" />
|
||||
<Folder Include="Beatmaps\IO\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Beatmaps\IO\OszArchiveReaderTest.cs" />
|
||||
<Compile Include="Resources\Resource.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
4
osu.Game.Tests/packages.config
Normal file
4
osu.Game.Tests/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="2.6.4" targetFramework="net45" />
|
||||
</packages>
|
@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Game.Beatmaps.Objects;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public class OsuLegacyDecoder : BeatmapDecoder
|
||||
{
|
||||
static OsuLegacyDecoder()
|
||||
public static void Register()
|
||||
{
|
||||
AddDecoder<OsuLegacyDecoder>("osu file format v14");
|
||||
AddDecoder<OsuLegacyDecoder>("osu file format v13");
|
||||
@ -16,6 +20,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
}
|
||||
private enum Section
|
||||
{
|
||||
None,
|
||||
General,
|
||||
Editor,
|
||||
Metadata,
|
||||
@ -25,10 +30,102 @@ namespace osu.Game.Beatmaps.Formats
|
||||
Colours,
|
||||
HitObjects,
|
||||
}
|
||||
private void HandleGeneral(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case "AudioFilename":
|
||||
beatmap.Metadata.AudioFile = val;
|
||||
break;
|
||||
case "AudioLeadIn":
|
||||
// TODO
|
||||
break;
|
||||
case "PreviewTime":
|
||||
beatmap.Metadata.PreviewTime = int.Parse(val);
|
||||
break;
|
||||
case "Countdown":
|
||||
// TODO
|
||||
break;
|
||||
case "SampleSet":
|
||||
// TODO
|
||||
break;
|
||||
case "StackLeniency":
|
||||
// TODO
|
||||
break;
|
||||
case "Mode":
|
||||
beatmap.Metadata.Mode = (PlayMode)int.Parse(val);
|
||||
break;
|
||||
case "LetterboxInBreaks":
|
||||
// TODO
|
||||
break;
|
||||
case "SpecialStyle":
|
||||
// TODO
|
||||
break;
|
||||
case "WidescreenStoryboard":
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override Beatmap Decode(TextReader stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
{
|
||||
var beatmap = new Beatmap
|
||||
{
|
||||
Metadata = new BeatmapMetadata(),
|
||||
HitObjects = new List<HitObject>(),
|
||||
ControlPoints = new List<ControlPoint>(),
|
||||
};
|
||||
var section = Section.None;
|
||||
string line;
|
||||
while (true)
|
||||
{
|
||||
line = stream.ReadLine();
|
||||
if (line == null)
|
||||
break;
|
||||
line = line.Trim();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
|
||||
if (line.StartsWith("[") && line.EndsWith("]"))
|
||||
{
|
||||
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
||||
throw new InvalidOperationException($@"Unknown osu section {line}");
|
||||
continue;
|
||||
}
|
||||
|
||||
string val = line, key = null;
|
||||
if (section != Section.Events && section != Section.TimingPoints
|
||||
&& section != Section.HitObjects)
|
||||
{
|
||||
key = val.Remove(val.IndexOf(':')).Trim();
|
||||
val = val.Substring(val.IndexOf(':') + 1).Trim();
|
||||
}
|
||||
switch (section)
|
||||
{
|
||||
case Section.General:
|
||||
HandleGeneral(beatmap, key, val);
|
||||
break;
|
||||
case Section.Editor:
|
||||
// TODO
|
||||
break;
|
||||
case Section.Metadata:
|
||||
// TODO
|
||||
break;
|
||||
case Section.Difficulty:
|
||||
// TODO
|
||||
break;
|
||||
case Section.Events:
|
||||
// TODO
|
||||
break;
|
||||
case Section.TimingPoints:
|
||||
// TODO
|
||||
break;
|
||||
case Section.HitObjects:
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
return beatmap;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public class OszArchiveReader : ArchiveReader
|
||||
public sealed class OszArchiveReader : ArchiveReader
|
||||
{
|
||||
static OszArchiveReader()
|
||||
public static void Register()
|
||||
{
|
||||
AddReader<OszArchiveReader>((storage, path) =>
|
||||
{
|
||||
@ -20,6 +20,7 @@ namespace osu.Game.Beatmaps.IO
|
||||
return zip.Entries.Any(e => e.FileName.EndsWith(".osu"));
|
||||
}
|
||||
});
|
||||
OsuLegacyDecoder.Register();
|
||||
}
|
||||
|
||||
private ZipFile Archive { get; set; }
|
||||
|
@ -5,6 +5,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
@ -34,6 +35,7 @@ namespace osu.Game
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
OszArchiveReader.Register();
|
||||
Beatmaps = new BeatmapDatabase(Host.Storage);
|
||||
|
||||
//this completely overrides the framework default. will need to change once we make a proper FontStore.
|
||||
|
9
osu.sln
9
osu.sln
@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Framework.Desktop", "os
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Desktop.VisualTests", "osu.Desktop.VisualTests\osu.Desktop.VisualTests.csproj", "{69051C69-12AE-4E7D-A3E6-460D2E282312}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Game.Tests", "osu.Game.Tests\osu.Game.Tests.csproj", "{54377672-20B1-40AF-8087-5CF73BF3953A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -56,6 +58,12 @@ Global
|
||||
{69051C69-12AE-4E7D-A3E6-460D2E282312}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{69051C69-12AE-4E7D-A3E6-460D2E282312}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{69051C69-12AE-4E7D-A3E6-460D2E282312}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Deploy|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Deploy|Any CPU.Build.0 = Release|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -67,6 +75,7 @@ Global
|
||||
{D9A367C9-4C1A-489F-9B05-A0CEA2B53B58} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3}
|
||||
{65DC628F-A640-4111-AB35-3A5652BC1E17} = {7A75DFA2-DE65-4458-98AF-26AF96FFD6DC}
|
||||
{69051C69-12AE-4E7D-A3E6-460D2E282312} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3}
|
||||
{54377672-20B1-40AF-8087-5CF73BF3953A} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3}
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
Policies = $0
|
||||
|
Loading…
Reference in New Issue
Block a user