1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-24 04:49:28 +08:00

Refactor database to reuse existing types

This commit is contained in:
Drew DeVault 2016-10-07 13:50:34 -04:00
parent 87f3e2e1db
commit 364dc9f709
11 changed files with 44 additions and 67 deletions

@ -45,7 +45,7 @@ namespace osu.Desktop.Beatmaps.IO
return File.OpenRead(Path.Combine(BasePath, name)); return File.OpenRead(Path.Combine(BasePath, name));
} }
public override Metadata ReadMetadata() public override BeatmapMetadata ReadMetadata()
{ {
return FirstMap.Metadata; return FirstMap.Metadata;
} } } }

@ -1,16 +1,12 @@
using System; using System;
using SQLite; using SQLite;
namespace osu.Game.Database namespace osu.Game.Beatmaps
{ {
public class Beatmap public class BaseDifficulty
{ {
[PrimaryKey] [PrimaryKey, AutoIncrement]
public int ID { get; set; } public int ID { get; set; }
[NotNull, Indexed]
public int BeatmapSetID { get; set; }
[Indexed]
public int BeatmapMetadataID { get; set; }
public float DrainRate { get; set; } public float DrainRate { get; set; }
public float CircleSize { get; set; } public float CircleSize { get; set; }
public float OverallDifficulty { get; set; } public float OverallDifficulty { get; set; }
@ -18,4 +14,5 @@ namespace osu.Game.Database
public float SliderMultiplier { get; set; } public float SliderMultiplier { get; set; }
public float SliderTickRate { get; set; } public float SliderTickRate { get; set; }
} }
} }

@ -5,17 +5,27 @@ using System.Collections.Generic;
using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Users; using osu.Game.Users;
using SQLite;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
public class Beatmap public class Beatmap
{ {
public int BeatmapID; [PrimaryKey]
public int BeatmapID { get; set; }
public List<HitObject> HitObjects; [NotNull, Indexed]
public List<ControlPoint> ControlPoints; public int BeatmapSetID { get; set; }
[Indexed]
public string Version; public int BeatmapMetadataID { get; set; }
public Metadata Metadata; public int BaseDifficultyID { get; set; }
[Ignore]
public List<HitObject> HitObjects { get; set; }
[Ignore]
public List<ControlPoint> ControlPoints { get; set; }
[Ignore]
public BeatmapMetadata Metadata { get; set; }
[Ignore]
public BaseDifficulty BaseDifficulty { get; set; }
public string Version { get; set; }
} }
} }

@ -2,11 +2,15 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.GameModes.Play; using osu.Game.GameModes.Play;
using SQLite;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
public class Metadata public class BeatmapMetadata
{ {
[PrimaryKey]
public int ID { get; set; }
public int BeatmapSetID { get; set; } public int BeatmapSetID { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string TitleUnicode { get; set; } public string TitleUnicode { get; set; }

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Users; using osu.Game.Users;
using SQLite;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
@ -11,12 +12,15 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public class BeatmapSet public class BeatmapSet
{ {
public int BeatmapSetID; [PrimaryKey]
public int BeatmapSetID { get; set; }
[NotNull, Indexed]
public int BeatmapMetadataID { get; set; }
[Ignore]
public List<Beatmap> Beatmaps { get; protected set; } public List<Beatmap> Beatmaps { get; protected set; }
[Ignore]
public Metadata Metadata; public BeatmapMetadata Metadata { get; set; }
[Ignore]
public User Creator; public User Creator { get; set; }
} }
} }

@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps.IO
/// <summary> /// <summary>
/// Reads the beatmap metadata from this archive. /// Reads the beatmap metadata from this archive.
/// </summary> /// </summary>
public abstract Metadata ReadMetadata(); public abstract BeatmapMetadata ReadMetadata();
/// <summary> /// <summary>
/// Gets a list of beatmap file names. /// Gets a list of beatmap file names.
/// </summary> /// </summary>

@ -53,7 +53,7 @@ namespace osu.Game.Beatmaps.IO
return entry.OpenReader(); return entry.OpenReader();
} }
public override Metadata ReadMetadata() public override BeatmapMetadata ReadMetadata()
{ {
return FirstMap.Metadata; return FirstMap.Metadata;
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using osu.Framework.OS; using osu.Framework.OS;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.IO; using osu.Game.Beatmaps.IO;
using SQLite; using SQLite;
@ -52,7 +53,7 @@ namespace osu.Game.Database
var beatmap = decoder.Decode(stream); var beatmap = decoder.Decode(stream);
maps.Add(new Beatmap maps.Add(new Beatmap
{ {
ID = beatmap.BeatmapID, BeatmapID = beatmap.BeatmapID,
BeatmapSetID = metadata.BeatmapSetID, BeatmapSetID = metadata.BeatmapSetID,
// TODO: Import more things // TODO: Import more things
}); });

@ -1,23 +0,0 @@
using System;
using osu.Game.GameModes.Play;
using SQLite;
namespace osu.Game.Database
{
public class BeatmapMetadata
{
[PrimaryKey]
public int ID { get; set; }
public string Title { get; set; }
public string TitleUnicode { get; set; }
public string Artist { get; set; }
public string ArtistUnicode { get; set; }
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; }
}
}

@ -1,14 +0,0 @@
using System;
using SQLite;
namespace osu.Game.Database
{
public class BeatmapSet
{
[PrimaryKey]
public int BeatmapSetID { get; set; }
[NotNull, Indexed]
public int BeatmapMetadataID { get; set; }
}
}

@ -62,7 +62,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Beatmaps\Beatmap.cs" /> <Compile Include="Beatmaps\Beatmap.cs" />
<Compile Include="Beatmaps\BeatmapSet.cs" /> <Compile Include="Beatmaps\BeatmapSet.cs" />
<Compile Include="Beatmaps\Metadata.cs" /> <Compile Include="Beatmaps\BeatmapMetadata.cs" />
<Compile Include="Beatmaps\Objects\HitObject.cs" /> <Compile Include="Beatmaps\Objects\HitObject.cs" />
<Compile Include="Beatmaps\Objects\Catch\CatchBaseHit.cs" /> <Compile Include="Beatmaps\Objects\Catch\CatchBaseHit.cs" />
<Compile Include="Beatmaps\Objects\Catch\Droplet.cs" /> <Compile Include="Beatmaps\Objects\Catch\Droplet.cs" />
@ -149,13 +149,11 @@
<Compile Include="Users\User.cs" /> <Compile Include="Users\User.cs" />
<Compile Include="VolumeControl.cs" /> <Compile Include="VolumeControl.cs" />
<Compile Include="Database\BeatmapDatabase.cs" /> <Compile Include="Database\BeatmapDatabase.cs" />
<Compile Include="Database\BeatmapSet.cs" />
<Compile Include="Database\BeatmapMetadata.cs" />
<Compile Include="Database\Beatmap.cs" />
<Compile Include="Beatmaps\IO\ArchiveReader.cs" /> <Compile Include="Beatmaps\IO\ArchiveReader.cs" />
<Compile Include="Beatmaps\Formats\BeatmapDecoder.cs" /> <Compile Include="Beatmaps\Formats\BeatmapDecoder.cs" />
<Compile Include="Beatmaps\Formats\OsuLegacyDecoder.cs" /> <Compile Include="Beatmaps\Formats\OsuLegacyDecoder.cs" />
<Compile Include="Beatmaps\IO\OszArchiveReader.cs" /> <Compile Include="Beatmaps\IO\OszArchiveReader.cs" />
<Compile Include="Beatmaps\BaseDifficulty.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj"> <ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">